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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const char kPageNavigateCommand[] = "Page.navigate"; | 64 const char kPageNavigateCommand[] = "Page.navigate"; |
65 | 65 |
66 const int kMinVersionNewWithURL = 32; | 66 const int kMinVersionNewWithURL = 32; |
67 const int kNewPageNavigateDelayMs = 500; | 67 const int kNewPageNavigateDelayMs = 500; |
68 | 68 |
69 bool IsWebRTCDeviceProviderEnabled() { | 69 bool IsWebRTCDeviceProviderEnabled() { |
70 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 70 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
71 switches::kEnableDevToolsExperiments); | 71 switches::kEnableDevToolsExperiments); |
72 } | 72 } |
73 | 73 |
| 74 bool BrowserIdFromString(const std::string& browser_id_str, |
| 75 DevToolsAndroidBridge::BrowserId* browser_id) { |
| 76 size_t colon_pos = browser_id_str.find(':'); |
| 77 if (colon_pos == std::string::npos) |
| 78 return false; |
| 79 browser_id->first = browser_id_str.substr(0, colon_pos); |
| 80 browser_id->second = browser_id_str.substr(colon_pos + 1); |
| 81 return true; |
| 82 } |
| 83 |
74 } // namespace | 84 } // namespace |
75 | 85 |
76 // DiscoveryRequest ----------------------------------------------------- | 86 // DiscoveryRequest ----------------------------------------------------- |
77 | 87 |
78 class DevToolsAndroidBridge::DiscoveryRequest | 88 class DevToolsAndroidBridge::DiscoveryRequest |
79 : public base::RefCountedThreadSafe<DiscoveryRequest, | 89 : public base::RefCountedThreadSafe<DiscoveryRequest, |
80 BrowserThread::DeleteOnUIThread> { | 90 BrowserThread::DeleteOnUIThread> { |
81 public: | 91 public: |
82 DiscoveryRequest(AndroidDeviceManager* device_manager, | 92 DiscoveryRequest(AndroidDeviceManager* device_manager, |
83 const DeviceListCallback& callback); | 93 const DeviceListCallback& callback); |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 DevToolsAndroidBridge::GetBrowserAgentHost( | 681 DevToolsAndroidBridge::GetBrowserAgentHost( |
672 scoped_refptr<RemoteBrowser> browser) { | 682 scoped_refptr<RemoteBrowser> browser) { |
673 return AgentHostDelegate::GetOrCreateAgentHost( | 683 return AgentHostDelegate::GetOrCreateAgentHost( |
674 this, | 684 this, |
675 "adb:" + browser->serial() + ":" + browser->socket(), | 685 "adb:" + browser->serial() + ":" + browser->socket(), |
676 browser->browser_id_, | 686 browser->browser_id_, |
677 kBrowserTargetSocket, | 687 kBrowserTargetSocket, |
678 browser->IsWebView()); | 688 browser->IsWebView()); |
679 } | 689 } |
680 | 690 |
| 691 void DevToolsAndroidBridge::SendJsonRequest( |
| 692 const std::string& browser_id_str, |
| 693 const std::string& url, |
| 694 const JsonRequestCallback& callback) { |
| 695 BrowserId browser_id; |
| 696 if (!BrowserIdFromString(browser_id_str, &browser_id)) { |
| 697 callback.Run(net::ERR_FAILED, std::string()); |
| 698 return; |
| 699 } |
| 700 SendJsonRequest(browser_id, url, callback); |
| 701 } |
| 702 |
681 scoped_refptr<AndroidDeviceManager::Device> DevToolsAndroidBridge::FindDevice( | 703 scoped_refptr<AndroidDeviceManager::Device> DevToolsAndroidBridge::FindDevice( |
682 const std::string& serial) { | 704 const std::string& serial) { |
683 DeviceMap::iterator it = device_map_.find(serial); | 705 DeviceMap::iterator it = device_map_.find(serial); |
684 return it == device_map_.end() ? nullptr : it->second; | 706 return it == device_map_.end() ? nullptr : it->second; |
685 } | 707 } |
686 | 708 |
687 void DevToolsAndroidBridge::RespondToOpenOnUIThread( | 709 void DevToolsAndroidBridge::RespondToOpenOnUIThread( |
688 scoped_refptr<RemoteBrowser> browser, | 710 scoped_refptr<RemoteBrowser> browser, |
689 const RemotePageCallback& callback, | 711 const RemotePageCallback& callback, |
690 int result, | 712 int result, |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 device_providers.push_back( | 1034 device_providers.push_back( |
1013 new WebRTCDeviceProvider(profile_, signin_manager_, token_service_)); | 1035 new WebRTCDeviceProvider(profile_, signin_manager_, token_service_)); |
1014 } | 1036 } |
1015 | 1037 |
1016 device_manager_->SetDeviceProviders(device_providers); | 1038 device_manager_->SetDeviceProviders(device_providers); |
1017 if (NeedsDeviceListPolling()) { | 1039 if (NeedsDeviceListPolling()) { |
1018 StopDeviceListPolling(); | 1040 StopDeviceListPolling(); |
1019 StartDeviceListPolling(); | 1041 StartDeviceListPolling(); |
1020 } | 1042 } |
1021 } | 1043 } |
OLD | NEW |