| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "headless/public/devtools/domains/css.h" | 12 #include "headless/public/devtools/domains/css.h" |
| 13 #include "headless/public/devtools/domains/dom.h" | 13 #include "headless/public/devtools/domains/dom.h" |
| 14 #include "headless/public/headless_export.h" |
| 14 | 15 |
| 15 namespace headless { | 16 namespace headless { |
| 16 class HeadlessDevToolsClient; | 17 class HeadlessDevToolsClient; |
| 17 | 18 |
| 18 // A utility class for extracting information from the DOM via DevTools. In | 19 // A utility class for extracting information from the DOM via DevTools. In |
| 19 // addition, it also extracts details of bounding boxes and layout text (NB the | 20 // addition, it also extracts details of bounding boxes and layout text (NB the |
| 20 // exact layout should not be regarded as stable, it's subject to change without | 21 // exact layout should not be regarded as stable, it's subject to change without |
| 21 // notice). | 22 // notice). |
| 22 // TODO(alexclarke): Remove in favor of one using DOM.getFlattenedDocument. | 23 // TODO(alexclarke): Remove in favor of one using DOM.getFlattenedDocument. |
| 23 class DomTreeExtractor { | 24 class HEADLESS_EXPORT DomTreeExtractor { |
| 24 public: | 25 public: |
| 25 explicit DomTreeExtractor(HeadlessDevToolsClient* devtools_client); | 26 explicit DomTreeExtractor(HeadlessDevToolsClient* devtools_client); |
| 26 ~DomTreeExtractor(); | 27 ~DomTreeExtractor(); |
| 27 | 28 |
| 28 using NodeId = int; | 29 using NodeId = int; |
| 29 using Index = size_t; | 30 using Index = size_t; |
| 30 | 31 |
| 31 class DomTree { | 32 class HEADLESS_EXPORT DomTree { |
| 32 public: | 33 public: |
| 33 DomTree(); | 34 DomTree(); |
| 34 DomTree(DomTree&& other); | 35 DomTree(DomTree&& other); |
| 35 ~DomTree(); | 36 ~DomTree(); |
| 36 | 37 |
| 37 // Flattened dom tree. The root node is always the first entry. | 38 // Flattened dom tree. The root node is always the first entry. |
| 38 std::vector<const dom::Node*> dom_nodes_; | 39 std::vector<const dom::Node*> dom_nodes_; |
| 39 | 40 |
| 40 // Map of node IDs to indexes into |dom_nodes_|. | 41 // Map of node IDs to indexes into |dom_nodes_|. |
| 41 std::unordered_map<NodeId, Index> node_id_to_index_; | 42 std::unordered_map<NodeId, Index> node_id_to_index_; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 bool work_in_progress_; | 81 bool work_in_progress_; |
| 81 HeadlessDevToolsClient* devtools_client_; // NOT OWNED | 82 HeadlessDevToolsClient* devtools_client_; // NOT OWNED |
| 82 base::WeakPtrFactory<DomTreeExtractor> weak_factory_; | 83 base::WeakPtrFactory<DomTreeExtractor> weak_factory_; |
| 83 | 84 |
| 84 DISALLOW_COPY_AND_ASSIGN(DomTreeExtractor); | 85 DISALLOW_COPY_AND_ASSIGN(DomTreeExtractor); |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 } // namespace headless | 88 } // namespace headless |
| 88 | 89 |
| 89 #endif // HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_ | 90 #endif // HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_ |
| OLD | NEW |