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

Unified Diff: headless/public/util/dom_tree_extractor.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: headless/public/util/dom_tree_extractor.h
diff --git a/headless/public/util/dom_tree_extractor.h b/headless/public/util/dom_tree_extractor.h
deleted file mode 100644
index 081e4babb16ae06d5162e8a726668f7590b1f3d6..0000000000000000000000000000000000000000
--- a/headless/public/util/dom_tree_extractor.h
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright 2016 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 HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_
-#define HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_
-
-#include <unordered_map>
-#include <vector>
-
-#include "base/macros.h"
-#include "headless/public/devtools/domains/css.h"
-#include "headless/public/devtools/domains/dom.h"
-#include "headless/public/headless_export.h"
-
-namespace headless {
-class HeadlessDevToolsClient;
-
-// A utility class for extracting information from the DOM via DevTools. In
-// addition, it also extracts details of bounding boxes and layout text (NB the
-// exact layout should not be regarded as stable, it's subject to change without
-// notice).
-// TODO(alexclarke): Remove in favor of one using DOM.getFlattenedDocument.
-class HEADLESS_EXPORT DomTreeExtractor {
- public:
- explicit DomTreeExtractor(HeadlessDevToolsClient* devtools_client);
- ~DomTreeExtractor();
-
- using NodeId = int;
- using Index = size_t;
-
- class HEADLESS_EXPORT DomTree {
- public:
- DomTree();
- DomTree(DomTree&& other);
- ~DomTree();
-
- // Flattened dom tree. The root node is always the first entry.
- std::vector<const dom::Node*> dom_nodes_;
-
- // Map of node IDs to indexes into |dom_nodes_|.
- std::unordered_map<NodeId, Index> node_id_to_index_;
-
- std::vector<const css::LayoutTreeNode*> layout_tree_nodes_;
-
- std::vector<const css::ComputedStyle*> computed_styles_;
-
- private:
- friend class DomTreeExtractor;
-
- // Owns the raw pointers in |dom_nodes_|.
- std::unique_ptr<dom::GetDocumentResult> document_result_;
-
- // Owns the raw pointers in |layout_tree_nodes_|.
- std::unique_ptr<css::GetLayoutTreeAndStylesResult>
- layout_tree_and_styles_result_;
-
- DISALLOW_COPY_AND_ASSIGN(DomTree);
- };
-
- using DomResultCB = base::Callback<void(DomTree)>;
-
- // Extracts all nodes from the DOM. This is an asynchronous operation and
- // it's an error to call ExtractDom while a previous operation is in flight.
- void ExtractDomTree(const std::vector<std::string>& css_style_whitelist,
- DomResultCB callback);
-
- private:
- void OnDocumentFetched(std::unique_ptr<dom::GetDocumentResult> result);
-
- void OnLayoutTreeAndStylesFetched(
- std::unique_ptr<css::GetLayoutTreeAndStylesResult> result);
-
- void MaybeExtractDomTree();
- void EnumerateNodes(const dom::Node* node);
- void ExtractLayoutTreeNodes();
- void ExtractComputedStyles();
-
- DomResultCB callback_;
- DomTree dom_tree_;
- bool work_in_progress_;
- HeadlessDevToolsClient* devtools_client_; // NOT OWNED
- base::WeakPtrFactory<DomTreeExtractor> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(DomTreeExtractor);
-};
-
-} // namespace headless
-
-#endif // HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_

Powered by Google App Engine
This is Rietveld 408576698