Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
|
dgozman
2016/08/27 00:49:13
Stray change?
pfeldman
2016/08/27 01:53:55
No, git picked wrong prototype.
| |
| 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/devtools_manager_delegate_android.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | |
| 13 #include "chrome/browser/android/tab_android.h" | 11 #include "chrome/browser/android/tab_android.h" |
| 14 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/devtools/devtools_network_protocol_handler.h" |
| 15 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 13 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 16 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 14 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 17 #include "components/devtools_discovery/devtools_discovery_manager.h" | 15 #include "chrome/common/features.h" |
| 18 #include "content/public/browser/devtools_agent_host.h" | 16 #include "content/public/browser/devtools_agent_host.h" |
| 19 #include "content/public/browser/devtools_agent_host_client.h" | 17 #include "content/public/browser/devtools_agent_host_client.h" |
| 20 #include "content/public/browser/devtools_external_agent_proxy.h" | 18 #include "content/public/browser/devtools_external_agent_proxy.h" |
| 21 #include "content/public/browser/devtools_external_agent_proxy_delegate.h" | 19 #include "content/public/browser/devtools_external_agent_proxy_delegate.h" |
| 22 #include "content/public/browser/favicon_status.h" | |
| 23 #include "content/public/browser/navigation_entry.h" | |
| 24 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 25 | 21 |
| 26 using content::DevToolsAgentHost; | 22 using content::DevToolsAgentHost; |
| 27 using content::WebContents; | 23 using content::WebContents; |
| 28 | 24 |
| 29 namespace { | |
|
dgozman
2016/08/27 00:49:13
Bring back the namespace!
pfeldman
2016/08/27 01:53:55
Done.
| |
| 30 | |
| 31 class TabProxyDelegate : public content::DevToolsExternalAgentProxyDelegate, | 25 class TabProxyDelegate : public content::DevToolsExternalAgentProxyDelegate, |
| 32 public content::DevToolsAgentHostClient { | 26 public content::DevToolsAgentHostClient { |
| 33 public: | 27 public: |
| 34 explicit TabProxyDelegate(TabAndroid* tab) | 28 explicit TabProxyDelegate(TabAndroid* tab) |
| 35 : tab_id_(tab->GetAndroidId()), | 29 : tab_id_(tab->GetAndroidId()), |
| 36 title_(base::UTF16ToUTF8(tab->GetTitle())), | 30 title_(base::UTF16ToUTF8(tab->GetTitle())), |
| 37 url_(tab->GetURL()), | 31 url_(tab->GetURL()), |
| 38 agent_host_(tab->web_contents() ? | 32 agent_host_(tab->web_contents() ? |
| 39 DevToolsAgentHost::GetOrCreateFor(tab->web_contents()) : nullptr) { | 33 DevToolsAgentHost::GetOrCreateFor(tab->web_contents()) : nullptr) { |
| 40 } | 34 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 return true; | 144 return true; |
| 151 } | 145 } |
| 152 } | 146 } |
| 153 } | 147 } |
| 154 return false; | 148 return false; |
| 155 } | 149 } |
| 156 | 150 |
| 157 const int tab_id_; | 151 const int tab_id_; |
| 158 const std::string title_; | 152 const std::string title_; |
| 159 const GURL url_; | 153 const GURL url_; |
| 160 scoped_refptr<content::DevToolsAgentHost> agent_host_; | 154 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 161 content::DevToolsExternalAgentProxy* proxy_; | 155 content::DevToolsExternalAgentProxy* proxy_; |
| 162 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate); | 156 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate); |
| 163 }; | 157 }; |
| 164 | 158 |
| 165 scoped_refptr<content::DevToolsAgentHost> CreateNewAndroidTab(const GURL& url) { | 159 DevToolsAgentHost::List GetDescriptors() { |
| 166 if (TabModelList::empty()) | 160 DevToolsAgentHost::List result; |
| 167 return nullptr; | |
| 168 | |
| 169 TabModel* tab_model = TabModelList::get(0); | |
| 170 if (!tab_model) | |
| 171 return nullptr; | |
| 172 | |
| 173 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); | |
| 174 if (!web_contents) | |
| 175 return nullptr; | |
| 176 | |
| 177 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | |
| 178 if (!tab) | |
| 179 return nullptr; | |
| 180 | |
| 181 return content::DevToolsAgentHost::Create(new TabProxyDelegate(tab)); | |
| 182 } | |
| 183 | |
| 184 } // namespace | |
| 185 | |
| 186 DevToolsDiscoveryProviderAndroid::DevToolsDiscoveryProviderAndroid() { | |
| 187 } | |
| 188 | |
| 189 DevToolsDiscoveryProviderAndroid::~DevToolsDiscoveryProviderAndroid() { | |
| 190 } | |
| 191 | |
| 192 content::DevToolsAgentHost::List | |
| 193 DevToolsDiscoveryProviderAndroid::GetDescriptors() { | |
| 194 content::DevToolsAgentHost::List result; | |
| 195 | 161 |
| 196 // Enumerate existing tabs, including the ones with no WebContents. | 162 // Enumerate existing tabs, including the ones with no WebContents. |
| 197 std::set<WebContents*> tab_web_contents; | 163 std::set<WebContents*> tab_web_contents; |
| 198 for (TabModelList::const_iterator iter = TabModelList::begin(); | 164 for (TabModelList::const_iterator iter = TabModelList::begin(); |
| 199 iter != TabModelList::end(); ++iter) { | 165 iter != TabModelList::end(); ++iter) { |
| 200 TabModel* model = *iter; | 166 TabModel* model = *iter; |
| 201 for (int i = 0; i < model->GetTabCount(); ++i) { | 167 for (int i = 0; i < model->GetTabCount(); ++i) { |
| 202 TabAndroid* tab = model->GetTabAt(i); | 168 TabAndroid* tab = model->GetTabAt(i); |
| 203 if (!tab) | 169 if (!tab) |
| 204 continue; | 170 continue; |
| 205 | 171 |
| 206 scoped_refptr<content::DevToolsAgentHost> host = | 172 scoped_refptr<DevToolsAgentHost> host = |
| 207 DevToolsAgentHost::Create(new TabProxyDelegate(tab)); | 173 DevToolsAgentHost::Create(new TabProxyDelegate(tab)); |
| 208 } | 174 } |
| 209 } | 175 } |
| 210 | 176 |
| 211 // Add descriptors for targets not associated with any tabs. | 177 // Add descriptors for targets not associated with any tabs. |
| 212 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); | 178 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); |
| 213 for (DevToolsAgentHost::List::iterator it = agents.begin(); | 179 for (DevToolsAgentHost::List::iterator it = agents.begin(); |
| 214 it != agents.end(); ++it) { | 180 it != agents.end(); ++it) { |
| 215 if (WebContents* web_contents = (*it)->GetWebContents()) { | 181 if (WebContents* web_contents = (*it)->GetWebContents()) { |
| 216 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) | 182 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) |
| 217 continue; | 183 continue; |
| 218 } | 184 } |
| 219 result.push_back(*it); | 185 result.push_back(*it); |
| 220 } | 186 } |
| 221 | 187 |
| 222 return result; | 188 return result; |
| 223 } | 189 } |
| 224 | 190 |
| 225 // static | 191 DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid() |
| 226 void DevToolsDiscoveryProviderAndroid::Install() { | 192 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { |
| 227 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = | 193 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 228 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); | 194 DevToolsAgentHost::AddDiscoveryProvider(base::Bind(&GetDescriptors)); |
| 229 discovery_manager->AddProvider( | 195 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 230 base::WrapUnique(new DevToolsDiscoveryProviderAndroid())); | |
| 231 discovery_manager->SetCreateCallback(base::Bind(&CreateNewAndroidTab)); | |
| 232 } | 196 } |
| 197 | |
| 198 DevToolsManagerDelegateAndroid::~DevToolsManagerDelegateAndroid() { | |
| 199 } | |
| 200 | |
| 201 void DevToolsManagerDelegateAndroid::Inspect( | |
| 202 DevToolsAgentHost* agent_host) { | |
| 203 } | |
| 204 | |
| 205 base::DictionaryValue* DevToolsManagerDelegateAndroid::HandleCommand( | |
| 206 DevToolsAgentHost* agent_host, | |
| 207 base::DictionaryValue* command_dict) { | |
| 208 return network_protocol_handler_->HandleCommand(agent_host, command_dict); | |
| 209 } | |
| 210 | |
| 211 std::string DevToolsManagerDelegateAndroid::GetTargetType( | |
| 212 content::RenderFrameHost* host) { | |
| 213 content::WebContents* web_contents = | |
| 214 content::WebContents::FromRenderFrameHost(host); | |
| 215 for (TabModelList::const_iterator iter = TabModelList::begin(); | |
| 216 iter != TabModelList::end(); ++iter) { | |
| 217 TabModel* model = *iter; | |
| 218 for (int i = 0; i < model->GetTabCount(); ++i) { | |
| 219 TabAndroid* tab = model->GetTabAt(i); | |
| 220 if (tab && web_contents == tab->web_contents()) | |
| 221 return DevToolsAgentHost::kTypePage; | |
|
dgozman
2016/08/27 00:49:13
Use TabAndroid::FromWebContents(web_contents) here
pfeldman
2016/08/27 01:53:55
What?
| |
| 222 } | |
| 223 } | |
| 224 return DevToolsAgentHost::kTypeOther; | |
| 225 } | |
| 226 | |
| 227 std::string DevToolsManagerDelegateAndroid::GetTargetTitle( | |
| 228 content::RenderFrameHost* host) { | |
| 229 content::WebContents* web_contents = | |
| 230 content::WebContents::FromRenderFrameHost(host); | |
| 231 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | |
| 232 return tab ? base::UTF16ToUTF8(tab->GetTitle()) : ""; | |
| 233 } | |
| 234 | |
| 235 scoped_refptr<DevToolsAgentHost> | |
| 236 DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) { | |
| 237 if (TabModelList::empty()) | |
| 238 return nullptr; | |
| 239 | |
| 240 TabModel* tab_model = TabModelList::get(0); | |
| 241 if (!tab_model) | |
| 242 return nullptr; | |
| 243 | |
| 244 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); | |
| 245 if (!web_contents) | |
| 246 return nullptr; | |
| 247 | |
| 248 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | |
| 249 if (!tab) | |
| 250 return nullptr; | |
| 251 | |
| 252 return DevToolsAgentHost::Create(new TabProxyDelegate(tab)); | |
| 253 } | |
| 254 | |
| 255 void DevToolsManagerDelegateAndroid::DevToolsAgentStateChanged( | |
| 256 DevToolsAgentHost* agent_host, bool attached) { | |
| 257 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); | |
| 258 } | |
| OLD | NEW |