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

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: further cuts on InspectorPageAgent inter-agents API Created 5 years, 8 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
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"
76 #include "core/inspector/InspectorState.h" 75 #include "core/inspector/InspectorState.h"
77 #include "core/inspector/InstrumentingAgents.h" 76 #include "core/inspector/InstrumentingAgents.h"
78 #include "core/layout/HitTestResult.h" 77 #include "core/layout/HitTestResult.h"
79 #include "core/layout/LayoutView.h" 78 #include "core/layout/LayoutView.h"
80 #include "core/loader/DocumentLoader.h" 79 #include "core/loader/DocumentLoader.h"
81 #include "core/page/FrameTree.h" 80 #include "core/page/FrameTree.h"
82 #include "core/page/Page.h" 81 #include "core/page/Page.h"
83 #include "core/xml/DocumentXPathEvaluator.h" 82 #include "core/xml/DocumentXPathEvaluator.h"
84 #include "core/xml/XPathResult.h" 83 #include "core/xml/XPathResult.h"
85 #include "platform/PlatformGestureEvent.h" 84 #include "platform/PlatformGestureEvent.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 *type = TypeBuilder::DOM::PseudoType::Resizer; 284 *type = TypeBuilder::DOM::PseudoType::Resizer;
286 return true; 285 return true;
287 case INPUT_LIST_BUTTON: 286 case INPUT_LIST_BUTTON:
288 *type = TypeBuilder::DOM::PseudoType::Input_list_button; 287 *type = TypeBuilder::DOM::PseudoType::Input_list_button;
289 return true; 288 return true;
290 default: 289 default:
291 return false; 290 return false;
292 } 291 }
293 } 292 }
294 293
295 InspectorDOMAgent::InspectorDOMAgent(InspectorPageAgent* pageAgent, InjectedScri ptManager* injectedScriptManager, InspectorOverlay* overlay) 294 InspectorDOMAgent::InspectorDOMAgent(LocalFrame* inspectedFrame, InjectedScriptM anager* injectedScriptManager, InspectorOverlay* overlay)
296 : InspectorBaseAgent<InspectorDOMAgent, InspectorFrontend::DOM>("DOM") 295 : InspectorBaseAgent<InspectorDOMAgent, InspectorFrontend::DOM>("DOM")
297 , m_pageAgent(pageAgent) 296 , m_inspectedFrame(inspectedFrame)
298 , m_injectedScriptManager(injectedScriptManager) 297 , m_injectedScriptManager(injectedScriptManager)
299 , m_overlay(overlay) 298 , m_overlay(overlay)
300 , m_domListener(nullptr) 299 , m_domListener(nullptr)
301 , m_documentNodeToIdMap(adoptPtrWillBeNoop(new NodeToIdMap())) 300 , m_documentNodeToIdMap(adoptPtrWillBeNoop(new NodeToIdMap()))
302 , m_lastNodeId(1) 301 , m_lastNodeId(1)
303 , m_searchingForNode(NotSearching) 302 , m_searchingForNode(NotSearching)
304 , m_suppressAttributeModifiedEvent(false) 303 , m_suppressAttributeModifiedEvent(false)
305 , m_listener(nullptr) 304 , m_listener(nullptr)
306 , m_backendNodeIdToInspect(0) 305 , m_backendNodeIdToInspect(0)
307 { 306 {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 529 }
531 530
532 return element; 531 return element;
533 } 532 }
534 533
535 void InspectorDOMAgent::innerEnable() 534 void InspectorDOMAgent::innerEnable()
536 { 535 {
537 m_state->setBoolean(DOMAgentState::domAgentEnabled, true); 536 m_state->setBoolean(DOMAgentState::domAgentEnabled, true);
538 m_history = adoptPtrWillBeNoop(new InspectorHistory()); 537 m_history = adoptPtrWillBeNoop(new InspectorHistory());
539 m_domEditor = adoptPtrWillBeNoop(new DOMEditor(m_history.get())); 538 m_domEditor = adoptPtrWillBeNoop(new DOMEditor(m_history.get()));
540 m_document = m_pageAgent->inspectedFrame()->document(); 539 m_document = m_inspectedFrame->document();
541 m_instrumentingAgents->setInspectorDOMAgent(this); 540 m_instrumentingAgents->setInspectorDOMAgent(this);
542 if (m_listener) 541 if (m_listener)
543 m_listener->domAgentWasEnabled(); 542 m_listener->domAgentWasEnabled();
544 if (m_backendNodeIdToInspect) 543 if (m_backendNodeIdToInspect)
545 frontend()->inspectNodeRequested(m_backendNodeIdToInspect); 544 frontend()->inspectNodeRequested(m_backendNodeIdToInspect);
546 m_backendNodeIdToInspect = 0; 545 m_backendNodeIdToInspect = 0;
547 } 546 }
548 547
549 void InspectorDOMAgent::enable(ErrorString*) 548 void InspectorDOMAgent::enable(ErrorString*)
550 { 549 {
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 return; 1324 return;
1326 1325
1327 OwnPtr<InspectorHighlightConfig> highlightConfig = highlightConfigFromInspec torObject(errorString, highlightInspectorObject.get()); 1326 OwnPtr<InspectorHighlightConfig> highlightConfig = highlightConfigFromInspec torObject(errorString, highlightInspectorObject.get());
1328 if (!highlightConfig) 1327 if (!highlightConfig)
1329 return; 1328 return;
1330 1329
1331 m_overlay->highlightNode(node, 0 /* eventTarget */, *highlightConfig, false) ; 1330 m_overlay->highlightNode(node, 0 /* eventTarget */, *highlightConfig, false) ;
1332 } 1331 }
1333 1332
1334 void InspectorDOMAgent::highlightFrame( 1333 void InspectorDOMAgent::highlightFrame(
1335 ErrorString*, 1334 ErrorString* errorString,
1336 const String& frameId, 1335 const String& frameId,
1337 const RefPtr<JSONObject>* color, 1336 const RefPtr<JSONObject>* color,
1338 const RefPtr<JSONObject>* outlineColor) 1337 const RefPtr<JSONObject>* outlineColor)
1339 { 1338 {
1340 LocalFrame* frame = m_pageAgent->frameForId(frameId); 1339 LocalFrame* frame = InspectorIdentifiers<LocalFrame>::lookup(frameId);
1341 // FIXME: Inspector doesn't currently work cross process. 1340 if (!frame || frame->instrumentingAgents() != m_inspectedFrame->instrumentin gAgents()) {
yurys 2015/04/24 08:54:40 Please return this.
1342 if (frame && frame->deprecatedLocalOwner()) { 1341 *errorString = "No frame for given id found";
1343 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new Inspecto rHighlightConfig()); 1342 return;
1344 highlightConfig->showInfo = true; // Always show tooltips for frames.
1345 highlightConfig->content = parseColor(color);
1346 highlightConfig->contentOutline = parseColor(outlineColor);
1347 m_overlay->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTarget */, *highlightConfig, false);
1348 } 1343 }
1344 FrameOwner* owner = frame->owner();
1345 if (!owner || !owner->isLocal())
1346 return;
1347 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(owner);
1348 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new InspectorHig hlightConfig());
1349 highlightConfig->showInfo = true; // Always show tooltips for frames.
1350 highlightConfig->content = parseColor(color);
1351 highlightConfig->contentOutline = parseColor(outlineColor);
1352 m_overlay->highlightNode(ownerElement, 0 /* eventTarget */, *highlightConfig , false);
1349 } 1353 }
1350 1354
1351 void InspectorDOMAgent::hideHighlight(ErrorString*) 1355 void InspectorDOMAgent::hideHighlight(ErrorString*)
1352 { 1356 {
1353 m_overlay->hideHighlight(); 1357 m_overlay->hideHighlight();
1354 } 1358 }
1355 1359
1356 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId) 1360 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId)
1357 { 1361 {
1358 Node* node = assertEditableNode(errorString, nodeId); 1362 Node* node = assertEditableNode(errorString, nodeId);
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 } 1813 }
1810 1814
1811 bool InspectorDOMAgent::isWhitespace(Node* node) 1815 bool InspectorDOMAgent::isWhitespace(Node* node)
1812 { 1816 {
1813 //TODO: pull ignoreWhitespace setting from the frontend and use here. 1817 //TODO: pull ignoreWhitespace setting from the frontend and use here.
1814 return node && node->nodeType() == Node::TEXT_NODE && node->nodeValue().stri pWhiteSpace().length() == 0; 1818 return node && node->nodeType() == Node::TEXT_NODE && node->nodeValue().stri pWhiteSpace().length() == 0;
1815 } 1819 }
1816 1820
1817 void InspectorDOMAgent::domContentLoadedEventFired(LocalFrame* frame) 1821 void InspectorDOMAgent::domContentLoadedEventFired(LocalFrame* frame)
1818 { 1822 {
1819 if (frame != m_pageAgent->inspectedFrame()) 1823 if (frame != m_inspectedFrame)
1820 return; 1824 return;
1821 1825
1822 // Re-push document once it is loaded. 1826 // Re-push document once it is loaded.
1823 discardFrontendBindings(); 1827 discardFrontendBindings();
1824 if (enabled()) 1828 if (enabled())
1825 frontend()->documentUpdated(); 1829 frontend()->documentUpdated();
1826 } 1830 }
1827 1831
1828 void InspectorDOMAgent::invalidateFrameOwnerElement(LocalFrame* frame) 1832 void InspectorDOMAgent::invalidateFrameOwnerElement(LocalFrame* frame)
1829 { 1833 {
(...skipping 11 matching lines...) Expand all
1841 unbind(frameOwner, m_documentNodeToIdMap.get()); 1845 unbind(frameOwner, m_documentNodeToIdMap.get());
1842 1846
1843 RefPtr<TypeBuilder::DOM::Node> value = buildObjectForNode(frameOwner, 0, m_d ocumentNodeToIdMap.get()); 1847 RefPtr<TypeBuilder::DOM::Node> value = buildObjectForNode(frameOwner, 0, m_d ocumentNodeToIdMap.get());
1844 Node* previousSibling = innerPreviousSibling(frameOwner); 1848 Node* previousSibling = innerPreviousSibling(frameOwner);
1845 int prevId = previousSibling ? m_documentNodeToIdMap->get(previousSibling) : 0; 1849 int prevId = previousSibling ? m_documentNodeToIdMap->get(previousSibling) : 0;
1846 frontend()->childNodeInserted(parentId, prevId, value.release()); 1850 frontend()->childNodeInserted(parentId, prevId, value.release());
1847 } 1851 }
1848 1852
1849 void InspectorDOMAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader) 1853 void InspectorDOMAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader)
1850 { 1854 {
1851 LocalFrame* inspectedFrame = m_pageAgent->inspectedFrame(); 1855 if (loader->frame() != m_inspectedFrame) {
1852 if (loader->frame() != inspectedFrame) {
1853 invalidateFrameOwnerElement(loader->frame()); 1856 invalidateFrameOwnerElement(loader->frame());
1854 return; 1857 return;
1855 } 1858 }
1856 1859
1857 setDocument(inspectedFrame->document()); 1860 setDocument(m_inspectedFrame->document());
1858 } 1861 }
1859 1862
1860 void InspectorDOMAgent::didInsertDOMNode(Node* node) 1863 void InspectorDOMAgent::didInsertDOMNode(Node* node)
1861 { 1864 {
1862 if (isWhitespace(node)) 1865 if (isWhitespace(node))
1863 return; 1866 return;
1864 1867
1865 // We could be attaching existing subtree. Forget the bindings. 1868 // We could be attaching existing subtree. Forget the bindings.
1866 unbind(node, m_documentNodeToIdMap.get()); 1869 unbind(node, m_documentNodeToIdMap.get());
1867 1870
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 } 2035 }
2033 } 2036 }
2034 } 2037 }
2035 2038
2036 void InspectorDOMAgent::frameDocumentUpdated(LocalFrame* frame) 2039 void InspectorDOMAgent::frameDocumentUpdated(LocalFrame* frame)
2037 { 2040 {
2038 Document* document = frame->document(); 2041 Document* document = frame->document();
2039 if (!document) 2042 if (!document)
2040 return; 2043 return;
2041 2044
2042 if (frame != m_pageAgent->inspectedFrame()) 2045 if (frame != m_inspectedFrame)
2043 return; 2046 return;
2044 2047
2045 // Only update the main frame document, nested frame document updates are no t required 2048 // Only update the main frame document, nested frame document updates are no t required
2046 // (will be handled by invalidateFrameOwnerElement()). 2049 // (will be handled by invalidateFrameOwnerElement()).
2047 setDocument(document); 2050 setDocument(document);
2048 } 2051 }
2049 2052
2050 void InspectorDOMAgent::pseudoElementCreated(PseudoElement* pseudoElement) 2053 void InspectorDOMAgent::pseudoElementCreated(PseudoElement* pseudoElement)
2051 { 2054 {
2052 Element* parent = pseudoElement->parentOrShadowHostElement(); 2055 Element* parent = pseudoElement->parentOrShadowHostElement();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 result = TypeBuilder::Array<int>::create(); 2141 result = TypeBuilder::Array<int>::create();
2139 for (const auto& backendNode : *backendNodeIds) { 2142 for (const auto& backendNode : *backendNodeIds) {
2140 int backendNodeId; 2143 int backendNodeId;
2141 2144
2142 if (!(backendNode)->asNumber(&backendNodeId)) { 2145 if (!(backendNode)->asNumber(&backendNodeId)) {
2143 *errorString = "Invalid argument type"; 2146 *errorString = "Invalid argument type";
2144 return; 2147 return;
2145 } 2148 }
2146 2149
2147 Node* node = DOMNodeIds::nodeForId(backendNodeId); 2150 Node* node = DOMNodeIds::nodeForId(backendNodeId);
2148 if (node && node->document().frame() && node->document().frame()->instru mentingAgents() == m_pageAgent->inspectedFrame()->instrumentingAgents()) 2151 if (node && node->document().frame() && node->document().frame()->instru mentingAgents() == m_inspectedFrame->instrumentingAgents())
2149 result->addItem(pushNodePathToFrontend(node)); 2152 result->addItem(pushNodePathToFrontend(node));
2150 else 2153 else
2151 result->addItem(0); 2154 result->addItem(0);
2152 } 2155 }
2153 } 2156 }
2154 2157
2155 class InspectableNode final : public InjectedScriptHost::InspectableObject { 2158 class InspectableNode final : public InjectedScriptHost::InspectableObject {
2156 public: 2159 public:
2157 explicit InspectableNode(Node* node) : m_node(node) { } 2160 explicit InspectableNode(Node* node) : m_node(node) { }
2158 virtual ScriptValue get(ScriptState* state) override 2161 virtual ScriptValue get(ScriptState* state) override
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2216 RefPtr<TypeBuilder::DOM::Node> root; 2219 RefPtr<TypeBuilder::DOM::Node> root;
2217 getDocument(errorString, root); 2220 getDocument(errorString, root);
2218 return errorString->isEmpty(); 2221 return errorString->isEmpty();
2219 } 2222 }
2220 return true; 2223 return true;
2221 } 2224 }
2222 2225
2223 DEFINE_TRACE(InspectorDOMAgent) 2226 DEFINE_TRACE(InspectorDOMAgent)
2224 { 2227 {
2225 visitor->trace(m_domListener); 2228 visitor->trace(m_domListener);
2226 visitor->trace(m_pageAgent); 2229 visitor->trace(m_inspectedFrame);
2227 visitor->trace(m_injectedScriptManager); 2230 visitor->trace(m_injectedScriptManager);
2228 visitor->trace(m_overlay); 2231 visitor->trace(m_overlay);
2229 #if ENABLE(OILPAN) 2232 #if ENABLE(OILPAN)
2230 visitor->trace(m_documentNodeToIdMap); 2233 visitor->trace(m_documentNodeToIdMap);
2231 visitor->trace(m_danglingNodeToIdMaps); 2234 visitor->trace(m_danglingNodeToIdMaps);
2232 visitor->trace(m_idToNode); 2235 visitor->trace(m_idToNode);
2233 visitor->trace(m_idToNodesMap); 2236 visitor->trace(m_idToNodesMap);
2234 visitor->trace(m_document); 2237 visitor->trace(m_document);
2235 visitor->trace(m_revalidateTask); 2238 visitor->trace(m_revalidateTask);
2236 visitor->trace(m_searchResults); 2239 visitor->trace(m_searchResults);
2237 #endif 2240 #endif
2238 visitor->trace(m_hoveredNodeForInspectMode); 2241 visitor->trace(m_hoveredNodeForInspectMode);
2239 visitor->trace(m_history); 2242 visitor->trace(m_history);
2240 visitor->trace(m_domEditor); 2243 visitor->trace(m_domEditor);
2241 visitor->trace(m_listener); 2244 visitor->trace(m_listener);
2242 InspectorBaseAgent::trace(visitor); 2245 InspectorBaseAgent::trace(visitor);
2243 } 2246 }
2244 2247
2245 } // namespace blink 2248 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698