Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1212)

Unified Diff: ash/common/devtools/devtools_dom_agent.cc

Issue 2372843002: Add ash devtools client (Closed)
Patch Set: Use MakeUnique Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/common/devtools/devtools_dom_agent.h ('k') | ash/common/wm_shell.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/devtools/devtools_dom_agent.cc
diff --git a/ash/common/devtools/devtools_dom_agent.cc b/ash/common/devtools/devtools_dom_agent.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8673b77fbd574a8c815ef2ee948f45b05719de92
--- /dev/null
+++ b/ash/common/devtools/devtools_dom_agent.cc
@@ -0,0 +1,110 @@
+// Copyright 2016 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 "ash/common/devtools/devtools_dom_agent.h"
+
+#include "ash/common/wm_shell.h"
+#include "ash/common/wm_window.h"
+#include "components/ui_devtools/DOM.h"
+#include "components/ui_devtools/devtools_server.h"
+#include "ui/views/view.h"
+#include "ui/views/widget/widget.h"
+
+namespace ash {
+namespace devtools {
+
+namespace {
+using namespace ui::devtools::protocol;
+
+std::unique_ptr<DOM::Node> BuildNode(
+ const std::string& name,
+ std::unique_ptr<Array<std::string>> attributes,
+ std::unique_ptr<Array<DOM::Node>> children) {
+ static DOM::NodeId node_ids = 0;
+ constexpr int kDomElementNodeType = 1;
+ return DOM::Node::create()
+ .setNodeId(node_ids++)
+ .setNodeName(name)
+ .setNodeType(kDomElementNodeType)
+ .setAttributes(std::move(attributes))
+ .setChildNodeCount(children->length())
+ .setChildren(std::move(children))
+ .build();
+}
+
+std::unique_ptr<Array<std::string>> GetAttributes(const ash::WmWindow* window) {
+ std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create();
+ attributes->addItem("name");
+ attributes->addItem(window->GetName());
+ attributes->addItem("active");
+ attributes->addItem(window->IsActive() ? "true" : "false");
+ return attributes;
+}
+
+std::unique_ptr<Array<std::string>> GetAttributes(const views::Widget* widget) {
+ std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create();
+ attributes->addItem("name");
+ attributes->addItem(widget->GetName());
+ attributes->addItem("active");
+ attributes->addItem(widget->IsActive() ? "true" : "false");
+ return attributes;
+}
+
+std::unique_ptr<Array<std::string>> GetAttributes(const views::View* view) {
+ std::unique_ptr<Array<std::string>> attributes = Array<std::string>::create();
+ attributes->addItem("name");
+ attributes->addItem(view->GetClassName());
+ return attributes;
+}
+
+std::unique_ptr<DOM::Node> BuildTreeForView(views::View* view) {
+ std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
+ for (int i = 0, count = view->child_count(); i < count; i++) {
+ children->addItem(BuildTreeForView(view->child_at(i)));
+ }
+ return BuildNode("View", GetAttributes(view), std::move(children));
+}
+
+std::unique_ptr<DOM::Node> BuildTreeForRootWidget(views::Widget* widget) {
+ std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
+ children->addItem(BuildTreeForView(widget->GetRootView()));
+ return BuildNode("Widget", GetAttributes(widget), std::move(children));
+}
+
+std::unique_ptr<DOM::Node> BuildTreeForWindow(ash::WmWindow* window) {
+ std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
+ for (ash::WmWindow* child : window->GetChildren()) {
+ children->addItem(BuildTreeForWindow(child));
+ views::Widget* widget = child->GetInternalWidget();
+ if (widget)
+ children->addItem(BuildTreeForRootWidget(widget));
+ }
+ return BuildNode("Window", GetAttributes(window), std::move(children));
+}
+
+} // namespace
+
+AshDevToolsDOMAgent::AshDevToolsDOMAgent(ash::WmShell* shell) : shell_(shell) {
+ DCHECK(shell_);
+}
+
+AshDevToolsDOMAgent::~AshDevToolsDOMAgent() {}
+
+std::unique_ptr<ui::devtools::protocol::DOM::Node>
+AshDevToolsDOMAgent::BuildInitialTree() {
+ std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
+ for (ash::WmWindow* window : shell_->GetAllRootWindows()) {
+ children->addItem(BuildTreeForWindow(window));
+ }
+ return BuildNode("root", nullptr, std::move(children));
+}
+
+void AshDevToolsDOMAgent::getDocument(
+ ui::devtools::protocol::ErrorString* error,
+ std::unique_ptr<ui::devtools::protocol::DOM::Node>* out_root) {
+ *out_root = BuildInitialTree();
+}
+
+} // namespace devtools
+} // namespace ash
« no previous file with comments | « ash/common/devtools/devtools_dom_agent.h ('k') | ash/common/wm_shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698