Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: chrome/browser/devtools/device/devtools_android_bridge.cc

Issue 521573002: Support for browser aliases in DevTools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/devtools/device/devtools_android_bridge.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 const char kBrowserTargetSocket[] = "/devtools/browser"; 50 const char kBrowserTargetSocket[] = "/devtools/browser";
51 const int kAdbPollingIntervalMs = 1000; 51 const int kAdbPollingIntervalMs = 1000;
52 52
53 const char kUrlParam[] = "url"; 53 const char kUrlParam[] = "url";
54 const char kPageReloadCommand[] = "Page.reload"; 54 const char kPageReloadCommand[] = "Page.reload";
55 const char kPageNavigateCommand[] = "Page.navigate"; 55 const char kPageNavigateCommand[] = "Page.navigate";
56 56
57 const int kMinVersionNewWithURL = 32; 57 const int kMinVersionNewWithURL = 32;
58 const int kNewPageNavigateDelayMs = 500; 58 const int kNewPageNavigateDelayMs = 500;
59 59
60 static int last_remote_browser_id_ = 1;
61
60 // DiscoveryRequest ----------------------------------------------------- 62 // DiscoveryRequest -----------------------------------------------------
61 63
62 class DiscoveryRequest : public base::RefCountedThreadSafe< 64 class DiscoveryRequest : public base::RefCountedThreadSafe<
63 DiscoveryRequest, 65 DiscoveryRequest,
64 BrowserThread::DeleteOnUIThread> { 66 BrowserThread::DeleteOnUIThread> {
65 public: 67 public:
66 typedef AndroidDeviceManager::Device Device; 68 typedef AndroidDeviceManager::Device Device;
67 typedef AndroidDeviceManager::Devices Devices; 69 typedef AndroidDeviceManager::Devices Devices;
68 typedef AndroidDeviceManager::DeviceInfo DeviceInfo; 70 typedef AndroidDeviceManager::DeviceInfo DeviceInfo;
69 typedef DevToolsAndroidBridge::RemoteDevice RemoteDevice; 71 typedef DevToolsAndroidBridge::RemoteDevice RemoteDevice;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 virtual std::string GetId() const OVERRIDE; 404 virtual std::string GetId() const OVERRIDE;
403 virtual bool IsAttached() const OVERRIDE; 405 virtual bool IsAttached() const OVERRIDE;
404 virtual bool Activate() const OVERRIDE; 406 virtual bool Activate() const OVERRIDE;
405 virtual bool Close() const OVERRIDE; 407 virtual bool Close() const OVERRIDE;
406 virtual void Inspect(Profile* profile) const OVERRIDE; 408 virtual void Inspect(Profile* profile) const OVERRIDE;
407 virtual void Reload() const OVERRIDE; 409 virtual void Reload() const OVERRIDE;
408 410
409 void Navigate(const std::string& url, base::Closure callback) const; 411 void Navigate(const std::string& url, base::Closure callback) const;
410 412
411 private: 413 private:
412 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser_; 414 const scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser_;
413 std::string debug_url_; 415 const std::string debug_url_;
414 std::string frontend_url_; 416 std::string frontend_url_;
415 std::string remote_id_; 417 const std::string remote_id_;
416 std::string remote_type_; 418 const std::string local_id_;
419 const std::string remote_type_;
417 DISALLOW_COPY_AND_ASSIGN(RemotePageTarget); 420 DISALLOW_COPY_AND_ASSIGN(RemotePageTarget);
418 }; 421 };
419 422
420 static std::string GetStringProperty(const base::DictionaryValue& value, 423 static std::string GetStringProperty(const base::DictionaryValue& value,
421 const std::string& name) { 424 const std::string& name) {
422 std::string result; 425 std::string result;
423 value.GetString(name, &result); 426 value.GetString(name, &result);
424 return result; 427 return result;
425 } 428 }
426 429
(...skipping 14 matching lines...) Expand all
441 return debug_url; 444 return debug_url;
442 } 445 }
443 446
444 RemotePageTarget::RemotePageTarget( 447 RemotePageTarget::RemotePageTarget(
445 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser, 448 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser,
446 const base::DictionaryValue& value) 449 const base::DictionaryValue& value)
447 : DevToolsTargetImpl(AgentHostDelegate::GetOrCreateAgentHost( 450 : DevToolsTargetImpl(AgentHostDelegate::GetOrCreateAgentHost(
448 BuildUniqueTargetId(browser.get(), value), 451 BuildUniqueTargetId(browser.get(), value),
449 browser, GetDebugURL(value))), 452 browser, GetDebugURL(value))),
450 browser_(browser), 453 browser_(browser),
451 debug_url_(GetDebugURL(value)), 454 debug_url_(GetDebugURL(value)),
SeRya 2014/08/29 07:04:41 Initialized twice.
452 remote_id_(GetStringProperty(value, "id")), 455 remote_id_(GetStringProperty(value, "id")),
456 local_id_(base::IntToString(browser->GetId()) + ":" + remote_id_),
453 remote_type_(GetStringProperty(value, "type")) { 457 remote_type_(GetStringProperty(value, "type")) {
454 set_type("adb_page"); 458 set_type("adb_page");
455 set_url(GURL(GetStringProperty(value, "url"))); 459 set_url(GURL(GetStringProperty(value, "url")));
456 set_title(base::UTF16ToUTF8(net::UnescapeForHTML(base::UTF8ToUTF16( 460 set_title(base::UTF16ToUTF8(net::UnescapeForHTML(base::UTF8ToUTF16(
457 GetStringProperty(value, "title"))))); 461 GetStringProperty(value, "title")))));
458 set_description(GetStringProperty(value, "description")); 462 set_description(GetStringProperty(value, "description"));
459 set_favicon_url(GURL(GetStringProperty(value, "faviconUrl"))); 463 set_favicon_url(GURL(GetStringProperty(value, "faviconUrl")));
460 debug_url_ = GetDebugURL(value);
461 frontend_url_ = GetStringProperty(value, "devtoolsFrontendUrl"); 464 frontend_url_ = GetStringProperty(value, "devtoolsFrontendUrl");
462 465
463 size_t ws_param = frontend_url_.find("?ws"); 466 size_t ws_param = frontend_url_.find("?ws");
464 if (ws_param != std::string::npos) 467 if (ws_param != std::string::npos)
465 frontend_url_ = frontend_url_.substr(0, ws_param); 468 frontend_url_ = frontend_url_.substr(0, ws_param);
466 if (frontend_url_.find("http:") == 0) 469 if (frontend_url_.find("http:") == 0)
467 frontend_url_ = "https:" + frontend_url_.substr(5); 470 frontend_url_ = "https:" + frontend_url_.substr(5);
468 } 471 }
469 472
470 RemotePageTarget::~RemotePageTarget() { 473 RemotePageTarget::~RemotePageTarget() {
471 } 474 }
472 475
473 DevToolsTargetImpl* RemotePageTarget::GetTarget() { 476 DevToolsTargetImpl* RemotePageTarget::GetTarget() {
474 return this; 477 return this;
475 } 478 }
476 479
477 std::string RemotePageTarget::GetFrontendURL() { 480 std::string RemotePageTarget::GetFrontendURL() {
478 return frontend_url_; 481 return frontend_url_;
479 } 482 }
480 483
481 std::string RemotePageTarget::GetId() const { 484 std::string RemotePageTarget::GetId() const {
482 return remote_id_; 485 return local_id_;
483 } 486 }
484 487
485 bool RemotePageTarget::IsAttached() const { 488 bool RemotePageTarget::IsAttached() const {
486 return debug_url_.empty(); 489 return debug_url_.empty();
487 } 490 }
488 491
489 static void NoOp(int, const std::string&) {} 492 static void NoOp(int, const std::string&) {}
490 493
491 void RemotePageTarget::Inspect(Profile* profile) const { 494 void RemotePageTarget::Inspect(Profile* profile) const {
492 Activate(); 495 Activate();
(...skipping 28 matching lines...) Expand all
521 params.SetString(kUrlParam, url); 524 params.SetString(kUrlParam, url);
522 browser_->SendProtocolCommand(debug_url_, kPageNavigateCommand, &params, 525 browser_->SendProtocolCommand(debug_url_, kPageNavigateCommand, &params,
523 callback); 526 callback);
524 } 527 }
525 528
526 // DevToolsAndroidBridge::RemoteBrowser --------------------------------------- 529 // DevToolsAndroidBridge::RemoteBrowser ---------------------------------------
527 530
528 DevToolsAndroidBridge::RemoteBrowser::RemoteBrowser( 531 DevToolsAndroidBridge::RemoteBrowser::RemoteBrowser(
529 scoped_refptr<Device> device, 532 scoped_refptr<Device> device,
530 const AndroidDeviceManager::BrowserInfo& browser_info) 533 const AndroidDeviceManager::BrowserInfo& browser_info)
531 : device_(device), 534 : id_(last_remote_browser_id_++),
535 device_(device),
532 socket_(browser_info.socket_name), 536 socket_(browser_info.socket_name),
533 display_name_(browser_info.display_name), 537 display_name_(browser_info.display_name),
534 type_(browser_info.type), 538 type_(browser_info.type),
535 page_descriptors_(new base::ListValue()) { 539 page_descriptors_(new base::ListValue()) {
536 } 540 }
537 541
538 bool DevToolsAndroidBridge::RemoteBrowser::IsChrome() const { 542 bool DevToolsAndroidBridge::RemoteBrowser::IsChrome() const {
539 return type_ == AndroidDeviceManager::BrowserInfo::kTypeChrome; 543 return type_ == AndroidDeviceManager::BrowserInfo::kTypeChrome;
540 } 544 }
541 545
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 bool enabled; 898 bool enabled;
895 if (pref_value->GetAsBoolean(&enabled) && enabled) { 899 if (pref_value->GetAsBoolean(&enabled) && enabled) {
896 device_providers.push_back(new UsbDeviceProvider(profile_)); 900 device_providers.push_back(new UsbDeviceProvider(profile_));
897 } 901 }
898 device_manager_->SetDeviceProviders(device_providers); 902 device_manager_->SetDeviceProviders(device_providers);
899 if (!device_list_listeners_.empty()) { 903 if (!device_list_listeners_.empty()) {
900 StopDeviceListPolling(); 904 StopDeviceListPolling();
901 StartDeviceListPolling(); 905 StartDeviceListPolling();
902 } 906 }
903 } 907 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/device/devtools_android_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698