Web Inspector: REGRESSION: lazy agents used outside of frontend/instrumentation can...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Apr 2019 23:15:08 +0000 (23:15 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Apr 2019 23:15:08 +0000 (23:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196725
<rdar://problem/49669810>

Reviewed by Timothy Hatcher.

Source/WebCore:

Move the logic for creating the `InspectorPageAgent` and `InspectorDOMAgent` into separate
functions so that callers into `InspectorController` can be guaranteed to have a valid
instance of the agent.

This doesn't interfere with the `Page.enable` command, as it doesn't clear any saved state.
There is no `DOM.enable` command, so there's no issue there either.

* inspector/InspectorController.h:
(WebCore::InspectorController::pageAgent): Deleted.
* inspector/InspectorController.cpp:
(WebCore::InspectorController::createLazyAgents):
(WebCore::InspectorController::inspect):
(WebCore::InspectorController::hideHighlight):
(WebCore::InspectorController::ensureDOMAgent): Added.
(WebCore::InspectorController::ensurePageAgent): Added.

* inspector/InspectorFrontendClientLocal.cpp:
(WebCore::InspectorFrontendClientLocal::showMainResourceForFrame):

Source/WebKit:

* WebProcess/WebPage/WebInspector.cpp:
(WebKit::WebInspector::showMainResourceForFrame):

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

Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/InspectorController.h
Source/WebCore/inspector/InspectorFrontendClientLocal.cpp
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/WebInspector.cpp

index b200f39..fb2d5a6 100644 (file)
@@ -1,3 +1,30 @@
+2019-04-10  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: REGRESSION: lazy agents used outside of frontend/instrumentation can be accessed before being created
+        https://bugs.webkit.org/show_bug.cgi?id=196725
+        <rdar://problem/49669810>
+
+        Reviewed by Timothy Hatcher.
+
+        Move the logic for creating the `InspectorPageAgent` and `InspectorDOMAgent` into separate
+        functions so that callers into `InspectorController` can be guaranteed to have a valid
+        instance of the agent.
+
+        This doesn't interfere with the `Page.enable` command, as it doesn't clear any saved state.
+        There is no `DOM.enable` command, so there's no issue there either.
+
+        * inspector/InspectorController.h:
+        (WebCore::InspectorController::pageAgent): Deleted.
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::createLazyAgents):
+        (WebCore::InspectorController::inspect):
+        (WebCore::InspectorController::hideHighlight):
+        (WebCore::InspectorController::ensureDOMAgent): Added.
+        (WebCore::InspectorController::ensurePageAgent): Added.
+
+        * inspector/InspectorFrontendClientLocal.cpp:
+        (WebCore::InspectorFrontendClientLocal::showMainResourceForFrame):
+
 2019-04-10  Alex Christensen  <achristensen@webkit.org>
 
         Add SPI WKNavigationResponse._downloadAttribute
index fb00124..6b31890 100644 (file)
@@ -157,9 +157,7 @@ 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));
+    ensurePageAgent();
 
     m_agents.append(std::make_unique<PageRuntimeAgent>(pageContext));
 
@@ -169,7 +167,7 @@ void InspectorController::createLazyAgents()
 
     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()));
+    ensureDOMAgent();
     m_agents.append(std::make_unique<InspectorDOMDebuggerAgent>(pageContext, debuggerAgentPtr));
     m_agents.append(std::make_unique<InspectorApplicationCacheAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorLayerTreeAgent>(pageContext));
@@ -382,8 +380,7 @@ void InspectorController::inspect(Node* node)
     if (!hasRemoteFrontend())
         show();
 
-    if (auto* domAgent = m_instrumentingAgents->inspectorDOMAgent())
-        domAgent->inspect(node);
+    ensureDOMAgent().inspect(node);
 }
 
 bool InspectorController::enabled() const
@@ -403,10 +400,7 @@ void InspectorController::dispatchMessageFromFrontend(const String& message)
 
 void InspectorController::hideHighlight()
 {
-    if (auto* domAgent = m_instrumentingAgents->inspectorDOMAgent()) {
-        ErrorString unused;
-        domAgent->hideHighlight(unused);
-    }
+    m_overlay->hideHighlight();
 }
 
 Node* InspectorController::highlightedNode() const
@@ -426,6 +420,28 @@ void InspectorController::setIndicating(bool indicating)
 #endif
 }
 
+InspectorDOMAgent& InspectorController::ensureDOMAgent()
+{
+    if (!m_inspectorDOMAgent) {
+        auto pageContext = pageAgentContext();
+        auto domAgent = std::make_unique<InspectorDOMAgent>(pageContext, m_overlay.get());
+        m_inspectorDOMAgent = domAgent.get();
+        m_agents.append(WTFMove(domAgent));
+    }
+    return *m_inspectorDOMAgent;
+}
+
+InspectorPageAgent& InspectorController::ensurePageAgent()
+{
+    if (!m_inspectorPageAgent) {
+        auto pageContext = pageAgentContext();
+        auto pageAgent = std::make_unique<InspectorPageAgent>(pageContext, m_inspectorClient, m_overlay.get());
+        m_inspectorPageAgent = pageAgent.get();
+        m_agents.append(WTFMove(pageAgent));
+    }
+    return *m_inspectorPageAgent;
+}
+
 bool InspectorController::developerExtrasEnabled() const
 {
     return m_page.settings().developerExtrasEnabled();
index b77a4d0..71f2642 100644 (file)
@@ -52,6 +52,7 @@ class DOMWrapperWorld;
 class Frame;
 class GraphicsContext;
 class InspectorClient;
+class InspectorDOMAgent;
 class InspectorFrontendClient;
 class InspectorInstrumentation;
 class InspectorPageAgent;
@@ -104,7 +105,9 @@ public:
 
     InspectorClient* inspectorClient() const { return m_inspectorClient; }
     InspectorFrontendClient* inspectorFrontendClient() const { return m_inspectorFrontendClient; }
-    InspectorPageAgent* pageAgent() const { return m_pageAgent; }
+
+    InspectorDOMAgent& ensureDOMAgent();
+    WEBCORE_EXPORT InspectorPageAgent& ensurePageAgent();
 
     // InspectorEnvironment
     bool developerExtrasEnabled() const override;
@@ -136,7 +139,10 @@ private:
     InspectorFrontendClient* m_inspectorFrontendClient { nullptr };
 
     Inspector::InspectorAgent* m_inspectorAgent { nullptr };
-    InspectorPageAgent* m_pageAgent { nullptr };
+
+    // Lazy, but also on-demand agents.
+    InspectorDOMAgent* m_inspectorDOMAgent { nullptr };
+    InspectorPageAgent* m_inspectorPageAgent { nullptr };
 
     bool m_isUnderTest { false };
     bool m_isAutomaticInspection { false };
index 243d849..74120d2 100644 (file)
@@ -338,7 +338,7 @@ void InspectorFrontendClientLocal::showResources()
 
 void InspectorFrontendClientLocal::showMainResourceForFrame(Frame* frame)
 {
-    String frameId = m_inspectedPageController->pageAgent()->frameId(frame);
+    String frameId = m_inspectedPageController->ensurePageAgent().frameId(frame);
     evaluateOnLoad(makeString("[\"showMainResourceForFrame\", \"", frameId, "\"]"));
 }
 
index a960f18..1a2b874 100644 (file)
@@ -1,3 +1,14 @@
+2019-04-10  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: REGRESSION: lazy agents used outside of frontend/instrumentation can be accessed before being created
+        https://bugs.webkit.org/show_bug.cgi?id=196725
+        <rdar://problem/49669810>
+
+        Reviewed by Timothy Hatcher.
+
+        * WebProcess/WebPage/WebInspector.cpp:
+        (WebKit::WebInspector::showMainResourceForFrame):
+
 2019-04-10  Youenn Fablet  <youenn@apple.com>
 
         Clear Cache Storage structures before removing all related files
index 8a83b80..d77e637 100644 (file)
@@ -232,7 +232,7 @@ void WebInspector::showMainResourceForFrame(uint64_t frameIdentifier)
 
     m_page->corePage()->inspectorController().show();
 
-    String inspectorFrameIdentifier = m_page->corePage()->inspectorController().pageAgent()->frameId(frame->coreFrame());
+    String inspectorFrameIdentifier = m_page->corePage()->inspectorController().ensurePageAgent().frameId(frame->coreFrame());
 
     whenFrontendConnectionEstablished([=] {
         m_frontendConnection->send(Messages::WebInspectorUI::ShowMainResourceForFrame(inspectorFrameIdentifier), 0);