| 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 "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/devtools/device/android_device_manager.h" | 10 #include "chrome/browser/devtools/device/android_device_manager.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "extensions/browser/extension_registry.h" | 27 #include "extensions/browser/extension_registry.h" |
| 28 #include "extensions/browser/process_manager.h" | 28 #include "extensions/browser/process_manager.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 30 | 30 |
| 31 using content::DevToolsAgentHost; | 31 using content::DevToolsAgentHost; |
| 32 | 32 |
| 33 char ChromeDevToolsManagerDelegate::kTypeApp[] = "app"; | 33 char ChromeDevToolsManagerDelegate::kTypeApp[] = "app"; |
| 34 char ChromeDevToolsManagerDelegate::kTypeBackgroundPage[] = "background_page"; | 34 char ChromeDevToolsManagerDelegate::kTypeBackgroundPage[] = "background_page"; |
| 35 char ChromeDevToolsManagerDelegate::kTypeWebView[] = "webview"; | 35 char ChromeDevToolsManagerDelegate::kTypeWebView[] = "webview"; |
| 36 | 36 |
| 37 namespace { |
| 38 |
| 37 char kLocationsParam[] = "locations"; | 39 char kLocationsParam[] = "locations"; |
| 38 char kHostParam[] = "host"; | 40 char kHostParam[] = "host"; |
| 39 char kPortParam[] = "port"; | 41 char kPortParam[] = "port"; |
| 40 | 42 |
| 43 bool GetExtensionInfo(content::RenderFrameHost* host, |
| 44 std::string* name, |
| 45 std::string* type) { |
| 46 content::WebContents* wc = content::WebContents::FromRenderFrameHost(host); |
| 47 if (!wc) |
| 48 return false; |
| 49 Profile* profile = Profile::FromBrowserContext(wc->GetBrowserContext()); |
| 50 if (!profile) |
| 51 return false; |
| 52 const extensions::Extension* extension = |
| 53 extensions::ProcessManager::Get(profile)->GetExtensionForRenderFrameHost( |
| 54 host); |
| 55 if (!extension) |
| 56 return false; |
| 57 extensions::ExtensionHost* extension_host = |
| 58 extensions::ProcessManager::Get(profile)->GetBackgroundHostForExtension( |
| 59 extension->id()); |
| 60 if (extension_host && extension_host->host_contents() == wc) { |
| 61 *name = extension->name(); |
| 62 *type = ChromeDevToolsManagerDelegate::kTypeBackgroundPage; |
| 63 return true; |
| 64 } else if (extension->is_hosted_app() || |
| 65 extension->is_legacy_packaged_app() || |
| 66 extension->is_platform_app()) { |
| 67 *name = extension->name(); |
| 68 *type = ChromeDevToolsManagerDelegate::kTypeApp; |
| 69 return true; |
| 70 } |
| 71 return false; |
| 72 } |
| 73 |
| 74 } // namespace |
| 75 |
| 41 class ChromeDevToolsManagerDelegate::HostData { | 76 class ChromeDevToolsManagerDelegate::HostData { |
| 42 public: | 77 public: |
| 43 HostData() {} | 78 HostData() {} |
| 44 ~HostData() {} | 79 ~HostData() {} |
| 45 | 80 |
| 46 RemoteLocations& remote_locations() { return remote_locations_; } | 81 RemoteLocations& remote_locations() { return remote_locations_; } |
| 47 | 82 |
| 48 void set_remote_locations(RemoteLocations& locations) { | 83 void set_remote_locations(RemoteLocations& locations) { |
| 49 remote_locations_.swap(locations); | 84 remote_locations_.swap(locations); |
| 50 } | 85 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 return kTypeWebView; | 131 return kTypeWebView; |
| 97 | 132 |
| 98 if (host->GetParent()) | 133 if (host->GetParent()) |
| 99 return DevToolsAgentHost::kTypeFrame; | 134 return DevToolsAgentHost::kTypeFrame; |
| 100 | 135 |
| 101 for (TabContentsIterator it; !it.done(); it.Next()) { | 136 for (TabContentsIterator it; !it.done(); it.Next()) { |
| 102 if (*it == web_contents) | 137 if (*it == web_contents) |
| 103 return DevToolsAgentHost::kTypePage; | 138 return DevToolsAgentHost::kTypePage; |
| 104 } | 139 } |
| 105 | 140 |
| 106 const extensions::Extension* extension = extensions::ExtensionRegistry::Get( | 141 std::string extension_name; |
| 107 web_contents->GetBrowserContext())->enabled_extensions().GetByID( | 142 std::string extension_type; |
| 108 host->GetLastCommittedURL().host()); | 143 if (!GetExtensionInfo(host, &extension_name, &extension_type)) |
| 109 if (!extension) | |
| 110 return DevToolsAgentHost::kTypeOther; | 144 return DevToolsAgentHost::kTypeOther; |
| 111 | 145 return extension_type; |
| 112 Profile* profile = | |
| 113 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 114 if (!profile) | |
| 115 return DevToolsAgentHost::kTypeOther; | |
| 116 | |
| 117 extensions::ExtensionHost* extension_host = | |
| 118 extensions::ProcessManager::Get(profile) | |
| 119 ->GetBackgroundHostForExtension(extension->id()); | |
| 120 if (extension_host && | |
| 121 extension_host->host_contents() == web_contents) { | |
| 122 return kTypeBackgroundPage; | |
| 123 } else if (extension->is_hosted_app() | |
| 124 || extension->is_legacy_packaged_app() | |
| 125 || extension->is_platform_app()) { | |
| 126 return kTypeApp; | |
| 127 } | |
| 128 return DevToolsAgentHost::kTypeOther; | |
| 129 } | 146 } |
| 130 | 147 |
| 131 std::string ChromeDevToolsManagerDelegate::GetTargetTitle( | 148 std::string ChromeDevToolsManagerDelegate::GetTargetTitle( |
| 132 content::RenderFrameHost* host) { | 149 content::RenderFrameHost* host) { |
| 133 content::WebContents* web_contents = | 150 std::string extension_name; |
| 134 content::WebContents::FromRenderFrameHost(host); | 151 std::string extension_type; |
| 135 if (host->GetParent()) | 152 if (!GetExtensionInfo(host, &extension_name, &extension_type)) |
| 136 return host->GetLastCommittedURL().spec(); | 153 return std::string(); |
| 137 for (TabContentsIterator it; !it.done(); it.Next()) { | 154 return extension_name; |
| 138 if (*it == web_contents) | |
| 139 return base::UTF16ToUTF8(web_contents->GetTitle()); | |
| 140 } | |
| 141 const extensions::Extension* extension = extensions::ExtensionRegistry::Get( | |
| 142 web_contents->GetBrowserContext())->enabled_extensions().GetByID( | |
| 143 host->GetLastCommittedURL().host()); | |
| 144 if (extension) | |
| 145 return extension->name(); | |
| 146 return ""; | |
| 147 } | 155 } |
| 148 | 156 |
| 149 scoped_refptr<DevToolsAgentHost> | 157 scoped_refptr<DevToolsAgentHost> |
| 150 ChromeDevToolsManagerDelegate::CreateNewTarget(const GURL& url) { | 158 ChromeDevToolsManagerDelegate::CreateNewTarget(const GURL& url) { |
| 151 chrome::NavigateParams params(ProfileManager::GetLastUsedProfile(), | 159 chrome::NavigateParams params(ProfileManager::GetLastUsedProfile(), |
| 152 url, ui::PAGE_TRANSITION_AUTO_TOPLEVEL); | 160 url, ui::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| 153 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | 161 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| 154 chrome::Navigate(¶ms); | 162 chrome::Navigate(¶ms); |
| 155 if (!params.target_contents) | 163 if (!params.target_contents) |
| 156 return nullptr; | 164 return nullptr; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 tcp_locations.insert(net::HostPortPair(host, port)); | 281 tcp_locations.insert(net::HostPortPair(host, port)); |
| 274 } | 282 } |
| 275 | 283 |
| 276 host_data_[agent_host]->set_remote_locations(tcp_locations); | 284 host_data_[agent_host]->set_remote_locations(tcp_locations); |
| 277 UpdateDeviceDiscovery(); | 285 UpdateDeviceDiscovery(); |
| 278 | 286 |
| 279 std::unique_ptr<base::DictionaryValue> result( | 287 std::unique_ptr<base::DictionaryValue> result( |
| 280 base::MakeUnique<base::DictionaryValue>()); | 288 base::MakeUnique<base::DictionaryValue>()); |
| 281 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result)); | 289 return DevToolsProtocol::CreateSuccessResponse(command_id, std::move(result)); |
| 282 } | 290 } |
| OLD | NEW |