Web Inspector: Uncaught Exception: null is not an object (evaluating 'this.ownerDocum...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Apr 2019 21:06:43 +0000 (21:06 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Apr 2019 21:06:43 +0000 (21:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196420
<rdar://problem/49444205>

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* inspector/protocol/DOM.json:
Modify the existing `frameId` to represent the owner frame of the node, rather than the
frame it holds (in the case of an `<iframe>`).

Source/WebCore:

Modify the existing `frameId` to represent the owner frame of the node, rather than the
frame it holds (in the case of an `<iframe>`).

* inspector/agents/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::buildObjectForNode):

Source/WebInspectorUI:

* UserInterface/Models/DOMNode.js:
(WI.DOMNode):
(WI.DOMNode.prototype.get frame): Added.
(WI.DOMNode.prototype.get frameIdentifier): Deleted.
Modify the existing `frameId` to represent the owner frame of the node, rather than the
frame it holds (in the case of an `<iframe>`).

* UserInterface/Controllers/DOMDebuggerManager.js:
(WI.DOMDebuggerManager.prototype.domBreakpointsForNode):
(WI.DOMDebuggerManager.prototype._detachDOMBreakpoint):
(WI.DOMDebuggerManager.prototype._resolveDOMBreakpoint):
(WI.DOMDebuggerManager.prototype._nodeInserted):
(WI.DOMDebuggerManager.prototype._nodeRemoved):
* UserInterface/Views/DOMTreeElement.js:
(WI.DOMTreeElement.prototype._populateTagContextMenu):
(WI.DOMTreeElement.prototype._buildAttributeDOM):
* UserInterface/Views/QuickConsole.js:
(WI.QuickConsole.prototype._selectExecutionContext):
* UserInterface/Views/SpreadsheetCSSStyleDeclarationSection.js:
(WI.SpreadsheetCSSStyleDeclarationSection.prototype._highlightNodesWithSelector):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/protocol/DOM.json
Source/WebCore/ChangeLog
Source/WebCore/inspector/agents/InspectorDOMAgent.cpp
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/DOMDebuggerManager.js
Source/WebInspectorUI/UserInterface/Models/DOMNode.js
Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js
Source/WebInspectorUI/UserInterface/Views/QuickConsole.js
Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationSection.js

index c031750..0819699 100644 (file)
@@ -1,3 +1,15 @@
+2019-04-23  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Uncaught Exception: null is not an object (evaluating 'this.ownerDocument.frameIdentifier')
+        https://bugs.webkit.org/show_bug.cgi?id=196420
+        <rdar://problem/49444205>
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/protocol/DOM.json:
+        Modify the existing `frameId` to represent the owner frame of the node, rather than the
+        frame it holds (in the case of an `<iframe>`).
+
 2019-04-23  Alex Christensen  <achristensen@webkit.org>
 
         Remove DeprecatedOptional
index 38ef776..1195e88 100644 (file)
@@ -47,6 +47,7 @@
                 { "name": "nodeName", "type": "string", "description": "<code>Node</code>'s nodeName." },
                 { "name": "localName", "type": "string", "description": "<code>Node</code>'s localName." },
                 { "name": "nodeValue", "type": "string", "description": "<code>Node</code>'s nodeValue." },
+                { "name": "frameId", "$ref": "Network.FrameId", "optional": true, "description": "Identifier of the containing frame." },
                 { "name": "childNodeCount", "type": "integer", "optional": true, "description": "Child count for <code>Container</code> nodes." },
                 { "name": "children", "type": "array", "optional": true, "items": { "$ref": "Node" }, "description": "Child nodes of this node when requested with children." },
                 { "name": "attributes", "type": "array", "optional": true, "items": { "type": "string" }, "description": "Attributes of the <code>Element</code> node in the form of flat array <code>[name1, value1, name2, value2]</code>." },
@@ -60,7 +61,6 @@
                 { "name": "pseudoType", "$ref": "PseudoType", "optional": true, "description": "Pseudo element type for this node." },
                 { "name": "shadowRootType", "$ref": "ShadowRootType", "optional": true, "description": "Shadow root type." },
                 { "name": "customElementState", "$ref": "CustomElementState", "optional": true, "description": "Custom element state." },
-                { "name": "frameId", "$ref": "Network.FrameId", "optional": true, "description": "Frame ID for frame owner elements." },
                 { "name": "contentDocument", "$ref": "Node", "optional": true, "description": "Content document for frame owner elements." },
                 { "name": "shadowRoots", "type": "array", "optional": true, "items": { "$ref": "Node" }, "description": "Shadow root list for given element host." },
                 { "name": "templateContent", "$ref": "Node", "optional": true, "description": "Content document fragment for template elements" },
index 3ac25e8..83ce3c5 100644 (file)
@@ -1,5 +1,19 @@
 2019-04-23  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Uncaught Exception: null is not an object (evaluating 'this.ownerDocument.frameIdentifier')
+        https://bugs.webkit.org/show_bug.cgi?id=196420
+        <rdar://problem/49444205>
+
+        Reviewed by Timothy Hatcher.
+
+        Modify the existing `frameId` to represent the owner frame of the node, rather than the
+        frame it holds (in the case of an `<iframe>`).
+
+        * inspector/agents/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::buildObjectForNode):
+
+2019-04-23  Devin Rousso  <drousso@apple.com>
+
         ContentSecurityPolicy::logToConsole should include line/column number and source location
         https://bugs.webkit.org/show_bug.cgi?id=114317
         <rdar://problem/13614617>
index 46dd82b..ce6a279 100644 (file)
@@ -59,6 +59,7 @@
 #include "EventNames.h"
 #include "Frame.h"
 #include "FrameTree.h"
+#include "FrameView.h"
 #include "FullscreenManager.h"
 #include "HTMLElement.h"
 #include "HTMLFrameOwnerElement.h"
@@ -1561,19 +1562,16 @@ Ref<Inspector::Protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode(Node*
     }
 
     auto* pageAgent = m_instrumentingAgents.inspectorPageAgent();
+    if (pageAgent) {
+        if (auto* frameView = node->document().view())
+            value->setFrameId(pageAgent->frameId(&frameView->frame()));
+    }
 
     if (is<Element>(*node)) {
         Element& element = downcast<Element>(*node);
         value->setAttributes(buildArrayForElementAttributes(&element));
         if (is<HTMLFrameOwnerElement>(element)) {
-            HTMLFrameOwnerElement& frameOwner = downcast<HTMLFrameOwnerElement>(element);
-            if (pageAgent) {
-                Frame* frame = frameOwner.contentFrame();
-                if (frame)
-                    value->setFrameId(pageAgent->frameId(frame));
-            }
-            Document* document = frameOwner.contentDocument();
-            if (document)
+            if (auto* document = downcast<HTMLFrameOwnerElement>(element).contentDocument())
                 value->setContentDocument(buildObjectForNode(document, 0, nodesMap));
         }
 
index d41e808..f622ad2 100644 (file)
@@ -1,5 +1,34 @@
 2019-04-23  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Uncaught Exception: null is not an object (evaluating 'this.ownerDocument.frameIdentifier')
+        https://bugs.webkit.org/show_bug.cgi?id=196420
+        <rdar://problem/49444205>
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Models/DOMNode.js:
+        (WI.DOMNode):
+        (WI.DOMNode.prototype.get frame): Added.
+        (WI.DOMNode.prototype.get frameIdentifier): Deleted.
+        Modify the existing `frameId` to represent the owner frame of the node, rather than the
+        frame it holds (in the case of an `<iframe>`).
+
+        * UserInterface/Controllers/DOMDebuggerManager.js:
+        (WI.DOMDebuggerManager.prototype.domBreakpointsForNode):
+        (WI.DOMDebuggerManager.prototype._detachDOMBreakpoint):
+        (WI.DOMDebuggerManager.prototype._resolveDOMBreakpoint):
+        (WI.DOMDebuggerManager.prototype._nodeInserted):
+        (WI.DOMDebuggerManager.prototype._nodeRemoved):
+        * UserInterface/Views/DOMTreeElement.js:
+        (WI.DOMTreeElement.prototype._populateTagContextMenu):
+        (WI.DOMTreeElement.prototype._buildAttributeDOM):
+        * UserInterface/Views/QuickConsole.js:
+        (WI.QuickConsole.prototype._selectExecutionContext):
+        * UserInterface/Views/SpreadsheetCSSStyleDeclarationSection.js:
+        (WI.SpreadsheetCSSStyleDeclarationSection.prototype._highlightNodesWithSelector):
+
+2019-04-23  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Canvas: no obvious way of switching to the overview when viewing an imported recording
         https://bugs.webkit.org/show_bug.cgi?id=197178
         <rdar://problem/50106641>
index 12fbeb9..09ab83b 100644 (file)
@@ -170,10 +170,10 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
     {
         console.assert(node instanceof WI.DOMNode);
 
-        if (!node)
+        if (!node || !node.frame)
             return [];
 
-        let domBreakpointNodeIdentifierMap = this._domBreakpointFrameIdentifierMap.get(node.frameIdentifier);
+        let domBreakpointNodeIdentifierMap = this._domBreakpointFrameIdentifierMap.get(node.frame.id);
         if (!domBreakpointNodeIdentifierMap)
             return [];
 
@@ -397,10 +397,10 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
         let nodeIdentifier = breakpoint.domNodeIdentifier;
         let node = WI.domManager.nodeForId(nodeIdentifier);
         console.assert(node, "Missing DOM node for breakpoint.", breakpoint);
-        if (!node)
+        if (!node || !node.frame)
             return;
 
-        let frameIdentifier = node.frameIdentifier;
+        let frameIdentifier = node.frame.id;
         let domBreakpointNodeIdentifierMap = this._domBreakpointFrameIdentifierMap.get(frameIdentifier);
         console.assert(domBreakpointNodeIdentifierMap, "Missing DOM breakpoints for node parent frame.", node);
         if (!domBreakpointNodeIdentifierMap)
@@ -457,10 +457,10 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
     {
         let node = WI.domManager.nodeForId(nodeIdentifier);
         console.assert(node, "Missing DOM node for nodeIdentifier.", nodeIdentifier);
-        if (!node)
+        if (!node || !node.frame)
             return;
 
-        let frameIdentifier = node.frameIdentifier;
+        let frameIdentifier = node.frame.id;
         let domBreakpointNodeIdentifierMap = this._domBreakpointFrameIdentifierMap.get(frameIdentifier);
         if (!domBreakpointNodeIdentifierMap) {
             domBreakpointNodeIdentifierMap = new Map;
@@ -611,10 +611,10 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
     _nodeInserted(event)
     {
         let node = event.data.node;
-        if (node.nodeType() !== Node.ELEMENT_NODE || !node.ownerDocument)
+        if (node.nodeType() !== Node.ELEMENT_NODE || !node.frame)
             return;
 
-        let url = node.ownerDocument.documentURL;
+        let url = node.frame.url;
         let breakpoints = this._domBreakpointURLMap.get(url);
         if (!breakpoints)
             return;
@@ -633,10 +633,10 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
     _nodeRemoved(event)
     {
         let node = event.data.node;
-        if (node.nodeType() !== Node.ELEMENT_NODE || !node.ownerDocument)
+        if (node.nodeType() !== Node.ELEMENT_NODE || !node.frame)
             return;
 
-        let domBreakpointNodeIdentifierMap = this._domBreakpointFrameIdentifierMap.get(node.frameIdentifier);
+        let domBreakpointNodeIdentifierMap = this._domBreakpointFrameIdentifierMap.get(node.frame.id);
         if (!domBreakpointNodeIdentifierMap)
             return;
 
@@ -647,7 +647,7 @@ WI.DOMDebuggerManager = class DOMDebuggerManager extends WI.Object
         domBreakpointNodeIdentifierMap.delete(node.id);
 
         if (!domBreakpointNodeIdentifierMap.size)
-            this._domBreakpointFrameIdentifierMap.delete(node.frameIdentifier);
+            this._domBreakpointFrameIdentifierMap.delete(node.frame.id);
 
         for (let breakpoint of breakpoints)
             breakpoint.domNodeIdentifier = null;
index 3981841..18b7e15 100644 (file)
@@ -56,6 +56,17 @@ WI.DOMNode = class DOMNode extends WI.Object
         else
             this.ownerDocument = doc;
 
+        this._frame = null;
+
+        // COMPATIBILITY (iOS 12.2): DOM.Node.frameId was changed to represent the owner frame, not the content frame.
+        if (InspectorBackend.domains.Timeline && !InspectorBackend.domains.Timeline.hasEvent("programmaticCaptureStarted")) {
+            if (payload.frameId)
+                this._frame = WI.networkManager.frameForIdentifier(payload.frameId);
+        }
+
+        if (!this._frame && this.ownerDocument)
+            this._frame = WI.networkManager.frameForIdentifier(this.ownerDocument.frameIdentifier);
+
         this._attributes = [];
         this._attributesMap = new Map;
         if (payload.attributes)
@@ -116,9 +127,6 @@ WI.DOMNode = class DOMNode extends WI.Object
             this._renumber();
         }
 
-        if (payload.frameId)
-            this._frameIdentifier = payload.frameId;
-
         if (this._nodeType === Node.ELEMENT_NODE) {
             // HTML and BODY from internal iframes should not overwrite top-level ones.
             if (this.ownerDocument && !this.ownerDocument.documentElement && this._nodeName === "HTML")
@@ -178,21 +186,10 @@ WI.DOMNode = class DOMNode extends WI.Object
 
     // Public
 
+    get frame() { return this._frame; }
     get domEvents() { return this._domEvents; }
     get lowPowerRanges() { return this._lowPowerRanges; }
 
-    get frameIdentifier()
-    {
-        return this._frameIdentifier || this.ownerDocument.frameIdentifier;
-    }
-
-    get frame()
-    {
-        if (!this._frame)
-            this._frame = WI.networkManager.frameForIdentifier(this.frameIdentifier);
-        return this._frame;
-    }
-
     get attached()
     {
         for (let node = this; node; node = node.parentNode) {
index c87d343..0be9b08 100644 (file)
@@ -736,11 +736,8 @@ WI.DOMTreeElement = class DOMTreeElement extends WI.TreeElement
         let isNonShadowEditable = !node.isInUserAgentShadowTree() && this.editable;
         let attached = node.attached;
 
-        if (event.target && event.target.tagName === "A") {
-            let url = event.target.href;
-            let frame = WI.networkManager.frameForIdentifier(node.frameIdentifier);
-            WI.appendContextMenuItemsForURL(contextMenu, url, {frame});
-        }
+        if (event.target && event.target.tagName === "A")
+            WI.appendContextMenuItemsForURL(contextMenu, event.target.href, {frame: node.frame});
 
         contextMenu.appendSeparator();
 
@@ -1276,7 +1273,7 @@ WI.DOMTreeElement = class DOMTreeElement extends WI.TreeElement
             attrSpanElement.append("=\u200B\"");
 
         if (name === "src" || /\bhref\b/.test(name)) {
-            let baseURL = node.ownerDocument ? node.ownerDocument.documentURL : null;
+            let baseURL = node.frame ? node.frame.url : null;
             let rewrittenURL = absoluteURL(value, baseURL);
             value = value.insertWordBreakCharacters();
             if (!rewrittenURL) {
@@ -1292,7 +1289,7 @@ WI.DOMTreeElement = class DOMTreeElement extends WI.TreeElement
                 attrSpanElement.appendChild(attrValueElement);
             }
         } else if (name === "srcset") {
-            let baseURL = node.ownerDocument ? node.ownerDocument.documentURL : null;
+            let baseURL = node.frame ? node.frame.url : null;
             attrValueElement = attrSpanElement.createChild("span", "html-attribute-value");
 
             // Leading whitespace.
index f3a55e7..5187b30 100644 (file)
@@ -145,11 +145,10 @@ WI.QuickConsole = class QuickConsole extends WI.View
 
         let inspectedNode = WI.domManager.inspectedNode;
         if (inspectedNode) {
-            let frame = inspectedNode.ownerDocument.frame;
+            let frame = inspectedNode.frame;
             if (frame) {
                 if (this._shouldAutomaticallySelectExecutionContext)
                     executionContext = frame.pageExecutionContext;
-
                 preferredName = this._preferredNameForFrame(frame);
             }
         }
index 67f6a77..b04f923 100644 (file)
@@ -493,13 +493,18 @@ WI.SpreadsheetCSSStyleDeclarationSection = class SpreadsheetCSSStyleDeclarationS
 
     _highlightNodesWithSelector()
     {
+        let node = this._style.node;
+
         if (!this._style.ownerRule) {
-            WI.domManager.highlightDOMNode(this._style.node.id);
+            WI.domManager.highlightDOMNode(node.id);
             return;
         }
 
         let selectorText = this._selectorElement.textContent.trim();
-        WI.domManager.highlightSelector(selectorText, this._style.node.ownerDocument.frameIdentifier);
+        if (node.frame)
+            WI.domManager.highlightSelector(selectorText, node.frame.id);
+        else
+            WI.domManager.highlightSelector(selectorText);
     }
 
     _hideDOMNodeHighlight()