Skip to content

Commit 1ad6134

Browse files
authored
browser(webkit): ensure user worlds created when attaching to new pages (#765)
1 parent f4640d1 commit 1ad6134

File tree

2 files changed

+76
-26
lines changed

2 files changed

+76
-26
lines changed

browser_patches/webkit/BUILD_NUMBER

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1124
1+
1125

browser_patches/webkit/patches/bootstrap.diff

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,7 +2507,7 @@ index a68f84520736977c8b9216616c5a178fbf5275d6..8d6ed7188bca75fb46d1a5963983f088
25072507

25082508
} // namespace WebCore
25092509
diff --git a/Source/WebCore/inspector/agents/InspectorPageAgent.cpp b/Source/WebCore/inspector/agents/InspectorPageAgent.cpp
2510-
index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eeaafa37089 100644
2510+
index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..5809b8726af46cf93007b15cad6904506352b26d 100644
25112511
--- a/Source/WebCore/inspector/agents/InspectorPageAgent.cpp
25122512
+++ b/Source/WebCore/inspector/agents/InspectorPageAgent.cpp
25132513
@@ -32,6 +32,8 @@
@@ -2535,7 +2535,7 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
25352535
#include "HTMLNames.h"
25362536
#include "ImageBuffer.h"
25372537
#include "InspectorClient.h"
2538-
@@ -56,18 +61,24 @@
2538+
@@ -56,19 +61,28 @@
25392539
#include "MIMETypeRegistry.h"
25402540
#include "MemoryCache.h"
25412541
#include "Page.h"
@@ -2558,17 +2558,53 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
25582558
#include <JavaScriptCore/RegularExpression.h>
25592559
+#include <platform/ProcessIdentifier.h>
25602560
#include <wtf/ListHashSet.h>
2561+
+#include <wtf/NeverDestroyed.h>
2562+
+#include <wtf/Ref.h>
2563+
+#include <wtf/RefPtr.h>
25612564
#include <wtf/Stopwatch.h>
25622565
#include <wtf/text/Base64.h>
2563-
@@ -340,6 +351,7 @@ InspectorPageAgent::InspectorPageAgent(PageAgentContext& context, InspectorClien
2566+
#include <wtf/text/StringBuilder.h>
2567+
@@ -81,7 +95,6 @@
2568+
#include "LegacyWebArchive.h"
2569+
#endif
2570+
2571+
-
2572+
namespace WebCore {
2573+
2574+
using namespace Inspector;
2575+
@@ -100,6 +113,11 @@ using namespace Inspector;
2576+
macro(WebRTCEncryptionEnabled) \
2577+
macro(WebSecurityEnabled)
2578+
2579+
+HashMap<String, Ref<DOMWrapperWorld>>& createdUserWorlds() {
2580+
+ static NeverDestroyed<HashMap<String, Ref<DOMWrapperWorld>>> nameToWorld;
2581+
+ return nameToWorld;
2582+
+}
2583+
+
2584+
static bool decodeBuffer(const char* buffer, unsigned size, const String& textEncodingName, String* result)
2585+
{
2586+
if (buffer) {
2587+
@@ -340,6 +358,7 @@ InspectorPageAgent::InspectorPageAgent(PageAgentContext& context, InspectorClien
25642588
, m_frontendDispatcher(makeUnique<Inspector::PageFrontendDispatcher>(context.frontendRouter))
25652589
, m_backendDispatcher(Inspector::PageBackendDispatcher::create(context.backendDispatcher, this))
25662590
, m_inspectedPage(context.inspectedPage)
25672591
+ , m_injectedScriptManager(context.injectedScriptManager)
25682592
, m_client(client)
25692593
, m_overlay(overlay)
25702594
{
2571-
@@ -378,6 +390,8 @@ void InspectorPageAgent::enable(ErrorString& errorString)
2595+
@@ -373,11 +392,20 @@ void InspectorPageAgent::enable(ErrorString& errorString)
2596+
#if HAVE(OS_DARK_MODE_SUPPORT)
2597+
defaultAppearanceDidChange(m_inspectedPage.defaultUseDarkAppearance());
2598+
#endif
2599+
+
2600+
+ if (!createdUserWorlds().isEmpty()) {
2601+
+ Vector<DOMWrapperWorld*> worlds;
2602+
+ for (const auto& world : createdUserWorlds().values())
2603+
+ worlds.append(world.ptr());
2604+
+ ensureUserWorldsExistInAllFrames(worlds);
2605+
+ }
2606+
}
2607+
25722608
void InspectorPageAgent::disable(ErrorString&)
25732609
{
25742610
m_instrumentingAgents.setInspectorPageAgent(nullptr);
@@ -2577,7 +2613,7 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
25772613

25782614
ErrorString unused;
25792615
setShowPaintRects(unused, false);
2580-
@@ -415,14 +429,36 @@ void InspectorPageAgent::reload(ErrorString&, const bool* optionalReloadFromOrig
2616+
@@ -415,14 +443,36 @@ void InspectorPageAgent::reload(ErrorString&, const bool* optionalReloadFromOrig
25812617
m_inspectedPage.mainFrame().loader().reload(reloadOptions);
25822618
}
25832619

@@ -2603,23 +2639,23 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
26032639
+ return;
26042640
+
26052641
+ ResourceRequest resourceRequest { frame->document()->completeURL(url) };
2606-
+
2607-
+ if (!resourceRequest.url().isValid()) {
2608-
+ errorString = "Cannot navigate to invalid URL"_s;
2609-
+ return;
2610-
+ }
26112642

26122643
- ResourceRequest resourceRequest { frame.document()->completeURL(url) };
26132644
- FrameLoadRequest frameLoadRequest { *frame.document(), frame.document()->securityOrigin(), resourceRequest, "_self"_s, LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, ShouldOpenExternalURLsPolicy::ShouldNotAllow, InitiatedByMainFrame::Unknown };
26142645
- frame.loader().changeLocation(WTFMove(frameLoadRequest));
2646+
+ if (!resourceRequest.url().isValid()) {
2647+
+ errorString = "Cannot navigate to invalid URL"_s;
2648+
+ return;
2649+
+ }
2650+
+
26152651
+ if (referrer)
26162652
+ resourceRequest.setInitiatorIdentifier(InspectorNetworkAgent::createInitiatorIdentifierForInspectorNavigation(*referrer));
26172653
+ FrameLoadRequest frameLoadRequest { *frame->document(), frame->document()->securityOrigin(), resourceRequest, "_self"_s, LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, ShouldOpenExternalURLsPolicy::ShouldNotAllow, InitiatedByMainFrame::Unknown };
26182654
+ frame->loader().changeLocation(WTFMove(frameLoadRequest));
26192655
}
26202656

26212657
void InspectorPageAgent::overrideUserAgent(ErrorString&, const String* value)
2622-
@@ -683,15 +719,16 @@ void InspectorPageAgent::setShowPaintRects(ErrorString&, bool show)
2658+
@@ -683,15 +733,16 @@ void InspectorPageAgent::setShowPaintRects(ErrorString&, bool show)
26232659
m_overlay->setShowPaintRects(show);
26242660
}
26252661

@@ -2641,7 +2677,7 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
26412677
}
26422678

26432679
void InspectorPageAgent::frameNavigated(Frame& frame)
2644-
@@ -699,13 +736,18 @@ void InspectorPageAgent::frameNavigated(Frame& frame)
2680+
@@ -699,13 +750,18 @@ void InspectorPageAgent::frameNavigated(Frame& frame)
26452681
m_frontendDispatcher->frameNavigated(buildObjectForFrame(&frame));
26462682
}
26472683

@@ -2663,7 +2699,7 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
26632699
}
26642700

26652701
Frame* InspectorPageAgent::frameForId(const String& frameId)
2666-
@@ -717,20 +759,18 @@ String InspectorPageAgent::frameId(Frame* frame)
2702+
@@ -717,20 +773,18 @@ String InspectorPageAgent::frameId(Frame* frame)
26672703
{
26682704
if (!frame)
26692705
return emptyString();
@@ -2690,7 +2726,7 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
26902726
}
26912727

26922728
Frame* InspectorPageAgent::assertFrame(ErrorString& errorString, const String& frameId)
2693-
@@ -741,11 +781,6 @@ Frame* InspectorPageAgent::assertFrame(ErrorString& errorString, const String& f
2729+
@@ -741,11 +795,6 @@ Frame* InspectorPageAgent::assertFrame(ErrorString& errorString, const String& f
26942730
return frame;
26952731
}
26962732

@@ -2702,7 +2738,7 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
27022738
void InspectorPageAgent::frameStartedLoading(Frame& frame)
27032739
{
27042740
m_frontendDispatcher->frameStartedLoading(frameId(&frame));
2705-
@@ -766,6 +801,12 @@ void InspectorPageAgent::frameClearedScheduledNavigation(Frame& frame)
2741+
@@ -766,6 +815,12 @@ void InspectorPageAgent::frameClearedScheduledNavigation(Frame& frame)
27062742
m_frontendDispatcher->frameClearedScheduledNavigation(frameId(&frame));
27072743
}
27082744

@@ -2715,7 +2751,7 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
27152751
void InspectorPageAgent::defaultAppearanceDidChange(bool useDarkAppearance)
27162752
{
27172753
m_frontendDispatcher->defaultAppearanceDidChange(useDarkAppearance ? Inspector::Protocol::Page::Appearance::Dark : Inspector::Protocol::Page::Appearance::Light);
2718-
@@ -823,6 +864,38 @@ void InspectorPageAgent::didRecalculateStyle()
2754+
@@ -823,6 +878,38 @@ void InspectorPageAgent::didRecalculateStyle()
27192755
m_overlay->update();
27202756
}
27212757

@@ -2754,7 +2790,7 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
27542790
Ref<Inspector::Protocol::Page::Frame> InspectorPageAgent::buildObjectForFrame(Frame* frame)
27552791
{
27562792
ASSERT_ARG(frame, frame);
2757-
@@ -966,6 +1039,18 @@ void InspectorPageAgent::snapshotRect(ErrorString& errorString, int x, int y, in
2793+
@@ -966,6 +1053,18 @@ void InspectorPageAgent::snapshotRect(ErrorString& errorString, int x, int y, in
27582794
*outDataURL = snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes);
27592795
}
27602796

@@ -2773,7 +2809,7 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
27732809
void InspectorPageAgent::archive(ErrorString& errorString, String* data)
27742810
{
27752811
#if ENABLE(WEB_ARCHIVE) && USE(CF)
2776-
@@ -983,4 +1068,514 @@ void InspectorPageAgent::archive(ErrorString& errorString, String* data)
2812+
@@ -983,4 +1082,520 @@ void InspectorPageAgent::archive(ErrorString& errorString, String* data)
27772813
#endif
27782814
}
27792815

@@ -3265,16 +3301,22 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
32653301
+
32663302
+void InspectorPageAgent::createUserWorld(ErrorString& errorString, const String& name)
32673303
+{
3268-
+ static NeverDestroyed<HashSet<String>> createdUserWorlds;
3269-
+ if (createdUserWorlds->contains(name)) {
3304+
+ if (createdUserWorlds().contains(name)) {
32703305
+ errorString = "World with the given name already exists"_s;
32713306
+ return;
32723307
+ }
3273-
+ createdUserWorlds->add(name);
32743308
+
32753309
+ Ref<DOMWrapperWorld> world = ScriptController::createWorld(name, ScriptController::WorldType::User);
3276-
+ for (Frame* frame = &m_inspectedPage.mainFrame(); frame; frame = frame->tree().traverseNext())
3277-
+ frame->windowProxy().jsWindowProxy(world)->window();
3310+
+ ensureUserWorldsExistInAllFrames({world.ptr()});
3311+
+ createdUserWorlds().set(name, WTFMove(world));
3312+
+}
3313+
+
3314+
+void InspectorPageAgent::ensureUserWorldsExistInAllFrames(const Vector<DOMWrapperWorld*>& worlds)
3315+
+{
3316+
+ for (Frame* frame = &m_inspectedPage.mainFrame(); frame; frame = frame->tree().traverseNext()) {
3317+
+ for (auto* world : worlds)
3318+
+ frame->windowProxy().jsWindowProxy(*world)->window();
3319+
+ }
32783320
+}
32793321
+
32803322
+void InspectorPageAgent::setBypassCSP(ErrorString&, bool enabled)
@@ -3289,7 +3331,7 @@ index d678cddbd20a1a2b410a8ebbb17f5f63f0fc620d..4732b818204dc5a7e00d38b6635d9eea
32893331
+
32903332
} // namespace WebCore
32913333
diff --git a/Source/WebCore/inspector/agents/InspectorPageAgent.h b/Source/WebCore/inspector/agents/InspectorPageAgent.h
3292-
index 110173dbbfe819226b6c4caa0f65a5dee8c39f2b..8cbb35194cfd408e934400ed1e3abd7b1dcd3949 100644
3334+
index 110173dbbfe819226b6c4caa0f65a5dee8c39f2b..cba0b43011a390c305aef7c01cc95e5350766283 100644
32933335
--- a/Source/WebCore/inspector/agents/InspectorPageAgent.h
32943336
+++ b/Source/WebCore/inspector/agents/InspectorPageAgent.h
32953337
@@ -40,11 +40,16 @@
@@ -3363,7 +3405,15 @@ index 110173dbbfe819226b6c4caa0f65a5dee8c39f2b..8cbb35194cfd408e934400ed1e3abd7b
33633405

33643406
Frame* frameForId(const String& frameId);
33653407
WEBCORE_EXPORT String frameId(Frame*);
3366-
@@ -152,18 +170,19 @@ private:
3408+
@@ -141,6 +159,7 @@ public:
3409+
3410+
private:
3411+
double timestamp();
3412+
+ void ensureUserWorldsExistInAllFrames(const Vector<DOMWrapperWorld*>&);
3413+
3414+
static bool mainResourceContent(Frame*, bool withBase64Encode, String* result);
3415+
static bool dataContent(const char* data, unsigned size, const String& textEncodingName, bool withBase64Encode, String* result);
3416+
@@ -152,18 +171,19 @@ private:
33673417
RefPtr<Inspector::PageBackendDispatcher> m_backendDispatcher;
33683418

33693419
Page& m_inspectedPage;

0 commit comments

Comments
 (0)