 Chromium Code Reviews
 Chromium Code Reviews Issue 144303005:
  DevTools: Generate correct id for a remote target  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 144303005:
  DevTools: Generate correct id for a remote target  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/devtools_adb_bridge.h" | 5 #include "chrome/browser/devtools/devtools_adb_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 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 // DevToolsTargetImpl overrides: | 839 // DevToolsTargetImpl overrides: | 
| 840 virtual void Inspect(Profile* profile) const OVERRIDE; | 840 virtual void Inspect(Profile* profile) const OVERRIDE; | 
| 841 virtual void Reload() const OVERRIDE; | 841 virtual void Reload() const OVERRIDE; | 
| 842 | 842 | 
| 843 void Navigate(const std::string& url) const; | 843 void Navigate(const std::string& url) const; | 
| 844 | 844 | 
| 845 private: | 845 private: | 
| 846 scoped_refptr<DevToolsAdbBridge::RemoteBrowser> browser_; | 846 scoped_refptr<DevToolsAdbBridge::RemoteBrowser> browser_; | 
| 847 std::string debug_url_; | 847 std::string debug_url_; | 
| 848 std::string frontend_url_; | 848 std::string frontend_url_; | 
| 849 std::string agent_id_; | 849 std::string remote_id_; | 
| 850 DISALLOW_COPY_AND_ASSIGN(RemotePageTarget); | 850 DISALLOW_COPY_AND_ASSIGN(RemotePageTarget); | 
| 851 }; | 851 }; | 
| 852 | 852 | 
| 853 RemotePageTarget::RemotePageTarget( | 853 RemotePageTarget::RemotePageTarget( | 
| 854 scoped_refptr<DevToolsAdbBridge::RemoteBrowser> browser, | 854 scoped_refptr<DevToolsAdbBridge::RemoteBrowser> browser, | 
| 855 const base::DictionaryValue& value) | 855 const base::DictionaryValue& value) | 
| 856 : browser_(browser) { | 856 : browser_(browser) { | 
| 857 type_ = "adb_page"; | 857 type_ = "adb_page"; | 
| 858 value.GetString("id", &id_); | 858 value.GetString("id", &remote_id_); | 
| 859 std::string url; | 859 std::string url; | 
| 860 value.GetString("url", &url); | 860 value.GetString("url", &url); | 
| 861 url_ = GURL(url); | 861 url_ = GURL(url); | 
| 862 value.GetString("title", &title_); | 862 value.GetString("title", &title_); | 
| 863 title_ = base::UTF16ToUTF8(net::UnescapeForHTML(base::UTF8ToUTF16(title_))); | 863 title_ = base::UTF16ToUTF8(net::UnescapeForHTML(base::UTF8ToUTF16(title_))); | 
| 864 value.GetString("description", &description_); | 864 value.GetString("description", &description_); | 
| 865 std::string favicon_url; | 865 std::string favicon_url; | 
| 866 value.GetString("faviconUrl", &favicon_url); | 866 value.GetString("faviconUrl", &favicon_url); | 
| 867 favicon_url_ = GURL(favicon_url); | 867 favicon_url_ = GURL(favicon_url); | 
| 868 value.GetString("webSocketDebuggerUrl", &debug_url_); | 868 value.GetString("webSocketDebuggerUrl", &debug_url_); | 
| 869 value.GetString("devtoolsFrontendUrl", &frontend_url_); | 869 value.GetString("devtoolsFrontendUrl", &frontend_url_); | 
| 870 | 870 | 
| 871 if (id_.empty() && !debug_url_.empty()) { | 871 if (remote_id_.empty() && !debug_url_.empty()) { | 
| 872 // Target id is not available until Chrome 26. Use page id at the end of | 872 // Target id is not available until Chrome 26. Use page id at the end of | 
| 873 // debug_url_ instead. For attached targets the id will remain empty. | 873 // debug_url_ instead. For attached targets the id will remain empty. | 
| 874 std::vector<std::string> parts; | 874 std::vector<std::string> parts; | 
| 875 Tokenize(debug_url_, "/", &parts); | 875 Tokenize(debug_url_, "/", &parts); | 
| 876 id_ = parts[parts.size()-1]; | 876 remote_id_ = parts[parts.size()-1]; | 
| 877 } | 877 } | 
| 878 | 878 | 
| 879 if (debug_url_.find("ws://") == 0) | 879 if (debug_url_.find("ws://") == 0) | 
| 880 debug_url_ = debug_url_.substr(5); | 880 debug_url_ = debug_url_.substr(5); | 
| 881 else | 881 else | 
| 882 debug_url_ = ""; | 882 debug_url_ = ""; | 
| 883 | 883 | 
| 884 size_t ws_param = frontend_url_.find("?ws"); | 884 size_t ws_param = frontend_url_.find("?ws"); | 
| 885 if (ws_param != std::string::npos) | 885 if (ws_param != std::string::npos) | 
| 886 frontend_url_ = frontend_url_.substr(0, ws_param); | 886 frontend_url_ = frontend_url_.substr(0, ws_param); | 
| 887 if (frontend_url_.find("http:") == 0) | 887 if (frontend_url_.find("http:") == 0) | 
| 888 frontend_url_ = "https:" + frontend_url_.substr(5); | 888 frontend_url_ = "https:" + frontend_url_.substr(5); | 
| 889 | 889 | 
| 890 agent_id_ = base::StringPrintf("%s:%s:%s", | 890 id_ = base::StringPrintf("%s:%s:%s", | 
| 891 browser_->device()->serial().c_str(), | 891 browser_->device()->serial().c_str(), | 
| 892 browser_->socket().c_str(), | 892 browser_->socket().c_str(), | 
| 893 id_.c_str()); | 893 remote_id_.c_str()); | 
| 894 } | 894 } | 
| 895 | 895 | 
| 896 RemotePageTarget::~RemotePageTarget() { | 896 RemotePageTarget::~RemotePageTarget() { | 
| 897 } | 897 } | 
| 898 | 898 | 
| 899 bool RemotePageTarget::IsAttached() const { | 899 bool RemotePageTarget::IsAttached() const { | 
| 900 return debug_url_.empty(); | 900 return debug_url_.empty(); | 
| 901 } | 901 } | 
| 902 | 902 | 
| 903 void RemotePageTarget::Inspect(Profile* profile) const { | 903 void RemotePageTarget::Inspect(Profile* profile) const { | 
| 904 std::string request = base::StringPrintf(kActivatePageRequest, id_.c_str()); | 904 std::string request = base::StringPrintf(kActivatePageRequest, | 
| 905 remote_id_.c_str()); | |
| 905 base::Closure inspect_callback = base::Bind(&AgentHostDelegate::Create, | 906 base::Closure inspect_callback = base::Bind(&AgentHostDelegate::Create, | 
| 906 id_, browser_, debug_url_, frontend_url_, profile); | 907 id_, browser_, debug_url_, frontend_url_, profile); | 
| 
dgozman
2014/01/29 15:07:16
Just to be sure: AgentHostDelegate should know abo
 | |
| 907 browser_->SendJsonRequest(request, inspect_callback); | 908 browser_->SendJsonRequest(request, inspect_callback); | 
| 908 } | 909 } | 
| 909 | 910 | 
| 910 bool RemotePageTarget::Activate() const { | 911 bool RemotePageTarget::Activate() const { | 
| 911 std::string request = base::StringPrintf(kActivatePageRequest, id_.c_str()); | 912 std::string request = base::StringPrintf(kActivatePageRequest, | 
| 913 remote_id_.c_str()); | |
| 912 browser_->SendJsonRequest(request, base::Closure()); | 914 browser_->SendJsonRequest(request, base::Closure()); | 
| 913 return true; | 915 return true; | 
| 914 } | 916 } | 
| 915 | 917 | 
| 916 bool RemotePageTarget::Close() const { | 918 bool RemotePageTarget::Close() const { | 
| 917 if (IsAttached()) | 919 if (IsAttached()) | 
| 918 return false; | 920 return false; | 
| 919 std::string request = base::StringPrintf(kClosePageRequest, id_.c_str()); | 921 std::string request = base::StringPrintf(kClosePageRequest, | 
| 922 remote_id_.c_str()); | |
| 920 browser_->SendJsonRequest(request, base::Closure()); | 923 browser_->SendJsonRequest(request, base::Closure()); | 
| 921 return true; | 924 return true; | 
| 922 } | 925 } | 
| 923 | 926 | 
| 924 void RemotePageTarget::Reload() const { | 927 void RemotePageTarget::Reload() const { | 
| 925 browser_->SendProtocolCommand(debug_url_, kPageReloadCommand, NULL); | 928 browser_->SendProtocolCommand(debug_url_, kPageReloadCommand, NULL); | 
| 926 } | 929 } | 
| 927 | 930 | 
| 928 void RemotePageTarget::Navigate(const std::string& url) const { | 931 void RemotePageTarget::Navigate(const std::string& url) const { | 
| 929 base::DictionaryValue params; | 932 base::DictionaryValue params; | 
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1142 | 1145 | 
| 1143 if (listeners_.empty()) | 1146 if (listeners_.empty()) | 
| 1144 return; | 1147 return; | 
| 1145 | 1148 | 
| 1146 BrowserThread::PostDelayedTask( | 1149 BrowserThread::PostDelayedTask( | 
| 1147 BrowserThread::UI, | 1150 BrowserThread::UI, | 
| 1148 FROM_HERE, | 1151 FROM_HERE, | 
| 1149 base::Bind(&DevToolsAdbBridge::RequestRemoteDevices, this), | 1152 base::Bind(&DevToolsAdbBridge::RequestRemoteDevices, this), | 
| 1150 base::TimeDelta::FromMilliseconds(kAdbPollingIntervalMs)); | 1153 base::TimeDelta::FromMilliseconds(kAdbPollingIntervalMs)); | 
| 1151 } | 1154 } | 
| OLD | NEW |