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-134551-20140703222016.patch (text/plain), 74.03 KB, created by
Adrian Perez
on 2014-07-03 12:18:08 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Adrian Perez
Created:
2014-07-03 12:18:08 PDT
Size:
74.03 KB
patch
obsolete
>Subversion Revision: 170760 >diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog >index ccd9c474186b80a3acaceac3a3d6b29f014ac79e..01e63f739c692cc2d5ec796b95b37a2252516ce3 100644 >--- a/Source/WebKit2/ChangeLog >+++ b/Source/WebKit2/ChangeLog >@@ -1,3 +1,89 @@ >+2014-07-03 Adrian Perez de Castro <aperez@igalia.com> >+ >+ [GTK] Move user style sheet API out of WebKitWebViewGroup >+ https://bugs.webkit.org/show_bug.cgi?id=134551 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * PlatformGTK.cmake: Include the new source files in the build. >+ * UIProcess/API/C/gtk/WKView.cpp: >+ (WKViewCreate): >+ Adapt to the additional webkitWebViewBaseCreateWebPage() parameter. >+ * UIProcess/API/gtk/WebKitUserContent.cpp: Added. >+ (toUserContentInjectedFrames): >+ (toUserStyleLevel): >+ (toStringVector): >+ (_WebKitUserStyleSheet::_WebKitUserStyleSheet): >+ (webkit_user_style_sheet_ref): >+ (webkit_user_style_sheet_unref): >+ (webkit_user_style_sheet_new): >+ (webkitWebKitUserStyleSheetToUserStyleSheet): >+ * UIProcess/API/gtk/WebKitUserContent.h: Added. >+ * UIProcess/API/gtk/WebKitUserContentManager.cpp: Added. >+ (_WebKitUserContentManagerPrivate::_WebKitUserContentManagerPrivate): >+ (webkit_user_content_manager_class_init): >+ (webkit_user_content_manager_new): >+ (webkit_user_content_manager_add_style_sheet): >+ (webkit_user_content_manager_remove_all_style_sheets): >+ (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): Add a new parameter to allow >+ passing the WebKitUserContentManager that the web view will use. >+ * UIProcess/API/gtk/WebKitWebContextPrivate.h: Ditto. >+ * UIProcess/API/gtk/WebKitWebView.cpp: >+ (webkitWebViewConstructed): Added handling of the >+ "user-content-manager" property on construction. >+ (webkitWebViewSetProperty): Added support for the >+ "user-content-manager" property. >+ (webkitWebViewGetProperty): Added support for the >+ "user-content-manager" property. >+ (webkit_web_view_class_init): Added the "user-content-manager" >+ property definition to the WebKitWebView class. >+ (webkit_web_view_new_with_related_view): Made related views share >+ the same WebKitUserContentManager used by the view they are >+ related to. >+ (webkit_web_view_new_with_user_content_manager): Added. >+ (webkit_web_view_get_user_content_manager): Added. >+ * UIProcess/API/gtk/WebKitWebView.h: Add new API methods. >+ * UIProcess/API/gtk/WebKitWebViewBase.cpp: >+ (webkitWebViewBaseCreate): Added a parameter to pass the user >+ content manager. >+ (webkitWebViewBaseCreateWebPage): Added a parameter to pass the user >+ content manager. >+ * UIProcess/API/gtk/WebKitWebViewBasePrivate.h: Ditto. >+ * UIProcess/API/gtk/WebKitWebViewGroup.cpp: Removed the bits related >+ to user style sheet support from WebKitWebViewGroup. >+ (webkit_web_view_group_set_settings): >+ (toAPIArray): Deleted. >+ (webkit_web_view_group_add_user_style_sheet): Deleted. >+ (webkit_web_view_group_remove_all_user_style_sheets): Deleted. >+ * UIProcess/API/gtk/WebKitWebViewGroup.h: Deleted the API methods >+ for user style sheet handling. >+ * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Added the new API >+ functions and types, and removed the methods which are no longer >+ available in WebKitWebViewGroup. >+ * UIProcess/API/gtk/webkit2.h: Add the new headers. >+ * UIProcess/UserContent/WebUserContentControllerProxy.cpp: Added >+ methods to add and remove user style sheets, alike those used for >+ user scripts. >+ (WebKit::WebUserContentControllerProxy::addProcess): >+ (WebKit::WebUserContentControllerProxy::addUserStyleSheet): >+ (WebKit::WebUserContentControllerProxy::removeAllUserStyleSheets): >+ * UIProcess/UserContent/WebUserContentControllerProxy.h: Ditto. >+ * UIProcess/gtk/WebInspectorProxyGtk.cpp: >+ (WebKit::WebInspectorProxy::platformCreateInspectorPage): >+ Adapt to the additional webkitWebViewBaseCreateWebPage() parameter. >+ * WebProcess/UserContent/WebUserContentController.cpp: Added methods >+ to add and remove user style sheets, alike those used for user scripts. >+ (WebKit::WebUserContentController::addUserStyleSheets): >+ (WebKit::WebUserContentController::removeAllUserStyleSheets): >+ * WebProcess/UserContent/WebUserContentController.h: Ditto. >+ * WebProcess/UserContent/WebUserContentController.messages.in: >+ Ditto. >+ > 2014-07-03 Brady Eidson <beidson@apple.com> > > Followup to "rects sent to ServicesOverlayController are wrong" >diff --git a/Source/WebCore/WebCore.exp.in b/Source/WebCore/WebCore.exp.in >index 4bfb801cf07226ee39d56619818240048dc16841..1f0ab3bf1a4991bc82c55b150a3dc6951418f6c4 100644 >--- a/Source/WebCore/WebCore.exp.in >+++ b/Source/WebCore/WebCore.exp.in >@@ -926,6 +926,8 @@ __ZN7WebCore21SerializedScriptValueD1Ev > __ZN7WebCore21URLByRemovingUserInfoEP5NSURL > __ZN7WebCore21UserContentController13addUserScriptERNS_15DOMWrapperWorldENSt3__110unique_ptrINS_10UserScriptENS3_14default_deleteIS5_EEEE > __ZN7WebCore21UserContentController17removeUserScriptsERNS_15DOMWrapperWorldE >+__ZN7WebCore21UserContentController17addUserStyleSheetERNS_15DOMWrapperWorldENSt3__110unique_ptrINS_14UserStyleSheetENS3_14default_deleteIS5_EEEENS_22UserStyleInjectionTimeE >+__ZN7WebCore21UserContentController21removeUserStyleSheetsERNS_15DOMWrapperWorldE > __ZN7WebCore21UserContentController31addUserMessageHandlerDescriptorERNS_28UserMessageHandlerDescriptorE > __ZN7WebCore21UserContentController34removeUserMessageHandlerDescriptorERNS_28UserMessageHandlerDescriptorE > __ZN7WebCore21UserContentController6createEv >diff --git a/Source/WebKit2/PlatformGTK.cmake b/Source/WebKit2/PlatformGTK.cmake >index a4ba9aa9ac0b113e0eb8c9d74f793b4756db911e..818e0ef7a506e0493521c097a2b52abe6a4faddd 100644 >--- a/Source/WebKit2/PlatformGTK.cmake >+++ b/Source/WebKit2/PlatformGTK.cmake >@@ -210,6 +210,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 >@@ -353,6 +359,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..5eaa95127340e9ee773d858c131e3b456f733eaa >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.cpp >@@ -0,0 +1,161 @@ >+/* >+ * 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 <wtf/text/CString.h> >+#include <wtf/text/StringBuilder.h> >+ >+using namespace WebCore; >+ >+/** >+ * SECTION:WebKitUserContent >+ * @short_description: Defines user content types which affect web pages. >+ * @title: User content >+ * >+ * See also: #WebKitUserContentManager >+ * >+ * Since: 2.6 >+ */ >+ >+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 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 Vector<String> toStringVector(const char* const* strv) >+{ >+ if (!strv) >+ return Vector<String>(); >+ >+ Vector<String> result; >+ for (auto str = strv; *str; ++str) >+ result.append(std::move(String::fromUTF8(*str))); >+ return result; >+} >+ >+struct _WebKitUserStyleSheet { >+ _WebKitUserStyleSheet(const gchar* source, WebKitUserContentInjectedFrames injectedFrames, WebKitUserStyleLevel level, const char* const* whitelist, const char* const* blacklist) >+ : userStyleSheet(std::make_unique<UserStyleSheet>( >+ String::fromUTF8(source), URL { }, >+ toStringVector(whitelist), toStringVector(blacklist), >+ toUserContentInjectedFrames(injectedFrames), >+ toUserStyleLevel(level))) >+ , referenceCount(1) >+ { >+ } >+ >+ std::unique_ptr<UserStyleSheet> userStyleSheet; >+ int referenceCount; >+}; >+ >+G_DEFINE_BOXED_TYPE(WebKitUserStyleSheet, webkit_user_style_sheet, webkit_user_style_sheet_ref, webkit_user_style_sheet_unref) >+ >+/** >+ * webkit_user_style_sheet_ref: >+ * @user_style_sheet: a #WebKitUserStyleSheet >+ * >+ * Atomically increments the reference count of @user_style_sheet by one. >+ * This function is MT-safe and may be called from any thread. >+ * >+ * Returns: The passed #WebKitUserStyleSheet >+ * >+ * Since: 2.6 >+ */ >+WebKitUserStyleSheet* webkit_user_style_sheet_ref(WebKitUserStyleSheet* userStyleSheet) >+{ >+ g_atomic_int_inc(&userStyleSheet->referenceCount); >+ return userStyleSheet; >+} >+ >+/** >+ * webkit_user_style_sheet_unref: >+ * @user_style_sheet: a #WebKitUserStyleSheet >+ * >+ * Atomically decrements the reference count of @user_style_sheet by one. >+ * If the reference count drops to 0, all memory allocated by >+ * #WebKitUserStyleSheet is released. This function is MT-safe and may be >+ * called from any thread. >+ * >+ * Since: 2.6 >+ */ >+void webkit_user_style_sheet_unref(WebKitUserStyleSheet* userStyleSheet) >+{ >+ if (g_atomic_int_dec_and_test(&userStyleSheet->referenceCount)) { >+ userStyleSheet->~WebKitUserStyleSheet(); >+ g_slice_free(WebKitUserStyleSheet, userStyleSheet); >+ } >+} >+ >+/** >+ * 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: A new #WebKitUserStyleSheet >+ * >+ * Since: 2.6 >+ */ >+WebKitUserStyleSheet* webkit_user_style_sheet_new(const gchar* source, WebKitUserContentInjectedFrames injectedFrames, WebKitUserStyleLevel level, const char* const* whitelist, const char* const* blacklist) >+{ >+ g_return_val_if_fail(source, nullptr); >+ WebKitUserStyleSheet* userStyleSheet = g_slice_new(WebKitUserStyleSheet); >+ new (userStyleSheet) WebKitUserStyleSheet(source, injectedFrames, level, whitelist, blacklist); >+ return userStyleSheet; >+} >+ >+const UserStyleSheet& webkitUserStyleSheetGetUserStyleSheet(WebKitUserStyleSheet* userStyleSheet) >+{ >+ return *userStyleSheet->userStyleSheet; >+} >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.h b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.h >new file mode 100644 >index 0000000000000000000000000000000000000000..21d3adeb5228f3e82248e412f37a440e834d6cde >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.h >@@ -0,0 +1,89 @@ >+/* >+ * 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: >+ * @WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES: Insert the user 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 style >+ * sheet *only* in the top-level frame loaded by the web view, >+ * and *not* in the nested frames. >+ * >+ * Specifies in which frames user style sheets are to be inserted in. >+ * >+ * Since: 2.6 >+ */ >+typedef enum { >+ WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, >+ WEBKIT_USER_CONTENT_INJECT_TOP_FRAME, >+} WebKitUserContentInjectedFrames; >+ >+/** >+ * WebKitUserStyleLevel: >+ * @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. >+ * >+ * Specifies how to treat an user style sheet. >+ * >+ * Since: 2.6 >+ */ >+typedef enum { >+ WEBKIT_USER_STYLE_LEVEL_USER, >+ WEBKIT_USER_STYLE_LEVEL_AUTHOR, >+} WebKitUserStyleLevel; >+ >+#define WEBKIT_TYPE_USER_STYLE_SHEET (webkit_user_content_get_type()) >+ >+typedef struct _WebKitUserStyleSheet WebKitUserStyleSheet; >+ >+WEBKIT_API GType >+webkit_user_style_sheet_get_type (void); >+ >+WEBKIT_API WebKitUserStyleSheet * >+webkit_user_style_sheet_ref (WebKitUserStyleSheet *user_style_sheet); >+ >+WEBKIT_API void >+webkit_user_style_sheet_unref (WebKitUserStyleSheet *user_style_sheet); >+ >+WEBKIT_API WebKitUserStyleSheet * >+webkit_user_style_sheet_new (const gchar *source, >+ WebKitUserContentInjectedFrames injected_frames, >+ WebKitUserStyleLevel level, >+ const gchar* const *whitelist, >+ const gchar* const *blacklist); >+ >+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..5182668984f3d06e233eec653568883db819e231 >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.cpp >@@ -0,0 +1,113 @@ >+/* >+ * 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 "WebKitPrivate.h" >+#include "WebKitUserContentManagerPrivate.h" >+#include "WebKitUserContentPrivate.h" >+#include <wtf/gobject/GRefPtr.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 user CSS style sheets can be set to >+ * be injected in the web pages loaded by a #WebKitWebView, by >+ * webkit_user_content_manager_add_style_sheet(). >+ * >+ * 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 style >+ * sheets can be created with webkit_user_style_sheet_new(). >+ * >+ * User style sheets can be added and removed at any time, but >+ * they will affect the web pages loaded afterwards. >+ * >+ * Since: 2.6 >+ */ >+ >+WEBKIT_DEFINE_TYPE(WebKitUserContentManager, webkit_user_content_manager, G_TYPE_OBJECT) >+ >+static void webkit_user_content_manager_class_init(WebKitUserContentManagerClass*) >+{ >+} >+ >+/** >+ * webkit_user_content_manager_new: >+ * >+ * Creates a new user content manager. >+ * >+ * Returns: A #WebKitUserContentManager >+ * >+ * Since: 2.6 >+ */ >+WebKitUserContentManager* webkit_user_content_manager_new() >+{ >+ return WEBKIT_USER_CONTENT_MANAGER(g_object_new(WEBKIT_TYPE_USER_CONTENT_MANAGER, nullptr)); >+} >+ >+/** >+ * webkit_user_content_manager_add_style_sheet: >+ * @manager: A #WebKitUserContentManager >+ * @stylesheet: A #WebKitUserStyleSheet >+ * >+ * Adds a #WebKitUserStyleSheet to the given #WebKitUserContentManager. >+ * The same #WebKitUserStyleSheet can be reused with multiple >+ * #WebKitUserContentManager instances. >+ * >+ * Since: 2.6 >+ */ >+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(styleSheet); >+ manager->priv->userContentController->addUserStyleSheet(webkitUserStyleSheetGetUserStyleSheet(styleSheet)); >+} >+ >+/** >+ * webkit_user_content_manager_remove_all_style_sheets: >+ * @manager: A #WebKitUserContentManager >+ * >+ * Removes all user style sheets from the given #WebKitUserContentManager. >+ * >+ * Since: 2.6 >+ */ >+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(); >+} >+ >+WebUserContentControllerProxy* webkitUserContentManagerGetUserContentControllerProxy(WebKitUserContentManager* manager) >+{ >+ 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..b919500faef0c585f0ca4963642e6eb833a172ed >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.h >@@ -0,0 +1,76 @@ >+/* >+ * 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_style_sheet (WebKitUserContentManager *manager, >+ WebKitUserStyleSheet *stylesheet); >+WEBKIT_API void >+webkit_user_content_manager_remove_all_style_sheets (WebKitUserContentManager *manager); >+ >+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..f791a5357b419219cf66dfc76bdc2d164fb3b65c >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManagerPrivate.h >@@ -0,0 +1,28 @@ >+/* >+ * 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" >+#include "WebUserContentControllerProxy.h" >+ >+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..83958abca3d969df999f204d9f6544253c337d0c >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentPrivate.h >@@ -0,0 +1,29 @@ >+/* >+ * 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" >+ >+#include <WebCore/UserStyleSheet.h> >+ >+const WebCore::UserStyleSheet& webkitUserStyleSheetGetUserStyleSheet(WebKitUserStyleSheet*); >+ >+#endif // WebKitUserContentPrivate_h >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp >index 62808b76cef86da7233b1d0262a2ecc44c1f3272..70d4ac17e545b9b598f85a81fb18b99f751ee3b6 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp >@@ -39,6 +39,7 @@ > #include "WebKitSecurityManagerPrivate.h" > #include "WebKitTextChecker.h" > #include "WebKitURISchemeRequestPrivate.h" >+#include "WebKitUserContentManagerPrivate.h" > #include "WebKitWebContextPrivate.h" > #include "WebKitWebViewBasePrivate.h" > #include "WebKitWebViewGroupPrivate.h" >@@ -1050,12 +1051,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 0f855e57bf7511aaee6eb02a9930277b271061e3..f826cea079b17a7e976641b62241d40b2dee277f 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,23 @@ 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. >+ * >+ * Since: 2.6 >+ */ >+ 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 >@@ -1924,6 +1951,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 >@@ -1932,7 +1961,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)); > } > > /** >@@ -1953,6 +1985,25 @@ GtkWidget* webkit_web_view_new_with_group(WebKitWebViewGroup* group) > } > > /** >+ * webkit_web_view_new_with_user_content_manager: >+ * @user_content_manager: a #WebKitUserContentManager. >+ * >+ * Creates a new #WebKitWebView with the given #WebKitUserContentManager. >+ * The content loaded in the view may be affected by the content injected >+ * in the view by the user content manager. >+ * >+ * Returns: The newly created #WebKitWebView widget >+ * >+ * Since: 2.6 >+ */ >+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 > * >@@ -1986,6 +2037,24 @@ 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, or %NULL if the >+ * view does not have an user content manager. >+ * >+ * 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 549d254cc26eb37e2ffecc01eda6703d2197ccca..9bf2cc546bc456232c097ee6f9bb2f9fec20378d 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h >@@ -44,6 +44,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> >@@ -260,6 +261,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); > >@@ -455,6 +459,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/WebKitWebViewGroup.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.cpp >index b21e79f683da7effd198ddfc82a37e9bf3dc24c0..c8a6507a8e5986fcad6b684b7e3bd599bb9b2074 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.cpp >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.cpp >@@ -236,63 +236,3 @@ void webkit_web_view_group_set_settings(WebKitWebViewGroup* group, WebKitSetting > webkitWebViewGroupAttachSettingsToPageGroup(group); > g_object_notify(G_OBJECT(group), "settings"); > } >- >-static PassRefPtr<API::Array> toAPIArray(const char* const* list) >-{ >- if (!list) >- return 0; >- >- Vector<RefPtr<API::Object> > entries; >- while (*list) { >- entries.append(API::String::createFromUTF8String(*list)); >- list++; >- } >- return API::Array::create(std::move(entries)); >-} >- >-/** >- * webkit_web_view_group_add_user_style_sheet: >- * @group: a #WebKitWebViewGroup >- * @source: the source of the style_sheet to inject >- * @base_uri: (allow-none): the base URI to use when processing the style_sheet contents or %NULL for about:blank >- * @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 >- * @injected_frames: a #WebKitInjectedContentFrames describing to which frames the style_sheet should apply >- * >- * Inject an external style sheet into pages. It is possible to only apply the style sheet >- * to some URIs 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 a 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. >- */ >-void webkit_web_view_group_add_user_style_sheet(WebKitWebViewGroup* group, const char* source, const char* baseURI, const char* const* whitelist, const char* const* blacklist, WebKitInjectedContentFrames injectedFrames) >-{ >- g_return_if_fail(WEBKIT_IS_WEB_VIEW_GROUP(group)); >- g_return_if_fail(source); >- >- RefPtr<API::Array> webWhitelist = toAPIArray(whitelist); >- RefPtr<API::Array> webBlacklist = toAPIArray(blacklist); >- >- // We always use UserStyleUserLevel to match the behavior of WKPageGroupAddUserStyleSheet. >- group->priv->pageGroup->addUserStyleSheet( >- String::fromUTF8(source), >- String::fromUTF8(baseURI), >- webWhitelist.get(), >- webBlacklist.get(), >- toWebCoreUserContentInjectedFrames(injectedFrames), >- WebCore::UserStyleUserLevel); >-} >- >-/** >- * webkit_web_view_group_remove_all_user_style_sheets: >- * @group: a #WebKitWebViewGroup >- * >- * Remove all style sheets previously injected into this #WebKitWebViewGroup >- * via webkit_web_view_group_add_user_style_sheet(). >- */ >-void webkit_web_view_group_remove_all_user_style_sheets(WebKitWebViewGroup* group) >-{ >- g_return_if_fail(WEBKIT_IS_WEB_VIEW_GROUP(group)); >- group->priv->pageGroup->removeAllUserStyleSheets(); >-} >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.h >index 685f19904edcfd9c6b5adb0b53be07a7456358d8..836ea1734f368920c48cc3f44b27bb29bfee5d34 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.h >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewGroup.h >@@ -84,17 +84,6 @@ WEBKIT_API void > webkit_web_view_group_set_settings (WebKitWebViewGroup *group, > WebKitSettings *settings); > >-WEBKIT_API void >-webkit_web_view_group_add_user_style_sheet (WebKitWebViewGroup *group, >- const gchar *source, >- const gchar *base_uri, >- const gchar * const *whitelist, >- const gchar * const *blacklist, >- WebKitInjectedContentFrames injected_frames); >- >-WEBKIT_API void >-webkit_web_view_group_remove_all_user_style_sheets (WebKitWebViewGroup *group); >- > G_END_DECLS > > #endif >diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt >index 54813c900ad6ec2f117b1621b41880c21dc9dcae..063cb675bbfa92a8d570c3b01f685fb02ce56bea 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt >+++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt >@@ -73,6 +73,45 @@ webkit_web_context_get_type > </SECTION> > > <SECTION> >+<FILE>WebKitUserContent</FILE> >+<TITLE>WebKitUserContent</TITLE> >+WebKitUserStyleSheet >+WebKitUserContentInjectedFrames >+WebKitUserStyleLevel >+webkit_user_style_sheet_ref >+webkit_user_style_sheet_unref >+webkit_user_style_sheet_new >+ >+<SUBSECTION Standard> >+WEBKIT_TYPE_USER_STYLE_SHEET >+ >+<SUBSECTION Private> >+webkit_user_style_sheet_get_type >+</SECTION> >+ >+<SECTION> >+<FILE>WebKitUserContentManager</FILE> >+<TITLE>WebKitUserContentManager</TITLE> >+WebKitUserContentManager >+webkit_user_content_manager_new >+webkit_user_content_manager_add_style_sheet >+webkit_user_content_manager_remove_all_style_sheets >+ >+<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 >@@ -96,8 +135,10 @@ webkit_web_view_new > webkit_web_view_new_with_context > webkit_web_view_new_with_related_view > webkit_web_view_new_with_group >+webkit_web_view_new_with_user_content_manager > webkit_web_view_get_context > webkit_web_view_get_group >+webkit_web_view_get_user_content_manager > webkit_web_view_load_uri > webkit_web_view_load_html > webkit_web_view_load_alternate_html >@@ -1025,8 +1066,6 @@ webkit_web_view_group_new > webkit_web_view_group_get_name > webkit_web_view_group_get_settings > webkit_web_view_group_set_settings >-webkit_web_view_group_add_user_style_sheet >-webkit_web_view_group_remove_all_user_style_sheets > > <SUBSECTION Standard> > WebKitWebViewGroupClass >diff --git a/Source/WebKit2/UIProcess/API/gtk/webkit2.h b/Source/WebKit2/UIProcess/API/gtk/webkit2.h >index 46490a2e014d63faab0a3072c9038493448a2312..52ccad3062be8c583e05bee6ac795e90684f519d 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/webkit2.h >+++ b/Source/WebKit2/UIProcess/API/gtk/webkit2.h >@@ -61,6 +61,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..90a1e47c0888c09be58d7bc283db7c963bb43b76 100644 >--- a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp >+++ b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp >@@ -66,7 +66,8 @@ void WebUserContentControllerProxy::addProcess(WebProcessProxy& webProcessProxy) > webProcessProxy.addMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), m_identifier, *this); > > webProcessProxy.connection()->send(Messages::WebUserContentController::AddUserScripts(m_userScripts), m_identifier); >- >+ webProcessProxy.connection()->send(Messages::WebUserContentController::AddUserStyleSheets(m_userStyleSheets), m_identifier); >+ > Vector<WebScriptMessageHandlerHandle> messageHandlerHandles; > for (auto& handler : m_scriptMessageHandlers.values()) > messageHandlerHandles.append(handler->handle()); >@@ -97,6 +98,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/Tools/ChangeLog b/Tools/ChangeLog >index eb822f7757fcb3de2e95ee307ac50bc9b1d3970a..c8541069fe10e47b827c1bfbc51e5c13ebc7b2eb 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,39 @@ >+2014-07-03 Adrian Perez de Castro <aperez@igalia.com> >+ >+ [GTK] Move user style sheet API out of WebKitWebViewGroup >+ https://bugs.webkit.org/show_bug.cgi?id=134551 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Removes testing user style sheet injection from >+ TestWebKitWebViewGroup and moves that into a new >+ TestWebKitUserContentManager, adapting the existing tests to the new >+ API. Also, it contains a new test case for >+ webkit_web_view_new_with_user_content_manager(). >+ >+ * TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt: >+ * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp: Added. >+ (UserContentManagerTest::UserContentManagerTest): >+ (testWebViewNewWithUserContentManager): >+ (isStyleSheetInjectedForURLAtPath): >+ (fillURLListFromPaths): >+ (removeOldInjectedStyleSheetsAndResetLists): >+ (testUserContentManagerInjectedStyleSheet): >+ (serverCallback): >+ (beforeAll): >+ (afterAll): >+ * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebViewGroup.cpp: >+ (beforeAll): >+ (afterAll): >+ (isStyleSheetInjectedForURLAtPath): Deleted. >+ (fillURLListFromPaths): Deleted. >+ (removeOldInjectedStyleSheetsAndResetLists): Deleted. >+ (testWebViewGroupInjectedStyleSheet): Deleted. >+ (serverCallback): Deleted. >+ * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp: >+ (WebViewTest::WebViewTest): >+ * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h: >+ > 2014-07-03 László Langó <llango.u-szeged@partner.samsung.com> > > [JavaScriptCore] Add --cmakeargs option to build-jsc. >diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt >index f66b730a88b6501ffb8d2f14b9b1b316178f5935..172b38aa087472b135131a6284314a04d949db5d 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt >+++ b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt >@@ -112,6 +112,7 @@ ADD_WK2_TEST(TestWebViewEditor TestWebViewEditor.cpp) > ADD_WK2_TEST(TestWebKitWebViewGroup TestWebKitWebViewGroup.cpp) > ADD_WK2_TEST(TestWebKitWebContext TestWebKitWebContext.cpp) > ADD_WK2_TEST(TestWebKitWebView TestWebKitWebView.cpp) >+ADD_WK2_TEST(TestWebKitUserContentManager TestWebKitUserContentManager.cpp) > > if (ATSPI_FOUND) > ADD_WK2_TEST(AccessibilityTestServer AccessibilityTestServer.cpp) >diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..104e367bce2419afd887f569f5d41b60ff84d5e9 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp >@@ -0,0 +1,172 @@ >+/* >+ * Copyright (C) 2013 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,1 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 "WebKitTestServer.h" >+#include "WebViewTest.h" >+#include <cstdarg> >+#include <gtk/gtk.h> >+#include <webkit2/webkit2.h> >+#include <wtf/gobject/GRefPtr.h> >+ >+class UserContentManagerTest : public WebViewTest { >+public: >+ MAKE_GLIB_TEST_FIXTURE(UserContentManagerTest); >+ >+ UserContentManagerTest() >+ : WebViewTest(WEBKIT_WEB_VIEW(webkit_web_view_new_with_user_content_manager(webkit_user_content_manager_new()))) >+ { >+ // A reference is leaked when passing the result of webkit_user_content_manager_new() >+ // directly to webkit_web_view_new_with_user_content_manager() above. Adopting the >+ // reference here avoids the leak. >+ m_userContentManager = adoptGRef(webkit_web_view_get_user_content_manager(m_webView)); >+ assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_userContentManager.get())); >+ } >+ >+ GRefPtr<WebKitUserContentManager> m_userContentManager; >+}; >+ >+static WebKitTestServer* kServer; >+ >+// These are all here so that they can be changed easily, if necessary. >+static const char* kStyleSheetHTML = "<html><div id=\"styledElement\">Sweet stylez!</div></html>"; >+static const char* kInjectedStyleSheet = "#styledElement { font-weight: bold; }"; >+static const char* kStyleSheetTestScript = "getComputedStyle(document.getElementById('styledElement'))['font-weight']"; >+static const char* kStyleSheetTestScriptResult = "bold"; >+ >+static void testWebViewNewWithUserContentManager(Test* test, gconstpointer) >+{ >+ GRefPtr<WebKitUserContentManager> userContentManager1 = adoptGRef(webkit_user_content_manager_new()); >+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(userContentManager1.get())); >+ GRefPtr<WebKitWebView> webView1 = WEBKIT_WEB_VIEW(webkit_web_view_new_with_user_content_manager(userContentManager1.get())); >+ g_assert(webkit_web_view_get_user_content_manager(webView1.get()) == userContentManager1.get()); >+ >+ GRefPtr<WebKitWebView> webView2 = WEBKIT_WEB_VIEW(webkit_web_view_new()); >+ g_assert(webkit_web_view_get_user_content_manager(webView2.get()) != userContentManager1.get()); >+} >+ >+static bool isStyleSheetInjectedForURLAtPath(WebViewTest* test, const char* path) >+{ >+ test->loadURI(kServer->getURIForPath(path).data()); >+ test->waitUntilLoadFinished(); >+ >+ GUniqueOutPtr<GError> error; >+ WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished(kStyleSheetTestScript, &error.outPtr()); >+ g_assert(javascriptResult); >+ g_assert(!error.get()); >+ >+ GUniquePtr<char> resultString(WebViewTest::javascriptResultToCString(javascriptResult)); >+ return !g_strcmp0(resultString.get(), kStyleSheetTestScriptResult); >+} >+ >+static void fillURLListFromPaths(char** list, const char* path, ...) >+{ >+ va_list argumentList; >+ va_start(argumentList, path); >+ >+ int i = 0; >+ while (path) { >+ // FIXME: We must use a wildcard for the host here until http://wkbug.com/112476 is fixed. >+ // Until that time patterns with port numbers in them will not properly match URLs with port numbers. >+ list[i++] = g_strdup_printf("http://*/%s*", path); >+ path = va_arg(argumentList, const char*); >+ } >+} >+ >+static void removeOldInjectedStyleSheetsAndResetLists(WebKitUserContentManager* userContentManager, char** whitelist, char** blacklist) >+{ >+ webkit_user_content_manager_remove_all_style_sheets(userContentManager); >+ >+ while (*whitelist) { >+ g_free(*whitelist); >+ *whitelist = 0; >+ whitelist++; >+ } >+ >+ while (*blacklist) { >+ g_free(*blacklist); >+ *blacklist = 0; >+ blacklist++; >+ } >+} >+ >+static void testUserContentManagerInjectedStyleSheet(UserContentManagerTest* test, gconstpointer) >+{ >+ char* whitelist[3] = { 0, 0, 0 }; >+ char* blacklist[3] = { 0, 0, 0 }; >+ >+ removeOldInjectedStyleSheetsAndResetLists(test->m_userContentManager.get(), whitelist, blacklist); >+ >+ // Without a whitelist or a blacklist all URLs should have the injected style sheet. >+ static const char* randomPath = "somerandompath"; >+ g_assert(!isStyleSheetInjectedForURLAtPath(test, randomPath)); >+ WebKitUserStyleSheet* styleSheet = webkit_user_style_sheet_new(kInjectedStyleSheet, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, WEBKIT_USER_STYLE_LEVEL_USER, nullptr, nullptr); >+ webkit_user_content_manager_add_style_sheet(test->m_userContentManager.get(), styleSheet); >+ webkit_user_style_sheet_unref(styleSheet); >+ g_assert(isStyleSheetInjectedForURLAtPath(test, randomPath)); >+ >+ removeOldInjectedStyleSheetsAndResetLists(test->m_userContentManager.get(), whitelist, blacklist); >+ >+ fillURLListFromPaths(blacklist, randomPath, 0); >+ styleSheet = webkit_user_style_sheet_new(kInjectedStyleSheet, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, WEBKIT_USER_STYLE_LEVEL_USER, nullptr, blacklist); >+ webkit_user_content_manager_add_style_sheet(test->m_userContentManager.get(), styleSheet); >+ webkit_user_style_sheet_unref(styleSheet); >+ g_assert(!isStyleSheetInjectedForURLAtPath(test, randomPath)); >+ g_assert(isStyleSheetInjectedForURLAtPath(test, "someotherrandompath")); >+ >+ removeOldInjectedStyleSheetsAndResetLists(test->m_userContentManager.get(), whitelist, blacklist); >+ >+ static const char* inTheWhiteList = "inthewhitelist"; >+ static const char* notInWhitelist = "notinthewhitelist"; >+ static const char* inTheWhiteListAndBlackList = "inthewhitelistandblacklist"; >+ >+ fillURLListFromPaths(whitelist, inTheWhiteList, inTheWhiteListAndBlackList, 0); >+ fillURLListFromPaths(blacklist, inTheWhiteListAndBlackList, 0); >+ styleSheet = webkit_user_style_sheet_new(kInjectedStyleSheet, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, WEBKIT_USER_STYLE_LEVEL_USER, whitelist, blacklist); >+ webkit_user_content_manager_add_style_sheet(test->m_userContentManager.get(), styleSheet); >+ webkit_user_style_sheet_unref(styleSheet); >+ g_assert(isStyleSheetInjectedForURLAtPath(test, inTheWhiteList)); >+ g_assert(!isStyleSheetInjectedForURLAtPath(test, inTheWhiteListAndBlackList)); >+ g_assert(!isStyleSheetInjectedForURLAtPath(test, notInWhitelist)); >+ >+ // It's important to clean up the environment before other tests. >+ removeOldInjectedStyleSheetsAndResetLists(test->m_userContentManager.get(), whitelist, blacklist); >+} >+ >+static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) >+{ >+ soup_message_set_status(message, SOUP_STATUS_OK); >+ soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kStyleSheetHTML, strlen(kStyleSheetHTML)); >+ soup_message_body_complete(message->response_body); >+} >+ >+void beforeAll() >+{ >+ kServer = new WebKitTestServer(); >+ kServer->run(serverCallback); >+ >+ Test::add("WebKitWebView", "new-with-user-content-manager", testWebViewNewWithUserContentManager); >+ UserContentManagerTest::add("WebKitUserContentManager", "injected-style-sheet", testUserContentManagerInjectedStyleSheet); >+} >+ >+void afterAll() >+{ >+ delete kServer; >+} >diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebViewGroup.cpp b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebViewGroup.cpp >index 448abd2fe532c6c14fe2339f3c1767f0a9da8031..ccba89d462e44a253ee8fae46db6d69ee4856ec9 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebViewGroup.cpp >+++ b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebViewGroup.cpp >@@ -26,14 +26,6 @@ > #include <webkit2/webkit2.h> > #include <wtf/gobject/GRefPtr.h> > >-static WebKitTestServer* kServer; >- >-// These are all here so that they can be changed easily, if necessary. >-static const char* kStyleSheetHTML = "<html><div id=\"styledElement\">Sweet stylez!</div></html>"; >-static const char* kInjectedStyleSheet = "#styledElement { font-weight: bold; }"; >-static const char* kStyleSheetTestScript = "getComputedStyle(document.getElementById('styledElement'))['font-weight']"; >-static const char* kStyleSheetTestScriptResult = "bold"; >- > static void testWebViewGroupDefault(Test* test, gconstpointer) > { > // Default group is shared by all WebViews by default. >@@ -98,109 +90,14 @@ static void testWebViewGroupSettings(Test* test, gconstpointer) > g_assert(webkit_web_view_group_get_settings(webkit_web_view_get_group(webView1.get())) == webView2Settings); > } > >-static bool isStyleSheetInjectedForURLAtPath(WebViewTest* test, const char* path) >-{ >- test->loadURI(kServer->getURIForPath(path).data()); >- test->waitUntilLoadFinished(); >- >- GUniqueOutPtr<GError> error; >- WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished(kStyleSheetTestScript, &error.outPtr()); >- g_assert(javascriptResult); >- g_assert(!error.get()); >- >- GUniquePtr<char> resultString(WebViewTest::javascriptResultToCString(javascriptResult)); >- return !g_strcmp0(resultString.get(), kStyleSheetTestScriptResult); >-} >- >-static void fillURLListFromPaths(char** list, const char* path, ...) >-{ >- va_list argumentList; >- va_start(argumentList, path); >- >- int i = 0; >- while (path) { >- // FIXME: We must use a wildcard for the host here until http://wkbug.com/112476 is fixed. >- // Until that time patterns with port numbers in them will not properly match URLs with port numbers. >- list[i++] = g_strdup_printf("http://*/%s*", path); >- path = va_arg(argumentList, const char*); >- } >-} >- >-static void removeOldInjectedStyleSheetsAndResetLists(WebKitWebViewGroup* group, char** whitelist, char** blacklist) >-{ >- webkit_web_view_group_remove_all_user_style_sheets(group); >- >- while (*whitelist) { >- g_free(*whitelist); >- *whitelist = 0; >- whitelist++; >- } >- >- while (*blacklist) { >- g_free(*blacklist); >- *blacklist = 0; >- blacklist++; >- } >-} >- >-static void testWebViewGroupInjectedStyleSheet(WebViewTest* test, gconstpointer) >-{ >- WebKitWebViewGroup* group = webkit_web_view_get_group(test->m_webView); >- char* whitelist[3] = { 0, 0, 0 }; >- char* blacklist[3] = { 0, 0, 0 }; >- >- removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist); >- >- // Without a whitelist or a blacklist all URLs should have the injected style sheet. >- static const char* randomPath = "somerandompath"; >- g_assert(!isStyleSheetInjectedForURLAtPath(test, randomPath)); >- webkit_web_view_group_add_user_style_sheet(group, kInjectedStyleSheet, 0, 0, 0, WEBKIT_INJECTED_CONTENT_FRAMES_ALL); >- g_assert(isStyleSheetInjectedForURLAtPath(test, randomPath)); >- >- removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist); >- >- fillURLListFromPaths(blacklist, randomPath, 0); >- webkit_web_view_group_add_user_style_sheet(group, kInjectedStyleSheet, 0, 0, blacklist, WEBKIT_INJECTED_CONTENT_FRAMES_ALL); >- g_assert(!isStyleSheetInjectedForURLAtPath(test, randomPath)); >- g_assert(isStyleSheetInjectedForURLAtPath(test, "someotherrandompath")); >- >- removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist); >- >- static const char* inTheWhiteList = "inthewhitelist"; >- static const char* notInWhitelist = "notinthewhitelist"; >- static const char* inTheWhiteListAndBlackList = "inthewhitelistandblacklist"; >- >- fillURLListFromPaths(whitelist, inTheWhiteList, inTheWhiteListAndBlackList, 0); >- fillURLListFromPaths(blacklist, inTheWhiteListAndBlackList, 0); >- webkit_web_view_group_add_user_style_sheet(group, kInjectedStyleSheet, 0, whitelist, blacklist, WEBKIT_INJECTED_CONTENT_FRAMES_ALL); >- g_assert(isStyleSheetInjectedForURLAtPath(test, inTheWhiteList)); >- g_assert(!isStyleSheetInjectedForURLAtPath(test, inTheWhiteListAndBlackList)); >- g_assert(!isStyleSheetInjectedForURLAtPath(test, notInWhitelist)); >- >- // It's important to clean up the environment before other tests. >- removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist); >-} >- >-static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) >-{ >- soup_message_set_status(message, SOUP_STATUS_OK); >- soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kStyleSheetHTML, strlen(kStyleSheetHTML)); >- soup_message_body_complete(message->response_body); >-} >- > void beforeAll() > { >- kServer = new WebKitTestServer(); >- kServer->run(serverCallback); >- > Test::add("WebKitWebViewGroup", "default-group", testWebViewGroupDefault); > Test::add("WebKitWebViewGroup", "new-group", testWebViewGroupNewGroup); > Test::add("WebKitWebView", "new-with-group", testWebViewNewWithGroup); > Test::add("WebKitWebViewGroup", "settings", testWebViewGroupSettings); >- WebViewTest::add("WebKitWebViewGroup", "injected-style-sheet", testWebViewGroupInjectedStyleSheet); > } > > void afterAll() > { >- delete kServer; > } >diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp >index 1198b08be683d5939246d90a50e3b1d4ef73c037..ebd03b4d4aa802cae68290e4dd67225d04c37e55 100644 >--- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp >+++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp >@@ -25,7 +25,10 @@ > #include <WebCore/GUniquePtrGtk.h> > > WebViewTest::WebViewTest() >- : m_webView(WEBKIT_WEB_VIEW(g_object_ref_sink(webkit_web_view_new()))) >+ : WebViewTest(WEBKIT_WEB_VIEW(webkit_web_view_new())) { } >+ >+WebViewTest::WebViewTest(WebKitWebView* webView) >+ : m_webView(WEBKIT_WEB_VIEW(g_object_ref_sink(webView))) > , m_mainLoop(g_main_loop_new(0, TRUE)) > , m_parentWindow(0) > , m_javascriptResult(0) >diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h >index f45e125c9d4fa2dcd643d6140aaa37df160ba388..2bcf563598a7eff86a2861012d0cfa8741997ad1 100644 >--- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h >+++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h >@@ -28,6 +28,7 @@ > class WebViewTest: public Test { > public: > MAKE_GLIB_TEST_FIXTURE(WebViewTest); >+ WebViewTest(WebKitWebView*); > WebViewTest(); > virtual ~WebViewTest(); >
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 134551
:
234330
|
234337
|
234338
|
234340
|
234342
|
234361
|
234486
|
234561