Skip to content

Commit cfca39e

Browse files
committed
Remove WaitForNotificationBeforeInjecting and friends.
https://webkit.org/b/288647 rdar://problem/145689560 Reviewed by Alex Christensen. Remove this support since it is no longer used by any clients. * Source/WebCore/page/LocalFrame.cpp: (WebCore::LocalFrame::injectUserScripts): (WebCore::LocalFrame::addUserScriptAwaitingNotification): Deleted. (WebCore::LocalFrame::injectUserScriptsAwaitingNotification): Deleted. * Source/WebCore/page/LocalFrame.h: * Source/WebCore/page/Page.cpp: (WebCore::m_presentingApplicationBundleIdentifier): (WebCore::Page::notifyToInjectUserScripts): Deleted. * Source/WebCore/page/Page.h: (WebCore::Page::hasBeenNotifiedToInjectUserScripts const): Deleted. * Source/WebCore/page/PageConfiguration.h: * Source/WebCore/page/Quirks.cpp: (WebCore::Quirks::triggerOptionalStorageAccessQuirk const): * Source/WebCore/page/UserScript.cpp: (WebCore::UserScript::UserScript): * Source/WebCore/page/UserScript.h: (WebCore::UserScript::injectedFrames const): (WebCore::UserScript::waitForNotificationBeforeInjecting const): Deleted. * Source/WebCore/page/UserScriptTypes.h: * Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in: * Source/WebKit/Shared/WebPageCreationParameters.h: * Source/WebKit/Shared/WebPageCreationParameters.serialization.in: * Source/WebKit/UIProcess/API/APIPageConfiguration.h: (API::PageConfiguration::userScriptsShouldWaitUntilNotification const): Deleted. (API::PageConfiguration::setUserScriptsShouldWaitUntilNotification): Deleted. * Source/WebKit/UIProcess/API/C/WKUserScriptRef.cpp: (WKUserScriptCreate): (WKUserScriptCreateWithSource): * Source/WebKit/UIProcess/API/Cocoa/WKUserScript.mm: (-[WKUserScript _initWithSource:injectionTime:forMainFrameOnly:includeMatchPatternStrings:excludeMatchPatternStrings:associatedURL:contentWorld:deferRunningUntilNotification:]): Deprecated. (-[WKUserScript _initWithSource:injectionTime:forMainFrameOnly:includeMatchPatternStrings:excludeMatchPatternStrings:associatedURL:contentWorld:]): Added. * Source/WebKit/UIProcess/API/Cocoa/WKUserScriptPrivate.h: * Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _notifyUserScripts]): Deleted. (-[WKWebView _deferrableUserScriptsNeedNotification]): Deleted. * Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm: (-[WKWebViewConfiguration _deferrableUserScriptsShouldWaitUntilNotification]): Deleted. (-[WKWebViewConfiguration _setDeferrableUserScriptsShouldWaitUntilNotification:]): Deleted. * Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: * Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h: * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm: (WebKit::WebExtensionContext::addInjectedContent): * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::creationParameters): (WebKit::WebPageProxy::notifyUserScripts): Deleted. (WebKit::WebPageProxy::userScriptsNeedNotification const): Deleted. * Source/WebKit/UIProcess/WebPageProxy.h: * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::m_textAnimationController): (WebKit::WebPage::addUserScript): (WebKit::WebPage::notifyUserScripts): Deleted. * Source/WebKit/WebProcess/WebPage/WebPage.h: * Source/WebKit/WebProcess/WebPage/WebPage.messages.in: * Source/WebKitLegacy/mac/WebView/WebView.mm: (-[WebView _injectLaBanquePostaleQuirks]): (+[WebView _addUserScriptToGroup:world:source:url:includeMatchPatternStrings:excludeMatchPatternStrings:injectionTime:injectedFrames:]): * Tools/TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm: (TEST(WKUserContentController, UserScriptNotification)): Deleted. Canonical link: https://commits.webkit.org/291165@main
1 parent 3961561 commit cfca39e

28 files changed

+25
-187
lines changed

Source/WebCore/page/LocalFrame.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -735,14 +735,9 @@ void LocalFrame::injectUserScripts(UserScriptInjectionTime injectionTime)
735735
return;
736736

737737
RefPtr page = this->page();
738-
bool pageWasNotified = page->hasBeenNotifiedToInjectUserScripts();
739-
page->protectedUserContentProvider()->forEachUserScript([this, protectedThis = Ref { *this }, injectionTime, pageWasNotified] (DOMWrapperWorld& world, const UserScript& script) {
740-
if (script.injectionTime() == injectionTime) {
741-
if (script.waitForNotificationBeforeInjecting() == WaitForNotificationBeforeInjecting::Yes && !pageWasNotified)
742-
addUserScriptAwaitingNotification(world, script);
743-
else
744-
injectUserScriptImmediately(world, script);
745-
}
738+
page->protectedUserContentProvider()->forEachUserScript([this, protectedThis = Ref { *this }, injectionTime] (DOMWrapperWorld& world, const UserScript& script) {
739+
if (script.injectionTime() == injectionTime)
740+
injectUserScriptImmediately(world, script);
746741
});
747742
}
748743

@@ -775,17 +770,6 @@ void LocalFrame::injectUserScriptImmediately(DOMWrapperWorld& world, const UserS
775770
checkedScript()->evaluateInWorldIgnoringException(ScriptSourceCode(script.source(), JSC::SourceTaintedOrigin::Untainted, URL(script.url())), world);
776771
}
777772

778-
void LocalFrame::addUserScriptAwaitingNotification(DOMWrapperWorld& world, const UserScript& script)
779-
{
780-
m_userScriptsAwaitingNotification.append({ world, makeUniqueRef<UserScript>(script) });
781-
}
782-
783-
void LocalFrame::injectUserScriptsAwaitingNotification()
784-
{
785-
for (const auto& [world, script] : std::exchange(m_userScriptsAwaitingNotification, { }))
786-
injectUserScriptImmediately(world, script.get());
787-
}
788-
789773
RenderView* LocalFrame::contentRenderer() const
790774
{
791775
return document() ? document()->renderView() : nullptr;

Source/WebCore/page/LocalFrame.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ class LocalFrame final : public Frame {
195195
WEBCORE_EXPORT void injectUserScripts(UserScriptInjectionTime);
196196
WEBCORE_EXPORT void injectUserScriptImmediately(DOMWrapperWorld&, const UserScript&);
197197

198-
void injectUserScriptsAwaitingNotification();
199-
void addUserScriptAwaitingNotification(DOMWrapperWorld&, const UserScript&);
200-
201198
WEBCORE_EXPORT String trackedRepaintRectsAsText() const;
202199

203200
WEBCORE_EXPORT static LocalFrame* frameForWidget(const Widget&);
@@ -361,8 +358,6 @@ class LocalFrame final : public Frame {
361358

362359
WeakHashSet<FrameDestructionObserver> m_destructionObservers;
363360

364-
Vector<std::pair<Ref<DOMWrapperWorld>, UniqueRef<UserScript>>> m_userScriptsAwaitingNotification;
365-
366361
const UniqueRef<FrameLoader> m_loader;
367362

368363
RefPtr<LocalFrameView> m_view;

Source/WebCore/page/Page.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,6 @@ Page::Page(PageConfiguration&& pageConfiguration)
500500

501501
settingsDidChange();
502502

503-
if (!pageConfiguration.userScriptsShouldWaitUntilNotification)
504-
m_hasBeenNotifiedToInjectUserScripts = true;
505-
506503
if (m_lowPowerModeNotifier->isLowPowerModeEnabled())
507504
m_throttlingReasons.add(ThrottlingReason::LowPowerMode);
508505

@@ -3819,15 +3816,6 @@ Ref<UserContentProvider> Page::protectedUserContentProvider()
38193816
return m_userContentProvider;
38203817
}
38213818

3822-
void Page::notifyToInjectUserScripts()
3823-
{
3824-
m_hasBeenNotifiedToInjectUserScripts = true;
3825-
3826-
forEachLocalFrame([] (LocalFrame& frame) {
3827-
frame.injectUserScriptsAwaitingNotification();
3828-
});
3829-
}
3830-
38313819
void Page::setUserContentProvider(Ref<UserContentProvider>&& userContentProvider)
38323820
{
38333821
protectedUserContentProvider()->removePage(*this);

Source/WebCore/page/Page.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,9 +1138,6 @@ class Page : public RefCountedAndCanMakeWeakPtr<Page>, public Supplementable<Pag
11381138
bool isTakingSnapshotsForApplicationSuspension() const { return m_isTakingSnapshotsForApplicationSuspension; }
11391139
void setIsTakingSnapshotsForApplicationSuspension(bool isTakingSnapshotsForApplicationSuspension) { m_isTakingSnapshotsForApplicationSuspension = isTakingSnapshotsForApplicationSuspension; }
11401140

1141-
bool hasBeenNotifiedToInjectUserScripts() const { return m_hasBeenNotifiedToInjectUserScripts; }
1142-
WEBCORE_EXPORT void notifyToInjectUserScripts();
1143-
11441141
MonotonicTime lastRenderingUpdateTimestamp() const { return m_lastRenderingUpdateTimestamp; }
11451142
std::optional<MonotonicTime> nextRenderingUpdateTimestamp() const;
11461143

@@ -1669,7 +1666,6 @@ class Page : public RefCountedAndCanMakeWeakPtr<Page>, public Supplementable<Pag
16691666
bool m_canUseCredentialStorage { true };
16701667
ShouldRelaxThirdPartyCookieBlocking m_shouldRelaxThirdPartyCookieBlocking;
16711668
LoadSchedulingMode m_loadSchedulingMode { LoadSchedulingMode::Direct };
1672-
bool m_hasBeenNotifiedToInjectUserScripts { false };
16731669
bool m_isServiceWorkerPage { false };
16741670

16751671
MonotonicTime m_lastRenderingUpdateTimestamp;

Source/WebCore/page/PageConfiguration.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ class PageConfiguration {
206206
// FIXME: These should be all be Settings.
207207
bool loadsSubresources { true };
208208
std::optional<MemoryCompactLookupOnlyRobinHoodHashSet<String>> allowedNetworkHosts;
209-
bool userScriptsShouldWaitUntilNotification { true };
210209
ShouldRelaxThirdPartyCookieBlocking shouldRelaxThirdPartyCookieBlocking { ShouldRelaxThirdPartyCookieBlocking::No };
211210
bool httpsUpgradeEnabled { true };
212211
std::optional<std::pair<uint16_t, uint16_t>> portsForUpgradingInsecureSchemeForTesting;

Source/WebCore/page/Quirks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ Quirks::StorageAccessResult Quirks::triggerOptionalStorageAccessQuirk(Element& e
10591059

10601060
static NeverDestroyed<String> loginPopupWindowFeatureString = "toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=599,height=600,top=420,left=980.5"_s;
10611061

1062-
static NeverDestroyed<UserScript> kinjaLoginUserScript { "function triggerLoginForm() { let elements = document.getElementsByClassName('js_header-userbutton'); if (elements && elements[0]) { elements[0].click(); clearInterval(interval); } } let interval = setInterval(triggerLoginForm, 200);"_s, URL(aboutBlankURL()), Vector<String>(), Vector<String>(), UserScriptInjectionTime::DocumentEnd, UserContentInjectedFrames::InjectInTopFrameOnly, WaitForNotificationBeforeInjecting::Yes };
1062+
static NeverDestroyed<UserScript> kinjaLoginUserScript { "function triggerLoginForm() { let elements = document.getElementsByClassName('js_header-userbutton'); if (elements && elements[0]) { elements[0].click(); clearInterval(interval); } } let interval = setInterval(triggerLoginForm, 200);"_s, URL(aboutBlankURL()), Vector<String>(), Vector<String>(), UserScriptInjectionTime::DocumentEnd, UserContentInjectedFrames::InjectInTopFrameOnly };
10631063

10641064
if (isAnyClick(eventType)) {
10651065
RefPtr document = m_document.get();
@@ -1097,7 +1097,7 @@ Quirks::StorageAccessResult Quirks::triggerOptionalStorageAccessQuirk(Element& e
10971097
auto* abstractFrame = proxy->frame();
10981098
if (RefPtr frame = dynamicDowncast<LocalFrame>(abstractFrame)) {
10991099
auto world = ScriptController::createWorld("kinjaComQuirkWorld"_s, ScriptController::WorldType::User);
1100-
frame->addUserScriptAwaitingNotification(world.get(), kinjaLoginUserScript);
1100+
frame->injectUserScriptImmediately(world.get(), kinjaLoginUserScript);
11011101
return Quirks::StorageAccessResult::ShouldCancelEvent;
11021102
}
11031103
}

Source/WebCore/page/UserScript.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ static WTF::URL generateUserScriptUniqueURL()
3939
return { { }, makeString("user-script:"_s, ++identifier) };
4040
}
4141

42-
UserScript::UserScript(String&& source, URL&& url, Vector<String>&& allowlist, Vector<String>&& blocklist, UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames, WaitForNotificationBeforeInjecting waitForNotification)
42+
UserScript::UserScript(String&& source, URL&& url, Vector<String>&& allowlist, Vector<String>&& blocklist, UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames)
4343
: m_source(WTFMove(source))
4444
, m_url(url.isEmpty() ? generateUserScriptUniqueURL() : WTFMove(url))
4545
, m_allowlist(WTFMove(allowlist))
4646
, m_blocklist(WTFMove(blocklist))
4747
, m_injectionTime(injectionTime)
4848
, m_injectedFrames(injectedFrames)
49-
, m_waitForNotificationBeforeInjecting(waitForNotification)
5049
{
5150
}
5251

Source/WebCore/page/UserScript.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ class UserScript {
4242
UserScript& operator=(const UserScript&) = default;
4343
UserScript& operator=(UserScript&&) = default;
4444

45-
WEBCORE_EXPORT UserScript(String&&, URL&&, Vector<String>&&, Vector<String>&&, UserScriptInjectionTime, UserContentInjectedFrames, WaitForNotificationBeforeInjecting);
45+
WEBCORE_EXPORT UserScript(String&&, URL&&, Vector<String>&&, Vector<String>&&, UserScriptInjectionTime, UserContentInjectedFrames);
4646

4747
const String& source() const { return m_source; }
4848
const URL& url() const { return m_url; }
4949
const Vector<String>& allowlist() const { return m_allowlist; }
5050
const Vector<String>& blocklist() const { return m_blocklist; }
5151
UserScriptInjectionTime injectionTime() const { return m_injectionTime; }
5252
UserContentInjectedFrames injectedFrames() const { return m_injectedFrames; }
53-
WaitForNotificationBeforeInjecting waitForNotificationBeforeInjecting() const { return m_waitForNotificationBeforeInjecting; }
5453

5554
private:
5655
String m_source;
@@ -59,7 +58,6 @@ class UserScript {
5958
Vector<String> m_blocklist;
6059
UserScriptInjectionTime m_injectionTime { UserScriptInjectionTime::DocumentStart };
6160
UserContentInjectedFrames m_injectedFrames { UserContentInjectedFrames::InjectInAllFrames };
62-
WaitForNotificationBeforeInjecting m_waitForNotificationBeforeInjecting { WaitForNotificationBeforeInjecting::No };
6361
};
6462

6563
} // namespace WebCore

Source/WebCore/page/UserScriptTypes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
namespace WebCore {
3232

3333
enum class UserScriptInjectionTime : bool { DocumentStart, DocumentEnd };
34-
enum class WaitForNotificationBeforeInjecting : bool { No, Yes };
3534

3635
class DOMWrapperWorld;
3736
class UserScript;

Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7525,8 +7525,6 @@ header: <WebCore/FontTaggedSettings.h>
75257525

75267526
enum class WebCore::UserScriptInjectionTime : bool;
75277527

7528-
enum class WebCore::WaitForNotificationBeforeInjecting : bool;
7529-
75307528
enum class WebCore::UserContentInjectedFrames : bool;
75317529

75327530
class WebCore::UserScript {
@@ -7536,7 +7534,6 @@ class WebCore::UserScript {
75367534
Vector<String> blocklist();
75377535
WebCore::UserScriptInjectionTime injectionTime();
75387536
WebCore::UserContentInjectedFrames injectedFrames();
7539-
WebCore::WaitForNotificationBeforeInjecting waitForNotificationBeforeInjecting();
75407537
}
75417538

75427539
header: <WebCore/GraphicsContextState.h>

0 commit comments

Comments
 (0)