WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-133730-20140624022348.patch (text/plain), 73.36 KB, created by
Adrian Perez
on 2014-06-23 16:21:47 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Adrian Perez
Created:
2014-06-23 16:21:47 PDT
Size:
73.36 KB
patch
obsolete
>Subversion Revision: 170326 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index 493d6d233be6dc94319776c1ccfc731abb835e7d..ba761bb56fda8f11dc70dcbc44d2dcc6699ae4c4 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,19 @@ >+2014-06-23 Adrian Perez de Castro <aperez@igalia.com> >+ >+ [GTK] Add new WebKitUserContent[Manager] API >+ https://bugs.webkit.org/show_bug.cgi?id=133730 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add a new WebKitUserContentManager API, and accompanying >+ WebKitUser{Content,Script,StyleSheet} classes. This enables >+ the GTK port to use the user script and style sheet injection >+ support, and the user script message handlers. >+ >+ * wtf/Platform.h: >+ Define ENABLE_USER_MESSAGE_HANDLERS when building for >+ PLATFORM(GTK). >+ > 2014-06-21 Brady Eidson <beidson@apple.com> > > Gamepad API - Deprecate the existing implementation >diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog >index bd190043332fb165d4ca4fa6498df3da4aec529a..ccfa8d68ce094aa5a8c7a63ce0b6f8583ef42612 100644 >--- a/Source/WebKit2/ChangeLog >+++ b/Source/WebKit2/ChangeLog >@@ -1,3 +1,117 @@ >+2014-06-23 Adrian Perez de Castro <aperez@igalia.com> >+ >+ [GTK] Add new WebKitUserContent[Manager] API >+ https://bugs.webkit.org/show_bug.cgi?id=133730 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add a new WebKitUserContentManager API, and accompanying >+ WebKitUser{Content,Script,StyleSheet} classes. This enables >+ the GTK port to use the user script and style sheet injection >+ support, and the user script message handlers. >+ >+ * PlatformGTK.cmake: >+ Add the new source files. >+ * UIProcess/API/C/gtk/WKView.cpp: >+ (WKViewCreate): >+ Accomodate for the additional argument to webkitWebViewBaseCreate(). >+ * UIProcess/API/gtk/WebKitUserContent.cpp: Added. >+ (toUserContentInjectedFrames): >+ (toWebKitUserContentInjectedFrames): >+ (toUserScriptInjectionTime): >+ (toWebKitUserScriptInjectionTime): >+ (toUserStyleLevel): >+ (toWebKitUserStyleLevel): >+ (_WebKitUserContentPrivate::~_WebKitUserContentPrivate): >+ (webkit_user_content_class_init): >+ (webkit_user_content_get_source): >+ (webkit_user_content_get_injected_frames): >+ (toStrV): >+ (toStringVector): >+ (webkit_user_content_get_whitelist): >+ (webkit_user_content_get_blacklist): >+ (webkit_user_script_class_init): >+ (webkit_user_script_new): >+ (webkit_user_script_get_injection_time): >+ (webkit_user_style_sheet_class_init): >+ (webkit_user_style_sheet_new): >+ (webkit_user_style_sheet_get_level): >+ (webkitWebKitUserScriptToUserScript): >+ (webkitWebKitUserStyleSheetToUserStyleSheet): >+ * UIProcess/API/gtk/WebKitUserContent.h: Added. >+ * UIProcess/API/gtk/WebKitUserContentManager.cpp: Added. >+ (_WebKitUserContentManagerPrivate::_WebKitUserContentManagerPrivate): >+ (webkit_user_content_manager_get_default): >+ (webkit_user_content_manager_add_script): >+ (webkit_user_content_manager_remove_all_scripts): >+ (webkit_user_content_manager_add_style_sheet): >+ (webkit_user_content_manager_remove_all_style_sheets): >+ (webkit_user_content_manager_register_script_message_handler): >+ (webkit_user_content_manager_unregister_script_message_handler): >+ (webkitUserContentManagerGetUserContentControllerProxy): >+ * UIProcess/API/gtk/WebKitUserContentManager.h: Added. >+ * UIProcess/API/gtk/WebKitUserContentManagerPrivate.h: Added. >+ * UIProcess/API/gtk/WebKitUserContentPrivate.h: Added. >+ * UIProcess/API/gtk/WebKitWebContext.cpp: >+ (webkitWebContextCreatePageForWebView): >+ Accept a WebKitUserContentManager as optional parameter, which can >+ be nullptr, or the content manager to attach to the newly-created >+ web view. >+ * UIProcess/API/gtk/WebKitWebContextPrivate.h: >+ Ditto. >+ * UIProcess/API/gtk/WebKitWebView.cpp: >+ (webkitWebViewConstructed): >+ Arrange to pass the WebKitUserContentManager set in property >+ "user-content-manager" to webkitWebContextCreatePageForWebView(). >+ (webkitWebViewSetProperty): >+ Support setting the "user-content-manager" property. >+ (webkitWebViewGetProperty): >+ Support getting the "user-content-manager" property. >+ (webkit_web_view_class_init): >+ Add the "user-content-manager" construct-only property. >+ (webkit_web_view_new_with_related_view): >+ Make new related views share the same user content manager as the >+ view they are related to. >+ (webkit_web_view_new_with_user_content_manager): >+ New method to create a WebKitWebView with an associated user content >+ manager. >+ (webkit_web_view_get_user_content_manager): >+ Getter for "user-content-manager". >+ * UIProcess/API/gtk/WebKitWebView.h: >+ Add the new public functions to the API. >+ * UIProcess/API/gtk/WebKitWebViewBase.cpp: >+ (webkitWebViewBaseCreate): >+ Add an optional WebUserContentControllerProxy argument. >+ (webkitWebViewBaseCreateWebPage): >+ Ditto. >+ * UIProcess/API/gtk/WebKitWebViewBasePrivate.h: >+ Ditto. >+ * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: >+ Add new API to gtk-doc. >+ * UIProcess/API/gtk/webkit2.h: >+ Include the new WebKitUserContent.h and WebKitUserContentManager.h >+ headers from the top-level API header. >+ * UIProcess/UserContent/WebUserContentControllerProxy.cpp: >+ (WebKit::WebUserContentControllerProxy::addUserStyleSheet): >+ Add missing method to add user style sheets. >+ (WebKit::WebUserContentControllerProxy::removeAllUserStyleSheets): >+ Add missing method to remove all the user style sheets. >+ * UIProcess/UserContent/WebUserContentControllerProxy.h: >+ Ditto. >+ * UIProcess/gtk/WebInspectorProxyGtk.cpp: >+ (WebKit::WebInspectorProxy::platformCreateInspectorPage): >+ Always pass nullptr as the user content manager, scripts and user >+ style sheets shall not be ever injected to the inspector code. >+ * WebProcess/UserContent/WebUserContentController.cpp: >+ (WebKit::WebUserContentController::addUserStyleSheets): >+ Add missing method to add user style sheets. >+ (WebKit::WebUserContentController::removeAllUserStyleSheets): >+ Add missing method to remove all the user style sheets. >+ * WebProcess/UserContent/WebUserContentController.h: >+ Add missing methods to add/remove user style sheets. >+ * WebProcess/UserContent/WebUserContentController.messages.in: >+ Ditto. >+ > 2014-06-23 Timothy Horton <timothy_horton@apple.com> > > [iOS][wk2] Don't use view snapshots if the destination layer is a different size >diff --git a/Source/WTF/wtf/Platform.h b/Source/WTF/wtf/Platform.h >index c06cbde8aa6bb035d8f90e2a58abed1493c4b15f..d20f9714e22be08a36cecfd91d3c587a6985706d 100644 >--- a/Source/WTF/wtf/Platform.h >+++ b/Source/WTF/wtf/Platform.h >@@ -454,6 +454,7 @@ > #define WTF_USE_HARFBUZZ 1 > #define WTF_USE_SOUP 1 > #define WTF_USE_WEBP 1 >+#define ENABLE_USER_MESSAGE_HANDLERS 1 > #endif > > /* On Windows, use QueryPerformanceCounter by default */ >diff --git a/Source/WebKit2/PlatformGTK.cmake b/Source/WebKit2/PlatformGTK.cmake >index 7649f14d97c96240547e611bc94d18312fd2119c..895185b6690ac036a0cc88f7c10dfe9b41865718 100644 >--- a/Source/WebKit2/PlatformGTK.cmake >+++ b/Source/WebKit2/PlatformGTK.cmake >@@ -207,6 +207,12 @@ list(APPEND WebKit2_SOURCES > UIProcess/API/gtk/WebKitURISchemeRequest.cpp > UIProcess/API/gtk/WebKitURISchemeRequest.h > UIProcess/API/gtk/WebKitURISchemeRequestPrivate.h >+ UIProcess/API/gtk/WebKitUserContent.h >+ UIProcess/API/gtk/WebKitUserContent.cpp >+ UIProcess/API/gtk/WebKitUserContentPrivate.h >+ UIProcess/API/gtk/WebKitUserContentManager.h >+ UIProcess/API/gtk/WebKitUserContentManagerPrivate.h >+ UIProcess/API/gtk/WebKitUserContentManager.cpp > UIProcess/API/gtk/WebKitVersion.cpp > UIProcess/API/gtk/WebKitVersion.h.in > UIProcess/API/gtk/WebKitWebContext.cpp >@@ -349,6 +355,8 @@ set(WebKit2GTK_INSTALLED_HEADERS > ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitURIRequest.h > ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitURIResponse.h > ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitURISchemeRequest.h >+ ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitUserContent.h >+ ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitUserContentManager.h > ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebContext.h > ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebInspector.h > ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebResource.h >diff --git a/Source/WebKit2/UIProcess/API/C/gtk/WKView.cpp b/Source/WebKit2/UIProcess/API/C/gtk/WKView.cpp >index 6f0c04bf273dbff61d9b0fbdc27a80d538f2c323..bc7b83f95a472e5373c07816afaeee14c5d21d05 100644 >--- a/Source/WebKit2/UIProcess/API/C/gtk/WKView.cpp >+++ b/Source/WebKit2/UIProcess/API/C/gtk/WKView.cpp >@@ -37,7 +37,7 @@ using namespace WebCore; > > WKViewRef WKViewCreate(WKContextRef contextRef, WKPageGroupRef pageGroupRef) > { >- return toAPI(webkitWebViewBaseCreate(toImpl(contextRef), toImpl(pageGroupRef), nullptr)); >+ return toAPI(webkitWebViewBaseCreate(toImpl(contextRef), toImpl(pageGroupRef), nullptr, nullptr)); > } > > WKPageRef WKViewGetPage(WKViewRef viewRef) >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..a97fb17214c8ace1449787b8b409edbc5822aaf2 >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.cpp >@@ -0,0 +1,404 @@ >+/* >+ * Copyright (C) 2014 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 "WebKitUserContent.h" >+ >+#include "WebKitPrivate.h" >+#include "WebKitUserContentPrivate.h" >+#include <WebCore/page/UserScript.h> >+#include <WebCore/page/UserStyleSheet.h> >+#include <wtf/text/CString.h> >+#include <wtf/text/StringBuilder.h> >+ >+using namespace WebCore; >+ >+ >+static inline UserContentInjectedFrames toUserContentInjectedFrames(WebKitUserContentInjectedFrames injectedFrames) >+{ >+ switch (injectedFrames) { >+ case WEBKIT_USER_CONTENT_INJECT_TOP_FRAME: >+ return InjectInTopFrameOnly; >+ case WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES: >+ return InjectInAllFrames; >+ default: >+ ASSERT_NOT_REACHED(); >+ return InjectInAllFrames; >+ } >+} >+ >+ >+static inline WebKitUserContentInjectedFrames toWebKitUserContentInjectedFrames(UserContentInjectedFrames injectedFrames) >+{ >+ switch (injectedFrames) { >+ case InjectInTopFrameOnly: >+ return WEBKIT_USER_CONTENT_INJECT_TOP_FRAME; >+ case InjectInAllFrames: >+ return WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES; >+ default: >+ ASSERT_NOT_REACHED(); >+ return WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES; >+ } >+} >+ >+ >+static inline UserScriptInjectionTime toUserScriptInjectionTime(WebKitUserScriptInjectionTime injectionTime) >+{ >+ switch (injectionTime) { >+ case WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START: >+ return InjectAtDocumentStart; >+ case WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END: >+ return InjectAtDocumentEnd; >+ default: >+ ASSERT_NOT_REACHED(); >+ return InjectAtDocumentStart; >+ } >+} >+ >+ >+static inline WebKitUserScriptInjectionTime toWebKitUserScriptInjectionTime(UserScriptInjectionTime injectionTime) >+{ >+ switch (injectionTime) { >+ case InjectAtDocumentStart: >+ return WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START; >+ case InjectAtDocumentEnd: >+ return WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END; >+ default: >+ ASSERT_NOT_REACHED(); >+ return WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END; >+ } >+} >+ >+ >+static inline UserStyleLevel toUserStyleLevel(WebKitUserStyleLevel styleLevel) >+{ >+ switch (styleLevel) { >+ case WEBKIT_USER_STYLE_LEVEL_USER: >+ return UserStyleUserLevel; >+ case WEBKIT_USER_STYLE_LEVEL_AUTHOR: >+ return UserStyleAuthorLevel; >+ default: >+ ASSERT_NOT_REACHED(); >+ return UserStyleAuthorLevel; >+ } >+} >+ >+ >+static inline WebKitUserStyleLevel toWebKitUserStyleLevel(UserStyleLevel styleLevel) >+{ >+ switch (styleLevel) { >+ case UserStyleUserLevel: >+ return WEBKIT_USER_STYLE_LEVEL_USER; >+ case UserStyleAuthorLevel: >+ return WEBKIT_USER_STYLE_LEVEL_AUTHOR; >+ default: >+ ASSERT_NOT_REACHED(); >+ return WEBKIT_USER_STYLE_LEVEL_AUTHOR; >+ } >+} >+ >+ >+enum UserContentType { >+ UserContentScript, >+ UserContentStyleSheet, >+}; >+ >+struct _WebKitUserContentPrivate { >+ ~_WebKitUserContentPrivate() >+ { >+ switch (type) { >+ case UserContentScript: >+ delete script; >+ break; >+ case UserContentStyleSheet: >+ delete styleSheet; >+ break; >+ default: >+ ASSERT_NOT_REACHED(); >+ } >+ } >+ >+ UserContentType type; >+ union { >+ UserScript* script; >+ UserStyleSheet* styleSheet; >+ }; >+}; >+ >+WEBKIT_DEFINE_ABSTRACT_TYPE(WebKitUserContent, webkit_user_content, G_TYPE_OBJECT) >+ >+ >+static void webkit_user_content_class_init(WebKitUserContentClass*) >+{ >+} >+ >+/** >+ * webkit_user_content_get_source: >+ * @user_content: A #WebKitUserContent >+ * >+ * Obtains a copy of the source for an user content object. The returned >+ * string must be freed using g_free(). >+ * >+ * Returns: (transfer full): An UTF-8 string. >+ */ >+gchar* webkit_user_content_get_source(WebKitUserContent* userContent) >+{ >+ g_return_val_if_fail(WEBKIT_IS_USER_CONTENT(userContent), nullptr); >+ switch (userContent->priv->type) { >+ case UserContentScript: >+ return g_strdup(userContent->priv->script->source().utf8().data()); >+ break; >+ case UserContentStyleSheet: >+ return g_strdup(userContent->priv->styleSheet->source().utf8().data()); >+ break; >+ default: >+ ASSERT_NOT_REACHED(); >+ return nullptr; >+ } >+} >+ >+/** >+ * webkit_user_content_get_injected_frames: >+ * @user_content: A #WebKitUserContent >+ * >+ * Gets in which frames the user content is to be injected in. >+ * >+ * Returns: A #WebKitUserContentInjectedFrames value. >+ */ >+WebKitUserContentInjectedFrames webkit_user_content_get_injected_frames(WebKitUserContent* userContent) >+{ >+ g_return_val_if_fail(WEBKIT_IS_USER_CONTENT(userContent), WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES); >+ switch (userContent->priv->type) { >+ case UserContentScript: >+ return toWebKitUserContentInjectedFrames(userContent->priv->script->injectedFrames()); >+ case UserContentStyleSheet: >+ return toWebKitUserContentInjectedFrames(userContent->priv->styleSheet->injectedFrames()); >+ default: >+ ASSERT_NOT_REACHED(); >+ return WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES; >+ } >+} >+ >+ >+static inline gchar** toStrV(const Vector<String>& strv) >+{ >+ GPtrArray* result = g_ptr_array_sized_new(strv.size()); >+ for (auto i = strv.begin(); i != strv.end(); ++i) { >+ if (i->isEmpty()) >+ continue; >+ g_ptr_array_add(result, g_strdup(i->utf8().data())); >+ } >+ g_ptr_array_add(result, nullptr); >+ return reinterpret_cast<gchar**>(g_ptr_array_free(result, FALSE)); >+} >+ >+ >+static inline Vector<String> toStringVector(const char* const* strv) >+{ >+ if (!strv) >+ return Vector<String>(); >+ >+ Vector<String> result; >+ for (auto str = *strv; str != nullptr; ++str) >+ result.append(std::move(String::fromUTF8(str))); >+ return result; >+} >+ >+ >+/** >+ * webkit_user_content_get_whitelist: >+ * @user_content: A #WebKitUserContent >+ * >+ * Obtains the list whitelisted URL patterns to which the user content is >+ * to be applied. >+ * >+ * The returned value is a %NULL terminated array of strings which must be >+ * released with g_strfreev(). >+ * >+ * Returns: (transfer full) (array zero-terminated=1): A %NULL terminated >+ * array of string, or %NULL in case of error. >+ */ >+gchar** webkit_user_content_get_whitelist(WebKitUserContent* userContent) >+{ >+ g_return_val_if_fail(WEBKIT_IS_USER_CONTENT(userContent), nullptr); >+ >+ switch (userContent->priv->type) { >+ case UserContentScript: >+ return toStrV(userContent->priv->script->whitelist()); >+ case UserContentStyleSheet: >+ return toStrV(userContent->priv->styleSheet->whitelist()); >+ default: >+ ASSERT_NOT_REACHED(); >+ return nullptr; >+ } >+} >+ >+/** >+ * webkit_user_content_get_blacklist: >+ * @user_content: A #WebKitUserContent >+ * >+ * Obtains the list blacklisted URI patterns to which the user content is >+ * *not* to be applied. >+ * >+ * The returned value is a %NULL terminated array of strings which must be >+ * released with g_strfreev(). >+ * >+ * Returns: (transfer full) (array zero-terminated=1): A %NULL terminated >+ * array of string, or %NULL in case of error. >+ */ >+gchar** webkit_user_content_get_blacklist(WebKitUserContent* userContent) >+{ >+ g_return_val_if_fail(WEBKIT_IS_USER_CONTENT(userContent), nullptr); >+ >+ switch (userContent->priv->type) { >+ case UserContentScript: >+ return toStrV(userContent->priv->script->blacklist()); >+ case UserContentStyleSheet: >+ return toStrV(userContent->priv->styleSheet->blacklist()); >+ default: >+ ASSERT_NOT_REACHED(); >+ return nullptr; >+ } >+} >+ >+ >+ >+struct _WebKitUserScriptPrivate { >+}; >+ >+WEBKIT_DEFINE_TYPE(WebKitUserScript, webkit_user_script, WEBKIT_TYPE_USER_CONTENT) >+ >+ >+static void webkit_user_script_class_init(WebKitUserScriptClass*) >+{ >+} >+ >+/** >+ * webkit_user_script_new: >+ * @source: JavaScript source code of the user script >+ * @injected_frames: A #WebKitUserContentInjectedFrames value >+ * @injection_time: A #WebKitUserScriptInjectionTime value >+ * @whitelist: (array zero-terminated=1) (allow-none): A whitelist of URI patterns or %NULL >+ * @blacklist: (array zero-terminated=1) (allow-none): A blacklist of URI patterns or %NULL >+ * >+ * Creates a new user script. Scripts can be applied to some URIs >+ * only by passing non-null values for @whitelist or @blacklist. Passing a >+ * %NULL whitelist implies that all URIs are on the whitelist. The script >+ * is applied if an URI matches the whitelist and not the blacklist. >+ * URI patterns must be of the form `[protocol]://[host]/[path]`, where the >+ * *host* and *path* components can contain the wildcard character (`*`) to >+ * represent zero or more other characters. >+ * >+ * Returns: (transfer full): A new #WebKitUserScript >+ */ >+WebKitUserScript* webkit_user_script_new(const gchar* source, WebKitUserContentInjectedFrames injectedFrames, >+ WebKitUserScriptInjectionTime injectionTime, const char* const* whitelist, const char* const* blacklist) >+{ >+ WebKitUserContent* userContent = WEBKIT_USER_CONTENT(g_object_new(WEBKIT_TYPE_USER_SCRIPT, nullptr)); >+ userContent->priv->type = UserContentScript; >+ userContent->priv->script = new UserScript(String::fromUTF8(source), URL { }, >+ toStringVector(whitelist), toStringVector(blacklist), >+ toUserScriptInjectionTime(injectionTime), >+ toUserContentInjectedFrames(injectedFrames)); >+ return WEBKIT_USER_SCRIPT(userContent); >+} >+ >+/** >+ * webkit_user_script_get_injection_time: >+ * @user_script: A #WebKitUserScript >+ * >+ * Returns: A #WebKitUserScriptInjectionTime value. >+ */ >+WebKitUserScriptInjectionTime webkit_user_script_get_injection_time(WebKitUserScript* userScript) >+{ >+ g_return_val_if_fail(WEBKIT_IS_USER_SCRIPT(userScript), WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END); >+ >+ WebKitUserContent* userContent = WEBKIT_USER_CONTENT(userScript); >+ g_return_val_if_fail(userContent->priv->type == UserContentScript, WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START); >+ >+ return toWebKitUserScriptInjectionTime(userContent->priv->script->injectionTime()); >+} >+ >+ >+struct _WebKitUserStyleSheetPrivate { >+}; >+ >+WEBKIT_DEFINE_TYPE(WebKitUserStyleSheet, webkit_user_style_sheet, WEBKIT_TYPE_USER_CONTENT) >+ >+ >+static void webkit_user_style_sheet_class_init(WebKitUserStyleSheetClass*) >+{ >+} >+ >+/** >+ * webkit_user_style_sheet_new: >+ * @source: Source code of the user style sheet. >+ * @injected_frames: A #WebKitUserContentInjectedFrames value >+ * @level: A #WebKitUserStyleLevel >+ * @whitelist: (array zero-terminated=1) (allow-none): A whitelist of URI patterns or %NULL >+ * @blacklist: (array zero-terminated=1) (allow-none): A blacklist of URI patterns or %NULL >+ * >+ * Creates a new user style sheet. Style sheets can be applied to some URIs >+ * only by passing non-null values for @whitelist or @blacklist. Passing a >+ * %NULL whitelist implies that all URIs are on the whitelist. The style >+ * sheet is applied if an URI matches the whitelist and not the blacklist. >+ * URI patterns must be of the form `[protocol]://[host]/[path]`, where the >+ * *host* and *path* components can contain the wildcard character (`*`) to >+ * represent zero or more other characters. >+ * >+ * Returns: (transfer full): A new #WebKitUserStyleSheet object >+ */ >+WebKitUserStyleSheet* webkit_user_style_sheet_new(const gchar* source, WebKitUserContentInjectedFrames injectedFrames, >+ WebKitUserStyleLevel level, const char* const* whitelist, const char* const* blacklist) >+{ >+ WebKitUserContent* userContent = WEBKIT_USER_CONTENT(g_object_new(WEBKIT_TYPE_USER_STYLE_SHEET, nullptr)); >+ userContent->priv->type = UserContentStyleSheet; >+ userContent->priv->styleSheet = new UserStyleSheet(String::fromUTF8(source), URL { }, >+ toStringVector(whitelist), toStringVector(blacklist), >+ toUserContentInjectedFrames(injectedFrames), >+ toUserStyleLevel(level)); >+ return WEBKIT_USER_STYLE_SHEET(userContent); >+} >+ >+/** >+ * webkit_user_style_sheet_get_level: >+ * @user_style_sheet: A #WebKitUserStyleSheet >+ * >+ * Returns: A #WebKitUserStyleLevel value. >+ */ >+WebKitUserStyleLevel webkit_user_style_sheet_get_level(WebKitUserStyleSheet* userStyleSheet) >+{ >+ g_return_val_if_fail(WEBKIT_IS_USER_STYLE_SHEET(userStyleSheet), WEBKIT_USER_STYLE_LEVEL_USER); >+ >+ WebKitUserContent* userContent = WEBKIT_USER_CONTENT(userStyleSheet); >+ g_return_val_if_fail(userContent->priv->type == UserContentStyleSheet, WEBKIT_USER_STYLE_LEVEL_USER); >+ >+ return toWebKitUserStyleLevel(userContent->priv->styleSheet->level()); >+} >+ >+ >+const UserScript& webkitWebKitUserScriptToUserScript(WebKitUserScript* userScript) >+{ >+ return *WEBKIT_USER_CONTENT(userScript)->priv->script; >+} >+ >+const UserStyleSheet& webkitWebKitUserStyleSheetToUserStyleSheet(WebKitUserStyleSheet* userStyleSheet) >+{ >+ return *WEBKIT_USER_CONTENT(userStyleSheet)->priv->styleSheet; >+} >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.h b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.h >new file mode 100644 >index 0000000000000000000000000000000000000000..ca68695dab2a6744ed5903b6a00356c90ee058b6 >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.h >@@ -0,0 +1,193 @@ >+/* >+ * Copyright (C) 2014 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. >+ */ >+ >+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) >+#error "Only <webkit2/webkit2.h> can be included directly." >+#endif >+ >+#ifndef WebKitUserContent_h >+#define WebKitUserContent_h >+ >+#include <glib-object.h> >+#include <webkit2/WebKitDefines.h> >+ >+G_BEGIN_DECLS >+ >+/** >+ * WebKitUserContentInjectedFrames: Specifies in which frames user >+ * scripts and user style sheets are to be inserted in. >+ * >+ * @WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES: Insert the user content >+ * (a script or style sheet) in all the frames loaded by the web >+ * view, including nested frames. This is the default. >+ * @WEBKIT_USER_CONTENT_INJECT_TOP_FRAME: Insert the user content >+ * (a script or style sheet) *only* in the top-level frame loaded >+ * by the web view, and *not* in the nested frames. >+ */ >+typedef enum { >+ WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, >+ WEBKIT_USER_CONTENT_INJECT_TOP_FRAME, >+} WebKitUserContentInjectedFrames; >+ >+#define WEBKIT_TYPE_USER_CONTENT (webkit_user_content_get_type()) >+#define WEBKIT_USER_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_USER_CONTENT, WebKitUserContent)) >+#define WEBKIT_IS_USER_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_USER_CONTENT)) >+#define WEBKIT_USER_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_USER_CONTENT, WebKitUserContentClass)) >+#define WEBKIT_IS_USER_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_USER_CONTENT)) >+#define WEBKIT_USER_CONTENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_USER_CONTENT, WebKitUserContentClass)) >+ >+typedef struct _WebKitUserContent WebKitUserContent; >+typedef struct _WebKitUserContentClass WebKitUserContentClass; >+typedef struct _WebKitUserContentPrivate WebKitUserContentPrivate; >+ >+ >+struct _WebKitUserContent { >+ GObject parent; >+ >+ /*< private >*/ >+ WebKitUserContentPrivate *priv; >+}; >+ >+struct _WebKitUserContentClass { >+ GObjectClass parent_class; >+}; >+ >+ >+WEBKIT_API GType >+webkit_user_content_get_type (void); >+ >+WEBKIT_API gchar * >+webkit_user_content_get_source (WebKitUserContent *user_content); >+ >+WEBKIT_API WebKitUserContentInjectedFrames >+webkit_user_content_get_injected_frames (WebKitUserContent *user_content); >+ >+WEBKIT_API gchar ** >+webkit_user_content_get_whitelist (WebKitUserContent *user_content); >+ >+WEBKIT_API gchar ** >+webkit_user_content_get_blacklist (WebKitUserContent *user_content); >+ >+ >+/** >+ * WebKitUserScriptInjectionTime: Specifies at which place user scripts >+ * are inserted. >+ * >+ * @WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START: Insert the code of the user >+ * script at the beginning of the loaded documents. This is the default. >+ * @WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END: Insert the code of the user >+ * script at the end of the loaded documents. >+ */ >+typedef enum { >+ WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START, >+ WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END, >+} WebKitUserScriptInjectionTime; >+ >+#define WEBKIT_TYPE_USER_SCRIPT (webkit_user_content_get_type()) >+#define WEBKIT_USER_SCRIPT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_USER_SCRIPT, WebKitUserScript)) >+#define WEBKIT_IS_USER_SCRIPT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_USER_SCRIPT)) >+#define WEBKIT_USER_SCRIPT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_USER_SCRIPT, WebKitUserScriptClass)) >+#define WEBKIT_IS_USER_SCRIPT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_USER_SCRIPT)) >+#define WEBKIT_USER_SCRIPT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_USER_SCRIPT, WebKitUserScriptClass)) >+ >+typedef struct _WebKitUserScript WebKitUserScript; >+typedef struct _WebKitUserScriptClass WebKitUserScriptClass; >+typedef struct _WebKitUserScriptPrivate WebKitUserScriptPrivate; >+ >+ >+struct _WebKitUserScript { >+ WebKitUserContent parent; >+ >+ /*< private >*/ >+ WebKitUserScriptPrivate *priv; >+}; >+ >+struct _WebKitUserScriptClass { >+ WebKitUserContentClass parent_class; >+}; >+ >+ >+WEBKIT_API GType >+webkit_user_script_get_type (void); >+ >+WEBKIT_API WebKitUserScript * >+webkit_user_script_new (const gchar *source, >+ WebKitUserContentInjectedFrames injected_frames, >+ WebKitUserScriptInjectionTime injection_time, >+ const gchar* const *whitelist, >+ const gchar* const *blacklist); >+ >+WEBKIT_API WebKitUserScriptInjectionTime >+webkit_user_script_get_injection_time (WebKitUserScript *user_script); >+ >+ >+/** >+ * WebKitUserStyleLevel: Specifies how to treat an user style sheet. >+ * >+ * @WEBKIT_USER_STYLE_LEVEL_USER: The style sheet is an user style sheet, >+ * its contents always override other style sheets. This is the default. >+ * @WEBKIT_USER_STYLE_LEVEL_AUTHOR: The style sheet will be treated as if >+ * it was provided by the loaded documents. That means other user style >+ * sheets may still override it. >+ */ >+typedef enum { >+ WEBKIT_USER_STYLE_LEVEL_USER, >+ WEBKIT_USER_STYLE_LEVEL_AUTHOR, >+} WebKitUserStyleLevel; >+ >+#define WEBKIT_TYPE_USER_STYLE_SHEET (webkit_user_content_get_type()) >+#define WEBKIT_USER_STYLE_SHEET(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_USER_STYLE_SHEET, WebKitUserStyleSheet)) >+#define WEBKIT_IS_USER_STYLE_SHEET(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_USER_STYLE_SHEET)) >+#define WEBKIT_USER_STYLE_SHEET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_USER_STYLE_SHEET, WebKitUserStyleSheetClass)) >+#define WEBKIT_IS_USER_STYLE_SHEET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_USER_STYLE_SHEET)) >+#define WEBKIT_USER_STYLE_SHEET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_USER_STYLE_SHEET, WebKitUserStyleSheetClass)) >+ >+typedef struct _WebKitUserStyleSheet WebKitUserStyleSheet; >+typedef struct _WebKitUserStyleSheetClass WebKitUserStyleSheetClass; >+typedef struct _WebKitUserStyleSheetPrivate WebKitUserStyleSheetPrivate; >+ >+ >+struct _WebKitUserStyleSheet { >+ WebKitUserContent parent; >+ >+ /*< private >*/ >+ WebKitUserStyleSheetPrivate *priv; >+}; >+ >+struct _WebKitUserStyleSheetClass { >+ WebKitUserContentClass parent_class; >+}; >+ >+ >+WEBKIT_API GType >+webkit_user_style_sheet_get_type (void); >+ >+WEBKIT_API WebKitUserStyleSheet * >+webkit_user_style_sheet_new (const gchar *source, >+ WebKitUserContentInjectedFrames injected_frames, >+ WebKitUserStyleLevel level, >+ const gchar* const *whitelist, >+ const gchar* const *blacklist); >+ >+WEBKIT_API WebKitUserStyleLevel >+webkit_user_style_sheet_get_level (WebKitUserStyleSheet *user_style_sheet); >+ >+G_END_DECLS >+ >+#endif >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..cd71a560cc5c12f76f1c855ba65989335eebb5bf >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.cpp >@@ -0,0 +1,271 @@ >+/* >+ * Copyright (C) 2014 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 "WebKitUserContentManager.h" >+ >+#include "WebKitJavascriptResult.h" >+#include "WebKitJavascriptResultPrivate.h" >+#include "WebKitPrivate.h" >+#include "WebKitUserContentManagerPrivate.h" >+#include "WebKitUserContentPrivate.h" >+#include "WebKitWebContextPrivate.h" >+#include "WebPageProxy.h" >+#include "WebScriptMessageHandler.h" >+#include "WebSerializedScriptValue.h" >+#include "WebUserContentControllerProxy.h" >+#include <WebCore/bindings/js/SerializedScriptValue.h> >+#include <WebCore/page/UserScript.h> >+#include <WebCore/page/UserStyleSheet.h> >+#include <wtf/gobject/GRefPtr.h> >+#include <wtf/text/CString.h> >+ >+using namespace WebCore; >+using namespace WebKit; >+ >+ >+struct _WebKitUserContentManagerPrivate { >+ _WebKitUserContentManagerPrivate() >+ : userContentController(WebUserContentControllerProxy::create()) { } >+ >+ RefPtr<WebUserContentControllerProxy> userContentController; >+}; >+ >+/** >+ * SECTION:WebKitUserContentManager >+ * @short_description: Manages user-defined content which affects web pages. >+ * @title: WebKitUserContentManager >+ * >+ * Using a #WebKitUserContentManager JavaScript user scripts and CSS >+ * style sheets can be set to be injected in the web pages loaded by a >+ * #WebKitWebView, by using webkit_user_content_manager_add_script() >+ * and webkit_user_content_manager_add_style_sheet(). Scripts can >+ * communicate back using script message handlers, which can be registered >+ * with webkit_user_content_manager_register_script_message_handler(). >+ * >+ * To use a #WebKitUserContentManager, it must be created using >+ * webkit_user_content_manager_new(), and then passed to >+ * webkit_web_view_new_with_user_content_manager(). User scripts and style >+ * sheets can be created with webkit_user_script_new() and >+ * webkit_user_style_sheet_new(), respectively. >+ * >+ * Scripts and user style sheets can be added and removed at any time, but >+ * they will affect the web pages loaded afterwards. Script message handlers >+ * can be registered at any time and they will be in effect immediately. >+ * >+ * Since: 2.6 >+ */ >+ >+WEBKIT_DEFINE_TYPE(WebKitUserContentManager, webkit_user_content_manager, G_TYPE_OBJECT) >+ >+ >+enum { >+ SCRIPT_MESSAGE_RECEIVED, >+ >+ LAST_SIGNAL >+}; >+ >+static guint signals[LAST_SIGNAL] = { 0, }; >+ >+ >+class ScriptMessageClientGtk final : public WebScriptMessageHandler::Client { >+public: >+ ScriptMessageClientGtk(const GRefPtr<WebKitUserContentManager>& manager, const gchar* handlerName) >+ : m_handlerName(g_quark_from_string(handlerName)) >+ , m_manager(manager) >+ { >+ } >+ >+ virtual void didPostMessage(WebPageProxy& page, WebFrameProxy&, WebCore::SerializedScriptValue& jsSerializedValue) >+ { >+ auto webView = webkitWebContextGetWebViewForPage(webkit_web_context_get_default(), &page); >+ auto jsValue = WebSerializedScriptValue::create(&jsSerializedValue); >+ auto jsResult = adoptGRef(webkitJavascriptResultCreate(webView, jsValue.get())); >+ g_signal_emit(m_manager.get(), signals[SCRIPT_MESSAGE_RECEIVED], m_handlerName, jsResult.get()); >+ } >+ >+ virtual ~ScriptMessageClientGtk() { } >+ >+private: >+ GQuark m_handlerName; >+ GRefPtr<WebKitUserContentManager> m_manager; >+}; >+ >+ >+static void webkit_user_content_manager_class_init(WebKitUserContentManagerClass *klass) >+{ >+ GObjectClass* gObjectClass = G_OBJECT_CLASS(klass); >+ >+ /** >+ * WebKitUserContentManager::script-message-received: >+ * @manager: the #WebKitUserContentManager >+ * @js_result: the #WebKitJavascriptResult holding the value received >+ * from the JavaScript world. >+ * >+ * This signal is emitted when JavaScript in a web view calls >+ * <code>window.webkit.<name>.postMessage()</code>, after registering >+ * <code><name></code> using >+ * webkit_user_content_manager_register_script_message_handler() >+ */ >+ signals[SCRIPT_MESSAGE_RECEIVED] = >+ g_signal_new( >+ "script-message-received", >+ G_TYPE_FROM_CLASS(gObjectClass), >+ static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED), >+ 0, nullptr, nullptr, >+ g_cclosure_marshal_VOID__BOXED, >+ G_TYPE_NONE, 1, >+ WEBKIT_TYPE_JAVASCRIPT_RESULT); >+} >+ >+/** >+ * webkit_user_content_manager_new: >+ * >+ * Creates a new user content manager. >+ * >+ * Returns: (transfer none): a #WebKitUserContentManager >+ */ >+WebKitUserContentManager* webkit_user_content_manager_get_default(void) >+{ >+ return WEBKIT_USER_CONTENT_MANAGER(g_object_new(WEBKIT_TYPE_USER_CONTENT_MANAGER, nullptr)); >+} >+ >+/** >+ * webkit_user_content_manager_add_script: >+ * @manager: A #WebKitUserContentManager >+ * @script: A #WebKitUserScript >+ * >+ * Adds a script to an user content manager. The same #WebKitUserScript can >+ * be reused with multiple managers. >+ */ >+void >+webkit_user_content_manager_add_script(WebKitUserContentManager* manager, WebKitUserScript* script) >+{ >+ g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); >+ g_return_if_fail(WEBKIT_IS_USER_SCRIPT(script)); >+ manager->priv->userContentController->addUserScript(webkitWebKitUserScriptToUserScript(script)); >+} >+ >+/** >+ * webkit_user_content_manager_remove_all_scripts: >+ * @manager: A #WebKitUserContentManager >+ * >+ * Removes all user scripts from the user content manager. >+ */ >+void >+webkit_user_content_manager_remove_all_scripts(WebKitUserContentManager* manager) >+{ >+ g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); >+ manager->priv->userContentController->removeAllUserScripts(); >+} >+ >+/** >+ * webkit_user_content_manager_add_style_sheet: >+ * @manager: A #WebKitUserContentManager >+ * @stylesheet: A #WebKitUserStyleSheet >+ * >+ * Adds a script to an user content manager. The same #WebKitUserScript can >+ * be reused with multiple managers. >+ */ >+void >+webkit_user_content_manager_add_style_sheet(WebKitUserContentManager* manager, WebKitUserStyleSheet* stylesheet) >+{ >+ g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); >+ g_return_if_fail(WEBKIT_IS_USER_STYLE_SHEET(stylesheet)); >+ manager->priv->userContentController->addUserStyleSheet(webkitWebKitUserStyleSheetToUserStyleSheet(stylesheet)); >+} >+ >+/** >+ * webkit_user_content_manager_remove_all_style_sheets: >+ * @manager: A #WebKitUserContentManager >+ * >+ * Removes all user style sheets from the user content manager. >+ */ >+void >+webkit_user_content_manager_remove_all_style_sheets(WebKitUserContentManager* manager) >+{ >+ g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); >+ manager->priv->userContentController->removeAllUserStyleSheets(); >+} >+ >+ >+/** >+ * webkit_user_content_manager_register_script_message_handler: >+ * @manager: A #WebKitUserContentManager >+ * @name: Name of the script message channel >+ * >+ * Registers a new user script message handler name. After it is >+ * registered, scripts can use `window.webkit.<name>.postMessage(value)` >+ * to send messages. Those messages are received by connecting handlers >+ * to the WebKitUserContentManager::script-message-received signal. The >+ * handler name is used as the detail of the signal. To avoid race >+ * conditions between registering the handler name, and starting to >+ * receive the signals, it is recommended to connect to the signal >+ * *before* registering the handler name: >+ * >+ * <informalexample><programlisting> >+ * WebKitWebView *view = webkit_web_view_new (); >+ * WebKitUserContentManager *manager = webkit_web_view_get_user_content_manager (); >+ * g_signal_connect (manager, "script-message-received::foobar", >+ * G_CALLBACK (handle_script_message), NULL); >+ * webkit_user_content_manager_register_script_message_handler (manager, "foobar"); >+ * </programlisting></informalexample> >+ * >+ * Registering a script message handler will fail if the requested >+ * name has been already registered before. >+ * >+ * Returns: Whether the message channel was registered successfully. >+ */ >+gboolean webkit_user_content_manager_register_script_message_handler(WebKitUserContentManager* manager, const gchar* name) >+{ >+ g_return_val_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager), FALSE); >+ g_return_val_if_fail(name != nullptr, FALSE); >+ >+ const auto handler_name = String::fromUTF8(name); >+ auto handler = WebScriptMessageHandler::create(std::make_unique<ScriptMessageClientGtk>(manager, name), handler_name); >+ return manager->priv->userContentController->addUserScriptMessageHandler(handler.get()); >+} >+ >+/** >+ * webkit_user_content_manager_unregister_script_message_handler: >+ * @manager: A #WebKitUserContentManager >+ * @name: Name of the script message channel >+ * >+ * Unregisters a previously registered message handler name. >+ * >+ * Note that this does *not* disconnect handlers for the >+ * WebKitUserContentManager::script-message-received signal: >+ * the signal handlers will be kept connected, but the signal >+ * will not be emitted unless the handler name is registered >+ * again. >+ * >+ * See: webkit_user_content_manager_register_script_message_handler() >+ */ >+void webkit_user_content_manager_unregister_script_message_handler(WebKitUserContentManager* manager, const gchar* name) >+{ >+ g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); >+ manager->priv->userContentController->removeUserMessageHandlerForName(String::fromUTF8(name)); >+} >+ >+ >+WebUserContentControllerProxy* webkitUserContentManagerGetUserContentControllerProxy(WebKitUserContentManager* manager) >+{ >+ g_return_val_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager), nullptr); >+ return manager->priv->userContentController.get(); >+} >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.h b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.h >new file mode 100644 >index 0000000000000000000000000000000000000000..a383511395983b8b44a739706b003e2b067d9d7d >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.h >@@ -0,0 +1,90 @@ >+/* >+ * Copyright (C) 2014 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. >+ */ >+ >+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) >+#error "Only <webkit2/webkit2.h> can be included directly." >+#endif >+ >+#ifndef WebKitUserContentManager_h >+#define WebKitUserContentManager_h >+ >+#include <glib-object.h> >+#include <webkit2/WebKitDefines.h> >+#include <webkit2/WebKitUserContent.h> >+ >+G_BEGIN_DECLS >+ >+#define WEBKIT_TYPE_USER_CONTENT_MANAGER (webkit_user_content_manager_get_type()) >+#define WEBKIT_USER_CONTENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_USER_CONTENT_MANAGER, WebKitUserContentManager)) >+#define WEBKIT_IS_USER_CONTENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_USER_CONTENT_MANAGER)) >+#define WEBKIT_USER_CONTENT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_USER_CONTENT_MANAGER, WebKitUserContentManagerClass)) >+#define WEBKIT_IS_USER_CONTENT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_USER_CONTENT_MANAGER)) >+#define WEBKIT_USER_CONTENT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_USER_CONTENT_MANAGER, WebKitUserContentManagerClass)) >+ >+typedef struct _WebKitUserContentManager WebKitUserContentManager; >+typedef struct _WebKitUserContentManagerClass WebKitUserContentManagerClass; >+typedef struct _WebKitUserContentManagerPrivate WebKitUserContentManagerPrivate; >+ >+ >+struct _WebKitUserContentManager { >+ GObject parent; >+ >+ /*< private >*/ >+ WebKitUserContentManagerPrivate *priv; >+}; >+ >+struct _WebKitUserContentManagerClass { >+ GObjectClass parent_class; >+ >+ void (*_webkit_reserved0) (void); >+ void (*_webkit_reserved1) (void); >+ void (*_webkit_reserved2) (void); >+ void (*_webkit_reserved3) (void); >+}; >+ >+ >+WEBKIT_API GType >+webkit_user_content_manager_get_type (void); >+ >+WEBKIT_API WebKitUserContentManager * >+webkit_user_content_manager_new (void); >+ >+WEBKIT_API void >+webkit_user_content_manager_add_script (WebKitUserContentManager *manager, >+ WebKitUserScript *script); >+WEBKIT_API void >+webkit_user_content_manager_remove_all_scripts (WebKitUserContentManager *manager); >+ >+WEBKIT_API void >+webkit_user_content_manager_add_style_sheet (WebKitUserContentManager *manager, >+ WebKitUserStyleSheet *stylesheet); >+WEBKIT_API void >+webkit_user_content_manager_remove_all_style_sheets (WebKitUserContentManager *manager); >+ >+WEBKIT_API gboolean >+webkit_user_content_manager_register_script_message_handler (WebKitUserContentManager *manager, >+ const gchar *name); >+ >+WEBKIT_API void >+webkit_user_content_manager_unregister_script_message_handler (WebKitUserContentManager *manager, >+ const gchar *name); >+ >+G_END_DECLS >+ >+#endif >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManagerPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManagerPrivate.h >new file mode 100644 >index 0000000000000000000000000000000000000000..d00253aa4d2635a50ff5471f18a757767e11c12e >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManagerPrivate.h >@@ -0,0 +1,31 @@ >+/* >+ * Copyright (C) 2014 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. >+ */ >+ >+#ifndef WebKitUserContentManagerPrivate_h >+#define WebKitUserContentManagerPrivate_h >+ >+#include "WebKitUserContentManager.h" >+ >+namespace WebKit { >+class WebUserContentControllerProxy; >+}; >+ >+WebKit::WebUserContentControllerProxy* webkitUserContentManagerGetUserContentControllerProxy(WebKitUserContentManager*); >+ >+#endif // WebKitUserContentManagerPrivate_h >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentPrivate.h >new file mode 100644 >index 0000000000000000000000000000000000000000..ffad72f78e9aa3cbfdb0f1c4cc64171a318a44d2 >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentPrivate.h >@@ -0,0 +1,33 @@ >+/* >+ * Copyright (C) 2014 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. >+ */ >+ >+#ifndef WebKitUserContentPrivate_h >+#define WebKitUserContentPrivate_h >+ >+#include "WebKitUserContent.h" >+ >+namespace WebCore { >+class UserScript; >+class UserStyleSheet; >+}; >+ >+const WebCore::UserScript& webkitWebKitUserScriptToUserScript(WebKitUserScript*); >+const WebCore::UserStyleSheet& webkitWebKitUserStyleSheetToUserStyleSheet(WebKitUserStyleSheet*); >+ >+#endif // WebKitUserContentPrivate_h >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp >index 62808b76cef86da7233b1d0262a2ecc44c1f3272..bdf58a4936ac3566fca4c7fe38dab396f8865d10 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp >@@ -39,6 +39,8 @@ > #include "WebKitSecurityManagerPrivate.h" > #include "WebKitTextChecker.h" > #include "WebKitURISchemeRequestPrivate.h" >+#include "WebKitUserContentManager.h" >+#include "WebKitUserContentManagerPrivate.h" > #include "WebKitWebContextPrivate.h" > #include "WebKitWebViewBasePrivate.h" > #include "WebKitWebViewGroupPrivate.h" >@@ -1050,12 +1052,13 @@ void webkitWebContextDidFinishLoadingCustomProtocol(WebKitWebContext* context, u > context->priv->uriSchemeRequests.remove(customProtocolID); > } > >-void webkitWebContextCreatePageForWebView(WebKitWebContext* context, WebKitWebView* webView, WebKitWebViewGroup* webViewGroup, WebKitWebView* relatedView) >+void webkitWebContextCreatePageForWebView(WebKitWebContext* context, WebKitWebView* webView, WebKitWebViewGroup* webViewGroup, WebKitUserContentManager* userContentManager, WebKitWebView* relatedView) > { > WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(webView); > WebPageGroup* pageGroup = webViewGroup ? webkitWebViewGroupGetPageGroup(webViewGroup) : 0; > WebPageProxy* relatedPage = relatedView ? webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(relatedView)) : nullptr; >- webkitWebViewBaseCreateWebPage(webViewBase, context->priv->context.get(), pageGroup, relatedPage); >+ WebUserContentControllerProxy* userContentControllerProxy = userContentManager ? webkitUserContentManagerGetUserContentControllerProxy(userContentManager) : nullptr; >+ webkitWebViewBaseCreateWebPage(webViewBase, context->priv->context.get(), pageGroup, userContentControllerProxy, relatedPage); > > WebPageProxy* page = webkitWebViewBaseGetPage(webViewBase); > context->priv->webViews.set(page->pageID(), webView); >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h >index 06474a1ef0ab324240be2f11130414fb229e3e14..76dcd36586ca4c39608b160ea0a345f6dd3901a5 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h >@@ -29,6 +29,7 @@ > #include "DownloadProxy.h" > #include "WebContext.h" > #include "WebKitPrivate.h" >+#include "WebKitUserContentManager.h" > #include "WebKitWebContext.h" > #include "WebKitWebViewGroup.h" > #include "WebSoupCustomProtocolRequestManager.h" >@@ -42,7 +43,7 @@ WebKit::WebSoupCustomProtocolRequestManager* webkitWebContextGetRequestManager(W > void webkitWebContextStartLoadingCustomProtocol(WebKitWebContext*, uint64_t customProtocolID, API::URLRequest*); > void webkitWebContextStopLoadingCustomProtocol(WebKitWebContext*, uint64_t customProtocolID); > void webkitWebContextDidFinishLoadingCustomProtocol(WebKitWebContext*, uint64_t customProtocolID); >-void webkitWebContextCreatePageForWebView(WebKitWebContext*, WebKitWebView*, WebKitWebViewGroup*, WebKitWebView*); >+void webkitWebContextCreatePageForWebView(WebKitWebContext*, WebKitWebView*, WebKitWebViewGroup*, WebKitUserContentManager*, WebKitWebView*); > void webkitWebContextWebViewDestroyed(WebKitWebContext*, WebKitWebView*); > WebKitWebView* webkitWebContextGetWebViewForPage(WebKitWebContext*, WebKit::WebPageProxy*); > WebKitWebViewGroup* webkitWebContextGetDefaultWebViewGroup(WebKitWebContext*); >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp >index 4f88a0b1729ab8eaec591a3cc1c77a6fa6b463ef..1c2685ad80d9f4d4f656568932b098405a68131e 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp >@@ -133,6 +133,7 @@ enum { > PROP_WEB_CONTEXT, > PROP_RELATED_VIEW, > PROP_GROUP, >+ PROP_USER_CONTENT_MANAGER, > PROP_TITLE, > PROP_ESTIMATED_LOAD_PROGRESS, > PROP_FAVICON, >@@ -171,6 +172,7 @@ struct _WebKitWebViewPrivate { > GRefPtr<WebKitSettings> settings; > unsigned long settingsChangedHandlerID; > GRefPtr<WebKitWebViewGroup> group; >+ GRefPtr<WebKitUserContentManager> userContentManager; > GRefPtr<WebKitWindowProperties> windowProperties; > > GRefPtr<GMainLoop> modalLoop; >@@ -501,7 +503,7 @@ static void webkitWebViewConstructed(GObject* object) > > WebKitWebView* webView = WEBKIT_WEB_VIEW(object); > WebKitWebViewPrivate* priv = webView->priv; >- webkitWebContextCreatePageForWebView(priv->context, webView, priv->group.get(), priv->relatedView); >+ webkitWebContextCreatePageForWebView(priv->context, webView, priv->group.get(), priv->userContentManager.get(), priv->relatedView); > // The related view is only valid during the construction. > priv->relatedView = nullptr; > >@@ -542,6 +544,11 @@ static void webkitWebViewSetProperty(GObject* object, guint propId, const GValue > webView->priv->group = group ? WEBKIT_WEB_VIEW_GROUP(group) : 0; > break; > } >+ case PROP_USER_CONTENT_MANAGER: { >+ gpointer userContentManager = g_value_get_object(value); >+ webView->priv->userContentManager = userContentManager ? WEBKIT_USER_CONTENT_MANAGER(userContentManager) : nullptr; >+ break; >+ } > case PROP_ZOOM_LEVEL: > webkit_web_view_set_zoom_level(webView, g_value_get_double(value)); > break; >@@ -561,6 +568,9 @@ static void webkitWebViewGetProperty(GObject* object, guint propId, GValue* valu > case PROP_GROUP: > g_value_set_object(value, webkit_web_view_get_group(webView)); > break; >+ case PROP_USER_CONTENT_MANAGER: >+ g_value_set_object(value, webkit_web_view_get_user_content_manager(webView)); >+ break; > case PROP_TITLE: > g_value_set_string(value, webView->priv->title.data()); > break; >@@ -671,6 +681,21 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) > static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); > > /** >+ * WebKitWebView:user-content-manager: >+ * >+ * The #WebKitUserContentManager of the view. >+ */ >+ g_object_class_install_property( >+ gObjectClass, >+ PROP_USER_CONTENT_MANAGER, >+ g_param_spec_object( >+ "user-content-manager", >+ _("WebView user content manager"), >+ _("The WebKitUserContentManager of the view"), >+ WEBKIT_TYPE_USER_CONTENT_MANAGER, >+ static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); >+ >+ /** > * WebKitWebView:title: > * > * The main frame document title of this #WebKitWebView. If >@@ -1907,6 +1932,8 @@ GtkWidget* webkit_web_view_new_with_context(WebKitWebContext* context) > * You can also use this method to implement other process models based on %WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES, > * like for example, sharing the same web process for all the views in the same security domain. > * >+ * The newly created #WebKitWebView will also have the same #WebKitUserContentManager as @web_view. >+ * > * Returns: (transfer full): The newly created #WebKitWebView widget > * > * Since: 2.4 >@@ -1915,7 +1942,10 @@ GtkWidget* webkit_web_view_new_with_related_view(WebKitWebView* webView) > { > g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), nullptr); > >- return GTK_WIDGET(g_object_new(WEBKIT_TYPE_WEB_VIEW, "related-view", webView, nullptr)); >+ return GTK_WIDGET(g_object_new(WEBKIT_TYPE_WEB_VIEW, >+ "user-content-manager", webView->priv->userContentManager.get(), >+ "related-view", webView, >+ nullptr)); > } > > /** >@@ -1936,6 +1966,19 @@ GtkWidget* webkit_web_view_new_with_group(WebKitWebViewGroup* group) > } > > /** >+ * webkit_web_view_new_with_user_content_manager: >+ * @user_content_manager: a #WebKitUserContentManager. >+ * >+ * Returns: The newly created #WebKitWebView widget. >+ */ >+GtkWidget* webkit_web_view_new_with_user_content_manager(WebKitUserContentManager* userContentManager) >+{ >+ g_return_val_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(userContentManager), nullptr); >+ >+ return GTK_WIDGET(g_object_new(WEBKIT_TYPE_WEB_VIEW, "user-content-manager", userContentManager, nullptr)); >+} >+ >+/** > * webkit_web_view_get_context: > * @web_view: a #WebKitWebView > * >@@ -1969,6 +2012,23 @@ WebKitWebViewGroup* webkit_web_view_get_group(WebKitWebView* webView) > } > > /** >+ * webkit_web_view_get_user_content_manager: >+ * @web_view: a #WebKitWebView >+ * >+ * Gets the user content manager associated to @web_view. >+ * >+ * Returns: (transfer none): the #WebKitUserContentManager associated with >+ * the view >+ * Since: 2.6 >+ */ >+WebKitUserContentManager* webkit_web_view_get_user_content_manager(WebKitWebView* webView) >+{ >+ g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), nullptr); >+ >+ return webView->priv->userContentManager.get(); >+} >+ >+/** > * webkit_web_view_load_uri: > * @web_view: a #WebKitWebView > * @uri: an URI string >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h >index 980f458e747f40db77ac12e8e90b7336b4b8e53f..68356cfb365218e0aaea467c82765690ba1f5091 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h >@@ -43,6 +43,7 @@ > #include <webkit2/WebKitScriptDialog.h> > #include <webkit2/WebKitSettings.h> > #include <webkit2/WebKitURIRequest.h> >+#include <webkit2/WebKitUserContentManager.h> > #include <webkit2/WebKitWebContext.h> > #include <webkit2/WebKitWebInspector.h> > #include <webkit2/WebKitWebResource.h> >@@ -258,6 +259,9 @@ webkit_web_view_new_with_related_view (WebKitWebView > WEBKIT_API GtkWidget * > webkit_web_view_new_with_group (WebKitWebViewGroup *group); > >+WEBKIT_API GtkWidget * >+webkit_web_view_new_with_user_content_manager (WebKitUserContentManager *user_content_manager); >+ > WEBKIT_API WebKitWebContext * > webkit_web_view_get_context (WebKitWebView *web_view); > >@@ -453,6 +457,10 @@ WEBKIT_API cairo_surface_t * > webkit_web_view_get_snapshot_finish (WebKitWebView *web_view, > GAsyncResult *result, > GError **error); >+ >+WEBKIT_API WebKitUserContentManager * >+webkit_web_view_get_user_content_manager (WebKitWebView *web_view); >+ > G_END_DECLS > > #endif >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp >index 71c7ce5ad2b0297d3c4e1336471a5ad1105f3918..98dffd99db3542298963d6c58885a636c7b81b03 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp >@@ -45,6 +45,7 @@ > #include "WebPageGroup.h" > #include "WebPageProxy.h" > #include "WebPreferences.h" >+#include "WebUserContentControllerProxy.h" > #include "WebViewBaseInputMethodFilter.h" > #include <WebCore/CairoUtilities.h> > #include <WebCore/ClipboardUtilitiesGtk.h> >@@ -941,10 +942,10 @@ static void webkit_web_view_base_class_init(WebKitWebViewBaseClass* webkitWebVie > containerClass->forall = webkitWebViewBaseContainerForall; > } > >-WebKitWebViewBase* webkitWebViewBaseCreate(WebContext* context, WebPageGroup* pageGroup, WebPageProxy* relatedPage) >+WebKitWebViewBase* webkitWebViewBaseCreate(WebContext* context, WebPageGroup* pageGroup, WebUserContentControllerProxy* userContentController, WebPageProxy* relatedPage) > { > WebKitWebViewBase* webkitWebViewBase = WEBKIT_WEB_VIEW_BASE(g_object_new(WEBKIT_TYPE_WEB_VIEW_BASE, NULL)); >- webkitWebViewBaseCreateWebPage(webkitWebViewBase, context, pageGroup, relatedPage); >+ webkitWebViewBaseCreateWebPage(webkitWebViewBase, context, pageGroup, userContentController, relatedPage); > return webkitWebViewBase; > } > >@@ -977,13 +978,14 @@ static void deviceScaleFactorChanged(WebKitWebViewBase* webkitWebViewBase) > } > #endif // HAVE(GTK_SCALE_FACTOR) > >-void webkitWebViewBaseCreateWebPage(WebKitWebViewBase* webkitWebViewBase, WebContext* context, WebPageGroup* pageGroup, WebPageProxy* relatedPage) >+void webkitWebViewBaseCreateWebPage(WebKitWebViewBase* webkitWebViewBase, WebContext* context, WebPageGroup* pageGroup, WebUserContentControllerProxy* userContentController, WebPageProxy* relatedPage) > { > WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv; > > WebPageConfiguration webPageConfiguration; > webPageConfiguration.pageGroup = pageGroup; > webPageConfiguration.relatedPage = relatedPage; >+ webPageConfiguration.userContentController = userContentController; > priv->pageProxy = context->createWebPage(*priv->pageClient, std::move(webPageConfiguration)); > priv->pageProxy->initializeWebPage(); > >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h >index b9c38c2658524b56aeefa2ee3d55a8e8af9d33e4..dfe2285e9a7aa76feb34ee7a98f9362bf02bc5c2 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h >@@ -34,10 +34,10 @@ > #include "WebKitWebViewBase.h" > #include "WebPageProxy.h" > >-WebKitWebViewBase* webkitWebViewBaseCreate(WebKit::WebContext*, WebKit::WebPageGroup*, WebKit::WebPageProxy*); >+WebKitWebViewBase* webkitWebViewBaseCreate(WebKit::WebContext*, WebKit::WebPageGroup*, WebKit::WebUserContentControllerProxy*, WebKit::WebPageProxy*); > GtkIMContext* webkitWebViewBaseGetIMContext(WebKitWebViewBase*); > WebKit::WebPageProxy* webkitWebViewBaseGetPage(WebKitWebViewBase*); >-void webkitWebViewBaseCreateWebPage(WebKitWebViewBase*, WebKit::WebContext*, WebKit::WebPageGroup*, WebKit::WebPageProxy*); >+void webkitWebViewBaseCreateWebPage(WebKitWebViewBase*, WebKit::WebContext*, WebKit::WebPageGroup*, WebKit::WebUserContentControllerProxy*, WebKit::WebPageProxy*); > void webkitWebViewBaseSetTooltipText(WebKitWebViewBase*, const char*); > void webkitWebViewBaseSetTooltipArea(WebKitWebViewBase*, const WebCore::IntRect&); > void webkitWebViewBaseForwardNextKeyEvent(WebKitWebViewBase*); >diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt >index 47b864e4091581d71c63643cbe07102c0adbe2a4..652a17a48736c5bfa2d7ee58b57d3b3d9d419d31 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt >+++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt >@@ -73,6 +73,89 @@ webkit_web_context_get_type > </SECTION> > > <SECTION> >+<FILE>WebKitUserContent</FILE> >+<TITLE>WebKitUserContent</TITLE> >+WebKitUserContent >+WebKitUserScript >+WebKitUserStyleSheet >+WebKitUserContentInjectedFrames >+WebKitUserScriptInjectionTime >+WebKitUserStyleLevel >+webkit_user_content_get_injected_frames >+webkit_user_content_set_injected_frames >+webkit_user_content_get_source >+webkit_user_content_set_source >+webkit_user_content_get_blacklist >+webkit_user_content_set_blacklist >+webkit_user_content_get_whitelist >+webkit_user_content_set_whitelist >+webkit_user_script_new >+webkit_user_script_get_injection_time >+webkit_user_script_set_injection_time >+webkit_user_style_sheet_new >+webkit_user_style_sheet_get_level >+webkit_user_style_sheet_set_level >+ >+<SUBSECTION Standard> >+WebKitUserContentClass >+WEBKIT_USER_CONTENT >+WEBKIT_IS_USER_CONTENT >+WEBKIT_TYPE_USER_CONTENT >+WEBKIT_USER_CONTENT_CLASS >+WEBKIT_IS_USER_CONTENT_CLASS >+WEBKIT_USER_CONTENT_GET_CLASS >+WebKitUserScriptClass >+WEBKIT_USER_SCRIPT >+WEBKIT_IS_USER_SCRIPT >+WEBKIT_TYPE_USER_SCRIPT >+WEBKIT_USER_SCRIPT_CLASS >+WEBKIT_IS_USER_SCRIPT_CLASS >+WEBKIT_USER_SCRIPT_GET_CLASS >+WebKitUserStyleSheetClass >+WEBKIT_USER_STYLE_SHEET >+WEBKIT_IS_USER_STYLE_SHEET >+WEBKIT_TYPE_USER_STYLE_SHEET >+WEBKIT_USER_STYLE_SHEET_CLASS >+WEBKIT_IS_USER_STYLE_SHEET_CLASS >+WEBKIT_USER_STYLE_SHEET_GET_CLASS >+ >+<SUBSECTION Private> >+WebKitUserContentPrivate >+WebKitUserScriptPrivate >+WebKitUserStyleSheetPrivate >+webkit_user_content_get_type >+webkit_user_script_get_type >+webkit_user_style_sheet_get_type >+</SECTION> >+ >+<SECTION> >+<FILE>WebKitUserContentManager</FILE> >+<TITLE>WebKitUserContentManager</TITLE> >+WebKitUserContentManager >+webkit_user_content_manager_get_default >+webkit_user_content_manager_add_script >+webkit_user_content_manager_remove_all_scripts >+webkit_user_content_manager_add_style_sheet >+webkit_user_content_manager_remove_all_style_sheets >+webkit_user_content_manager_register_script_message_handler_name >+webkit_user_content_manager_unregister_script_message_handler_name >+ >+<SUBSECTION Standard> >+WEBKIT_IS_USER_CONTENT_MANAGER >+WEBKIT_IS_USER_CONTENT_MANAGER_CLASS >+WEBKIT_TYPE_USER_CONTENT_MANAGER >+WEBKIT_USER_CONTENT_MANAGER >+WEBKIT_USER_CONTENT_MANAGER_CLASS >+WEBKIT_USER_CONTENT_MANAGER_GET_CLASS >+WebKitUserContentManagerClass >+ >+<SUBSECTION Private> >+WebKitUserContentManagerPrivate >+webkit_user_content_manager_get_type >+ >+</SECTION> >+ >+<SECTION> > <FILE>WebKitWebView</FILE> > <TITLE>WebKitWebView</TITLE> > WebKitWebView >diff --git a/Source/WebKit2/UIProcess/API/gtk/webkit2.h b/Source/WebKit2/UIProcess/API/gtk/webkit2.h >index c18538a63111040e46bb282f0680bd3bc2f564e8..23d0bb87a08cd4b6991a360ccf42c3722ae37e04 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/webkit2.h >+++ b/Source/WebKit2/UIProcess/API/gtk/webkit2.h >@@ -60,6 +60,8 @@ > #include <webkit2/WebKitURIRequest.h> > #include <webkit2/WebKitURIResponse.h> > #include <webkit2/WebKitURISchemeRequest.h> >+#include <webkit2/WebKitUserContent.h> >+#include <webkit2/WebKitUserContentManager.h> > #include <webkit2/WebKitVersion.h> > #include <webkit2/WebKitWebContext.h> > #include <webkit2/WebKitWebInspector.h> >diff --git a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp >index f0dd6c792403c89ac881988b3b29d3c5630be5c5..7105fa471393f13451c6a97aa0bc4f8fdd55591d 100644 >--- a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp >+++ b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp >@@ -97,6 +97,22 @@ void WebUserContentControllerProxy::removeAllUserScripts() > processAndCount.key->connection()->send(Messages::WebUserContentController::RemoveAllUserScripts(), m_identifier); > } > >+void WebUserContentControllerProxy::addUserStyleSheet(WebCore::UserStyleSheet userStyleSheet) >+{ >+ m_userStyleSheets.append(std::move(userStyleSheet)); >+ >+ for (auto& processAndCount : m_processes) >+ processAndCount.key->connection()->send(Messages::WebUserContentController::AddUserStyleSheets({ m_userStyleSheets.last() }), m_identifier); >+} >+ >+void WebUserContentControllerProxy::removeAllUserStyleSheets() >+{ >+ m_userStyleSheets.clear(); >+ >+ for (auto& processAndCount : m_processes) >+ processAndCount.key->connection()->send(Messages::WebUserContentController::RemoveAllUserStyleSheets(), m_identifier); >+} >+ > bool WebUserContentControllerProxy::addUserScriptMessageHandler(WebScriptMessageHandler* handler) > { > for (auto& existingHandler : m_scriptMessageHandlers.values()) { >diff --git a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h >index cff6f29d4864e0a76849ffaf2ea0449d74db0849..7dc0595aa2b7c2de82bfc08334a173c6b941daae 100644 >--- a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h >+++ b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h >@@ -39,6 +39,7 @@ class DataReference; > > namespace WebCore { > class UserScript; >+class UserStyleSheet; > } > > namespace WebKit { >@@ -59,6 +60,9 @@ public: > void addUserScript(WebCore::UserScript); > void removeAllUserScripts(); > >+ void addUserStyleSheet(WebCore::UserStyleSheet); >+ void removeAllUserStyleSheets(); >+ > // Returns false if there was a name conflict. > bool addUserScriptMessageHandler(WebScriptMessageHandler*); > void removeUserMessageHandlerForName(const String&); >@@ -75,6 +79,7 @@ private: > HashCountedSet<WebProcessProxy*> m_processes; > > Vector<WebCore::UserScript> m_userScripts; >+ Vector<WebCore::UserStyleSheet> m_userStyleSheets; > HashMap<uint64_t, RefPtr<WebScriptMessageHandler>> m_scriptMessageHandlers; > }; > >diff --git a/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp >index 579b099f84d2068717350d2264e7f9085142a743..1eda7e8efe86dca15c873b1328f0a196a649ea0a 100644 >--- a/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp >+++ b/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp >@@ -62,7 +62,7 @@ WebPageProxy* WebInspectorProxy::platformCreateInspectorPage() > { > ASSERT(m_page); > ASSERT(!m_inspectorView); >- m_inspectorView = GTK_WIDGET(webkitWebViewBaseCreate(&page()->process().context(), inspectorPageGroup(), m_page)); >+ m_inspectorView = GTK_WIDGET(webkitWebViewBaseCreate(&page()->process().context(), inspectorPageGroup(), nullptr, m_page)); > g_object_add_weak_pointer(G_OBJECT(m_inspectorView), reinterpret_cast<void**>(&m_inspectorView)); > return webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_inspectorView)); > } >diff --git a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.cpp b/Source/WebKit2/WebProcess/UserContent/WebUserContentController.cpp >index d9dc15c58455b908927546f066d8295d1353f692..24f214815a43cdb110ef50a470925b5d445bc9fc 100644 >--- a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.cpp >+++ b/Source/WebKit2/WebProcess/UserContent/WebUserContentController.cpp >@@ -35,6 +35,7 @@ > #include <WebCore/DOMWrapperWorld.h> > #include <WebCore/ScriptController.h> > #include <WebCore/SerializedScriptValue.h> >+#include <WebCore/UserStyleSheet.h> > #include <wtf/NeverDestroyed.h> > > #if ENABLE(USER_MESSAGE_HANDLERS) >@@ -92,6 +93,19 @@ void WebUserContentController::removeAllUserScripts() > m_userContentController->removeUserScripts(mainThreadNormalWorld()); > } > >+void WebUserContentController::addUserStyleSheets(const Vector<WebCore::UserStyleSheet>& userStyleSheets) >+{ >+ for (const auto& userStyleSheet : userStyleSheets) { >+ m_userContentController->addUserStyleSheet(mainThreadNormalWorld(), >+ std::make_unique<WebCore::UserStyleSheet>(userStyleSheet), InjectInExistingDocuments); >+ } >+} >+ >+void WebUserContentController::removeAllUserStyleSheets() >+{ >+ m_userContentController->removeUserStyleSheets(mainThreadNormalWorld()); >+} >+ > #if ENABLE(USER_MESSAGE_HANDLERS) > class WebUserMessageHandlerDescriptorProxy : public RefCounted<WebUserMessageHandlerDescriptorProxy>, public WebCore::UserMessageHandlerDescriptor::Client { > public: >diff --git a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.h b/Source/WebKit2/WebProcess/UserContent/WebUserContentController.h >index 4c8469964cffd0f69a9c67eafadfd05efa556997..639c20e000aed798c2b73cd1f04cfb6c2b5d64f6 100644 >--- a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.h >+++ b/Source/WebKit2/WebProcess/UserContent/WebUserContentController.h >@@ -54,6 +54,9 @@ private: > void addUserScripts(const Vector<WebCore::UserScript>& userScripts); > void removeAllUserScripts(); > >+ void addUserStyleSheets(const Vector<WebCore::UserStyleSheet>& userStyleSheets); >+ void removeAllUserStyleSheets(); >+ > void addUserScriptMessageHandlers(const Vector<WebScriptMessageHandlerHandle>& scriptMessageHandlers); > void removeUserScriptMessageHandler(uint64_t); > >diff --git a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.messages.in b/Source/WebKit2/WebProcess/UserContent/WebUserContentController.messages.in >index d0cfc1f766781fc0d737516cb2ab52bc95653974..a93fa47c068487f5cad6e5ae2f5ee16efbb5014b 100644 >--- a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.messages.in >+++ b/Source/WebKit2/WebProcess/UserContent/WebUserContentController.messages.in >@@ -27,6 +27,9 @@ messages -> WebUserContentController { > AddUserScripts(Vector<WebCore::UserScript> userScripts); > RemoveAllUserScripts() > >+ AddUserStyleSheets(Vector<WebCore::UserStyleSheet> userStyleShhets); >+ RemoveAllUserStyleSheets() >+ > AddUserScriptMessageHandlers(Vector<WebKit::WebScriptMessageHandlerHandle> scriptMessageHandlers); > RemoveUserScriptMessageHandler(uint64_t identifier) > } >diff --git a/Source/cmake/OptionsGTK.cmake b/Source/cmake/OptionsGTK.cmake >index e14e22b8e5a87bb6d787d1830d15b7b9c7836cf0..5759be3f49ecae876483ea3ac55a0c53da2077f6 100644 >--- a/Source/cmake/OptionsGTK.cmake >+++ b/Source/cmake/OptionsGTK.cmake >@@ -89,6 +89,7 @@ set(ENABLE_INSPECTOR ON) > set(ENABLE_WEBKIT OFF) > set(ENABLE_WEBKIT2 ON) > set(ENABLE_PLUGIN_PROCESS ON) >+set(ENABLE_USER_MESSAGE_HANDLERS ON) > > set(GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_6) > set(GTK_API_VERSION 3.0)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 133730
:
232952
|
233651
|
234981
|
234982
|
234986
|
240219
|
240479
|
240561
|
240666