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

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

Issue 2372843002: Add ash devtools client (Closed)
Patch Set: Add ash devtools client Created 4 years, 3 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
Index: ash/common/devtools/devtools_client_backend.cc
diff --git a/ash/common/devtools/devtools_client_backend.cc b/ash/common/devtools/devtools_client_backend.cc
new file mode 100644
index 0000000000000000000000000000000000000000..da0b6f0586eaf58375a0066ade4c154eaebebcc8
--- /dev/null
+++ b/ash/common/devtools/devtools_client_backend.cc
@@ -0,0 +1,127 @@
+// 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_client_backend.h"
+
+#include "ash/common/wm_shell.h"
+#include "ash/common/wm_window.h"
+#include "ui/devtools/DOM.h"
+#include "ui/devtools/devtools_server.h"
+#include "ui/views/view.h"
+#include "ui/views/widget/widget.h"
+
+namespace ui {
+namespace devtools {
+
+AshDevToolsBackend::AshDevToolsBackend(ash::WmShell* shell) : shell_(shell) {
+ DCHECK(shell_);
+}
+
+AshDevToolsBackend::~AshDevToolsBackend() {}
+
+namespace {
sadrul 2016/10/17 16:18:59 This anon-namespace block should go before the Ash
Sarmad Hashmi 2016/10/17 19:11:47 Done.
+using namespace protocol;
+
+DOM::NodeId node_ids = 0;
sadrul 2016/10/17 16:18:59 Move this into BuildNode below, as 'static DOM::No
Sarmad Hashmi 2016/10/17 19:11:48 Done.
+
+std::unique_ptr<DOM::Node> buildNode(
sadrul 2016/10/17 16:18:59 BuildNode
Sarmad Hashmi 2016/10/17 19:11:48 Done.
+ const String& name,
+ std::unique_ptr<Array<String>> attributes,
sadrul 2016/10/17 16:18:59 Where is Array defined?
Sarmad Hashmi 2016/10/17 19:11:47 protocol::Array (generated)
+ std::unique_ptr<Array<DOM::Node>> children) {
+ return DOM::Node::create()
+ .setNodeId(node_ids++)
+ .setNodeName(name)
+ .setNodeType(1)
sadrul 2016/10/17 16:18:59 What does '1' mean here?
Sarmad Hashmi 2016/10/17 19:11:47 https://www.w3.org/TR/1998/REC-DOM-Level-1-1998100
+ .setAttributes(std::move(attributes))
+ .setChildNodeCount(children->length())
+ .setChildren(std::move(children))
+ .build();
+}
+
+std::unique_ptr<Array<String>> getAttributes(const ash::WmWindow* window) {
sadrul 2016/10/17 16:18:59 GetAttributes
Sarmad Hashmi 2016/10/17 19:11:47 Done.
+ std::unique_ptr<Array<String>> attributes = Array<String>::create();
+ attributes->addItem("name");
+ attributes->addItem(window->GetName());
+ attributes->addItem("visible");
+ attributes->addItem(window->IsVisible() ? "true" : "false");
+ attributes->addItem("active");
+ attributes->addItem(window->IsActive() ? "true" : "false");
+ attributes->addItem("bounds_height");
+ attributes->addItem(base::IntToString(window->GetBounds().height()));
+ attributes->addItem("bounds_width");
+ attributes->addItem(base::IntToString(window->GetBounds().width()));
+ return attributes;
+}
+
+std::unique_ptr<Array<String>> getAttributes(const views::Widget* widget) {
+ std::unique_ptr<Array<String>> attributes = Array<String>::create();
+ attributes->addItem("name");
+ attributes->addItem(widget->GetName());
+ attributes->addItem("visible");
+ attributes->addItem(widget->IsVisible() ? "true" : "false");
+ attributes->addItem("active");
+ attributes->addItem(widget->IsActive() ? "true" : "false");
+ return attributes;
+}
+
+std::unique_ptr<Array<String>> getAttributes(const views::View* view) {
+ std::unique_ptr<Array<String>> attributes = Array<String>::create();
+ attributes->addItem("name");
+ attributes->addItem(view->GetClassName());
+ attributes->addItem("visible");
+ attributes->addItem(view->visible() ? "true" : "false");
+ attributes->addItem("x");
+ attributes->addItem(base::IntToString(view->x()));
+ attributes->addItem("y");
+ attributes->addItem(base::IntToString(view->y()));
+ attributes->addItem("bounds_height");
+ attributes->addItem(base::IntToString(view->bounds().bottom()));
+ attributes->addItem("bounds_width");
+ attributes->addItem(base::IntToString(view->bounds().right()));
+ return attributes;
+}
+
+std::unique_ptr<DOM::Node> buildTreeForRootView(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(buildTreeForRootView(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(buildTreeForRootView(widget->GetRootView()));
+ return buildNode("Widget", getAttributes(widget), std::move(children));
+}
+
+std::unique_ptr<DOM::Node> buildTreeForRootWindow(ash::WmWindow* window) {
+ std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
+ for (ash::WmWindow* child : window->GetChildren()) {
+ children->addItem(buildTreeForRootWindow(child));
+ views::Widget* widget = child->GetInternalWidget();
+ if (widget)
+ children->addItem(buildTreeForRootWidget(widget));
+ }
+ return buildNode("Window", getAttributes(window), std::move(children));
+}
+
+} // namespace
+
+std::unique_ptr<protocol::DOM::Node> AshDevToolsBackend::buildInitialTree() {
+ std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
+ for (ash::WmWindow* window : shell_->GetAllRootWindows()) {
+ children->addItem(buildTreeForRootWindow(window));
+ }
+ return buildNode("root", nullptr, std::move(children));
+}
+
+void AshDevToolsBackend::getDocument(
+ protocol::ErrorString* error,
+ std::unique_ptr<protocol::DOM::Node>* out_root) {
+ *out_root = buildInitialTree();
+}
+
+} // namespace devtools
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698