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; |
| 70 std::string method; |
| 71 base::DictionaryValue* params = nullptr; |
| 72 |
| 73 if (!DevToolsProtocol::ParseCommand(command_dict, &id, &method, ¶ms)) |
| 74 return nullptr; |
| 75 |
| 76 if (base::DictionaryValue* ret = network_protocol_handler_->HandleCommand( |
| 77 agent_host, id, method, params)) { |
| 78 return ret; |
| 79 } |
| 80 |
| 81 if (method == ::chrome::devtools::Page::requestAppBanner::kName) |
| 82 return RequestAppBanner(agent_host, id, params).release(); |
| 83 return nullptr; |
42 } | 84 } |
43 | 85 |
44 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( | 86 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( |
45 content::DevToolsAgentHost* agent_host, | 87 content::DevToolsAgentHost* agent_host, |
46 bool attached) { | 88 bool attached) { |
47 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); | 89 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); |
48 } | 90 } |
OLD | NEW |