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

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

Issue 2808923002: Revert of add a new set of commands to resize and position windows (patchset #35 id:680001 of https… (Closed)
Patch Set: Created 3 years, 8 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 <utility>
8
9 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
10 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
11 #include "build/build_config.h" 9 #include "build/build_config.h"
12 #include "chrome/browser/devtools/device/android_device_manager.h" 10 #include "chrome/browser/devtools/device/android_device_manager.h"
13 #include "chrome/browser/devtools/device/tcp_device_provider.h" 11 #include "chrome/browser/devtools/device/tcp_device_provider.h"
14 #include "chrome/browser/devtools/devtools_network_protocol_handler.h" 12 #include "chrome/browser/devtools/devtools_network_protocol_handler.h"
15 #include "chrome/browser/devtools/devtools_protocol_constants.h" 13 #include "chrome/browser/devtools/devtools_protocol_constants.h"
16 #include "chrome/browser/devtools/devtools_window.h" 14 #include "chrome/browser/devtools/devtools_window.h"
17 #include "chrome/browser/extensions/extension_tab_util.h" 15 #include "chrome/browser/extensions/extension_tab_util.h"
18 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/ui/browser_navigator.h" 18 #include "chrome/browser/ui/browser_navigator.h"
21 #include "chrome/browser/ui/browser_navigator_params.h" 19 #include "chrome/browser/ui/browser_navigator_params.h"
22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
24 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/grit/browser_resources.h" 21 #include "chrome/grit/browser_resources.h"
27 #include "components/guest_view/browser/guest_view_base.h" 22 #include "components/guest_view/browser/guest_view_base.h"
28 #include "content/public/browser/devtools_agent_host.h" 23 #include "content/public/browser/devtools_agent_host.h"
29 #include "content/public/browser/render_frame_host.h" 24 #include "content/public/browser/render_frame_host.h"
30 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
31 #include "extensions/browser/extension_host.h" 26 #include "extensions/browser/extension_host.h"
32 #include "extensions/browser/extension_registry.h" 27 #include "extensions/browser/extension_registry.h"
33 #include "extensions/browser/process_manager.h" 28 #include "extensions/browser/process_manager.h"
34 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
35 30
36 using content::DevToolsAgentHost; 31 using content::DevToolsAgentHost;
37 32
38 char ChromeDevToolsManagerDelegate::kTypeApp[] = "app"; 33 char ChromeDevToolsManagerDelegate::kTypeApp[] = "app";
39 char ChromeDevToolsManagerDelegate::kTypeBackgroundPage[] = "background_page"; 34 char ChromeDevToolsManagerDelegate::kTypeBackgroundPage[] = "background_page";
40 char ChromeDevToolsManagerDelegate::kTypeWebView[] = "webview"; 35 char ChromeDevToolsManagerDelegate::kTypeWebView[] = "webview";
41 36
42 namespace { 37 namespace {
43 38
44 char kLocationsParam[] = "locations"; 39 char kLocationsParam[] = "locations";
45 char kHostParam[] = "host"; 40 char kHostParam[] = "host";
46 char kPortParam[] = "port"; 41 char kPortParam[] = "port";
47 42
48 BrowserWindow* GetBrowserWindow(int window_id) {
49 for (auto* b : *BrowserList::GetInstance()) {
50 if (b->session_id().id() == window_id)
51 return b->window();
52 }
53 return nullptr;
54 }
55
56 // Get the bounds and state of the browser window. The bounds is for the
57 // restored window when the window is minimized. Otherwise, it is for the actual
58 // window.
59 std::unique_ptr<base::DictionaryValue> GetBounds(BrowserWindow* window) {
60 gfx::Rect bounds;
61 if (window->IsMinimized())
62 bounds = window->GetRestoredBounds();
63 else
64 bounds = window->GetBounds();
65
66 auto bounds_object = base::MakeUnique<base::DictionaryValue>();
67
68 bounds_object->SetInteger("left", bounds.x());
69 bounds_object->SetInteger("top", bounds.y());
70 bounds_object->SetInteger("width", bounds.width());
71 bounds_object->SetInteger("height", bounds.height());
72
73 std::string window_state = "normal";
74 if (window->IsMinimized())
75 window_state = "minimized";
76 if (window->IsMaximized())
77 window_state = "maximized";
78 if (window->IsFullscreen())
79 window_state = "fullscreen";
80 bounds_object->SetString("windowState", window_state);
81
82 return bounds_object;
83 }
84
85 bool GetExtensionInfo(content::RenderFrameHost* host, 43 bool GetExtensionInfo(content::RenderFrameHost* host,
86 std::string* name, 44 std::string* name,
87 std::string* type) { 45 std::string* type) {
88 content::WebContents* wc = content::WebContents::FromRenderFrameHost(host); 46 content::WebContents* wc = content::WebContents::FromRenderFrameHost(host);
89 if (!wc) 47 if (!wc)
90 return false; 48 return false;
91 Profile* profile = Profile::FromBrowserContext(wc->GetBrowserContext()); 49 Profile* profile = Profile::FromBrowserContext(wc->GetBrowserContext());
92 if (!profile) 50 if (!profile)
93 return false; 51 return false;
94 const extensions::Extension* extension = 52 const extensions::Extension* extension =
(...skipping 13 matching lines...) Expand all
108 extension->is_platform_app()) { 66 extension->is_platform_app()) {
109 *name = extension->name(); 67 *name = extension->name();
110 *type = ChromeDevToolsManagerDelegate::kTypeApp; 68 *type = ChromeDevToolsManagerDelegate::kTypeApp;
111 return true; 69 return true;
112 } 70 }
113 return false; 71 return false;
114 } 72 }
115 73
116 } // namespace 74 } // namespace
117 75
118 // static
119 std::unique_ptr<base::DictionaryValue>
120 ChromeDevToolsManagerDelegate::GetWindowForTarget(
121 int id,
122 base::DictionaryValue* params) {
123 std::string target_id;
124 if (!params->GetString("targetId", &target_id))
125 return DevToolsProtocol::CreateInvalidParamsResponse(id, "targetId");
126
127 Browser* browser = nullptr;
128 scoped_refptr<DevToolsAgentHost> host =
129 DevToolsAgentHost::GetForId(target_id);
130 if (!host)
131 return DevToolsProtocol::CreateErrorResponse(id, "No target with given id");
132 content::WebContents* web_contents = host->GetWebContents();
133 if (!web_contents) {
134 return DevToolsProtocol::CreateErrorResponse(
135 id, "No web contents in the target");
136 }
137 for (auto* b : *BrowserList::GetInstance()) {
138 int tab_index = b->tab_strip_model()->GetIndexOfWebContents(web_contents);
139 if (tab_index != TabStripModel::kNoTab)
140 browser = b;
141 }
142 if (!browser) {
143 return DevToolsProtocol::CreateErrorResponse(id,
144 "Browser window not found");
145 }
146
147 auto result = base::MakeUnique<base::DictionaryValue>();
148 result->SetInteger("windowId", browser->session_id().id());
149 result->Set("bounds", GetBounds(browser->window()));
150 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
151 }
152
153 // static
154 std::unique_ptr<base::DictionaryValue>
155 ChromeDevToolsManagerDelegate::GetWindowBounds(int id,
156 base::DictionaryValue* params) {
157 int window_id;
158 if (!params->GetInteger("windowId", &window_id))
159 return DevToolsProtocol::CreateInvalidParamsResponse(id, "windowId");
160 BrowserWindow* window = GetBrowserWindow(window_id);
161 if (!window) {
162 return DevToolsProtocol::CreateErrorResponse(id,
163 "Browser window not found");
164 }
165
166 auto result = base::MakeUnique<base::DictionaryValue>();
167 result->Set("bounds", GetBounds(window));
168 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
169 }
170
171 // static
172 std::unique_ptr<base::DictionaryValue>
173 ChromeDevToolsManagerDelegate::SetWindowBounds(int id,
174 base::DictionaryValue* params) {
175 int window_id;
176 if (!params->GetInteger("windowId", &window_id))
177 return DevToolsProtocol::CreateInvalidParamsResponse(id, "windowId");
178 BrowserWindow* window = GetBrowserWindow(window_id);
179 if (!window) {
180 return DevToolsProtocol::CreateErrorResponse(id,
181 "Browser window not found");
182 }
183
184 const base::Value* value = nullptr;
185 const base::DictionaryValue* bounds_dict = nullptr;
186 if (!params->Get("bounds", &value) || !value->GetAsDictionary(&bounds_dict))
187 return DevToolsProtocol::CreateInvalidParamsResponse(id, "bounds");
188
189 std::string window_state;
190 if (!bounds_dict->GetString("windowState", &window_state))
191 window_state = "normal";
192 else if (window_state != "normal" && window_state != "minimized" &&
193 window_state != "maximized" && window_state != "fullscreen")
194 return DevToolsProtocol::CreateInvalidParamsResponse(id, "windowState");
195
196 // Compute updated bounds when window state is normal.
197 bool set_bounds = false;
198 gfx::Rect bounds = window->GetBounds();
199 int left, top, width, height;
200 if (bounds_dict->GetInteger("left", &left)) {
201 bounds.set_x(left);
202 set_bounds = true;
203 }
204 if (bounds_dict->GetInteger("top", &top)) {
205 bounds.set_y(top);
206 set_bounds = true;
207 }
208 if (bounds_dict->GetInteger("width", &width)) {
209 if (width < 0)
210 return DevToolsProtocol::CreateInvalidParamsResponse(id, "width");
211 bounds.set_width(width);
212 set_bounds = true;
213 }
214 if (bounds_dict->GetInteger("height", &height)) {
215 if (height < 0)
216 return DevToolsProtocol::CreateInvalidParamsResponse(id, "height");
217 bounds.set_height(height);
218 set_bounds = true;
219 }
220
221 if (set_bounds && window_state != "normal") {
222 return DevToolsProtocol::CreateErrorResponse(
223 id,
224 "The 'minimized', 'maximized' and 'fullscreen' states cannot be "
225 "combined with 'left', 'top', 'width' or 'height'");
226 }
227
228 if (set_bounds && (window->IsMinimized() || window->IsMaximized() ||
229 window->IsFullscreen())) {
230 return DevToolsProtocol::CreateErrorResponse(
231 id,
232 "To resize minimized/maximized/fullscreen window, restore it to normal "
233 "state first.");
234 }
235
236 if (window_state == "fullscreen") {
237 if (window->IsMinimized()) {
238 return DevToolsProtocol::CreateErrorResponse(id,
239 "To make minimized window "
240 "fullscreen, restore it to "
241 "normal state first.");
242 }
243 window->GetExclusiveAccessContext()->EnterFullscreen(
244 GURL(), EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE);
245 }
246
247 if (window_state == "maximized") {
248 if (window->IsMinimized() || window->IsFullscreen()) {
249 return DevToolsProtocol::CreateErrorResponse(
250 id,
251 "To maximize a minimized or fullscreen window, restore it to normal "
252 "state first.");
253 }
254 window->Maximize();
255 }
256
257 if (window_state == "minimized") {
258 if (window->IsFullscreen()) {
259 return DevToolsProtocol::CreateErrorResponse(
260 id,
261 "To minimize a fullscreen window, restore it to normal "
262 "state first.");
263 }
264 window->Minimize();
265 }
266
267 if (window_state == "normal") {
268 if (window->IsFullscreen()) {
269 window->GetExclusiveAccessContext()->ExitFullscreen();
270 } else if (window->IsMinimized()) {
271 window->Show();
272 } else if (window->IsMaximized()) {
273 window->Restore();
274 } else if (set_bounds) {
275 window->SetBounds(bounds);
276 }
277 }
278
279 return DevToolsProtocol::CreateSuccessResponse(id, nullptr);
280 }
281
282 std::unique_ptr<base::DictionaryValue>
283 ChromeDevToolsManagerDelegate::HandleBrowserCommand(
284 int id,
285 std::string method,
286 base::DictionaryValue* params) {
287 if (method == chrome::devtools::Browser::getWindowForTarget::kName)
288 return GetWindowForTarget(id, params);
289 if (method == chrome::devtools::Browser::getWindowBounds::kName)
290 return GetWindowBounds(id, params);
291 if (method == chrome::devtools::Browser::setWindowBounds::kName)
292 return SetWindowBounds(id, params);
293 return nullptr;
294 }
295
296 class ChromeDevToolsManagerDelegate::HostData { 76 class ChromeDevToolsManagerDelegate::HostData {
297 public: 77 public:
298 HostData() {} 78 HostData() {}
299 ~HostData() {} 79 ~HostData() {}
300 80
301 RemoteLocations& remote_locations() { return remote_locations_; } 81 RemoteLocations& remote_locations() { return remote_locations_; }
302 82
303 void set_remote_locations(RemoteLocations& locations) { 83 void set_remote_locations(RemoteLocations& locations) {
304 remote_locations_.swap(locations); 84 remote_locations_.swap(locations);
305 } 85 }
(...skipping 19 matching lines...) Expand all
325 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( 105 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand(
326 DevToolsAgentHost* agent_host, 106 DevToolsAgentHost* agent_host,
327 base::DictionaryValue* command_dict) { 107 base::DictionaryValue* command_dict) {
328 108
329 int id = 0; 109 int id = 0;
330 std::string method; 110 std::string method;
331 base::DictionaryValue* params = nullptr; 111 base::DictionaryValue* params = nullptr;
332 if (!DevToolsProtocol::ParseCommand(command_dict, &id, &method, &params)) 112 if (!DevToolsProtocol::ParseCommand(command_dict, &id, &method, &params))
333 return nullptr; 113 return nullptr;
334 114
335 if (agent_host->GetType() == DevToolsAgentHost::kTypeBrowser &&
336 method.find("Browser.") == 0)
337 return HandleBrowserCommand(id, method, params).release();
338
339 if (method == chrome::devtools::Target::setRemoteLocations::kName) 115 if (method == chrome::devtools::Target::setRemoteLocations::kName)
340 return SetRemoteLocations(agent_host, id, params).release(); 116 return SetRemoteLocations(agent_host, id, params).release();
341 117
342 return network_protocol_handler_->HandleCommand(agent_host, command_dict); 118 return network_protocol_handler_->HandleCommand(agent_host, command_dict);
343 } 119 }
344 120
345 std::string ChromeDevToolsManagerDelegate::GetTargetType( 121 std::string ChromeDevToolsManagerDelegate::GetTargetType(
346 content::RenderFrameHost* host) { 122 content::RenderFrameHost* host) {
347 content::WebContents* web_contents = 123 content::WebContents* web_contents =
348 content::WebContents::FromRenderFrameHost(host); 124 content::WebContents::FromRenderFrameHost(host);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 if (!dictionary->GetIntegerWithoutPathExpansion(kPortParam, &port)) { 277 if (!dictionary->GetIntegerWithoutPathExpansion(kPortParam, &port)) {
502 return DevToolsProtocol::CreateInvalidParamsResponse(command_id, 278 return DevToolsProtocol::CreateInvalidParamsResponse(command_id,
503 kLocationsParam); 279 kLocationsParam);
504 } 280 }
505 tcp_locations.insert(net::HostPortPair(host, port)); 281 tcp_locations.insert(net::HostPortPair(host, port));
506 } 282 }
507 283
508 host_data_[agent_host]->set_remote_locations(tcp_locations); 284 host_data_[agent_host]->set_remote_locations(tcp_locations);
509 UpdateDeviceDiscovery(); 285 UpdateDeviceDiscovery();
510 286
511 return DevToolsProtocol::CreateSuccessResponse(command_id, nullptr); 287 std::unique_ptr<base::DictionaryValue> result(
288 base::MakeUnique<base::DictionaryValue>());
289 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result));
512 } 290 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/chrome_devtools_manager_delegate.h ('k') | chrome/browser/devtools/devtools_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698