1/* 2 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18*/ 19 20#include "config.h" 21 22#include "qwebpermissionrequest_p.h" 23 24#include "WKStringQt.h" 25#include <WebKit2/WKBase.h> 26#include <WebKit2/WKRetainPtr.h> 27 28class QWebPermissionRequestPrivate : public QSharedData { 29public: 30 QWebPermissionRequestPrivate(WKSecurityOriginRef securityOrigin, WKGeolocationPermissionRequestRef geo = 0, WKNotificationPermissionRequestRef notify = 0, QWebPermissionRequest::RequestType reqType = QWebPermissionRequest::Geolocation) 31 : origin(securityOrigin) 32 , geolocationRequest(geo) 33 , notificationRequest(notify) 34 , type(reqType) 35 , allow(false) 36 { 37 WKRetainPtr<WKStringRef> url = adoptWK(WKSecurityOriginCopyProtocol(origin.get())); 38 securityInfo.setScheme(WKStringCopyQString(url.get())); 39 40 WKRetainPtr<WKStringRef> host = adoptWK(WKSecurityOriginCopyHost(origin.get())); 41 securityInfo.setHost(WKStringCopyQString(host.get())); 42 43 securityInfo.setPort(static_cast<int>(WKSecurityOriginGetPort(origin.get()))); 44 } 45 46 ~QWebPermissionRequestPrivate() 47 { 48 } 49 50 WKRetainPtr<WKSecurityOriginRef> origin; 51 WKRetainPtr<WKGeolocationPermissionRequestRef> geolocationRequest; 52 WKRetainPtr<WKNotificationPermissionRequestRef> notificationRequest; 53 QWebPermissionRequest::RequestType type; 54 QtWebSecurityOrigin securityInfo; 55 bool allow; 56}; 57 58QWebPermissionRequest* QWebPermissionRequest::create(WKSecurityOriginRef origin, WKGeolocationPermissionRequestRef request) 59{ 60 return new QWebPermissionRequest(origin, request); 61} 62 63QWebPermissionRequest* QWebPermissionRequest::create(WKSecurityOriginRef origin, WKNotificationPermissionRequestRef request) 64{ 65 return new QWebPermissionRequest(origin, 0, request, QWebPermissionRequest::Notification); 66} 67 68QWebPermissionRequest::QWebPermissionRequest(WKSecurityOriginRef securityOrigin 69 , WKGeolocationPermissionRequestRef geo 70 , WKNotificationPermissionRequestRef notify 71 , QWebPermissionRequest::RequestType type 72 , QObject* parent) 73 : QObject(parent) 74 , d(new QWebPermissionRequestPrivate(securityOrigin, geo, notify, type)) 75{ 76} 77 78QWebPermissionRequest::~QWebPermissionRequest() 79{ 80} 81 82QWebPermissionRequest::RequestType QWebPermissionRequest::type() const 83{ 84 return d->type; 85} 86 87void QWebPermissionRequest::setAllow(bool accepted) 88{ 89 d->allow = accepted; 90 switch (type()) { 91 case Geolocation: { 92 if (accepted) 93 WKGeolocationPermissionRequestAllow(d->geolocationRequest.get()); 94 else 95 WKGeolocationPermissionRequestDeny(d->geolocationRequest.get()); 96 break; 97 } 98 case Notification: { 99 if (accepted) 100 WKNotificationPermissionRequestAllow(d->notificationRequest.get()); 101 else 102 WKNotificationPermissionRequestDeny(d->notificationRequest.get()); 103 break; 104 } 105 default: 106 ASSERT_NOT_REACHED(); 107 } 108 109 deleteLater(); 110} 111 112bool QWebPermissionRequest::allow() const 113{ 114 return d->allow; 115} 116 117QtWebSecurityOrigin* QWebPermissionRequest::securityOrigin() 118{ 119 return &(d->securityInfo); 120} 121 122