diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-27 16:38:13 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-27 16:38:13 +0000 |
commit | 6b9907e7f689c21ae84abf60caf43025089e6661 (patch) | |
tree | 11d32d837401e1496bd020742600948f50d3f15a /content | |
parent | d5b528c5a418faaf40c5f1a33de4b829b95dba62 (diff) | |
download | chromium_src-6b9907e7f689c21ae84abf60caf43025089e6661.zip chromium_src-6b9907e7f689c21ae84abf60caf43025089e6661.tar.gz chromium_src-6b9907e7f689c21ae84abf60caf43025089e6661.tar.bz2 |
DevTools [remote debugging]: serve devtools front-end files from the bundle, never redirect to chrome-devtools://.
Review URL: https://chromiumcodereview.appspot.com/10986050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159042 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/debugger/devtools_http_handler_impl.cc | 159 | ||||
-rw-r--r-- | content/browser/debugger/devtools_http_handler_impl.h | 22 | ||||
-rw-r--r-- | content/public/browser/devtools_http_handler.h | 1 | ||||
-rw-r--r-- | content/public/browser/devtools_http_handler_delegate.h | 7 | ||||
-rw-r--r-- | content/shell/shell_browser_main_parts.cc | 3 | ||||
-rw-r--r-- | content/shell/shell_devtools_delegate.cc | 11 | ||||
-rw-r--r-- | content/shell/shell_devtools_delegate.h | 9 | ||||
-rw-r--r-- | content/shell/shell_devtools_delegate_android.cc | 11 |
8 files changed, 37 insertions, 186 deletions
diff --git a/content/browser/debugger/devtools_http_handler_impl.cc b/content/browser/debugger/devtools_http_handler_impl.cc index 704fd40..20ab93c 100644 --- a/content/browser/debugger/devtools_http_handler_impl.cc +++ b/content/browser/debugger/devtools_http_handler_impl.cc @@ -9,6 +9,7 @@ #include "base/bind.h" #include "base/compiler_specific.h" +#include "base/file_util.h" #include "base/json/json_writer.h" #include "base/lazy_instance.h" #include "base/logging.h" @@ -35,9 +36,8 @@ #include "grit/devtools_resources_map.h" #include "net/base/escape.h" #include "net/base/io_buffer.h" +#include "net/base/ip_endpoint.h" #include "net/server/http_server_request_info.h" -#include "net/url_request/url_request_context.h" -#include "net/url_request/url_request_context_getter.h" #include "ui/base/layout.h" namespace content { @@ -131,12 +131,10 @@ int DevToolsHttpHandler::GetFrontendResourceId(const std::string& name) { DevToolsHttpHandler* DevToolsHttpHandler::Start( const net::StreamListenSocketFactory* socket_factory, const std::string& frontend_url, - net::URLRequestContextGetter* request_context_getter, DevToolsHttpHandlerDelegate* delegate) { DevToolsHttpHandlerImpl* http_handler = new DevToolsHttpHandlerImpl(socket_factory, frontend_url, - request_context_getter, delegate); http_handler->Start(); return http_handler; @@ -232,41 +230,33 @@ void DevToolsHttpHandlerImpl::OnHttpRequest( return; } - // Proxy static files from chrome-devtools://devtools/*. - net::URLRequestContext* request_context = - request_context_getter_->GetURLRequestContext(); - if (!request_context) { + if (info.path.find("/devtools/") != 0) { server_->Send404(connection_id); return; } - net::URLRequest* request; - - if (info.path.find("/devtools/") == 0) { - // Serve front-end files from resource bundle. - std::string filename = PathWithoutParams(info.path.substr(10)); - - if (delegate_->BundlesFrontendResources()) { - int resource_id = DevToolsHttpHandler::GetFrontendResourceId(filename); - if (resource_id != -1) { - base::StringPiece data = - content::GetContentClient()->GetDataResource( - resource_id, ui::SCALE_FACTOR_NONE); - server_->Send200(connection_id, - data.as_string(), - GetMimeType(filename)); - } + std::string filename = PathWithoutParams(info.path.substr(10)); + std::string mime_type = GetMimeType(filename); + + FilePath frontend_dir = delegate_->GetDebugFrontendDir(); + if (!frontend_dir.empty()) { + FilePath path = frontend_dir.AppendASCII(filename); + std::string data; + file_util::ReadFileToString(path, &data); + server_->Send200(connection_id, data, mime_type); + return; + } + if (delegate_->BundlesFrontendResources()) { + int resource_id = DevToolsHttpHandler::GetFrontendResourceId(filename); + if (resource_id != -1) { + base::StringPiece data = + content::GetContentClient()->GetDataResource( + resource_id, ui::SCALE_FACTOR_NONE); + server_->Send200(connection_id, data.as_string(), mime_type); return; } - std::string base_url = delegate_->GetFrontendResourcesBaseURL(); - request = request_context->CreateRequest(GURL(base_url + filename), this); - } else { - server_->Send404(connection_id); - return; } - - Bind(request, connection_id); - request->Start(); + server_->Send404(connection_id); } void DevToolsHttpHandlerImpl::OnWebSocketRequest( @@ -296,21 +286,6 @@ void DevToolsHttpHandlerImpl::OnWebSocketMessage( } void DevToolsHttpHandlerImpl::OnClose(int connection_id) { - ConnectionToRequestsMap::iterator it = - connection_to_requests_io_.find(connection_id); - if (it != connection_to_requests_io_.end()) { - // Dispose delegating socket. - for (std::set<net::URLRequest*>::iterator it2 = it->second.begin(); - it2 != it->second.end(); ++it2) { - net::URLRequest* request = *it2; - request->Cancel(); - request_to_connection_io_.erase(request); - request_to_buffer_io_.erase(request); - delete request; - } - connection_to_requests_io_.erase(connection_id); - } - BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, @@ -521,72 +496,12 @@ void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) { } } -void DevToolsHttpHandlerImpl::OnResponseStarted(net::URLRequest* request) { - RequestToSocketMap::iterator it = request_to_connection_io_.find(request); - if (it == request_to_connection_io_.end()) - return; - - int connection_id = it->second; - - std::string content_type; - request->GetMimeType(&content_type); - - if (request->status().is_success()) { - server_->Send(connection_id, - base::StringPrintf("HTTP/1.1 200 OK\r\n" - "Content-Type:%s\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n", - content_type.c_str())); - } else { - server_->Send404(connection_id); - } - - int bytes_read = 0; - // Some servers may treat HEAD requests as GET requests. To free up the - // network connection as soon as possible, signal that the request has - // completed immediately, without trying to read any data back (all we care - // about is the response code and headers, which we already have). - net::IOBuffer* buffer = request_to_buffer_io_[request].get(); - if (request->status().is_success()) - request->Read(buffer, kBufferSize, &bytes_read); - OnReadCompleted(request, bytes_read); -} - -void DevToolsHttpHandlerImpl::OnReadCompleted(net::URLRequest* request, - int bytes_read) { - RequestToSocketMap::iterator it = request_to_connection_io_.find(request); - if (it == request_to_connection_io_.end()) - return; - - int connection_id = it->second; - - net::IOBuffer* buffer = request_to_buffer_io_[request].get(); - do { - if (!request->status().is_success() || bytes_read <= 0) - break; - std::string chunk_size = base::StringPrintf("%X\r\n", bytes_read); - server_->Send(connection_id, chunk_size); - server_->Send(connection_id, buffer->data(), bytes_read); - server_->Send(connection_id, "\r\n"); - } while (request->Read(buffer, kBufferSize, &bytes_read)); - - - // See comments re: HEAD requests in OnResponseStarted(). - if (!request->status().is_io_pending()) { - server_->Send(connection_id, "0\r\n\r\n"); - RequestCompleted(request); - } -} - DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( const net::StreamListenSocketFactory* socket_factory, const std::string& frontend_url, - net::URLRequestContextGetter* request_context_getter, DevToolsHttpHandlerDelegate* delegate) : overridden_frontend_url_(frontend_url), socket_factory_(socket_factory), - request_context_getter_(request_context_getter), delegate_(delegate) { if (overridden_frontend_url_.empty()) overridden_frontend_url_ = "/devtools/devtools.html"; @@ -604,40 +519,12 @@ void DevToolsHttpHandlerImpl::Init() { // Run on I/O thread void DevToolsHttpHandlerImpl::TeardownAndRelease() { server_ = NULL; + BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind(&DevToolsHttpHandlerImpl::Release, this)); } -void DevToolsHttpHandlerImpl::Bind(net::URLRequest* request, - int connection_id) { - request_to_connection_io_[request] = connection_id; - ConnectionToRequestsMap::iterator it = - connection_to_requests_io_.find(connection_id); - if (it == connection_to_requests_io_.end()) { - std::pair<int, std::set<net::URLRequest*> > value( - connection_id, - std::set<net::URLRequest*>()); - it = connection_to_requests_io_.insert(value).first; - } - it->second.insert(request); - request_to_buffer_io_[request] = new net::IOBuffer(kBufferSize); -} - -void DevToolsHttpHandlerImpl::RequestCompleted(net::URLRequest* request) { - RequestToSocketMap::iterator it = request_to_connection_io_.find(request); - if (it == request_to_connection_io_.end()) - return; - - int connection_id = it->second; - request_to_connection_io_.erase(request); - ConnectionToRequestsMap::iterator it2 = - connection_to_requests_io_.find(connection_id); - it2->second.erase(request); - request_to_buffer_io_.erase(request); - delete request; -} - void DevToolsHttpHandlerImpl::Send200(int connection_id, const std::string& data, const std::string& mime_type) { diff --git a/content/browser/debugger/devtools_http_handler_impl.h b/content/browser/debugger/devtools_http_handler_impl.h index 06bdf3d..25f7133 100644 --- a/content/browser/debugger/devtools_http_handler_impl.h +++ b/content/browser/debugger/devtools_http_handler_impl.h @@ -16,7 +16,6 @@ #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_http_handler_delegate.h" #include "net/server/http_server.h" -#include "net/url_request/url_request.h" namespace net { class StreamListenSocketFactory; @@ -31,8 +30,7 @@ class RenderViewHost; class DevToolsHttpHandlerImpl : public DevToolsHttpHandler, public base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>, - public net::HttpServer::Delegate, - public net::URLRequest::Delegate { + public net::HttpServer::Delegate { private: struct PageInfo; typedef std::vector<PageInfo> PageList; @@ -44,7 +42,6 @@ class DevToolsHttpHandlerImpl // Takes ownership over |socket_factory|. DevToolsHttpHandlerImpl(const net::StreamListenSocketFactory* socket_factory, const std::string& frontend_url, - net::URLRequestContextGetter* request_context_getter, DevToolsHttpHandlerDelegate* delegate); virtual ~DevToolsHttpHandlerImpl(); void Start(); @@ -74,15 +71,8 @@ class DevToolsHttpHandlerImpl void OnWebSocketMessageUI(int connection_id, const std::string& data); void OnCloseUI(int connection_id); - // net::URLRequest::Delegate implementation. - virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; - virtual void OnReadCompleted(net::URLRequest* request, - int bytes_read) OVERRIDE; - void Init(); void TeardownAndRelease(); - void Bind(net::URLRequest* request, int connection_id); - void RequestCompleted(net::URLRequest* request); void Send200(int connection_id, const std::string& data, @@ -102,19 +92,9 @@ class DevToolsHttpHandlerImpl std::string overridden_frontend_url_; scoped_ptr<const net::StreamListenSocketFactory> socket_factory_; scoped_refptr<net::HttpServer> server_; - typedef std::map<net::URLRequest*, int> - RequestToSocketMap; - RequestToSocketMap request_to_connection_io_; - typedef std::map<int, std::set<net::URLRequest*> > - ConnectionToRequestsMap; - ConnectionToRequestsMap connection_to_requests_io_; - typedef std::map<net::URLRequest*, scoped_refptr<net::IOBuffer> > - BuffersMap; - BuffersMap request_to_buffer_io_; typedef std::map<int, content::DevToolsClientHost*> ConnectionToClientHostMap; ConnectionToClientHostMap connection_to_client_host_ui_; - net::URLRequestContextGetter* request_context_getter_; scoped_ptr<DevToolsHttpHandlerDelegate> delegate_; RenderViewHostBinding* binding_; scoped_ptr<RenderViewHostBinding> default_binding_; diff --git a/content/public/browser/devtools_http_handler.h b/content/public/browser/devtools_http_handler.h index 4642b54..5ad9375 100644 --- a/content/public/browser/devtools_http_handler.h +++ b/content/public/browser/devtools_http_handler.h @@ -47,7 +47,6 @@ class DevToolsHttpHandler { CONTENT_EXPORT static DevToolsHttpHandler* Start( const net::StreamListenSocketFactory* socket_factory, const std::string& frontend_url, - net::URLRequestContextGetter* request_context_getter, DevToolsHttpHandlerDelegate* delegate); // Called from the main thread in order to stop protocol handler. diff --git a/content/public/browser/devtools_http_handler_delegate.h b/content/public/browser/devtools_http_handler_delegate.h index 36c3b07f..593c37c 100644 --- a/content/public/browser/devtools_http_handler_delegate.h +++ b/content/public/browser/devtools_http_handler_delegate.h @@ -8,6 +8,8 @@ #include <string> #include <vector> +#include "base/file_path.h" + class GURL; namespace content { @@ -25,9 +27,8 @@ class DevToolsHttpHandlerDelegate { // Returns true if and only if frontend resources are bundled. virtual bool BundlesFrontendResources() = 0; - // Returns URL that front-end files are available at, empty string if - // no internal server is available. - virtual std::string GetFrontendResourcesBaseURL() = 0; + // Returns path to the front-end files on the local filesystem for debugging. + virtual FilePath GetDebugFrontendDir() = 0; // Get a thumbnail for a given page. Returns non-empty string iff we have the // thumbnail. diff --git a/content/shell/shell_browser_main_parts.cc b/content/shell/shell_browser_main_parts.cc index 9e7108d..25e500f 100644 --- a/content/shell/shell_browser_main_parts.cc +++ b/content/shell/shell_browser_main_parts.cc @@ -127,8 +127,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { } } #endif - devtools_delegate_ = new ShellDevToolsDelegate( - port, browser_context_->GetRequestContext()); + devtools_delegate_ = new ShellDevToolsDelegate(port); if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { Shell::CreateNewWindow(browser_context_.get(), diff --git a/content/shell/shell_devtools_delegate.cc b/content/shell/shell_devtools_delegate.cc index 2c20720..88821ef 100644 --- a/content/shell/shell_devtools_delegate.cc +++ b/content/shell/shell_devtools_delegate.cc @@ -13,14 +13,10 @@ namespace content { -ShellDevToolsDelegate::ShellDevToolsDelegate( - int port, - net::URLRequestContextGetter* context_getter) - : context_getter_(context_getter) { +ShellDevToolsDelegate::ShellDevToolsDelegate(int port) { devtools_http_handler_ = DevToolsHttpHandler::Start( new net::TCPListenSocketFactory("127.0.0.1", port), "", - context_getter_, this); } @@ -42,11 +38,10 @@ bool ShellDevToolsDelegate::BundlesFrontendResources() { return true; } -std::string ShellDevToolsDelegate::GetFrontendResourcesBaseURL() { - return ""; +FilePath ShellDevToolsDelegate::GetDebugFrontendDir() { + return FilePath(); } - std::string ShellDevToolsDelegate::GetPageThumbnailData(const GURL& url) { return ""; } diff --git a/content/shell/shell_devtools_delegate.h b/content/shell/shell_devtools_delegate.h index 1638247..19557c1 100644 --- a/content/shell/shell_devtools_delegate.h +++ b/content/shell/shell_devtools_delegate.h @@ -11,17 +11,13 @@ #include "base/compiler_specific.h" #include "content/public/browser/devtools_http_handler_delegate.h" -namespace net { -class URLRequestContextGetter; -} - namespace content { class DevToolsHttpHandler; class ShellDevToolsDelegate : public DevToolsHttpHandlerDelegate { public: - ShellDevToolsDelegate(int port, net::URLRequestContextGetter* context_getter); + explicit ShellDevToolsDelegate(int port); virtual ~ShellDevToolsDelegate(); // Stops http server. @@ -30,7 +26,7 @@ class ShellDevToolsDelegate : public DevToolsHttpHandlerDelegate { // DevToolsHttpProtocolHandler::Delegate overrides. virtual std::string GetDiscoveryPageHTML() OVERRIDE; virtual bool BundlesFrontendResources() OVERRIDE; - virtual std::string GetFrontendResourcesBaseURL() OVERRIDE; + virtual FilePath GetDebugFrontendDir() OVERRIDE; virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE; DevToolsHttpHandler* devtools_http_handler() { @@ -38,7 +34,6 @@ class ShellDevToolsDelegate : public DevToolsHttpHandlerDelegate { } private: - net::URLRequestContextGetter* context_getter_; DevToolsHttpHandler* devtools_http_handler_; DISALLOW_COPY_AND_ASSIGN(ShellDevToolsDelegate); diff --git a/content/shell/shell_devtools_delegate_android.cc b/content/shell/shell_devtools_delegate_android.cc index 38df1b4..7584c68 100644 --- a/content/shell/shell_devtools_delegate_android.cc +++ b/content/shell/shell_devtools_delegate_android.cc @@ -9,7 +9,6 @@ #include "content/public/browser/devtools_http_handler.h" #include "grit/shell_resources.h" #include "net/base/unix_domain_socket_posix.h" -#include "net/url_request/url_request_context_getter.h" #include "ui/base/layout.h" #include "ui/base/resource/resource_bundle.h" @@ -27,16 +26,12 @@ const char kFrontEndURL[] = namespace content { -ShellDevToolsDelegate::ShellDevToolsDelegate( - int port, - net::URLRequestContextGetter* context_getter) - : context_getter_(context_getter) { +ShellDevToolsDelegate::ShellDevToolsDelegate(int port) { devtools_http_handler_ = DevToolsHttpHandler::Start( new net::UnixDomainSocketWithAbstractNamespaceFactory( kSocketName, base::Bind(&CanUserConnectToDevTools)), StringPrintf(kFrontEndURL, kFrontendVersion), - context_getter, this); } @@ -58,8 +53,8 @@ bool ShellDevToolsDelegate::BundlesFrontendResources() { return false; } -std::string ShellDevToolsDelegate::GetFrontendResourcesBaseURL() { - return ""; +FilePath ShellDevToolsDelegate::GetDebugFrontendDir() { + return FilePath(); } std::string ShellDevToolsDelegate::GetPageThumbnailData(const GURL& url) { |