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 118 119 120 121 122 123 124 125 126 127 128
|
/*
* Copyright (C) 2018 Igalia S.L
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "WebKitDeviceInfoPermissionRequest.h"
#include "DeviceIdHashSaltStorage.h"
#include "UserMediaPermissionCheckProxy.h"
#include "WebKitDeviceInfoPermissionRequestPrivate.h"
#include "WebKitPermissionRequest.h"
#include "WebsiteDataStore.h"
#include <glib/gi18n-lib.h>
#include <wtf/glib/WTFGType.h>
#if !ENABLE(2022_GLIB_API)
typedef WebKitPermissionRequestIface WebKitPermissionRequestInterface;
#endif
using namespace WebKit;
/**
* WebKitDeviceInfoPermissionRequest:
* @See_also: #WebKitPermissionRequest, #WebKitWebView
*
* A permission request for accessing user's audio/video devices.
*
* WebKitUserMediaPermissionRequest represents a request for
* permission to whether WebKit should be allowed to access the user's
* devices information when requested through the enumerateDevices API.
*
* When a WebKitDeviceInfoPermissionRequest is not handled by the user,
* it is denied by default.
*
* Since: 2.24
*/
static void webkit_permission_request_interface_init(WebKitPermissionRequestInterface*);
struct _WebKitDeviceInfoPermissionRequestPrivate {
RefPtr<UserMediaPermissionCheckProxy> request;
RefPtr<DeviceIdHashSaltStorage> deviceIdHashSaltStorage;
bool madeDecision;
};
WEBKIT_DEFINE_FINAL_TYPE_WITH_CODE(
WebKitDeviceInfoPermissionRequest, webkit_device_info_permission_request, G_TYPE_OBJECT, GObject,
G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_PERMISSION_REQUEST, webkit_permission_request_interface_init))
static void webkitDeviceInfoPermissionRequestAllow(WebKitPermissionRequest* request)
{
ASSERT(WEBKIT_IS_DEVICE_INFO_PERMISSION_REQUEST(request));
auto* priv = WEBKIT_DEVICE_INFO_PERMISSION_REQUEST(request)->priv;
if (!priv->deviceIdHashSaltStorage) {
priv->request->setUserMediaAccessInfo(false);
return;
}
// Only one decision at a time.
if (priv->madeDecision)
return;
priv->madeDecision = true;
priv->request->setUserMediaAccessInfo(true);
}
static void webkitDeviceInfoPermissionRequestDeny(WebKitPermissionRequest* request)
{
ASSERT(WEBKIT_IS_DEVICE_INFO_PERMISSION_REQUEST(request));
auto* priv = WEBKIT_DEVICE_INFO_PERMISSION_REQUEST(request)->priv;
if (!priv->deviceIdHashSaltStorage) {
priv->request->setUserMediaAccessInfo(false);
return;
}
// Only one decision at a time.
if (priv->madeDecision)
return;
priv->madeDecision = true;
priv->request->setUserMediaAccessInfo(false);
}
static void webkit_permission_request_interface_init(WebKitPermissionRequestInterface* iface)
{
iface->allow = webkitDeviceInfoPermissionRequestAllow;
iface->deny = webkitDeviceInfoPermissionRequestDeny;
}
static void webkitDeviceInfoPermissionRequestDispose(GObject* object)
{
// Default behaviour when no decision has been made is denying the request.
webkitDeviceInfoPermissionRequestDeny(WEBKIT_PERMISSION_REQUEST(object));
G_OBJECT_CLASS(webkit_device_info_permission_request_parent_class)->dispose(object);
}
static void webkit_device_info_permission_request_class_init(WebKitDeviceInfoPermissionRequestClass* klass)
{
GObjectClass* objectClass = G_OBJECT_CLASS(klass);
objectClass->dispose = webkitDeviceInfoPermissionRequestDispose;
}
WebKitDeviceInfoPermissionRequest* webkitDeviceInfoPermissionRequestCreate(UserMediaPermissionCheckProxy& request, DeviceIdHashSaltStorage* deviceIdHashSaltStorage)
{
auto* deviceInfoPermissionRequest = WEBKIT_DEVICE_INFO_PERMISSION_REQUEST(g_object_new(WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST, nullptr));
deviceInfoPermissionRequest->priv->request = &request;
deviceInfoPermissionRequest->priv->deviceIdHashSaltStorage = deviceIdHashSaltStorage;
return deviceInfoPermissionRequest;
}
|