-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GTK] Add WebKitClipboardPermissionRequest to handle DOM paste access…
… requests https://bugs.webkit.org/show_bug.cgi?id=254510 Reviewed by Michael Catanzaro and Adrian Perez de Castro. * Source/WebKit/PlatformGTK.cmake: * Source/WebKit/SourcesGTK.txt: * Source/WebKit/UIProcess/API/glib/WebKitClipboardPermissionRequest.cpp: Added. (webkitClipboardPermissionRequestAllow): (webkitClipboardPermissionRequestDeny): (webkit_permission_request_interface_init): (webkitClipboardPermissionRequestDispose): (webkit_clipboard_permission_request_class_init): (webkitClipboardPermissionRequestCreate): * Source/WebKit/UIProcess/API/glib/WebKitClipboardPermissionRequest.h.in: Added. * Source/WebKit/UIProcess/API/glib/WebKitClipboardPermissionRequestPrivate.h: Added. * Source/WebKit/UIProcess/API/glib/webkit.h.in: * Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp: (WebKit::PageClientImpl::requestDOMPasteAccess): * Tools/MiniBrowser/gtk/BrowserTab.c: (permissionRequestDialogResponse): (decidePermissionRequest): (browser_tab_class_init): * Tools/TestWebKitAPI/Tests/WebKitGtk/TestWebViewEditor.cpp: (Clipboard::writeText): (testWebViewClipboardPermissionRequest): (beforeAll): Canonical link: https://commits.webkit.org/262202@main
- Loading branch information
1 parent
3823da2
commit 2ec3bfd
Showing
9 changed files
with
299 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
Source/WebKit/UIProcess/API/glib/WebKitClipboardPermissionRequest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (C) 2023 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 "WebKitClipboardPermissionRequest.h" | ||
|
||
#include "WebKitClipboardPermissionRequestPrivate.h" | ||
#include "WebKitPermissionRequest.h" | ||
#include <wtf/glib/WTFGType.h> | ||
|
||
#if !ENABLE(2022_GLIB_API) | ||
typedef WebKitPermissionRequestIface WebKitPermissionRequestInterface; | ||
#endif | ||
|
||
/** | ||
* WebKitClipboardPermissionRequest: | ||
* @See_also: #WebKitPermissionRequest, #WebKitWebView | ||
* | ||
* A permission request for reading clipboard contents. | ||
* | ||
* WebKitClipboardPermissionRequest represents a request for | ||
* permission to decide whether WebKit can access the clibpard to read | ||
* its contents through the Async Clipboard API. | ||
* | ||
* When a WebKitClipboardPermissionRequest is not handled by the user, | ||
* it is denied by default. | ||
* | ||
* Since: 2.42 | ||
*/ | ||
|
||
static void webkit_permission_request_interface_init(WebKitPermissionRequestInterface*); | ||
|
||
struct _WebKitClipboardPermissionRequestPrivate { | ||
CompletionHandler<void(WebCore::DOMPasteAccessResponse)> completionHandler; | ||
}; | ||
|
||
WEBKIT_DEFINE_FINAL_TYPE_WITH_CODE( | ||
WebKitClipboardPermissionRequest, webkit_clipboard_permission_request, G_TYPE_OBJECT, GObject, | ||
G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_PERMISSION_REQUEST, webkit_permission_request_interface_init)) | ||
|
||
static void webkitClipboardPermissionRequestAllow(WebKitPermissionRequest* request) | ||
{ | ||
ASSERT(WEBKIT_IS_CLIPBOARD_PERMISSION_REQUEST(request)); | ||
|
||
WebKitClipboardPermissionRequestPrivate* priv = WEBKIT_CLIPBOARD_PERMISSION_REQUEST(request)->priv; | ||
|
||
if (priv->completionHandler) | ||
priv->completionHandler(WebCore::DOMPasteAccessResponse::GrantedForGesture); | ||
} | ||
|
||
static void webkitClipboardPermissionRequestDeny(WebKitPermissionRequest* request) | ||
{ | ||
ASSERT(WEBKIT_IS_CLIPBOARD_PERMISSION_REQUEST(request)); | ||
|
||
WebKitClipboardPermissionRequestPrivate* priv = WEBKIT_CLIPBOARD_PERMISSION_REQUEST(request)->priv; | ||
|
||
if (priv->completionHandler) | ||
priv->completionHandler(WebCore::DOMPasteAccessResponse::DeniedForGesture); | ||
} | ||
|
||
static void webkit_permission_request_interface_init(WebKitPermissionRequestInterface* iface) | ||
{ | ||
iface->allow = webkitClipboardPermissionRequestAllow; | ||
iface->deny = webkitClipboardPermissionRequestDeny; | ||
} | ||
|
||
static void webkitClipboardPermissionRequestDispose(GObject* object) | ||
{ | ||
// Default behaviour when no decision has been made is denying the request. | ||
webkitClipboardPermissionRequestDeny(WEBKIT_PERMISSION_REQUEST(object)); | ||
G_OBJECT_CLASS(webkit_clipboard_permission_request_parent_class)->dispose(object); | ||
} | ||
|
||
static void webkit_clipboard_permission_request_class_init(WebKitClipboardPermissionRequestClass* klass) | ||
{ | ||
GObjectClass* objectClass = G_OBJECT_CLASS(klass); | ||
objectClass->dispose = webkitClipboardPermissionRequestDispose; | ||
} | ||
|
||
WebKitClipboardPermissionRequest* webkitClipboardPermissionRequestCreate(CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler) | ||
{ | ||
WebKitClipboardPermissionRequest* clipboardPermissionRequest = WEBKIT_CLIPBOARD_PERMISSION_REQUEST(g_object_new(WEBKIT_TYPE_CLIPBOARD_PERMISSION_REQUEST, nullptr)); | ||
clipboardPermissionRequest->priv->completionHandler = WTFMove(completionHandler); | ||
return clipboardPermissionRequest; | ||
} |
47 changes: 47 additions & 0 deletions
47
Source/WebKit/UIProcess/API/glib/WebKitClipboardPermissionRequest.h.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2023 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. | ||
*/ | ||
|
||
@API_SINGLE_HEADER_CHECK@ | ||
|
||
#ifndef WebKitClipboardPermissionRequest_h | ||
#define WebKitClipboardPermissionRequest_h | ||
|
||
#include <glib-object.h> | ||
#include <@API_INCLUDE_PREFIX@/WebKitDefines.h> | ||
|
||
G_BEGIN_DECLS | ||
|
||
#define WEBKIT_TYPE_CLIPBOARD_PERMISSION_REQUEST (webkit_clipboard_permission_request_get_type()) | ||
#if !ENABLE(2022_GLIB_API) | ||
#define WEBKIT_CLIPBOARD_PERMISSION_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_CLIPBOARD_PERMISSION_REQUEST, WebKitClipboardPermissionRequest)) | ||
#define WEBKIT_CLIPBOARD_PERMISSION_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_CLIPBOARD_PERMISSION_REQUEST, WebKitClipboardPermissionRequestClass)) | ||
#define WEBKIT_IS_CLIPBOARD_PERMISSION_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_CLIPBOARD_PERMISSION_REQUEST)) | ||
#define WEBKIT_IS_CLIPBOARD_PERMISSION_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_CLIPBOARD_PERMISSION_REQUEST)) | ||
#define WEBKIT_CLIPBOARD_PERMISSION_REQUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_CLIPBOARD_PERMISSION_REQUEST, WebKitClipboardPermissionRequestClass)) | ||
|
||
struct _WebKitClipboardPermissionRequestClass { | ||
GObjectClass parent_class; | ||
}; | ||
#endif | ||
|
||
WEBKIT_DECLARE_FINAL_TYPE (WebKitClipboardPermissionRequest, webkit_clipboard_permission_request, WEBKIT, CLIPBOARD_PERMISSION_REQUEST, GObject) | ||
|
||
G_END_DECLS | ||
|
||
#endif |
26 changes: 26 additions & 0 deletions
26
Source/WebKit/UIProcess/API/glib/WebKitClipboardPermissionRequestPrivate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (C) 2023 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "WebKitClipboardPermissionRequest.h" | ||
#include <WebCore/DOMPasteAccess.h> | ||
#include <wtf/CompletionHandler.h> | ||
|
||
WebKitClipboardPermissionRequest* webkitClipboardPermissionRequestCreate(CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.