summaryrefslogtreecommitdiffstats
path: root/content/renderer/devtools_agent.cc
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 09:57:20 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 09:57:20 +0000
commit8262245d384be025f13e2a5b3a03b7e5c98374ce (patch)
treeb92377c4ce653f721bf7339c8fa33f7a7049ce67 /content/renderer/devtools_agent.cc
parent2469a22063c3539147f55fe899a8dabc12901c01 (diff)
downloadchromium_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/renderer/devtools_agent.cc')
-rw-r--r--content/renderer/devtools_agent.cc214
1 files changed, 214 insertions, 0 deletions
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();
+}