OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_ | 5 #ifndef HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_ |
6 #define HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_ | 6 #define HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_ |
7 | 7 |
8 #include <unordered_map> | 8 #include <unordered_map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 // Map of node IDs to indexes into |dom_nodes_|. | 40 // Map of node IDs to indexes into |dom_nodes_|. |
41 std::unordered_map<NodeId, Index> node_id_to_index_; | 41 std::unordered_map<NodeId, Index> node_id_to_index_; |
42 | 42 |
43 std::vector<const css::LayoutTreeNode*> layout_tree_nodes_; | 43 std::vector<const css::LayoutTreeNode*> layout_tree_nodes_; |
44 | 44 |
45 std::vector<const css::ComputedStyle*> computed_styles_; | 45 std::vector<const css::ComputedStyle*> computed_styles_; |
46 | 46 |
47 private: | 47 private: |
48 friend class FlatDomTreeExtractor; | 48 friend class FlatDomTreeExtractor; |
49 | 49 |
50 // Owns the raw pointers in |dom_nodes_|. | 50 // Owns the raw pointers in |dom_nodes_| and |layout_tree_nodes_|. |
51 std::unique_ptr<dom::GetFlattenedDocumentResult> document_result_; | 51 std::unique_ptr<css::GetDocumentSnapshotResult> document_snapshot_result_; |
52 | |
53 // Owns the raw pointers in |layout_tree_nodes_|. | |
54 std::unique_ptr<css::GetLayoutTreeAndStylesResult> | |
55 layout_tree_and_styles_result_; | |
56 | 52 |
57 DISALLOW_COPY_AND_ASSIGN(DomTree); | 53 DISALLOW_COPY_AND_ASSIGN(DomTree); |
58 }; | 54 }; |
59 | 55 |
60 using DomResultCB = base::Callback<void(DomTree)>; | 56 using DomResultCB = base::Callback<void(DomTree)>; |
61 | 57 |
62 // Extracts all nodes from the DOM. This is an asynchronous operation and | 58 // Extracts all nodes from the DOM. This is an asynchronous operation and |
63 // it's an error to call ExtractDom while a previous operation is in flight. | 59 // it's an error to call ExtractDom while a previous operation is in flight. |
64 void ExtractDomTree(const std::vector<std::string>& css_style_whitelist, | 60 void ExtractDomTree(const std::vector<std::string>& css_style_whitelist, |
65 DomResultCB callback); | 61 DomResultCB callback); |
66 | 62 |
67 private: | 63 private: |
68 void OnDocumentFetched( | 64 void OnDocumentSnapshotResult( |
69 std::unique_ptr<dom::GetFlattenedDocumentResult> result); | 65 std::unique_ptr<css::GetDocumentSnapshotResult> result); |
70 | 66 |
71 void OnLayoutTreeAndStylesFetched( | |
72 std::unique_ptr<css::GetLayoutTreeAndStylesResult> result); | |
73 | |
74 void MaybeExtractDomTree(); | |
75 void EnumerateNodes(const dom::Node* node); | 67 void EnumerateNodes(const dom::Node* node); |
76 void ExtractLayoutTreeNodes(); | 68 void ExtractLayoutTreeNodes(); |
77 void ExtractComputedStyles(); | 69 void ExtractComputedStyles(); |
78 | 70 |
79 DomResultCB callback_; | 71 DomResultCB callback_; |
80 DomTree dom_tree_; | 72 DomTree dom_tree_; |
81 bool work_in_progress_; | 73 bool work_in_progress_; |
82 HeadlessDevToolsClient* devtools_client_; // NOT OWNED | 74 HeadlessDevToolsClient* devtools_client_; // NOT OWNED |
83 base::WeakPtrFactory<FlatDomTreeExtractor> weak_factory_; | 75 base::WeakPtrFactory<FlatDomTreeExtractor> weak_factory_; |
84 | 76 |
85 DISALLOW_COPY_AND_ASSIGN(FlatDomTreeExtractor); | 77 DISALLOW_COPY_AND_ASSIGN(FlatDomTreeExtractor); |
86 }; | 78 }; |
87 | 79 |
88 } // namespace headless | 80 } // namespace headless |
89 | 81 |
90 #endif // HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_ | 82 #endif // HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_ |
OLD | NEW |