From f497fb7a80fc1eeccec8f74f391151ab0ab59dbc Mon Sep 17 00:00:00 2001 From: yurys Date: Thu, 2 Jul 2015 10:10:56 -0700 Subject: [PATCH] DevTools: cut host and port from webSocketDebuggerUrl in addition to ws:// prefix At the moment we only use path component of the url. This CL makes it works correctly when webSocketDebuggerUrl contains non-empty host component. Drive-by: renamed method parameters from debug_url and url to target_path where appropriate. BUG=506609 Review URL: https://codereview.chromium.org/1219263004 Cr-Commit-Position: refs/heads/master@{#337235} --- .../devtools/device/android_device_manager.cc | 8 +-- .../devtools/device/android_device_manager.h | 8 +-- .../browser/devtools/device/android_web_socket.cc | 8 +-- .../devtools/device/devtools_android_bridge.cc | 58 ++++++++++++---------- .../devtools/device/devtools_android_bridge.h | 2 +- 5 files changed, 44 insertions(+), 40 deletions(-) diff --git a/chrome/browser/devtools/device/android_device_manager.cc b/chrome/browser/devtools/device/android_device_manager.cc index 88310fe01513..3426726d31ab 100644 --- a/chrome/browser/devtools/device/android_device_manager.cc +++ b/chrome/browser/devtools/device/android_device_manager.cc @@ -356,7 +356,7 @@ void AndroidDeviceManager::DeviceProvider::SendJsonRequest( void AndroidDeviceManager::DeviceProvider::HttpUpgrade( const std::string& serial, const std::string& socket_name, - const std::string& url, + const std::string& path, const std::string& extensions, const HttpUpgradeCallback& callback) { std::string extensions_with_new_line = @@ -366,7 +366,7 @@ void AndroidDeviceManager::DeviceProvider::HttpUpgrade( socket_name, base::Bind(&HttpRequest::HttpUpgradeRequest, base::StringPrintf(kWebSocketUpgradeRequest, - url.c_str(), + path.c_str(), extensions_with_new_line.c_str()), callback)); } @@ -411,13 +411,13 @@ void AndroidDeviceManager::Device::SendJsonRequest( void AndroidDeviceManager::Device::HttpUpgrade( const std::string& socket_name, - const std::string& url, + const std::string& path, const std::string& extensions, const HttpUpgradeCallback& callback) { task_runner_->PostTask( FROM_HERE, base::Bind(&DeviceProvider::HttpUpgrade, provider_, serial_, socket_name, - url, extensions, + path, extensions, base::Bind(&PostHttpUpgradeCallback, base::ThreadTaskRunnerHandle::Get(), callback))); } diff --git a/chrome/browser/devtools/device/android_device_manager.h b/chrome/browser/devtools/device/android_device_manager.h index 54e593bf7232..235c5c52870d 100644 --- a/chrome/browser/devtools/device/android_device_manager.h +++ b/chrome/browser/devtools/device/android_device_manager.h @@ -86,7 +86,7 @@ class AndroidDeviceManager : public base::NonThreadSafe { AndroidWebSocket( scoped_refptr device, const std::string& socket_name, - const std::string& url, + const std::string& path, AndroidWebSocket::Delegate* delegate); void Connected(int result, const std::string& extensions, @@ -118,12 +118,12 @@ class AndroidDeviceManager : public base::NonThreadSafe { const CommandCallback& callback); void HttpUpgrade(const std::string& socket_name, - const std::string& url, + const std::string& path, const std::string& extensions, const HttpUpgradeCallback& callback); AndroidWebSocket* CreateWebSocket( const std::string& socket_name, - const std::string& url, + const std::string& path, AndroidWebSocket::Delegate* delegate); std::string serial() { return serial_; } @@ -174,7 +174,7 @@ class AndroidDeviceManager : public base::NonThreadSafe { virtual void HttpUpgrade(const std::string& serial, const std::string& socket_name, - const std::string& url, + const std::string& path, const std::string& extensions, const HttpUpgradeCallback& callback); diff --git a/chrome/browser/devtools/device/android_web_socket.cc b/chrome/browser/devtools/device/android_web_socket.cc index fba70b2f8c44..890602608c4b 100644 --- a/chrome/browser/devtools/device/android_web_socket.cc +++ b/chrome/browser/devtools/device/android_web_socket.cc @@ -147,7 +147,7 @@ class AndroidDeviceManager::AndroidWebSocket::WebSocketImpl { AndroidDeviceManager::AndroidWebSocket::AndroidWebSocket( scoped_refptr device, const std::string& socket_name, - const std::string& url, + const std::string& path, Delegate* delegate) : device_(device.get()), socket_impl_(nullptr), @@ -158,7 +158,7 @@ AndroidDeviceManager::AndroidWebSocket::AndroidWebSocket( DCHECK(device_); device_->sockets_.insert(this); device_->HttpUpgrade( - socket_name, url, net::WebSocketEncoder::kClientExtensions, + socket_name, path, net::WebSocketEncoder::kClientExtensions, base::Bind(&AndroidWebSocket::Connected, weak_factory_.GetWeakPtr())); } @@ -224,7 +224,7 @@ void AndroidDeviceManager::AndroidWebSocket::Terminate() { AndroidDeviceManager::AndroidWebSocket* AndroidDeviceManager::Device::CreateWebSocket( const std::string& socket_name, - const std::string& url, + const std::string& path, AndroidWebSocket::Delegate* delegate) { - return new AndroidWebSocket(this, socket_name, url, delegate); + return new AndroidWebSocket(this, socket_name, path, delegate); } diff --git a/chrome/browser/devtools/device/devtools_android_bridge.cc b/chrome/browser/devtools/device/devtools_android_bridge.cc index cf55d61c5bd1..68245c175ace 100644 --- a/chrome/browser/devtools/device/devtools_android_bridge.cc +++ b/chrome/browser/devtools/device/devtools_android_bridge.cc @@ -206,7 +206,7 @@ class ProtocolCommand ProtocolCommand( scoped_refptr device, const std::string& socket, - const std::string& debug_url, + const std::string& target_path, const std::string& command, const base::Closure callback); @@ -226,12 +226,12 @@ class ProtocolCommand ProtocolCommand::ProtocolCommand( scoped_refptr device, const std::string& socket, - const std::string& debug_url, + const std::string& target_path, const std::string& command, const base::Closure callback) : command_(command), callback_(callback), - web_socket_(device->CreateWebSocket(socket, debug_url, this)) { + web_socket_(device->CreateWebSocket(socket, target_path, this)) { } void ProtocolCommand::OnSocketOpened() { @@ -303,14 +303,14 @@ class DevToolsAndroidBridge::AgentHostDelegate DevToolsAndroidBridge* bridge, const std::string& id, const BrowserId& browser_id, - const std::string& debug_url); + const std::string& target_path); private: AgentHostDelegate( DevToolsAndroidBridge* bridge, const std::string& id, const BrowserId& browser_id, - const std::string& debug_url); + const std::string& target_path); ~AgentHostDelegate() override; void Attach(content::DevToolsExternalAgentProxy* proxy) override; void Detach() override; @@ -322,7 +322,7 @@ class DevToolsAndroidBridge::AgentHostDelegate std::string id_; base::WeakPtr bridge_; BrowserId browser_id_; - std::string debug_url_; + std::string target_path_; bool socket_opened_; std::vector pending_messages_; scoped_refptr device_; @@ -338,14 +338,14 @@ DevToolsAndroidBridge::AgentHostDelegate::GetOrCreateAgentHost( DevToolsAndroidBridge* bridge, const std::string& id, const BrowserId& browser_id, - const std::string& debug_url) { + const std::string& target_path) { DCHECK_CURRENTLY_ON(BrowserThread::UI); AgentHostDelegates::iterator it = bridge->host_delegates_.find(id); if (it != bridge->host_delegates_.end()) return it->second->agent_host_; AgentHostDelegate* delegate = - new AgentHostDelegate(bridge, id, browser_id, debug_url); + new AgentHostDelegate(bridge, id, browser_id, target_path); scoped_refptr result = content::DevToolsAgentHost::Create(delegate); delegate->agent_host_ = result.get(); @@ -356,11 +356,11 @@ DevToolsAndroidBridge::AgentHostDelegate::AgentHostDelegate( DevToolsAndroidBridge* bridge, const std::string& id, const BrowserId& browser_id, - const std::string& debug_url) + const std::string& target_path) : id_(id), bridge_(bridge->AsWeakPtr()), browser_id_(browser_id), - debug_url_(debug_url), + target_path_(target_path), socket_opened_(false), agent_host_(NULL), proxy_(NULL) { @@ -386,7 +386,7 @@ void DevToolsAndroidBridge::AgentHostDelegate::Attach( return; web_socket_.reset( - device_->CreateWebSocket(browser_id_.second, debug_url_, this)); + device_->CreateWebSocket(browser_id_.second, target_path_, this)); } void DevToolsAndroidBridge::AgentHostDelegate::Detach() { @@ -442,7 +442,7 @@ class DevToolsAndroidBridge::RemotePageTarget : public DevToolsTargetImpl { private: base::WeakPtr bridge_; BrowserId browser_id_; - std::string debug_url_; + std::string target_path_; std::string frontend_url_; std::string remote_id_; std::string remote_type_; @@ -474,14 +474,18 @@ static std::string GetFrontendURL(const base::DictionaryValue& value) { return frontend_url; } -static std::string GetDebugURL(const base::DictionaryValue& value) { - std::string debug_url = GetStringProperty(value, "webSocketDebuggerUrl"); +static std::string GetTargetPath(const base::DictionaryValue& value) { + std::string target_path = GetStringProperty(value, "webSocketDebuggerUrl"); - if (debug_url.find("ws://") == 0) - debug_url = debug_url.substr(5); - else - debug_url = std::string(); - return debug_url; + if (target_path.find("ws://") == 0) { + size_t pos = target_path.find("/", 5); + if (pos == std::string::npos) + pos = 5; + target_path = target_path.substr(pos); + } else { + target_path = std::string(); + } + return target_path; } DevToolsAndroidBridge::RemotePageTarget::RemotePageTarget( @@ -492,10 +496,10 @@ DevToolsAndroidBridge::RemotePageTarget::RemotePageTarget( bridge, BuildUniqueTargetId(browser_id, value), browser_id, - GetDebugURL(value))), + GetTargetPath(value))), bridge_(bridge->AsWeakPtr()), browser_id_(browser_id), - debug_url_(GetDebugURL(value)), + target_path_(GetTargetPath(value)), frontend_url_(GetFrontendURL(value)), remote_id_(GetStringProperty(value, "id")), remote_type_(GetStringProperty(value, "type")), @@ -506,7 +510,7 @@ DevToolsAndroidBridge::RemotePageTarget::RemotePageTarget( GetStringProperty(value, "title"))))); set_description(GetStringProperty(value, "description")); set_favicon_url(GURL(GetStringProperty(value, "faviconUrl"))); - debug_url_ = GetDebugURL(value); + target_path_ = GetTargetPath(value); } DevToolsAndroidBridge::RemotePageTarget::~RemotePageTarget() { @@ -517,7 +521,7 @@ std::string DevToolsAndroidBridge::RemotePageTarget::GetId() const { } bool DevToolsAndroidBridge::RemotePageTarget::IsAttached() const { - return debug_url_.empty(); + return target_path_.empty(); } static void NoOp(int, const std::string&) {} @@ -554,7 +558,7 @@ void DevToolsAndroidBridge::RemotePageTarget::Reload() const { if (!bridge_) return; - bridge_->SendProtocolCommand(browser_id_, debug_url_, kPageReloadCommand, + bridge_->SendProtocolCommand(browser_id_, target_path_, kPageReloadCommand, NULL, base::Closure()); } @@ -622,12 +626,12 @@ void DevToolsAndroidBridge::SendJsonRequest( void DevToolsAndroidBridge::SendProtocolCommand( const BrowserId& browser_id, - const std::string& debug_url, + const std::string& target_path, const std::string& method, scoped_ptr params, const base::Closure callback) { DCHECK_CURRENTLY_ON(BrowserThread::UI); - if (debug_url.empty()) + if (target_path.empty()) return; scoped_refptr device( FindDevice(browser_id.first)); @@ -636,7 +640,7 @@ void DevToolsAndroidBridge::SendProtocolCommand( return; } new ProtocolCommand( - device, browser_id.second, debug_url, + device, browser_id.second, target_path, DevToolsProtocol::SerializeCommand(1, method, params.Pass()), callback); } diff --git a/chrome/browser/devtools/device/devtools_android_bridge.h b/chrome/browser/devtools/device/devtools_android_bridge.h index e562c2a30e4e..b112ff9b6621 100644 --- a/chrome/browser/devtools/device/devtools_android_bridge.h +++ b/chrome/browser/devtools/device/devtools_android_bridge.h @@ -260,7 +260,7 @@ class DevToolsAndroidBridge : public KeyedService { const JsonRequestCallback& callback); void SendProtocolCommand(const BrowserId& browser_id, - const std::string& debug_url, + const std::string& target_path, const std::string& method, scoped_ptr params, const base::Closure callback); -- 2.11.4.GIT