WebCore/ChangeLog

 12010-06-22 Pavel Feldman <pfeldman@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Web Inspector: move nodeByPath from InjectedScript to InspectorBackend.
 6
 7 https://bugs.webkit.org/show_bug.cgi?id=40988
 8
 9 * inspector/InjectedScriptHost.cpp:
 10 * inspector/InjectedScriptHost.h:
 11 * inspector/InjectedScriptHost.idl:
 12 * inspector/InspectorBackend.cpp:
 13 (WebCore::InspectorBackend::pushNodeByPathToFrontend):
 14 * inspector/InspectorBackend.h:
 15 * inspector/InspectorBackend.idl:
 16 * inspector/InspectorDOMAgent.cpp:
 17 (WebCore::InspectorDOMAgent::pushNodeByPathToFrontend):
 18 (WebCore::InspectorDOMAgent::nodeForPath):
 19 * inspector/InspectorDOMAgent.h:
 20 * inspector/InspectorFrontend.cpp:
 21 (WebCore::InspectorFrontend::didPushNodeByPathToFrontend):
 22 * inspector/InspectorFrontend.h:
 23 * inspector/front-end/DOMAgent.js:
 24 * inspector/front-end/ElementsPanel.js:
 25 (WebInspector.ElementsPanel.prototype.setDocument):
 26 * inspector/front-end/InjectedScript.js:
 27 * inspector/front-end/InjectedScriptAccess.js:
 28
1292010-06-22 Yuta Kitamura <yutak@chromium.org>
230
331 Reviewed by Alexey Proskuryakov.

WebCore/inspector/InjectedScriptHost.cpp

@@long InjectedScriptHost::pushNodePathToFrontend(Node* node, bool withChildren, b
110110 return id;
111111}
112112
113 long InjectedScriptHost::pushNodeByPathToFrontend(const String& path)
114 {
115  InspectorDOMAgent* domAgent = inspectorDOMAgent();
116  if (!domAgent)
117  return 0;
118 
119  Node* node = domAgent->nodeForPath(path);
120  if (!node)
121  return 0;
122 
123  return domAgent->pushNodePathToFrontend(node);
124 }
125 
126113long InjectedScriptHost::inspectedNode(unsigned long num)
127114{
128115 InspectorDOMAgent* domAgent = inspectorDOMAgent();

WebCore/inspector/InjectedScriptHost.h

@@public:
6868 void copyText(const String& text);
6969 Node* nodeForId(long nodeId);
7070 long pushNodePathToFrontend(Node* node, bool withChildren, bool selectInUI);
71  long pushNodeByPathToFrontend(const String& path);
7271 long inspectedNode(unsigned long num);
7372
7473#if ENABLE(DATABASE)

WebCore/inspector/InjectedScriptHost.idl

@@module core {
3737 void copyText(in DOMString text);
3838 [Custom] DOMObject nodeForId(in long nodeId);
3939 [Custom] int pushNodePathToFrontend(in DOMObject node, in boolean withChildren, in boolean selectInUI);
40  long pushNodeByPathToFrontend(in DOMString path);
4140 long inspectedNode(in unsigned long num);
4241
4342#if defined(ENABLE_JAVASCRIPT_DEBUGGER) && ENABLE_JAVASCRIPT_DEBUGGER

WebCore/inspector/InspectorBackend.cpp

@@void InspectorBackend::searchCanceled()
413413 domAgent->searchCanceled();
414414}
415415
 416void InspectorBackend::pushNodeByPathToFrontend(long callId, const String& path)
 417{
 418 InspectorDOMAgent* domAgent = inspectorDOMAgent();
 419 InspectorFrontend* frontend = inspectorFrontend();
 420 if (!domAgent || !frontend)
 421 return;
 422
 423 long id = domAgent->pushNodeByPathToFrontend(path);
 424 frontend->didPushNodeByPathToFrontend(callId, id);
 425}
 426
416427void InspectorBackend::clearConsoleMessages()
417428{
418429 if (m_inspectorController)

WebCore/inspector/InspectorBackend.h

@@public:
130130 void addInspectedNode(long nodeId);
131131 void performSearch(const String& query, bool runSynchronously);
132132 void searchCanceled();
 133 void pushNodeByPathToFrontend(long callId, const String& path);
133134
134135 void clearConsoleMessages();
135136

WebCore/inspector/InspectorBackend.idl

@@module core {
105105 void addInspectedNode(in long nodeId);
106106 void performSearch(in DOMString query, in boolean runSynchronously);
107107 void searchCanceled();
 108 void pushNodeByPathToFrontend(in long callId, in DOMString path);
108109
109110 void clearConsoleMessages();
110111

WebCore/inspector/InspectorDOMAgent.cpp

@@void InspectorDOMAgent::pushChildNodesToFrontend(long nodeId)
355355 m_frontend->setChildNodes(nodeId, children);
356356}
357357
 358long InspectorDOMAgent::pushNodeByPathToFrontend(const String& path)
 359{
 360 Node* node = nodeForPath(path);
 361 if (!node)
 362 return 0;
 363 return pushNodePathToFrontend(node);
 364}
 365
358366long InspectorDOMAgent::inspectedNode(unsigned long num)
359367{
360368 if (num < m_inspectedNodes.size())

@@Node* InspectorDOMAgent::nodeForId(long id)
382390 return 0;
383391}
384392
385 Node* InspectorDOMAgent::nodeForPath(const String& path)
386 {
387  // The path is of form "1,HTML,2,BODY,1,DIV"
388  Node* node = mainFrameDocument();
389  if (!node)
390  return 0;
391 
392  Vector<String> pathTokens;
393  path.split(",", false, pathTokens);
394  for (size_t i = 0; i < pathTokens.size() - 1; i += 2) {
395  bool success = true;
396  unsigned childNumber = pathTokens[i].toUInt(&success);
397  if (!success)
398  return 0;
399  if (childNumber >= innerChildNodeCount(node))
400  return 0;
401 
402  Node* child = innerFirstChild(node);
403  String childName = pathTokens[i + 1];
404  for (size_t j = 0; child && j < childNumber; ++j)
405  child = innerNextSibling(child);
406 
407  if (!child || child->nodeName() != childName)
408  return 0;
409  node = child;
410  }
411  return node;
412 }
413 
414393void InspectorDOMAgent::getChildNodes(long callId, long nodeId)
415394{
416395 pushChildNodesToFrontend(nodeId);

@@bool InspectorDOMAgent::ruleAffectsNode(CSSStyleRule* rule, Node* node)
15851564 return false;
15861565}
15871566
 1567Node* InspectorDOMAgent::nodeForPath(const String& path)
 1568{
 1569 // The path is of form "1,HTML,2,BODY,1,DIV"
 1570 Node* node = mainFrameDocument();
 1571 if (!node)
 1572 return 0;
 1573
 1574 Vector<String> pathTokens;
 1575 path.split(",", false, pathTokens);
 1576 for (size_t i = 0; i < pathTokens.size() - 1; i += 2) {
 1577 bool success = true;
 1578 unsigned childNumber = pathTokens[i].toUInt(&success);
 1579 if (!success)
 1580 return 0;
 1581 if (childNumber >= innerChildNodeCount(node))
 1582 return 0;
 1583
 1584 Node* child = innerFirstChild(node);
 1585 String childName = pathTokens[i + 1];
 1586 for (size_t j = 0; child && j < childNumber; ++j)
 1587 child = innerNextSibling(child);
 1588
 1589 if (!child || child->nodeName() != childName)
 1590 return 0;
 1591 node = child;
 1592 }
 1593 return node;
 1594}
 1595
15881596ScriptArray InspectorDOMAgent::toArray(const Vector<String>& data)
15891597{
15901598 ScriptArray result = m_frontend->newScriptArray();

WebCore/inspector/InspectorDOMAgent.h

@@namespace WebCore {
134134 void didModifyDOMAttr(Element*);
135135
136136 Node* nodeForId(long nodeId);
137  Node* nodeForPath(const String& path);
138137 long pushNodePathToFrontend(Node* node);
139138 void pushChildNodesToFrontend(long nodeId);
 139 long pushNodeByPathToFrontend(const String& path);
140140 long inspectedNode(unsigned long num);
141141
142142 private:

@@namespace WebCore {
187187 String shorthandValue(CSSStyleDeclaration*, const String& shorthandProperty);
188188 String shorthandPriority(CSSStyleDeclaration*, const String& shorthandProperty);
189189 bool ruleAffectsNode(CSSStyleRule*, Node*);
 190 Node* nodeForPath(const String& path);
190191 ScriptArray toArray(const Vector<String>& data);
191192
192193 void discardBindings();

WebCore/inspector/InspectorFrontend.cpp

2929
3030#include "config.h"
3131#include "InspectorFrontend.h"
32 
3332#if ENABLE(INSPECTOR)
3433
3534#include "ConsoleMessage.h"

@@void InspectorFrontend::didSetOuterHTML(long callId, long nodeId)
541540 function.call();
542541}
543542
 543void InspectorFrontend::didPushNodeByPathToFrontend(long callId, long nodeId)
 544{
 545 ScriptFunctionCall function(m_webInspector, "dispatch");
 546 function.appendArgument("didPushNodeByPathToFrontend");
 547 function.appendArgument(callId);
 548 function.appendArgument(nodeId);
 549 function.call();
 550}
 551
544552void InspectorFrontend::didGetChildNodes(long callId)
545553{
546554 ScriptFunctionCall function(m_webInspector, "dispatch");

WebCore/inspector/InspectorFrontend.h

@@namespace WebCore {
147147 void didChangeTagName(long callId, long nodeId);
148148 void didGetOuterHTML(long callId, const String& outerHTML);
149149 void didSetOuterHTML(long callId, long nodeId);
 150 void didPushNodeByPathToFrontend(long callId, long nodeId);
150151
151152 void didGetStyles(long callId, const ScriptValue& styles);
152153 void didGetAllStyles(long callId, const ScriptArray& styles);

WebCore/inspector/front-end/DOMAgent.js

@@WebInspector.didRemoveNode = WebInspector.Callback.processCallback;
671671WebInspector.didChangeTagName = WebInspector.Callback.processCallback;
672672WebInspector.didGetOuterHTML = WebInspector.Callback.processCallback;
673673WebInspector.didSetOuterHTML = WebInspector.Callback.processCallback;
 674WebInspector.didPushNodeByPathToFrontend = WebInspector.Callback.processCallback;
674675WebInspector.didGetEventListenersForNode = WebInspector.Callback.processCallback;
675676
676677WebInspector.didGetStyles = WebInspector.Callback.processCallback;

WebCore/inspector/front-end/ElementsPanel.js

@@WebInspector.ElementsPanel.prototype = {
224224 selectNode.call(this, node);
225225 }
226226
227  if (this._selectedPathOnReset)
228  InjectedScriptAccess.getDefault().nodeByPath(this._selectedPathOnReset, selectLastSelectedNode.bind(this));
229  else
 227 if (this._selectedPathOnReset) {
 228 var callId = WebInspector.Callback.wrap(selectLastSelectedNode.bind(this));
 229 InspectorBackend.pushNodeByPathToFrontend(callId, this._selectedPathOnReset);
 230 } else
230231 selectNode.call(this);
231232 delete this._selectedPathOnReset;
232233 },

WebCore/inspector/front-end/InjectedScript.js

@@InjectedScript.pushNodeToFrontend = function(objectProxy)
403403 return InjectedScriptHost.pushNodePathToFrontend(object, false, false);
404404}
405405
406 InjectedScript.nodeByPath = function(path)
407 {
408  // We make this call through the injected script only to get a nice
409  // callback for it.
410  return InjectedScriptHost.pushNodeByPathToFrontend(path.join(","));
411 }
412 
413406// Called from within InspectorController on the 'inspected page' side.
414407InjectedScript.createProxyObject = function(object, objectId, abbreviate)
415408{

WebCore/inspector/front-end/InjectedScriptAccess.js

@@InjectedScriptAccess._installHandler("getProperties");
7777InjectedScriptAccess._installHandler("getPrototypes");
7878InjectedScriptAccess._installHandler("openInInspectedWindow");
7979InjectedScriptAccess._installHandler("pushNodeToFrontend");
80 InjectedScriptAccess._installHandler("nodeByPath");
8180InjectedScriptAccess._installHandler("setPropertyValue");
8281InjectedScriptAccess._installHandler("evaluateOnSelf");
8382