Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_ | |
| 6 #define HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_ | |
| 7 | |
| 8 #include <unordered_map> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "headless/public/domains/dom.h" | |
| 13 | |
| 14 namespace headless { | |
| 15 class HeadlessDevToolsClient; | |
| 16 | |
| 17 // A utility class for extracting information from the DOM via DevTools. In | |
| 18 // addition it also extracts details of bounding boxes and layout text (NB the | |
| 19 // exact layout should not be regarded as stable, it's subject to change without | |
| 20 // notice). | |
|
Sami
2016/09/30 10:56:03
Could you briefly document what the received struc
alex clarke (OOO till 29th)
2016/09/30 13:16:33
Is that still needed? It should be obvious now.
| |
| 21 class DomTreeExtractor : public dom::Observer { | |
| 22 public: | |
| 23 explicit DomTreeExtractor(HeadlessDevToolsClient* devtools_client); | |
| 24 ~DomTreeExtractor() override; | |
| 25 | |
| 26 using DomResultCB = | |
| 27 base::Callback<void(std::vector<std::unique_ptr<base::DictionaryValue>>)>; | |
| 28 | |
| 29 // Extracts all nodes from the DOM. This is an asynchronous operation and its | |
| 30 // an error to call ExtractDom while a previous operation is in flight. | |
| 31 void ExtractDom(DomResultCB callback); | |
| 32 | |
| 33 // headless::dom::Observer implementation: | |
| 34 void OnSetChildNodes(const dom::SetChildNodesParams& params) override; | |
| 35 | |
| 36 private: | |
| 37 void OnRootDocumentFetched(std::unique_ptr<dom::GetDocumentResult> result); | |
| 38 | |
| 39 void OnLayoutTreeNodesFetched( | |
| 40 std::unique_ptr<dom::GetLayoutTreeNodesResult> result); | |
| 41 | |
| 42 void MaybeExtractDomTree(); | |
| 43 void EnumerateNodes(const dom::Node* node); | |
| 44 void ExtractDomTree(); | |
| 45 | |
| 46 DomResultCB callback_; | |
| 47 | |
| 48 using NodeId = int; | |
| 49 using Index = size_t; | |
| 50 | |
| 51 std::unique_ptr<dom::GetDocumentResult> document_result_; | |
| 52 std::unique_ptr<dom::GetLayoutTreeNodesResult> layout_tree_result_; | |
| 53 std::vector<const dom::Node*> nodes_; | |
| 54 std::unordered_map<NodeId, size_t> node_id_to_index_; | |
| 55 bool child_nodes_fetched_; | |
| 56 bool dom_observer_registered_; | |
| 57 bool work_in_progress_; | |
| 58 HeadlessDevToolsClient* devtools_client_; // NOT OWNED | |
| 59 base::WeakPtrFactory<DomTreeExtractor> weak_factory_; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(DomTreeExtractor); | |
| 62 }; | |
| 63 | |
| 64 } // namespace headless | |
| 65 | |
| 66 #endif // HEADLESS_PUBLIC_UTIL_DOM_TREE_EXTRACTOR_H_ | |
| OLD | NEW |