Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "chrome/browser/devtools/devtools_network_protocol_handler.h" | 8 #include "chrome/browser/devtools/devtools_network_protocol_handler.h" |
| 9 #include "chrome/browser/devtools/devtools_protocol_constants.h" | |
| 10 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | |
| 11 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" | |
| 12 #include "chrome/common/chrome_switches.h" | |
| 13 #include "content/public/browser/devtools_agent_host.h" | |
| 14 #include "content/public/browser/render_frame_host.h" | |
| 9 | 15 |
| 10 #if !defined(OS_ANDROID) | 16 #if !defined(OS_ANDROID) |
| 11 #include "chrome/browser/devtools/devtools_window.h" | 17 #include "chrome/browser/devtools/devtools_window.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 13 #include "content/public/browser/devtools_agent_host.h" | |
| 14 #endif // !defined(OS_ANDROID) | 19 #endif // !defined(OS_ANDROID) |
| 15 | 20 |
| 21 namespace { | |
| 22 | |
| 23 scoped_ptr<base::DictionaryValue> RequestAppBanner( | |
| 24 content::DevToolsAgentHost* agent_host, | |
| 25 int command_id, | |
| 26 base::DictionaryValue* params) { | |
| 27 content::WebContents* web_contents = agent_host->GetWebContents(); | |
| 28 const bool ret = CoreTabHelper::FromWebContents(web_contents) | |
| 29 ->delegate() | |
| 30 ->RequestAppBanner(web_contents); | |
| 31 if (!ret) { | |
| 32 web_contents->GetMainFrame()->AddMessageToConsole( | |
| 33 content::CONSOLE_MESSAGE_LEVEL_DEBUG, | |
| 34 "App banners are currently disabled. Please check chrome://flags/#" + | |
| 35 std::string(switches::kEnableAddToShelf)); | |
| 36 } | |
| 37 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
| 38 result->SetBoolean(chrome::devtools::kResult, ret); | |
| 39 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result)); | |
| 40 } | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 16 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() | 44 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() |
| 17 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { | 45 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { |
| 18 } | 46 } |
| 19 | 47 |
| 20 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { | 48 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { |
| 21 } | 49 } |
| 22 | 50 |
| 23 void ChromeDevToolsManagerDelegate::Inspect( | 51 void ChromeDevToolsManagerDelegate::Inspect( |
| 24 content::BrowserContext* browser_context, | 52 content::BrowserContext* browser_context, |
| 25 content::DevToolsAgentHost* agent_host) { | 53 content::DevToolsAgentHost* agent_host) { |
| 26 #if !defined(OS_ANDROID) | 54 #if !defined(OS_ANDROID) |
| 27 content::DevToolsAgentHost::Type type = agent_host->GetType(); | 55 content::DevToolsAgentHost::Type type = agent_host->GetType(); |
| 28 if (type != content::DevToolsAgentHost::TYPE_SHARED_WORKER && | 56 if (type != content::DevToolsAgentHost::TYPE_SHARED_WORKER && |
| 29 type != content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { | 57 type != content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { |
| 30 // TODO(horo): Support other types of DevToolsAgentHost when necessary. | 58 // TODO(horo): Support other types of DevToolsAgentHost when necessary. |
| 31 NOTREACHED() << "Inspect() only supports workers."; | 59 NOTREACHED() << "Inspect() only supports workers."; |
| 32 } | 60 } |
| 33 if (Profile* profile = Profile::FromBrowserContext(browser_context)) | 61 if (Profile* profile = Profile::FromBrowserContext(browser_context)) |
| 34 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); | 62 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); |
| 35 #endif // !defined(OS_ANDROID) | 63 #endif // !defined(OS_ANDROID) |
| 36 } | 64 } |
| 37 | 65 |
| 38 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( | 66 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( |
| 39 content::DevToolsAgentHost* agent_host, | 67 content::DevToolsAgentHost* agent_host, |
| 40 base::DictionaryValue* command_dict) { | 68 base::DictionaryValue* command_dict) { |
| 41 return network_protocol_handler_->HandleCommand(agent_host, command_dict); | 69 int id = 0; |
|
gone
2016/01/19 18:35:00
nit: Can you break this up with newlines? It's ha
horo
2016/01/20 02:26:34
Done.
| |
| 70 std::string method; | |
| 71 base::DictionaryValue* params = nullptr; | |
| 72 if (!DevToolsProtocol::ParseCommand(command_dict, &id, &method, ¶ms)) | |
| 73 return nullptr; | |
| 74 base::DictionaryValue* ret = | |
| 75 network_protocol_handler_->HandleCommand(agent_host, id, method, params); | |
| 76 if (ret) | |
| 77 return ret; | |
| 78 if (method == ::chrome::devtools::Page::requestAppBanner::kName) | |
| 79 return RequestAppBanner(agent_host, id, params).release(); | |
| 80 return nullptr; | |
| 42 } | 81 } |
| 43 | 82 |
| 44 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( | 83 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( |
| 45 content::DevToolsAgentHost* agent_host, | 84 content::DevToolsAgentHost* agent_host, |
| 46 bool attached) { | 85 bool attached) { |
| 47 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); | 86 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); |
| 48 } | 87 } |
| OLD | NEW |