Web Inspector: Page: lazily create the agent
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 18:22:08 +0000 (18:22 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 18:22:08 +0000 (18:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195592
<rdar://problem/48791916>

Reviewed by Timothy Hatcher.

No change in functionality.

Have more agents save the inspected `Page` so they don't need to access it via the
`InspectorPageAgent`. Make some of `InspectorPageAgent`'s functions `static` so other
agents can use them without needing to have access to an enabled `InspectorPageAgent`.

* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
(WebCore::InspectorController::createLazyAgents):

* inspector/agents/InspectorPageAgent.h:
(WebCore::InspectorPageAgent::page): Deleted.
* inspector/agents/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::InspectorPageAgent):
(WebCore::InspectorPageAgent::enable):
(WebCore::InspectorPageAgent::disable):
(WebCore::InspectorPageAgent::reload):
(WebCore::InspectorPageAgent::navigate):
(WebCore::InspectorPageAgent::overrideSetting):
(WebCore::InspectorPageAgent::getCookies):
(WebCore::InspectorPageAgent::deleteCookie):
(WebCore::InspectorPageAgent::getResourceTree):
(WebCore::InspectorPageAgent::searchInResources):
(WebCore::InspectorPageAgent::didPaint):
(WebCore::InspectorPageAgent::didLayout):
(WebCore::InspectorPageAgent::didScroll):
(WebCore::InspectorPageAgent::didRecalculateStyle):
(WebCore::InspectorPageAgent::setEmulatedMedia):
(WebCore::InspectorPageAgent::setForcedAppearance):
(WebCore::InspectorPageAgent::getCompositingBordersVisible):
(WebCore::InspectorPageAgent::setCompositingBordersVisible):
(WebCore::InspectorPageAgent::snapshotNode):
(WebCore::InspectorPageAgent::snapshotRect):
(WebCore::InspectorPageAgent::archive):
(WebCore::InspectorPageAgent::mainFrame): Deleted.
(WebCore::InspectorPageAgent::hasIdForFrame const): Deleted.

* inspector/agents/InspectorApplicationCacheAgent.h:
* inspector/agents/InspectorApplicationCacheAgent.cpp:
(WebCore::InspectorApplicationCacheAgent::InspectorApplicationCacheAgent):
(WebCore::InspectorApplicationCacheAgent::updateApplicationCacheStatus):
(WebCore::InspectorApplicationCacheAgent::getFramesWithManifests):
(WebCore::InspectorApplicationCacheAgent::assertFrameWithDocumentLoader):

* inspector/agents/InspectorCanvasAgent.h:
* inspector/agents/InspectorCanvasAgent.cpp:
(WebCore::InspectorCanvasAgent::InspectorCanvasAgent):
(WebCore::InspectorCanvasAgent::enable):

* inspector/agents/InspectorDOMStorageAgent.h:
* inspector/agents/InspectorDOMStorageAgent.cpp:
(WebCore::InspectorDOMStorageAgent::InspectorDOMStorageAgent):
(WebCore::InspectorDOMStorageAgent::findStorageArea):

* inspector/agents/InspectorIndexedDBAgent.h:
* inspector/agents/InspectorIndexedDBAgent.cpp:
(WebCore::InspectorIndexedDBAgent::InspectorIndexedDBAgent):
(WebCore::InspectorIndexedDBAgent::requestDatabaseNames):
(WebCore::InspectorIndexedDBAgent::requestDatabase):
(WebCore::InspectorIndexedDBAgent::requestData):
(WebCore::InspectorIndexedDBAgent::clearObjectStore):

* inspector/agents/page/PageDebuggerAgent.h:
* inspector/agents/page/PageDebuggerAgent.cpp:
(WebCore::PageDebuggerAgent::PageDebuggerAgent):
(WebCore::PageDebuggerAgent::sourceMapURLForScript):
(WebCore::PageDebuggerAgent::breakpointActionLog):
(WebCore::PageDebuggerAgent::injectedScriptForEval):

* inspector/agents/page/PageNetworkAgent.h:
* inspector/agents/page/PageNetworkAgent.cpp:
(WebCore::PageNetworkAgent::PageNetworkAgent):
(WebCore::PageNetworkAgent::loaderIdentifier):
(WebCore::PageNetworkAgent::frameIdentifier):
(WebCore::PageNetworkAgent::setResourceCachingDisabled):
(WebCore::PageNetworkAgent::scriptExecutionContext):

* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::didClearWindowObjectInWorldImpl):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243303 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/agents/InspectorApplicationCacheAgent.cpp
Source/WebCore/inspector/agents/InspectorApplicationCacheAgent.h
Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp
Source/WebCore/inspector/agents/InspectorCanvasAgent.h
Source/WebCore/inspector/agents/InspectorDOMStorageAgent.cpp
Source/WebCore/inspector/agents/InspectorDOMStorageAgent.h
Source/WebCore/inspector/agents/InspectorIndexedDBAgent.cpp
Source/WebCore/inspector/agents/InspectorIndexedDBAgent.h
Source/WebCore/inspector/agents/InspectorPageAgent.cpp
Source/WebCore/inspector/agents/InspectorPageAgent.h
Source/WebCore/inspector/agents/page/PageDebuggerAgent.cpp
Source/WebCore/inspector/agents/page/PageDebuggerAgent.h
Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp
Source/WebCore/inspector/agents/page/PageNetworkAgent.h

index ff5194f..4d7c5ef 100644 (file)
@@ -1,3 +1,91 @@
+2019-03-21  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Page: lazily create the agent
+        https://bugs.webkit.org/show_bug.cgi?id=195592
+        <rdar://problem/48791916>
+
+        Reviewed by Timothy Hatcher.
+
+        No change in functionality.
+
+        Have more agents save the inspected `Page` so they don't need to access it via the
+        `InspectorPageAgent`. Make some of `InspectorPageAgent`'s functions `static` so other
+        agents can use them without needing to have access to an enabled `InspectorPageAgent`.
+
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        (WebCore::InspectorController::createLazyAgents):
+
+        * inspector/agents/InspectorPageAgent.h:
+        (WebCore::InspectorPageAgent::page): Deleted.
+        * inspector/agents/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::InspectorPageAgent):
+        (WebCore::InspectorPageAgent::enable):
+        (WebCore::InspectorPageAgent::disable):
+        (WebCore::InspectorPageAgent::reload):
+        (WebCore::InspectorPageAgent::navigate):
+        (WebCore::InspectorPageAgent::overrideSetting):
+        (WebCore::InspectorPageAgent::getCookies):
+        (WebCore::InspectorPageAgent::deleteCookie):
+        (WebCore::InspectorPageAgent::getResourceTree):
+        (WebCore::InspectorPageAgent::searchInResources):
+        (WebCore::InspectorPageAgent::didPaint):
+        (WebCore::InspectorPageAgent::didLayout):
+        (WebCore::InspectorPageAgent::didScroll):
+        (WebCore::InspectorPageAgent::didRecalculateStyle):
+        (WebCore::InspectorPageAgent::setEmulatedMedia):
+        (WebCore::InspectorPageAgent::setForcedAppearance):
+        (WebCore::InspectorPageAgent::getCompositingBordersVisible):
+        (WebCore::InspectorPageAgent::setCompositingBordersVisible):
+        (WebCore::InspectorPageAgent::snapshotNode):
+        (WebCore::InspectorPageAgent::snapshotRect):
+        (WebCore::InspectorPageAgent::archive):
+        (WebCore::InspectorPageAgent::mainFrame): Deleted.
+        (WebCore::InspectorPageAgent::hasIdForFrame const): Deleted.
+
+        * inspector/agents/InspectorApplicationCacheAgent.h:
+        * inspector/agents/InspectorApplicationCacheAgent.cpp:
+        (WebCore::InspectorApplicationCacheAgent::InspectorApplicationCacheAgent):
+        (WebCore::InspectorApplicationCacheAgent::updateApplicationCacheStatus):
+        (WebCore::InspectorApplicationCacheAgent::getFramesWithManifests):
+        (WebCore::InspectorApplicationCacheAgent::assertFrameWithDocumentLoader):
+
+        * inspector/agents/InspectorCanvasAgent.h:
+        * inspector/agents/InspectorCanvasAgent.cpp:
+        (WebCore::InspectorCanvasAgent::InspectorCanvasAgent):
+        (WebCore::InspectorCanvasAgent::enable):
+
+        * inspector/agents/InspectorDOMStorageAgent.h:
+        * inspector/agents/InspectorDOMStorageAgent.cpp:
+        (WebCore::InspectorDOMStorageAgent::InspectorDOMStorageAgent):
+        (WebCore::InspectorDOMStorageAgent::findStorageArea):
+
+        * inspector/agents/InspectorIndexedDBAgent.h:
+        * inspector/agents/InspectorIndexedDBAgent.cpp:
+        (WebCore::InspectorIndexedDBAgent::InspectorIndexedDBAgent):
+        (WebCore::InspectorIndexedDBAgent::requestDatabaseNames):
+        (WebCore::InspectorIndexedDBAgent::requestDatabase):
+        (WebCore::InspectorIndexedDBAgent::requestData):
+        (WebCore::InspectorIndexedDBAgent::clearObjectStore):
+
+        * inspector/agents/page/PageDebuggerAgent.h:
+        * inspector/agents/page/PageDebuggerAgent.cpp:
+        (WebCore::PageDebuggerAgent::PageDebuggerAgent):
+        (WebCore::PageDebuggerAgent::sourceMapURLForScript):
+        (WebCore::PageDebuggerAgent::breakpointActionLog):
+        (WebCore::PageDebuggerAgent::injectedScriptForEval):
+
+        * inspector/agents/page/PageNetworkAgent.h:
+        * inspector/agents/page/PageNetworkAgent.cpp:
+        (WebCore::PageNetworkAgent::PageNetworkAgent):
+        (WebCore::PageNetworkAgent::loaderIdentifier):
+        (WebCore::PageNetworkAgent::frameIdentifier):
+        (WebCore::PageNetworkAgent::setResourceCachingDisabled):
+        (WebCore::PageNetworkAgent::scriptExecutionContext):
+
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::didClearWindowObjectInWorldImpl):
+
 2019-03-21  Brent Fulgham  <bfulgham@apple.com>
 
         Hardening: Use WeakPtrs in VideoFullscreenInterface{Mac,AVKit}
index b9aa66c..007a09c 100644 (file)
@@ -110,10 +110,6 @@ InspectorController::InspectorController(Page& page, InspectorClient* inspectorC
     m_instrumentingAgents->setInspectorAgent(m_inspectorAgent);
     m_agents.append(WTFMove(inspectorAgentPtr));
 
-    auto pageAgentPtr = std::make_unique<InspectorPageAgent>(pageContext, inspectorClient, m_overlay.get());
-    m_pageAgent = pageAgentPtr.get();
-    m_agents.append(WTFMove(pageAgentPtr));
-
     auto consoleAgent = std::make_unique<PageConsoleAgent>(pageContext);
     m_instrumentingAgents->setWebConsoleAgent(consoleAgent.get());
     m_agents.append(WTFMove(consoleAgent));
@@ -160,23 +156,27 @@ void InspectorController::createLazyAgents()
 
     auto pageContext = pageAgentContext();
 
+    auto pageAgentPtr = std::make_unique<InspectorPageAgent>(pageContext, m_inspectorClient, m_overlay.get());
+    m_pageAgent = pageAgentPtr.get();
+    m_agents.append(WTFMove(pageAgentPtr));
+
     m_agents.append(std::make_unique<PageRuntimeAgent>(pageContext));
 
-    auto debuggerAgent = std::make_unique<PageDebuggerAgent>(pageContext, m_pageAgent);
+    auto debuggerAgent = std::make_unique<PageDebuggerAgent>(pageContext);
     auto debuggerAgentPtr = debuggerAgent.get();
     m_agents.append(WTFMove(debuggerAgent));
 
-    m_agents.append(std::make_unique<PageNetworkAgent>(pageContext, m_pageAgent));
+    m_agents.append(std::make_unique<PageNetworkAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorCSSAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorDOMAgent>(pageContext, m_overlay.get()));
     m_agents.append(std::make_unique<InspectorDOMDebuggerAgent>(pageContext, debuggerAgentPtr));
-    m_agents.append(std::make_unique<InspectorApplicationCacheAgent>(pageContext, m_pageAgent));
+    m_agents.append(std::make_unique<InspectorApplicationCacheAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorLayerTreeAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorWorkerAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorDOMStorageAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorDatabaseAgent>(pageContext));
 #if ENABLE(INDEXED_DATABASE)
-    m_agents.append(std::make_unique<InspectorIndexedDBAgent>(pageContext, m_pageAgent));
+    m_agents.append(std::make_unique<InspectorIndexedDBAgent>(pageContext));
 #endif
 
     auto scriptProfilerAgentPtr = std::make_unique<InspectorScriptProfilerAgent>(pageContext);
index a53a910..2efe16c 100644 (file)
@@ -109,11 +109,11 @@ static Frame* frameForScriptExecutionContext(ScriptExecutionContext& context)
 
 void InspectorInstrumentation::didClearWindowObjectInWorldImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, DOMWrapperWorld& world)
 {
-    InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent();
     if (PageDebuggerAgent* debuggerAgent = instrumentingAgents.pageDebuggerAgent()) {
-        if (pageAgent && &world == &mainThreadNormalWorld() && &frame == &pageAgent->mainFrame())
+        if (&world == &mainThreadNormalWorld() && frame.isMainFrame())
             debuggerAgent->didClearMainFrameWindowObject();
     }
+
     if (PageRuntimeAgent* pageRuntimeAgent = instrumentingAgents.pageRuntimeAgent()) {
         if (&world == &mainThreadNormalWorld())
             pageRuntimeAgent->didCreateMainWorldContext(frame);
index 76f316f..5f0f85b 100644 (file)
@@ -40,11 +40,11 @@ namespace WebCore {
 
 using namespace Inspector;
 
-InspectorApplicationCacheAgent::InspectorApplicationCacheAgent(WebAgentContext& context, InspectorPageAgent* pageAgent)
+InspectorApplicationCacheAgent::InspectorApplicationCacheAgent(PageAgentContext& context)
     : InspectorAgentBase("ApplicationCache"_s, context)
     , m_frontendDispatcher(std::make_unique<Inspector::ApplicationCacheFrontendDispatcher>(context.frontendRouter))
     , m_backendDispatcher(Inspector::ApplicationCacheBackendDispatcher::create(context.backendDispatcher, this))
-    , m_pageAgent(pageAgent)
+    , m_inspectedPage(context.inspectedPage)
 {
 }
 
@@ -67,8 +67,13 @@ void InspectorApplicationCacheAgent::enable(ErrorString&)
 
 void InspectorApplicationCacheAgent::updateApplicationCacheStatus(Frame* frame)
 {
+    auto* pageAgent = m_instrumentingAgents.inspectorPageAgent();
+    if (!pageAgent)
+        return;
+
     if (!frame)
         return;
+
     auto* documentLoader = frame->loader().documentLoader();
     if (!documentLoader)
         return;
@@ -77,7 +82,7 @@ void InspectorApplicationCacheAgent::updateApplicationCacheStatus(Frame* frame)
     int status = host.status();
     auto manifestURL = host.applicationCacheInfo().manifest.string();
 
-    m_frontendDispatcher->applicationCacheStatusUpdated(m_pageAgent->frameId(frame), manifestURL, status);
+    m_frontendDispatcher->applicationCacheStatusUpdated(pageAgent->frameId(frame), manifestURL, status);
 }
 
 void InspectorApplicationCacheAgent::networkStateChanged()
@@ -89,7 +94,9 @@ void InspectorApplicationCacheAgent::getFramesWithManifests(ErrorString&, RefPtr
 {
     result = JSON::ArrayOf<Inspector::Protocol::ApplicationCache::FrameWithManifest>::create();
 
-    for (Frame* frame = &m_pageAgent->mainFrame(); frame; frame = frame->tree().traverseNext()) {
+    auto* pageAgent = m_instrumentingAgents.inspectorPageAgent();
+
+    for (Frame* frame = &m_inspectedPage.mainFrame(); frame; frame = frame->tree().traverseNext()) {
         auto* documentLoader = frame->loader().documentLoader();
         if (!documentLoader)
             continue;
@@ -98,7 +105,7 @@ void InspectorApplicationCacheAgent::getFramesWithManifests(ErrorString&, RefPtr
         String manifestURL = host.applicationCacheInfo().manifest.string();
         if (!manifestURL.isEmpty()) {
             result->addItem(Inspector::Protocol::ApplicationCache::FrameWithManifest::create()
-                .setFrameId(m_pageAgent->frameId(frame))
+                .setFrameId(pageAgent->frameId(frame))
                 .setManifestURL(manifestURL)
                 .setStatus(static_cast<int>(host.status()))
                 .release());
@@ -108,7 +115,13 @@ void InspectorApplicationCacheAgent::getFramesWithManifests(ErrorString&, RefPtr
 
 DocumentLoader* InspectorApplicationCacheAgent::assertFrameWithDocumentLoader(ErrorString& errorString, const String& frameId)
 {
-    Frame* frame = m_pageAgent->assertFrame(errorString, frameId);
+    auto* pageAgent = m_instrumentingAgents.inspectorPageAgent();
+    if (!pageAgent) {
+        errorString = "Missing Page agent"_s;
+        return nullptr;
+    }
+
+    Frame* frame = pageAgent->assertFrame(errorString, frameId);
     if (!frame)
         return nullptr;
 
index 5fe5c2d..640f0a4 100644 (file)
@@ -37,7 +37,6 @@ class ApplicationCacheFrontendDispatcher;
 namespace WebCore {
 
 class Frame;
-class InspectorPageAgent;
 class Page;
 
 typedef String ErrorString;
@@ -46,15 +45,17 @@ class InspectorApplicationCacheAgent final : public InspectorAgentBase, public I
     WTF_MAKE_NONCOPYABLE(InspectorApplicationCacheAgent);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    InspectorApplicationCacheAgent(WebAgentContext&, InspectorPageAgent*);
+    InspectorApplicationCacheAgent(PageAgentContext&);
     virtual ~InspectorApplicationCacheAgent() = default;
 
     void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
     void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override;
 
+    // InspectorInstrumentation
     void updateApplicationCacheStatus(Frame*);
     void networkStateChanged();
 
+    // ApplicationCacheBackendDispatcherHandler
     void enable(ErrorString&) override;
     void getFramesWithManifests(ErrorString&, RefPtr<JSON::ArrayOf<Inspector::Protocol::ApplicationCache::FrameWithManifest>>& result) override;
     void getManifestForFrame(ErrorString&, const String& frameId, String* manifestURL) override;
@@ -69,7 +70,7 @@ private:
 
     std::unique_ptr<Inspector::ApplicationCacheFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::ApplicationCacheBackendDispatcher> m_backendDispatcher;
-    InspectorPageAgent* m_pageAgent { nullptr };
+    Page& m_inspectedPage;
 };
 
 } // namespace WebCore
index 4119089..941e249 100644 (file)
@@ -71,11 +71,12 @@ namespace WebCore {
 
 using namespace Inspector;
 
-InspectorCanvasAgent::InspectorCanvasAgent(WebAgentContext& context)
+InspectorCanvasAgent::InspectorCanvasAgent(PageAgentContext& context)
     : InspectorAgentBase("Canvas"_s, context)
     , m_frontendDispatcher(std::make_unique<Inspector::CanvasFrontendDispatcher>(context.frontendRouter))
     , m_backendDispatcher(Inspector::CanvasBackendDispatcher::create(context.backendDispatcher, this))
     , m_injectedScriptManager(context.injectedScriptManager)
+    , m_inspectedPage(context.inspectedPage)
     , m_canvasDestroyedTimer(*this, &InspectorCanvasAgent::canvasDestroyedTimerFired)
     , m_canvasRecordingTimer(*this, &InspectorCanvasAgent::canvasRecordingTimerFired)
 {
@@ -111,13 +112,9 @@ void InspectorCanvasAgent::enable(ErrorString&)
         if (!is<Document>(scriptExecutionContext))
             return false;
 
-        if (auto* inspectorPageAgent = m_instrumentingAgents.inspectorPageAgent()) {
-            // FIXME: <https://webkit.org/b/168475> Web Inspector: Correctly display iframe's WebSockets
-            auto* document = downcast<Document>(scriptExecutionContext);
-            return document->page() == &inspectorPageAgent->page();
-        }
-
-        return false;
+        // FIXME: <https://webkit.org/b/168475> Web Inspector: Correctly display iframe's WebSockets
+        auto* document = downcast<Document>(scriptExecutionContext);
+        return document->page() == &m_inspectedPage;
     };
 
     {
index 469e3ed..5b299c8 100644 (file)
@@ -59,7 +59,7 @@ class InspectorCanvasAgent final : public InspectorAgentBase, public CanvasObser
     WTF_MAKE_NONCOPYABLE(InspectorCanvasAgent);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    explicit InspectorCanvasAgent(WebAgentContext&);
+    explicit InspectorCanvasAgent(PageAgentContext&);
     virtual ~InspectorCanvasAgent() = default;
 
     void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
@@ -128,12 +128,15 @@ private:
 
     std::unique_ptr<Inspector::CanvasFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::CanvasBackendDispatcher> m_backendDispatcher;
+
     Inspector::InjectedScriptManager& m_injectedScriptManager;
+    Page& m_inspectedPage;
+
     HashMap<String, RefPtr<InspectorCanvas>> m_identifierToInspectorCanvas;
     Vector<String> m_removedCanvasIdentifiers;
+    Optional<size_t> m_recordingAutoCaptureFrameCount;
     Timer m_canvasDestroyedTimer;
     Timer m_canvasRecordingTimer;
-    Optional<size_t> m_recordingAutoCaptureFrameCount;
 };
 
 } // namespace WebCore
index f096ea9..61a9e11 100644 (file)
@@ -54,10 +54,11 @@ namespace WebCore {
 
 using namespace Inspector;
 
-InspectorDOMStorageAgent::InspectorDOMStorageAgent(WebAgentContext& context)
+InspectorDOMStorageAgent::InspectorDOMStorageAgent(PageAgentContext& context)
     : InspectorAgentBase("DOMStorage"_s, context)
     , m_frontendDispatcher(std::make_unique<Inspector::DOMStorageFrontendDispatcher>(context.frontendRouter))
     , m_backendDispatcher(Inspector::DOMStorageBackendDispatcher::create(context.backendDispatcher, this))
+    , m_inspectedPage(context.inspectedPage)
 {
 }
 
@@ -178,22 +179,15 @@ RefPtr<StorageArea> InspectorDOMStorageAgent::findStorageArea(ErrorString& error
         return nullptr;
     }
 
-    auto* pageAgent = m_instrumentingAgents.inspectorPageAgent();
-    ASSERT(pageAgent);
-    if (!pageAgent) {
-        errorString = "Missing Page agent"_s;
-        return nullptr;
-    }
-
-    targetFrame = pageAgent->findFrameWithSecurityOrigin(securityOrigin);
+    targetFrame = InspectorPageAgent::findFrameWithSecurityOrigin(m_inspectedPage, securityOrigin);
     if (!targetFrame) {
         errorString = "Frame not found for the given security origin"_s;
         return nullptr;
     }
 
     if (!isLocalStorage)
-        return pageAgent->page().sessionStorage()->storageArea(targetFrame->document()->securityOrigin().data());
-    return pageAgent->page().storageNamespaceProvider().localStorageArea(*targetFrame->document());
+        return m_inspectedPage.sessionStorage()->storageArea(targetFrame->document()->securityOrigin().data());
+    return m_inspectedPage.storageNamespaceProvider().localStorageArea(*targetFrame->document());
 }
 
 } // namespace WebCore
index 5d4ff63..faa1a83 100644 (file)
@@ -51,7 +51,7 @@ class InspectorDOMStorageAgent final : public InspectorAgentBase, public Inspect
     WTF_MAKE_NONCOPYABLE(InspectorDOMStorageAgent);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    InspectorDOMStorageAgent(WebAgentContext&);
+    InspectorDOMStorageAgent(PageAgentContext&);
     virtual ~InspectorDOMStorageAgent() = default;
 
     void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
@@ -76,6 +76,8 @@ private:
 
     std::unique_ptr<Inspector::DOMStorageFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::DOMStorageBackendDispatcher> m_backendDispatcher;
+
+    Page& m_inspectedPage;
 };
 
 } // namespace WebCore
index e4443db..dd715cb 100644 (file)
@@ -519,16 +519,14 @@ public:
 
 } // namespace
 
-InspectorIndexedDBAgent::InspectorIndexedDBAgent(WebAgentContext& context, InspectorPageAgent* pageAgent)
+InspectorIndexedDBAgent::InspectorIndexedDBAgent(PageAgentContext& context)
     : InspectorAgentBase("IndexedDB"_s, context)
     , m_injectedScriptManager(context.injectedScriptManager)
     , m_backendDispatcher(Inspector::IndexedDBBackendDispatcher::create(context.backendDispatcher, this))
-    , m_pageAgent(pageAgent)
+    , m_inspectedPage(context.inspectedPage)
 {
 }
 
-InspectorIndexedDBAgent::~InspectorIndexedDBAgent() = default;
-
 void InspectorIndexedDBAgent::didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*)
 {
 }
@@ -590,7 +588,7 @@ static bool getDocumentAndIDBFactoryFromFrameOrSendFailure(Frame* frame, Documen
     
 void InspectorIndexedDBAgent::requestDatabaseNames(const String& securityOrigin, Ref<RequestDatabaseNamesCallback>&& callback)
 {
-    Frame* frame = m_pageAgent->findFrameWithSecurityOrigin(securityOrigin);
+    auto* frame = InspectorPageAgent::findFrameWithSecurityOrigin(m_inspectedPage, securityOrigin);
     Document* document;
     IDBFactory* idbFactory;
     if (!getDocumentAndIDBFactoryFromFrameOrSendFailure(frame, document, idbFactory, callback))
@@ -612,7 +610,7 @@ void InspectorIndexedDBAgent::requestDatabaseNames(const String& securityOrigin,
 
 void InspectorIndexedDBAgent::requestDatabase(const String& securityOrigin, const String& databaseName, Ref<RequestDatabaseCallback>&& callback)
 {
-    Frame* frame = m_pageAgent->findFrameWithSecurityOrigin(securityOrigin);
+    auto* frame = InspectorPageAgent::findFrameWithSecurityOrigin(m_inspectedPage, securityOrigin);
     Document* document;
     IDBFactory* idbFactory;
     if (!getDocumentAndIDBFactoryFromFrameOrSendFailure(frame, document, idbFactory, callback))
@@ -624,7 +622,7 @@ void InspectorIndexedDBAgent::requestDatabase(const String& securityOrigin, cons
 
 void InspectorIndexedDBAgent::requestData(const String& securityOrigin, const String& databaseName, const String& objectStoreName, const String& indexName, int skipCount, int pageSize, const JSON::Object* keyRange, Ref<RequestDataCallback>&& callback)
 {
-    Frame* frame = m_pageAgent->findFrameWithSecurityOrigin(securityOrigin);
+    auto* frame = InspectorPageAgent::findFrameWithSecurityOrigin(m_inspectedPage, securityOrigin);
     Document* document;
     IDBFactory* idbFactory;
     if (!getDocumentAndIDBFactoryFromFrameOrSendFailure(frame, document, idbFactory, callback))
@@ -735,7 +733,7 @@ private:
 
 void InspectorIndexedDBAgent::clearObjectStore(const String& securityOrigin, const String& databaseName, const String& objectStoreName, Ref<ClearObjectStoreCallback>&& callback)
 {
-    Frame* frame = m_pageAgent->findFrameWithSecurityOrigin(securityOrigin);
+    auto* frame = InspectorPageAgent::findFrameWithSecurityOrigin(m_inspectedPage, securityOrigin);
     Document* document;
     IDBFactory* idbFactory;
     if (!getDocumentAndIDBFactoryFromFrameOrSendFailure(frame, document, idbFactory, callback))
index 4f6f2e9..45feb91 100644 (file)
@@ -43,7 +43,7 @@ class InjectedScriptManager;
 
 namespace WebCore {
 
-class InspectorPageAgent;
+class Page;
 
 typedef String ErrorString;
 
@@ -51,13 +51,13 @@ class InspectorIndexedDBAgent final : public InspectorAgentBase, public Inspecto
     WTF_MAKE_NONCOPYABLE(InspectorIndexedDBAgent);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    InspectorIndexedDBAgent(WebAgentContext&, InspectorPageAgent*);
-    virtual ~InspectorIndexedDBAgent();
+    InspectorIndexedDBAgent(PageAgentContext&);
+    virtual ~InspectorIndexedDBAgent() = default;
 
     void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
     void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override;
 
-    // Called from the front-end.
+    // IndexedDBBackendDispatcherHandler
     void enable(ErrorString&) override;
     void disable(ErrorString&) override;
     void requestDatabaseNames(const String& securityOrigin, Ref<RequestDatabaseNamesCallback>&&) override;
@@ -68,7 +68,8 @@ public:
 private:
     Inspector::InjectedScriptManager& m_injectedScriptManager;
     RefPtr<Inspector::IndexedDBBackendDispatcher> m_backendDispatcher;
-    InspectorPageAgent* m_pageAgent { nullptr };
+
+    Page& m_inspectedPage;
 };
 
 } // namespace WebCore
index 005b98c..dbdfa36 100644 (file)
@@ -309,11 +309,29 @@ Inspector::Protocol::Page::ResourceType InspectorPageAgent::cachedResourceTypeJS
     return resourceTypeJSON(inspectorResourceType(cachedResource));
 }
 
+Frame* InspectorPageAgent::findFrameWithSecurityOrigin(Page& page, const String& originRawString)
+{
+    for (Frame* frame = &page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
+        if (frame->document()->securityOrigin().toRawString() == originRawString)
+            return frame;
+    }
+    return nullptr;
+}
+
+DocumentLoader* InspectorPageAgent::assertDocumentLoader(ErrorString& errorString, Frame* frame)
+{
+    FrameLoader& frameLoader = frame->loader();
+    DocumentLoader* documentLoader = frameLoader.documentLoader();
+    if (!documentLoader)
+        errorString = "No documentLoader for given frame found"_s;
+    return documentLoader;
+}
+
 InspectorPageAgent::InspectorPageAgent(PageAgentContext& context, InspectorClient* client, InspectorOverlay* overlay)
     : InspectorAgentBase("Page"_s, context)
     , m_frontendDispatcher(std::make_unique<Inspector::PageFrontendDispatcher>(context.frontendRouter))
     , m_backendDispatcher(Inspector::PageBackendDispatcher::create(context.backendDispatcher, this))
-    , m_page(context.inspectedPage)
+    , m_inspectedPage(context.inspectedPage)
     , m_client(client)
     , m_overlay(overlay)
 {
@@ -336,7 +354,9 @@ double InspectorPageAgent::timestamp()
 
 void InspectorPageAgent::enable(ErrorString&)
 {
-    m_enabled = true;
+    if (m_instrumentingAgents.inspectorPageAgent() == this)
+        return;
+
     m_instrumentingAgents.setInspectorPageAgent(this);
 
     auto stopwatch = m_environment.executionStopwatch();
@@ -344,15 +364,12 @@ void InspectorPageAgent::enable(ErrorString&)
     stopwatch->start();
 
 #if HAVE(OS_DARK_MODE_SUPPORT)
-    defaultAppearanceDidChange(m_page.defaultUseDarkAppearance());
+    defaultAppearanceDidChange(m_inspectedPage.defaultUseDarkAppearance());
 #endif
 }
 
 void InspectorPageAgent::disable(ErrorString&)
 {
-    m_enabled = false;
-    m_instrumentingAgents.setInspectorPageAgent(nullptr);
-
     ErrorString unused;
     setShowPaintRects(unused, false);
     setShowRulers(unused, false);
@@ -361,11 +378,13 @@ void InspectorPageAgent::disable(ErrorString&)
     setForcedAppearance(unused, emptyString());
 
 #define DISABLE_INSPECTOR_OVERRIDE_SETTING(name) \
-    m_page.settings().set##name##InspectorOverride(WTF::nullopt);
+    m_inspectedPage.settings().set##name##InspectorOverride(WTF::nullopt);
 
     FOR_EACH_INSPECTOR_OVERRIDE_SETTING(DISABLE_INSPECTOR_OVERRIDE_SETTING)
 
 #undef DISABLE_INSPECTOR_OVERRIDE_SETTING
+
+    m_instrumentingAgents.setInspectorPageAgent(nullptr);
 }
 
 void InspectorPageAgent::reload(ErrorString&, const bool* optionalReloadFromOrigin, const bool* optionalRevalidateAllResources)
@@ -379,13 +398,13 @@ void InspectorPageAgent::reload(ErrorString&, const bool* optionalReloadFromOrig
     if (!revalidateAllResources)
         reloadOptions.add(ReloadOption::ExpiredOnly);
 
-    m_page.mainFrame().loader().reload(reloadOptions);
+    m_inspectedPage.mainFrame().loader().reload(reloadOptions);
 }
 
 void InspectorPageAgent::navigate(ErrorString&, const String& url)
 {
     UserGestureIndicator indicator { ProcessingUserGesture };
-    Frame& frame = m_page.mainFrame();
+    Frame& frame = m_inspectedPage.mainFrame();
 
     ResourceRequest resourceRequest { frame.document()->completeURL(url) };
     FrameLoadRequest frameLoadRequest { *frame.document(), frame.document()->securityOrigin(), resourceRequest, "_self"_s, LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, ShouldOpenExternalURLsPolicy::ShouldNotAllow, InitiatedByMainFrame::Unknown };
@@ -414,9 +433,9 @@ void InspectorPageAgent::overrideSetting(ErrorString& errorString, const String&
 #define CASE_INSPECTOR_OVERRIDE_SETTING(name) \
     case Inspector::Protocol::Page::Setting::name: { \
         if (value) \
-            m_page.settings().set##name##InspectorOverride(*value); \
+            m_inspectedPage.settings().set##name##InspectorOverride(*value); \
         else \
-            m_page.settings().set##name##InspectorOverride(WTF::nullopt); \
+            m_inspectedPage.settings().set##name##InspectorOverride(WTF::nullopt); \
         return; \
     } \
 
@@ -493,7 +512,7 @@ void InspectorPageAgent::getCookies(ErrorString&, RefPtr<JSON::ArrayOf<Inspector
     // always return the same true/false value.
     bool rawCookiesImplemented = false;
 
-    for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
+    for (Frame* frame = &m_inspectedPage.mainFrame(); frame; frame = frame->tree().traverseNext()) {
         Document* document = frame->document();
         if (!document || !document->page())
             continue;
@@ -524,7 +543,7 @@ void InspectorPageAgent::getCookies(ErrorString&, RefPtr<JSON::ArrayOf<Inspector
 void InspectorPageAgent::deleteCookie(ErrorString&, const String& cookieName, const String& url)
 {
     URL parsedURL({ }, url);
-    for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
+    for (Frame* frame = &m_inspectedPage.mainFrame(); frame; frame = frame->tree().traverseNext()) {
         if (auto* document = frame->document()) {
             if (auto* page = document->page())
                 page->cookieJar().deleteCookie(*document, parsedURL, cookieName);
@@ -534,7 +553,7 @@ void InspectorPageAgent::deleteCookie(ErrorString&, const String& cookieName, co
 
 void InspectorPageAgent::getResourceTree(ErrorString&, RefPtr<Inspector::Protocol::Page::FrameResourceTree>& object)
 {
-    object = buildObjectForFrameTree(&m_page.mainFrame());
+    object = buildObjectForFrameTree(&m_inspectedPage.mainFrame());
 }
 
 void InspectorPageAgent::getResourceContent(ErrorString& errorString, const String& frameId, const String& url, String* content, bool* base64Encoded)
@@ -607,7 +626,7 @@ void InspectorPageAgent::searchInResources(ErrorString&, const String& text, con
     bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false;
     JSC::Yarr::RegularExpression regex = ContentSearchUtilities::createSearchRegex(text, caseSensitive, isRegex);
 
-    for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
+    for (Frame* frame = &m_inspectedPage.mainFrame(); frame; frame = frame->tree().traverseNext()) {
         for (auto* cachedResource : cachedResourcesForFrame(frame)) {
             if (auto textContent = InspectorNetworkAgent::textContentForCachedResource(*cachedResource)) {
                 int matchesCount = ContentSearchUtilities::countRegularExpressionMatches(regex, *textContent);
@@ -662,11 +681,6 @@ void InspectorPageAgent::frameDetached(Frame& frame)
     m_identifierToFrame.remove(identifier);
 }
 
-Frame& InspectorPageAgent::mainFrame()
-{
-    return m_page.mainFrame();
-}
-
 Frame* InspectorPageAgent::frameForId(const String& frameId)
 {
     return frameId.isEmpty() ? nullptr : m_identifierToFrame.get(frameId);
@@ -683,11 +697,6 @@ String InspectorPageAgent::frameId(Frame* frame)
     }).iterator->value;
 }
 
-bool InspectorPageAgent::hasIdForFrame(Frame* frame) const
-{
-    return frame && m_frameToIdentifier.contains(frame);
-}
-
 String InspectorPageAgent::loaderId(DocumentLoader* loader)
 {
     if (!loader)
@@ -697,15 +706,6 @@ String InspectorPageAgent::loaderId(DocumentLoader* loader)
     }).iterator->value;
 }
 
-Frame* InspectorPageAgent::findFrameWithSecurityOrigin(const String& originRawString)
-{
-    for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
-        if (frame->document()->securityOrigin().toRawString() == originRawString)
-            return frame;
-    }
-    return nullptr;
-}
-
 Frame* InspectorPageAgent::assertFrame(ErrorString& errorString, const String& frameId)
 {
     Frame* frame = frameForId(frameId);
@@ -714,15 +714,6 @@ Frame* InspectorPageAgent::assertFrame(ErrorString& errorString, const String& f
     return frame;
 }
 
-DocumentLoader* InspectorPageAgent::assertDocumentLoader(ErrorString& errorString, Frame* frame)
-{
-    FrameLoader& frameLoader = frame->loader();
-    DocumentLoader* documentLoader = frameLoader.documentLoader();
-    if (!documentLoader)
-        errorString = "No documentLoader for given frame found"_s;
-    return documentLoader;
-}
-
 void InspectorPageAgent::loaderDetachedFromFrame(DocumentLoader& loader)
 {
     m_loaderToIdentifier.remove(&loader);
@@ -755,7 +746,7 @@ void InspectorPageAgent::defaultAppearanceDidChange(bool useDarkAppearance)
 
 void InspectorPageAgent::didPaint(RenderObject& renderer, const LayoutRect& rect)
 {
-    if (!m_enabled || !m_showPaintRects)
+    if (!m_showPaintRects)
         return;
 
     LayoutRect absoluteRect = LayoutRect(renderer.localToAbsoluteQuad(FloatRect(rect)).boundingBox());
@@ -781,22 +772,17 @@ void InspectorPageAgent::didLayout()
     if (isFirstLayout)
         m_isFirstLayoutAfterOnLoad = false;
 
-    if (!m_enabled)
-        return;
-
     m_overlay->update();
 }
 
 void InspectorPageAgent::didScroll()
 {
-    if (m_enabled)
-        m_overlay->update();
+    m_overlay->update();
 }
 
 void InspectorPageAgent::didRecalculateStyle()
 {
-    if (m_enabled)
-        m_overlay->update();
+    m_overlay->update();
 }
 
 Ref<Inspector::Protocol::Page::Frame> InspectorPageAgent::buildObjectForFrame(Frame* frame)
@@ -870,9 +856,9 @@ void InspectorPageAgent::setEmulatedMedia(ErrorString&, const String& media)
 
     m_emulatedMedia = media;
 
-    m_page.updateStyleAfterChangeInEnvironment();
+    m_inspectedPage.updateStyleAfterChangeInEnvironment();
 
-    if (auto* document = m_page.mainFrame().document())
+    if (auto* document = m_inspectedPage.mainFrame().document())
         document->updateLayout();
 }
 
@@ -884,11 +870,11 @@ void InspectorPageAgent::setForcedAppearance(ErrorString&, const String& appeara
     m_forcedAppearance = appearance;
 
     if (appearance == "Light"_s)
-        m_page.setUseDarkAppearanceOverride(false);
+        m_inspectedPage.setUseDarkAppearanceOverride(false);
     else if (appearance == "Dark"_s)
-        m_page.setUseDarkAppearanceOverride(true);
+        m_inspectedPage.setUseDarkAppearanceOverride(true);
     else
-        m_page.setUseDarkAppearanceOverride(WTF::nullopt);
+        m_inspectedPage.setUseDarkAppearanceOverride(WTF::nullopt);
 }
 
 void InspectorPageAgent::applyUserAgentOverride(String& userAgent)
@@ -905,26 +891,24 @@ void InspectorPageAgent::applyEmulatedMedia(String& media)
 
 void InspectorPageAgent::getCompositingBordersVisible(ErrorString&, bool* outParam)
 {
-    *outParam = m_page.settings().showDebugBorders() || m_page.settings().showRepaintCounter();
+    *outParam = m_inspectedPage.settings().showDebugBorders() || m_inspectedPage.settings().showRepaintCounter();
 }
 
 void InspectorPageAgent::setCompositingBordersVisible(ErrorString&, bool visible)
 {
-    m_page.settings().setShowDebugBorders(visible);
-    m_page.settings().setShowRepaintCounter(visible);
+    m_inspectedPage.settings().setShowDebugBorders(visible);
+    m_inspectedPage.settings().setShowRepaintCounter(visible);
 }
 
 void InspectorPageAgent::snapshotNode(ErrorString& errorString, int nodeId, String* outDataURL)
 {
-    Frame& frame = mainFrame();
-
     InspectorDOMAgent* domAgent = m_instrumentingAgents.inspectorDOMAgent();
     ASSERT(domAgent);
     Node* node = domAgent->assertNode(errorString, nodeId);
     if (!node)
         return;
 
-    std::unique_ptr<ImageBuffer> snapshot = WebCore::snapshotNode(frame, *node);
+    std::unique_ptr<ImageBuffer> snapshot = WebCore::snapshotNode(m_inspectedPage.mainFrame(), *node);
     if (!snapshot) {
         errorString = "Could not capture snapshot"_s;
         return;
@@ -935,14 +919,12 @@ void InspectorPageAgent::snapshotNode(ErrorString& errorString, int nodeId, Stri
 
 void InspectorPageAgent::snapshotRect(ErrorString& errorString, int x, int y, int width, int height, const String& coordinateSystem, String* outDataURL)
 {
-    Frame& frame = mainFrame();
-
     SnapshotOptions options = SnapshotOptionsNone;
     if (coordinateSystem == "Viewport")
         options |= SnapshotOptionsInViewCoordinates;
 
     IntRect rectangle(x, y, width, height);
-    std::unique_ptr<ImageBuffer> snapshot = snapshotFrameRect(frame, rectangle, options);
+    std::unique_ptr<ImageBuffer> snapshot = snapshotFrameRect(m_inspectedPage.mainFrame(), rectangle, options);
 
     if (!snapshot) {
         errorString = "Could not capture snapshot"_s;
@@ -955,8 +937,7 @@ void InspectorPageAgent::snapshotRect(ErrorString& errorString, int x, int y, in
 void InspectorPageAgent::archive(ErrorString& errorString, String* data)
 {
 #if ENABLE(WEB_ARCHIVE) && USE(CF)
-    Frame& frame = mainFrame();
-    auto archive = LegacyWebArchive::create(frame);
+    auto archive = LegacyWebArchive::create(m_inspectedPage.mainFrame());
     if (!archive) {
         errorString = "Could not create web archive for main frame"_s;
         return;
index c37b4dd..0ff4578 100644 (file)
@@ -79,12 +79,13 @@ public:
     static Vector<CachedResource*> cachedResourcesForFrame(Frame*);
     static void resourceContent(ErrorString&, Frame*, const URL&, String* result, bool* base64Encoded);
     static String sourceMapURLForResource(CachedResource*);
-
     static CachedResource* cachedResource(Frame*, const URL&);
     static Inspector::Protocol::Page::ResourceType resourceTypeJSON(ResourceType);
     static ResourceType inspectorResourceType(CachedResource::Type);
     static ResourceType inspectorResourceType(const CachedResource&);
     static Inspector::Protocol::Page::ResourceType cachedResourceTypeJSON(const CachedResource&);
+    static Frame* findFrameWithSecurityOrigin(Page&, const String& originRawString);
+    static DocumentLoader* assertDocumentLoader(ErrorString&, Frame*);
 
     // Page API for InspectorFrontend
     void enable(ErrorString&) final;
@@ -132,15 +133,10 @@ public:
     void willDestroyFrontendAndBackend(Inspector::DisconnectReason) final;
 
     // Cross-agents API
-    Page& page() { return m_page; }
-    Frame& mainFrame();
     Frame* frameForId(const String& frameId);
     WEBCORE_EXPORT String frameId(Frame*);
-    bool hasIdForFrame(Frame*) const;
     String loaderId(DocumentLoader*);
-    Frame* findFrameWithSecurityOrigin(const String& originRawString);
     Frame* assertFrame(ErrorString&, const String& frameId);
-    static DocumentLoader* assertDocumentLoader(ErrorString&, Frame*);
 
 private:
     double timestamp();
@@ -154,19 +150,18 @@ private:
     std::unique_ptr<Inspector::PageFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::PageBackendDispatcher> m_backendDispatcher;
 
-    Page& m_page;
+    Page& m_inspectedPage;
     InspectorClient* m_client { nullptr };
     InspectorOverlay* m_overlay { nullptr };
 
     HashMap<Frame*, String> m_frameToIdentifier;
     HashMap<String, Frame*> m_identifierToFrame;
     HashMap<DocumentLoader*, String> m_loaderToIdentifier;
-    bool m_enabled { false };
-    bool m_isFirstLayoutAfterOnLoad { false };
-    bool m_showPaintRects { false };
     String m_userAgentOverride;
     String m_emulatedMedia;
     String m_forcedAppearance;
+    bool m_isFirstLayoutAfterOnLoad { false };
+    bool m_showPaintRects { false };
 };
 
 } // namespace WebCore
index 6e24d02..cff3d23 100644 (file)
@@ -56,10 +56,9 @@ namespace WebCore {
 
 using namespace Inspector;
 
-PageDebuggerAgent::PageDebuggerAgent(PageAgentContext& context, InspectorPageAgent* pageAgent)
+PageDebuggerAgent::PageDebuggerAgent(PageAgentContext& context)
     : WebDebuggerAgent(context)
-    , m_page(context.inspectedPage)
-    , m_pageAgent(pageAgent)
+    , m_inspectedPage(context.inspectedPage)
 {
 }
 
@@ -81,7 +80,7 @@ String PageDebuggerAgent::sourceMapURLForScript(const Script& script)
     static NeverDestroyed<String> sourceMapHTTPHeaderDeprecated(MAKE_STATIC_STRING_IMPL("X-SourceMap"));
 
     if (!script.url.isEmpty()) {
-        CachedResource* resource = m_pageAgent->cachedResource(&m_page.mainFrame(), URL({ }, script.url));
+        CachedResource* resource = InspectorPageAgent::cachedResource(&m_inspectedPage.mainFrame(), URL({ }, script.url));
         if (resource) {
             String sourceMapHeader = resource->response().httpHeaderField(sourceMapHTTPHeader);
             if (!sourceMapHeader.isEmpty())
@@ -116,13 +115,13 @@ void PageDebuggerAgent::unmuteConsole()
 
 void PageDebuggerAgent::breakpointActionLog(JSC::ExecState& state, const String& message)
 {
-    m_pageAgent->page().console().addMessage(MessageSource::JS, MessageLevel::Log, message, createScriptCallStack(&state));
+    m_inspectedPage.console().addMessage(MessageSource::JS, MessageLevel::Log, message, createScriptCallStack(&state));
 }
 
 InjectedScript PageDebuggerAgent::injectedScriptForEval(ErrorString& errorString, const int* executionContextId)
 {
     if (!executionContextId) {
-        JSC::ExecState* scriptState = mainWorldExecState(&m_pageAgent->mainFrame());
+        JSC::ExecState* scriptState = mainWorldExecState(&m_inspectedPage.mainFrame());
         return injectedScriptManager().injectedScriptFor(scriptState);
     }
 
index e8122a9..a2acc2d 100644 (file)
@@ -38,7 +38,6 @@ namespace WebCore {
 class Document;
 class EventListener;
 class EventTarget;
-class InspectorPageAgent;
 class Page;
 class RegisteredEventListener;
 class TimerBase;
@@ -47,7 +46,7 @@ class PageDebuggerAgent final : public WebDebuggerAgent {
     WTF_MAKE_NONCOPYABLE(PageDebuggerAgent);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    PageDebuggerAgent(PageAgentContext&, InspectorPageAgent*);
+    PageDebuggerAgent(PageAgentContext&);
     virtual ~PageDebuggerAgent() = default;
 
     void didClearMainFrameWindowObject();
@@ -85,9 +84,7 @@ private:
 
     Inspector::InjectedScript injectedScriptForEval(ErrorString&, const int* executionContextId) override;
 
-    Page& m_page;
-
-    InspectorPageAgent* m_pageAgent;
+    Page& m_inspectedPage;
 
     HashMap<const RegisteredEventListener*, int> m_registeredEventListeners;
     HashMap<const TimerBase*, int> m_postMessageTimers;
index c5d926a..5c1731f 100644 (file)
@@ -38,23 +38,28 @@ namespace WebCore {
 
 using namespace Inspector;
 
-PageNetworkAgent::PageNetworkAgent(PageAgentContext& context, InspectorPageAgent* pageAgent)
+PageNetworkAgent::PageNetworkAgent(PageAgentContext& context)
     : InspectorNetworkAgent(context)
-    , m_pageAgent(pageAgent)
+    , m_inspectedPage(context.inspectedPage)
 {
-    ASSERT(m_pageAgent);
 }
 
 String PageNetworkAgent::loaderIdentifier(DocumentLoader* loader)
 {
-    return m_pageAgent->loaderId(loader);
+    if (loader) {
+        if (auto* pageAgent = m_instrumentingAgents.inspectorPageAgent())
+            return pageAgent->loaderId(loader);
+    }
+    return { };
 }
 
 String PageNetworkAgent::frameIdentifier(DocumentLoader* loader)
 {
-    if (!loader)
-        return { };
-    return m_pageAgent->frameId(loader->frame());
+    if (loader) {
+        if (auto* pageAgent = m_instrumentingAgents.inspectorPageAgent())
+            return pageAgent->frameId(loader->frame());
+    }
+    return { };
 }
 
 Vector<WebSocket*> PageNetworkAgent::activeWebSockets(const LockHolder& lock)
@@ -77,7 +82,7 @@ Vector<WebSocket*> PageNetworkAgent::activeWebSockets(const LockHolder& lock)
 
         // FIXME: <https://webkit.org/b/168475> Web Inspector: Correctly display iframe's WebSockets
         auto* document = downcast<Document>(webSocket->scriptExecutionContext());
-        if (document->page() != &m_pageAgent->page())
+        if (document->page() != &m_inspectedPage)
             continue;
 
         webSockets.append(webSocket);
@@ -88,12 +93,18 @@ Vector<WebSocket*> PageNetworkAgent::activeWebSockets(const LockHolder& lock)
 
 void PageNetworkAgent::setResourceCachingDisabled(bool disabled)
 {
-    m_pageAgent->page().setResourceCachingDisabledOverride(disabled);
+    m_inspectedPage.setResourceCachingDisabledOverride(disabled);
 }
 
 ScriptExecutionContext* PageNetworkAgent::scriptExecutionContext(ErrorString& errorString, const String& frameId)
 {
-    auto* frame = m_pageAgent->assertFrame(errorString, frameId);
+    auto* pageAgent = m_instrumentingAgents.inspectorPageAgent();
+    if (!pageAgent) {
+        errorString = "Missing Page agent"_s;
+        return nullptr;
+    }
+
+    auto* frame = pageAgent->assertFrame(errorString, frameId);
     if (!frame)
         return nullptr;
 
index fe0ebeb..5a19d9a 100644 (file)
 
 namespace WebCore {
 
+class Page;
+
 class PageNetworkAgent final : public InspectorNetworkAgent {
     WTF_MAKE_NONCOPYABLE(PageNetworkAgent);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    PageNetworkAgent(PageAgentContext&, InspectorPageAgent*);
+    PageNetworkAgent(PageAgentContext&);
     virtual ~PageNetworkAgent() = default;
 
 private:
@@ -44,7 +46,7 @@ private:
     ScriptExecutionContext* scriptExecutionContext(ErrorString&, const String& frameId) final;
     bool shouldForceBufferingNetworkResourceData() const final { return false; }
 
-    InspectorPageAgent* m_pageAgent { nullptr };
+    Page& m_inspectedPage;
 };
 
 } // namespace WebCore