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/banners/app_banner_manager_desktop.h" | |
| 8 #include "chrome/browser/devtools/devtools_network_protocol_handler.h" | 9 #include "chrome/browser/devtools/devtools_network_protocol_handler.h" |
| 10 #include "chrome/browser/devtools/devtools_protocol_constants.h" | |
| 11 #include "content/public/browser/render_frame_host.h" | |
| 9 | 12 |
| 10 #if !defined(OS_ANDROID) | 13 #if !defined(OS_ANDROID) |
| 11 #include "chrome/browser/devtools/devtools_window.h" | 14 #include "chrome/browser/devtools/devtools_window.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 13 #include "content/public/browser/devtools_agent_host.h" | 16 #include "content/public/browser/devtools_agent_host.h" |
| 14 #endif // !defined(OS_ANDROID) | 17 #endif // !defined(OS_ANDROID) |
| 15 | 18 |
| 16 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() | 19 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() |
| 17 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { | 20 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { |
| 18 } | 21 } |
| 19 | 22 |
| 20 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { | 23 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { |
| 21 } | 24 } |
| 22 | 25 |
| 23 void ChromeDevToolsManagerDelegate::Inspect( | 26 void ChromeDevToolsManagerDelegate::Inspect( |
| 24 content::BrowserContext* browser_context, | 27 content::BrowserContext* browser_context, |
| 25 content::DevToolsAgentHost* agent_host) { | 28 content::DevToolsAgentHost* agent_host) { |
| 26 #if !defined(OS_ANDROID) | 29 #if !defined(OS_ANDROID) |
| 27 content::DevToolsAgentHost::Type type = agent_host->GetType(); | 30 content::DevToolsAgentHost::Type type = agent_host->GetType(); |
| 28 if (type != content::DevToolsAgentHost::TYPE_SHARED_WORKER && | 31 if (type != content::DevToolsAgentHost::TYPE_SHARED_WORKER && |
| 29 type != content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { | 32 type != content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { |
| 30 // TODO(horo): Support other types of DevToolsAgentHost when necessary. | 33 // TODO(horo): Support other types of DevToolsAgentHost when necessary. |
| 31 NOTREACHED() << "Inspect() only supports workers."; | 34 NOTREACHED() << "Inspect() only supports workers."; |
| 32 } | 35 } |
| 33 if (Profile* profile = Profile::FromBrowserContext(browser_context)) | 36 if (Profile* profile = Profile::FromBrowserContext(browser_context)) |
| 34 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); | 37 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); |
| 35 #endif // !defined(OS_ANDROID) | 38 #endif // !defined(OS_ANDROID) |
| 36 } | 39 } |
| 37 | 40 |
| 41 scoped_ptr<base::DictionaryValue> CanOpenAppBanner( | |
|
pfeldman
2016/01/14 04:43:05
I am not sure we need this. Should we make it avai
horo
2016/01/15 10:00:22
I think we should.
But AppBannerDataFetcherDesktop
| |
| 42 content::DevToolsAgentHost* agent_host, | |
| 43 int command_id, | |
| 44 base::DictionaryValue* params) { | |
| 45 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
| 46 result->SetBoolean(chrome::devtools::kResult, true); | |
| 47 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result)); | |
| 48 } | |
| 49 | |
| 50 scoped_ptr<base::DictionaryValue> OpenAppBanner( | |
| 51 content::DevToolsAgentHost* agent_host, | |
| 52 int command_id, | |
| 53 base::DictionaryValue* params) { | |
| 54 content::WebContents* web_contents = agent_host->GetWebContents(); | |
| 55 content::RenderFrameHost* frame = web_contents->GetMainFrame(); | |
| 56 banners::AppBannerManagerDesktop* manaager = | |
|
pfeldman
2016/01/14 04:43:05
manager
horo
2016/01/15 10:00:22
Done.
| |
| 57 banners::AppBannerManagerDesktop::FromWebContents(web_contents); | |
| 58 if (manaager) { | |
| 59 manaager->TriggerAppBannerFetch(frame, frame->GetLastCommittedURL(), true); | |
| 60 } | |
| 61 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
| 62 result->SetBoolean(chrome::devtools::kResult, true); | |
| 63 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result)); | |
| 64 } | |
| 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 base::DictionaryValue* ret = |
| 70 network_protocol_handler_->HandleCommand(agent_host, command_dict); | |
| 71 if (ret) | |
| 72 return ret; | |
| 73 { | |
|
pfeldman
2016/01/14 04:43:05
why new scope?
horo
2016/01/15 10:00:22
Removed.
Sorry this was still a WIP patch.
| |
| 74 int id = 0; | |
|
pfeldman
2016/01/14 04:43:05
This already has happened in the network handler.
horo
2016/01/15 10:00:22
Done.
| |
| 75 std::string method; | |
| 76 base::DictionaryValue* params = nullptr; | |
| 77 if (!DevToolsProtocol::ParseCommand(command_dict, &id, &method, ¶ms)) | |
| 78 return nullptr; | |
| 79 namespace page = ::chrome::devtools::Page; | |
| 80 if (method == page::canOpenAppBanner::kName) | |
| 81 return CanOpenAppBanner(agent_host, id, params).release(); | |
| 82 if (method == page::openAppBanner::kName) | |
| 83 return OpenAppBanner(agent_host, id, params).release(); | |
| 84 } | |
| 85 return nullptr; | |
| 42 } | 86 } |
| 43 | 87 |
| 44 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( | 88 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( |
| 45 content::DevToolsAgentHost* agent_host, | 89 content::DevToolsAgentHost* agent_host, |
| 46 bool attached) { | 90 bool attached) { |
| 47 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); | 91 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); |
| 48 } | 92 } |
| OLD | NEW |