Index: headless/public/util/flat_dom_tree_extractor.cc |
diff --git a/headless/public/util/flat_dom_tree_extractor.cc b/headless/public/util/flat_dom_tree_extractor.cc |
index 1ac9210aabc618e3711f7e57df61a034db828180..cc420ee20c43f2dde02ed096c6e451e234ad2d6c 100644 |
--- a/headless/public/util/flat_dom_tree_extractor.cc |
+++ b/headless/public/util/flat_dom_tree_extractor.cc |
@@ -26,49 +26,34 @@ void FlatDomTreeExtractor::ExtractDomTree( |
callback_ = std::move(callback); |
+ // GetDocumentSnapshot requires DOM domain to be enabled. |
devtools_client_->GetDOM()->Enable(); |
- devtools_client_->GetDOM()->GetFlattenedDocument( |
- dom::GetFlattenedDocumentParams::Builder() |
- .SetDepth(-1) |
- .SetPierce(true) |
- .Build(), |
- base::Bind(&FlatDomTreeExtractor::OnDocumentFetched, |
- weak_factory_.GetWeakPtr())); |
- devtools_client_->GetCSS()->GetExperimental()->GetLayoutTreeAndStyles( |
- css::GetLayoutTreeAndStylesParams::Builder() |
+ devtools_client_->GetCSS()->GetExperimental()->GetDocumentSnapshot( |
+ css::GetDocumentSnapshotParams::Builder() |
.SetComputedStyleWhitelist(css_style_whitelist) |
+ .SetDomDepth(-1) |
+ .SetPierce(true) |
.Build(), |
- base::Bind(&FlatDomTreeExtractor::OnLayoutTreeAndStylesFetched, |
+ base::Bind(&FlatDomTreeExtractor::OnDocumentSnapshotResult, |
weak_factory_.GetWeakPtr())); |
} |
-void FlatDomTreeExtractor::OnDocumentFetched( |
- std::unique_ptr<dom::GetFlattenedDocumentResult> result) { |
- dom_tree_.document_result_ = std::move(result); |
- MaybeExtractDomTree(); |
-} |
+void FlatDomTreeExtractor::OnDocumentSnapshotResult( |
+ std::unique_ptr<css::GetDocumentSnapshotResult> result) { |
+ dom_tree_.document_snapshot_result_ = std::move(result); |
-void FlatDomTreeExtractor::OnLayoutTreeAndStylesFetched( |
- std::unique_ptr<css::GetLayoutTreeAndStylesResult> result) { |
- dom_tree_.layout_tree_and_styles_result_ = std::move(result); |
- MaybeExtractDomTree(); |
-} |
- |
-void FlatDomTreeExtractor::MaybeExtractDomTree() { |
- if (dom_tree_.document_result_ && dom_tree_.layout_tree_and_styles_result_) { |
- for (const std::unique_ptr<headless::dom::Node>& node : |
- *dom_tree_.document_result_->GetNodes()) { |
- EnumerateNodes(node.get()); |
- } |
- ExtractLayoutTreeNodes(); |
- ExtractComputedStyles(); |
- devtools_client_->GetDOM()->Disable(); |
+ for (const std::unique_ptr<headless::dom::Node>& node : |
+ *dom_tree_.document_snapshot_result_->GetDomNodes()) { |
+ EnumerateNodes(node.get()); |
+ } |
+ ExtractLayoutTreeNodes(); |
+ ExtractComputedStyles(); |
+ devtools_client_->GetDOM()->Disable(); |
- work_in_progress_ = false; |
+ work_in_progress_ = false; |
- callback_.Run(std::move(dom_tree_)); |
- } |
+ callback_.Run(std::move(dom_tree_)); |
} |
void FlatDomTreeExtractor::EnumerateNodes(const dom::Node* node) { |
@@ -85,10 +70,10 @@ void FlatDomTreeExtractor::EnumerateNodes(const dom::Node* node) { |
void FlatDomTreeExtractor::ExtractLayoutTreeNodes() { |
dom_tree_.layout_tree_nodes_.reserve( |
- dom_tree_.layout_tree_and_styles_result_->GetLayoutTreeNodes()->size()); |
+ dom_tree_.document_snapshot_result_->GetLayoutTreeNodes()->size()); |
for (const std::unique_ptr<css::LayoutTreeNode>& layout_node : |
- *dom_tree_.layout_tree_and_styles_result_->GetLayoutTreeNodes()) { |
+ *dom_tree_.document_snapshot_result_->GetLayoutTreeNodes()) { |
std::unordered_map<NodeId, size_t>::const_iterator it = |
dom_tree_.node_id_to_index_.find(layout_node->GetNodeId()); |
DCHECK(it != dom_tree_.node_id_to_index_.end()); |
@@ -98,10 +83,10 @@ void FlatDomTreeExtractor::ExtractLayoutTreeNodes() { |
void FlatDomTreeExtractor::ExtractComputedStyles() { |
dom_tree_.computed_styles_.reserve( |
- dom_tree_.layout_tree_and_styles_result_->GetComputedStyles()->size()); |
+ dom_tree_.document_snapshot_result_->GetComputedStyles()->size()); |
for (const std::unique_ptr<css::ComputedStyle>& computed_style : |
- *dom_tree_.layout_tree_and_styles_result_->GetComputedStyles()) { |
+ *dom_tree_.document_snapshot_result_->GetComputedStyles()) { |
dom_tree_.computed_styles_.push_back(computed_style.get()); |
} |
} |