Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Side by Side Diff: Source/core/inspector/InspectorDOMAgent.cpp

Issue 1092123004: DevTools: remove dependency of most agents on InspectorPageAgent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed debug build Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/inspector/InspectorDOMAgent.h ('k') | Source/core/inspector/InspectorInputAgent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Copyright (C) 2009 Joseph Pecoraro 4 * Copyright (C) 2009 Joseph Pecoraro
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "core/inspector/DOMEditor.h" 65 #include "core/inspector/DOMEditor.h"
66 #include "core/inspector/DOMPatchSupport.h" 66 #include "core/inspector/DOMPatchSupport.h"
67 #include "core/inspector/EventListenerInfo.h" 67 #include "core/inspector/EventListenerInfo.h"
68 #include "core/inspector/IdentifiersFactory.h" 68 #include "core/inspector/IdentifiersFactory.h"
69 #include "core/inspector/InjectedScriptHost.h" 69 #include "core/inspector/InjectedScriptHost.h"
70 #include "core/inspector/InjectedScriptManager.h" 70 #include "core/inspector/InjectedScriptManager.h"
71 #include "core/inspector/InspectorHighlight.h" 71 #include "core/inspector/InspectorHighlight.h"
72 #include "core/inspector/InspectorHistory.h" 72 #include "core/inspector/InspectorHistory.h"
73 #include "core/inspector/InspectorIdentifiers.h" 73 #include "core/inspector/InspectorIdentifiers.h"
74 #include "core/inspector/InspectorOverlay.h" 74 #include "core/inspector/InspectorOverlay.h"
75 #include "core/inspector/InspectorPageAgent.h" 75 #include "core/inspector/InspectorResolver.h"
76 #include "core/inspector/InspectorState.h" 76 #include "core/inspector/InspectorState.h"
77 #include "core/inspector/InstrumentingAgents.h" 77 #include "core/inspector/InstrumentingAgents.h"
78 #include "core/layout/HitTestResult.h" 78 #include "core/layout/HitTestResult.h"
79 #include "core/layout/LayoutView.h" 79 #include "core/layout/LayoutView.h"
80 #include "core/loader/DocumentLoader.h" 80 #include "core/loader/DocumentLoader.h"
81 #include "core/page/FrameTree.h" 81 #include "core/page/FrameTree.h"
82 #include "core/page/Page.h" 82 #include "core/page/Page.h"
83 #include "core/xml/DocumentXPathEvaluator.h" 83 #include "core/xml/DocumentXPathEvaluator.h"
84 #include "core/xml/XPathResult.h" 84 #include "core/xml/XPathResult.h"
85 #include "platform/PlatformGestureEvent.h" 85 #include "platform/PlatformGestureEvent.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 *type = TypeBuilder::DOM::PseudoType::Resizer; 285 *type = TypeBuilder::DOM::PseudoType::Resizer;
286 return true; 286 return true;
287 case INPUT_LIST_BUTTON: 287 case INPUT_LIST_BUTTON:
288 *type = TypeBuilder::DOM::PseudoType::Input_list_button; 288 *type = TypeBuilder::DOM::PseudoType::Input_list_button;
289 return true; 289 return true;
290 default: 290 default:
291 return false; 291 return false;
292 } 292 }
293 } 293 }
294 294
295 InspectorDOMAgent::InspectorDOMAgent(InspectorPageAgent* pageAgent, InjectedScri ptManager* injectedScriptManager, InspectorOverlay* overlay) 295 InspectorDOMAgent::InspectorDOMAgent(LocalFrame* inspectedFrame, InjectedScriptM anager* injectedScriptManager, InspectorOverlay* overlay)
296 : InspectorBaseAgent<InspectorDOMAgent, InspectorFrontend::DOM>("DOM") 296 : InspectorBaseAgent<InspectorDOMAgent, InspectorFrontend::DOM>("DOM")
297 , m_pageAgent(pageAgent) 297 , m_inspectedFrame(inspectedFrame)
298 , m_injectedScriptManager(injectedScriptManager) 298 , m_injectedScriptManager(injectedScriptManager)
299 , m_overlay(overlay) 299 , m_overlay(overlay)
300 , m_domListener(nullptr) 300 , m_domListener(nullptr)
301 , m_documentNodeToIdMap(adoptPtrWillBeNoop(new NodeToIdMap())) 301 , m_documentNodeToIdMap(adoptPtrWillBeNoop(new NodeToIdMap()))
302 , m_lastNodeId(1) 302 , m_lastNodeId(1)
303 , m_searchingForNode(NotSearching) 303 , m_searchingForNode(NotSearching)
304 , m_suppressAttributeModifiedEvent(false) 304 , m_suppressAttributeModifiedEvent(false)
305 , m_listener(nullptr) 305 , m_listener(nullptr)
306 , m_backendNodeIdToInspect(0) 306 , m_backendNodeIdToInspect(0)
307 { 307 {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 530 }
531 531
532 return element; 532 return element;
533 } 533 }
534 534
535 void InspectorDOMAgent::innerEnable() 535 void InspectorDOMAgent::innerEnable()
536 { 536 {
537 m_state->setBoolean(DOMAgentState::domAgentEnabled, true); 537 m_state->setBoolean(DOMAgentState::domAgentEnabled, true);
538 m_history = adoptPtrWillBeNoop(new InspectorHistory()); 538 m_history = adoptPtrWillBeNoop(new InspectorHistory());
539 m_domEditor = adoptPtrWillBeNoop(new DOMEditor(m_history.get())); 539 m_domEditor = adoptPtrWillBeNoop(new DOMEditor(m_history.get()));
540 m_document = m_pageAgent->inspectedFrame()->document(); 540 m_document = m_inspectedFrame->document();
541 m_instrumentingAgents->setInspectorDOMAgent(this); 541 m_instrumentingAgents->setInspectorDOMAgent(this);
542 if (m_listener) 542 if (m_listener)
543 m_listener->domAgentWasEnabled(); 543 m_listener->domAgentWasEnabled();
544 if (m_backendNodeIdToInspect) 544 if (m_backendNodeIdToInspect)
545 frontend()->inspectNodeRequested(m_backendNodeIdToInspect); 545 frontend()->inspectNodeRequested(m_backendNodeIdToInspect);
546 m_backendNodeIdToInspect = 0; 546 m_backendNodeIdToInspect = 0;
547 } 547 }
548 548
549 void InspectorDOMAgent::enable(ErrorString*) 549 void InspectorDOMAgent::enable(ErrorString*)
550 { 550 {
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 highlightConfig->contentOutline = parseColor(outlineColor); 1305 highlightConfig->contentOutline = parseColor(outlineColor);
1306 m_overlay->highlightQuad(quad, *highlightConfig); 1306 m_overlay->highlightQuad(quad, *highlightConfig);
1307 } 1307 }
1308 1308
1309 void InspectorDOMAgent::highlightNode(ErrorString* errorString, const RefPtr<JSO NObject>& highlightInspectorObject, const int* nodeId, const int* backendNodeId, const String* objectId) 1309 void InspectorDOMAgent::highlightNode(ErrorString* errorString, const RefPtr<JSO NObject>& highlightInspectorObject, const int* nodeId, const int* backendNodeId, const String* objectId)
1310 { 1310 {
1311 Node* node = nullptr; 1311 Node* node = nullptr;
1312 if (nodeId) { 1312 if (nodeId) {
1313 node = assertNode(errorString, *nodeId); 1313 node = assertNode(errorString, *nodeId);
1314 } else if (backendNodeId) { 1314 } else if (backendNodeId) {
1315 node = DOMNodeIds::nodeForId(*backendNodeId); 1315 node = InspectorResolver::resolveNode(m_inspectedFrame, *backendNodeId);
1316 } else if (objectId) { 1316 } else if (objectId) {
1317 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptF orObjectId(*objectId); 1317 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptF orObjectId(*objectId);
1318 node = injectedScript.nodeForObjectId(*objectId); 1318 node = injectedScript.nodeForObjectId(*objectId);
1319 if (!node) 1319 if (!node)
1320 *errorString = "Node for given objectId not found"; 1320 *errorString = "Node for given objectId not found";
1321 } else 1321 } else
1322 *errorString = "Either nodeId or objectId must be specified"; 1322 *errorString = "Either nodeId or objectId must be specified";
1323 1323
1324 if (!node) 1324 if (!node)
1325 return; 1325 return;
1326 1326
1327 OwnPtr<InspectorHighlightConfig> highlightConfig = highlightConfigFromInspec torObject(errorString, highlightInspectorObject.get()); 1327 OwnPtr<InspectorHighlightConfig> highlightConfig = highlightConfigFromInspec torObject(errorString, highlightInspectorObject.get());
1328 if (!highlightConfig) 1328 if (!highlightConfig)
1329 return; 1329 return;
1330 1330
1331 m_overlay->highlightNode(node, 0 /* eventTarget */, *highlightConfig, false) ; 1331 m_overlay->highlightNode(node, 0 /* eventTarget */, *highlightConfig, false) ;
1332 } 1332 }
1333 1333
1334 void InspectorDOMAgent::highlightFrame( 1334 void InspectorDOMAgent::highlightFrame(
1335 ErrorString*, 1335 ErrorString* errorString,
1336 const String& frameId, 1336 const String& frameId,
1337 const RefPtr<JSONObject>* color, 1337 const RefPtr<JSONObject>* color,
1338 const RefPtr<JSONObject>* outlineColor) 1338 const RefPtr<JSONObject>* outlineColor)
1339 { 1339 {
1340 LocalFrame* frame = m_pageAgent->frameForId(frameId); 1340 LocalFrame* frame = InspectorResolver::resolveFrame(m_inspectedFrame, frameI d);
1341 if (!frame) {
1342 *errorString = "No frame for given id found";
1343 return;
1344 }
1345 FrameOwner* owner = frame->owner();
1341 // FIXME: Inspector doesn't currently work cross process. 1346 // FIXME: Inspector doesn't currently work cross process.
1342 if (frame && frame->deprecatedLocalOwner()) { 1347 if (!owner || !owner->isLocal())
1343 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new Inspecto rHighlightConfig()); 1348 return;
1344 highlightConfig->showInfo = true; // Always show tooltips for frames. 1349 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(owner);
1345 highlightConfig->content = parseColor(color); 1350 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new InspectorHig hlightConfig());
1346 highlightConfig->contentOutline = parseColor(outlineColor); 1351 highlightConfig->showInfo = true; // Always show tooltips for frames.
1347 m_overlay->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTarget */, *highlightConfig, false); 1352 highlightConfig->content = parseColor(color);
1348 } 1353 highlightConfig->contentOutline = parseColor(outlineColor);
1354 m_overlay->highlightNode(ownerElement, 0 /* eventTarget */, *highlightConfig , false);
1349 } 1355 }
1350 1356
1351 void InspectorDOMAgent::hideHighlight(ErrorString*) 1357 void InspectorDOMAgent::hideHighlight(ErrorString*)
1352 { 1358 {
1353 m_overlay->hideHighlight(); 1359 m_overlay->hideHighlight();
1354 } 1360 }
1355 1361
1356 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId) 1362 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId)
1357 { 1363 {
1358 Node* node = assertEditableNode(errorString, nodeId); 1364 Node* node = assertEditableNode(errorString, nodeId);
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 } 1815 }
1810 1816
1811 bool InspectorDOMAgent::isWhitespace(Node* node) 1817 bool InspectorDOMAgent::isWhitespace(Node* node)
1812 { 1818 {
1813 //TODO: pull ignoreWhitespace setting from the frontend and use here. 1819 //TODO: pull ignoreWhitespace setting from the frontend and use here.
1814 return node && node->nodeType() == Node::TEXT_NODE && node->nodeValue().stri pWhiteSpace().length() == 0; 1820 return node && node->nodeType() == Node::TEXT_NODE && node->nodeValue().stri pWhiteSpace().length() == 0;
1815 } 1821 }
1816 1822
1817 void InspectorDOMAgent::domContentLoadedEventFired(LocalFrame* frame) 1823 void InspectorDOMAgent::domContentLoadedEventFired(LocalFrame* frame)
1818 { 1824 {
1819 if (frame != m_pageAgent->inspectedFrame()) 1825 if (frame != m_inspectedFrame)
1820 return; 1826 return;
1821 1827
1822 // Re-push document once it is loaded. 1828 // Re-push document once it is loaded.
1823 discardFrontendBindings(); 1829 discardFrontendBindings();
1824 if (enabled()) 1830 if (enabled())
1825 frontend()->documentUpdated(); 1831 frontend()->documentUpdated();
1826 } 1832 }
1827 1833
1828 void InspectorDOMAgent::invalidateFrameOwnerElement(LocalFrame* frame) 1834 void InspectorDOMAgent::invalidateFrameOwnerElement(LocalFrame* frame)
1829 { 1835 {
(...skipping 11 matching lines...) Expand all
1841 unbind(frameOwner, m_documentNodeToIdMap.get()); 1847 unbind(frameOwner, m_documentNodeToIdMap.get());
1842 1848
1843 RefPtr<TypeBuilder::DOM::Node> value = buildObjectForNode(frameOwner, 0, m_d ocumentNodeToIdMap.get()); 1849 RefPtr<TypeBuilder::DOM::Node> value = buildObjectForNode(frameOwner, 0, m_d ocumentNodeToIdMap.get());
1844 Node* previousSibling = innerPreviousSibling(frameOwner); 1850 Node* previousSibling = innerPreviousSibling(frameOwner);
1845 int prevId = previousSibling ? m_documentNodeToIdMap->get(previousSibling) : 0; 1851 int prevId = previousSibling ? m_documentNodeToIdMap->get(previousSibling) : 0;
1846 frontend()->childNodeInserted(parentId, prevId, value.release()); 1852 frontend()->childNodeInserted(parentId, prevId, value.release());
1847 } 1853 }
1848 1854
1849 void InspectorDOMAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader) 1855 void InspectorDOMAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader)
1850 { 1856 {
1851 LocalFrame* inspectedFrame = m_pageAgent->inspectedFrame(); 1857 if (loader->frame() != m_inspectedFrame) {
1852 if (loader->frame() != inspectedFrame) {
1853 invalidateFrameOwnerElement(loader->frame()); 1858 invalidateFrameOwnerElement(loader->frame());
1854 return; 1859 return;
1855 } 1860 }
1856 1861
1857 setDocument(inspectedFrame->document()); 1862 setDocument(m_inspectedFrame->document());
1858 } 1863 }
1859 1864
1860 void InspectorDOMAgent::didInsertDOMNode(Node* node) 1865 void InspectorDOMAgent::didInsertDOMNode(Node* node)
1861 { 1866 {
1862 if (isWhitespace(node)) 1867 if (isWhitespace(node))
1863 return; 1868 return;
1864 1869
1865 // We could be attaching existing subtree. Forget the bindings. 1870 // We could be attaching existing subtree. Forget the bindings.
1866 unbind(node, m_documentNodeToIdMap.get()); 1871 unbind(node, m_documentNodeToIdMap.get());
1867 1872
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 } 2037 }
2033 } 2038 }
2034 } 2039 }
2035 2040
2036 void InspectorDOMAgent::frameDocumentUpdated(LocalFrame* frame) 2041 void InspectorDOMAgent::frameDocumentUpdated(LocalFrame* frame)
2037 { 2042 {
2038 Document* document = frame->document(); 2043 Document* document = frame->document();
2039 if (!document) 2044 if (!document)
2040 return; 2045 return;
2041 2046
2042 if (frame != m_pageAgent->inspectedFrame()) 2047 if (frame != m_inspectedFrame)
2043 return; 2048 return;
2044 2049
2045 // Only update the main frame document, nested frame document updates are no t required 2050 // Only update the main frame document, nested frame document updates are no t required
2046 // (will be handled by invalidateFrameOwnerElement()). 2051 // (will be handled by invalidateFrameOwnerElement()).
2047 setDocument(document); 2052 setDocument(document);
2048 } 2053 }
2049 2054
2050 void InspectorDOMAgent::pseudoElementCreated(PseudoElement* pseudoElement) 2055 void InspectorDOMAgent::pseudoElementCreated(PseudoElement* pseudoElement)
2051 { 2056 {
2052 Element* parent = pseudoElement->parentOrShadowHostElement(); 2057 Element* parent = pseudoElement->parentOrShadowHostElement();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2137 { 2142 {
2138 result = TypeBuilder::Array<int>::create(); 2143 result = TypeBuilder::Array<int>::create();
2139 for (const auto& backendNode : *backendNodeIds) { 2144 for (const auto& backendNode : *backendNodeIds) {
2140 int backendNodeId; 2145 int backendNodeId;
2141 2146
2142 if (!(backendNode)->asNumber(&backendNodeId)) { 2147 if (!(backendNode)->asNumber(&backendNodeId)) {
2143 *errorString = "Invalid argument type"; 2148 *errorString = "Invalid argument type";
2144 return; 2149 return;
2145 } 2150 }
2146 2151
2147 Node* node = DOMNodeIds::nodeForId(backendNodeId); 2152 if (Node* node = InspectorResolver::resolveNode(m_inspectedFrame, backen dNodeId))
2148 if (node && node->document().frame() && node->document().frame()->instru mentingAgents() == m_pageAgent->inspectedFrame()->instrumentingAgents())
2149 result->addItem(pushNodePathToFrontend(node)); 2153 result->addItem(pushNodePathToFrontend(node));
2150 else 2154 else
2151 result->addItem(0); 2155 result->addItem(0);
2152 } 2156 }
2153 } 2157 }
2154 2158
2155 class InspectableNode final : public InjectedScriptHost::InspectableObject { 2159 class InspectableNode final : public InjectedScriptHost::InspectableObject {
2156 public: 2160 public:
2157 explicit InspectableNode(Node* node) : m_node(node) { } 2161 explicit InspectableNode(Node* node) : m_node(node) { }
2158 virtual ScriptValue get(ScriptState* state) override 2162 virtual ScriptValue get(ScriptState* state) override
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2216 RefPtr<TypeBuilder::DOM::Node> root; 2220 RefPtr<TypeBuilder::DOM::Node> root;
2217 getDocument(errorString, root); 2221 getDocument(errorString, root);
2218 return errorString->isEmpty(); 2222 return errorString->isEmpty();
2219 } 2223 }
2220 return true; 2224 return true;
2221 } 2225 }
2222 2226
2223 DEFINE_TRACE(InspectorDOMAgent) 2227 DEFINE_TRACE(InspectorDOMAgent)
2224 { 2228 {
2225 visitor->trace(m_domListener); 2229 visitor->trace(m_domListener);
2226 visitor->trace(m_pageAgent); 2230 visitor->trace(m_inspectedFrame);
2227 visitor->trace(m_injectedScriptManager); 2231 visitor->trace(m_injectedScriptManager);
2228 visitor->trace(m_overlay); 2232 visitor->trace(m_overlay);
2229 #if ENABLE(OILPAN) 2233 #if ENABLE(OILPAN)
2230 visitor->trace(m_documentNodeToIdMap); 2234 visitor->trace(m_documentNodeToIdMap);
2231 visitor->trace(m_danglingNodeToIdMaps); 2235 visitor->trace(m_danglingNodeToIdMaps);
2232 visitor->trace(m_idToNode); 2236 visitor->trace(m_idToNode);
2233 visitor->trace(m_idToNodesMap); 2237 visitor->trace(m_idToNodesMap);
2234 visitor->trace(m_document); 2238 visitor->trace(m_document);
2235 visitor->trace(m_revalidateTask); 2239 visitor->trace(m_revalidateTask);
2236 visitor->trace(m_searchResults); 2240 visitor->trace(m_searchResults);
2237 #endif 2241 #endif
2238 visitor->trace(m_hoveredNodeForInspectMode); 2242 visitor->trace(m_hoveredNodeForInspectMode);
2239 visitor->trace(m_history); 2243 visitor->trace(m_history);
2240 visitor->trace(m_domEditor); 2244 visitor->trace(m_domEditor);
2241 visitor->trace(m_listener); 2245 visitor->trace(m_listener);
2242 InspectorBaseAgent::trace(visitor); 2246 InspectorBaseAgent::trace(visitor);
2243 } 2247 }
2244 2248
2245 } // namespace blink 2249 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorDOMAgent.h ('k') | Source/core/inspector/InspectorInputAgent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698