| 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/devtools_manager_delegate_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/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 152 } |
| 153 | 153 |
| 154 const int tab_id_; | 154 const int tab_id_; |
| 155 const std::string title_; | 155 const std::string title_; |
| 156 const GURL url_; | 156 const GURL url_; |
| 157 scoped_refptr<DevToolsAgentHost> agent_host_; | 157 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 158 content::DevToolsExternalAgentProxy* proxy_; | 158 content::DevToolsExternalAgentProxy* proxy_; |
| 159 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate); | 159 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate); |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 DevToolsAgentHost::List GetDescriptors() { | |
| 163 DevToolsAgentHost::List result; | |
| 164 | |
| 165 // Enumerate existing tabs, including the ones with no WebContents. | |
| 166 std::set<WebContents*> tab_web_contents; | |
| 167 for (TabModelList::const_iterator iter = TabModelList::begin(); | |
| 168 iter != TabModelList::end(); ++iter) { | |
| 169 TabModel* model = *iter; | |
| 170 for (int i = 0; i < model->GetTabCount(); ++i) { | |
| 171 TabAndroid* tab = model->GetTabAt(i); | |
| 172 if (!tab) | |
| 173 continue; | |
| 174 | |
| 175 if (tab->web_contents()) | |
| 176 tab_web_contents.insert(tab->web_contents()); | |
| 177 | |
| 178 scoped_refptr<DevToolsAgentHost> host = | |
| 179 DevToolsAgentHost::Forward( | |
| 180 base::IntToString(tab->GetAndroidId()), | |
| 181 base::WrapUnique(new TabProxyDelegate(tab))); | |
| 182 result.push_back(host); | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 // Add descriptors for targets not associated with any tabs. | |
| 187 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); | |
| 188 for (DevToolsAgentHost::List::iterator it = agents.begin(); | |
| 189 it != agents.end(); ++it) { | |
| 190 if (WebContents* web_contents = (*it)->GetWebContents()) { | |
| 191 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) | |
| 192 continue; | |
| 193 } | |
| 194 result.push_back(*it); | |
| 195 } | |
| 196 | |
| 197 return result; | |
| 198 } | |
| 199 | |
| 200 } // namespace | 162 } // namespace |
| 201 | 163 |
| 202 DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid() | 164 DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid() |
| 203 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { | 165 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { |
| 204 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 205 DevToolsAgentHost::AddDiscoveryProvider(base::Bind(&GetDescriptors)); | |
| 206 #endif // BUILDFLAG(ANDROID_JAVA_UI) | |
| 207 } | 166 } |
| 208 | 167 |
| 209 DevToolsManagerDelegateAndroid::~DevToolsManagerDelegateAndroid() { | 168 DevToolsManagerDelegateAndroid::~DevToolsManagerDelegateAndroid() { |
| 210 } | 169 } |
| 211 | 170 |
| 212 void DevToolsManagerDelegateAndroid::Inspect( | 171 void DevToolsManagerDelegateAndroid::Inspect( |
| 213 DevToolsAgentHost* agent_host) { | 172 DevToolsAgentHost* agent_host) { |
| 214 } | 173 } |
| 215 | 174 |
| 216 base::DictionaryValue* DevToolsManagerDelegateAndroid::HandleCommand( | 175 base::DictionaryValue* DevToolsManagerDelegateAndroid::HandleCommand( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 230 } | 189 } |
| 231 | 190 |
| 232 std::string DevToolsManagerDelegateAndroid::GetTargetTitle( | 191 std::string DevToolsManagerDelegateAndroid::GetTargetTitle( |
| 233 content::RenderFrameHost* host) { | 192 content::RenderFrameHost* host) { |
| 234 content::WebContents* web_contents = | 193 content::WebContents* web_contents = |
| 235 content::WebContents::FromRenderFrameHost(host); | 194 content::WebContents::FromRenderFrameHost(host); |
| 236 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | 195 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
| 237 return tab ? base::UTF16ToUTF8(tab->GetTitle()) : ""; | 196 return tab ? base::UTF16ToUTF8(tab->GetTitle()) : ""; |
| 238 } | 197 } |
| 239 | 198 |
| 199 bool DevToolsManagerDelegateAndroid::DiscoverTargets( |
| 200 const DevToolsAgentHost::DiscoveryCallback& callback) { |
| 201 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 202 // Enumerate existing tabs, including the ones with no WebContents. |
| 203 DevToolsAgentHost::List result; |
| 204 std::set<WebContents*> tab_web_contents; |
| 205 for (TabModelList::const_iterator iter = TabModelList::begin(); |
| 206 iter != TabModelList::end(); ++iter) { |
| 207 TabModel* model = *iter; |
| 208 for (int i = 0; i < model->GetTabCount(); ++i) { |
| 209 TabAndroid* tab = model->GetTabAt(i); |
| 210 if (!tab) |
| 211 continue; |
| 212 |
| 213 if (tab->web_contents()) |
| 214 tab_web_contents.insert(tab->web_contents()); |
| 215 |
| 216 scoped_refptr<DevToolsAgentHost> host = |
| 217 DevToolsAgentHost::Forward( |
| 218 base::IntToString(tab->GetAndroidId()), |
| 219 base::WrapUnique(new TabProxyDelegate(tab))); |
| 220 result.push_back(host); |
| 221 } |
| 222 } |
| 223 |
| 224 // Add descriptors for targets not associated with any tabs. |
| 225 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); |
| 226 for (DevToolsAgentHost::List::iterator it = agents.begin(); |
| 227 it != agents.end(); ++it) { |
| 228 if (WebContents* web_contents = (*it)->GetWebContents()) { |
| 229 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) |
| 230 continue; |
| 231 } |
| 232 result.push_back(*it); |
| 233 } |
| 234 |
| 235 callback.Run(std::move(result)); |
| 236 return true; |
| 237 #else |
| 238 return false; |
| 239 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 240 } |
| 241 |
| 240 scoped_refptr<DevToolsAgentHost> | 242 scoped_refptr<DevToolsAgentHost> |
| 241 DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) { | 243 DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) { |
| 242 if (TabModelList::empty()) | 244 if (TabModelList::empty()) |
| 243 return nullptr; | 245 return nullptr; |
| 244 | 246 |
| 245 TabModel* tab_model = TabModelList::get(0); | 247 TabModel* tab_model = TabModelList::get(0); |
| 246 if (!tab_model) | 248 if (!tab_model) |
| 247 return nullptr; | 249 return nullptr; |
| 248 | 250 |
| 249 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); | 251 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 261 | 263 |
| 262 std::string DevToolsManagerDelegateAndroid::GetDiscoveryPageHTML() { | 264 std::string DevToolsManagerDelegateAndroid::GetDiscoveryPageHTML() { |
| 263 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 265 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 264 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); | 266 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); |
| 265 } | 267 } |
| 266 | 268 |
| 267 void DevToolsManagerDelegateAndroid::DevToolsAgentStateChanged( | 269 void DevToolsManagerDelegateAndroid::DevToolsAgentStateChanged( |
| 268 DevToolsAgentHost* agent_host, bool attached) { | 270 DevToolsAgentHost* agent_host, bool attached) { |
| 269 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); | 271 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); |
| 270 } | 272 } |
| OLD | NEW |