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_; | |
419 DISALLOW_COPY_AND_ASSIGN(RemotePageTarget); | 418 DISALLOW_COPY_AND_ASSIGN(RemotePageTarget); |
420 }; | 419 }; |
421 | 420 |
422 static std::string GetStringProperty(const base::DictionaryValue& value, | 421 static std::string GetStringProperty(const base::DictionaryValue& value, |
423 const std::string& name) { | 422 const std::string& name) { |
424 std::string result; | 423 std::string result; |
425 value.GetString(name, &result); | 424 value.GetString(name, &result); |
426 return result; | 425 return result; |
427 } | 426 } |
428 | 427 |
(...skipping 16 matching lines...) Expand all Loading... |
445 | 444 |
446 RemotePageTarget::RemotePageTarget( | 445 RemotePageTarget::RemotePageTarget( |
447 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser, | 446 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser, |
448 const base::DictionaryValue& value) | 447 const base::DictionaryValue& value) |
449 : DevToolsTargetImpl(AgentHostDelegate::GetOrCreateAgentHost( | 448 : DevToolsTargetImpl(AgentHostDelegate::GetOrCreateAgentHost( |
450 BuildUniqueTargetId(browser.get(), value), | 449 BuildUniqueTargetId(browser.get(), value), |
451 browser, GetDebugURL(value))), | 450 browser, GetDebugURL(value))), |
452 browser_(browser), | 451 browser_(browser), |
453 debug_url_(GetDebugURL(value)), | 452 debug_url_(GetDebugURL(value)), |
454 remote_id_(GetStringProperty(value, "id")), | 453 remote_id_(GetStringProperty(value, "id")), |
455 remote_type_(GetStringProperty(value, "type")), | 454 remote_type_(GetStringProperty(value, "type")) { |
456 local_id_(BuildUniqueTargetId(browser.get(), value)) { | |
457 set_type("adb_page"); | 455 set_type("adb_page"); |
458 set_url(GURL(GetStringProperty(value, "url"))); | 456 set_url(GURL(GetStringProperty(value, "url"))); |
459 set_title(base::UTF16ToUTF8(net::UnescapeForHTML(base::UTF8ToUTF16( | 457 set_title(base::UTF16ToUTF8(net::UnescapeForHTML(base::UTF8ToUTF16( |
460 GetStringProperty(value, "title"))))); | 458 GetStringProperty(value, "title"))))); |
461 set_description(GetStringProperty(value, "description")); | 459 set_description(GetStringProperty(value, "description")); |
462 set_favicon_url(GURL(GetStringProperty(value, "faviconUrl"))); | 460 set_favicon_url(GURL(GetStringProperty(value, "faviconUrl"))); |
463 debug_url_ = GetDebugURL(value); | 461 debug_url_ = GetDebugURL(value); |
464 frontend_url_ = GetStringProperty(value, "devtoolsFrontendUrl"); | 462 frontend_url_ = GetStringProperty(value, "devtoolsFrontendUrl"); |
465 | 463 |
466 size_t ws_param = frontend_url_.find("?ws"); | 464 size_t ws_param = frontend_url_.find("?ws"); |
467 if (ws_param != std::string::npos) | 465 if (ws_param != std::string::npos) |
468 frontend_url_ = frontend_url_.substr(0, ws_param); | 466 frontend_url_ = frontend_url_.substr(0, ws_param); |
469 if (frontend_url_.find("http:") == 0) | 467 if (frontend_url_.find("http:") == 0) |
470 frontend_url_ = "https:" + frontend_url_.substr(5); | 468 frontend_url_ = "https:" + frontend_url_.substr(5); |
471 } | 469 } |
472 | 470 |
473 RemotePageTarget::~RemotePageTarget() { | 471 RemotePageTarget::~RemotePageTarget() { |
474 } | 472 } |
475 | 473 |
476 DevToolsTargetImpl* RemotePageTarget::GetTarget() { | 474 DevToolsTargetImpl* RemotePageTarget::GetTarget() { |
477 return this; | 475 return this; |
478 } | 476 } |
479 | 477 |
480 std::string RemotePageTarget::GetFrontendURL() { | 478 std::string RemotePageTarget::GetFrontendURL() { |
481 return frontend_url_; | 479 return frontend_url_; |
482 } | 480 } |
483 | 481 |
484 std::string RemotePageTarget::GetId() const { | 482 std::string RemotePageTarget::GetId() const { |
485 return local_id_; | 483 return remote_id_; |
486 } | 484 } |
487 | 485 |
488 bool RemotePageTarget::IsAttached() const { | 486 bool RemotePageTarget::IsAttached() const { |
489 return debug_url_.empty(); | 487 return debug_url_.empty(); |
490 } | 488 } |
491 | 489 |
492 static void NoOp(int, const std::string&) {} | 490 static void NoOp(int, const std::string&) {} |
493 | 491 |
494 void RemotePageTarget::Inspect(Profile* profile) const { | 492 void RemotePageTarget::Inspect(Profile* profile) const { |
495 Activate(); | 493 Activate(); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 bool enabled; | 930 bool enabled; |
933 if (pref_value->GetAsBoolean(&enabled) && enabled) { | 931 if (pref_value->GetAsBoolean(&enabled) && enabled) { |
934 device_providers.push_back(new UsbDeviceProvider(profile_)); | 932 device_providers.push_back(new UsbDeviceProvider(profile_)); |
935 } | 933 } |
936 device_manager_->SetDeviceProviders(device_providers); | 934 device_manager_->SetDeviceProviders(device_providers); |
937 if (NeedsDeviceListPolling()) { | 935 if (NeedsDeviceListPolling()) { |
938 StopDeviceListPolling(); | 936 StopDeviceListPolling(); |
939 StartDeviceListPolling(); | 937 StartDeviceListPolling(); |
940 } | 938 } |
941 } | 939 } |
OLD | NEW |