Diff
Modified: trunk/Source/WebCore/ChangeLog (233751 => 233752)
--- trunk/Source/WebCore/ChangeLog 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebCore/ChangeLog 2018-07-12 02:32:19 UTC (rev 233752)
@@ -1,5 +1,26 @@
2018-07-11 Alex Christensen <[email protected]>
+ Add SPI for immediate injection of user scripts
+ https://bugs.webkit.org/show_bug.cgi?id=173342
+ <rdar://problem/29202285>
+
+ Reviewed by Brady Eidson, Youenn Fablet, and Geoff Garen.
+
+ The new SPI is WKUserContentController._addUserScriptImmediately.
+ It is covered by new API tests.
+ Existing functionality remains unchanged unless the new SPI is adopted.
+
+ * page/Frame.cpp:
+ (WebCore::Frame::injectUserScripts):
+ (WebCore::Frame::injectUserScriptImmediately):
+ Move injection functionality to allow us to call it directly from the new SPI.
+ * page/Frame.h:
+ * page/Page.cpp:
+ (WebCore::Page::forEachPage):
+ * page/Page.h:
+
+2018-07-11 Alex Christensen <[email protected]>
+
Reduce size of WebCore::URL
https://bugs.webkit.org/show_bug.cgi?id=186820
Modified: trunk/Source/WebCore/page/Frame.cpp (233751 => 233752)
--- trunk/Source/WebCore/page/Frame.cpp 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebCore/page/Frame.cpp 2018-07-12 02:32:19 UTC (rev 233752)
@@ -735,20 +735,25 @@
return;
m_page->userContentProvider().forEachUserScript([this, protectedThis = makeRef(*this), injectionTime](DOMWrapperWorld& world, const UserScript& script) {
- auto* document = this->document();
- if (!document)
- return;
- if (script.injectedFrames() == InjectInTopFrameOnly && ownerElement())
- return;
-
- if (script.injectionTime() == injectionTime && UserContentURLPattern::matchesPatterns(document->url(), script.whitelist(), script.blacklist())) {
- if (m_page)
- m_page->setAsRunningUserScripts();
- m_script->evaluateInWorld(ScriptSourceCode(script.source(), script.url()), world);
- }
+ if (script.injectionTime() == injectionTime)
+ injectUserScriptImmediately(world, script);
});
}
+void Frame::injectUserScriptImmediately(DOMWrapperWorld& world, const UserScript& script)
+{
+ auto* document = this->document();
+ if (!document)
+ return;
+ if (script.injectedFrames() == InjectInTopFrameOnly && !isMainFrame())
+ return;
+ if (!UserContentURLPattern::matchesPatterns(document->url(), script.whitelist(), script.blacklist()))
+ return;
+ if (m_page)
+ m_page->setAsRunningUserScripts();
+ m_script->evaluateInWorld(ScriptSourceCode(script.source(), script.url()), world);
+}
+
RenderView* Frame::contentRenderer() const
{
return document() ? document()->renderView() : nullptr;
Modified: trunk/Source/WebCore/page/Frame.h (233751 => 233752)
--- trunk/Source/WebCore/page/Frame.h 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebCore/page/Frame.h 2018-07-12 02:32:19 UTC (rev 233752)
@@ -175,7 +175,8 @@
// ======== All public functions below this point are candidates to move out of Frame into another class. ========
- void injectUserScripts(UserScriptInjectionTime);
+ WEBCORE_EXPORT void injectUserScripts(UserScriptInjectionTime);
+ WEBCORE_EXPORT void injectUserScriptImmediately(DOMWrapperWorld&, const UserScript&);
WEBCORE_EXPORT String layerTreeAsText(LayerTreeFlags = 0) const;
WEBCORE_EXPORT String trackedRepaintRectsAsText() const;
Modified: trunk/Source/WebCore/page/Page.h (233751 => 233752)
--- trunk/Source/WebCore/page/Page.h 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebCore/page/Page.h 2018-07-12 02:32:19 UTC (rev 233752)
@@ -203,7 +203,7 @@
PageGroup& group();
- static void forEachPage(const WTF::Function<void(Page&)>&);
+ WEBCORE_EXPORT static void forEachPage(const WTF::Function<void(Page&)>&);
void incrementSubframeCount() { ++m_subframeCount; }
void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
Modified: trunk/Source/WebKit/ChangeLog (233751 => 233752)
--- trunk/Source/WebKit/ChangeLog 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/ChangeLog 2018-07-12 02:32:19 UTC (rev 233752)
@@ -1,3 +1,33 @@
+2018-07-11 Alex Christensen <[email protected]>
+
+ Add SPI for immediate injection of user scripts
+ https://bugs.webkit.org/show_bug.cgi?id=173342
+ <rdar://problem/29202285>
+
+ Reviewed by Brady Eidson, Youenn Fablet, and Geoff Garen.
+
+ * UIProcess/API/C/WKPageGroup.cpp:
+ (WKPageGroupAddUserScript):
+ * UIProcess/API/C/WKUserContentControllerRef.cpp:
+ (WKUserContentControllerAddUserScript):
+ * UIProcess/API/Cocoa/WKUserContentController.mm:
+ (-[WKUserContentController addUserScript:]):
+ (-[WKUserContentController _addUserScriptImmediately:]):
+ * UIProcess/API/Cocoa/WKUserContentControllerPrivate.h:
+ * UIProcess/UserContent/WebUserContentControllerProxy.cpp:
+ (WebKit::WebUserContentControllerProxy::addUserScript):
+ * UIProcess/UserContent/WebUserContentControllerProxy.h:
+ * WebProcess/UserContent/WebUserContentController.cpp:
+ (WebKit::WebUserContentController::addUserScripts):
+ (WebKit::WebUserContentController::addUserScriptInternal):
+ If we are to inject the script internally, inject it into the appropriate pages.
+ If we're injecting into the top frame only, there's no need to traverse the frame tree.
+ (WebKit::WebUserContentController::addUserScript):
+ * WebProcess/UserContent/WebUserContentController.h:
+ * WebProcess/UserContent/WebUserContentController.messages.in:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::m_cpuLimit):
+
2018-07-11 Simon Fraser <[email protected]>
[iOS WK2] Address a possible cause of missing tiles
Modified: trunk/Source/WebKit/UIProcess/API/C/WKPageGroup.cpp (233751 => 233752)
--- trunk/Source/WebKit/UIProcess/API/C/WKPageGroup.cpp 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/UIProcess/API/C/WKPageGroup.cpp 2018-07-12 02:32:19 UTC (rev 233752)
@@ -31,9 +31,11 @@
#include "APIUserContentWorld.h"
#include "APIUserScript.h"
#include "APIUserStyleSheet.h"
+#include "InjectUserScriptImmediately.h"
#include "WKAPICast.h"
#include "WebPageGroup.h"
#include "WebPreferences.h"
+#include "WebUserContentController.h"
#include "WebUserContentControllerProxy.h"
using namespace WebKit;
@@ -98,7 +100,7 @@
auto url = "" ? WebCore::blankURL() : WebCore::URL(WebCore::URL(), baseURLString);
Ref<API::UserScript> userScript = API::UserScript::create(WebCore::UserScript { WTFMove(source), WTFMove(url), whitelist ? whitelist->toStringVector() : Vector<String>(), blacklist ? blacklist->toStringVector() : Vector<String>(), toUserScriptInjectionTime(injectionTime), toUserContentInjectedFrames(injectedFrames) }, API::UserContentWorld::normalWorld());
- toImpl(pageGroupRef)->userContentController().addUserScript(userScript.get());
+ toImpl(pageGroupRef)->userContentController().addUserScript(userScript.get(), InjectUserScriptImmediately::No);
}
void WKPageGroupRemoveAllUserScripts(WKPageGroupRef pageGroupRef)
Modified: trunk/Source/WebKit/UIProcess/API/C/WKUserContentControllerRef.cpp (233751 => 233752)
--- trunk/Source/WebKit/UIProcess/API/C/WKUserContentControllerRef.cpp 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/UIProcess/API/C/WKUserContentControllerRef.cpp 2018-07-12 02:32:19 UTC (rev 233752)
@@ -29,6 +29,7 @@
#include "APIArray.h"
#include "APIContentRuleList.h"
#include "APIUserScript.h"
+#include "InjectUserScriptImmediately.h"
#include "WKAPICast.h"
#include "WebUserContentControllerProxy.h"
@@ -52,7 +53,7 @@
void WKUserContentControllerAddUserScript(WKUserContentControllerRef userContentControllerRef, WKUserScriptRef userScriptRef)
{
- toImpl(userContentControllerRef)->addUserScript(*toImpl(userScriptRef));
+ toImpl(userContentControllerRef)->addUserScript(*toImpl(userScriptRef), InjectUserScriptImmediately::No);
}
void WKUserContentControllerRemoveAllUserScripts(WKUserContentControllerRef userContentControllerRef)
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUserContentController.mm (233751 => 233752)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUserContentController.mm 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUserContentController.mm 2018-07-12 02:32:19 UTC (rev 233752)
@@ -30,6 +30,7 @@
#import "APISerializedScriptValue.h"
#import "APIUserContentWorld.h"
+#import "InjectUserScriptImmediately.h"
#import "WKContentRuleListInternal.h"
#import "WKFrameInfoInternal.h"
#import "WKNSArray.h"
@@ -89,7 +90,7 @@
- (void)addUserScript:(WKUserScript *)userScript
{
- _userContentControllerProxy->addUserScript(*userScript->_userScript);
+ _userContentControllerProxy->addUserScript(*userScript->_userScript, WebKit::InjectUserScriptImmediately::No);
}
- (void)removeAllUserScripts
@@ -177,6 +178,11 @@
_userContentControllerProxy->removeAllUserScripts(*userContentWorld->_userContentWorld);
}
+- (void)_addUserScriptImmediately:(WKUserScript *)userScript
+{
+ _userContentControllerProxy->addUserScript(*userScript->_userScript, WebKit::InjectUserScriptImmediately::Yes);
+}
+
- (void)_addUserContentFilter:(_WKUserContentFilter *)userContentFilter
{
#if ENABLE(CONTENT_EXTENSIONS)
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUserContentControllerPrivate.h (233751 => 233752)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUserContentControllerPrivate.h 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUserContentControllerPrivate.h 2018-07-12 02:32:19 UTC (rev 233752)
@@ -37,6 +37,8 @@
- (void)_removeUserScript:(WKUserScript *)userScript WK_API_AVAILABLE(macosx(10.12), ios(10.0));
- (void)_removeAllUserScriptsAssociatedWithUserContentWorld:(_WKUserContentWorld *)userContentWorld WK_API_AVAILABLE(macosx(10.12), ios(10.0));
+- (void)_addUserScriptImmediately:(WKUserScript *)userScript WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
- (void)_addUserContentFilter:(_WKUserContentFilter *)userContentFilter WK_API_AVAILABLE(macosx(10.11), ios(9.0));
- (void)_removeUserContentFilter:(NSString *)userContentFilterName WK_API_AVAILABLE(macosx(10.11), ios(9.0));
- (void)_removeAllUserContentFilters WK_API_AVAILABLE(macosx(10.11), ios(9.0));
Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp (233751 => 233752)
--- trunk/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp 2018-07-12 02:32:19 UTC (rev 233752)
@@ -21,6 +21,7 @@
#include "WebKitUserContentManager.h"
#include "APISerializedScriptValue.h"
+#include "InjectUserScriptImmediately.h"
#include "WebKitJavascriptResultPrivate.h"
#include "WebKitUserContentManagerPrivate.h"
#include "WebKitUserContentPrivate.h"
@@ -163,7 +164,7 @@
{
g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager));
g_return_if_fail(script);
- manager->priv->userContentController->addUserScript(webkitUserScriptGetUserScript(script));
+ manager->priv->userContentController->addUserScript(webkitUserScriptGetUserScript(script), InjectUserScriptImmediately::No);
}
/**
Modified: trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp (233751 => 233752)
--- trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp 2018-07-12 02:32:19 UTC (rev 233752)
@@ -31,6 +31,7 @@
#include "APIUserScript.h"
#include "APIUserStyleSheet.h"
#include "DataReference.h"
+#include "InjectUserScriptImmediately.h"
#include "NetworkContentRuleListManagerMessages.h"
#include "NetworkProcessProxy.h"
#include "WebPageCreationParameters.h"
@@ -167,7 +168,7 @@
process->send(Messages::WebUserContentController::RemoveUserContentWorlds(worldsToRemove), identifier().toUInt64());
}
-void WebUserContentControllerProxy::addUserScript(API::UserScript& userScript)
+void WebUserContentControllerProxy::addUserScript(API::UserScript& userScript, InjectUserScriptImmediately immediately)
{
Ref<API::UserContentWorld> world = userScript.userContentWorld();
@@ -176,7 +177,7 @@
m_userScripts->elements().append(&userScript);
for (WebProcessProxy* process : m_processes)
- process->send(Messages::WebUserContentController::AddUserScripts({ { userScript.identifier(), world->identifier(), userScript.userScript() } }), identifier().toUInt64());
+ process->send(Messages::WebUserContentController::AddUserScripts({ { userScript.identifier(), world->identifier(), userScript.userScript() } }, immediately), identifier().toUInt64());
}
void WebUserContentControllerProxy::removeUserScript(API::UserScript& userScript)
Modified: trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.h (233751 => 233752)
--- trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.h 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.h 2018-07-12 02:32:19 UTC (rev 233752)
@@ -59,6 +59,7 @@
class WebScriptMessageHandler;
struct FrameInfoData;
struct WebPageCreationParameters;
+enum class InjectUserScriptImmediately;
class WebUserContentControllerProxy : public API::ObjectImpl<API::Object::Type::UserContentController>, private IPC::MessageReceiver {
public:
@@ -75,7 +76,7 @@
void removeProcess(WebProcessProxy&);
API::Array& userScripts() { return m_userScripts.get(); }
- void addUserScript(API::UserScript&);
+ void addUserScript(API::UserScript&, InjectUserScriptImmediately);
void removeUserScript(API::UserScript&);
void removeAllUserScripts(API::UserContentWorld&);
void removeAllUserScripts();
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (233751 => 233752)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2018-07-12 02:32:19 UTC (rev 233752)
@@ -3318,6 +3318,7 @@
4103FBA22061BDB800C2EAF8 /* NetworkLoadChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkLoadChecker.cpp; path = NetworkProcess/NetworkLoadChecker.cpp; sourceTree = "<group>"; };
410482CB1DDD2FB500F006D0 /* RTCNetwork.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCNetwork.cpp; sourceTree = "<group>"; };
410482CC1DDD2FB500F006D0 /* RTCNetwork.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCNetwork.h; sourceTree = "<group>"; };
+ 4111436320F677B10026F912 /* InjectUserScriptImmediately.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectUserScriptImmediately.h; sourceTree = "<group>"; };
4112B5471F9FD3AB00E67875 /* NetworkRTCResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkRTCResolver.cpp; path = NetworkProcess/webrtc/NetworkRTCResolver.cpp; sourceTree = "<group>"; };
4112B5471F9FD3AB00E67986 /* NetworkRTCResolverCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkRTCResolverCocoa.cpp; path = NetworkProcess/webrtc/NetworkRTCResolverCocoa.cpp; sourceTree = "<group>"; };
4112B5481F9FD3AC00E67875 /* NetworkRTCResolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkRTCResolver.h; path = NetworkProcess/webrtc/NetworkRTCResolver.h; sourceTree = "<group>"; };
@@ -5467,6 +5468,7 @@
1AAF08AA1926930B00B6390C /* UserContent */ = {
isa = PBXGroup;
children = (
+ 4111436320F677B10026F912 /* InjectUserScriptImmediately.h */,
1AAF08AB1926936700B6390C /* WebUserContentController.cpp */,
1AAF08AC1926936700B6390C /* WebUserContentController.h */,
1AAF08B419269E2400B6390C /* WebUserContentController.messages.in */,
Added: trunk/Source/WebKit/WebProcess/UserContent/InjectUserScriptImmediately.h (0 => 233752)
--- trunk/Source/WebKit/WebProcess/UserContent/InjectUserScriptImmediately.h (rev 0)
+++ trunk/Source/WebKit/WebProcess/UserContent/InjectUserScriptImmediately.h 2018-07-12 02:32:19 UTC (rev 233752)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/EnumTraits.h>
+
+namespace WebKit {
+
+enum class InjectUserScriptImmediately { No, Yes };
+
+}
+
+namespace WTF {
+
+template<> struct EnumTraits<WebKit::InjectUserScriptImmediately> {
+ using values = EnumValues<
+ WebKit::InjectUserScriptImmediately,
+ WebKit::InjectUserScriptImmediately::No,
+ WebKit::InjectUserScriptImmediately::Yes
+ >;
+};
+
+}
Modified: trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.cpp (233751 => 233752)
--- trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.cpp 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.cpp 2018-07-12 02:32:19 UTC (rev 233752)
@@ -28,6 +28,7 @@
#include "DataReference.h"
#include "FrameInfoData.h"
+#include "InjectUserScriptImmediately.h"
#include "InjectedBundleScriptWorld.h"
#include "WebCompiledContentRuleList.h"
#include "WebFrame.h"
@@ -36,6 +37,7 @@
#include "WebUserContentControllerMessages.h"
#include "WebUserContentControllerProxyMessages.h"
#include <WebCore/DOMWrapperWorld.h>
+#include <WebCore/Frame.h>
#include <WebCore/SecurityOriginData.h>
#include <WebCore/SerializedScriptValue.h>
#include <WebCore/UserStyleSheet.h>
@@ -122,7 +124,7 @@
}
}
-void WebUserContentController::addUserScripts(const Vector<WebUserScriptData>& userScripts)
+void WebUserContentController::addUserScripts(Vector<WebUserScriptData>&& userScripts, InjectUserScriptImmediately immediately)
{
for (const auto& userScriptData : userScripts) {
auto it = worldMap().find(userScriptData.worldIdentifier);
@@ -132,7 +134,7 @@
}
UserScript script = userScriptData.userScript;
- addUserScriptInternal(*it->value.first, userScriptData.identifier, WTFMove(script));
+ addUserScriptInternal(*it->value.first, userScriptData.identifier, WTFMove(script), immediately);
}
}
@@ -360,8 +362,24 @@
}
#endif
-void WebUserContentController::addUserScriptInternal(InjectedBundleScriptWorld& world, uint64_t userScriptIdentifier, UserScript&& userScript)
+void WebUserContentController::addUserScriptInternal(InjectedBundleScriptWorld& world, uint64_t userScriptIdentifier, UserScript&& userScript, InjectUserScriptImmediately immediately)
{
+ if (immediately == InjectUserScriptImmediately::Yes) {
+ Page::forEachPage([&] (auto& page) {
+ if (&page.userContentProvider() != this)
+ return;
+
+ auto& mainFrame = page.mainFrame();
+ if (userScript.injectedFrames() == InjectInTopFrameOnly) {
+ mainFrame.injectUserScriptImmediately(world.coreWorld(), userScript);
+ return;
+ }
+
+ for (auto* frame = &mainFrame; frame; frame = frame->tree().traverseNext(&mainFrame))
+ frame->injectUserScriptImmediately(world.coreWorld(), userScript);
+ });
+ }
+
auto& scriptsInWorld = m_userScripts.ensure(&world, [] { return Vector<std::pair<uint64_t, WebCore::UserScript>>(); }).iterator->value;
scriptsInWorld.append(std::make_pair(userScriptIdentifier, WTFMove(userScript)));
}
@@ -368,7 +386,7 @@
void WebUserContentController::addUserScript(InjectedBundleScriptWorld& world, UserScript&& userScript)
{
- addUserScriptInternal(world, 0, WTFMove(userScript));
+ addUserScriptInternal(world, 0, WTFMove(userScript), InjectUserScriptImmediately::No);
}
void WebUserContentController::removeUserScriptWithURL(InjectedBundleScriptWorld& world, const URL& url)
Modified: trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.h (233751 => 233752)
--- trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.h 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.h 2018-07-12 02:32:19 UTC (rev 233752)
@@ -47,6 +47,7 @@
class InjectedBundleScriptWorld;
class WebCompiledContentRuleListData;
class WebUserMessageHandlerDescriptorProxy;
+enum class InjectUserScriptImmediately;
class WebUserContentController final : public WebCore::UserContentProvider, private IPC::MessageReceiver {
public:
@@ -64,7 +65,7 @@
void removeAllUserContent();
void addUserContentWorlds(const Vector<std::pair<uint64_t, String>>&);
- void addUserScripts(const Vector<WebUserScriptData>&);
+ void addUserScripts(Vector<WebUserScriptData>&&, InjectUserScriptImmediately);
void addUserStyleSheets(const Vector<WebUserStyleSheetData>&);
void addUserScriptMessageHandlers(const Vector<WebScriptMessageHandlerData>&);
#if ENABLE(CONTENT_EXTENSIONS)
@@ -103,7 +104,7 @@
void removeAllContentRuleLists();
#endif
- void addUserScriptInternal(InjectedBundleScriptWorld&, uint64_t userScriptIdentifier, WebCore::UserScript&&);
+ void addUserScriptInternal(InjectedBundleScriptWorld&, uint64_t userScriptIdentifier, WebCore::UserScript&&, InjectUserScriptImmediately);
void removeUserScriptInternal(InjectedBundleScriptWorld&, uint64_t userScriptIdentifier);
void addUserStyleSheetInternal(InjectedBundleScriptWorld&, uint64_t userStyleSheetIdentifier, WebCore::UserStyleSheet&&);
void removeUserStyleSheetInternal(InjectedBundleScriptWorld&, uint64_t userStyleSheetIdentifier);
Modified: trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.messages.in (233751 => 233752)
--- trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.messages.in 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.messages.in 2018-07-12 02:32:19 UTC (rev 233752)
@@ -27,7 +27,7 @@
AddUserContentWorlds(Vector<std::pair<uint64_t, String>> worlds);
RemoveUserContentWorlds(Vector<uint64_t> worldIdentifiers);
- AddUserScripts(Vector<struct WebKit::WebUserScriptData> userScripts);
+ AddUserScripts(Vector<struct WebKit::WebUserScriptData> userScripts, enum WebKit::InjectUserScriptImmediately immediately);
RemoveUserScript(uint64_t worldIdentifier, uint64_t identifier);
RemoveAllUserScripts(Vector<uint64_t> worldIdentifiers);
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (233751 => 233752)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2018-07-12 02:32:19 UTC (rev 233752)
@@ -40,6 +40,7 @@
#include "FindController.h"
#include "FormDataReference.h"
#include "GeolocationPermissionRequestManager.h"
+#include "InjectUserScriptImmediately.h"
#include "InjectedBundle.h"
#include "InjectedBundleBackForwardList.h"
#include "InjectedBundleScriptWorld.h"
@@ -612,7 +613,7 @@
registerURLSchemeHandler(iterator.value, iterator.key);
m_userContentController->addUserContentWorlds(parameters.userContentWorlds);
- m_userContentController->addUserScripts(parameters.userScripts);
+ m_userContentController->addUserScripts(WTFMove(parameters.userScripts), InjectUserScriptImmediately::No);
m_userContentController->addUserStyleSheets(parameters.userStyleSheets);
m_userContentController->addUserScriptMessageHandlers(parameters.messageHandlers);
#if ENABLE(CONTENT_EXTENSIONS)
Modified: trunk/Tools/ChangeLog (233751 => 233752)
--- trunk/Tools/ChangeLog 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Tools/ChangeLog 2018-07-12 02:32:19 UTC (rev 233752)
@@ -1,3 +1,15 @@
+2018-07-11 Alex Christensen <[email protected]>
+
+ Add SPI for immediate injection of user scripts
+ https://bugs.webkit.org/show_bug.cgi?id=173342
+ <rdar://problem/29202285>
+
+ Reviewed by Brady Eidson, Youenn Fablet, and Geoff Garen.
+
+ * TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm:
+ (waitForMessage):
+ (TEST):
+
2018-07-11 Myles C. Maxfield <[email protected]>
Move WHLSL spec work to the W3C GPUWeb GitHub repository
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm (233751 => 233752)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm 2018-07-12 02:09:12 UTC (rev 233751)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm 2018-07-12 02:32:19 UTC (rev 233752)
@@ -37,6 +37,7 @@
#import <WebKit/_WKUserContentWorld.h>
#import <WebKit/_WKUserStyleSheet.h>
#import <wtf/RetainPtr.h>
+#import <wtf/Vector.h>
#if WK_API_ENABLED
@@ -55,7 +56,7 @@
@end
static bool receivedScriptMessage;
-static RetainPtr<WKScriptMessage> lastScriptMessage;
+static Vector<RetainPtr<WKScriptMessage>> scriptMessages;
@interface ScriptMessageHandler : NSObject <WKScriptMessageHandler>
@end
@@ -65,7 +66,7 @@
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
{
receivedScriptMessage = true;
- lastScriptMessage = message;
+ scriptMessages.append(message);
}
@end
@@ -88,7 +89,7 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(@"Hello", (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"Hello", (NSString *)[scriptMessages[0] body]);
}
TEST(WKUserContentController, ScriptMessageHandlerBasicPostIsolatedWorld)
@@ -115,7 +116,7 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(@"Hello", (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"Hello", (NSString *)[scriptMessages[0] body]);
if (!isDoneWithNavigation)
TestWebKitAPI::Util::run(&isDoneWithNavigation);
@@ -166,7 +167,7 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(@"PASS", (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"PASS", (NSString *)[scriptMessages[0] body]);
[userContentController removeScriptMessageHandlerForName:@"handlerToRemove"];
@@ -181,7 +182,7 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(@"PASS", (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"PASS", (NSString *)[scriptMessages[0] body]);
}
TEST(WKUserContentController, ScriptMessageHandlerCallRemovedHandler)
@@ -214,7 +215,7 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(@"PASS", (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"PASS", (NSString *)[scriptMessages[0] body]);
}
static RetainPtr<WKWebView> webViewForScriptMessageHandlerMultipleHandlerRemovalTest(WKWebViewConfiguration *configuration)
@@ -255,7 +256,7 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(@"PASS", (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"PASS", (NSString *)[scriptMessages[0] body]);
}
#if !PLATFORM(IOS) // FIXME: hangs in the iOS simulator
@@ -275,10 +276,9 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
- EXPECT_WK_STREQ(@"First Message", (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"First Message", (NSString *)[scriptMessages[0] body]);
receivedScriptMessage = false;
- lastScriptMessage = nullptr;
[webView loadRequest:request];
[webView _test_waitForDidFinishNavigation];
@@ -287,7 +287,7 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
- EXPECT_WK_STREQ(@"Second Message", (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"Second Message", (NSString *)[scriptMessages[1] body]);
}
#endif
@@ -311,7 +311,7 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(@"PASS1", (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"PASS1", (NSString *)[scriptMessages[0] body]);
[userContentController removeScriptMessageHandlerForName:@"handlerToReplace"];
[userContentController addScriptMessageHandler:handler.get() name:@"handlerToReplace"];
@@ -322,7 +322,7 @@
TestWebKitAPI::Util::run(&receivedScriptMessage);
receivedScriptMessage = false;
- EXPECT_WK_STREQ(@"PASS2", (NSString *)[lastScriptMessage body]);
+ EXPECT_WK_STREQ(@"PASS2", (NSString *)[scriptMessages[1] body]);
}
static NSString *styleSheetSource = @"body { background-color: green !important; }";
@@ -592,4 +592,50 @@
EXPECT_EQ(userScriptAssociatedWithWorld2.get(), [userContentController userScripts][1]);
}
+static void waitForMessages(size_t expectedCount)
+{
+ while (scriptMessages.size() < expectedCount) {
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+ receivedScriptMessage = false;
+ }
+}
+
+static void compareMessages(Vector<const char*>&& expectedMessages)
+{
+ EXPECT_EQ(expectedMessages.size(), scriptMessages.size());
+ for (size_t i = 0; i < expectedMessages.size(); ++i)
+ EXPECT_STREQ([[scriptMessages[i] body] UTF8String], expectedMessages[i]);
+}
+
+TEST(WKUserContentController, InjectUserScriptImmediately)
+{
+ auto handler = adoptNS([[ScriptMessageHandler alloc] init]);
+ auto startAllFrames = adoptNS([[WKUserScript alloc] initWithSource:@"window.webkit.messageHandlers.testHandler.postMessage('start all')" injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO]);
+ auto endMainFrameOnly = adoptNS([[WKUserScript alloc] initWithSource:@"window.webkit.messageHandlers.testHandler.postMessage('end main')" injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]);
+
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+ auto delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
+ [webView setNavigationDelegate:delegate.get()];
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple-iframe" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+
+ isDoneWithNavigation = false;
+ [webView loadRequest:request];
+ TestWebKitAPI::Util::run(&isDoneWithNavigation);
+
+ receivedScriptMessage = false;
+ [[configuration userContentController] _addUserScriptImmediately:startAllFrames.get()];
+ // simple-iframe.html has a main frame and one iframe.
+ waitForMessages(2);
+ [[configuration userContentController] _addUserScriptImmediately:endMainFrameOnly.get()];
+ waitForMessages(3);
+ [webView reload];
+ waitForMessages(6);
+ compareMessages({"start all", "start all", "end main", "start all", "end main", "start all"});
+}
+
#endif