diff options
23 files changed, 153 insertions, 43 deletions
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 3f255c8..386920b 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -1134,6 +1134,9 @@ const char kReloadKilledTabs[] = "reload-killed-tabs"; // Uses custom front-end URL for the remote debugging. const char kRemoteDebuggingFrontend[] = "remote-debugging-frontend"; +// Enables remote debug over HTTP on the specified port. +const char kRemoteDebuggingPort[] = "remote-debugging-port"; + // Enables print preview in the renderer. This flag is generated internally by // Chrome and does nothing when directly passed to the browser. const char kRendererPrintPreview[] = "renderer-print-preview"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 6539ef3..7ac577f 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -302,6 +302,7 @@ extern const char kRecordStats[]; extern const char kRecordMode[]; extern const char kReloadKilledTabs[]; extern const char kRemoteDebuggingFrontend[]; +extern const char kRemoteDebuggingPort[]; extern const char kRendererPrintPreview[]; extern const char kResetVariationState[]; extern const char kRestoreLastSession[]; diff --git a/content/browser/debugger/devtools_http_handler_impl.cc b/content/browser/debugger/devtools_http_handler_impl.cc index 3982a45..819cd52 100644 --- a/content/browser/debugger/devtools_http_handler_impl.cc +++ b/content/browser/debugger/devtools_http_handler_impl.cc @@ -167,6 +167,17 @@ void DevToolsHttpHandlerImpl::SetRenderViewHostBinding( binding_ = default_binding_.get(); } +GURL DevToolsHttpHandlerImpl::GetFrontendURL(RenderViewHost* render_view_host) { + net::IPEndPoint ip_address; + if (server_->GetLocalAddress(&ip_address)) + return GURL(); + std::string host = ip_address.ToString(); + std::string id = binding_->GetIdentifier(render_view_host); + return GURL(std::string("http://") + + ip_address.ToString() + + GetFrontendURLInternal(id, host)); +} + static std::string PathWithoutParams(const std::string& path) { size_t query_position = path.find("?"); if (query_position != std::string::npos) @@ -377,6 +388,17 @@ DevToolsHttpHandlerImpl::PageList DevToolsHttpHandlerImpl::GeneratePageList() { return page_list; } +std::string DevToolsHttpHandlerImpl::GetFrontendURLInternal( + const std::string rvh_id, + const std::string& host) { + return base::StringPrintf( + "%s%sws=%s/devtools/page/%s", + overridden_frontend_url_.c_str(), + overridden_frontend_url_.find("?") == std::string::npos ? "?" : "&", + host.c_str(), + rvh_id.c_str()); +} + void DevToolsHttpHandlerImpl::OnJsonRequestUI( int connection_id, const net::HttpServerRequestInfo& info) { @@ -396,12 +418,8 @@ void DevToolsHttpHandlerImpl::OnJsonRequestUI( base::StringPrintf("ws://%s/devtools/page/%s", host.c_str(), i->id.c_str())); - std::string devtools_frontend_url = base::StringPrintf( - "%s%sws=%s/devtools/page/%s", - overridden_frontend_url_.c_str(), - overridden_frontend_url_.find("?") == std::string::npos ? "?" : "&", - host.c_str(), - i->id.c_str()); + std::string devtools_frontend_url = GetFrontendURLInternal(i->id.c_str(), + host); page_info->SetString("devtoolsFrontendUrl", devtools_frontend_url); } } diff --git a/content/browser/debugger/devtools_http_handler_impl.h b/content/browser/debugger/devtools_http_handler_impl.h index ef3e864..8d5770f 100644 --- a/content/browser/debugger/devtools_http_handler_impl.h +++ b/content/browser/debugger/devtools_http_handler_impl.h @@ -53,6 +53,7 @@ class DevToolsHttpHandlerImpl virtual void Stop() OVERRIDE; virtual void SetRenderViewHostBinding( RenderViewHostBinding* binding) OVERRIDE; + virtual GURL GetFrontendURL(RenderViewHost* render_view_host) OVERRIDE; // net::HttpServer::Delegate implementation. virtual void OnHttpRequest(int connection_id, @@ -64,15 +65,12 @@ class DevToolsHttpHandlerImpl const std::string& data) OVERRIDE; virtual void OnClose(int connection_id) OVERRIDE; - PageList GeneratePageList(); - - virtual void OnJsonRequestUI(int connection_id, - const net::HttpServerRequestInfo& info); - virtual void OnWebSocketRequestUI(int connection_id, - const net::HttpServerRequestInfo& info); - virtual void OnWebSocketMessageUI(int connection_id, - const std::string& data); - virtual void OnCloseUI(int connection_id); + void OnJsonRequestUI(int connection_id, + const net::HttpServerRequestInfo& info); + void OnWebSocketRequestUI(int connection_id, + const net::HttpServerRequestInfo& info); + 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; @@ -93,6 +91,12 @@ class DevToolsHttpHandlerImpl void AcceptWebSocket(int connection_id, const net::HttpServerRequestInfo& request); + PageList GeneratePageList(); + + // Returns the front end url without the host at the beginning. + std::string GetFrontendURLInternal(const std::string rvh_id, + const std::string& host); + std::string overridden_frontend_url_; scoped_ptr<const net::StreamListenSocketFactory> socket_factory_; scoped_refptr<net::HttpServer> server_; diff --git a/content/public/browser/devtools_http_handler.h b/content/public/browser/devtools_http_handler.h index 8ba316c..4642b54 100644 --- a/content/public/browser/devtools_http_handler.h +++ b/content/public/browser/devtools_http_handler.h @@ -9,6 +9,8 @@ #include "content/common/content_export.h" +class GURL; + namespace net { class StreamListenSocketFactory; class URLRequestContextGetter; @@ -56,6 +58,9 @@ class DevToolsHttpHandler { // default implementation will be used. virtual void SetRenderViewHostBinding(RenderViewHostBinding* binding) = 0; + // Returns the URL for the address to debug |render_view_host|. + virtual GURL GetFrontendURL(RenderViewHost* render_view_host) = 0; + protected: virtual ~DevToolsHttpHandler() {} }; diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index e31a47c..52b3336 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -527,9 +527,6 @@ const char kProcessType[] = "type"; // Register Pepper plugins (see pepper_plugin_registry.cc for its format). const char kRegisterPepperPlugins[] = "register-pepper-plugins"; -// Enables remote debug over HTTP on the specified port. -const char kRemoteDebuggingPort[] = "remote-debugging-port"; - // Causes the renderer process to throw an assertion on launch. const char kRendererAssertTest[] = "renderer-assert-test"; diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index 7c85ac9..38908de 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -166,7 +166,6 @@ CONTENT_EXPORT extern const char kProcessPerSite[]; CONTENT_EXPORT extern const char kProcessPerTab[]; CONTENT_EXPORT extern const char kProcessType[]; CONTENT_EXPORT extern const char kRegisterPepperPlugins[]; -CONTENT_EXPORT extern const char kRemoteDebuggingPort[]; CONTENT_EXPORT extern const char kRendererAssertTest[]; extern const char kRendererCmdPrefix[]; CONTENT_EXPORT extern const char kRendererProcess[]; diff --git a/content/shell/resource.h b/content/shell/resource.h index 849ee86..29bb74d 100644 --- a/content/shell/resource.h +++ b/content/shell/resource.h @@ -12,6 +12,7 @@ #define IDM_EXIT 105 #define IDM_CLOSE_WINDOW 106 #define IDM_NEW_WINDOW 107 +#define IDM_SHOW_DEVELOPER_TOOLS 108 #define IDC_CONTENTSHELL 109 #define IDD_ALERT 130 #define IDD_CONFIRM 131 diff --git a/content/shell/shell.cc b/content/shell/shell.cc index a481a68..7fe9722 100644 --- a/content/shell/shell.cc +++ b/content/shell/shell.cc @@ -8,8 +8,10 @@ #include "base/command_line.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/notification_details.h" @@ -17,6 +19,9 @@ #include "content/public/browser/notification_types.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" +#include "content/shell/shell_browser_main_parts.h" +#include "content/shell/shell_content_browser_client.h" +#include "content/shell/shell_devtools_delegate.h" #include "content/shell/shell_javascript_dialog_creator.h" #include "content/shell/shell_messages.h" #include "content/shell/shell_switches.h" @@ -151,6 +156,19 @@ void Shell::UpdateNavigationControls() { PlatformEnableUIControl(STOP_BUTTON, web_contents_->IsLoading()); } +void Shell::ShowDevTools() { + ShellContentBrowserClient* browser_client = + static_cast<ShellContentBrowserClient*>( + GetContentClient()->browser()); + ShellDevToolsDelegate* delegate = + browser_client->shell_browser_main_parts()->devtools_delegate(); + GURL url = delegate->devtools_http_handler()->GetFrontendURL( + web_contents()->GetRenderViewHost()); + CreateNewWindow( + web_contents()->GetBrowserContext(), + url, NULL, MSG_ROUTING_NONE, NULL); +} + gfx::NativeView Shell::GetContentView() { if (!web_contents_.get()) return NULL; diff --git a/content/shell/shell.h b/content/shell/shell.h index 12228aa..2332c45 100644 --- a/content/shell/shell.h +++ b/content/shell/shell.h @@ -58,6 +58,7 @@ class Shell : public WebContentsDelegate, void Stop(); void UpdateNavigationControls(); void Close(); + void ShowDevTools(); // Do one time initialization at application startup. static void PlatformInitialize(); diff --git a/content/shell/shell.rc b/content/shell/shell.rc index 2652573..0ea80bf 100644 --- a/content/shell/shell.rc +++ b/content/shell/shell.rc @@ -30,6 +30,10 @@ BEGIN MENUITEM "&Close Window", IDM_CLOSE_WINDOW MENUITEM "E&xit", IDM_EXIT END + POPUP "&Debug" + BEGIN + MENUITEM "&Show Developer Tools...", IDM_SHOW_DEVELOPER_TOOLS + END END diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h index 52814c2..76a1a86 100644 --- a/content/shell/shell_browser_context.h +++ b/content/shell/shell_browser_context.h @@ -16,7 +16,6 @@ namespace content { class DownloadManagerDelegate; class ResourceContext; -class ShellBrowserMainParts; class ShellDownloadManagerDelegate; class ShellBrowserContext : public BrowserContext { diff --git a/content/shell/shell_browser_main_parts.cc b/content/shell/shell_browser_main_parts.cc index 7ea1728..ac5471f 100644 --- a/content/shell/shell_browser_main_parts.cc +++ b/content/shell/shell_browser_main_parts.cc @@ -7,7 +7,6 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/message_loop.h" -#include "base/string_number_conversions.h" #include "base/threading/thread.h" #include "base/threading/thread_restrictions.h" #include "content/public/common/content_switches.h" @@ -82,22 +81,10 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { #if defined(OS_ANDROID) devtools_delegate_ = new ShellDevToolsDelegate( - 0, // On android the port number isn't used. browser_context_->GetRequestContext()); #else - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { - std::string port_str = - command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); - int port; - if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) { - devtools_delegate_ = new ShellDevToolsDelegate( - port, - browser_context_->GetRequestContext()); - } else { - DLOG(WARNING) << "Invalid http debugger port number " << port; - } - } + devtools_delegate_ = new ShellDevToolsDelegate( + browser_context_->GetRequestContext()); #endif if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index e3ffe85..dfcba1a 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -44,6 +44,9 @@ class ShellContentBrowserClient : public ContentBrowserClient { ShellResourceDispatcherHostDelegate* resource_dispatcher_host_delegate() { return resource_dispatcher_host_delegate_.get(); } + ShellBrowserMainParts* shell_browser_main_parts() { + return shell_browser_main_parts_; + } private: scoped_ptr<ShellResourceDispatcherHostDelegate> diff --git a/content/shell/shell_devtools_delegate.cc b/content/shell/shell_devtools_delegate.cc index 58427da..27a2620 100644 --- a/content/shell/shell_devtools_delegate.cc +++ b/content/shell/shell_devtools_delegate.cc @@ -4,8 +4,6 @@ #include "content/shell/shell_devtools_delegate.h" -#include <algorithm> - #include "content/public/browser/devtools_http_handler.h" #include "grit/shell_resources.h" #include "net/base/tcp_listen_socket.h" @@ -16,11 +14,10 @@ namespace content { ShellDevToolsDelegate::ShellDevToolsDelegate( - int port, net::URLRequestContextGetter* context_getter) : context_getter_(context_getter) { devtools_http_handler_ = DevToolsHttpHandler::Start( - new net::TCPListenSocketFactory("127.0.0.1", port), + new net::TCPListenSocketFactory("127.0.0.1", 0), "", context_getter_, this); diff --git a/content/shell/shell_devtools_delegate.h b/content/shell/shell_devtools_delegate.h index 569eb3a..9cf3d13 100644 --- a/content/shell/shell_devtools_delegate.h +++ b/content/shell/shell_devtools_delegate.h @@ -21,7 +21,7 @@ class DevToolsHttpHandler; class ShellDevToolsDelegate : public DevToolsHttpHandlerDelegate { public: - ShellDevToolsDelegate(int port, net::URLRequestContextGetter* context_getter); + explicit ShellDevToolsDelegate(net::URLRequestContextGetter* context_getter); virtual ~ShellDevToolsDelegate(); // Stops http server. @@ -32,6 +32,10 @@ class ShellDevToolsDelegate : public DevToolsHttpHandlerDelegate { virtual bool BundlesFrontendResources() OVERRIDE; virtual std::string GetFrontendResourcesBaseURL() OVERRIDE; + DevToolsHttpHandler* devtools_http_handler() { + return devtools_http_handler_; + } + private: net::URLRequestContextGetter* context_getter_; DevToolsHttpHandler* devtools_http_handler_; diff --git a/content/shell/shell_devtools_delegate_android.cc b/content/shell/shell_devtools_delegate_android.cc index fd87fb3..a9f69bd 100644 --- a/content/shell/shell_devtools_delegate_android.cc +++ b/content/shell/shell_devtools_delegate_android.cc @@ -28,7 +28,6 @@ const char kFrontEndURL[] = namespace content { ShellDevToolsDelegate::ShellDevToolsDelegate( - int port, net::URLRequestContextGetter* context_getter) : context_getter_(context_getter) { devtools_http_handler_ = DevToolsHttpHandler::Start( diff --git a/content/shell/shell_gtk.cc b/content/shell/shell_gtk.cc index 0f9121b..a09b639 100644 --- a/content/shell/shell_gtk.cc +++ b/content/shell/shell_gtk.cc @@ -23,6 +23,40 @@ namespace content { +namespace { + +// Callback for Debug > Show web inspector... menu item. +gboolean ShowWebInspectorActivated(GtkWidget* widget, Shell* shell) { + shell->ShowDevTools(); + return FALSE; // Don't stop this message. +} + +GtkWidget* AddMenuEntry(GtkWidget* menu_widget, const char* text, + GCallback callback, Shell* shell) { + GtkWidget* entry = gtk_menu_item_new_with_label(text); + g_signal_connect(entry, "activate", callback, shell); + gtk_menu_shell_append(GTK_MENU_SHELL(menu_widget), entry); + return entry; +} + +GtkWidget* CreateMenu(GtkWidget* menu_bar, const char* text) { + GtkWidget* menu_widget = gtk_menu_new(); + GtkWidget* menu_header = gtk_menu_item_new_with_label(text); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_header), menu_widget); + gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), menu_header); + return menu_widget; +} + +GtkWidget* CreateMenuBar(Shell* shell) { + GtkWidget* menu_bar = gtk_menu_bar_new(); + GtkWidget* debug_menu = CreateMenu(menu_bar, "Debug"); + AddMenuEntry(debug_menu, "Show web inspector...", + G_CALLBACK(ShowWebInspectorActivated), shell); + return menu_bar; +} + +} // namespace + void Shell::PlatformInitialize() { } @@ -73,6 +107,10 @@ void Shell::PlatformCreateWindow(int width, int height) { vbox_ = gtk_vbox_new(FALSE, 0); + // Create the menu bar. + GtkWidget* menu_bar = CreateMenuBar(this); + gtk_box_pack_start(GTK_BOX(vbox_), menu_bar, FALSE, FALSE, 0); + // Create the object that mediates accelerators. GtkAccelGroup* accel_group = gtk_accel_group_new(); gtk_window_add_accel_group(GTK_WINDOW(window_), accel_group); diff --git a/content/shell/shell_win.cc b/content/shell/shell_win.cc index d33ea21..6998ccd 100644 --- a/content/shell/shell_win.cc +++ b/content/shell/shell_win.cc @@ -236,6 +236,9 @@ LRESULT CALLBACK Shell::WndProc(HWND hwnd, UINT message, WPARAM wParam, case IDM_EXIT: PlatformExit(); break; + case IDM_SHOW_DEVELOPER_TOOLS: + shell->ShowDevTools(); + break; case IDC_NAV_BACK: shell->GoBackOrForward(-1); break; diff --git a/net/base/stream_listen_socket.cc b/net/base/stream_listen_socket.cc index fb28c66..2382668 100644 --- a/net/base/stream_listen_socket.cc +++ b/net/base/stream_listen_socket.cc @@ -24,6 +24,8 @@ #include "base/sys_byteorder.h" #include "base/threading/platform_thread.h" #include "build/build_config.h" +#include "net/base/ip_endpoint.h" +#include "net/base/net_errors.h" #include "net/base/net_util.h" using std::string; @@ -115,6 +117,21 @@ void StreamListenSocket::Send(const string& str, bool append_linefeed) { Send(str.data(), static_cast<int>(str.length()), append_linefeed); } +int StreamListenSocket::GetLocalAddress(IPEndPoint* address) { + SockaddrStorage storage; + if (getsockname(socket_, storage.addr, &storage.addr_len)) { +#if defined(OS_WIN) + int err = WSAGetLastError(); +#else + int err = errno; +#endif + return MapSystemError(err); + } + if (!address->FromSockAddr(storage.addr, storage.addr_len)) + return ERR_FAILED; + return OK; +} + SocketDescriptor StreamListenSocket::AcceptSocket() { SocketDescriptor conn = HANDLE_EINTR(accept(socket_, NULL, NULL)); if (conn == kInvalidSocket) diff --git a/net/base/stream_listen_socket.h b/net/base/stream_listen_socket.h index e1dddbb..54e9d2b 100644 --- a/net/base/stream_listen_socket.h +++ b/net/base/stream_listen_socket.h @@ -47,6 +47,8 @@ typedef SOCKET SocketDescriptor; namespace net { +class IPEndPoint; + class NET_EXPORT StreamListenSocket : public base::RefCountedThreadSafe<StreamListenSocket>, #if defined(OS_WIN) @@ -79,6 +81,9 @@ class NET_EXPORT StreamListenSocket void Send(const char* bytes, int len, bool append_linefeed = false); void Send(const std::string& str, bool append_linefeed = false); + // Copies the local address to |address|. Returns a network error code. + int GetLocalAddress(IPEndPoint* address); + static const SocketDescriptor kInvalidSocket; static const int kSocketError; diff --git a/net/server/http_server.cc b/net/server/http_server.cc index 2e12d17..9582487 100644 --- a/net/server/http_server.cc +++ b/net/server/http_server.cc @@ -83,8 +83,7 @@ void HttpServer::Send500(int connection_id, const std::string& message) { connection->Send500(message); } -void HttpServer::Close(int connection_id) -{ +void HttpServer::Close(int connection_id) { HttpConnection* connection = FindConnection(connection_id); if (connection == NULL) return; @@ -94,6 +93,10 @@ void HttpServer::Close(int connection_id) DidClose(connection->socket_); } +int HttpServer::GetLocalAddress(IPEndPoint* address) { + return server_->GetLocalAddress(address); +} + void HttpServer::DidAccept(StreamListenSocket* server, StreamListenSocket* socket) { HttpConnection* connection = new HttpConnection(this, socket); diff --git a/net/server/http_server.h b/net/server/http_server.h index d9404c4..bc6a290 100644 --- a/net/server/http_server.h +++ b/net/server/http_server.h @@ -16,6 +16,7 @@ namespace net { class HttpConnection; class HttpServerRequestInfo; +class IPEndPoint; class WebSocket; class HttpServer : public StreamListenSocket::Delegate, @@ -53,6 +54,9 @@ class HttpServer : public StreamListenSocket::Delegate, void Send500(int connection_id, const std::string& message); void Close(int connection_id); + // Copies the local address to |address|. Returns a network error code. + int GetLocalAddress(IPEndPoint* address); + // ListenSocketDelegate virtual void DidAccept(StreamListenSocket* server, StreamListenSocket* socket) OVERRIDE; |