Index: chrome/browser/devtools/chrome_devtools_manager_delegate.cc |
diff --git a/chrome/browser/devtools/chrome_devtools_manager_delegate.cc b/chrome/browser/devtools/chrome_devtools_manager_delegate.cc |
index 101d544a6be728d7695c7639e35c8e0173ba8192..e54c269ae5eda1eb4dc044a169b5ecf9207f15eb 100644 |
--- a/chrome/browser/devtools/chrome_devtools_manager_delegate.cc |
+++ b/chrome/browser/devtools/chrome_devtools_manager_delegate.cc |
@@ -17,7 +17,10 @@ |
#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/browser/ui/browser_navigator.h" |
#include "chrome/browser/ui/browser_navigator_params.h" |
+#include "chrome/browser/ui/browser_window.h" |
+#include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
#include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/grit/browser_resources.h" |
#include "components/guest_view/browser/guest_view_base.h" |
#include "content/public/browser/devtools_agent_host.h" |
@@ -38,6 +41,160 @@ char kLocationsParam[] = "locations"; |
char kHostParam[] = "host"; |
char kPortParam[] = "port"; |
+BrowserWindow* GetBrowserWindow(int window_id) { |
+ for (auto* b : *BrowserList::GetInstance()) { |
+ if (b->session_id().id() == window_id) |
+ return b->window(); |
+ } |
+ return nullptr; |
+} |
+ |
+std::unique_ptr<base::DictionaryValue> HandleUICommand( |
pfeldman
2017/03/21 17:36:02
dgozman: is this time to instantiate inspector_pro
jzfeng
2017/03/22 06:56:09
Done.
|
+ content::DevToolsAgentHost* agent_host, |
+ int id, |
+ std::string method, |
+ base::DictionaryValue* params) { |
+ if (method == chrome::devtools::UI::getWindowFromTarget::kName) { |
+ std::string target_id; |
+ if (!params->GetString("targetId", &target_id)) |
+ return DevToolsProtocol::CreateInvalidParamsResponse(id, "targetId"); |
+ |
+ Browser* browser = nullptr; |
+ scoped_refptr<DevToolsAgentHost> host = |
+ DevToolsAgentHost::GetForId(target_id); |
+ if (!host) |
+ return DevToolsProtocol::CreateErrorResponse(id, |
+ "No target with given id"); |
+ content::WebContents* web_contents = host->GetWebContents(); |
pfeldman
2017/03/21 17:36:02
This is nullable, no need to run getIndexOfWebCont
jzfeng
2017/03/22 06:56:09
Done.
|
+ for (auto* b : *BrowserList::GetInstance()) { |
+ int tab_index = b->tab_strip_model()->GetIndexOfWebContents(web_contents); |
+ if (tab_index != TabStripModel::kNoTab) |
+ browser = b; |
+ } |
+ if (!browser) |
+ return DevToolsProtocol::CreateErrorResponse(id, |
+ "Browser window not found"); |
+ |
+ std::unique_ptr<base::DictionaryValue> result( |
+ base::MakeUnique<base::DictionaryValue>()); |
+ result->SetInteger("windowId", browser->session_id().id()); |
+ return DevToolsProtocol::CreateSuccessResponse(id, std::move(result)); |
+ } |
+ |
+ if (method == chrome::devtools::UI::maximizeWindow::kName) { |
+ int window_id; |
+ if (!params->GetInteger("windowId", &window_id)) |
+ return DevToolsProtocol::CreateInvalidParamsResponse(id, "windowId"); |
+ BrowserWindow* window = GetBrowserWindow(window_id); |
+ if (!window) |
+ return DevToolsProtocol::CreateErrorResponse(id, |
+ "browser window not found"); |
+ window->Maximize(); |
+ std::unique_ptr<base::DictionaryValue> result( |
+ base::MakeUnique<base::DictionaryValue>()); |
+ return DevToolsProtocol::CreateSuccessResponse(id, std::move(result)); |
+ } |
+ if (method == chrome::devtools::UI::minimizeWindow::kName) { |
+ int window_id; |
+ if (!params->GetInteger("windowId", &window_id)) |
+ return DevToolsProtocol::CreateInvalidParamsResponse(id, "windowId"); |
+ BrowserWindow* window = GetBrowserWindow(window_id); |
+ if (!window) |
+ return DevToolsProtocol::CreateErrorResponse(id, |
+ "browser window not found"); |
+ window->Minimize(); |
+ std::unique_ptr<base::DictionaryValue> result( |
+ base::MakeUnique<base::DictionaryValue>()); |
+ return DevToolsProtocol::CreateSuccessResponse(id, std::move(result)); |
+ } |
+ if (method == chrome::devtools::UI::getWindowBounds::kName) { |
+ int window_id; |
+ if (!params->GetInteger("windowId", &window_id)) |
+ return DevToolsProtocol::CreateInvalidParamsResponse(id, "windowId"); |
+ BrowserWindow* window = GetBrowserWindow(window_id); |
+ if (!window) |
+ return DevToolsProtocol::CreateErrorResponse(id, |
+ "browser window not found"); |
+ gfx::Rect bounds; |
+ if (window->IsMinimized()) |
+ bounds = window->GetRestoredBounds(); |
+ else |
+ bounds = window->GetBounds(); |
+ std::unique_ptr<base::DictionaryValue> result( |
+ base::MakeUnique<base::DictionaryValue>()); |
+ result->SetInteger("left", bounds.x()); |
+ result->SetInteger("top", bounds.y()); |
+ result->SetInteger("width", bounds.width()); |
+ result->SetInteger("height", bounds.height()); |
+ return DevToolsProtocol::CreateSuccessResponse(id, std::move(result)); |
+ } |
+ if (method == chrome::devtools::UI::setWindowBounds::kName) { |
+ int window_id; |
+ if (!params->GetInteger("windowId", &window_id)) |
+ return DevToolsProtocol::CreateInvalidParamsResponse(id, "windowId"); |
+ BrowserWindow* window = GetBrowserWindow(window_id); |
+ if (!window) |
+ return DevToolsProtocol::CreateErrorResponse(id, |
+ "browser window not found"); |
+ gfx::Rect bounds; |
+ if (window->IsMinimized()) |
+ bounds = window->GetRestoredBounds(); |
+ else |
+ bounds = window->GetBounds(); |
+ |
+ int left, top, width, height; |
+ bool set_bounds = false; |
+ // Any part of the bounds can optionally be set by the caller. |
+ if (params->GetInteger("left", &left)) { |
+ bounds.set_x(left); |
+ set_bounds = true; |
+ } |
+ if (params->GetInteger("top", &top)) { |
+ bounds.set_y(top); |
+ set_bounds = true; |
+ } |
+ if (params->GetInteger("width", &width)) { |
+ if (width < 0) |
+ return DevToolsProtocol::CreateInvalidParamsResponse(id, "width"); |
+ bounds.set_width(width); |
+ set_bounds = true; |
+ } |
+ if (params->GetInteger("height", &height)) { |
+ if (height < 0) |
+ return DevToolsProtocol::CreateInvalidParamsResponse(id, "height"); |
+ bounds.set_height(height); |
+ set_bounds = true; |
+ } |
+ |
+ if (set_bounds) |
+ window->SetBounds(bounds); |
+ std::unique_ptr<base::DictionaryValue> result( |
+ base::MakeUnique<base::DictionaryValue>()); |
+ return DevToolsProtocol::CreateSuccessResponse(id, std::move(result)); |
+ } |
+ if (method == chrome::devtools::UI::setWindowFullscreen::kName) { |
+ int window_id; |
+ if (!params->GetInteger("windowId", &window_id)) |
+ return DevToolsProtocol::CreateInvalidParamsResponse(id, "windowId"); |
+ BrowserWindow* window = GetBrowserWindow(window_id); |
+ if (!window) |
+ return DevToolsProtocol::CreateErrorResponse(id, |
+ "browser window not found"); |
+ bool fullscreen = false; |
+ if (!params->GetBoolean("fullscreen", &fullscreen)) |
+ return DevToolsProtocol::CreateInvalidParamsResponse(id, "fullscreen"); |
+ auto* context = window->GetExclusiveAccessContext(); |
+ if (fullscreen) |
+ context->EnterFullscreen(GURL(), EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE); |
+ else |
+ context->ExitFullscreen(); |
+ std::unique_ptr<base::DictionaryValue> result( |
+ base::MakeUnique<base::DictionaryValue>()); |
+ return DevToolsProtocol::CreateSuccessResponse(id, std::move(result)); |
+ } |
+ return nullptr; |
+} |
+ |
class ChromeDevToolsManagerDelegate::HostData { |
public: |
HostData() {} |
@@ -77,6 +234,9 @@ base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( |
if (!DevToolsProtocol::ParseCommand(command_dict, &id, &method, ¶ms)) |
return nullptr; |
+ if (method.find("UI.") == 0) |
+ return HandleUICommand(agent_host, id, method, params).release(); |
+ |
if (method == chrome::devtools::Target::setRemoteLocations::kName) |
return SetRemoteLocations(agent_host, id, params).release(); |