| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/android/dev_tools_discovery_provider_android.h" | 5 #include "chrome/browser/android/dev_tools_discovery_provider_android.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/android/tab_android.h" | 13 #include "chrome/browser/android/tab_android.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 15 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 16 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 16 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 17 #include "components/devtools_discovery/basic_target_descriptor.h" | |
| 18 #include "components/devtools_discovery/devtools_discovery_manager.h" | 17 #include "components/devtools_discovery/devtools_discovery_manager.h" |
| 19 #include "content/public/browser/devtools_agent_host.h" | 18 #include "content/public/browser/devtools_agent_host.h" |
| 20 #include "content/public/browser/devtools_agent_host_client.h" | 19 #include "content/public/browser/devtools_agent_host_client.h" |
| 21 #include "content/public/browser/devtools_external_agent_proxy.h" | 20 #include "content/public/browser/devtools_external_agent_proxy.h" |
| 22 #include "content/public/browser/devtools_external_agent_proxy_delegate.h" | 21 #include "content/public/browser/devtools_external_agent_proxy_delegate.h" |
| 23 #include "content/public/browser/favicon_status.h" | 22 #include "content/public/browser/favicon_status.h" |
| 24 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
| 25 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 26 | 25 |
| 27 using content::DevToolsAgentHost; | 26 using content::DevToolsAgentHost; |
| 28 using content::WebContents; | 27 using content::WebContents; |
| 29 using devtools_discovery::DevToolsTargetDescriptor; | |
| 30 | 28 |
| 31 namespace { | 29 namespace { |
| 32 | 30 |
| 33 class TabProxyDelegate : public content::DevToolsExternalAgentProxyDelegate, | 31 class TabProxyDelegate : public content::DevToolsExternalAgentProxyDelegate, |
| 34 public content::DevToolsAgentHostClient { | 32 public content::DevToolsAgentHostClient { |
| 35 public: | 33 public: |
| 36 explicit TabProxyDelegate(TabAndroid* tab) | 34 explicit TabProxyDelegate(TabAndroid* tab) |
| 37 : tab_id_(tab->GetAndroidId()), | 35 : tab_id_(tab->GetAndroidId()), |
| 38 title_(base::UTF16ToUTF8(tab->GetTitle())), | 36 title_(base::UTF16ToUTF8(tab->GetTitle())), |
| 39 url_(tab->GetURL()), | 37 url_(tab->GetURL()), |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 155 } |
| 158 | 156 |
| 159 const int tab_id_; | 157 const int tab_id_; |
| 160 const std::string title_; | 158 const std::string title_; |
| 161 const GURL url_; | 159 const GURL url_; |
| 162 scoped_refptr<content::DevToolsAgentHost> agent_host_; | 160 scoped_refptr<content::DevToolsAgentHost> agent_host_; |
| 163 content::DevToolsExternalAgentProxy* proxy_; | 161 content::DevToolsExternalAgentProxy* proxy_; |
| 164 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate); | 162 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate); |
| 165 }; | 163 }; |
| 166 | 164 |
| 167 std::unique_ptr<devtools_discovery::DevToolsTargetDescriptor> | 165 scoped_refptr<content::DevToolsAgentHost> CreateNewAndroidTab(const GURL& url) { |
| 168 CreateNewAndroidTab(const GURL& url) { | |
| 169 if (TabModelList::empty()) | 166 if (TabModelList::empty()) |
| 170 return std::unique_ptr<devtools_discovery::DevToolsTargetDescriptor>(); | 167 return nullptr; |
| 171 | 168 |
| 172 TabModel* tab_model = TabModelList::get(0); | 169 TabModel* tab_model = TabModelList::get(0); |
| 173 if (!tab_model) | 170 if (!tab_model) |
| 174 return std::unique_ptr<devtools_discovery::DevToolsTargetDescriptor>(); | 171 return nullptr; |
| 175 | 172 |
| 176 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); | 173 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); |
| 177 if (!web_contents) | 174 if (!web_contents) |
| 178 return std::unique_ptr<devtools_discovery::DevToolsTargetDescriptor>(); | 175 return nullptr; |
| 179 | 176 |
| 180 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | 177 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
| 181 if (!tab) | 178 if (!tab) |
| 182 return std::unique_ptr<devtools_discovery::DevToolsTargetDescriptor>(); | 179 return nullptr; |
| 183 | 180 |
| 184 scoped_refptr<content::DevToolsAgentHost> host = | 181 return content::DevToolsAgentHost::Create(new TabProxyDelegate(tab)); |
| 185 DevToolsAgentHost::Create(new TabProxyDelegate(tab)); | |
| 186 return base::WrapUnique(new devtools_discovery::BasicTargetDescriptor(host)); | |
| 187 } | 182 } |
| 188 | 183 |
| 189 } // namespace | 184 } // namespace |
| 190 | 185 |
| 191 DevToolsDiscoveryProviderAndroid::DevToolsDiscoveryProviderAndroid() { | 186 DevToolsDiscoveryProviderAndroid::DevToolsDiscoveryProviderAndroid() { |
| 192 } | 187 } |
| 193 | 188 |
| 194 DevToolsDiscoveryProviderAndroid::~DevToolsDiscoveryProviderAndroid() { | 189 DevToolsDiscoveryProviderAndroid::~DevToolsDiscoveryProviderAndroid() { |
| 195 } | 190 } |
| 196 | 191 |
| 197 devtools_discovery::DevToolsTargetDescriptor::List | 192 content::DevToolsAgentHost::List |
| 198 DevToolsDiscoveryProviderAndroid::GetDescriptors() { | 193 DevToolsDiscoveryProviderAndroid::GetDescriptors() { |
| 199 devtools_discovery::DevToolsTargetDescriptor::List result; | 194 content::DevToolsAgentHost::List result; |
| 200 | 195 |
| 201 // Enumerate existing tabs, including the ones with no WebContents. | 196 // Enumerate existing tabs, including the ones with no WebContents. |
| 202 std::set<WebContents*> tab_web_contents; | 197 std::set<WebContents*> tab_web_contents; |
| 203 for (TabModelList::const_iterator iter = TabModelList::begin(); | 198 for (TabModelList::const_iterator iter = TabModelList::begin(); |
| 204 iter != TabModelList::end(); ++iter) { | 199 iter != TabModelList::end(); ++iter) { |
| 205 TabModel* model = *iter; | 200 TabModel* model = *iter; |
| 206 for (int i = 0; i < model->GetTabCount(); ++i) { | 201 for (int i = 0; i < model->GetTabCount(); ++i) { |
| 207 TabAndroid* tab = model->GetTabAt(i); | 202 TabAndroid* tab = model->GetTabAt(i); |
| 208 if (!tab) | 203 if (!tab) |
| 209 continue; | 204 continue; |
| 210 | 205 |
| 211 scoped_refptr<content::DevToolsAgentHost> host = | 206 scoped_refptr<content::DevToolsAgentHost> host = |
| 212 DevToolsAgentHost::Create(new TabProxyDelegate(tab)); | 207 DevToolsAgentHost::Create(new TabProxyDelegate(tab)); |
| 213 } | 208 } |
| 214 } | 209 } |
| 215 | 210 |
| 216 // Add descriptors for targets not associated with any tabs. | 211 // Add descriptors for targets not associated with any tabs. |
| 217 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); | 212 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); |
| 218 for (DevToolsAgentHost::List::iterator it = agents.begin(); | 213 for (DevToolsAgentHost::List::iterator it = agents.begin(); |
| 219 it != agents.end(); ++it) { | 214 it != agents.end(); ++it) { |
| 220 if (WebContents* web_contents = (*it)->GetWebContents()) { | 215 if (WebContents* web_contents = (*it)->GetWebContents()) { |
| 221 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) | 216 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) |
| 222 continue; | 217 continue; |
| 223 } | 218 } |
| 224 result.push_back(new devtools_discovery::BasicTargetDescriptor(*it)); | 219 result.push_back(*it); |
| 225 } | 220 } |
| 226 | 221 |
| 227 return result; | 222 return result; |
| 228 } | 223 } |
| 229 | 224 |
| 230 // static | 225 // static |
| 231 void DevToolsDiscoveryProviderAndroid::Install() { | 226 void DevToolsDiscoveryProviderAndroid::Install() { |
| 232 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = | 227 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = |
| 233 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); | 228 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); |
| 234 discovery_manager->AddProvider( | 229 discovery_manager->AddProvider( |
| 235 base::WrapUnique(new DevToolsDiscoveryProviderAndroid())); | 230 base::WrapUnique(new DevToolsDiscoveryProviderAndroid())); |
| 236 discovery_manager->SetCreateCallback(base::Bind(&CreateNewAndroidTab)); | 231 discovery_manager->SetCreateCallback(base::Bind(&CreateNewAndroidTab)); |
| 237 } | 232 } |
| OLD | NEW |