OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef InspectorDOMSnapshotAgent_h |
| 6 #define InspectorDOMSnapshotAgent_h |
| 7 |
| 8 #include "core/CSSPropertyNames.h" |
| 9 #include "core/inspector/InspectorBaseAgent.h" |
| 10 #include "core/inspector/protocol/DOMSnapshot.h" |
| 11 #include "platform/wtf/HashMap.h" |
| 12 #include "platform/wtf/Vector.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 class Element; |
| 17 class InspectedFrames; |
| 18 class Node; |
| 19 |
| 20 class CORE_EXPORT InspectorDOMSnapshotAgent final |
| 21 : public InspectorBaseAgent<protocol::DOMSnapshot::Metainfo> { |
| 22 WTF_MAKE_NONCOPYABLE(InspectorDOMSnapshotAgent); |
| 23 |
| 24 public: |
| 25 static InspectorDOMSnapshotAgent* Create(InspectedFrames* inspected_frames) { |
| 26 return new InspectorDOMSnapshotAgent(inspected_frames); |
| 27 } |
| 28 |
| 29 ~InspectorDOMSnapshotAgent() override; |
| 30 DECLARE_VIRTUAL_TRACE(); |
| 31 |
| 32 protocol::Response getSnapshot( |
| 33 std::unique_ptr<protocol::Array<String>> style_whitelist, |
| 34 std::unique_ptr<protocol::Array<protocol::DOMSnapshot::DOMNode>>* |
| 35 dom_nodes, |
| 36 std::unique_ptr<protocol::Array<protocol::DOMSnapshot::LayoutTreeNode>>* |
| 37 layout_tree_nodes, |
| 38 std::unique_ptr<protocol::Array<protocol::DOMSnapshot::ComputedStyle>>* |
| 39 computed_styles) override; |
| 40 |
| 41 private: |
| 42 explicit InspectorDOMSnapshotAgent(InspectedFrames*); |
| 43 |
| 44 // Adds a DOMNode for the given Node to |dom_nodes_| and returns its index. |
| 45 int VisitNode(Node*); |
| 46 std::unique_ptr<protocol::Array<int>> VisitContainerChildren(Node* container); |
| 47 std::unique_ptr<protocol::Array<int>> VisitPseudoElements(Element* parent); |
| 48 std::unique_ptr<protocol::Array<protocol::DOMSnapshot::NameValue>> |
| 49 BuildArrayForElementAttributes(Element*); |
| 50 |
| 51 // Adds a LayoutTreeNode for the LayoutObject of the given Node to |
| 52 // |layout_tree_nodes_| and returns its index. Returns -1 if the Node has no |
| 53 // associated LayoutObject. |
| 54 int VisitLayoutTreeNode(Node*, int node_index); |
| 55 |
| 56 // Returns the index of the ComputedStyle in |computed_styles_| for the given |
| 57 // Node. Adds a new ComputedStyle if necessary, but ensures no duplicates are |
| 58 // added to |computed_styles_|. Returns -1 if the node has no values for |
| 59 // styles in |style_whitelist_|. |
| 60 int GetStyleIndexForNode(Node*); |
| 61 |
| 62 struct VectorStringHashTraits; |
| 63 using ComputedStylesMap = WTF::HashMap<Vector<String>, |
| 64 int, |
| 65 VectorStringHashTraits, |
| 66 VectorStringHashTraits>; |
| 67 using CSSPropertyWhitelist = Vector<std::pair<String, CSSPropertyID>>; |
| 68 |
| 69 // State of current snapshot. |
| 70 std::unique_ptr<protocol::Array<protocol::DOMSnapshot::DOMNode>> dom_nodes_; |
| 71 std::unique_ptr<protocol::Array<protocol::DOMSnapshot::LayoutTreeNode>> |
| 72 layout_tree_nodes_; |
| 73 std::unique_ptr<protocol::Array<protocol::DOMSnapshot::ComputedStyle>> |
| 74 computed_styles_; |
| 75 // Maps a style string vector to an index in |computed_styles_|. Used to avoid |
| 76 // duplicate entries in |computed_styles_|. |
| 77 std::unique_ptr<ComputedStylesMap> computed_styles_map_; |
| 78 std::unique_ptr<Vector<std::pair<String, CSSPropertyID>>> |
| 79 css_property_whitelist_; |
| 80 |
| 81 Member<InspectedFrames> inspected_frames_; |
| 82 }; |
| 83 |
| 84 } // namespace blink |
| 85 |
| 86 #endif // !defined(InspectorDOMSnapshotAgent_h) |
OLD | NEW |