OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/devtools_agent.h" | 5 #include "chrome/renderer/devtools_agent.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
12 #include "chrome/renderer/devtools_agent_filter.h" | 12 #include "chrome/renderer/devtools_agent_filter.h" |
13 #include "chrome/renderer/render_view.h" | |
14 #include "grit/webkit_chromium_resources.h" | 13 #include "grit/webkit_chromium_resources.h" |
15 #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" |
16 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
17 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
18 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
19 #include "webkit/glue/webkit_glue.h" | 18 #include "webkit/glue/webkit_glue.h" |
20 | 19 |
21 using WebKit::WebDevToolsAgent; | 20 using WebKit::WebDevToolsAgent; |
22 using WebKit::WebDevToolsAgentClient; | 21 using WebKit::WebDevToolsAgentClient; |
23 using WebKit::WebPoint; | 22 using WebKit::WebPoint; |
(...skipping 22 matching lines...) Expand all Loading... |
46 } | 45 } |
47 private: | 46 private: |
48 MessageLoop* message_loop_; | 47 MessageLoop* message_loop_; |
49 }; | 48 }; |
50 | 49 |
51 } // namespace | 50 } // namespace |
52 | 51 |
53 // static | 52 // static |
54 std::map<int, DevToolsAgent*> DevToolsAgent::agent_for_routing_id_; | 53 std::map<int, DevToolsAgent*> DevToolsAgent::agent_for_routing_id_; |
55 | 54 |
56 DevToolsAgent::DevToolsAgent(int routing_id, RenderView* render_view) | 55 DevToolsAgent::DevToolsAgent(RenderView* render_view) |
57 : routing_id_(routing_id), | 56 : RenderView::Observer(render_view) { |
58 render_view_(render_view) { | 57 agent_for_routing_id_[routing_id()] = this; |
59 agent_for_routing_id_[routing_id] = this; | |
60 | 58 |
61 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 59 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
62 expose_v8_debugger_protocol_ =cmd->HasSwitch(switches::kRemoteShellPort); | 60 expose_v8_debugger_protocol_ = cmd->HasSwitch(switches::kRemoteShellPort); |
63 } | 61 } |
64 | 62 |
65 DevToolsAgent::~DevToolsAgent() { | 63 DevToolsAgent::~DevToolsAgent() { |
66 agent_for_routing_id_.erase(routing_id_); | 64 agent_for_routing_id_.erase(routing_id()); |
67 } | |
68 | |
69 void DevToolsAgent::OnNavigate() { | |
70 WebDevToolsAgent* web_agent = GetWebAgent(); | |
71 if (web_agent) { | |
72 web_agent->didNavigate(); | |
73 } | |
74 } | 65 } |
75 | 66 |
76 // Called on the Renderer thread. | 67 // Called on the Renderer thread. |
77 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { | 68 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { |
78 bool handled = true; | 69 bool handled = true; |
79 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) | 70 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) |
80 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach) | 71 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach) |
81 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach) | 72 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach) |
82 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_FrontendLoaded, OnFrontendLoaded) | 73 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_FrontendLoaded, OnFrontendLoaded) |
83 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, | 74 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, |
84 OnDispatchOnInspectorBackend) | 75 OnDispatchOnInspectorBackend) |
85 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_InspectElement, OnInspectElement) | 76 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_InspectElement, OnInspectElement) |
86 IPC_MESSAGE_UNHANDLED(handled = false) | 77 IPC_MESSAGE_UNHANDLED(handled = false) |
87 IPC_END_MESSAGE_MAP() | 78 IPC_END_MESSAGE_MAP() |
| 79 |
| 80 if (message.type() == ViewMsg_Navigate::ID) |
| 81 OnNavigate(); // Don't want to swallow the message. |
| 82 |
88 return handled; | 83 return handled; |
89 } | 84 } |
90 | 85 |
91 void DevToolsAgent::sendMessageToInspectorFrontend( | 86 void DevToolsAgent::sendMessageToInspectorFrontend( |
92 const WebKit::WebString& message) { | 87 const WebKit::WebString& message) { |
93 IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient( | 88 Send(new ViewHostMsg_ForwardToDevToolsClient( |
94 routing_id_, | 89 routing_id(), |
95 DevToolsClientMsg_DispatchOnInspectorFrontend(message.utf8())); | 90 DevToolsClientMsg_DispatchOnInspectorFrontend(message.utf8()))); |
96 render_view_->Send(m); | |
97 } | 91 } |
98 | 92 |
99 void DevToolsAgent::sendDebuggerOutput(const WebKit::WebString& data) { | 93 void DevToolsAgent::sendDebuggerOutput(const WebKit::WebString& data) { |
100 IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient( | 94 Send(new ViewHostMsg_ForwardToDevToolsClient( |
101 routing_id_, | 95 routing_id(), |
102 DevToolsClientMsg_DebuggerOutput(data.utf8())); | 96 DevToolsClientMsg_DebuggerOutput(data.utf8()))); |
103 render_view_->Send(m); | |
104 } | 97 } |
105 | 98 |
106 int DevToolsAgent::hostIdentifier() { | 99 int DevToolsAgent::hostIdentifier() { |
107 return routing_id_; | 100 return routing_id(); |
108 } | 101 } |
109 | 102 |
110 void DevToolsAgent::runtimeFeatureStateChanged( | 103 void DevToolsAgent::runtimeFeatureStateChanged( |
111 const WebKit::WebString& feature, | 104 const WebKit::WebString& feature, |
112 bool enabled) { | 105 bool enabled) { |
113 render_view_->Send(new ViewHostMsg_DevToolsRuntimePropertyChanged( | 106 Send(new ViewHostMsg_DevToolsRuntimePropertyChanged( |
114 routing_id_, | 107 routing_id(), |
115 feature.utf8(), | 108 feature.utf8(), |
116 enabled ? "true" : "false")); | 109 enabled ? "true" : "false")); |
117 } | 110 } |
118 | 111 |
119 void DevToolsAgent::runtimePropertyChanged( | 112 void DevToolsAgent::runtimePropertyChanged( |
120 const WebKit::WebString& name, | 113 const WebKit::WebString& name, |
121 const WebKit::WebString& value) { | 114 const WebKit::WebString& value) { |
122 render_view_->Send(new ViewHostMsg_DevToolsRuntimePropertyChanged( | 115 Send(new ViewHostMsg_DevToolsRuntimePropertyChanged( |
123 routing_id_, | 116 routing_id(), |
124 name.utf8(), | 117 name.utf8(), |
125 value.utf8())); | 118 value.utf8())); |
126 } | 119 } |
127 | 120 |
128 WebCString DevToolsAgent::debuggerScriptSource() { | 121 WebCString DevToolsAgent::debuggerScriptSource() { |
129 base::StringPiece debuggerScriptjs = | 122 base::StringPiece debuggerScriptjs = |
130 webkit_glue::GetDataResource(IDR_DEVTOOLS_DEBUGGER_SCRIPT_JS); | 123 webkit_glue::GetDataResource(IDR_DEVTOOLS_DEBUGGER_SCRIPT_JS); |
131 return WebCString(debuggerScriptjs.data(), debuggerScriptjs.length()); | 124 return WebCString(debuggerScriptjs.data(), debuggerScriptjs.length()); |
132 } | 125 } |
133 | 126 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } | 177 } |
185 | 178 |
186 void DevToolsAgent::OnInspectElement(int x, int y) { | 179 void DevToolsAgent::OnInspectElement(int x, int y) { |
187 WebDevToolsAgent* web_agent = GetWebAgent(); | 180 WebDevToolsAgent* web_agent = GetWebAgent(); |
188 if (web_agent) { | 181 if (web_agent) { |
189 web_agent->attach(); | 182 web_agent->attach(); |
190 web_agent->inspectElementAt(WebPoint(x, y)); | 183 web_agent->inspectElementAt(WebPoint(x, y)); |
191 } | 184 } |
192 } | 185 } |
193 | 186 |
| 187 void DevToolsAgent::OnNavigate() { |
| 188 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 189 if (web_agent) { |
| 190 web_agent->didNavigate(); |
| 191 } |
| 192 } |
| 193 |
194 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { | 194 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { |
195 WebView* web_view = render_view_->webview(); | 195 WebView* web_view = render_view()->webview(); |
196 if (!web_view) | 196 if (!web_view) |
197 return NULL; | 197 return NULL; |
198 return web_view->devToolsAgent(); | 198 return web_view->devToolsAgent(); |
199 } | 199 } |
OLD | NEW |