2011-03-31 Andrey Kosyakov <caseq@chromium.org>
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Apr 2011 08:56:55 +0000 (08:56 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Apr 2011 08:56:55 +0000 (08:56 +0000)
        Reviewed by Pavel Feldman.

        Web Inspector: provide front-end wrappers for DOMAgent.querySelector[All]() that take care of fetching the document
        https://bugs.webkit.org/show_bug.cgi?id=57466

        - removed documentWide parameter to querySelector[All]() (user document node id instead)
        - factor out document request logic within DOMAgent into separate method
        - add querySelector() and querySelectorAll() to DOMAgent.js, assure we have document before calling back-end
        - use the above wrappers for querySelector() and querySelectorAll(), do not call backend directly
        - minor style fixes in Inspector.json
        - more error logging

        * inspector/Inspector.json:
        * inspector/InspectorDOMAgent.cpp:
        (WebCore::InspectorDOMAgent::querySelector):
        (WebCore::InspectorDOMAgent::querySelectorAll):
        * inspector/InspectorDOMAgent.h:
        * inspector/front-end/AuditRules.js:
        (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun):
        (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun.getStyles):
        * inspector/front-end/CSSStyleModel.js:
        (WebInspector.CSSStyleModel.prototype.setRuleSelector.callback):
        (WebInspector.CSSStyleModel.prototype.setRuleSelector):
        (WebInspector.CSSStyleModel.prototype.addRule.callback):
        (WebInspector.CSSStyleModel.prototype.addRule):
        * inspector/front-end/DOMAgent.js:
        (WebInspector.DOMAgent.prototype.requestDocument.onDocumentAvailable):
        (WebInspector.DOMAgent.prototype.requestDocument):
        (WebInspector.DOMAgent.prototype.pushNodeToFrontend):
        (WebInspector.DOMAgent.prototype.pushNodeByPathToFrontend):
        (WebInspector.DOMAgent.prototype._dispatchWhenDocumentAvailable.onDocumentAvailable):
        (WebInspector.DOMAgent.prototype._dispatchWhenDocumentAvailable):
        (WebInspector.DOMAgent.prototype.cancelSearch):
        (WebInspector.DOMAgent.prototype.querySelector):
        (WebInspector.DOMAgent.prototype.querySelectorAll):

2011-03-31  Andrey Kosyakov  <caseq@chromium.org>

        Reviewed by Pavel Feldman.

        Web Inspector: provide front-end wrappers for DOMAgent.querySelector[All]() that take care of fetching the document
        https://bugs.webkit.org/show_bug.cgi?id=57466

        * inspector/elements/dom-agent-query-selector.html: removed documentWide parameter to querySelectorAll

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

LayoutTests/ChangeLog
LayoutTests/inspector/elements/dom-agent-query-selector.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/Inspector.json
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorDOMAgent.h
Source/WebCore/inspector/front-end/AuditRules.js
Source/WebCore/inspector/front-end/CSSStyleModel.js
Source/WebCore/inspector/front-end/DOMAgent.js

index 4738081..78b6efe 100644 (file)
@@ -1,3 +1,12 @@
+2011-03-31  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: provide front-end wrappers for DOMAgent.querySelector[All]() that take care of fetching the document
+        https://bugs.webkit.org/show_bug.cgi?id=57466
+
+        * inspector/elements/dom-agent-query-selector.html: removed documentWide parameter to querySelectorAll 
+
 2011-03-31  Adam Barth  <abarth@webkit.org>
 
         Add two more preloader tests to the WebKit2 Skipped list.
index 5634dd4..d4b26c0 100644 (file)
@@ -12,26 +12,27 @@ function test()
     function step1(node)
     {
         var containerId = node.id;
+        var documentId = node.ownerDocument.id;
 
         InspectorTest.runTestSuite([
             function testDocumentQuerySelector(next)
             {
-                DOMAgent.querySelector(containerId, "div.foo", true, dumpNodes.bind(null, next));
+                DOMAgent.querySelector(documentId, "div.foo", dumpNodes.bind(null, next));
             },
 
             function testDocumentQuerySelectorAll(next)
             {
-                DOMAgent.querySelectorAll(containerId, "div.foo", true, dumpNodes.bind(null, next));
+                DOMAgent.querySelectorAll(documentId, "div.foo", dumpNodes.bind(null, next));
             },
 
             function testQuerySelector(next)
             {
-                DOMAgent.querySelector(containerId, "div.foo", false, dumpNodes.bind(null, next));
+                DOMAgent.querySelector(containerId, "div.foo", dumpNodes.bind(null, next));
             },
 
             function testQuerySelectorAll(next)
             {
-                DOMAgent.querySelectorAll(containerId, "div.foo", false, dumpNodes.bind(null, next));
+                DOMAgent.querySelectorAll(containerId, "div.foo", dumpNodes.bind(null, next));
             }
         ]);
     }
index 688d49f..3d2b0f6 100644 (file)
@@ -1,3 +1,41 @@
+2011-03-31  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        - removed documentWide parameter to querySelector[All]() (user document node id instead)
+        - factor out document request logic within DOMAgent into separate method
+        - add querySelector() and querySelectorAll() to DOMAgent.js, assure we have document before calling back-end
+        - use the above wrappers for querySelector() and querySelectorAll(), do not call backend directly
+        - minor style fixes in Inspector.json
+        - more error logging
+
+        Web Inspector: provide front-end wrappers for DOMAgent.querySelector[All]() that take care of fetching the document
+        https://bugs.webkit.org/show_bug.cgi?id=57466
+
+        * inspector/Inspector.json:
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::querySelector):
+        (WebCore::InspectorDOMAgent::querySelectorAll):
+        * inspector/InspectorDOMAgent.h:
+        * inspector/front-end/AuditRules.js:
+        (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun):
+        (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun.getStyles):
+        * inspector/front-end/CSSStyleModel.js:
+        (WebInspector.CSSStyleModel.prototype.setRuleSelector.callback):
+        (WebInspector.CSSStyleModel.prototype.setRuleSelector):
+        (WebInspector.CSSStyleModel.prototype.addRule.callback):
+        (WebInspector.CSSStyleModel.prototype.addRule):
+        * inspector/front-end/DOMAgent.js:
+        (WebInspector.DOMAgent.prototype.requestDocument.onDocumentAvailable):
+        (WebInspector.DOMAgent.prototype.requestDocument):
+        (WebInspector.DOMAgent.prototype.pushNodeToFrontend):
+        (WebInspector.DOMAgent.prototype.pushNodeByPathToFrontend):
+        (WebInspector.DOMAgent.prototype._dispatchWhenDocumentAvailable.onDocumentAvailable):
+        (WebInspector.DOMAgent.prototype._dispatchWhenDocumentAvailable):
+        (WebInspector.DOMAgent.prototype.cancelSearch):
+        (WebInspector.DOMAgent.prototype.querySelector):
+        (WebInspector.DOMAgent.prototype.querySelectorAll):
+
 2011-04-01  Kent Tamura  <tkent@chromium.org>
 
         Apply sort-Xcode-project-file.
index 249e31b..6454c91 100644 (file)
             },
             {
                 "name": "disable"
-           },
+            },
             {
                 "name": "clearConsoleMessages"
             },
                     { "name": "messageObj", "$ref": "ConsoleMessage" }
                 ]
             },
-           {
+            {
                 "name": "consoleMessageRepeatCountUpdated",
                 "parameters": [
                     { "name": "count", "type": "integer" }
                 "parameters": [
                     { "name": "nodeId", "type": "integer", "description": "Id of the node to query upon." },
                     { "name": "selectors", "type": "string", "description": "Selector string." },
-                    { "name": "documentWide", "type": "boolean", "description": "Set to true to start querying from the node's document." }
                 ],
                 "returns": [
                     { "name": "elementId", "type": "integer", "description": "Query selector result." }
                 "parameters": [
                     { "name": "nodeId", "type": "integer", "description": "Id of the node to query upon." },
                     { "name": "selectors", "type": "string", "description": "Selector string." },
-                    { "name": "documentWide", "type": "boolean", "description": "Set to true to start querying from the node's document." }
                 ],
                 "returns": [
-                    { "name": "nodeIds", "type": "array", "items": { "type": "integer" }, "description": "Query selector result."  }
+                    { "name": "nodeIds", "type": "array", "items": { "type": "integer" }, "description": "Query selector result." }
                 ],
                 "description": "Executes <code>querySelectorAll</code> on a given node. Setting <code>documentWide</code> to true starts selecting from the document node."
             },
             {
                 "name": "setNodeName",
                 "parameters": [
-                    { "name": "nodeId", "type": "integer", "description": "Id of the node to set name for."  },
+                    { "name": "nodeId", "type": "integer", "description": "Id of the node to set name for." },
                     { "name": "name", "type": "string", "description": "New node's name." }
                 ],
                 "returns": [
index 933acb9..5483cd8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Apple Inc. All rights reserved.
- * Copyright (C) 2009-2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011 Google Inc. All rights reserved.
  * Copyright (C) 2009 Joseph Pecoraro
  *
  * Redistribution and use in source and binary forms, with or without
@@ -430,24 +430,6 @@ HTMLElement* InspectorDOMAgent::assertHTMLElement(ErrorString* errorString, int
     return toHTMLElement(element);
 }
 
-Node* InspectorDOMAgent::nodeToSelectOn(ErrorString* errorString, int nodeId, bool documentWide)
-{
-    Node* node;
-    if (!nodeId) {
-        node = m_document.get();
-        if (!node)
-            *errorString = "No document to query on.";
-    } else
-        node = assertNode(errorString, nodeId);
-
-    if (!node)
-        return 0;
-
-    if (documentWide && nodeId)
-        node = node->ownerDocument();
-    return node;
-}
-
 void InspectorDOMAgent::getDocument(ErrorString*, RefPtr<InspectorObject>* root)
 {
     m_inspectorState->setBoolean(DOMAgentState::documentRequested, true);
@@ -502,10 +484,10 @@ void InspectorDOMAgent::getChildNodes(ErrorString*, int nodeId)
     pushChildNodesToFrontend(nodeId);
 }
 
-void InspectorDOMAgent::querySelector(ErrorString* errorString, int nodeId, const String& selectors, bool documentWide, int* elementId)
+void InspectorDOMAgent::querySelector(ErrorString* errorString, int nodeId, const String& selectors, int* elementId)
 {
     *elementId = 0;
-    Node* node = nodeToSelectOn(errorString, nodeId, documentWide);
+    Node* node = assertNode(errorString, nodeId);
     if (!node)
         return;
 
@@ -520,9 +502,9 @@ void InspectorDOMAgent::querySelector(ErrorString* errorString, int nodeId, cons
         *elementId = pushNodePathToFrontend(element.get());
 }
 
-void InspectorDOMAgent::querySelectorAll(ErrorString* errorString, int nodeId, const String& selectors, bool documentWide, RefPtr<InspectorArray>* result)
+void InspectorDOMAgent::querySelectorAll(ErrorString* errorString, int nodeId, const String& selectors, RefPtr<InspectorArray>* result)
 {
-    Node* node = nodeToSelectOn(errorString, nodeId, documentWide);
+    Node* node = assertNode(errorString, nodeId);
     if (!node)
         return;
 
index 8aeb66b..00f3e6c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Apple Inc. All rights reserved.
- * Copyright (C) 2009-2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -111,8 +111,8 @@ public:
     void reset();
 
     // Methods called from the frontend for DOM nodes inspection.
-    void querySelector(ErrorString*, int nodeId, const String& selectors, bool documentWide, int* elementId);
-    void querySelectorAll(ErrorString*, int nodeId, const String& selectors, bool documentWide, RefPtr<InspectorArray>* result);
+    void querySelector(ErrorString*, int nodeId, const String& selectors, int* elementId);
+    void querySelectorAll(ErrorString*, int nodeId, const String& selectors, RefPtr<InspectorArray>* result);
     void getDocument(ErrorString*, RefPtr<InspectorObject>* root);
     void getChildNodes(ErrorString*, int nodeId);
     void setAttribute(ErrorString*, int elementId, const String& name, const String& value);
@@ -186,7 +186,6 @@ private:
     Node* assertNode(ErrorString*, int nodeId);
     Element* assertElement(ErrorString*, int nodeId);
     HTMLElement* assertHTMLElement(ErrorString*, int nodeId);
-    Node* nodeToSelectOn(ErrorString*, int nodeId, bool documentWide);
 
     int pushNodePathToFrontend(Node*);
     void pushChildNodesToFrontend(int nodeId);
index 6c9e4e3..fd03aa1 100644 (file)
@@ -721,20 +721,21 @@ WebInspector.AuditRules.ImageDimensionsRule.prototype = {
                 doneCallback();
         }
 
-        function getStyles(error, nodeIds)
+        function getStyles(nodeIds)
         {
-            if (error)
+            if (!nodeIds) {
+                console.error("Failed to get styles");
                 return;
+            }
             for (var i = 0; i < nodeIds.length; ++i)
                 WebInspector.cssModel.getStylesAsync(nodeIds[i], imageStylesReady.bind(this, nodeIds[i], i === nodeIds.length - 1));
         }
-
-        function getImages()
+        function onDocumentAvailable(root)
         {
-            DOMAgent.querySelectorAll(0, "img[src]", true, getStyles);
+            WebInspector.domAgent.querySelectorAll(root.id, "img[src]", getStyles);
         }
+        WebInspector.domAgent.requestDocument(onDocumentAvailable);
 
-        WebInspector.domAgent.requestDocument(getImages);
     }
 }
 
index 06d96a6..21c9d06 100644 (file)
@@ -133,7 +133,7 @@ WebInspector.CSSStyleModel.prototype = {
             if (error)
                 failureCallback();
             else
-                DOMAgent.querySelectorAll(nodeId, newSelector, true, checkAffectsCallback.bind(this, nodeId, successCallback, rulePayload));
+                WebInspector.domAgent.querySelectorAll(nodeId, newSelector, checkAffectsCallback.bind(this, nodeId, successCallback, rulePayload));
         }
 
         CSSAgent.setRuleSelector(ruleId, newSelector, callback.bind(this, nodeId, successCallback, failureCallback, newSelector));
@@ -155,7 +155,7 @@ WebInspector.CSSStyleModel.prototype = {
                 // Invalid syntax for a selector
                 failureCallback();
             } else
-                DOMAgent.querySelectorAll(nodeId, selector, true, checkAffectsCallback.bind(this, nodeId, successCallback, rulePayload));
+                WebInspector.domAgent.querySelectorAll(nodeId, selector, checkAffectsCallback.bind(this, nodeId, successCallback, rulePayload));
         }
 
         CSSAgent.addRule(nodeId, selector, callback.bind(this, successCallback, failureCallback, selector));
index a2a9c2d..5918941 100644 (file)
@@ -328,7 +328,7 @@ WebInspector.DOMAgent.prototype = {
             return;
         }
 
-        function mycallback(error, root)
+        function onDocumentAvailable(error, root)
         {
             if (!error)
                 this._setDocument(root);
@@ -336,44 +336,49 @@ WebInspector.DOMAgent.prototype = {
             if (callback)
                 callback(this._document);
         }
-        DOMAgent.getDocument(mycallback.bind(this));
+        DOMAgent.getDocument(onDocumentAvailable.bind(this));
     },
 
     pushNodeToFrontend: function(objectId, callback)
     {
-        function callbackWrapper(error, nodeId)
-        {
-            if (callback)
-                callback(error ? 0 : nodeId);
-        }
-
-        function mycallback()
-        {
-            if (this._document)
-                DOMAgent.pushNodeToFrontend(objectId, callbackWrapper);
-            else
-                callbackWrapper("No document");
-        }
-
-        this.requestDocument(mycallback.bind(this));
+        this._dispatchWhenDocumentAvailable(DOMAgent.pushNodeToFrontend.bind(DOMAgent), objectId, callback);
     },
 
     pushNodeByPathToFrontend: function(path, callback)
     {
-        function callbackWrapper(error, nodeId)
+        this._dispatchWhenDocumentAvailable(DOMAgent.pushNodeByPathToFrontend.bind(DOMAgent), path, callback);
+    },
+
+    _wrapClientCallback: function(callback)
+    {
+        if (!callback)
+            return;
+        return function(error, result)
         {
-            if (callback)
-                callback(error ? 0 : nodeId);
+            callback(error ? null : result);
         }
+    },
+
+    _dispatchWhenDocumentAvailable: function(action)
+    {
+        var requestArguments = Array.prototype.slice.call(arguments, 1);
+        var callbackWrapper;
 
-        function mycallback()
+        if (typeof requestArguments[requestArguments.length - 1] === "function") {
+            var callback = requestArguments.pop();
+            callbackWrapper = this._wrapClientCallback(callback);
+            requestArguments.push(callbackWrapper);
+        }
+        function onDocumentAvailable()
         {
             if (this._document)
-                DOMAgent.pushNodeByPathToFrontend(path, callbackWrapper);
-            else
-                callbackWrapper("No document");
+                action.apply(null, requestArguments);
+            else {
+                if (callbackWrapper)
+                    callbackWrapper("No document");
+            }
         }
-        this.requestDocument(mycallback.bind(this));
+        this.requestDocument(onDocumentAvailable.bind(this));
     },
 
     _attributesUpdated: function(nodeId, attrsArray)
@@ -488,6 +493,16 @@ WebInspector.DOMAgent.prototype = {
     {
         delete this._searchResultCollector;
         DOMAgent.cancelSearch();
+    },
+
+    querySelector: function(nodeId, selectors, callback)
+    {
+        DOMAgent.querySelector(nodeId, selectors, this._wrapClientCallback(callback));
+    },
+
+    querySelectorAll: function(nodeId, selectors, callback)
+    {
+        DOMAgent.querySelectorAll(nodeId, selectors, this._wrapClientCallback(callback));
     }
 }