diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-22 09:57:20 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-22 09:57:20 +0000 |
commit | 8262245d384be025f13e2a5b3a03b7e5c98374ce (patch) | |
tree | b92377c4ce653f721bf7339c8fa33f7a7049ce67 /content | |
parent | 2469a22063c3539147f55fe899a8dabc12901c01 (diff) | |
download | chromium_src-8262245d384be025f13e2a5b3a03b7e5c98374ce.zip chromium_src-8262245d384be025f13e2a5b3a03b7e5c98374ce.tar.gz chromium_src-8262245d384be025f13e2a5b3a03b7e5c98374ce.tar.bz2 |
DevTools: move DevToolsAgent/Client into content.
BUG=84078
TEST=
Review URL: http://codereview.chromium.org/7461019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93596 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/renderer_host/browser_render_process_host.cc | 1 | ||||
-rw-r--r-- | content/common/content_switches.cc | 3 | ||||
-rw-r--r-- | content/common/content_switches.h | 1 | ||||
-rw-r--r-- | content/content_renderer.gypi | 6 | ||||
-rw-r--r-- | content/renderer/devtools_agent.cc | 214 | ||||
-rw-r--r-- | content/renderer/devtools_agent.h | 76 | ||||
-rw-r--r-- | content/renderer/devtools_agent_filter.cc | 99 | ||||
-rw-r--r-- | content/renderer/devtools_agent_filter.h | 54 | ||||
-rw-r--r-- | content/renderer/devtools_client.cc | 96 | ||||
-rw-r--r-- | content/renderer/devtools_client.h | 65 | ||||
-rw-r--r-- | content/renderer/render_thread.cc | 7 | ||||
-rw-r--r-- | content/renderer/render_thread.h | 2 | ||||
-rw-r--r-- | content/renderer/render_view.cc | 3 |
13 files changed, 627 insertions, 0 deletions
diff --git a/content/browser/renderer_host/browser_render_process_host.cc b/content/browser/renderer_host/browser_render_process_host.cc index 7c71dc2..d93f0f2 100644 --- a/content/browser/renderer_host/browser_render_process_host.cc +++ b/content/browser/renderer_host/browser_render_process_host.cc @@ -576,6 +576,7 @@ void BrowserRenderProcessHost::PropagateBrowserCommandLineToRenderer( switches::kPpapiOutOfProcess, switches::kRecordMode, switches::kRegisterPepperPlugins, + switches::kRemoteShellPort, switches::kRendererAssertTest, #if !defined(OFFICIAL_BUILD) switches::kRendererCheckFalseTest, diff --git a/content/common/content_switches.cc b/content/common/content_switches.cc index 9d98571..20dca2a 100644 --- a/content/common/content_switches.cc +++ b/content/common/content_switches.cc @@ -371,6 +371,9 @@ const char kProfileImportProcess[] = "profile-import"; // Register Pepper plugins (see pepper_plugin_registry.cc for its format). const char kRegisterPepperPlugins[] = "register-pepper-plugins"; +// Enable remote debug / automation shell on the specified port. +const char kRemoteShellPort[] = "remote-shell-port"; + // Causes the renderer process to throw an assertion on launch. const char kRendererAssertTest[] = "renderer-assert-test"; diff --git a/content/common/content_switches.h b/content/common/content_switches.h index 0e24440..a61a35b 100644 --- a/content/common/content_switches.h +++ b/content/common/content_switches.h @@ -120,6 +120,7 @@ extern const char kProcessType[]; extern const char kProfileImportProcess[]; extern const char kRecordMode[]; extern const char kRegisterPepperPlugins[]; +extern const char kRemoteShellPort[]; extern const char kRendererAssertTest[]; extern const char kRendererCmdPrefix[]; extern const char kRendererCrashTest[]; diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index 6c3c2bf..64c2f8a 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -36,6 +36,12 @@ 'renderer/content_renderer_client.h', 'renderer/device_orientation_dispatcher.cc', 'renderer/device_orientation_dispatcher.h', + 'renderer/devtools_agent.cc', + 'renderer/devtools_agent.h', + 'renderer/devtools_agent_filter.cc', + 'renderer/devtools_agent_filter.h', + 'renderer/devtools_client.cc', + 'renderer/devtools_client.h', 'renderer/external_popup_menu.cc', 'renderer/external_popup_menu.h', 'renderer/geolocation_dispatcher.cc', diff --git a/content/renderer/devtools_agent.cc b/content/renderer/devtools_agent.cc new file mode 100644 index 0000000..b154813 --- /dev/null +++ b/content/renderer/devtools_agent.cc @@ -0,0 +1,214 @@ +// 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. + +#include "content/renderer/devtools_agent.h" + +#include <map> + +#include "base/command_line.h" +#include "base/message_loop.h" +#include "base/process.h" +#include "base/string_number_conversions.h" +#include "content/common/content_switches.h" +#include "content/renderer/devtools_agent_filter.h" +#include "content/renderer/devtools_client.h" +#include "content/common/devtools_messages.h" +#include "content/common/view_messages.h" +#include "content/renderer/render_view.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" + +using WebKit::WebDevToolsAgent; +using WebKit::WebDevToolsAgentClient; +using WebKit::WebPoint; +using WebKit::WebString; +using WebKit::WebCString; +using WebKit::WebVector; +using WebKit::WebView; + +namespace { + +class WebKitClientMessageLoopImpl + : public WebDevToolsAgentClient::WebKitClientMessageLoop { + public: + WebKitClientMessageLoopImpl() : message_loop_(MessageLoop::current()) { } + virtual ~WebKitClientMessageLoopImpl() { + message_loop_ = NULL; + } + virtual void run() { + bool old_state = message_loop_->NestableTasksAllowed(); + message_loop_->SetNestableTasksAllowed(true); + message_loop_->Run(); + message_loop_->SetNestableTasksAllowed(old_state); + } + virtual void quitNow() { + message_loop_->QuitNow(); + } + private: + MessageLoop* message_loop_; +}; + +} // namespace + +// static +std::map<int, DevToolsAgent*> DevToolsAgent::agent_for_routing_id_; + +DevToolsAgent::DevToolsAgent(RenderView* render_view) + : RenderViewObserver(render_view) { + agent_for_routing_id_[routing_id()] = this; + + CommandLine* cmd = CommandLine::ForCurrentProcess(); + expose_v8_debugger_protocol_ = cmd->HasSwitch(switches::kRemoteShellPort); + + render_view->webview()->setDevToolsAgentClient(this); + render_view->webview()->devToolsAgent()->setProcessId( + base::Process::Current().pid()); +} + +DevToolsAgent::~DevToolsAgent() { + agent_for_routing_id_.erase(routing_id()); +} + +// Called on the Renderer thread. +bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) + IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach) + IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach) + IPC_MESSAGE_HANDLER(DevToolsAgentMsg_FrontendLoaded, OnFrontendLoaded) + IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, + OnDispatchOnInspectorBackend) + IPC_MESSAGE_HANDLER(DevToolsAgentMsg_InspectElement, OnInspectElement) + IPC_MESSAGE_HANDLER(DevToolsMsg_SetupDevToolsClient, OnSetupDevToolsClient) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + if (message.type() == ViewMsg_Navigate::ID) + OnNavigate(); // Don't want to swallow the message. + + return handled; +} + +void DevToolsAgent::sendMessageToInspectorFrontend( + const WebKit::WebString& message) { + Send(new DevToolsHostMsg_ForwardToClient( + routing_id(), + DevToolsClientMsg_DispatchOnInspectorFrontend(MSG_ROUTING_NONE, + message.utf8()))); +} + +void DevToolsAgent::sendDebuggerOutput(const WebKit::WebString& data) { + Send(new DevToolsHostMsg_ForwardToClient( + routing_id(), + DevToolsClientMsg_DebuggerOutput(MSG_ROUTING_NONE, data.utf8()))); +} + +int DevToolsAgent::hostIdentifier() { + return routing_id(); +} + +void DevToolsAgent::runtimeFeatureStateChanged( + const WebKit::WebString& feature, + bool enabled) { + Send(new DevToolsHostMsg_RuntimePropertyChanged( + routing_id(), + feature.utf8(), + enabled ? "true" : "false")); +} + +void DevToolsAgent::runtimePropertyChanged( + const WebKit::WebString& name, + const WebKit::WebString& value) { + Send(new DevToolsHostMsg_RuntimePropertyChanged( + routing_id(), + name.utf8(), + value.utf8())); +} + +WebKit::WebDevToolsAgentClient::WebKitClientMessageLoop* + DevToolsAgent::createClientMessageLoop() { + return new WebKitClientMessageLoopImpl(); +} + +bool DevToolsAgent::exposeV8DebuggerProtocol() { + return expose_v8_debugger_protocol_; +} + +void DevToolsAgent::clearBrowserCache() { + Send(new DevToolsHostMsg_ClearBrowserCache(routing_id())); +} + +void DevToolsAgent::clearBrowserCookies() { + Send(new DevToolsHostMsg_ClearBrowserCookies(routing_id())); +} + +// static +DevToolsAgent* DevToolsAgent::FromHostId(int host_id) { + std::map<int, DevToolsAgent*>::iterator it = + agent_for_routing_id_.find(host_id); + if (it != agent_for_routing_id_.end()) { + return it->second; + } + return NULL; +} + +void DevToolsAgent::OnAttach( + const DevToolsRuntimeProperties& runtime_properties) { + WebDevToolsAgent* web_agent = GetWebAgent(); + if (web_agent) { + web_agent->attach(); + for (DevToolsRuntimeProperties::const_iterator it = + runtime_properties.begin(); + it != runtime_properties.end(); ++it) { + web_agent->setRuntimeProperty(WebString::fromUTF8(it->first), + WebString::fromUTF8(it->second)); + } + } +} + +void DevToolsAgent::OnDetach() { + WebDevToolsAgent* web_agent = GetWebAgent(); + if (web_agent) + web_agent->detach(); +} + +void DevToolsAgent::OnFrontendLoaded() { + WebDevToolsAgent* web_agent = GetWebAgent(); + if (web_agent) + web_agent->frontendLoaded(); +} + +void DevToolsAgent::OnDispatchOnInspectorBackend(const std::string& message) { + WebDevToolsAgent* web_agent = GetWebAgent(); + if (web_agent) + web_agent->dispatchOnInspectorBackend(WebString::fromUTF8(message)); +} + +void DevToolsAgent::OnInspectElement(int x, int y) { + WebDevToolsAgent* web_agent = GetWebAgent(); + if (web_agent) { + web_agent->attach(); + web_agent->inspectElementAt(WebPoint(x, y)); + } +} + +void DevToolsAgent::OnNavigate() { + WebDevToolsAgent* web_agent = GetWebAgent(); + if (web_agent) { + web_agent->didNavigate(); + } +} + +void DevToolsAgent::OnSetupDevToolsClient() { + new DevToolsClient(render_view()); +} + +WebDevToolsAgent* DevToolsAgent::GetWebAgent() { + WebView* web_view = render_view()->webview(); + if (!web_view) + return NULL; + return web_view->devToolsAgent(); +} diff --git a/content/renderer/devtools_agent.h b/content/renderer/devtools_agent.h new file mode 100644 index 0000000..a1693b5 --- /dev/null +++ b/content/renderer/devtools_agent.h @@ -0,0 +1,76 @@ +// 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_RENDERER_DEVTOOLS_AGENT_H_ +#define CONTENT_RENDERER_DEVTOOLS_AGENT_H_ +#pragma once + +#include <map> +#include <string> + +#include "base/basictypes.h" +#include "content/renderer/render_view_observer.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgentClient.h" + +namespace WebKit { +class WebDevToolsAgent; +} + +struct DevToolsMessageData; + +typedef std::map<std::string, std::string> DevToolsRuntimeProperties; + +// DevToolsAgent belongs to the inspectable RenderView and provides Glue's +// agents with the communication capabilities. All messages from/to Glue's +// agents infrastructure are flowing through this communication agent. +// There is a corresponding DevToolsClient object on the client side. +class DevToolsAgent : public RenderViewObserver, + public WebKit::WebDevToolsAgentClient { + public: + explicit DevToolsAgent(RenderView* render_view); + virtual ~DevToolsAgent(); + + // Returns agent instance for its host id. + static DevToolsAgent* FromHostId(int host_id); + + WebKit::WebDevToolsAgent* GetWebAgent(); + + private: + friend class DevToolsAgentFilter; + + // RenderView::Observer implementation. + virtual bool OnMessageReceived(const IPC::Message& message); + + // WebDevToolsAgentClient implementation + virtual void sendMessageToInspectorFrontend(const WebKit::WebString& data); + virtual void sendDebuggerOutput(const WebKit::WebString& data); + + virtual int hostIdentifier(); + virtual void runtimeFeatureStateChanged(const WebKit::WebString& feature, + bool enabled); + virtual void runtimePropertyChanged(const WebKit::WebString& name, + const WebKit::WebString& value); + virtual WebKit::WebDevToolsAgentClient::WebKitClientMessageLoop* + createClientMessageLoop(); + virtual bool exposeV8DebuggerProtocol(); + virtual void clearBrowserCache(); + virtual void clearBrowserCookies(); + + void OnAttach(const DevToolsRuntimeProperties& runtime_properties); + void OnDetach(); + void OnFrontendLoaded(); + void OnDispatchOnInspectorBackend(const std::string& message); + void OnInspectElement(int x, int y); + void OnSetApuAgentEnabled(bool enabled); + void OnNavigate(); + void OnSetupDevToolsClient(); + + static std::map<int, DevToolsAgent*> agent_for_routing_id_; + + bool expose_v8_debugger_protocol_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsAgent); +}; + +#endif // CONTENT_RENDERER_DEVTOOLS_AGENT_H_ diff --git a/content/renderer/devtools_agent_filter.cc b/content/renderer/devtools_agent_filter.cc new file mode 100644 index 0000000..4890a36 --- /dev/null +++ b/content/renderer/devtools_agent_filter.cc @@ -0,0 +1,99 @@ +// Copyright (c) 2009 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. + +#include "content/renderer/devtools_agent_filter.h" + +#include "base/message_loop.h" +#include "content/common/devtools_messages.h" +#include "content/renderer/devtools_agent.h" +#include "content/renderer/plugin_channel_host.h" +#include "content/renderer/render_view.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" + +using WebKit::WebDevToolsAgent; +using WebKit::WebString; + +namespace { + +class MessageImpl : public WebDevToolsAgent::MessageDescriptor { + public: + MessageImpl(const std::string& message, int host_id) + : msg(message), + host_id(host_id) {} + virtual ~MessageImpl() {} + virtual WebDevToolsAgent* agent() { + DevToolsAgent* agent = DevToolsAgent::FromHostId(host_id); + if (!agent) + return 0; + return agent->GetWebAgent(); + } + virtual WebString message() { return WebString::fromUTF8(msg); } + private: + std::string msg; + int host_id; +}; + +} + +// static +void DevToolsAgentFilter::DispatchMessageLoop() { + MessageLoop* current = MessageLoop::current(); + bool old_state = current->NestableTasksAllowed(); + current->SetNestableTasksAllowed(true); + current->RunAllPending(); + current->SetNestableTasksAllowed(old_state); +} + +// static +IPC::Channel* DevToolsAgentFilter::channel_ = NULL; +// static +int DevToolsAgentFilter::current_routing_id_ = 0; + +DevToolsAgentFilter::DevToolsAgentFilter() + : message_handled_(false), + render_thread_loop_(MessageLoop::current()) { + WebDevToolsAgent::setMessageLoopDispatchHandler( + &DevToolsAgentFilter::DispatchMessageLoop); +} + +DevToolsAgentFilter::~DevToolsAgentFilter() { +} + +bool DevToolsAgentFilter::OnMessageReceived(const IPC::Message& message) { + // Dispatch debugger commands directly from IO. + message_handled_ = true; + current_routing_id_ = message.routing_id(); + IPC_BEGIN_MESSAGE_MAP(DevToolsAgentFilter, message) + IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebuggerCommand, OnDebuggerCommand) + IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, + OnDispatchOnInspectorBackend) + IPC_MESSAGE_UNHANDLED(message_handled_ = false) + IPC_END_MESSAGE_MAP() + return message_handled_; +} + +void DevToolsAgentFilter::OnFilterAdded(IPC::Channel* channel) { + channel_ = channel; +} + +void DevToolsAgentFilter::OnDebuggerCommand(const std::string& command) { + WebDevToolsAgent::executeDebuggerCommand( + WebString::fromUTF8(command), current_routing_id_); +} + +void DevToolsAgentFilter::OnDispatchOnInspectorBackend( + const std::string& message) { + if (!WebDevToolsAgent::shouldInterruptForMessage( + WebString::fromUTF8(message))) { + message_handled_ = false; + return; + } + WebDevToolsAgent::interruptAndDispatch( + new MessageImpl(message, current_routing_id_)); + + render_thread_loop_->PostTask( + FROM_HERE, + NewRunnableFunction(&WebDevToolsAgent::processPendingMessages)); +} diff --git a/content/renderer/devtools_agent_filter.h b/content/renderer/devtools_agent_filter.h new file mode 100644 index 0000000..0583885 --- /dev/null +++ b/content/renderer/devtools_agent_filter.h @@ -0,0 +1,54 @@ +// Copyright (c) 2010 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_RENDERER_DEVTOOLS_AGENT_FILTER_H_ +#define CONTENT_RENDERER_DEVTOOLS_AGENT_FILTER_H_ +#pragma once + +#include <string> + +#include "ipc/ipc_channel_proxy.h" + +class MessageLoop; +struct DevToolsMessageData; + +// DevToolsAgentFilter is registered as an IPC filter in order to be able to +// dispatch messages while on the IO thread. The reason for that is that while +// debugging, Render thread is being held by the v8 and hence no messages +// are being dispatched there. While holding the thread in a tight loop, +// v8 provides thread-safe Api for controlling debugger. In our case v8's Api +// is being used from this communication agent on the IO thread. +class DevToolsAgentFilter : public IPC::ChannelProxy::MessageFilter { + public: + // There is a single instance of this class instantiated by the RenderThread. + DevToolsAgentFilter(); + virtual ~DevToolsAgentFilter(); + + static void SendRpcMessage(const DevToolsMessageData& data); + + private: + // IPC::ChannelProxy::MessageFilter override. Called on IO thread. + virtual bool OnMessageReceived(const IPC::Message& message); + + virtual void OnFilterAdded(IPC::Channel* channel); + + static void DispatchMessageLoop(); + + // OnDebuggerCommand will be executed in the IO thread so that we can + // handle debug messages even when v8 is stopped. + void OnDebuggerCommand(const std::string& command); + void OnDispatchOnInspectorBackend(const std::string& message); + + bool message_handled_; + MessageLoop* render_thread_loop_; + + // Made static to allow DevToolsAgent to use it for replying directly + // from IO thread. + static int current_routing_id_; + static IPC::Channel* channel_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsAgentFilter); +}; + +#endif // CONTENT_RENDERER_DEVTOOLS_AGENT_FILTER_H_ diff --git a/content/renderer/devtools_client.cc b/content/renderer/devtools_client.cc new file mode 100644 index 0000000..cdebbba --- /dev/null +++ b/content/renderer/devtools_client.cc @@ -0,0 +1,96 @@ +// 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. + +#include "content/renderer/devtools_client.h" + +#include "base/command_line.h" +#include "base/message_loop.h" +#include "base/utf_string_conversions.h" +#include "content/common/content_switches.h" +#include "content/common/devtools_messages.h" +#include "content/renderer/render_thread.h" +#include "content/renderer/render_view.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsFrontend.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "ui/base/ui_base_switches.h" + +using WebKit::WebDevToolsFrontend; +using WebKit::WebString; + +DevToolsClient::DevToolsClient(RenderView* render_view) + : RenderViewObserver(render_view) { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + web_tools_frontend_.reset( + WebDevToolsFrontend::create( + render_view->webview(), + this, + ASCIIToUTF16(command_line.GetSwitchValueASCII(switches::kLang)))); +} + +DevToolsClient::~DevToolsClient() { +} + +void DevToolsClient::SendToAgent(const IPC::Message& tools_agent_message) { + Send(new DevToolsHostMsg_ForwardToAgent(routing_id(), tools_agent_message)); +} + +bool DevToolsClient::OnMessageReceived(const IPC::Message& message) { + DCHECK(RenderThread::current()->message_loop() == MessageLoop::current()); + + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(DevToolsClient, message) + IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, + OnDispatchOnInspectorFrontend) + IPC_MESSAGE_UNHANDLED(handled = false); + IPC_END_MESSAGE_MAP() + + return handled; +} + +void DevToolsClient::sendFrontendLoaded() { + SendToAgent(DevToolsAgentMsg_FrontendLoaded(MSG_ROUTING_NONE)); +} + +void DevToolsClient::sendMessageToBackend(const WebString& message) { + SendToAgent(DevToolsAgentMsg_DispatchOnInspectorBackend(MSG_ROUTING_NONE, + message.utf8())); +} + +void DevToolsClient::sendDebuggerCommandToAgent(const WebString& command) { + SendToAgent(DevToolsAgentMsg_DebuggerCommand(MSG_ROUTING_NONE, + command.utf8())); +} + +void DevToolsClient::activateWindow() { + Send(new DevToolsHostMsg_ActivateWindow(routing_id())); +} + +void DevToolsClient::closeWindow() { + Send(new DevToolsHostMsg_CloseWindow(routing_id())); +} + +void DevToolsClient::requestDockWindow() { + Send(new DevToolsHostMsg_RequestDockWindow(routing_id())); +} + +void DevToolsClient::requestUndockWindow() { + Send(new DevToolsHostMsg_RequestUndockWindow(routing_id())); +} + +void DevToolsClient::saveAs(const WebKit::WebString& file_name, + const WebKit::WebString& content) { + Send(new DevToolsHostMsg_SaveAs(routing_id(), + file_name.utf8(), + content.utf8())); +} + +void DevToolsClient::OnDispatchOnInspectorFrontend(const std::string& message) { + web_tools_frontend_->dispatchOnInspectorFrontend( + WebString::fromUTF8(message)); +} + +bool DevToolsClient::shouldHideScriptsPanel() { + CommandLine* cmd = CommandLine::ForCurrentProcess(); + return cmd->HasSwitch(switches::kRemoteShellPort); +} diff --git a/content/renderer/devtools_client.h b/content/renderer/devtools_client.h new file mode 100644 index 0000000..d00d33f --- /dev/null +++ b/content/renderer/devtools_client.h @@ -0,0 +1,65 @@ +// 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_RENDERER_DEVTOOLS_CLIENT_H_ +#define CONTENT_RENDERER_DEVTOOLS_CLIENT_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "content/renderer/render_view_observer.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsFrontendClient.h" + +class MessageLoop; + +namespace WebKit { +class WebDevToolsFrontend; +class WebString; +} + +struct DevToolsMessageData; + +// Developer tools UI end of communication channel between the render process of +// the page being inspected and tools UI renderer process. All messages will +// go through browser process. On the side of the inspected page there's +// corresponding DevToolsAgent object. +// TODO(yurys): now the client is almost empty later it will delegate calls to +// code in glue +class DevToolsClient : public RenderViewObserver, + public WebKit::WebDevToolsFrontendClient { + public: + explicit DevToolsClient(RenderView* render_view); + virtual ~DevToolsClient(); + + private: + // RenderView::Observer implementation. + virtual bool OnMessageReceived(const IPC::Message& message); + + // WebDevToolsFrontendClient implementation + virtual void sendFrontendLoaded(); + virtual void sendMessageToBackend(const WebKit::WebString&); + virtual void sendDebuggerCommandToAgent(const WebKit::WebString& command); + + virtual void activateWindow(); + virtual void closeWindow(); + virtual void requestDockWindow(); + virtual void requestUndockWindow(); + virtual void saveAs(const WebKit::WebString& file_name, + const WebKit::WebString& content); + + virtual bool shouldHideScriptsPanel(); + + void OnDispatchOnInspectorFrontend(const std::string& message); + + // Sends message to DevToolsAgent. + void SendToAgent(const IPC::Message& tools_agent_message); + + scoped_ptr<WebKit::WebDevToolsFrontend> web_tools_frontend_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsClient); +}; + +#endif // CONTENT_RENDERER_DEVTOOLS_CLIENT_H_ diff --git a/content/renderer/render_thread.cc b/content/renderer/render_thread.cc index 81caa2d..ba95709 100644 --- a/content/renderer/render_thread.cc +++ b/content/renderer/render_thread.cc @@ -34,6 +34,7 @@ #include "content/common/web_database_observer_impl.h" #include "content/plugin/npobject_util.h" #include "content/renderer/content_renderer_client.h" +#include "content/renderer/devtools_agent_filter.h" #include "content/renderer/gpu/gpu_channel_host.h" #include "content/renderer/indexed_db_dispatcher.h" #include "content/renderer/media/audio_input_message_filter.h" @@ -183,6 +184,9 @@ void RenderThread::Init() { audio_message_filter_ = new AudioMessageFilter(); AddFilter(audio_message_filter_.get()); + devtools_agent_message_filter_ = new DevToolsAgentFilter(); + AddFilter(devtools_agent_message_filter_.get()); + content::GetContentClient()->renderer()->RenderThreadStarted(); TRACE_EVENT_END_ETW("RenderThread::Init", 0, ""); @@ -197,6 +201,9 @@ RenderThread::~RenderThread() { web_database_observer_impl_->WaitForAllDatabasesToClose(); // Shutdown in reverse of the initialization order. + RemoveFilter(devtools_agent_message_filter_.get()); + devtools_agent_message_filter_ = NULL; + RemoveFilter(audio_input_message_filter_.get()); audio_input_message_filter_ = NULL; diff --git a/content/renderer/render_thread.h b/content/renderer/render_thread.h index 97419bd..d8042c9 100644 --- a/content/renderer/render_thread.h +++ b/content/renderer/render_thread.h @@ -25,6 +25,7 @@ class AppCacheDispatcher; class AudioInputMessageFilter; class AudioMessageFilter; class DBMessageFilter; +class DevToolsAgentFilter; class FilePath; class GpuChannelHost; class IndexedDBDispatcher; @@ -264,6 +265,7 @@ class RenderThread : public RenderThreadBase, scoped_refptr<DBMessageFilter> db_message_filter_; scoped_refptr<AudioInputMessageFilter> audio_input_message_filter_; scoped_refptr<AudioMessageFilter> audio_message_filter_; + scoped_refptr<DevToolsAgentFilter> devtools_agent_message_filter_; // Used on multiple threads. scoped_refptr<VideoCaptureImplManager> vc_manager_; diff --git a/content/renderer/render_view.cc b/content/renderer/render_view.cc index 762a637..1eeeb77 100644 --- a/content/renderer/render_view.cc +++ b/content/renderer/render_view.cc @@ -40,6 +40,7 @@ #include "content/common/url_constants.h" #include "content/common/view_messages.h" #include "content/renderer/content_renderer_client.h" +#include "content/renderer/devtools_agent.h" #include "content/renderer/device_orientation_dispatcher.h" #include "content/renderer/mhtml_generator.h" #include "content/renderer/external_popup_menu.h" @@ -409,6 +410,8 @@ RenderView::RenderView(RenderThreadBase* render_thread, new MHTMLGenerator(this); + new DevToolsAgent(this); + if (command_line.HasSwitch(switches::kEnableMediaStream)) { media_stream_impl_ = new MediaStreamImpl( RenderThread::current()->video_capture_impl_manager()); |