Chromium Code Reviews| 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 scoped_refptr<DevToolsAgentHost> DevToolsAgentHostForTab(TabAndroid* tab) { | |
| 163 scoped_refptr<DevToolsAgentHost> result = tab->GetDevToolsAgentHost(); | |
| 164 if (result) | |
| 165 return result; | |
| 166 | |
| 167 result = | |
| 168 DevToolsAgentHost::Forward(base::IntToString(tab->GetAndroidId()), | |
| 169 base::WrapUnique(new TabProxyDelegate(tab))); | |
|
Bernhard Bauer
2017/04/24 12:16:57
Use base::MakeUnique<>?
| |
| 170 tab->SetDevToolsAgentHost(result); | |
| 171 return result; | |
| 172 } | |
| 173 | |
| 162 } // namespace | 174 } // namespace |
| 163 | 175 |
| 164 DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid() | 176 DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid() |
| 165 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { | 177 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { |
| 166 content::DevToolsAgentHost::AddObserver(this); | 178 content::DevToolsAgentHost::AddObserver(this); |
| 167 } | 179 } |
| 168 | 180 |
| 169 DevToolsManagerDelegateAndroid::~DevToolsManagerDelegateAndroid() { | 181 DevToolsManagerDelegateAndroid::~DevToolsManagerDelegateAndroid() { |
| 170 content::DevToolsAgentHost::RemoveObserver(this); | 182 content::DevToolsAgentHost::RemoveObserver(this); |
| 171 } | 183 } |
| 172 | 184 |
| 173 base::DictionaryValue* DevToolsManagerDelegateAndroid::HandleCommand( | 185 base::DictionaryValue* DevToolsManagerDelegateAndroid::HandleCommand( |
| 174 DevToolsAgentHost* agent_host, | 186 DevToolsAgentHost* agent_host, |
| 175 base::DictionaryValue* command_dict) { | 187 base::DictionaryValue* command_dict) { |
| 176 return network_protocol_handler_->HandleCommand(agent_host, command_dict); | 188 return network_protocol_handler_->HandleCommand(agent_host, command_dict); |
| 177 } | 189 } |
| 178 | 190 |
| 179 std::string DevToolsManagerDelegateAndroid::GetTargetType( | 191 std::string DevToolsManagerDelegateAndroid::GetTargetType( |
| 180 content::RenderFrameHost* host) { | 192 content::RenderFrameHost* host) { |
| 181 content::WebContents* web_contents = | 193 content::WebContents* web_contents = |
| 182 content::WebContents::FromRenderFrameHost(host); | 194 content::WebContents::FromRenderFrameHost(host); |
| 183 TabAndroid* tab = web_contents ? TabAndroid::FromWebContents(web_contents) | 195 TabAndroid* tab = web_contents ? TabAndroid::FromWebContents(web_contents) |
| 184 : nullptr; | 196 : nullptr; |
| 185 return tab ? DevToolsAgentHost::kTypePage : | 197 return tab ? DevToolsAgentHost::kTypePage : |
| 186 DevToolsAgentHost::kTypeOther; | 198 DevToolsAgentHost::kTypeOther; |
| 187 } | 199 } |
| 188 | 200 |
| 189 bool DevToolsManagerDelegateAndroid::DiscoverTargets( | 201 DevToolsAgentHost::List |
| 190 const DevToolsAgentHost::DiscoveryCallback& callback) { | 202 DevToolsManagerDelegateAndroid::RemoteDebuggingTargets() { |
| 191 #if defined(OS_ANDROID) | |
| 192 // Enumerate existing tabs, including the ones with no WebContents. | 203 // Enumerate existing tabs, including the ones with no WebContents. |
| 193 DevToolsAgentHost::List result; | 204 DevToolsAgentHost::List result; |
| 194 std::set<WebContents*> tab_web_contents; | 205 std::set<WebContents*> tab_web_contents; |
| 195 for (TabModelList::const_iterator iter = TabModelList::begin(); | 206 for (TabModelList::const_iterator iter = TabModelList::begin(); |
| 196 iter != TabModelList::end(); ++iter) { | 207 iter != TabModelList::end(); ++iter) { |
| 197 TabModel* model = *iter; | 208 TabModel* model = *iter; |
| 198 for (int i = 0; i < model->GetTabCount(); ++i) { | 209 for (int i = 0; i < model->GetTabCount(); ++i) { |
| 199 TabAndroid* tab = model->GetTabAt(i); | 210 TabAndroid* tab = model->GetTabAt(i); |
| 200 if (!tab) | 211 if (!tab) |
| 201 continue; | 212 continue; |
| 202 | 213 |
| 203 if (tab->web_contents()) | 214 if (tab->web_contents()) |
| 204 tab_web_contents.insert(tab->web_contents()); | 215 tab_web_contents.insert(tab->web_contents()); |
| 205 | 216 result.push_back(DevToolsAgentHostForTab(tab)); |
| 206 scoped_refptr<DevToolsAgentHost> host = | |
| 207 DevToolsAgentHost::Forward( | |
| 208 base::IntToString(tab->GetAndroidId()), | |
| 209 base::WrapUnique(new TabProxyDelegate(tab))); | |
| 210 result.push_back(host); | |
| 211 } | 217 } |
| 212 } | 218 } |
| 213 | 219 |
| 214 // Add descriptors for targets not associated with any tabs. | 220 // Add descriptors for targets not associated with any tabs. |
| 215 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); | 221 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); |
| 216 for (DevToolsAgentHost::List::iterator it = agents.begin(); | 222 for (DevToolsAgentHost::List::iterator it = agents.begin(); |
| 217 it != agents.end(); ++it) { | 223 it != agents.end(); ++it) { |
| 218 if (WebContents* web_contents = (*it)->GetWebContents()) { | 224 if (WebContents* web_contents = (*it)->GetWebContents()) { |
| 219 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) | 225 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) |
| 220 continue; | 226 continue; |
| 221 } | 227 } |
| 222 result.push_back(*it); | 228 result.push_back(*it); |
| 223 } | 229 } |
| 224 | 230 |
| 225 callback.Run(std::move(result)); | 231 return result; |
| 226 return true; | |
| 227 #else | |
| 228 return false; | |
| 229 #endif // defined(OS_ANDROID) | |
| 230 } | 232 } |
| 231 | 233 |
| 232 scoped_refptr<DevToolsAgentHost> | 234 scoped_refptr<DevToolsAgentHost> |
| 233 DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) { | 235 DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) { |
| 234 if (TabModelList::empty()) | 236 if (TabModelList::empty()) |
| 235 return nullptr; | 237 return nullptr; |
| 236 | 238 |
| 237 TabModel* tab_model = TabModelList::get(0); | 239 TabModel* tab_model = TabModelList::get(0); |
| 238 if (!tab_model) | 240 if (!tab_model) |
| 239 return nullptr; | 241 return nullptr; |
| 240 | 242 |
| 241 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); | 243 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); |
| 242 if (!web_contents) | 244 if (!web_contents) |
| 243 return nullptr; | 245 return nullptr; |
| 244 | 246 |
| 245 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | 247 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
| 246 if (!tab) | 248 return tab ? DevToolsAgentHostForTab(tab) : nullptr; |
|
Bernhard Bauer
2017/04/24 12:16:57
Mini-nit: I kind of liked the old `if (tab) return
| |
| 247 return nullptr; | |
| 248 | |
| 249 return DevToolsAgentHost::Forward( | |
| 250 base::IntToString(tab->GetAndroidId()), | |
| 251 base::WrapUnique(new TabProxyDelegate(tab))); | |
| 252 } | 249 } |
| 253 | 250 |
| 254 std::string DevToolsManagerDelegateAndroid::GetDiscoveryPageHTML() { | 251 std::string DevToolsManagerDelegateAndroid::GetDiscoveryPageHTML() { |
| 255 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 252 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 256 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); | 253 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); |
| 257 } | 254 } |
| 258 | 255 |
| 259 void DevToolsManagerDelegateAndroid::DevToolsAgentHostAttached( | 256 void DevToolsManagerDelegateAndroid::DevToolsAgentHostAttached( |
| 260 content::DevToolsAgentHost* agent_host) { | 257 content::DevToolsAgentHost* agent_host) { |
| 261 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, true); | 258 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, true); |
| 262 } | 259 } |
| 263 | 260 |
| 264 void DevToolsManagerDelegateAndroid::DevToolsAgentHostDetached( | 261 void DevToolsManagerDelegateAndroid::DevToolsAgentHostDetached( |
| 265 content::DevToolsAgentHost* agent_host) { | 262 content::DevToolsAgentHost* agent_host) { |
| 266 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, false); | 263 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, false); |
| 267 } | 264 } |
| OLD | NEW |