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 "components/devtools_discovery/devtools_discovery_manager.h" | 9 #include "components/devtools_discovery/devtools_discovery_manager.h" |
| 10 #include "content/public/browser/devtools_agent_host.h" | |
| 11 #include "content/public/browser/web_contents.h" | |
| 10 | 12 |
| 11 #if !defined(OS_ANDROID) | 13 #if !defined(OS_ANDROID) |
| 12 #include "chrome/browser/devtools/devtools_window.h" | 14 #include "chrome/browser/devtools/devtools_window.h" |
| 15 #include "chrome/browser/extensions/extension_tab_util.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 14 #include "content/public/browser/devtools_agent_host.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 18 #include "content/public/browser/render_frame_host.h" | |
| 19 #include "extensions/browser/extension_host.h" | |
| 20 #include "extensions/browser/extension_registry.h" | |
| 21 #include "extensions/browser/process_manager.h" | |
| 22 #else // !defined(OS_ANDROID) | |
| 23 #include "chrome/browser/android/tab_android.h" | |
| 24 #include "chrome/browser/ui/android/tab_model/tab_model.h" | |
| 25 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | |
| 15 #endif // !defined(OS_ANDROID) | 26 #endif // !defined(OS_ANDROID) |
| 16 | 27 |
| 17 using devtools_discovery::DevToolsDiscoveryManager; | 28 using devtools_discovery::DevToolsDiscoveryManager; |
| 18 | 29 |
| 30 char ChromeDevToolsManagerDelegate::kTypeApp[] = "app"; | |
| 31 char ChromeDevToolsManagerDelegate::kTypeBackgroundPage[] = "background_page"; | |
| 32 | |
| 19 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() | 33 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() |
| 20 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { | 34 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { |
| 21 } | 35 } |
| 22 | 36 |
| 23 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { | 37 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { |
| 24 } | 38 } |
| 25 | 39 |
| 26 void ChromeDevToolsManagerDelegate::Inspect( | 40 void ChromeDevToolsManagerDelegate::Inspect( |
| 27 content::BrowserContext* browser_context, | |
| 28 content::DevToolsAgentHost* agent_host) { | 41 content::DevToolsAgentHost* agent_host) { |
| 29 #if !defined(OS_ANDROID) | 42 #if !defined(OS_ANDROID) |
| 30 Profile* profile = Profile::FromBrowserContext(browser_context); | 43 Profile* profile = |
| 44 Profile::FromBrowserContext(agent_host->GetBrowserContext()); | |
| 31 if (!profile) | 45 if (!profile) |
| 32 return; | 46 return; |
| 33 content::DevToolsAgentHost::Type type = agent_host->GetType(); | 47 std::string type = agent_host->GetType(); |
| 34 if (type == content::DevToolsAgentHost::TYPE_SHARED_WORKER || | 48 if (type == content::DevToolsAgentHost::kTypeSharedWorker || |
| 35 type == content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { | 49 type == content::DevToolsAgentHost::kTypeServiceWorker) { |
| 36 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); | 50 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); |
| 37 return; | 51 return; |
| 38 } | 52 } |
| 39 if (type == content::DevToolsAgentHost::TYPE_WEB_CONTENTS) { | 53 content::WebContents* web_contents = agent_host->GetWebContents(); |
| 40 content::WebContents* web_contents = agent_host->GetWebContents(); | 54 if (web_contents) |
| 41 DCHECK(web_contents); | |
| 42 DevToolsWindow::OpenDevToolsWindow(web_contents); | 55 DevToolsWindow::OpenDevToolsWindow(web_contents); |
| 43 } | |
| 44 #endif // !defined(OS_ANDROID) | 56 #endif // !defined(OS_ANDROID) |
| 45 } | 57 } |
| 46 | 58 |
| 47 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( | 59 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( |
| 48 content::DevToolsAgentHost* agent_host, | 60 content::DevToolsAgentHost* agent_host, |
| 49 base::DictionaryValue* command_dict) { | 61 base::DictionaryValue* command_dict) { |
| 50 std::unique_ptr<base::DictionaryValue> result = | 62 std::unique_ptr<base::DictionaryValue> result = |
| 51 DevToolsDiscoveryManager::GetInstance()->HandleCreateTargetCommand( | 63 DevToolsDiscoveryManager::GetInstance()->HandleCreateTargetCommand( |
| 52 command_dict); | 64 command_dict); |
| 53 if (result) | 65 if (result) |
| 54 return result.release(); // Caller takes ownership. | 66 return result.release(); // Caller takes ownership. |
| 55 return network_protocol_handler_->HandleCommand(agent_host, command_dict); | 67 return network_protocol_handler_->HandleCommand(agent_host, command_dict); |
| 56 } | 68 } |
| 57 | 69 |
| 70 std::string ChromeDevToolsManagerDelegate::GetTargetType( | |
| 71 content::RenderFrameHost* host) { | |
| 72 content::WebContents* web_contents = | |
| 73 content::WebContents::FromRenderFrameHost(host); | |
| 74 #if !defined(OS_ANDROID) | |
| 75 for (TabContentsIterator it; !it.done(); it.Next()) { | |
| 76 if (*it == web_contents) | |
| 77 return content::DevToolsAgentHost::kTypePage; | |
| 78 } | |
| 79 | |
| 80 if (host->GetParent()) | |
| 81 return content::DevToolsAgentHost::kTypeFrame; | |
| 82 | |
| 83 const extensions::Extension* extension = extensions::ExtensionRegistry::Get( | |
| 84 web_contents->GetBrowserContext())->enabled_extensions().GetByID( | |
| 85 host->GetLastCommittedURL().host()); | |
| 86 if (!extension) | |
| 87 return content::DevToolsAgentHost::kTypeOther; | |
| 88 | |
| 89 Profile* profile = | |
| 90 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 91 if (!profile) | |
| 92 return content::DevToolsAgentHost::kTypeOther; | |
| 93 | |
| 94 extensions::ExtensionHost* extension_host = | |
| 95 extensions::ProcessManager::Get(profile) | |
| 96 ->GetBackgroundHostForExtension(extension->id()); | |
| 97 if (extension_host && | |
| 98 extension_host->host_contents() == web_contents) { | |
| 99 return kTypeBackgroundPage; | |
| 100 } else if (extension->is_hosted_app() | |
| 101 || extension->is_legacy_packaged_app() | |
| 102 || extension->is_platform_app()) { | |
| 103 return kTypeApp; | |
| 104 } | |
| 105 #else // !defined(OS_ANDROID) | |
| 106 for (TabModelList::const_iterator iter = TabModelList::begin(); | |
|
dgozman
2016/08/23 23:48:31
style: extra 2 spaces indent
| |
| 107 iter != TabModelList::end(); ++iter) { | |
|
dgozman
2016/08/23 23:48:31
style: should be 4 spaces indent
| |
| 108 TabModel* model = *iter; | |
| 109 for (int i = 0; i < model->GetTabCount(); ++i) { | |
| 110 TabAndroid* tab = model->GetTabAt(i); | |
| 111 if (tab && web_contents == tab->web_contents()) | |
| 112 return content::DevToolsAgentHost::kTypePage; | |
| 113 } | |
| 114 } | |
| 115 #endif // !defined(OS_ANDROID) | |
| 116 return content::DevToolsAgentHost::kTypeOther; | |
| 117 } | |
| 118 | |
| 58 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( | 119 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( |
| 59 content::DevToolsAgentHost* agent_host, | 120 content::DevToolsAgentHost* agent_host, |
| 60 bool attached) { | 121 bool attached) { |
| 61 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); | 122 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); |
| 62 } | 123 } |
| OLD | NEW |