Web Inspector: REGRESSION: Elements: "Inspect Element" context menu often doesn't...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Apr 2019 00:30:35 +0000 (00:30 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Apr 2019 00:30:35 +0000 (00:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197091
<rdar://problem/49953728>

Reviewed by Joseph Pecoraro.

Delay the `inspect` event fron firing with the focued node until the frontend has had a
chance to request the document. Otherwise, requesting the document clears the mapping of
node-to-id, so the focused node's id would no longer be valid.

* inspector/agents/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::didCreateFrontendAndBackend):
(WebCore::InspectorDOMAgent::willDestroyFrontendAndBackend):
(WebCore::InspectorDOMAgent::getDocument):
(WebCore::InspectorDOMAgent::focusNode):
(WebCore::InspectorDOMAgent::didCommitLoad):

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

Source/WebCore/ChangeLog
Source/WebCore/inspector/agents/InspectorDOMAgent.cpp

index c86c461..eec2bc9 100644 (file)
@@ -1,3 +1,22 @@
+2019-04-19  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: REGRESSION: Elements: "Inspect Element" context menu often doesn't select that element
+        https://bugs.webkit.org/show_bug.cgi?id=197091
+        <rdar://problem/49953728>
+
+        Reviewed by Joseph Pecoraro.
+
+        Delay the `inspect` event fron firing with the focued node until the frontend has had a
+        chance to request the document. Otherwise, requesting the document clears the mapping of
+        node-to-id, so the focused node's id would no longer be valid.
+
+        * inspector/agents/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorDOMAgent::willDestroyFrontendAndBackend):
+        (WebCore::InspectorDOMAgent::getDocument):
+        (WebCore::InspectorDOMAgent::focusNode):
+        (WebCore::InspectorDOMAgent::didCommitLoad):
+
 2019-04-19  John Wilander  <wilander@apple.com>
 
         Disable Ad Click Attribution in ephemeral sessions and make sure conversion requests use an ephemeral, stateless session
index 33955ac..46dd82b 100644 (file)
@@ -313,16 +313,15 @@ void InspectorDOMAgent::didCreateFrontendAndBackend(Inspector::FrontendRouter*,
     for (auto* mediaElement : HTMLMediaElement::allMediaElements())
         addEventListenersToNode(*mediaElement);
 #endif
-
-    if (m_nodeToFocus)
-        focusNode();
 }
 
 void InspectorDOMAgent::willDestroyFrontendAndBackend(Inspector::DisconnectReason)
 {
     m_history.reset();
     m_domEditor.reset();
+    m_nodeToFocus = nullptr;
     m_mousedOverNode = nullptr;
+    m_inspectedNode = nullptr;
 
     ErrorString unused;
     setSearchingForNode(unused, false, nullptr);
@@ -507,6 +506,9 @@ void InspectorDOMAgent::getDocument(ErrorString& errorString, RefPtr<Inspector::
     m_document = document;
 
     root = buildObjectForNode(m_document.get(), 2, &m_documentNodeToIdMap);
+
+    if (m_nodeToFocus)
+        focusNode();
 }
 
 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, int depth)
@@ -1105,7 +1107,7 @@ void InspectorDOMAgent::inspect(Node* inspectedNode)
 
 void InspectorDOMAgent::focusNode()
 {
-    if (!m_frontendDispatcher)
+    if (!m_documentRequested)
         return;
 
     ASSERT(m_nodeToFocus);
@@ -2136,6 +2138,15 @@ Node* InspectorDOMAgent::innerParentNode(Node* node)
 
 void InspectorDOMAgent::didCommitLoad(Document* document)
 {
+    if (m_nodeToFocus && &m_nodeToFocus->document() == document)
+        m_nodeToFocus = nullptr;
+
+    if (m_mousedOverNode && &m_mousedOverNode->document() == document)
+        m_mousedOverNode = nullptr;
+
+    if (m_inspectedNode && &m_inspectedNode->document() == document)
+        m_inspectedNode = nullptr;
+
     RefPtr<Element> frameOwner = document->ownerElement();
     if (!frameOwner)
         return;