blob: 046b7550fe1f6ff3d3e3a0182b52f1698f2cea0f [file] [log] [blame]
[email protected]b2abac72009-02-26 12:39:281// Copyright (c) 2009 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e4ac5df2009-03-17 15:33:115#include "chrome/renderer/devtools_agent.h"
[email protected]b2abac72009-02-26 12:39:286
[email protected]7b4c0d62009-04-03 10:06:577#include "chrome/common/devtools_messages.h"
[email protected]b2abac72009-02-26 12:39:288#include "chrome/common/render_messages.h"
[email protected]b2abac72009-02-26 12:39:289#include "chrome/renderer/render_view.h"
[email protected]611cad42009-03-16 18:51:3410#include "webkit/glue/webdevtoolsagent.h"
[email protected]b2abac72009-02-26 12:39:2811
[email protected]b75b7d072009-04-06 13:47:0012DevToolsAgent::DevToolsAgent(int routing_id, RenderView* view)
[email protected]24b3b4d2009-04-01 14:26:4013 : routing_id_(routing_id),
[email protected]b75b7d072009-04-06 13:47:0014 view_(view) {
[email protected]b2abac72009-02-26 12:39:2815}
16
17DevToolsAgent::~DevToolsAgent() {
18}
19
[email protected]b75b7d072009-04-06 13:47:0020// Called on the Renderer thread.
[email protected]b2abac72009-02-26 12:39:2821bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) {
[email protected]b2abac72009-02-26 12:39:2822 bool handled = true;
23 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message)
[email protected]2573a232009-03-27 12:36:2124 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach)
25 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach)
[email protected]611cad42009-03-16 18:51:3426 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_RpcMessage, OnRpcMessage)
[email protected]d0ef30f42009-03-24 13:54:2827 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_InspectElement, OnInspectElement)
[email protected]b2abac72009-02-26 12:39:2828 IPC_MESSAGE_UNHANDLED(handled = false)
29 IPC_END_MESSAGE_MAP()
30 return handled;
31}
32
[email protected]b75b7d072009-04-06 13:47:0033void DevToolsAgent::SendMessageToClient(const std::string& raw_msg) {
34 IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient(
35 routing_id_,
36 DevToolsClientMsg_RpcMessage(raw_msg));
37 view_->Send(m);
[email protected]b2abac72009-02-26 12:39:2838}
39
[email protected]2573a232009-03-27 12:36:2140void DevToolsAgent::OnAttach() {
[email protected]2573a232009-03-27 12:36:2141 WebDevToolsAgent* web_agent = GetWebAgent();
42 if (web_agent) {
43 web_agent->Attach();
44 }
45}
46
[email protected]b75b7d072009-04-06 13:47:0047void DevToolsAgent::OnDetach() {
[email protected]2573a232009-03-27 12:36:2148 WebDevToolsAgent* web_agent = GetWebAgent();
49 if (web_agent) {
50 web_agent->Detach();
51 }
52}
53
[email protected]b75b7d072009-04-06 13:47:0054void DevToolsAgent::OnRpcMessage(const std::string& raw_msg) {
[email protected]2573a232009-03-27 12:36:2155 WebDevToolsAgent* web_agent = GetWebAgent();
56 if (web_agent) {
57 web_agent->DispatchMessageFromClient(raw_msg);
58 }
[email protected]611cad42009-03-16 18:51:3459}
[email protected]63a5c2a22009-03-26 11:12:5360
[email protected]b75b7d072009-04-06 13:47:0061void DevToolsAgent::OnInspectElement(int x, int y) {
[email protected]2573a232009-03-27 12:36:2162 WebDevToolsAgent* web_agent = GetWebAgent();
63 if (web_agent) {
[email protected]90ca3692009-04-09 16:09:4364 web_agent->Attach();
[email protected]2573a232009-03-27 12:36:2165 web_agent->InspectElement(x, y);
66 }
67}
68
69WebDevToolsAgent* DevToolsAgent::GetWebAgent() {
[email protected]63a5c2a22009-03-26 11:12:5370 WebView* web_view = view_->webview();
71 if (!web_view)
[email protected]2573a232009-03-27 12:36:2172 return NULL;
73 return web_view->GetWebDevToolsAgent();
[email protected]63a5c2a22009-03-26 11:12:5374}