1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*
* Copyright (C) 2019 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "WebKitPointerLockPermissionRequest.h"
#include "WebKitPermissionRequest.h"
#include "WebKitPointerLockPermissionRequestPrivate.h"
#include "WebKitWebViewPrivate.h"
#include <wtf/glib/WTFGType.h>
/**
* WebKitPointerLockPermissionRequest:
* @See_also: #WebKitPermissionRequest, #WebKitWebView
*
* A permission request for locking the pointer.
*
* WebKitPointerLockPermissionRequest represents a request for
* permission to decide whether WebKit can lock the pointer device when
* requested by web content.
*
* When a WebKitPointerLockPermissionRequest is not handled by the user,
* it is allowed by default.
*
* Since: 2.28
*/
#if !ENABLE(2022_GLIB_API)
typedef WebKitPermissionRequestIface WebKitPermissionRequestInterface;
#endif
static void webkit_permission_request_interface_init(WebKitPermissionRequestInterface*);
struct _WebKitPointerLockPermissionRequestPrivate {
GRefPtr<WebKitWebView> webView;
bool madeDecision;
};
WEBKIT_DEFINE_FINAL_TYPE_WITH_CODE(
WebKitPointerLockPermissionRequest, webkit_pointer_lock_permission_request, G_TYPE_OBJECT, GObject,
G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_PERMISSION_REQUEST, webkit_permission_request_interface_init))
static void webkitPointerLockPermissionRequestAllow(WebKitPermissionRequest* request)
{
ASSERT(WEBKIT_IS_POINTER_LOCK_PERMISSION_REQUEST(request));
WebKitPointerLockPermissionRequestPrivate* priv = WEBKIT_POINTER_LOCK_PERMISSION_REQUEST(request)->priv;
// Only one decision at a time.
if (priv->madeDecision)
return;
webkitWebViewRequestPointerLock(priv->webView.get());
priv->madeDecision = true;
}
static void webkitPointerLockPermissionRequestDeny(WebKitPermissionRequest* request)
{
ASSERT(WEBKIT_IS_POINTER_LOCK_PERMISSION_REQUEST(request));
WebKitPointerLockPermissionRequestPrivate* priv = WEBKIT_POINTER_LOCK_PERMISSION_REQUEST(request)->priv;
// Only one decision at a time.
if (priv->madeDecision)
return;
webkitWebViewDenyPointerLockRequest(priv->webView.get());
priv->madeDecision = true;
}
static void webkit_permission_request_interface_init(WebKitPermissionRequestInterface* iface)
{
iface->allow = webkitPointerLockPermissionRequestAllow;
iface->deny = webkitPointerLockPermissionRequestDeny;
}
static void webkitPointerLockPermissionRequestDispose(GObject* object)
{
// Default behaviour when no decision has been made is allowing the request.
webkitPointerLockPermissionRequestAllow(WEBKIT_PERMISSION_REQUEST(object));
G_OBJECT_CLASS(webkit_pointer_lock_permission_request_parent_class)->dispose(object);
}
static void webkit_pointer_lock_permission_request_class_init(WebKitPointerLockPermissionRequestClass* klass)
{
GObjectClass* objectClass = G_OBJECT_CLASS(klass);
objectClass->dispose = webkitPointerLockPermissionRequestDispose;
}
WebKitPointerLockPermissionRequest* webkitPointerLockPermissionRequestCreate(WebKitWebView* webView)
{
WebKitPointerLockPermissionRequest* request = WEBKIT_POINTER_LOCK_PERMISSION_REQUEST(g_object_new(WEBKIT_TYPE_POINTER_LOCK_PERMISSION_REQUEST, nullptr));
request->priv->webView = webView;
return request;
}
void webkitPointerLockPermissionRequestDidLosePointerLock(WebKitPointerLockPermissionRequest* request)
{
request->priv->madeDecision = true;
request->priv->webView = nullptr;
}
|