2010-01-05 Alexander Pavlov <apavlov@chromium.org>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Jan 2010 23:53:00 +0000 (23:53 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Jan 2010 23:53:00 +0000 (23:53 +0000)
        Reviewed by Pavel Feldman.

        Provide the "documentURL" property for documents and frame owner elements

        This is necessary to determine owner document URLs for nodes (all nodes have
        the top-level document set as ownerDocument).
        https://bugs.webkit.org/show_bug.cgi?id=33025

        * inspector/InspectorDOMAgent.cpp:
        (WebCore::InspectorDOMAgent::buildObjectForNode):
        * inspector/front-end/DOMAgent.js:
        (WebInspector.DOMNode):

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

WebCore/ChangeLog
WebCore/inspector/InspectorDOMAgent.cpp
WebCore/inspector/InspectorDOMAgent.h
WebCore/inspector/front-end/DOMAgent.js

index 82aacda..6842cee 100644 (file)
@@ -1,3 +1,18 @@
+2010-01-05  Alexander Pavlov  <apavlov@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Provide the "documentURL" property for documents and frame owner elements
+
+        This is necessary to determine owner document URLs for nodes (all nodes have
+        the top-level document set as ownerDocument).
+        https://bugs.webkit.org/show_bug.cgi?id=33025
+
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::buildObjectForNode):
+        * inspector/front-end/DOMAgent.js:
+        (WebInspector.DOMNode):
+
 2010-01-05  Peter Kasting  <pkasting@google.com>
 
         Reviewed by Adam Barth.
index 6a6ca5f..9632806 100644 (file)
@@ -479,6 +479,13 @@ void InspectorDOMAgent::getEventListenersForNode(long callId, long nodeId)
     m_frontend->didGetEventListenersForNode(callId, nodeId, listenersArray);
 }
 
+String InspectorDOMAgent::documentURLString(Document* document) const
+{
+    if (!document || document->url().isNull())
+        return "";
+    return document->url().string();
+}
+
 ScriptObject InspectorDOMAgent::buildObjectForNode(Node* node, int depth, NodeToIdMap* nodesMap)
 {
     ScriptObject value = m_frontend->newScriptObject();
@@ -512,18 +519,25 @@ ScriptObject InspectorDOMAgent::buildObjectForNode(Node* node, int depth, NodeTo
     value.set("localName", localName);
     value.set("nodeValue", nodeValue);
 
-    if (node->nodeType() == Node::ELEMENT_NODE) {
-        Element* element = static_cast<Element*>(node);
-        value.set("attributes", buildArrayForElementAttributes(element));
-    }
     if (node->nodeType() == Node::ELEMENT_NODE || node->nodeType() == Node::DOCUMENT_NODE) {
         int nodeCount = innerChildNodeCount(node);
         value.set("childNodeCount", nodeCount);
         ScriptArray children = buildArrayForContainerChildren(node, depth, nodesMap);
         if (children.length() > 0)
             value.set("children", children);
-    }
-    if (node->nodeType() == Node::DOCUMENT_TYPE_NODE) {
+
+        if (node->nodeType() == Node::ELEMENT_NODE) {
+            Element* element = static_cast<Element*>(node);
+            value.set("attributes", buildArrayForElementAttributes(element));
+            if (node->isFrameOwnerElement()) {
+                HTMLFrameOwnerElement* frameOwner = static_cast<HTMLFrameOwnerElement*>(node);
+                value.set("documentURL", documentURLString(frameOwner->contentDocument()));
+            }
+        } else {
+            Document* document = static_cast<Document*>(node);
+            value.set("documentURL", documentURLString(document));
+        }
+    } else if (node->nodeType() == Node::DOCUMENT_TYPE_NODE) {
         DocumentType* docType = static_cast<DocumentType*>(node);
         value.set("publicId", docType->publicId());
         value.set("systemId", docType->systemId());
index 26df5aa..ae302a8 100644 (file)
@@ -131,6 +131,7 @@ namespace WebCore {
         bool isWhitespace(Node* node);
 
         Document* mainFrameDocument() const;
+        String documentURLString(Document* document) const;
         void discardBindings();
 
         InspectorFrontend* m_frontend;
index 9900cbb..480a43e 100644 (file)
@@ -66,11 +66,14 @@ WebInspector.DOMNode = function(doc, payload) {
             this.ownerDocument.documentElement = this;
         if (!this.ownerDocument.body && this.nodeName === "BODY")
             this.ownerDocument.body = this;
+        if (payload.documentURL)
+            this.documentURL = payload.documentURL;
     } else if (this.nodeType === Node.DOCUMENT_TYPE_NODE) {
         this.publicId = payload.publicId;
         this.systemId = payload.systemId;
         this.internalSubset = payload.internalSubset;
-    }
+    } else if (this.nodeType === Node.DOCUMENT_NODE)
+        this.documentURL = payload.documentURL;
 }
 
 WebInspector.DOMNode.prototype = {