~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/WebKit/UIProcess/API/glib/WebKitPointerLockPermissionRequest.cpp

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2019 Igalia S.L.
 
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
#include "WebKitPointerLockPermissionRequest.h"
 
22
 
 
23
#include "WebKitPermissionRequest.h"
 
24
#include "WebKitPointerLockPermissionRequestPrivate.h"
 
25
#include "WebKitWebViewPrivate.h"
 
26
#include <wtf/glib/WTFGType.h>
 
27
 
 
28
/**
 
29
 * SECTION: WebKitPointerLockPermissionRequest
 
30
 * @Short_description: A permission request for locking the pointer
 
31
 * @Title: WebKitPointerLockPermissionRequest
 
32
 * @See_also: #WebKitPermissionRequest, #WebKitWebView
 
33
 *
 
34
 * WebKitPointerLockPermissionRequest represents a request for
 
35
 * permission to decide whether WebKit can lock the pointer device when
 
36
 * requested by web content.
 
37
 *
 
38
 * When a WebKitPointerLockPermissionRequest is not handled by the user,
 
39
 * it is allowed by default.
 
40
 *
 
41
 * Since: 2.28
 
42
 */
 
43
 
 
44
static void webkit_permission_request_interface_init(WebKitPermissionRequestIface*);
 
45
 
 
46
struct _WebKitPointerLockPermissionRequestPrivate {
 
47
    GRefPtr<WebKitWebView> webView;
 
48
    bool madeDecision;
 
49
};
 
50
 
 
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))
 
54
 
 
55
static void webkitPointerLockPermissionRequestAllow(WebKitPermissionRequest* request)
 
56
{
 
57
    ASSERT(WEBKIT_IS_POINTER_LOCK_PERMISSION_REQUEST(request));
 
58
 
 
59
    WebKitPointerLockPermissionRequestPrivate* priv = WEBKIT_POINTER_LOCK_PERMISSION_REQUEST(request)->priv;
 
60
 
 
61
    // Only one decision at a time.
 
62
    if (priv->madeDecision)
 
63
        return;
 
64
 
 
65
    webkitWebViewRequestPointerLock(priv->webView.get());
 
66
    priv->madeDecision = true;
 
67
}
 
68
 
 
69
static void webkitPointerLockPermissionRequestDeny(WebKitPermissionRequest* request)
 
70
{
 
71
    ASSERT(WEBKIT_IS_POINTER_LOCK_PERMISSION_REQUEST(request));
 
72
 
 
73
    WebKitPointerLockPermissionRequestPrivate* priv = WEBKIT_POINTER_LOCK_PERMISSION_REQUEST(request)->priv;
 
74
 
 
75
    // Only one decision at a time.
 
76
    if (priv->madeDecision)
 
77
        return;
 
78
 
 
79
    webkitWebViewDenyPointerLockRequest(priv->webView.get());
 
80
    priv->madeDecision = true;
 
81
}
 
82
 
 
83
static void webkit_permission_request_interface_init(WebKitPermissionRequestIface* iface)
 
84
{
 
85
    iface->allow = webkitPointerLockPermissionRequestAllow;
 
86
    iface->deny = webkitPointerLockPermissionRequestDeny;
 
87
}
 
88
 
 
89
static void webkitPointerLockPermissionRequestDispose(GObject* object)
 
90
{
 
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);
 
94
}
 
95
 
 
96
static void webkit_pointer_lock_permission_request_class_init(WebKitPointerLockPermissionRequestClass* klass)
 
97
{
 
98
    GObjectClass* objectClass = G_OBJECT_CLASS(klass);
 
99
    objectClass->dispose = webkitPointerLockPermissionRequestDispose;
 
100
}
 
101
 
 
102
WebKitPointerLockPermissionRequest* webkitPointerLockPermissionRequestCreate(WebKitWebView* webView)
 
103
{
 
104
    WebKitPointerLockPermissionRequest* request = WEBKIT_POINTER_LOCK_PERMISSION_REQUEST(g_object_new(WEBKIT_TYPE_POINTER_LOCK_PERMISSION_REQUEST, nullptr));
 
105
    request->priv->webView = webView;
 
106
    return request;
 
107
}
 
108
 
 
109
void webkitPointerLockPermissionRequestDidLosePointerLock(WebKitPointerLockPermissionRequest* request)
 
110
{
 
111
    request->priv->madeDecision = true;
 
112
    request->priv->webView = nullptr;
 
113
}