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

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: use browser window to support linux/window/mac 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"
21 #include "chrome/grit/browser_resources.h" 22 #include "chrome/grit/browser_resources.h"
22 #include "components/guest_view/browser/guest_view_base.h" 23 #include "components/guest_view/browser/guest_view_base.h"
24 #include "components/ui_devtools/string_util.h"
23 #include "content/public/browser/devtools_agent_host.h" 25 #include "content/public/browser/devtools_agent_host.h"
24 #include "content/public/browser/render_frame_host.h" 26 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
26 #include "extensions/browser/extension_host.h" 28 #include "extensions/browser/extension_host.h"
27 #include "extensions/browser/extension_registry.h" 29 #include "extensions/browser/extension_registry.h"
28 #include "extensions/browser/process_manager.h" 30 #include "extensions/browser/process_manager.h"
29 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
30 32
31 using content::DevToolsAgentHost; 33 using content::DevToolsAgentHost;
32 34
33 char ChromeDevToolsManagerDelegate::kTypeApp[] = "app"; 35 char ChromeDevToolsManagerDelegate::kTypeApp[] = "app";
34 char ChromeDevToolsManagerDelegate::kTypeBackgroundPage[] = "background_page"; 36 char ChromeDevToolsManagerDelegate::kTypeBackgroundPage[] = "background_page";
35 char ChromeDevToolsManagerDelegate::kTypeWebView[] = "webview"; 37 char ChromeDevToolsManagerDelegate::kTypeWebView[] = "webview";
36 38
37 char kLocationsParam[] = "locations"; 39 char kLocationsParam[] = "locations";
38 char kHostParam[] = "host"; 40 char kHostParam[] = "host";
39 char kPortParam[] = "port"; 41 char kPortParam[] = "port";
40 42
43 std::unique_ptr<base::DictionaryValue> HandlePageCommand(
44 content::DevToolsAgentHost* agent_host,
45 int id,
46 std::string method,
47 base::DictionaryValue* params) {
48 if (method == chrome::devtools::Page::maximizeWindow::kName) {
49 BrowserWindow::GetBrowserWindowForNativeWindow(
50 agent_host->GetWebContents()->GetTopLevelNativeWindow())
51 ->Maximize();
52 std::unique_ptr<base::DictionaryValue> result(
53 base::MakeUnique<base::DictionaryValue>());
54 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
55 }
56 if (method == chrome::devtools::Page::minimizeWindow::kName) {
57 BrowserWindow::GetBrowserWindowForNativeWindow(
58 agent_host->GetWebContents()->GetTopLevelNativeWindow())
59 ->Minimize();
60 std::unique_ptr<base::DictionaryValue> result(
61 base::MakeUnique<base::DictionaryValue>());
62 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
63 }
64 if (method == chrome::devtools::Page::getWindowBounds::kName) {
65 BrowserWindow* window = BrowserWindow::GetBrowserWindowForNativeWindow(
66 agent_host->GetWebContents()->GetTopLevelNativeWindow());
67 gfx::Rect bounds;
68 if (window->IsMinimized())
69 bounds = window->GetRestoredBounds();
70 else
71 bounds = window->GetBounds();
72 std::unique_ptr<base::DictionaryValue> result(
73 base::MakeUnique<base::DictionaryValue>());
74 result->SetInteger("left", bounds.x());
75 result->SetInteger("top", bounds.y());
76 result->SetInteger("width", bounds.width());
77 result->SetInteger("height", bounds.height());
78 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
79 }
80 if (method == chrome::devtools::Page::setWindowBounds::kName) {
81 BrowserWindow* window = BrowserWindow::GetBrowserWindowForNativeWindow(
82 agent_host->GetWebContents()->GetTopLevelNativeWindow());
83 gfx::Rect bounds;
84 if (window->IsMinimized())
85 bounds = window->GetRestoredBounds();
86 else
87 bounds = window->GetBounds();
88
89 namespace names = chrome::devtools::Page::setWindowBounds;
90 int left, top, width, height;
91 bool set_bounds = false;
92 // Any part of the bounds can optionally be set by the caller.
93 if (params && params->GetInteger(names::kParamLeft, &left)) {
94 bounds.set_x(left);
95 set_bounds = true;
96 }
97 if (params && params->GetInteger(names::kParamTop, &top)) {
98 bounds.set_y(top);
99 set_bounds = true;
100 }
101 if (params && params->GetInteger(names::kParamWidth, &width)) {
102 bounds.set_width(width);
103 set_bounds = true;
104 }
105 if (params && params->GetInteger(names::kParamHeight, &height)) {
106 bounds.set_height(height);
107 set_bounds = true;
108 }
109
110 if (set_bounds)
111 window->SetBounds(bounds);
112 std::unique_ptr<base::DictionaryValue> result(
113 base::MakeUnique<base::DictionaryValue>());
114 return DevToolsProtocol::CreateSuccessResponse(id, std::move(result));
115 }
116 return nullptr;
117 }
118
41 class ChromeDevToolsManagerDelegate::HostData { 119 class ChromeDevToolsManagerDelegate::HostData {
42 public: 120 public:
43 HostData() {} 121 HostData() {}
44 ~HostData() {} 122 ~HostData() {}
45 123
46 RemoteLocations& remote_locations() { return remote_locations_; } 124 RemoteLocations& remote_locations() { return remote_locations_; }
47 125
48 void set_remote_locations(RemoteLocations& locations) { 126 void set_remote_locations(RemoteLocations& locations) {
49 remote_locations_.swap(locations); 127 remote_locations_.swap(locations);
50 } 128 }
(...skipping 19 matching lines...) Expand all
70 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( 148 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand(
71 DevToolsAgentHost* agent_host, 149 DevToolsAgentHost* agent_host,
72 base::DictionaryValue* command_dict) { 150 base::DictionaryValue* command_dict) {
73 151
74 int id = 0; 152 int id = 0;
75 std::string method; 153 std::string method;
76 base::DictionaryValue* params = nullptr; 154 base::DictionaryValue* params = nullptr;
77 if (!DevToolsProtocol::ParseCommand(command_dict, &id, &method, &params)) 155 if (!DevToolsProtocol::ParseCommand(command_dict, &id, &method, &params))
78 return nullptr; 156 return nullptr;
79 157
158 using stringUtil = ::ui::devtools::protocol::StringUtil;
159 size_t dotIndex = stringUtil::find(method, ".");
160 if (dotIndex == stringUtil::kNotFound)
161 return nullptr;
162 std::string domain = stringUtil::substring(method, 0, dotIndex);
163 if (domain == chrome::devtools::Page::kName)
164 return HandlePageCommand(agent_host, id, method, params).release();
165
80 if (method == chrome::devtools::Target::setRemoteLocations::kName) 166 if (method == chrome::devtools::Target::setRemoteLocations::kName)
81 return SetRemoteLocations(agent_host, id, params).release(); 167 return SetRemoteLocations(agent_host, id, params).release();
82 168
83 return network_protocol_handler_->HandleCommand(agent_host, command_dict); 169 return network_protocol_handler_->HandleCommand(agent_host, command_dict);
84 } 170 }
85 171
86 std::string ChromeDevToolsManagerDelegate::GetTargetType( 172 std::string ChromeDevToolsManagerDelegate::GetTargetType(
87 content::RenderFrameHost* host) { 173 content::RenderFrameHost* host) {
88 content::WebContents* web_contents = 174 content::WebContents* web_contents =
89 content::WebContents::FromRenderFrameHost(host); 175 content::WebContents::FromRenderFrameHost(host);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 tcp_locations.insert(net::HostPortPair(host, port)); 359 tcp_locations.insert(net::HostPortPair(host, port));
274 } 360 }
275 361
276 host_data_[agent_host]->set_remote_locations(tcp_locations); 362 host_data_[agent_host]->set_remote_locations(tcp_locations);
277 UpdateDeviceDiscovery(); 363 UpdateDeviceDiscovery();
278 364
279 std::unique_ptr<base::DictionaryValue> result( 365 std::unique_ptr<base::DictionaryValue> result(
280 base::MakeUnique<base::DictionaryValue>()); 366 base::MakeUnique<base::DictionaryValue>());
281 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result)); 367 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result));
282 } 368 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/browser_window.h » ('j') | content/browser/devtools/protocol/page_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698