From 5076cb3241d93ad2c375c977d5272dcaabf08bf7 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 19 May 2021 18:11:09 +0000 Subject: [PATCH] browsr(webkit): cherry-pick(mac-14): bootstrap script in utility world (#6591) (#6655) --- .../deprecated-webkit-mac-10.14/BUILD_NUMBER | 4 +- .../patches/bootstrap.diff | 100 ++++++++++++++---- 2 files changed, 83 insertions(+), 21 deletions(-) diff --git a/browser_patches/deprecated-webkit-mac-10.14/BUILD_NUMBER b/browser_patches/deprecated-webkit-mac-10.14/BUILD_NUMBER index b0fa2aefcf..6e8c709a52 100644 --- a/browser_patches/deprecated-webkit-mac-10.14/BUILD_NUMBER +++ b/browser_patches/deprecated-webkit-mac-10.14/BUILD_NUMBER @@ -1,2 +1,2 @@ -1443 -Changed: yurys@chromium.org Mon 01 Mar 2021 09:57:46 AM PST +1444 +Changed: yurys@chromium.org Wed 19 May 2021 11:08:01 AM PDT diff --git a/browser_patches/deprecated-webkit-mac-10.14/patches/bootstrap.diff b/browser_patches/deprecated-webkit-mac-10.14/patches/bootstrap.diff index d5e234f6dd..40bf859468 100644 --- a/browser_patches/deprecated-webkit-mac-10.14/patches/bootstrap.diff +++ b/browser_patches/deprecated-webkit-mac-10.14/patches/bootstrap.diff @@ -745,7 +745,7 @@ index 65ab2092b0ffd0ead3da1ddccd398d4f4179f51a..2d9ef40a20df819193c9a5867fbf6f8f ], "events": [ diff --git a/Source/JavaScriptCore/inspector/protocol/Page.json b/Source/JavaScriptCore/inspector/protocol/Page.json -index db52479a72d459be23d4d8d080c0ed15ea9fc4c0..b77bec0ab30e8562ef16fa0b01a68ef7501a62eb 100644 +index db52479a72d459be23d4d8d080c0ed15ea9fc4c0..4a0a5819fafd109af8d828af0df092b34750c1af 100644 --- a/Source/JavaScriptCore/inspector/protocol/Page.json +++ b/Source/JavaScriptCore/inspector/protocol/Page.json @@ -27,7 +27,7 @@ @@ -814,7 +814,17 @@ index db52479a72d459be23d4d8d080c0ed15ea9fc4c0..b77bec0ab30e8562ef16fa0b01a68ef7 { "name": "navigate", "description": "Navigates current page to the given URL.", -@@ -270,6 +313,20 @@ +@@ -204,7 +247,8 @@ + "name": "setBootstrapScript", + "targetTypes": ["page"], + "parameters": [ +- { "name": "source", "type": "string", "optional": true, "description": "If `source` is provided (and not empty), it will be injected into all future global objects as soon as they're created. Omitting `source` will stop this from happening." } ++ { "name": "source", "type": "string", "optional": true, "description": "If `source` is provided (and not empty), it will be injected into all future global objects as soon as they're created. Omitting `source` will stop this from happening." }, ++ { "name": "worldName", "type": "string", "optional": true, "description": "Isolated world name to evaluate the script in. If not specified main world will be used." } + ] + }, + { +@@ -270,6 +314,20 @@ { "name": "appearance", "$ref": "Appearance", "optional": true } ] }, @@ -835,7 +845,7 @@ index db52479a72d459be23d4d8d080c0ed15ea9fc4c0..b77bec0ab30e8562ef16fa0b01a68ef7 { "name": "snapshotNode", "description": "Capture a snapshot of the specified node that does not include unrelated layers.", -@@ -308,12 +365,67 @@ +@@ -308,12 +366,67 @@ { "name": "setScreenSizeOverride", "description": "Overrides screen size exposed to DOM and used in media queries for testing with provided values.", @@ -904,7 +914,7 @@ index db52479a72d459be23d4d8d080c0ed15ea9fc4c0..b77bec0ab30e8562ef16fa0b01a68ef7 } ], "events": [ -@@ -321,14 +433,16 @@ +@@ -321,14 +434,16 @@ "name": "domContentEventFired", "targetTypes": ["page"], "parameters": [ @@ -923,7 +933,7 @@ index db52479a72d459be23d4d8d080c0ed15ea9fc4c0..b77bec0ab30e8562ef16fa0b01a68ef7 ] }, { -@@ -338,6 +452,14 @@ +@@ -338,6 +453,14 @@ { "name": "frame", "$ref": "Frame", "description": "Frame object." } ] }, @@ -938,7 +948,7 @@ index db52479a72d459be23d4d8d080c0ed15ea9fc4c0..b77bec0ab30e8562ef16fa0b01a68ef7 { "name": "frameDetached", "description": "Fired when frame has been detached from its parent.", -@@ -377,6 +499,22 @@ +@@ -377,6 +500,22 @@ { "name": "frameId", "$ref": "Network.FrameId", "description": "Id of the frame that has cleared its scheduled navigation." } ] }, @@ -961,7 +971,7 @@ index db52479a72d459be23d4d8d080c0ed15ea9fc4c0..b77bec0ab30e8562ef16fa0b01a68ef7 { "name": "defaultAppearanceDidChange", "description": "Fired when page's default appearance changes, even if there is a forced appearance.", -@@ -385,6 +523,28 @@ +@@ -385,6 +524,28 @@ "parameters": [ { "name": "appearance", "$ref": "Appearance", "description": "Name of the appearance that is active (not considering any forced appearance.)" } ] @@ -3175,7 +3185,7 @@ index 933601761667417ebe5de301586869ccc64fc3da..f63a95c3c45980d5606971b83881e824 // InspectorInstrumentation void willRecalculateStyle(); diff --git a/Source/WebCore/inspector/agents/InspectorPageAgent.cpp b/Source/WebCore/inspector/agents/InspectorPageAgent.cpp -index af0a051bdae52b2daf70b1fee76eee0866b7b046..b8a55168af379e51a62ffd8181b70f1ddeec40bc 100644 +index af0a051bdae52b2daf70b1fee76eee0866b7b046..b46f7b5f1d60bc21b7d966b244753ba956ff6708 100644 --- a/Source/WebCore/inspector/agents/InspectorPageAgent.cpp +++ b/Source/WebCore/inspector/agents/InspectorPageAgent.cpp @@ -32,19 +32,25 @@ @@ -3311,7 +3321,23 @@ index af0a051bdae52b2daf70b1fee76eee0866b7b046..b8a55168af379e51a62ffd8181b70f1d Protocol::ErrorStringOr InspectorPageAgent::navigate(const String& url) { UserGestureIndicator indicator { ProcessingUserGesture }; -@@ -801,15 +847,16 @@ Protocol::ErrorStringOr InspectorPageAgent::setShowPaintRects(bool show) +@@ -696,9 +742,13 @@ Protocol::ErrorStringOr> InspectorP + return { { content, base64Encoded } }; + } + +-Protocol::ErrorStringOr InspectorPageAgent::setBootstrapScript(const String& source) ++Protocol::ErrorStringOr InspectorPageAgent::setBootstrapScript(const String& source, const String& worldName) + { +- m_bootstrapScript = source; ++ String key = worldName.isNull() ? emptyString() : worldName; ++ if (source.isEmpty()) ++ m_worldNameToBootstrapScript.remove(key); ++ else ++ m_worldNameToBootstrapScript.set(key, source); + + return { }; + } +@@ -801,15 +851,16 @@ Protocol::ErrorStringOr InspectorPageAgent::setShowPaintRects(bool show) return { }; } @@ -3333,7 +3359,7 @@ index af0a051bdae52b2daf70b1fee76eee0866b7b046..b8a55168af379e51a62ffd8181b70f1d } void InspectorPageAgent::frameNavigated(Frame& frame) -@@ -817,13 +864,23 @@ void InspectorPageAgent::frameNavigated(Frame& frame) +@@ -817,13 +868,23 @@ void InspectorPageAgent::frameNavigated(Frame& frame) m_frontendDispatcher->frameNavigated(buildObjectForFrame(&frame)); } @@ -3360,7 +3386,7 @@ index af0a051bdae52b2daf70b1fee76eee0866b7b046..b8a55168af379e51a62ffd8181b70f1d } Frame* InspectorPageAgent::frameForId(const Protocol::Network::FrameId& frameId) -@@ -835,20 +892,18 @@ String InspectorPageAgent::frameId(Frame* frame) +@@ -835,20 +896,18 @@ String InspectorPageAgent::frameId(Frame* frame) { if (!frame) return emptyString(); @@ -3387,7 +3413,7 @@ index af0a051bdae52b2daf70b1fee76eee0866b7b046..b8a55168af379e51a62ffd8181b70f1d } Frame* InspectorPageAgent::assertFrame(Protocol::ErrorString& errorString, const Protocol::Network::FrameId& frameId) -@@ -859,11 +914,6 @@ Frame* InspectorPageAgent::assertFrame(Protocol::ErrorString& errorString, const +@@ -859,11 +918,6 @@ Frame* InspectorPageAgent::assertFrame(Protocol::ErrorString& errorString, const return frame; } @@ -3399,7 +3425,7 @@ index af0a051bdae52b2daf70b1fee76eee0866b7b046..b8a55168af379e51a62ffd8181b70f1d void InspectorPageAgent::frameStartedLoading(Frame& frame) { m_frontendDispatcher->frameStartedLoading(frameId(&frame)); -@@ -884,6 +934,12 @@ void InspectorPageAgent::frameClearedScheduledNavigation(Frame& frame) +@@ -884,6 +938,12 @@ void InspectorPageAgent::frameClearedScheduledNavigation(Frame& frame) m_frontendDispatcher->frameClearedScheduledNavigation(frameId(&frame)); } @@ -3412,7 +3438,33 @@ index af0a051bdae52b2daf70b1fee76eee0866b7b046..b8a55168af379e51a62ffd8181b70f1d #if ENABLE(DARK_MODE_CSS) || HAVE(OS_DARK_MODE_SUPPORT) void InspectorPageAgent::defaultAppearanceDidChange(bool useDarkAppearance) { -@@ -943,6 +999,52 @@ void InspectorPageAgent::didRecalculateStyle() +@@ -893,13 +953,22 @@ void InspectorPageAgent::defaultAppearanceDidChange(bool useDarkAppearance) + + void InspectorPageAgent::didClearWindowObjectInWorld(Frame& frame, DOMWrapperWorld& world) + { +- if (&world != &mainThreadNormalWorld()) ++ if (m_worldNameToBootstrapScript.isEmpty()) + return; + +- if (m_bootstrapScript.isEmpty()) ++ if (world.name().isEmpty() && &world != &mainThreadNormalWorld()) ++ return; ++ ++ String worldName = world.name(); ++ // Null string cannot be used as a key. ++ if (worldName.isNull()) ++ worldName = emptyString(); ++ ++ if (!m_worldNameToBootstrapScript.contains(worldName)) + return; + +- frame.script().evaluateIgnoringException(ScriptSourceCode(m_bootstrapScript, URL { URL(), "web-inspector://bootstrap.js"_s })); ++ String bootstrapScript = m_worldNameToBootstrapScript.get(worldName); ++ frame.script().evaluateInWorldIgnoringException(ScriptSourceCode(bootstrapScript, URL { URL(), "web-inspector://bootstrap.js"_s }), world); + } + + void InspectorPageAgent::didPaint(RenderObject& renderer, const LayoutRect& rect) +@@ -943,6 +1012,52 @@ void InspectorPageAgent::didRecalculateStyle() m_overlay->update(); } @@ -3465,7 +3517,7 @@ index af0a051bdae52b2daf70b1fee76eee0866b7b046..b8a55168af379e51a62ffd8181b70f1d Ref InspectorPageAgent::buildObjectForFrame(Frame* frame) { ASSERT_ARG(frame, frame); -@@ -1094,6 +1196,27 @@ Protocol::ErrorStringOr InspectorPageAgent::snapshotRect(int x, int y, i +@@ -1094,6 +1209,27 @@ Protocol::ErrorStringOr InspectorPageAgent::snapshotRect(int x, int y, i return snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes); } @@ -3493,7 +3545,7 @@ index af0a051bdae52b2daf70b1fee76eee0866b7b046..b8a55168af379e51a62ffd8181b70f1d #if ENABLE(WEB_ARCHIVE) && USE(CF) Protocol::ErrorStringOr InspectorPageAgent::archive() { -@@ -1106,7 +1229,6 @@ Protocol::ErrorStringOr InspectorPageAgent::archive() +@@ -1106,7 +1242,6 @@ Protocol::ErrorStringOr InspectorPageAgent::archive() } #endif @@ -3501,7 +3553,7 @@ index af0a051bdae52b2daf70b1fee76eee0866b7b046..b8a55168af379e51a62ffd8181b70f1d Protocol::ErrorStringOr InspectorPageAgent::setScreenSizeOverride(Optional&& width, Optional&& height) { if (width.hasValue() != height.hasValue()) -@@ -1121,6 +1243,533 @@ Protocol::ErrorStringOr InspectorPageAgent::setScreenSizeOverride(Optional +@@ -1121,6 +1256,533 @@ Protocol::ErrorStringOr InspectorPageAgent::setScreenSizeOverride(Optional m_inspectedPage.mainFrame().setOverrideScreenSize(FloatSize(width.valueOr(0), height.valueOr(0))); return { }; } @@ -4036,7 +4088,7 @@ index af0a051bdae52b2daf70b1fee76eee0866b7b046..b8a55168af379e51a62ffd8181b70f1d } // namespace WebCore diff --git a/Source/WebCore/inspector/agents/InspectorPageAgent.h b/Source/WebCore/inspector/agents/InspectorPageAgent.h -index 78a98224ab5450e0729751571fe1bb957d303301..a4f46cc377bde6a787f3e67ca4869bfc25461127 100644 +index 78a98224ab5450e0729751571fe1bb957d303301..cec612f2d12b68930d681ead74064169db6eb5ec 100644 --- a/Source/WebCore/inspector/agents/InspectorPageAgent.h +++ b/Source/WebCore/inspector/agents/InspectorPageAgent.h @@ -34,17 +34,23 @@ @@ -4087,6 +4139,15 @@ index 78a98224ab5450e0729751571fe1bb957d303301..a4f46cc377bde6a787f3e67ca4869bfc Inspector::Protocol::ErrorStringOr navigate(const String& url); Inspector::Protocol::ErrorStringOr overrideUserAgent(const String&); Inspector::Protocol::ErrorStringOr overrideSetting(Inspector::Protocol::Page::Setting, Optional&& value); +@@ -103,7 +113,7 @@ public: + Inspector::Protocol::ErrorStringOr deleteCookie(const String& cookieName, const String& url); + Inspector::Protocol::ErrorStringOr> getResourceTree(); + Inspector::Protocol::ErrorStringOr> getResourceContent(const Inspector::Protocol::Network::FrameId&, const String& url); +- Inspector::Protocol::ErrorStringOr setBootstrapScript(const String& source); ++ Inspector::Protocol::ErrorStringOr setBootstrapScript(const String& source, const String& worldName); + Inspector::Protocol::ErrorStringOr>> searchInResource(const Inspector::Protocol::Network::FrameId&, const String& url, const String& query, Optional&& caseSensitive, Optional&& isRegex, const Inspector::Protocol::Network::RequestId&); + Inspector::Protocol::ErrorStringOr>> searchInResources(const String&, Optional&& caseSensitive, Optional&& isRegex); + #if !PLATFORM(IOS_FAMILY) @@ -114,25 +124,35 @@ public: #if ENABLE(DARK_MODE_CSS) || HAVE(OS_DARK_MODE_SUPPORT) Inspector::Protocol::ErrorStringOr setForcedAppearance(Optional&&); @@ -4161,9 +4222,10 @@ index 78a98224ab5450e0729751571fe1bb957d303301..a4f46cc377bde6a787f3e67ca4869bfc - HashMap m_frameToIdentifier; HashMap> m_identifierToFrame; - HashMap m_loaderToIdentifier; ++ HashMap m_worldNameToBootstrapScript; String m_userAgentOverride; String m_emulatedMedia; - String m_bootstrapScript; +- String m_bootstrapScript; bool m_isFirstLayoutAfterOnLoad { false }; bool m_showPaintRects { false }; + bool m_interceptFileChooserDialog { false };