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

Side by Side Diff: chrome/browser/devtools/chrome_devtools_manager_delegate.cc

Issue 2734123004: add a new set of commands to resize and position windows (Closed)
Patch Set: add methods to UI domain Created 3 years, 9 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" 5 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/devtools/device/android_device_manager.h" 10 #include "chrome/browser/devtools/device/android_device_manager.h"
11 #include "chrome/browser/devtools/device/tcp_device_provider.h" 11 #include "chrome/browser/devtools/device/tcp_device_provider.h"
12 #include "chrome/browser/devtools/devtools_network_protocol_handler.h" 12 #include "chrome/browser/devtools/devtools_network_protocol_handler.h"
13 #include "chrome/browser/devtools/devtools_protocol_constants.h" 13 #include "chrome/browser/devtools/devtools_protocol_constants.h"
14 #include "chrome/browser/devtools/devtools_window.h" 14 #include "chrome/browser/devtools/devtools_window.h"
15 #include "chrome/browser/extensions/extension_tab_util.h" 15 #include "chrome/browser/extensions/extension_tab_util.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/ui/browser_navigator.h" 18 #include "chrome/browser/ui/browser_navigator.h"
19 #include "chrome/browser/ui/browser_navigator_params.h" 19 #include "chrome/browser/ui/browser_navigator_params.h"
20 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 21 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/grit/browser_resources.h" 23 #include "chrome/grit/browser_resources.h"
22 #include "components/guest_view/browser/guest_view_base.h" 24 #include "components/guest_view/browser/guest_view_base.h"
25 #include "components/ui_devtools/string_util.h"
23 #include "content/public/browser/devtools_agent_host.h" 26 #include "content/public/browser/devtools_agent_host.h"
24 #include "content/public/browser/render_frame_host.h" 27 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
26 #include "extensions/browser/extension_host.h" 29 #include "extensions/browser/extension_host.h"
27 #include "extensions/browser/extension_registry.h" 30 #include "extensions/browser/extension_registry.h"
28 #include "extensions/browser/process_manager.h" 31 #include "extensions/browser/process_manager.h"
29 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
30 33
31 using content::DevToolsAgentHost; 34 using content::DevToolsAgentHost;
32 35
33 char ChromeDevToolsManagerDelegate::kTypeApp[] = "app"; 36 char ChromeDevToolsManagerDelegate::kTypeApp[] = "app";
34 char ChromeDevToolsManagerDelegate::kTypeBackgroundPage[] = "background_page"; 37 char ChromeDevToolsManagerDelegate::kTypeBackgroundPage[] = "background_page";
35 char ChromeDevToolsManagerDelegate::kTypeWebView[] = "webview"; 38 char ChromeDevToolsManagerDelegate::kTypeWebView[] = "webview";
36 39
37 char kLocationsParam[] = "locations"; 40 char kLocationsParam[] = "locations";
38 char kHostParam[] = "host"; 41 char kHostParam[] = "host";
39 char kPortParam[] = "port"; 42 char kPortParam[] = "port";
40 43
44 BrowserWindow* GetBrowserWindow(base::DictionaryValue* params) {
45 if (!params)
46 return nullptr;
47 int window_id;
48 if (!params->GetInteger("windowId", &window_id))
49 return nullptr;
50 for (auto* b : *BrowserList::GetInstance()) {
51 if (b->session_id().id() == window_id)
52 return b->window();
53 }
54 return nullptr;
55 }
56
57 std::unique_ptr<base::DictionaryValue> HandleUICommand(
58 content::DevToolsAgentHost* agent_host,
59 int id,
60 std::string method,
61 base::DictionaryValue* params) {
62 if (method == chrome::devtools::UI::getWindowFromTarget::kName) {
63 if (!params)
64 return DevToolsProtocol::CreateInvalidParamsResponse(id, "params");
65 std::string target_id;
66 if (!params->GetString(
67 chrome::devtools::UI::getWindowFromTarget::kParamTargetId,
68 &target_id))
69 return DevToolsProtocol::CreateInvalidParamsResponse(id, "targetId");
70
71 Browser* browser = nullptr;
72 scoped_refptr<DevToolsAgentHost> host =
73 DevToolsAgentHost::GetForId(target_id);
dgozman 2017/03/20 22:00:48 if (!host) CreateErrorResponse(id, "No target wi
jzfeng 2017/03/21 09:13:32 Done.
74 content::WebContents* web_contents =
75 host ? host->GetWebContents() : nullptr;
76 for (auto* b : *BrowserList::GetInstance()) {
77 int tab_index = b->tab_strip_model()->GetIndexOfWebContents(web_contents);
78 if (tab_index != TabStripModel::kNoTab)
79 browser = b;
80 }
81 if (!browser)
82 return DevToolsProtocol::CreateErrorResponse(id,
83 "browser window not found");
84
85 std::unique_ptr<base::DictionaryValue> result(
86 base::MakeUnique<base::DictionaryValue>());
87 result->SetInteger("windowId", browser->session_id().id());
88 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
89 }
90
91 if (method == chrome::devtools::UI::maximizeWindow::kName) {
92 if (!params)
93 return DevToolsProtocol::CreateInvalidParamsResponse(id, "params");
94 BrowserWindow* window = GetBrowserWindow(params);
95 if (!window)
96 return DevToolsProtocol::CreateErrorResponse(id,
97 "browser window not found");
98 window->Maximize();
99 std::unique_ptr<base::DictionaryValue> result(
100 base::MakeUnique<base::DictionaryValue>());
101 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
102 }
103 if (method == chrome::devtools::UI::minimizeWindow::kName) {
104 if (!params)
105 return DevToolsProtocol::CreateInvalidParamsResponse(id, "params");
106 BrowserWindow* window = GetBrowserWindow(params);
107 if (!window)
108 return DevToolsProtocol::CreateErrorResponse(id,
109 "browser window not found");
110 window->Minimize();
111 std::unique_ptr<base::DictionaryValue> result(
112 base::MakeUnique<base::DictionaryValue>());
113 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
114 }
115 if (method == chrome::devtools::UI::getWindowBounds::kName) {
116 if (!params)
117 return DevToolsProtocol::CreateInvalidParamsResponse(id, "params");
118 BrowserWindow* window = GetBrowserWindow(params);
119 if (!window)
120 return DevToolsProtocol::CreateErrorResponse(id,
121 "browser window not found");
122 gfx::Rect bounds;
123 if (window->IsMinimized())
124 bounds = window->GetRestoredBounds();
125 else
126 bounds = window->GetBounds();
127 std::unique_ptr<base::DictionaryValue> result(
128 base::MakeUnique<base::DictionaryValue>());
129 result->SetInteger("left", bounds.x());
130 result->SetInteger("top", bounds.y());
131 result->SetInteger("width", bounds.width());
132 result->SetInteger("height", bounds.height());
133 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
134 }
135 if (method == chrome::devtools::UI::setWindowBounds::kName) {
136 if (!params)
137 return DevToolsProtocol::CreateInvalidParamsResponse(id, "params");
138 BrowserWindow* window = GetBrowserWindow(params);
139 if (!window)
140 return DevToolsProtocol::CreateErrorResponse(id,
141 "browser window not found");
142 gfx::Rect bounds;
143 if (window->IsMinimized())
144 bounds = window->GetRestoredBounds();
145 else
146 bounds = window->GetBounds();
147
148 namespace names = chrome::devtools::UI::setWindowBounds;
149 int left, top, width, height;
150 bool set_bounds = false;
151 // Any part of the bounds can optionally be set by the caller.
152 if (params->GetInteger(names::kParamLeft, &left)) {
153 bounds.set_x(left);
154 set_bounds = true;
155 }
156 if (params->GetInteger(names::kParamTop, &top)) {
157 bounds.set_y(top);
158 set_bounds = true;
159 }
160 if (params->GetInteger(names::kParamWidth, &width)) {
161 if (width < 0)
162 return DevToolsProtocol::CreateInvalidParamsResponse(id, "width");
163 bounds.set_width(width);
164 set_bounds = true;
165 }
166 if (params->GetInteger(names::kParamHeight, &height)) {
167 if (height < 0)
168 return DevToolsProtocol::CreateInvalidParamsResponse(id, "height");
169 bounds.set_height(height);
170 set_bounds = true;
171 }
172
173 if (set_bounds)
174 window->SetBounds(bounds);
175 std::unique_ptr<base::DictionaryValue> result(
176 base::MakeUnique<base::DictionaryValue>());
177 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
178 }
179 if (method == chrome::devtools::UI::setWindowFullscreen::kName) {
180 if (!params)
181 return DevToolsProtocol::CreateInvalidParamsResponse(id, "params");
182 BrowserWindow* window = GetBrowserWindow(params);
183 if (!window)
184 return DevToolsProtocol::CreateErrorResponse(id,
185 "browser window not found");
186 bool fullscreen = false;
187 if (!params->GetBoolean(
188 chrome::devtools::UI::setWindowFullscreen::kParamFullscreen,
189 &fullscreen))
190 return DevToolsProtocol::CreateInvalidParamsResponse(id, "fullscreen");
191 window->SetFullscreen(fullscreen);
dgozman 2017/03/20 22:00:48 Why not just call window->GetExclusiveAccessContex
jzfeng 2017/03/21 09:13:32 Good point! Done.
192 std::unique_ptr<base::DictionaryValue> result(
193 base::MakeUnique<base::DictionaryValue>());
194 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
195 }
196 return nullptr;
197 }
198
41 class ChromeDevToolsManagerDelegate::HostData { 199 class ChromeDevToolsManagerDelegate::HostData {
42 public: 200 public:
43 HostData() {} 201 HostData() {}
44 ~HostData() {} 202 ~HostData() {}
45 203
46 RemoteLocations& remote_locations() { return remote_locations_; } 204 RemoteLocations& remote_locations() { return remote_locations_; }
47 205
48 void set_remote_locations(RemoteLocations& locations) { 206 void set_remote_locations(RemoteLocations& locations) {
49 remote_locations_.swap(locations); 207 remote_locations_.swap(locations);
50 } 208 }
(...skipping 19 matching lines...) Expand all
70 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( 228 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand(
71 DevToolsAgentHost* agent_host, 229 DevToolsAgentHost* agent_host,
72 base::DictionaryValue* command_dict) { 230 base::DictionaryValue* command_dict) {
73 231
74 int id = 0; 232 int id = 0;
75 std::string method; 233 std::string method;
76 base::DictionaryValue* params = nullptr; 234 base::DictionaryValue* params = nullptr;
77 if (!DevToolsProtocol::ParseCommand(command_dict, &id, &method, &params)) 235 if (!DevToolsProtocol::ParseCommand(command_dict, &id, &method, &params))
78 return nullptr; 236 return nullptr;
79 237
238 using stringUtil = ::ui::devtools::protocol::StringUtil;
239 size_t dotIndex = stringUtil::find(method, ".");
240 if (dotIndex == stringUtil::kNotFound)
241 return nullptr;
242 std::string domain = stringUtil::substring(method, 0, dotIndex);
243 if (domain == chrome::devtools::UI::kName)
dgozman 2017/03/20 22:00:48 if (method.find("UI.") == 0)
jzfeng 2017/03/21 09:13:32 Done.
244 return HandleUICommand(agent_host, id, method, params).release();
245
80 if (method == chrome::devtools::Target::setRemoteLocations::kName) 246 if (method == chrome::devtools::Target::setRemoteLocations::kName)
81 return SetRemoteLocations(agent_host, id, params).release(); 247 return SetRemoteLocations(agent_host, id, params).release();
82 248
83 return network_protocol_handler_->HandleCommand(agent_host, command_dict); 249 return network_protocol_handler_->HandleCommand(agent_host, command_dict);
84 } 250 }
85 251
86 std::string ChromeDevToolsManagerDelegate::GetTargetType( 252 std::string ChromeDevToolsManagerDelegate::GetTargetType(
87 content::RenderFrameHost* host) { 253 content::RenderFrameHost* host) {
88 content::WebContents* web_contents = 254 content::WebContents* web_contents =
89 content::WebContents::FromRenderFrameHost(host); 255 content::WebContents::FromRenderFrameHost(host);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 tcp_locations.insert(net::HostPortPair(host, port)); 439 tcp_locations.insert(net::HostPortPair(host, port));
274 } 440 }
275 441
276 host_data_[agent_host]->set_remote_locations(tcp_locations); 442 host_data_[agent_host]->set_remote_locations(tcp_locations);
277 UpdateDeviceDiscovery(); 443 UpdateDeviceDiscovery();
278 444
279 std::unique_ptr<base::DictionaryValue> result( 445 std::unique_ptr<base::DictionaryValue> result(
280 base::MakeUnique<base::DictionaryValue>()); 446 base::MakeUnique<base::DictionaryValue>());
281 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result)); 447 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result));
282 } 448 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/devtools/devtools_protocol.h » ('j') | content/browser/devtools/protocol/ui_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698