1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
// 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 "chrome/renderer/devtools_agent.h"
#include "chrome/common/devtools_messages.h"
#include "chrome/common/render_messages.h"
#include "chrome/renderer/render_view.h"
#include "webkit/glue/webdevtoolsagent.h"
// static
std::map<int, DevToolsAgent*> DevToolsAgent::agent_for_routing_id_;
DevToolsAgent::DevToolsAgent(int routing_id, RenderView* view)
: routing_id_(routing_id),
view_(view) {
agent_for_routing_id_[routing_id] = this;
}
DevToolsAgent::~DevToolsAgent() {
agent_for_routing_id_.erase(routing_id_);
}
void DevToolsAgent::OnNavigate() {
WebDevToolsAgent* web_agent = GetWebAgent();
if (web_agent) {
web_agent->OnNavigate();
}
}
// 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_RpcMessage, OnRpcMessage)
IPC_MESSAGE_HANDLER(DevToolsAgentMsg_InspectElement, OnInspectElement)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void DevToolsAgent::SendMessageToClient(const std::string& class_name,
const std::string& method_name,
const std::string& raw_msg) {
IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient(
routing_id_,
DevToolsClientMsg_RpcMessage(class_name, method_name, raw_msg));
view_->Send(m);
}
int DevToolsAgent::GetHostId() {
return routing_id_;
}
void DevToolsAgent::ForceRepaint() {
view_->GenerateFullRepaint();
}
// 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() {
WebDevToolsAgent* web_agent = GetWebAgent();
if (web_agent) {
web_agent->Attach();
}
}
void DevToolsAgent::OnDetach() {
WebDevToolsAgent* web_agent = GetWebAgent();
if (web_agent) {
web_agent->Detach();
}
}
void DevToolsAgent::OnRpcMessage(const std::string& class_name,
const std::string& method_name,
const std::string& raw_msg) {
WebDevToolsAgent* web_agent = GetWebAgent();
if (web_agent) {
web_agent->DispatchMessageFromClient(class_name, method_name, raw_msg);
}
}
void DevToolsAgent::OnInspectElement(int x, int y) {
WebDevToolsAgent* web_agent = GetWebAgent();
if (web_agent) {
web_agent->Attach();
web_agent->InspectElement(x, y);
}
}
WebDevToolsAgent* DevToolsAgent::GetWebAgent() {
WebView* web_view = view_->webview();
if (!web_view)
return NULL;
return web_view->GetWebDevToolsAgent();
}
|