| OLD | NEW |
| 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 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #ifndef InspectorDOMAgent_h | 30 #ifndef InspectorDOMAgent_h |
| 31 #define InspectorDOMAgent_h | 31 #define InspectorDOMAgent_h |
| 32 | 32 |
| 33 #include <memory> | 33 #include <memory> |
| 34 #include "core/CoreExport.h" | 34 #include "core/CoreExport.h" |
| 35 #include "core/events/EventListenerMap.h" | 35 #include "core/events/EventListenerMap.h" |
| 36 #include "core/inspector/InspectorBaseAgent.h" | 36 #include "core/inspector/InspectorBaseAgent.h" |
| 37 #include "core/inspector/InspectorHighlight.h" |
| 37 #include "core/inspector/protocol/DOM.h" | 38 #include "core/inspector/protocol/DOM.h" |
| 38 #include "core/style/ComputedStyleConstants.h" | 39 #include "core/style/ComputedStyleConstants.h" |
| 39 #include "platform/geometry/FloatQuad.h" | 40 #include "platform/geometry/FloatQuad.h" |
| 40 #include "platform/wtf/HashMap.h" | 41 #include "platform/wtf/HashMap.h" |
| 41 #include "platform/wtf/HashSet.h" | 42 #include "platform/wtf/HashSet.h" |
| 42 #include "platform/wtf/RefPtr.h" | 43 #include "platform/wtf/RefPtr.h" |
| 43 #include "platform/wtf/Vector.h" | 44 #include "platform/wtf/Vector.h" |
| 44 #include "platform/wtf/text/AtomicString.h" | 45 #include "platform/wtf/text/AtomicString.h" |
| 45 #include "v8/include/v8-inspector.h" | 46 #include "v8/include/v8-inspector.h" |
| 46 | 47 |
| 47 namespace blink { | 48 namespace blink { |
| 48 | 49 |
| 49 class CharacterData; | 50 class CharacterData; |
| 50 class Color; | |
| 51 class DOMEditor; | 51 class DOMEditor; |
| 52 class Document; | 52 class Document; |
| 53 class DocumentLoader; | 53 class DocumentLoader; |
| 54 class Element; | 54 class Element; |
| 55 class ExceptionState; | 55 class ExceptionState; |
| 56 class FloatQuad; | 56 class FloatQuad; |
| 57 class HTMLSlotElement; | 57 class HTMLSlotElement; |
| 58 class InsertionPoint; | 58 class InsertionPoint; |
| 59 class InspectedFrames; | 59 class InspectedFrames; |
| 60 class InspectorHistory; | 60 class InspectorHistory; |
| 61 class Node; | 61 class Node; |
| 62 class QualifiedName; | 62 class QualifiedName; |
| 63 class PseudoElement; | 63 class PseudoElement; |
| 64 class InspectorRevalidateDOMTask; | 64 class InspectorRevalidateDOMTask; |
| 65 class ShadowRoot; | 65 class ShadowRoot; |
| 66 | 66 |
| 67 class CORE_EXPORT InspectorDOMAgent final | 67 class CORE_EXPORT InspectorDOMAgent final |
| 68 : public InspectorBaseAgent<protocol::DOM::Metainfo> { | 68 : public InspectorBaseAgent<protocol::DOM::Metainfo> { |
| 69 WTF_MAKE_NONCOPYABLE(InspectorDOMAgent); | 69 WTF_MAKE_NONCOPYABLE(InspectorDOMAgent); |
| 70 | 70 |
| 71 public: | 71 public: |
| 72 struct CORE_EXPORT DOMListener : public GarbageCollectedMixin { | 72 struct CORE_EXPORT DOMListener : public GarbageCollectedMixin { |
| 73 virtual ~DOMListener() {} | 73 virtual ~DOMListener() {} |
| 74 virtual void DidAddDocument(Document*) = 0; | 74 virtual void DidAddDocument(Document*) = 0; |
| 75 virtual void DidRemoveDocument(Document*) = 0; | 75 virtual void DidRemoveDocument(Document*) = 0; |
| 76 virtual void DidRemoveDOMNode(Node*) = 0; | 76 virtual void DidRemoveDOMNode(Node*) = 0; |
| 77 virtual void DidModifyDOMAttr(Element*) = 0; | 77 virtual void DidModifyDOMAttr(Element*) = 0; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 enum SearchMode { |
| 81 kNotSearching, |
| 82 kSearchingForNormal, |
| 83 kSearchingForUAShadow, |
| 84 }; |
| 85 |
| 86 class Client { |
| 87 public: |
| 88 virtual ~Client() {} |
| 89 virtual void HideHighlight() {} |
| 90 virtual void HighlightNode(Node*, |
| 91 const InspectorHighlightConfig&, |
| 92 bool omit_tooltip) {} |
| 93 virtual void HighlightQuad(std::unique_ptr<FloatQuad>, |
| 94 const InspectorHighlightConfig&) {} |
| 95 virtual void SetInspectMode(SearchMode search_mode, |
| 96 std::unique_ptr<InspectorHighlightConfig>) {} |
| 97 }; |
| 98 |
| 80 static protocol::Response ToResponse(ExceptionState&); | 99 static protocol::Response ToResponse(ExceptionState&); |
| 81 static bool GetPseudoElementType(PseudoId, String*); | 100 static bool GetPseudoElementType(PseudoId, String*); |
| 82 static ShadowRoot* UserAgentShadowRoot(Node*); | 101 static ShadowRoot* UserAgentShadowRoot(Node*); |
| 83 static Color ParseColor(protocol::DOM::RGBA*); | |
| 84 | 102 |
| 85 InspectorDOMAgent(v8::Isolate*, | 103 InspectorDOMAgent(v8::Isolate*, |
| 86 InspectedFrames*, | 104 InspectedFrames*, |
| 87 v8_inspector::V8InspectorSession*); | 105 v8_inspector::V8InspectorSession*, |
| 106 Client*); |
| 88 ~InspectorDOMAgent() override; | 107 ~InspectorDOMAgent() override; |
| 89 DECLARE_VIRTUAL_TRACE(); | 108 DECLARE_VIRTUAL_TRACE(); |
| 90 | 109 |
| 91 void Restore() override; | 110 void Restore() override; |
| 92 | 111 |
| 93 HeapVector<Member<Document>> Documents(); | 112 HeapVector<Member<Document>> Documents(); |
| 94 void Reset(); | 113 void Reset(); |
| 95 | 114 |
| 96 // Methods called from the frontend for DOM nodes inspection. | 115 // Methods called from the frontend for DOM nodes inspection. |
| 97 protocol::Response enable() override; | 116 protocol::Response enable() override; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 String* search_id, | 158 String* search_id, |
| 140 int* result_count) override; | 159 int* result_count) override; |
| 141 protocol::Response getSearchResults( | 160 protocol::Response getSearchResults( |
| 142 const String& search_id, | 161 const String& search_id, |
| 143 int from_index, | 162 int from_index, |
| 144 int to_index, | 163 int to_index, |
| 145 std::unique_ptr<protocol::Array<int>>* node_ids) override; | 164 std::unique_ptr<protocol::Array<int>>* node_ids) override; |
| 146 protocol::Response discardSearchResults(const String& search_id) override; | 165 protocol::Response discardSearchResults(const String& search_id) override; |
| 147 protocol::Response requestNode(const String& object_id, | 166 protocol::Response requestNode(const String& object_id, |
| 148 int* out_node_id) override; | 167 int* out_node_id) override; |
| 168 protocol::Response setInspectMode( |
| 169 const String& mode, |
| 170 protocol::Maybe<protocol::DOM::HighlightConfig>) override; |
| 171 protocol::Response highlightRect( |
| 172 int x, |
| 173 int y, |
| 174 int width, |
| 175 int height, |
| 176 protocol::Maybe<protocol::DOM::RGBA> color, |
| 177 protocol::Maybe<protocol::DOM::RGBA> outline_color) override; |
| 178 protocol::Response highlightQuad( |
| 179 std::unique_ptr<protocol::Array<double>> quad, |
| 180 protocol::Maybe<protocol::DOM::RGBA> color, |
| 181 protocol::Maybe<protocol::DOM::RGBA> outline_color) override; |
| 182 protocol::Response highlightNode( |
| 183 std::unique_ptr<protocol::DOM::HighlightConfig>, |
| 184 protocol::Maybe<int> node_id, |
| 185 protocol::Maybe<int> backend_node_id, |
| 186 protocol::Maybe<String> object_id) override; |
| 187 protocol::Response hideHighlight() override; |
| 188 protocol::Response highlightFrame( |
| 189 const String& frame_id, |
| 190 protocol::Maybe<protocol::DOM::RGBA> content_color, |
| 191 protocol::Maybe<protocol::DOM::RGBA> content_outline_color) override; |
| 149 protocol::Response pushNodeByPathToFrontend(const String& path, | 192 protocol::Response pushNodeByPathToFrontend(const String& path, |
| 150 int* out_node_id) override; | 193 int* out_node_id) override; |
| 151 protocol::Response pushNodesByBackendIdsToFrontend( | 194 protocol::Response pushNodesByBackendIdsToFrontend( |
| 152 std::unique_ptr<protocol::Array<int>> backend_node_ids, | 195 std::unique_ptr<protocol::Array<int>> backend_node_ids, |
| 153 std::unique_ptr<protocol::Array<int>>* node_ids) override; | 196 std::unique_ptr<protocol::Array<int>>* node_ids) override; |
| 154 protocol::Response setInspectedNode(int node_id) override; | 197 protocol::Response setInspectedNode(int node_id) override; |
| 155 protocol::Response resolveNode( | 198 protocol::Response resolveNode( |
| 156 int node_id, | 199 int node_id, |
| 157 protocol::Maybe<String> object_group, | 200 protocol::Maybe<String> object_group, |
| 158 std::unique_ptr<v8_inspector::protocol::Runtime::API::RemoteObject>*) | 201 std::unique_ptr<v8_inspector::protocol::Runtime::API::RemoteObject>*) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 178 protocol::Response getBoxModel( | 221 protocol::Response getBoxModel( |
| 179 int node_id, | 222 int node_id, |
| 180 std::unique_ptr<protocol::DOM::BoxModel>*) override; | 223 std::unique_ptr<protocol::DOM::BoxModel>*) override; |
| 181 protocol::Response getNodeForLocation( | 224 protocol::Response getNodeForLocation( |
| 182 int x, | 225 int x, |
| 183 int y, | 226 int y, |
| 184 protocol::Maybe<bool> include_user_agent_shadow_dom, | 227 protocol::Maybe<bool> include_user_agent_shadow_dom, |
| 185 int* out_node_id) override; | 228 int* out_node_id) override; |
| 186 protocol::Response getRelayoutBoundary(int node_id, | 229 protocol::Response getRelayoutBoundary(int node_id, |
| 187 int* out_node_id) override; | 230 int* out_node_id) override; |
| 231 protocol::Response getHighlightObjectForTest( |
| 232 int node_id, |
| 233 std::unique_ptr<protocol::DictionaryValue>* highlight) override; |
| 188 | 234 |
| 189 bool Enabled() const; | 235 bool Enabled() const; |
| 190 void ReleaseDanglingNodes(); | 236 void ReleaseDanglingNodes(); |
| 191 | 237 |
| 192 // Methods called from the InspectorInstrumentation. | 238 // Methods called from the InspectorInstrumentation. |
| 193 void DomContentLoadedEventFired(LocalFrame*); | 239 void DomContentLoadedEventFired(LocalFrame*); |
| 194 void DidCommitLoad(LocalFrame*, DocumentLoader*); | 240 void DidCommitLoad(LocalFrame*, DocumentLoader*); |
| 195 void DidInsertDOMNode(Node*); | 241 void DidInsertDOMNode(Node*); |
| 196 void WillRemoveDOMNode(Node*); | 242 void WillRemoveDOMNode(Node*); |
| 197 void WillModifyDOMAttr(Element*, | 243 void WillModifyDOMAttr(Element*, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 208 void WillPopShadowRoot(Element* host, ShadowRoot*); | 254 void WillPopShadowRoot(Element* host, ShadowRoot*); |
| 209 void DidPerformElementShadowDistribution(Element*); | 255 void DidPerformElementShadowDistribution(Element*); |
| 210 void DidPerformSlotDistribution(HTMLSlotElement*); | 256 void DidPerformSlotDistribution(HTMLSlotElement*); |
| 211 void FrameDocumentUpdated(LocalFrame*); | 257 void FrameDocumentUpdated(LocalFrame*); |
| 212 void PseudoElementCreated(PseudoElement*); | 258 void PseudoElementCreated(PseudoElement*); |
| 213 void PseudoElementDestroyed(PseudoElement*); | 259 void PseudoElementDestroyed(PseudoElement*); |
| 214 | 260 |
| 215 Node* NodeForId(int node_id); | 261 Node* NodeForId(int node_id); |
| 216 int BoundNodeId(Node*); | 262 int BoundNodeId(Node*); |
| 217 void SetDOMListener(DOMListener*); | 263 void SetDOMListener(DOMListener*); |
| 264 void Inspect(Node*); |
| 265 void NodeHighlightedInOverlay(Node*); |
| 218 int PushNodePathToFrontend(Node*); | 266 int PushNodePathToFrontend(Node*); |
| 219 protocol::Response PushDocumentUponHandlelessOperation(); | |
| 220 protocol::Response NodeForRemoteObjectId(const String& remote_object_id, | |
| 221 Node*&); | |
| 222 | 267 |
| 223 static String DocumentURLString(Document*); | 268 static String DocumentURLString(Document*); |
| 224 | 269 |
| 225 std::unique_ptr<v8_inspector::protocol::Runtime::API::RemoteObject> | 270 std::unique_ptr<v8_inspector::protocol::Runtime::API::RemoteObject> |
| 226 ResolveNode(Node*, const String& object_group); | 271 ResolveNode(Node*, const String& object_group); |
| 227 | 272 |
| 228 InspectorHistory* History() { return history_.Get(); } | 273 InspectorHistory* History() { return history_.Get(); } |
| 229 | 274 |
| 230 // We represent embedded doms as a part of the same hierarchy. Hence we treat | 275 // We represent embedded doms as a part of the same hierarchy. Hence we treat |
| 231 // children of frame owners differently. We also skip whitespace text nodes | 276 // children of frame owners differently. We also skip whitespace text nodes |
| (...skipping 12 matching lines...) Expand all Loading... |
| 244 HeapVector<Member<Node>>* result); | 289 HeapVector<Member<Node>>* result); |
| 245 | 290 |
| 246 protocol::Response AssertNode(int node_id, Node*&); | 291 protocol::Response AssertNode(int node_id, Node*&); |
| 247 protocol::Response AssertElement(int node_id, Element*&); | 292 protocol::Response AssertElement(int node_id, Element*&); |
| 248 Document* GetDocument() const { return document_.Get(); } | 293 Document* GetDocument() const { return document_.Get(); } |
| 249 | 294 |
| 250 private: | 295 private: |
| 251 void SetDocument(Document*); | 296 void SetDocument(Document*); |
| 252 void InnerEnable(); | 297 void InnerEnable(); |
| 253 | 298 |
| 299 protocol::Response SetSearchingForNode( |
| 300 SearchMode, |
| 301 protocol::Maybe<protocol::DOM::HighlightConfig>); |
| 302 protocol::Response HighlightConfigFromInspectorObject( |
| 303 protocol::Maybe<protocol::DOM::HighlightConfig> |
| 304 highlight_inspector_object, |
| 305 std::unique_ptr<InspectorHighlightConfig>*); |
| 306 |
| 254 // Node-related methods. | 307 // Node-related methods. |
| 255 typedef HeapHashMap<Member<Node>, int> NodeToIdMap; | 308 typedef HeapHashMap<Member<Node>, int> NodeToIdMap; |
| 256 int Bind(Node*, NodeToIdMap*); | 309 int Bind(Node*, NodeToIdMap*); |
| 257 void Unbind(Node*, NodeToIdMap*); | 310 void Unbind(Node*, NodeToIdMap*); |
| 258 | 311 |
| 259 protocol::Response AssertEditableNode(int node_id, Node*&); | 312 protocol::Response AssertEditableNode(int node_id, Node*&); |
| 260 protocol::Response AssertEditableChildNode(Element* parent_element, | 313 protocol::Response AssertEditableChildNode(Element* parent_element, |
| 261 int node_id, | 314 int node_id, |
| 262 Node*&); | 315 Node*&); |
| 263 protocol::Response AssertEditableElement(int node_id, Element*&); | 316 protocol::Response AssertEditableElement(int node_id, Element*&); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 285 NodeToIdMap* nodes_map, | 338 NodeToIdMap* nodes_map, |
| 286 protocol::Array<protocol::DOM::Node>* flatten_result); | 339 protocol::Array<protocol::DOM::Node>* flatten_result); |
| 287 std::unique_ptr<protocol::Array<protocol::DOM::Node>> | 340 std::unique_ptr<protocol::Array<protocol::DOM::Node>> |
| 288 BuildArrayForPseudoElements(Element*, NodeToIdMap* nodes_map); | 341 BuildArrayForPseudoElements(Element*, NodeToIdMap* nodes_map); |
| 289 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> | 342 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> |
| 290 BuildArrayForDistributedNodes(InsertionPoint*); | 343 BuildArrayForDistributedNodes(InsertionPoint*); |
| 291 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> | 344 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> |
| 292 BuildDistributedNodesForSlot(HTMLSlotElement*); | 345 BuildDistributedNodesForSlot(HTMLSlotElement*); |
| 293 | 346 |
| 294 Node* NodeForPath(const String& path); | 347 Node* NodeForPath(const String& path); |
| 348 protocol::Response NodeForRemoteId(const String& id, Node*&); |
| 295 | 349 |
| 296 void DiscardFrontendBindings(); | 350 void DiscardFrontendBindings(); |
| 297 | 351 |
| 352 void InnerHighlightQuad(std::unique_ptr<FloatQuad>, |
| 353 protocol::Maybe<protocol::DOM::RGBA> color, |
| 354 protocol::Maybe<protocol::DOM::RGBA> outline_color); |
| 355 |
| 356 protocol::Response PushDocumentUponHandlelessOperation(); |
| 357 |
| 298 InspectorRevalidateDOMTask* RevalidateTask(); | 358 InspectorRevalidateDOMTask* RevalidateTask(); |
| 299 | 359 |
| 300 v8::Isolate* isolate_; | 360 v8::Isolate* isolate_; |
| 301 Member<InspectedFrames> inspected_frames_; | 361 Member<InspectedFrames> inspected_frames_; |
| 302 v8_inspector::V8InspectorSession* v8_session_; | 362 v8_inspector::V8InspectorSession* v8_session_; |
| 363 Client* client_; |
| 303 Member<DOMListener> dom_listener_; | 364 Member<DOMListener> dom_listener_; |
| 304 Member<NodeToIdMap> document_node_to_id_map_; | 365 Member<NodeToIdMap> document_node_to_id_map_; |
| 305 // Owns node mappings for dangling nodes. | 366 // Owns node mappings for dangling nodes. |
| 306 HeapVector<Member<NodeToIdMap>> dangling_node_to_id_maps_; | 367 HeapVector<Member<NodeToIdMap>> dangling_node_to_id_maps_; |
| 307 HeapHashMap<int, Member<Node>> id_to_node_; | 368 HeapHashMap<int, Member<Node>> id_to_node_; |
| 308 HeapHashMap<int, Member<NodeToIdMap>> id_to_nodes_map_; | 369 HeapHashMap<int, Member<NodeToIdMap>> id_to_nodes_map_; |
| 309 HashSet<int> children_requested_; | 370 HashSet<int> children_requested_; |
| 310 HashSet<int> distributed_nodes_requested_; | 371 HashSet<int> distributed_nodes_requested_; |
| 311 HashMap<int, int> cached_child_count_; | 372 HashMap<int, int> cached_child_count_; |
| 312 int last_node_id_; | 373 int last_node_id_; |
| 313 Member<Document> document_; | 374 Member<Document> document_; |
| 314 typedef HeapHashMap<String, HeapVector<Member<Node>>> SearchResults; | 375 typedef HeapHashMap<String, HeapVector<Member<Node>>> SearchResults; |
| 315 SearchResults search_results_; | 376 SearchResults search_results_; |
| 316 Member<InspectorRevalidateDOMTask> revalidate_task_; | 377 Member<InspectorRevalidateDOMTask> revalidate_task_; |
| 317 Member<InspectorHistory> history_; | 378 Member<InspectorHistory> history_; |
| 318 Member<DOMEditor> dom_editor_; | 379 Member<DOMEditor> dom_editor_; |
| 319 bool suppress_attribute_modified_event_; | 380 bool suppress_attribute_modified_event_; |
| 381 int backend_node_id_to_inspect_; |
| 320 }; | 382 }; |
| 321 | 383 |
| 322 } // namespace blink | 384 } // namespace blink |
| 323 | 385 |
| 324 #endif // !defined(InspectorDOMAgent_h) | 386 #endif // !defined(InspectorDOMAgent_h) |
| OLD | NEW |