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/device/devtools_android_bridge.h" | 5 #include "chrome/browser/devtools/device/devtools_android_bridge.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 content::DevToolsExternalAgentProxy* proxy_; | 304 content::DevToolsExternalAgentProxy* proxy_; |
305 DISALLOW_COPY_AND_ASSIGN(AgentHostDelegate); | 305 DISALLOW_COPY_AND_ASSIGN(AgentHostDelegate); |
306 }; | 306 }; |
307 | 307 |
308 // static | 308 // static |
309 scoped_refptr<content::DevToolsAgentHost> | 309 scoped_refptr<content::DevToolsAgentHost> |
310 AgentHostDelegate::GetOrCreateAgentHost( | 310 AgentHostDelegate::GetOrCreateAgentHost( |
311 const std::string& id, | 311 const std::string& id, |
312 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser, | 312 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser, |
313 const std::string& debug_url) { | 313 const std::string& debug_url) { |
314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
315 AgentHostDelegates::iterator it = g_host_delegates.Get().find(id); | 315 AgentHostDelegates::iterator it = g_host_delegates.Get().find(id); |
316 if (it != g_host_delegates.Get().end()) | 316 if (it != g_host_delegates.Get().end()) |
317 return it->second->agent_host_; | 317 return it->second->agent_host_; |
318 | 318 |
319 AgentHostDelegate* delegate = new AgentHostDelegate(id, browser, debug_url); | 319 AgentHostDelegate* delegate = new AgentHostDelegate(id, browser, debug_url); |
320 scoped_refptr<content::DevToolsAgentHost> result = | 320 scoped_refptr<content::DevToolsAgentHost> result = |
321 content::DevToolsAgentHost::Create(delegate); | 321 content::DevToolsAgentHost::Create(delegate); |
322 delegate->agent_host_ = result.get(); | 322 delegate->agent_host_ = result.get(); |
323 return result; | 323 return result; |
324 } | 324 } |
325 | 325 |
326 AgentHostDelegate::AgentHostDelegate( | 326 AgentHostDelegate::AgentHostDelegate( |
327 const std::string& id, | 327 const std::string& id, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 virtual void Reload() const OVERRIDE; | 408 virtual void Reload() const OVERRIDE; |
409 | 409 |
410 void Navigate(const std::string& url, base::Closure callback) const; | 410 void Navigate(const std::string& url, base::Closure callback) const; |
411 | 411 |
412 private: | 412 private: |
413 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser_; | 413 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser_; |
414 std::string debug_url_; | 414 std::string debug_url_; |
415 std::string frontend_url_; | 415 std::string frontend_url_; |
416 std::string remote_id_; | 416 std::string remote_id_; |
417 std::string remote_type_; | 417 std::string remote_type_; |
| 418 std::string local_id_; |
418 DISALLOW_COPY_AND_ASSIGN(RemotePageTarget); | 419 DISALLOW_COPY_AND_ASSIGN(RemotePageTarget); |
419 }; | 420 }; |
420 | 421 |
421 static std::string GetStringProperty(const base::DictionaryValue& value, | 422 static std::string GetStringProperty(const base::DictionaryValue& value, |
422 const std::string& name) { | 423 const std::string& name) { |
423 std::string result; | 424 std::string result; |
424 value.GetString(name, &result); | 425 value.GetString(name, &result); |
425 return result; | 426 return result; |
426 } | 427 } |
427 | 428 |
(...skipping 16 matching lines...) Expand all Loading... |
444 | 445 |
445 RemotePageTarget::RemotePageTarget( | 446 RemotePageTarget::RemotePageTarget( |
446 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser, | 447 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser, |
447 const base::DictionaryValue& value) | 448 const base::DictionaryValue& value) |
448 : DevToolsTargetImpl(AgentHostDelegate::GetOrCreateAgentHost( | 449 : DevToolsTargetImpl(AgentHostDelegate::GetOrCreateAgentHost( |
449 BuildUniqueTargetId(browser.get(), value), | 450 BuildUniqueTargetId(browser.get(), value), |
450 browser, GetDebugURL(value))), | 451 browser, GetDebugURL(value))), |
451 browser_(browser), | 452 browser_(browser), |
452 debug_url_(GetDebugURL(value)), | 453 debug_url_(GetDebugURL(value)), |
453 remote_id_(GetStringProperty(value, "id")), | 454 remote_id_(GetStringProperty(value, "id")), |
454 remote_type_(GetStringProperty(value, "type")) { | 455 remote_type_(GetStringProperty(value, "type")), |
| 456 local_id_(BuildUniqueTargetId(browser.get(), value)) { |
455 set_type("adb_page"); | 457 set_type("adb_page"); |
456 set_url(GURL(GetStringProperty(value, "url"))); | 458 set_url(GURL(GetStringProperty(value, "url"))); |
457 set_title(base::UTF16ToUTF8(net::UnescapeForHTML(base::UTF8ToUTF16( | 459 set_title(base::UTF16ToUTF8(net::UnescapeForHTML(base::UTF8ToUTF16( |
458 GetStringProperty(value, "title"))))); | 460 GetStringProperty(value, "title"))))); |
459 set_description(GetStringProperty(value, "description")); | 461 set_description(GetStringProperty(value, "description")); |
460 set_favicon_url(GURL(GetStringProperty(value, "faviconUrl"))); | 462 set_favicon_url(GURL(GetStringProperty(value, "faviconUrl"))); |
461 debug_url_ = GetDebugURL(value); | 463 debug_url_ = GetDebugURL(value); |
462 frontend_url_ = GetStringProperty(value, "devtoolsFrontendUrl"); | 464 frontend_url_ = GetStringProperty(value, "devtoolsFrontendUrl"); |
463 | 465 |
464 size_t ws_param = frontend_url_.find("?ws"); | 466 size_t ws_param = frontend_url_.find("?ws"); |
465 if (ws_param != std::string::npos) | 467 if (ws_param != std::string::npos) |
466 frontend_url_ = frontend_url_.substr(0, ws_param); | 468 frontend_url_ = frontend_url_.substr(0, ws_param); |
467 if (frontend_url_.find("http:") == 0) | 469 if (frontend_url_.find("http:") == 0) |
468 frontend_url_ = "https:" + frontend_url_.substr(5); | 470 frontend_url_ = "https:" + frontend_url_.substr(5); |
469 } | 471 } |
470 | 472 |
471 RemotePageTarget::~RemotePageTarget() { | 473 RemotePageTarget::~RemotePageTarget() { |
472 } | 474 } |
473 | 475 |
474 DevToolsTargetImpl* RemotePageTarget::GetTarget() { | 476 DevToolsTargetImpl* RemotePageTarget::GetTarget() { |
475 return this; | 477 return this; |
476 } | 478 } |
477 | 479 |
478 std::string RemotePageTarget::GetFrontendURL() { | 480 std::string RemotePageTarget::GetFrontendURL() { |
479 return frontend_url_; | 481 return frontend_url_; |
480 } | 482 } |
481 | 483 |
482 std::string RemotePageTarget::GetId() const { | 484 std::string RemotePageTarget::GetId() const { |
483 return remote_id_; | 485 return local_id_; |
484 } | 486 } |
485 | 487 |
486 bool RemotePageTarget::IsAttached() const { | 488 bool RemotePageTarget::IsAttached() const { |
487 return debug_url_.empty(); | 489 return debug_url_.empty(); |
488 } | 490 } |
489 | 491 |
490 static void NoOp(int, const std::string&) {} | 492 static void NoOp(int, const std::string&) {} |
491 | 493 |
492 void RemotePageTarget::Inspect(Profile* profile) const { | 494 void RemotePageTarget::Inspect(Profile* profile) const { |
493 Activate(); | 495 Activate(); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 bool enabled; | 932 bool enabled; |
931 if (pref_value->GetAsBoolean(&enabled) && enabled) { | 933 if (pref_value->GetAsBoolean(&enabled) && enabled) { |
932 device_providers.push_back(new UsbDeviceProvider(profile_)); | 934 device_providers.push_back(new UsbDeviceProvider(profile_)); |
933 } | 935 } |
934 device_manager_->SetDeviceProviders(device_providers); | 936 device_manager_->SetDeviceProviders(device_providers); |
935 if (NeedsDeviceListPolling()) { | 937 if (NeedsDeviceListPolling()) { |
936 StopDeviceListPolling(); | 938 StopDeviceListPolling(); |
937 StartDeviceListPolling(); | 939 StartDeviceListPolling(); |
938 } | 940 } |
939 } | 941 } |
OLD | NEW |