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

Side by Side Diff: ash/common/devtools/devtools_client_backend.cc

Issue 2372843002: Add ash devtools client (Closed)
Patch Set: Add ash devtools client 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 unified diff | Download patch
OLDNEW
(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 #include "ash/common/devtools/devtools_client_backend.h"
6
7 #include "ash/common/wm_shell.h"
8 #include "ash/common/wm_window.h"
9 #include "ui/devtools/DOM.h"
10 #include "ui/devtools/devtools_server.h"
11 #include "ui/views/view.h"
12 #include "ui/views/widget/widget.h"
13
14 namespace ui {
15 namespace devtools {
16
17 AshDevToolsBackend::AshDevToolsBackend(ash::WmShell* shell) : shell_(shell) {
18 DCHECK(shell_);
19 }
20
21 AshDevToolsBackend::~AshDevToolsBackend() {}
22
23 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.
24 using namespace protocol;
25
26 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.
27
28 std::unique_ptr<DOM::Node> buildNode(
sadrul 2016/10/17 16:18:59 BuildNode
Sarmad Hashmi 2016/10/17 19:11:48 Done.
29 const String& name,
30 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)
31 std::unique_ptr<Array<DOM::Node>> children) {
32 return DOM::Node::create()
33 .setNodeId(node_ids++)
34 .setNodeName(name)
35 .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
36 .setAttributes(std::move(attributes))
37 .setChildNodeCount(children->length())
38 .setChildren(std::move(children))
39 .build();
40 }
41
42 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.
43 std::unique_ptr<Array<String>> attributes = Array<String>::create();
44 attributes->addItem("name");
45 attributes->addItem(window->GetName());
46 attributes->addItem("visible");
47 attributes->addItem(window->IsVisible() ? "true" : "false");
48 attributes->addItem("active");
49 attributes->addItem(window->IsActive() ? "true" : "false");
50 attributes->addItem("bounds_height");
51 attributes->addItem(base::IntToString(window->GetBounds().height()));
52 attributes->addItem("bounds_width");
53 attributes->addItem(base::IntToString(window->GetBounds().width()));
54 return attributes;
55 }
56
57 std::unique_ptr<Array<String>> getAttributes(const views::Widget* widget) {
58 std::unique_ptr<Array<String>> attributes = Array<String>::create();
59 attributes->addItem("name");
60 attributes->addItem(widget->GetName());
61 attributes->addItem("visible");
62 attributes->addItem(widget->IsVisible() ? "true" : "false");
63 attributes->addItem("active");
64 attributes->addItem(widget->IsActive() ? "true" : "false");
65 return attributes;
66 }
67
68 std::unique_ptr<Array<String>> getAttributes(const views::View* view) {
69 std::unique_ptr<Array<String>> attributes = Array<String>::create();
70 attributes->addItem("name");
71 attributes->addItem(view->GetClassName());
72 attributes->addItem("visible");
73 attributes->addItem(view->visible() ? "true" : "false");
74 attributes->addItem("x");
75 attributes->addItem(base::IntToString(view->x()));
76 attributes->addItem("y");
77 attributes->addItem(base::IntToString(view->y()));
78 attributes->addItem("bounds_height");
79 attributes->addItem(base::IntToString(view->bounds().bottom()));
80 attributes->addItem("bounds_width");
81 attributes->addItem(base::IntToString(view->bounds().right()));
82 return attributes;
83 }
84
85 std::unique_ptr<DOM::Node> buildTreeForRootView(views::View* view) {
86 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
87 for (int i = 0, count = view->child_count(); i < count; i++) {
88 children->addItem(buildTreeForRootView(view->child_at(i)));
89 }
90 return buildNode("View", getAttributes(view), std::move(children));
91 }
92
93 std::unique_ptr<DOM::Node> buildTreeForRootWidget(views::Widget* widget) {
94 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
95 children->addItem(buildTreeForRootView(widget->GetRootView()));
96 return buildNode("Widget", getAttributes(widget), std::move(children));
97 }
98
99 std::unique_ptr<DOM::Node> buildTreeForRootWindow(ash::WmWindow* window) {
100 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
101 for (ash::WmWindow* child : window->GetChildren()) {
102 children->addItem(buildTreeForRootWindow(child));
103 views::Widget* widget = child->GetInternalWidget();
104 if (widget)
105 children->addItem(buildTreeForRootWidget(widget));
106 }
107 return buildNode("Window", getAttributes(window), std::move(children));
108 }
109
110 } // namespace
111
112 std::unique_ptr<protocol::DOM::Node> AshDevToolsBackend::buildInitialTree() {
113 std::unique_ptr<Array<DOM::Node>> children = Array<DOM::Node>::create();
114 for (ash::WmWindow* window : shell_->GetAllRootWindows()) {
115 children->addItem(buildTreeForRootWindow(window));
116 }
117 return buildNode("root", nullptr, std::move(children));
118 }
119
120 void AshDevToolsBackend::getDocument(
121 protocol::ErrorString* error,
122 std::unique_ptr<protocol::DOM::Node>* out_root) {
123 *out_root = buildInitialTree();
124 }
125
126 } // namespace devtools
127 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698