Index: third_party/WebKit/Source/core/inspector/InspectorDOMSnapshotAgent.cpp |
diff --git a/third_party/WebKit/Source/core/inspector/InspectorDOMSnapshotAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorDOMSnapshotAgent.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a934220e0368fd3d279da446185376fe00471d93 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/inspector/InspectorDOMSnapshotAgent.cpp |
@@ -0,0 +1,56 @@ |
+// Copyright 2017 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. |
+ |
+#include "core/inspector/InspectorDOMSnapshotAgent.h" |
+ |
+#include "core/dom/Document.h" |
+ |
+namespace blink { |
+ |
+using protocol::Maybe; |
+using protocol::Response; |
+ |
+InspectorDOMSnapshotAgent::InspectorDOMSnapshotAgent( |
+ InspectorCSSAgent* css_agent, |
+ InspectorDOMAgent* dom_agent) |
+ : css_agent_(css_agent), dom_agent_(dom_agent) {} |
+ |
+InspectorDOMSnapshotAgent::~InspectorDOMSnapshotAgent() {} |
+ |
+Response InspectorDOMSnapshotAgent::getSnapshot( |
+ std::unique_ptr<protocol::Array<String>> style_whitelist, |
+ Maybe<int> dom_depth, |
+ Maybe<bool> pierce, |
+ std::unique_ptr<protocol::Array<protocol::DOM::Node>>* dom_nodes, |
+ std::unique_ptr<protocol::Array<protocol::CSS::LayoutTreeNode>>* |
+ layout_tree_nodes, |
+ std::unique_ptr<protocol::Array<protocol::CSS::ComputedStyle>>* |
+ computed_styles) { |
+ if (!dom_agent_->Enabled()) |
+ return Response::Error("DOM agent hasn't been enabled"); |
+ |
+ Document* document = dom_agent_->GetDocument(); |
+ if (!document) |
+ return Response::Error("Document is not available"); |
+ |
+ // Update layout tree first, so that it won't change between |
+ // getFlattenedDocument and getLayoutTreeAndStyles. |
+ document->UpdateStyleAndLayoutTree(); |
+ |
+ Response response = dom_agent_->getFlattenedDocument( |
+ std::move(dom_depth), std::move(pierce), dom_nodes); |
+ if (!response.isSuccess()) |
+ return response; |
+ |
+ return css_agent_->getLayoutTreeAndStyles(std::move(style_whitelist), |
+ layout_tree_nodes, computed_styles); |
+} |
+ |
+DEFINE_TRACE(InspectorDOMSnapshotAgent) { |
+ visitor->Trace(css_agent_); |
+ visitor->Trace(dom_agent_); |
+ InspectorBaseAgent::Trace(visitor); |
+} |
+ |
+} // namespace blink |