2
* Copyright (C) 2019 Igalia S.L.
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.
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.
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.
21
#include "WebKitPointerLockPermissionRequest.h"
23
#include "WebKitPermissionRequest.h"
24
#include "WebKitPointerLockPermissionRequestPrivate.h"
25
#include "WebKitWebViewPrivate.h"
26
#include <wtf/glib/WTFGType.h>
29
* SECTION: WebKitPointerLockPermissionRequest
30
* @Short_description: A permission request for locking the pointer
31
* @Title: WebKitPointerLockPermissionRequest
32
* @See_also: #WebKitPermissionRequest, #WebKitWebView
34
* WebKitPointerLockPermissionRequest represents a request for
35
* permission to decide whether WebKit can lock the pointer device when
36
* requested by web content.
38
* When a WebKitPointerLockPermissionRequest is not handled by the user,
39
* it is allowed by default.
44
static void webkit_permission_request_interface_init(WebKitPermissionRequestIface*);
46
struct _WebKitPointerLockPermissionRequestPrivate {
47
GRefPtr<WebKitWebView> webView;
51
WEBKIT_DEFINE_TYPE_WITH_CODE(
52
WebKitPointerLockPermissionRequest, webkit_pointer_lock_permission_request, G_TYPE_OBJECT,
53
G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_PERMISSION_REQUEST, webkit_permission_request_interface_init))
55
static void webkitPointerLockPermissionRequestAllow(WebKitPermissionRequest* request)
57
ASSERT(WEBKIT_IS_POINTER_LOCK_PERMISSION_REQUEST(request));
59
WebKitPointerLockPermissionRequestPrivate* priv = WEBKIT_POINTER_LOCK_PERMISSION_REQUEST(request)->priv;
61
// Only one decision at a time.
62
if (priv->madeDecision)
65
webkitWebViewRequestPointerLock(priv->webView.get());
66
priv->madeDecision = true;
69
static void webkitPointerLockPermissionRequestDeny(WebKitPermissionRequest* request)
71
ASSERT(WEBKIT_IS_POINTER_LOCK_PERMISSION_REQUEST(request));
73
WebKitPointerLockPermissionRequestPrivate* priv = WEBKIT_POINTER_LOCK_PERMISSION_REQUEST(request)->priv;
75
// Only one decision at a time.
76
if (priv->madeDecision)
79
webkitWebViewDenyPointerLockRequest(priv->webView.get());
80
priv->madeDecision = true;
83
static void webkit_permission_request_interface_init(WebKitPermissionRequestIface* iface)
85
iface->allow = webkitPointerLockPermissionRequestAllow;
86
iface->deny = webkitPointerLockPermissionRequestDeny;
89
static void webkitPointerLockPermissionRequestDispose(GObject* object)
91
// Default behaviour when no decision has been made is allowing the request.
92
webkitPointerLockPermissionRequestAllow(WEBKIT_PERMISSION_REQUEST(object));
93
G_OBJECT_CLASS(webkit_pointer_lock_permission_request_parent_class)->dispose(object);
96
static void webkit_pointer_lock_permission_request_class_init(WebKitPointerLockPermissionRequestClass* klass)
98
GObjectClass* objectClass = G_OBJECT_CLASS(klass);
99
objectClass->dispose = webkitPointerLockPermissionRequestDispose;
102
WebKitPointerLockPermissionRequest* webkitPointerLockPermissionRequestCreate(WebKitWebView* webView)
104
WebKitPointerLockPermissionRequest* request = WEBKIT_POINTER_LOCK_PERMISSION_REQUEST(g_object_new(WEBKIT_TYPE_POINTER_LOCK_PERMISSION_REQUEST, nullptr));
105
request->priv->webView = webView;
109
void webkitPointerLockPermissionRequestDidLosePointerLock(WebKitPointerLockPermissionRequest* request)
111
request->priv->madeDecision = true;
112
request->priv->webView = nullptr;