Commit d683ecda authored by yurys@chromium.org's avatar yurys@chromium.org

Add content API for DevTools HTTP handler

BUG=104625
TEST=Existing tests

Review URL: http://codereview.chromium.org/8554008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112662 0039d316-1c4b-4281-b951-d872f2087c98
parent 5bff94bb
...@@ -12,9 +12,11 @@ ...@@ -12,9 +12,11 @@
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
DevToolsHttpProtocolHandler::InspectableTabs using content::DevToolsHttpHandlerDelegate;
DevToolsHttpHandlerDelegate::InspectableTabs
BrowserListTabContentsProvider::GetInspectableTabs() { BrowserListTabContentsProvider::GetInspectableTabs() {
DevToolsHttpProtocolHandler::InspectableTabs tabs; DevToolsHttpHandlerDelegate::InspectableTabs tabs;
for (BrowserList::const_iterator it = BrowserList::begin(), for (BrowserList::const_iterator it = BrowserList::begin(),
end = BrowserList::end(); it != end; ++it) { end = BrowserList::end(); it != end; ++it) {
TabStripModel* model = (*it)->tabstrip_model(); TabStripModel* model = (*it)->tabstrip_model();
......
...@@ -6,19 +6,23 @@ ...@@ -6,19 +6,23 @@
#define CHROME_BROWSER_DEBUGGER_BROWSER_LIST_TABCONTENTS_PROVIDER_H_ #define CHROME_BROWSER_DEBUGGER_BROWSER_LIST_TABCONTENTS_PROVIDER_H_
#include <string> #include <string>
#include "content/browser/debugger/devtools_http_protocol_handler.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "content/public/browser/devtools_http_handler_delegate.h"
class BrowserListTabContentsProvider class BrowserListTabContentsProvider
: public DevToolsHttpProtocolHandler::Delegate { : public content::DevToolsHttpHandlerDelegate {
public: public:
BrowserListTabContentsProvider() {} BrowserListTabContentsProvider() {}
virtual ~BrowserListTabContentsProvider() {} virtual ~BrowserListTabContentsProvider() {}
// DevToolsHttpProtocolHandler::Delegate overrides. // DevToolsHttpProtocolHandler::Delegate overrides.
virtual DevToolsHttpProtocolHandler::InspectableTabs virtual DevToolsHttpHandlerDelegate::InspectableTabs
GetInspectableTabs() OVERRIDE; GetInspectableTabs() OVERRIDE;
virtual std::string GetDiscoveryPageHTML() OVERRIDE; virtual std::string GetDiscoveryPageHTML() OVERRIDE;
virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
private: private:
DISALLOW_COPY_AND_ASSIGN(BrowserListTabContentsProvider); DISALLOW_COPY_AND_ASSIGN(BrowserListTabContentsProvider);
}; };
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/browser/ui/webui/devtools_ui.h" #include "chrome/browser/ui/webui/devtools_ui.h"
#include "content/public/browser/devtools_http_handler.h"
RemoteDebuggingServer::RemoteDebuggingServer(Profile* profile, RemoteDebuggingServer::RemoteDebuggingServer(Profile* profile,
const std::string& ip, const std::string& ip,
...@@ -17,10 +18,10 @@ RemoteDebuggingServer::RemoteDebuggingServer(Profile* profile, ...@@ -17,10 +18,10 @@ RemoteDebuggingServer::RemoteDebuggingServer(Profile* profile,
DevToolsUI::RegisterDevToolsDataSource(profile); DevToolsUI::RegisterDevToolsDataSource(profile);
devtools_http_handler_ = devtools_http_handler_ =
DevToolsHttpProtocolHandler::Start(ip, content::DevToolsHttpHandler::Start(ip,
port, port,
frontend_url, frontend_url,
new BrowserListTabContentsProvider()); new BrowserListTabContentsProvider());
} }
RemoteDebuggingServer::~RemoteDebuggingServer() { RemoteDebuggingServer::~RemoteDebuggingServer() {
......
...@@ -9,23 +9,24 @@ ...@@ -9,23 +9,24 @@
#include <string> #include <string>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "content/browser/debugger/devtools_http_protocol_handler.h"
class DevToolsHttpProtocolHandler;
class Profile; class Profile;
namespace content {
class DevToolsHttpHandler;
}
class RemoteDebuggingServer { class RemoteDebuggingServer {
public: public:
RemoteDebuggingServer(Profile* profile, RemoteDebuggingServer(Profile* profile,
const std::string& ip, const std::string& ip,
int port, int port,
const std::string& frontend_url); const std::string& frontend_url);
virtual ~RemoteDebuggingServer(); virtual ~RemoteDebuggingServer();
private: private:
scoped_refptr<DevToolsHttpProtocolHandler> devtools_http_handler_; content::DevToolsHttpHandler* devtools_http_handler_;
DISALLOW_COPY_AND_ASSIGN(RemoteDebuggingServer); DISALLOW_COPY_AND_ASSIGN(RemoteDebuggingServer);
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/debugger/devtools_http_protocol_handler.h" #include "content/browser/debugger/devtools_http_handler_impl.h"
#include <utility> #include <utility>
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host_registry.h" #include "content/public/browser/devtools_agent_host_registry.h"
#include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_client_host.h"
#include "content/public/browser/devtools_http_handler_delegate.h"
#include "content/public/browser/devtools_manager.h" #include "content/public/browser/devtools_manager.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "net/base/escape.h" #include "net/base/escape.h"
...@@ -30,11 +31,7 @@ ...@@ -30,11 +31,7 @@
#include "net/server/http_server_request_info.h" #include "net/server/http_server_request_info.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
using content::BrowserThread; namespace content {
using content::DevToolsAgentHost;
using content::DevToolsAgentHostRegistry;
using content::DevToolsClientHost;
using content::DevToolsManager;
const int kBufferSize = 16 * 1024; const int kBufferSize = 16 * 1024;
...@@ -138,35 +135,36 @@ base::LazyInstance< ...@@ -138,35 +135,36 @@ base::LazyInstance<
} // namespace } // namespace
// static // static
scoped_refptr<DevToolsHttpProtocolHandler> DevToolsHttpProtocolHandler::Start( DevToolsHttpHandler* DevToolsHttpHandler::Start(
const std::string& ip, const std::string& ip,
int port, int port,
const std::string& frontend_url, const std::string& frontend_url,
Delegate* delegate) { DevToolsHttpHandlerDelegate* delegate) {
scoped_refptr<DevToolsHttpProtocolHandler> http_handler = DevToolsHttpHandlerImpl* http_handler =
new DevToolsHttpProtocolHandler(ip, port, frontend_url, delegate); new DevToolsHttpHandlerImpl(ip, port, frontend_url, delegate);
http_handler->Start(); http_handler->Start();
return http_handler; return http_handler;
} }
DevToolsHttpProtocolHandler::~DevToolsHttpProtocolHandler() { DevToolsHttpHandlerImpl::~DevToolsHttpHandlerImpl() {
// Stop() must be called prior to this being called // Stop() must be called prior to this being called
DCHECK(server_.get() == NULL); DCHECK(server_.get() == NULL);
} }
void DevToolsHttpProtocolHandler::Start() { void DevToolsHttpHandlerImpl::Start() {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::Bind(&DevToolsHttpProtocolHandler::Init, this)); base::Bind(&DevToolsHttpHandlerImpl::Init, this));
} }
void DevToolsHttpProtocolHandler::Stop() { void DevToolsHttpHandlerImpl::Stop() {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::Bind(&DevToolsHttpProtocolHandler::Teardown, this)); base::Bind(&DevToolsHttpHandlerImpl::Teardown, this));
protect_ptr_ = NULL;
} }
void DevToolsHttpProtocolHandler::OnHttpRequest( void DevToolsHttpHandlerImpl::OnHttpRequest(
int connection_id, int connection_id,
const net::HttpServerRequestInfo& info) { const net::HttpServerRequestInfo& info) {
if (info.path == "/json") { if (info.path == "/json") {
...@@ -174,7 +172,7 @@ void DevToolsHttpProtocolHandler::OnHttpRequest( ...@@ -174,7 +172,7 @@ void DevToolsHttpProtocolHandler::OnHttpRequest(
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, BrowserThread::UI,
FROM_HERE, FROM_HERE,
base::Bind(&DevToolsHttpProtocolHandler::OnJsonRequestUI, base::Bind(&DevToolsHttpHandlerImpl::OnJsonRequestUI,
this, this,
connection_id, connection_id,
info)); info));
...@@ -210,33 +208,33 @@ void DevToolsHttpProtocolHandler::OnHttpRequest( ...@@ -210,33 +208,33 @@ void DevToolsHttpProtocolHandler::OnHttpRequest(
request->Start(); request->Start();
} }
void DevToolsHttpProtocolHandler::OnWebSocketRequest( void DevToolsHttpHandlerImpl::OnWebSocketRequest(
int connection_id, int connection_id,
const net::HttpServerRequestInfo& request) { const net::HttpServerRequestInfo& request) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, BrowserThread::UI,
FROM_HERE, FROM_HERE,
base::Bind( base::Bind(
&DevToolsHttpProtocolHandler::OnWebSocketRequestUI, &DevToolsHttpHandlerImpl::OnWebSocketRequestUI,
this, this,
connection_id, connection_id,
request)); request));
} }
void DevToolsHttpProtocolHandler::OnWebSocketMessage( void DevToolsHttpHandlerImpl::OnWebSocketMessage(
int connection_id, int connection_id,
const std::string& data) { const std::string& data) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, BrowserThread::UI,
FROM_HERE, FROM_HERE,
base::Bind( base::Bind(
&DevToolsHttpProtocolHandler::OnWebSocketMessageUI, &DevToolsHttpHandlerImpl::OnWebSocketMessageUI,
this, this,
connection_id, connection_id,
data)); data));
} }
void DevToolsHttpProtocolHandler::OnClose(int connection_id) { void DevToolsHttpHandlerImpl::OnClose(int connection_id) {
ConnectionToRequestsMap::iterator it = ConnectionToRequestsMap::iterator it =
connection_to_requests_io_.find(connection_id); connection_to_requests_io_.find(connection_id);
if (it != connection_to_requests_io_.end()) { if (it != connection_to_requests_io_.end()) {
...@@ -256,7 +254,7 @@ void DevToolsHttpProtocolHandler::OnClose(int connection_id) { ...@@ -256,7 +254,7 @@ void DevToolsHttpProtocolHandler::OnClose(int connection_id) {
BrowserThread::UI, BrowserThread::UI,
FROM_HERE, FROM_HERE,
base::Bind( base::Bind(
&DevToolsHttpProtocolHandler::OnCloseUI, &DevToolsHttpHandlerImpl::OnCloseUI,
this, this,
connection_id)); connection_id));
} }
...@@ -273,10 +271,10 @@ struct PageInfo ...@@ -273,10 +271,10 @@ struct PageInfo
typedef std::vector<PageInfo> PageList; typedef std::vector<PageInfo> PageList;
static PageList GeneratePageList( static PageList GeneratePageList(
DevToolsHttpProtocolHandler::Delegate* delegate, DevToolsHttpHandlerDelegate* delegate,
int connection_id, int connection_id,
const net::HttpServerRequestInfo& info) { const net::HttpServerRequestInfo& info) {
typedef DevToolsHttpProtocolHandler::InspectableTabs Tabs; typedef DevToolsHttpHandlerDelegate::InspectableTabs Tabs;
Tabs inspectable_tabs = delegate->GetInspectableTabs(); Tabs inspectable_tabs = delegate->GetInspectableTabs();
PageList page_list; PageList page_list;
...@@ -306,7 +304,7 @@ static PageList GeneratePageList( ...@@ -306,7 +304,7 @@ static PageList GeneratePageList(
return page_list; return page_list;
} }
void DevToolsHttpProtocolHandler::OnJsonRequestUI( void DevToolsHttpHandlerImpl::OnJsonRequestUI(
int connection_id, int connection_id,
const net::HttpServerRequestInfo& info) { const net::HttpServerRequestInfo& info) {
PageList page_list = GeneratePageList(delegate_.get(), PageList page_list = GeneratePageList(delegate_.get(),
...@@ -340,7 +338,7 @@ void DevToolsHttpProtocolHandler::OnJsonRequestUI( ...@@ -340,7 +338,7 @@ void DevToolsHttpProtocolHandler::OnJsonRequestUI(
Send200(connection_id, response, "application/json; charset=UTF-8"); Send200(connection_id, response, "application/json; charset=UTF-8");
} }
void DevToolsHttpProtocolHandler::OnWebSocketRequestUI( void DevToolsHttpHandlerImpl::OnWebSocketRequestUI(
int connection_id, int connection_id,
const net::HttpServerRequestInfo& request) { const net::HttpServerRequestInfo& request) {
std::string prefix = "/devtools/page/"; std::string prefix = "/devtools/page/";
...@@ -379,7 +377,7 @@ void DevToolsHttpProtocolHandler::OnWebSocketRequestUI( ...@@ -379,7 +377,7 @@ void DevToolsHttpProtocolHandler::OnWebSocketRequestUI(
AcceptWebSocket(connection_id, request); AcceptWebSocket(connection_id, request);
} }
void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( void DevToolsHttpHandlerImpl::OnWebSocketMessageUI(
int connection_id, int connection_id,
const std::string& data) { const std::string& data) {
ConnectionToClientHostMap::iterator it = ConnectionToClientHostMap::iterator it =
...@@ -391,7 +389,7 @@ void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( ...@@ -391,7 +389,7 @@ void DevToolsHttpProtocolHandler::OnWebSocketMessageUI(
manager->DispatchOnInspectorBackend(it->second, data); manager->DispatchOnInspectorBackend(it->second, data);
} }
void DevToolsHttpProtocolHandler::OnCloseUI(int connection_id) { void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) {
ConnectionToClientHostMap::iterator it = ConnectionToClientHostMap::iterator it =
connection_to_client_host_ui_.find(connection_id); connection_to_client_host_ui_.find(connection_id);
if (it != connection_to_client_host_ui_.end()) { if (it != connection_to_client_host_ui_.end()) {
...@@ -403,7 +401,7 @@ void DevToolsHttpProtocolHandler::OnCloseUI(int connection_id) { ...@@ -403,7 +401,7 @@ void DevToolsHttpProtocolHandler::OnCloseUI(int connection_id) {
} }
} }
void DevToolsHttpProtocolHandler::OnResponseStarted(net::URLRequest* request) { void DevToolsHttpHandlerImpl::OnResponseStarted(net::URLRequest* request) {
RequestToSocketMap::iterator it = request_to_connection_io_.find(request); RequestToSocketMap::iterator it = request_to_connection_io_.find(request);
if (it == request_to_connection_io_.end()) if (it == request_to_connection_io_.end())
return; return;
...@@ -435,7 +433,7 @@ void DevToolsHttpProtocolHandler::OnResponseStarted(net::URLRequest* request) { ...@@ -435,7 +433,7 @@ void DevToolsHttpProtocolHandler::OnResponseStarted(net::URLRequest* request) {
OnReadCompleted(request, bytes_read); OnReadCompleted(request, bytes_read);
} }
void DevToolsHttpProtocolHandler::OnReadCompleted(net::URLRequest* request, void DevToolsHttpHandlerImpl::OnReadCompleted(net::URLRequest* request,
int bytes_read) { int bytes_read) {
RequestToSocketMap::iterator it = request_to_connection_io_.find(request); RequestToSocketMap::iterator it = request_to_connection_io_.find(request);
if (it == request_to_connection_io_.end()) if (it == request_to_connection_io_.end())
...@@ -461,29 +459,30 @@ void DevToolsHttpProtocolHandler::OnReadCompleted(net::URLRequest* request, ...@@ -461,29 +459,30 @@ void DevToolsHttpProtocolHandler::OnReadCompleted(net::URLRequest* request,
} }
} }
DevToolsHttpProtocolHandler::DevToolsHttpProtocolHandler( DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl(
const std::string& ip, const std::string& ip,
int port, int port,
const std::string& frontend_host, const std::string& frontend_host,
Delegate* delegate) DevToolsHttpHandlerDelegate* delegate)
: ip_(ip), : ip_(ip),
port_(port), port_(port),
overridden_frontend_url_(frontend_host), overridden_frontend_url_(frontend_host),
delegate_(delegate) { delegate_(delegate),
ALLOW_THIS_IN_INITIALIZER_LIST(protect_ptr_(this)) {
if (overridden_frontend_url_.empty()) if (overridden_frontend_url_.empty())
overridden_frontend_url_ = "/devtools/devtools.html"; overridden_frontend_url_ = "/devtools/devtools.html";
} }
void DevToolsHttpProtocolHandler::Init() { void DevToolsHttpHandlerImpl::Init() {
server_ = new net::HttpServer(ip_, port_, this); server_ = new net::HttpServer(ip_, port_, this);
} }
// Run on I/O thread // Run on I/O thread
void DevToolsHttpProtocolHandler::Teardown() { void DevToolsHttpHandlerImpl::Teardown() {
server_ = NULL; server_ = NULL;
} }
void DevToolsHttpProtocolHandler::Bind(net::URLRequest* request, void DevToolsHttpHandlerImpl::Bind(net::URLRequest* request,
int connection_id) { int connection_id) {
request_to_connection_io_[request] = connection_id; request_to_connection_io_[request] = connection_id;
ConnectionToRequestsMap::iterator it = ConnectionToRequestsMap::iterator it =
...@@ -498,7 +497,7 @@ void DevToolsHttpProtocolHandler::Bind(net::URLRequest* request, ...@@ -498,7 +497,7 @@ void DevToolsHttpProtocolHandler::Bind(net::URLRequest* request,
request_to_buffer_io_[request] = new net::IOBuffer(kBufferSize); request_to_buffer_io_[request] = new net::IOBuffer(kBufferSize);
} }
void DevToolsHttpProtocolHandler::RequestCompleted(net::URLRequest* request) { void DevToolsHttpHandlerImpl::RequestCompleted(net::URLRequest* request) {
RequestToSocketMap::iterator it = request_to_connection_io_.find(request); RequestToSocketMap::iterator it = request_to_connection_io_.find(request);
if (it == request_to_connection_io_.end()) if (it == request_to_connection_io_.end())
return; return;
...@@ -512,7 +511,7 @@ void DevToolsHttpProtocolHandler::RequestCompleted(net::URLRequest* request) { ...@@ -512,7 +511,7 @@ void DevToolsHttpProtocolHandler::RequestCompleted(net::URLRequest* request) {
delete request; delete request;
} }
void DevToolsHttpProtocolHandler::Send200(int connection_id, void DevToolsHttpHandlerImpl::Send200(int connection_id,
const std::string& data, const std::string& data,
const std::string& mime_type) { const std::string& mime_type) {
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -524,13 +523,13 @@ void DevToolsHttpProtocolHandler::Send200(int connection_id, ...@@ -524,13 +523,13 @@ void DevToolsHttpProtocolHandler::Send200(int connection_id,
mime_type)); mime_type));
} }
void DevToolsHttpProtocolHandler::Send404(int connection_id) { void DevToolsHttpHandlerImpl::Send404(int connection_id) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::Bind(&net::HttpServer::Send404, server_.get(), connection_id)); base::Bind(&net::HttpServer::Send404, server_.get(), connection_id));
} }
void DevToolsHttpProtocolHandler::Send500(int connection_id, void DevToolsHttpHandlerImpl::Send500(int connection_id,
const std::string& message) { const std::string& message) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
...@@ -538,7 +537,7 @@ void DevToolsHttpProtocolHandler::Send500(int connection_id, ...@@ -538,7 +537,7 @@ void DevToolsHttpProtocolHandler::Send500(int connection_id,
message)); message));
} }
void DevToolsHttpProtocolHandler::AcceptWebSocket( void DevToolsHttpHandlerImpl::AcceptWebSocket(
int connection_id, int connection_id,
const net::HttpServerRequestInfo& request) { const net::HttpServerRequestInfo& request) {
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -546,3 +545,5 @@ void DevToolsHttpProtocolHandler::AcceptWebSocket( ...@@ -546,3 +545,5 @@ void DevToolsHttpProtocolHandler::AcceptWebSocket(
base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(),
connection_id, request)); connection_id, request));
} }
} // namespace content
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_PROTOCOL_HANDLER_H_ #ifndef CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_HANDLER_IMPL_H_
#define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_PROTOCOL_HANDLER_H_ #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_HANDLER_IMPL_H_
#pragma once #pragma once
#include <map> #include <map>
...@@ -14,65 +14,38 @@ ...@@ -14,65 +14,38 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/devtools_http_handler.h"
#include "net/server/http_server.h" #include "net/server/http_server.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
class TabContents; class TabContents;
namespace content {
class DevToolsClientHost;
}
namespace net { namespace net {
class URLRequestContext; class URLRequestContext;
} }
class DevToolsHttpProtocolHandler namespace content {
: public net::HttpServer::Delegate,
public net::URLRequest::Delegate, class DevToolsClientHost;
public base::RefCountedThreadSafe<DevToolsHttpProtocolHandler> {
public:
typedef std::vector<TabContents*> InspectableTabs;
class Delegate {
public:
Delegate() {}
virtual ~Delegate() {}
// Should return the list of inspectable tabs. Called on the UI thread.
virtual InspectableTabs GetInspectableTabs() = 0;
// Should return discovery page HTML that should list available tabs
// and provide attach links. Called on the IO thread.
virtual std::string GetDiscoveryPageHTML() = 0;
// Should return URL request context for issuing requests against devtools
// webui or NULL if no context is available. Called on the IO thread.
virtual net::URLRequestContext* GetURLRequestContext() = 0;
private:
DISALLOW_COPY_AND_ASSIGN(Delegate);
};
// Takes ownership over |delegate|.
CONTENT_EXPORT static scoped_refptr<DevToolsHttpProtocolHandler> Start(
const std::string& ip,
int port,
const std::string& frontend_url,
Delegate* delegate);
// Called from the main thread in order to stop protocol handler.
// Will schedule tear down task on IO thread.
CONTENT_EXPORT void Stop();
class DevToolsHttpHandlerImpl
: public DevToolsHttpHandler,
public base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>,
public net::HttpServer::Delegate,
public net::URLRequest::Delegate {
private: private:
friend class base::RefCountedThreadSafe<DevToolsHttpProtocolHandler>; friend class base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>;
friend class DevToolsHttpHandler;
DevToolsHttpProtocolHandler(const std::string& ip, DevToolsHttpHandlerImpl(const std::string& ip,
int port, int port,
const std::string& frontend_url, const std::string& frontend_url,
Delegate* delegate); DevToolsHttpHandlerDelegate* delegate);
virtual ~DevToolsHttpProtocolHandler(); virtual ~DevToolsHttpHandlerImpl();
void Start(); void Start();
// DevToolsHttpHandler implementation.
virtual void Stop() OVERRIDE;
// net::HttpServer::Delegate implementation. // net::HttpServer::Delegate implementation.
virtual void OnHttpRequest(int connection_id, virtual void OnHttpRequest(int connection_id,
const net::HttpServerRequestInfo& info) OVERRIDE; const net::HttpServerRequestInfo& info) OVERRIDE;
...@@ -126,8 +99,11 @@ class DevToolsHttpProtocolHandler ...@@ -126,8 +99,11 @@ class DevToolsHttpProtocolHandler
typedef std::map<int, content::DevToolsClientHost*> typedef std::map<int, content::DevToolsClientHost*>
ConnectionToClientHostMap; ConnectionToClientHostMap;
ConnectionToClientHostMap connection_to_client_host_ui_; ConnectionToClientHostMap connection_to_client_host_ui_;
scoped_ptr<Delegate> delegate_; scoped_ptr<DevToolsHttpHandlerDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(DevToolsHttpProtocolHandler); scoped_refptr<DevToolsHttpHandlerImpl> protect_ptr_;
DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandlerImpl);
}; };
#endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_PROTOCOL_HANDLER_H_ } // namespace content
#endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_HANDLER_IMPL_H_
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
'public/browser/devtools_agent_host_registry.h', 'public/browser/devtools_agent_host_registry.h',
'public/browser/devtools_client_host.h', 'public/browser/devtools_client_host.h',
'public/browser/devtools_frontend_window_delegate.h', 'public/browser/devtools_frontend_window_delegate.h',
'public/browser/devtools_http_handler.h',
'public/browser/devtools_http_handler_delegate.h',
'public/browser/devtools_manager.h', 'public/browser/devtools_manager.h',
'public/browser/download_manager_delegate.h', 'public/browser/download_manager_delegate.h',
'public/browser/intents_host.h', 'public/browser/intents_host.h',
...@@ -113,8 +115,8 @@ ...@@ -113,8 +115,8 @@
'browser/debugger/devtools_agent_host.h', 'browser/debugger/devtools_agent_host.h',
'browser/debugger/devtools_frontend_host.cc', 'browser/debugger/devtools_frontend_host.cc',
'browser/debugger/devtools_frontend_host.h', 'browser/debugger/devtools_frontend_host.h',
'browser/debugger/devtools_http_protocol_handler.cc', 'browser/debugger/devtools_http_handler_impl.cc',
'browser/debugger/devtools_http_protocol_handler.h', 'browser/debugger/devtools_http_handler_impl.h',
'browser/debugger/devtools_manager_impl.cc', 'browser/debugger/devtools_manager_impl.cc',
'browser/debugger/devtools_manager_impl.h', 'browser/debugger/devtools_manager_impl.h',
'browser/debugger/devtools_netlog_observer.cc', 'browser/debugger/devtools_netlog_observer.cc',
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_HTTP_HANDLER_H_
#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_HTTP_HANDLER_H_
#pragma once
#include <string>
#include "content/common/content_export.h"
namespace content {
class DevToolsHttpHandlerDelegate;
// This class is used for managing DevTools remote debugging server.
// Clients can connect to the specified ip:port and start debugging
// this browser.
class DevToolsHttpHandler {
public:
// Takes ownership over |delegate|.
CONTENT_EXPORT static DevToolsHttpHandler* Start(
const std::string& ip,
int port,
const std::string& frontend_url,
DevToolsHttpHandlerDelegate* delegate);
// Called from the main thread in order to stop protocol handler.
virtual void Stop() = 0;
protected:
virtual ~DevToolsHttpHandler() {}
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_HTTP_HANDLER_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_HTTP_HANDLER_DELEGATE_H_
#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_HTTP_HANDLER_DELEGATE_H_
#pragma once
#include <string>
#include <vector>
class TabContents;
namespace net {
class URLRequestContext;
}
namespace content {
class DevToolsHttpHandlerDelegate {
public:
typedef std::vector<TabContents*> InspectableTabs;
virtual ~DevToolsHttpHandlerDelegate() {}
// Should return the list of inspectable tabs. Called on the UI thread.
virtual InspectableTabs GetInspectableTabs() = 0;
// Should return discovery page HTML that should list available tabs
// and provide attach links. Called on the IO thread.
virtual std::string GetDiscoveryPageHTML() = 0;
// Should return URL request context for issuing requests against devtools
// webui or NULL if no context is available. Called on the IO thread.
virtual net::URLRequestContext* GetURLRequestContext() = 0;
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_HTTP_HANDLER_DELEGATE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment