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

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorDOMSnapshotAgent.h

Issue 2882193002: [devtools] Add DOMSnapshot domain for dom+layout+style snapshots. (Closed)
Patch Set: back to DOMSnapshot domain, with custom node types + traversal. Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/inspector/InspectorDOMSnapshotAgent.h
diff --git a/third_party/WebKit/Source/core/inspector/InspectorDOMSnapshotAgent.h b/third_party/WebKit/Source/core/inspector/InspectorDOMSnapshotAgent.h
new file mode 100644
index 0000000000000000000000000000000000000000..aaacc2a7db6b4cc381b935fec0656465ccb6b813
--- /dev/null
+++ b/third_party/WebKit/Source/core/inspector/InspectorDOMSnapshotAgent.h
@@ -0,0 +1,91 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef InspectorDOMSnapshotAgent_h
+#define InspectorDOMSnapshotAgent_h
+
+#include "core/CSSPropertyNames.h"
+#include "core/inspector/InspectorBaseAgent.h"
+#include "core/inspector/protocol/DOMSnapshot.h"
+#include "platform/wtf/HashMap.h"
+#include "platform/wtf/Vector.h"
+
+namespace blink {
+
+class Element;
+class InspectedFrames;
+class Node;
+
+class CORE_EXPORT InspectorDOMSnapshotAgent final
+ : public InspectorBaseAgent<protocol::DOMSnapshot::Metainfo> {
+ WTF_MAKE_NONCOPYABLE(InspectorDOMSnapshotAgent);
+
+ public:
+ static InspectorDOMSnapshotAgent* Create(InspectedFrames* inspected_frames) {
+ return new InspectorDOMSnapshotAgent(inspected_frames);
+ }
+
+ ~InspectorDOMSnapshotAgent() override;
+ DECLARE_VIRTUAL_TRACE();
+
+ protocol::Response getSnapshot(
+ std::unique_ptr<protocol::Array<String>> style_whitelist,
+ protocol::Maybe<int> depth,
+ protocol::Maybe<bool> pierce,
+ std::unique_ptr<protocol::Array<protocol::DOMSnapshot::DOMNode>>*
+ dom_nodes,
+ std::unique_ptr<protocol::Array<protocol::DOMSnapshot::LayoutTreeNode>>*
+ layout_tree_nodes,
+ std::unique_ptr<protocol::Array<protocol::DOMSnapshot::ComputedStyle>>*
+ computed_styles) override;
+
+ private:
+ explicit InspectorDOMSnapshotAgent(InspectedFrames*);
+
+ // Adds a DOMNode for the given Node to |dom_nodes_| and returns its index.
+ int VisitNode(Node*, int depth);
+ std::unique_ptr<protocol::Array<int>> VisitContainerChildren(Node* container,
+ int depth);
+ std::unique_ptr<protocol::Array<int>> VisitPseudoElements(Element* parent,
+ int depth);
+ std::unique_ptr<protocol::Array<protocol::DOMSnapshot::Attribute>>
+ BuildArrayForElementAttributes(Element*);
+
+ // Adds a LayoutTreeNode for the LayoutObject of the given Node to
+ // |layout_tree_nodes_| and returns its index. Returns -1 if the Node has no
+ // associated LayoutObject.
+ int VisitLayoutTreeNode(Node*, int node_index);
+
+ // Returns the index of the ComputedStyle in |computed_styles_| for the given
+ // Node. Adds a new ComputedStyle if necessary, but ensures no duplicates are
+ // added to |computed_styles_|. Returns -1 if the node has no values for
+ // styles in |style_whitelist_|.
+ int GetStyleIndexForNode(Node*);
+
+ struct VectorStringHashTraits;
+ using ComputedStylesMap = WTF::HashMap<Vector<String>,
+ int,
+ VectorStringHashTraits,
+ VectorStringHashTraits>;
+ using CSSPropertyWhitelist = Vector<std::pair<String, CSSPropertyID>>;
+
+ // State of current snapshot.
+ std::unique_ptr<protocol::Array<protocol::DOMSnapshot::DOMNode>> dom_nodes_;
+ std::unique_ptr<protocol::Array<protocol::DOMSnapshot::LayoutTreeNode>>
+ layout_tree_nodes_;
+ std::unique_ptr<protocol::Array<protocol::DOMSnapshot::ComputedStyle>>
+ computed_styles_;
+ bool pierce_ = false;
+ // Maps a style string vector to an index in |computed_styles_|. Used to avoid
+ // duplicate entries in |computed_styles_|.
+ std::unique_ptr<ComputedStylesMap> computed_styles_map_;
+ std::unique_ptr<Vector<std::pair<String, CSSPropertyID>>>
+ css_property_whitelist_;
+
+ Member<InspectedFrames> inspected_frames_;
+};
+
+} // namespace blink
+
+#endif // !defined(InspectorDOMSnapshotAgent_h)

Powered by Google App Engine
This is Rietveld 408576698