WebKit Bugzilla
Attachment 341754 Details for
Bug 186192
: [GTK][WPE] Add API to run javascript from a WebKitWebView in an isolated world
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
wk2-run-js-isolated-world.diff (text/plain), 32.62 KB, created by
Carlos Garcia Campos
on 2018-06-01 06:13:07 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Carlos Garcia Campos
Created:
2018-06-01 06:13:07 PDT
Size:
32.62 KB
patch
obsolete
>diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index bf7a6c19f4d..e615232820f 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,14 @@ >+2018-06-01 Carlos Garcia Campos <cgarcia@igalia.com> >+ >+ [GTK][WPE] Add API run run javascript from a WebKitWebView in an isolated world >+ https://bugs.webkit.org/show_bug.cgi?id=186192 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * bindings/js/ScriptController.cpp: >+ (WebCore::ScriptController::executeScriptInWorld): Add ExceptionDetails parameter. >+ * bindings/js/ScriptController.h: >+ > 2018-06-01 Carlos Garcia Campos <cgarcia@igalia.com> > > Crash in WebAnimation::runPendingPlayTask >diff --git a/Source/WebCore/bindings/js/ScriptController.cpp b/Source/WebCore/bindings/js/ScriptController.cpp >index e9a3b69fedd..988b68a8b18 100644 >--- a/Source/WebCore/bindings/js/ScriptController.cpp >+++ b/Source/WebCore/bindings/js/ScriptController.cpp >@@ -539,7 +539,7 @@ void ScriptController::clearScriptObjects() > #endif > } > >-JSValue ScriptController::executeScriptInWorld(DOMWrapperWorld& world, const String& script, bool forceUserGesture) >+JSValue ScriptController::executeScriptInWorld(DOMWrapperWorld& world, const String& script, bool forceUserGesture, ExceptionDetails* exceptionDetails) > { > UserGestureIndicator gestureIndicator(forceUserGesture ? std::optional<ProcessingUserGestureState>(ProcessingUserGesture) : std::nullopt); > ScriptSourceCode sourceCode(script, m_frame.document()->url(), TextPosition(), JSC::SourceProviderSourceType::Program, CachedScriptFetcher::create(m_frame.document()->charset())); >@@ -547,7 +547,7 @@ JSValue ScriptController::executeScriptInWorld(DOMWrapperWorld& world, const Str > if (!canExecuteScripts(AboutToExecuteScript) || isPaused()) > return { }; > >- return evaluateInWorld(sourceCode, world); >+ return evaluateInWorld(sourceCode, world, exceptionDetails); > } > > bool ScriptController::canExecuteScripts(ReasonForCallingCanExecuteScripts reason) >diff --git a/Source/WebCore/bindings/js/ScriptController.h b/Source/WebCore/bindings/js/ScriptController.h >index fb4de4da15a..f7c0824e06c 100644 >--- a/Source/WebCore/bindings/js/ScriptController.h >+++ b/Source/WebCore/bindings/js/ScriptController.h >@@ -90,7 +90,7 @@ public: > > JSC::JSValue executeScript(const ScriptSourceCode&, ExceptionDetails* = nullptr); > WEBCORE_EXPORT JSC::JSValue executeScript(const String& script, bool forceUserGesture = false, ExceptionDetails* = nullptr); >- WEBCORE_EXPORT JSC::JSValue executeScriptInWorld(DOMWrapperWorld&, const String& script, bool forceUserGesture = false); >+ WEBCORE_EXPORT JSC::JSValue executeScriptInWorld(DOMWrapperWorld&, const String& script, bool forceUserGesture = false, ExceptionDetails* = nullptr); > > // Returns true if argument is a JavaScript URL. > bool executeIfJavaScriptURL(const URL&, ShouldReplaceDocumentIfJavaScriptURL shouldReplaceDocumentIfJavaScriptURL = ReplaceDocumentIfJavaScriptURL); >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index eb58aaa9abf..5c809176512 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,41 @@ >+2018-06-01 Carlos Garcia Campos <cgarcia@igalia.com> >+ >+ [GTK][WPE] Add API run run javascript from a WebKitWebView in an isolated world >+ https://bugs.webkit.org/show_bug.cgi?id=186192 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add webkit_web_view_run_javascript_in_world() that receives a world name. Also add >+ webkit_script_world_new_with_name() to create an isolated world with a name and webkit_script_world_get_name() >+ to get the name of a WebKitScriptWorld. >+ >+ * UIProcess/API/glib/WebKitWebView.cpp: >+ (webkit_web_view_run_javascript): >+ (webkit_web_view_run_javascript_finish): >+ (webkit_web_view_run_javascript_in_world): >+ (webkit_web_view_run_javascript_in_world_finish): >+ * UIProcess/API/gtk/WebKitWebView.h: >+ * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add new symbols. >+ * UIProcess/API/wpe/WebKitWebView.h: >+ * UIProcess/WebPageProxy.cpp: >+ (WebKit::WebPageProxy::runJavaScriptInMainFrameScriptWorld): Send RunJavaScriptInMainFrameScriptWorld message to >+ the WebProcess. >+ * UIProcess/WebPageProxy.h: >+ * WebProcess/InjectedBundle/API/glib/WebKitScriptWorld.cpp: >+ (webkitScriptWorldCreate): >+ (webkit_script_world_new_with_name): >+ (webkit_script_world_get_name): >+ * WebProcess/InjectedBundle/API/gtk/WebKitScriptWorld.h: >+ * WebProcess/InjectedBundle/API/wpe/WebKitScriptWorld.h: >+ * WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp: >+ (WebKit::InjectedBundleScriptWorld::find): Find an InjectedBundleScriptWorld by its name. >+ * WebProcess/InjectedBundle/InjectedBundleScriptWorld.h: >+ * WebProcess/WebPage/WebPage.cpp: >+ (WebKit::WebPage::runJavaScriptInMainFrameScriptWorld): Find the InjectedBundleScriptWorld for the given name >+ and run the script in its js context. >+ * WebProcess/WebPage/WebPage.h: >+ * WebProcess/WebPage/WebPage.messages.in: Add RunJavaScriptInMainFrameScriptWorld message. >+ > 2018-06-01 Carlos Garcia Campos <cgarcia@igalia.com> > > Unreviewed. Try to fix GTK+ build with old versions of GTK+ after r232390. >diff --git a/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp b/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp >index 3b7f2871520..dd8cd91afad 100644 >--- a/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp >+++ b/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp >@@ -3324,9 +3324,9 @@ void webkit_web_view_run_javascript(WebKitWebView* webView, const gchar* script, > g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); > g_return_if_fail(script); > >- GTask* task = g_task_new(webView, cancellable, callback, userData); >- getPage(webView).runJavaScriptInMainFrame(String::fromUTF8(script), true, [task](API::SerializedScriptValue* serializedScriptValue, bool, const ExceptionDetails& exceptionDetails, WebKit::CallbackBase::Error) { >- webkitWebViewRunJavaScriptCallback(serializedScriptValue, exceptionDetails, adoptGRef(task).get()); >+ GRefPtr<GTask> task = adoptGRef(g_task_new(webView, cancellable, callback, userData)); >+ getPage(webView).runJavaScriptInMainFrame(String::fromUTF8(script), true, [task = WTFMove(task)](API::SerializedScriptValue* serializedScriptValue, bool, const ExceptionDetails& exceptionDetails, WebKit::CallbackBase::Error) { >+ webkitWebViewRunJavaScriptCallback(serializedScriptValue, exceptionDetails, task.get()); > }); > } > >@@ -3393,8 +3393,58 @@ void webkit_web_view_run_javascript(WebKitWebView* webView, const gchar* script, > */ > WebKitJavascriptResult* webkit_web_view_run_javascript_finish(WebKitWebView* webView, GAsyncResult* result, GError** error) > { >- g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); >- g_return_val_if_fail(g_task_is_valid(result, webView), 0); >+ g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), nullptr); >+ g_return_val_if_fail(g_task_is_valid(result, webView), nullptr); >+ >+ return static_cast<WebKitJavascriptResult*>(g_task_propagate_pointer(G_TASK(result), error)); >+} >+ >+/** >+ * webkit_web_view_run_javascript_in_world: >+ * @web_view: a #WebKitWebView >+ * @script: the script to run >+ * @world_name: the name of a #WebKitScriptWorld >+ * @cancellable: (allow-none): a #GCancellable or %NULL to ignore >+ * @callback: (scope async): a #GAsyncReadyCallback to call when the script finished >+ * @user_data: (closure): the data to pass to callback function >+ * >+ * Asynchronously run @script in the script world with name @world_name of the current page context in @web_view. >+ * If WebKitSettings:enable-javascript is FALSE, this method will do nothing. >+ * >+ * When the operation is finished, @callback will be called. You can then call >+ * webkit_web_view_run_javascript_in_world_finish() to get the result of the operation. >+ * >+ * Since: 2.22 >+ */ >+void webkit_web_view_run_javascript_in_world(WebKitWebView* webView, const gchar* script, const char* worldName, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) >+{ >+ g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); >+ g_return_if_fail(script); >+ g_return_if_fail(worldName); >+ >+ GRefPtr<GTask> task = adoptGRef(g_task_new(webView, cancellable, callback, userData)); >+ getPage(webView).runJavaScriptInMainFrameScriptWorld(String::fromUTF8(script), true, String::fromUTF8(worldName), [task = WTFMove(task)](API::SerializedScriptValue* serializedScriptValue, bool, const ExceptionDetails& exceptionDetails, WebKit::CallbackBase::Error) { >+ webkitWebViewRunJavaScriptCallback(serializedScriptValue, exceptionDetails, task.get()); >+ }); >+} >+ >+/** >+ * webkit_web_view_run_javascript_in_world_finish: >+ * @web_view: a #WebKitWebView >+ * @result: a #GAsyncResult >+ * @error: return location for error or %NULL to ignore >+ * >+ * Finish an asynchronous operation started with webkit_web_view_run_javascript_in_world(). >+ * >+ * Returns: (transfer full): a #WebKitJavascriptResult with the result of the last executed statement in @script >+ * or %NULL in case of error >+ * >+ * Since: 2.22 >+ */ >+WebKitJavascriptResult* webkit_web_view_run_javascript_in_world_finish(WebKitWebView* webView, GAsyncResult* result, GError** error) >+{ >+ g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), nullptr); >+ g_return_val_if_fail(g_task_is_valid(result, webView), nullptr); > > return static_cast<WebKitJavascriptResult*>(g_task_propagate_pointer(G_TASK(result), error)); > } >diff --git a/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h b/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h >index 03dfea538bf..8c219a3b008 100644 >--- a/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h >+++ b/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h >@@ -444,6 +444,18 @@ webkit_web_view_run_javascript_finish (WebKitWebView > GAsyncResult *result, > GError **error); > >+WEBKIT_API void >+webkit_web_view_run_javascript_in_world (WebKitWebView *web_view, >+ const gchar *script, >+ const gchar *world_name, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+WEBKIT_API WebKitJavascriptResult * >+webkit_web_view_run_javascript_in_world_finish (WebKitWebView *web_view, >+ GAsyncResult *result, >+ GError **error); >+ > WEBKIT_API void > webkit_web_view_run_javascript_from_gresource (WebKitWebView *web_view, > const gchar *resource, >diff --git a/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt b/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt >index 01f3951b61f..e97743a45e2 100644 >--- a/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt >+++ b/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt >@@ -207,6 +207,8 @@ webkit_web_view_get_inspector > webkit_web_view_get_javascript_global_context > webkit_web_view_run_javascript > webkit_web_view_run_javascript_finish >+webkit_web_view_run_javascript_in_world >+webkit_web_view_run_javascript_in_world_finish > webkit_web_view_run_javascript_from_gresource > webkit_web_view_run_javascript_from_gresource_finish > webkit_web_view_can_show_mime_type >@@ -1509,6 +1511,8 @@ webkit_frame_get_type > WebKitScriptWorld > webkit_script_world_get_default > webkit_script_world_new >+webkit_script_world_new_with_name >+webkit_script_world_get_name > > <SUBSECTION Standard> > WebKitScriptWorldClass >diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h b/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h >index 3c02f0d9073..2e389fd0b3c 100644 >--- a/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h >+++ b/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h >@@ -410,6 +410,18 @@ webkit_web_view_run_javascript_finish (WebKitWebView > GAsyncResult *result, > GError **error); > >+WEBKIT_API void >+webkit_web_view_run_javascript_in_world (WebKitWebView *web_view, >+ const gchar *script, >+ const gchar *world_name, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+WEBKIT_API WebKitJavascriptResult * >+webkit_web_view_run_javascript_in_world_finish (WebKitWebView *web_view, >+ GAsyncResult *result, >+ GError **error); >+ > WEBKIT_API void > webkit_web_view_run_javascript_from_gresource (WebKitWebView *web_view, > const gchar *resource, >diff --git a/Source/WebKit/UIProcess/WebPageProxy.cpp b/Source/WebKit/UIProcess/WebPageProxy.cpp >index c43c1b35746..b16079d3359 100644 >--- a/Source/WebKit/UIProcess/WebPageProxy.cpp >+++ b/Source/WebKit/UIProcess/WebPageProxy.cpp >@@ -3125,6 +3125,17 @@ void WebPageProxy::runJavaScriptInMainFrame(const String& script, bool forceUser > m_process->send(Messages::WebPage::RunJavaScriptInMainFrame(script, forceUserGesture, callbackID), m_pageID); > } > >+void WebPageProxy::runJavaScriptInMainFrameScriptWorld(const String& script, bool forceUserGesture, const String& worldName, WTF::Function<void(API::SerializedScriptValue*, bool hadException, const ExceptionDetails&, CallbackBase::Error)>&& callbackFunction) >+{ >+ if (!isValid()) { >+ callbackFunction(nullptr, false, { }, CallbackBase::Error::Unknown); >+ return; >+ } >+ >+ auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); >+ m_process->send(Messages::WebPage::RunJavaScriptInMainFrameScriptWorld(script, forceUserGesture, worldName, callbackID), m_pageID); >+} >+ > void WebPageProxy::getRenderTreeExternalRepresentation(WTF::Function<void (const String&, CallbackBase::Error)>&& callbackFunction) > { > if (!isValid()) { >diff --git a/Source/WebKit/UIProcess/WebPageProxy.h b/Source/WebKit/UIProcess/WebPageProxy.h >index eb8efc938c9..8c0ae271a41 100644 >--- a/Source/WebKit/UIProcess/WebPageProxy.h >+++ b/Source/WebKit/UIProcess/WebPageProxy.h >@@ -874,6 +874,7 @@ public: > void getSourceForFrame(WebFrameProxy*, WTF::Function<void (const String&, CallbackBase::Error)>&&); > void getWebArchiveOfFrame(WebFrameProxy*, Function<void (API::Data*, CallbackBase::Error)>&&); > void runJavaScriptInMainFrame(const String&, bool, WTF::Function<void (API::SerializedScriptValue*, bool hadException, const WebCore::ExceptionDetails&, CallbackBase::Error)>&& callbackFunction); >+ void runJavaScriptInMainFrameScriptWorld(const String&, bool, const String& worldName, WTF::Function<void(API::SerializedScriptValue*, bool hadException, const WebCore::ExceptionDetails&, CallbackBase::Error)>&& callbackFunction); > void forceRepaint(RefPtr<VoidCallback>&&); > > float headerHeight(WebFrameProxy&); >diff --git a/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitScriptWorld.cpp b/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitScriptWorld.cpp >index ae554fe1a9a..a499b323587 100644 >--- a/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitScriptWorld.cpp >+++ b/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitScriptWorld.cpp >@@ -50,6 +50,7 @@ struct _WebKitScriptWorldPrivate { > } > > RefPtr<InjectedBundleScriptWorld> scriptWorld; >+ CString name; > }; > > static guint signals[LAST_SIGNAL] = { 0, }; >@@ -100,8 +101,9 @@ void webkitScriptWorldWindowObjectCleared(WebKitScriptWorld* world, WebKitWebPag > > static WebKitScriptWorld* webkitScriptWorldCreate(Ref<InjectedBundleScriptWorld>&& scriptWorld) > { >- WebKitScriptWorld* world = WEBKIT_SCRIPT_WORLD(g_object_new(WEBKIT_TYPE_SCRIPT_WORLD, NULL)); >+ WebKitScriptWorld* world = WEBKIT_SCRIPT_WORLD(g_object_new(WEBKIT_TYPE_SCRIPT_WORLD, nullptr)); > world->priv->scriptWorld = WTFMove(scriptWorld); >+ world->priv->name = world->priv->scriptWorld->name().utf8(); > > ASSERT(!scriptWorlds().contains(world->priv->scriptWorld.get())); > scriptWorlds().add(world->priv->scriptWorld.get(), world); >@@ -138,6 +140,9 @@ WebKitScriptWorld* webkit_script_world_get_default(void) > * Creates a new isolated #WebKitScriptWorld. Scripts executed in > * isolated worlds have access to the DOM but not to other variable > * or functions created by the page. >+ * The #WebKitScriptWorld is created with a generated unique name, use >+ * webkit_script_world_new_with_name() if you want to create it with a >+ * custom name. > * You can get the JavaScript execution context of a #WebKitScriptWorld > * for a given #WebKitFrame with webkit_frame_get_javascript_context_for_script_world(). > * >@@ -149,3 +154,41 @@ WebKitScriptWorld* webkit_script_world_new(void) > { > return webkitScriptWorldCreate(InjectedBundleScriptWorld::create()); > } >+ >+/** >+ * webkit_script_world_new_with_name: >+ * @name: a name for the script world >+ * >+ * Creates a new isolated #WebKitScriptWorld with a name. Scripts executed in >+ * isolated worlds have access to the DOM but not to other variable >+ * or functions created by the page. >+ * You can get the JavaScript execution context of a #WebKitScriptWorld >+ * for a given #WebKitFrame with webkit_frame_get_javascript_context_for_script_world(). >+ * >+ * Returns: (transfer full): a new isolated #WebKitScriptWorld >+ * >+ * Since: 2.22 >+ */ >+WebKitScriptWorld* webkit_script_world_new_with_name(const char* name) >+{ >+ g_return_val_if_fail(name, nullptr); >+ >+ return webkitScriptWorldCreate(InjectedBundleScriptWorld::create(String::fromUTF8(name))); >+} >+ >+/** >+ * webkit_script_world_get_name: >+ * @world: a #WebKitScriptWorld >+ * >+ * Get the name of a #WebKitScriptWorld. >+ * >+ * Returns: the name of @world >+ * >+ * Since: 2.22 >+ */ >+const char* webkit_script_world_get_name(WebKitScriptWorld* world) >+{ >+ g_return_val_if_fail(WEBKIT_IS_SCRIPT_WORLD(world), nullptr); >+ >+ return world->priv->name.data(); >+} >diff --git a/Source/WebKit/WebProcess/InjectedBundle/API/gtk/WebKitScriptWorld.h b/Source/WebKit/WebProcess/InjectedBundle/API/gtk/WebKitScriptWorld.h >index cb0673e1dc3..2978a39e4d5 100644 >--- a/Source/WebKit/WebProcess/InjectedBundle/API/gtk/WebKitScriptWorld.h >+++ b/Source/WebKit/WebProcess/InjectedBundle/API/gtk/WebKitScriptWorld.h >@@ -56,13 +56,19 @@ struct _WebKitScriptWorldClass { > }; > > WEBKIT_API GType >-webkit_script_world_get_type (void); >+webkit_script_world_get_type (void); > > WEBKIT_API WebKitScriptWorld * >-webkit_script_world_get_default (void); >+webkit_script_world_get_default (void); > > WEBKIT_API WebKitScriptWorld * >-webkit_script_world_new (void); >+webkit_script_world_new (void); >+ >+WEBKIT_API WebKitScriptWorld * >+webkit_script_world_new_with_name (const char *name); >+ >+WEBKIT_API const char * >+webkit_script_world_get_name (WebKitScriptWorld *world); > > G_END_DECLS > >diff --git a/Source/WebKit/WebProcess/InjectedBundle/API/wpe/WebKitScriptWorld.h b/Source/WebKit/WebProcess/InjectedBundle/API/wpe/WebKitScriptWorld.h >index 218d790e561..9645c4c5434 100644 >--- a/Source/WebKit/WebProcess/InjectedBundle/API/wpe/WebKitScriptWorld.h >+++ b/Source/WebKit/WebProcess/InjectedBundle/API/wpe/WebKitScriptWorld.h >@@ -56,13 +56,19 @@ struct _WebKitScriptWorldClass { > }; > > WEBKIT_API GType >-webkit_script_world_get_type (void); >+webkit_script_world_get_type (void); > > WEBKIT_API WebKitScriptWorld * >-webkit_script_world_get_default (void); >+webkit_script_world_get_default (void); > > WEBKIT_API WebKitScriptWorld * >-webkit_script_world_new (void); >+webkit_script_world_new (void); >+ >+WEBKIT_API WebKitScriptWorld * >+webkit_script_world_new_with_name (const char *name); >+ >+WEBKIT_API const char * >+webkit_script_world_get_name (WebKitScriptWorld *world); > > G_END_DECLS > >diff --git a/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp b/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp >index d19b37e38ad..323b6004d94 100644 >--- a/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp >+++ b/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp >@@ -72,6 +72,15 @@ Ref<InjectedBundleScriptWorld> InjectedBundleScriptWorld::getOrCreate(DOMWrapper > return adoptRef(*new InjectedBundleScriptWorld(world, uniqueWorldName())); > } > >+InjectedBundleScriptWorld* InjectedBundleScriptWorld::find(const String& name) >+{ >+ for (auto* world : allWorlds().values()) { >+ if (world->name() == name) >+ return world; >+ } >+ return nullptr; >+} >+ > InjectedBundleScriptWorld& InjectedBundleScriptWorld::normalWorld() > { > static InjectedBundleScriptWorld& world = adoptRef(*new InjectedBundleScriptWorld(mainThreadNormalWorld(), String())).leakRef(); >diff --git a/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h b/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h >index 312de27d454..c8b6656db27 100644 >--- a/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h >+++ b/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h >@@ -42,6 +42,7 @@ public: > static Ref<InjectedBundleScriptWorld> create(); > static Ref<InjectedBundleScriptWorld> create(const String&); > static Ref<InjectedBundleScriptWorld> getOrCreate(WebCore::DOMWrapperWorld&); >+ static InjectedBundleScriptWorld* find(const String&); > static InjectedBundleScriptWorld& normalWorld(); > > virtual ~InjectedBundleScriptWorld(); >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.cpp b/Source/WebKit/WebProcess/WebPage/WebPage.cpp >index 29ef66169b2..564b5804ce0 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.cpp >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.cpp >@@ -2955,6 +2955,26 @@ void WebPage::runJavaScriptInMainFrame(const String& script, bool forceUserGestu > send(Messages::WebPageProxy::ScriptValueCallback(dataReference, hadException, details, callbackID)); > } > >+void WebPage::runJavaScriptInMainFrameScriptWorld(const String& script, bool forceUserGesture, const String& worldName, CallbackID callbackID) >+{ >+ RefPtr<SerializedScriptValue> serializedResultValue; >+ JSLockHolder lock(commonVM()); >+ bool hadException = true; >+ ExceptionDetails details; >+ if (auto* world = InjectedBundleScriptWorld::find(worldName)) { >+ if (JSValue resultValue = m_mainFrame->coreFrame()->script().executeScriptInWorld(world->coreWorld(), script, forceUserGesture, &details)) { >+ hadException = false; >+ serializedResultValue = SerializedScriptValue::create(m_mainFrame->jsContextForWorld(world), >+ toRef(m_mainFrame->coreFrame()->script().globalObject(world->coreWorld())->globalExec(), resultValue), nullptr); >+ } >+ } >+ >+ IPC::DataReference dataReference; >+ if (serializedResultValue) >+ dataReference = serializedResultValue->data(); >+ send(Messages::WebPageProxy::ScriptValueCallback(dataReference, hadException, details, callbackID)); >+} >+ > void WebPage::getContentsAsString(CallbackID callbackID) > { > String resultString = m_mainFrame->contentsAsString(); >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.h b/Source/WebKit/WebProcess/WebPage/WebPage.h >index 1699a91157b..3784dd04788 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.h >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.h >@@ -1220,6 +1220,7 @@ private: > void getSourceForFrame(uint64_t frameID, CallbackID); > void getWebArchiveOfFrame(uint64_t frameID, CallbackID); > void runJavaScriptInMainFrame(const String&, bool forceUserGesture, CallbackID); >+ void runJavaScriptInMainFrameScriptWorld(const String&, bool forceUserGesture, const String& worldName, CallbackID); > void forceRepaint(CallbackID); > void takeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, CallbackID); > >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.messages.in b/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >index 7e1503065a2..c518482acdc 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >@@ -176,6 +176,7 @@ messages -> WebPage LegacyReceiver { > GetSourceForFrame(uint64_t frameID, WebKit::CallbackID callbackID) > GetWebArchiveOfFrame(uint64_t frameID, WebKit::CallbackID callbackID) > RunJavaScriptInMainFrame(String script, bool forceUserGesture, WebKit::CallbackID callbackID) >+ RunJavaScriptInMainFrameScriptWorld(String script, bool forceUserGesture, String worldName, WebKit::CallbackID callbackID) > ForceRepaint(WebKit::CallbackID callbackID) > > #if PLATFORM(COCOA) >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 14ec354e850..b6709d59c13 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,23 @@ >+2018-06-01 Carlos Garcia Campos <cgarcia@igalia.com> >+ >+ [GTK][WPE] Add API run run javascript from a WebKitWebView in an isolated world >+ https://bugs.webkit.org/show_bug.cgi?id=186192 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add tests cases for the new API. >+ >+ * TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp: >+ (testWebViewRunJavaScript): >+ * TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp: >+ (methodCallCallback): >+ (webkit_web_extension_initialize_with_user_data): >+ * TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp: >+ (runJavaScriptInWorldReadyCallback): >+ (WebViewTest::runJavaScriptFromGResourceAndWaitUntilFinished): >+ (WebViewTest::runJavaScriptInWorldAndWaitUntilFinished): >+ * TestWebKitAPI/glib/WebKitGLib/WebViewTest.h: >+ > 2018-05-31 Frederic Wang <fwang@igalia.com> > > export-w3c-test-changes should use the new location & name of the WPT repo >diff --git a/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp b/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp >index fe12ecb976e..ba910243328 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp >+++ b/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp >@@ -373,6 +373,29 @@ static void testWebViewRunJavaScript(WebViewTest* test, gconstpointer) > javascriptResult = test->runJavaScriptAndWaitUntilFinished("foo();", &error.outPtr()); > g_assert(!javascriptResult); > g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED); >+ >+ // Values of the main world are not available in the isolated one. >+ javascriptResult = test->runJavaScriptInWorldAndWaitUntilFinished("a", "WebExtensionTestScriptWorld", &error.outPtr()); >+ g_assert(!javascriptResult); >+ g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED); >+ >+ javascriptResult = test->runJavaScriptInWorldAndWaitUntilFinished("a = 50", "WebExtensionTestScriptWorld", &error.outPtr()); >+ g_assert(javascriptResult); >+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult))); >+ g_assert(!error.get()); >+ g_assert_cmpfloat(WebViewTest::javascriptResultToNumber(javascriptResult), ==, 50); >+ >+ // Values of the isolated world are not available in the normal one. >+ javascriptResult = test->runJavaScriptAndWaitUntilFinished("a", &error.outPtr()); >+ g_assert(javascriptResult); >+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult))); >+ g_assert(!error.get()); >+ g_assert_cmpfloat(WebViewTest::javascriptResultToNumber(javascriptResult), ==, 25); >+ >+ // Running a script in a world that doesn't exist should fail. >+ javascriptResult = test->runJavaScriptInWorldAndWaitUntilFinished("a", "InvalidScriptWorld", &error.outPtr()); >+ g_assert(!javascriptResult); >+ g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED); > } > > class FullScreenClientTest: public WebViewTest { >diff --git a/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp b/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp >index 5891faa38ac..97a75e5141e 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp >+++ b/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp >@@ -486,6 +486,7 @@ static void methodCallCallback(GDBusConnection* connection, const char* sender, > > GRefPtr<WebKitScriptWorld> world = adoptGRef(webkit_script_world_new()); > g_assert(webkit_script_world_get_default() != world.get()); >+ g_assert(g_str_has_prefix(webkit_script_world_get_name(world.get()), "UniqueWorld_")); > WebKitFrame* frame = webkit_web_page_get_main_frame(page); > GRefPtr<JSCContext> jsContext = adoptGRef(webkit_frame_get_js_context_for_script_world(frame, world.get())); > GRefPtr<JSCValue> result = adoptGRef(jsc_context_evaluate(jsContext.get(), script, -1)); >@@ -568,8 +569,13 @@ static void registerGResource(void) > > extern "C" void webkit_web_extension_initialize_with_user_data(WebKitWebExtension* extension, GVariant* userData) > { >+ WebKitScriptWorld* isolatedWorld = webkit_script_world_new_with_name("WebExtensionTestScriptWorld"); >+ g_assert(WEBKIT_IS_SCRIPT_WORLD(isolatedWorld)); >+ g_assert_cmpstr(webkit_script_world_get_name(isolatedWorld), ==, "WebExtensionTestScriptWorld"); >+ g_object_set_data_full(G_OBJECT(extension), "wk-script-world", isolatedWorld, g_object_unref); >+ > g_signal_connect(extension, "page-created", G_CALLBACK(pageCreatedCallback), extension); >- g_signal_connect(webkit_script_world_get_default(), "window-object-cleared", G_CALLBACK(windowObjectCleared), 0); >+ g_signal_connect(webkit_script_world_get_default(), "window-object-cleared", G_CALLBACK(windowObjectCleared), nullptr); > > registerGResource(); > >diff --git a/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp b/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp >index eed080c792a..3c095c37b42 100644 >--- a/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp >+++ b/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp >@@ -271,6 +271,12 @@ static void runJavaScriptFromGResourceReadyCallback(GObject*, GAsyncResult* resu > g_main_loop_quit(test->m_mainLoop); > } > >+static void runJavaScriptInWorldReadyCallback(GObject*, GAsyncResult* result, WebViewTest* test) >+{ >+ test->m_javascriptResult = webkit_web_view_run_javascript_in_world_finish(test->m_webView, result, test->m_javascriptError); >+ g_main_loop_quit(test->m_mainLoop); >+} >+ > WebKitJavascriptResult* WebViewTest::runJavaScriptAndWaitUntilFinished(const char* javascript, GError** error) > { > if (m_javascriptResult) >@@ -295,6 +301,18 @@ WebKitJavascriptResult* WebViewTest::runJavaScriptFromGResourceAndWaitUntilFinis > return m_javascriptResult; > } > >+WebKitJavascriptResult* WebViewTest::runJavaScriptInWorldAndWaitUntilFinished(const char* javascript, const char* world, GError** error) >+{ >+ if (m_javascriptResult) >+ webkit_javascript_result_unref(m_javascriptResult); >+ m_javascriptResult = 0; >+ m_javascriptError = error; >+ webkit_web_view_run_javascript_in_world(m_webView, javascript, world, nullptr, reinterpret_cast<GAsyncReadyCallback>(runJavaScriptInWorldReadyCallback), this); >+ g_main_loop_run(m_mainLoop); >+ >+ return m_javascriptResult; >+} >+ > char* WebViewTest::javascriptResultToCString(WebKitJavascriptResult* javascriptResult) > { > auto* value = webkit_javascript_result_get_js_value(javascriptResult); >diff --git a/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.h b/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.h >index 96d2331cd78..2d2b31f78b7 100644 >--- a/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.h >+++ b/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.h >@@ -71,6 +71,7 @@ public: > > WebKitJavascriptResult* runJavaScriptAndWaitUntilFinished(const char* javascript, GError**); > WebKitJavascriptResult* runJavaScriptFromGResourceAndWaitUntilFinished(const char* resource, GError**); >+ WebKitJavascriptResult* runJavaScriptInWorldAndWaitUntilFinished(const char* javascript, const char* world, GError**); > > // Javascript result helpers. > static char* javascriptResultToCString(WebKitJavascriptResult*);
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
Flags:
mcatanzaro
:
review+
ews-watchlist
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 186192
: 341754 |
341760