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(int routing_id) { |
57 : routing_id_(routing_id), | |
58 render_view_(render_view) { | |
59 agent_for_routing_id_[routing_id] = this; | 56 agent_for_routing_id_[routing_id] = this; |
60 | 57 |
61 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 58 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
62 expose_v8_debugger_protocol_ =cmd->HasSwitch(switches::kRemoteShellPort); | 59 expose_v8_debugger_protocol_ = cmd->HasSwitch(switches::kRemoteShellPort); |
63 } | 60 } |
64 | 61 |
65 DevToolsAgent::~DevToolsAgent() { | 62 DevToolsAgent::~DevToolsAgent() { |
66 agent_for_routing_id_.erase(routing_id_); | 63 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 } | 64 } |
75 | 65 |
76 // Called on the Renderer thread. | 66 // Called on the Renderer thread. |
77 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { | 67 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { |
78 bool handled = true; | 68 bool handled = true; |
79 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) | 69 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) |
80 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach) | 70 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach) |
81 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach) | 71 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach) |
82 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_FrontendLoaded, OnFrontendLoaded) | 72 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_FrontendLoaded, OnFrontendLoaded) |
83 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, | 73 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, |
84 OnDispatchOnInspectorBackend) | 74 OnDispatchOnInspectorBackend) |
85 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_InspectElement, OnInspectElement) | 75 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_InspectElement, OnInspectElement) |
86 IPC_MESSAGE_UNHANDLED(handled = false) | 76 IPC_MESSAGE_UNHANDLED(handled = false) |
87 IPC_END_MESSAGE_MAP() | 77 IPC_END_MESSAGE_MAP() |
| 78 |
| 79 if (message.type() == ViewMsg_Navigate::ID) |
| 80 OnNavigate(); // Don't want to swallow the message. |
| 81 |
88 return handled; | 82 return handled; |
89 } | 83 } |
90 | 84 |
91 void DevToolsAgent::sendMessageToInspectorFrontend( | 85 void DevToolsAgent::sendMessageToInspectorFrontend( |
92 const WebKit::WebString& message) { | 86 const WebKit::WebString& message) { |
93 IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient( | 87 Send(new ViewHostMsg_ForwardToDevToolsClient( |
94 routing_id_, | 88 routing_id(), |
95 DevToolsClientMsg_DispatchOnInspectorFrontend(message.utf8())); | 89 DevToolsClientMsg_DispatchOnInspectorFrontend(message.utf8()))); |
96 render_view_->Send(m); | |
97 } | 90 } |
98 | 91 |
99 void DevToolsAgent::sendDebuggerOutput(const WebKit::WebString& data) { | 92 void DevToolsAgent::sendDebuggerOutput(const WebKit::WebString& data) { |
100 IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient( | 93 Send(new ViewHostMsg_ForwardToDevToolsClient( |
101 routing_id_, | 94 routing_id(), |
102 DevToolsClientMsg_DebuggerOutput(data.utf8())); | 95 DevToolsClientMsg_DebuggerOutput(data.utf8()))); |
103 render_view_->Send(m); | |
104 } | 96 } |
105 | 97 |
106 int DevToolsAgent::hostIdentifier() { | 98 int DevToolsAgent::hostIdentifier() { |
107 return routing_id_; | 99 return routing_id(); |
108 } | 100 } |
109 | 101 |
110 void DevToolsAgent::runtimeFeatureStateChanged( | 102 void DevToolsAgent::runtimeFeatureStateChanged( |
111 const WebKit::WebString& feature, | 103 const WebKit::WebString& feature, |
112 bool enabled) { | 104 bool enabled) { |
113 render_view_->Send(new ViewHostMsg_DevToolsRuntimePropertyChanged( | 105 Send(new ViewHostMsg_DevToolsRuntimePropertyChanged( |
114 routing_id_, | 106 routing_id(), |
115 feature.utf8(), | 107 feature.utf8(), |
116 enabled ? "true" : "false")); | 108 enabled ? "true" : "false")); |
117 } | 109 } |
118 | 110 |
119 void DevToolsAgent::runtimePropertyChanged( | 111 void DevToolsAgent::runtimePropertyChanged( |
120 const WebKit::WebString& name, | 112 const WebKit::WebString& name, |
121 const WebKit::WebString& value) { | 113 const WebKit::WebString& value) { |
122 render_view_->Send(new ViewHostMsg_DevToolsRuntimePropertyChanged( | 114 Send(new ViewHostMsg_DevToolsRuntimePropertyChanged( |
123 routing_id_, | 115 routing_id(), |
124 name.utf8(), | 116 name.utf8(), |
125 value.utf8())); | 117 value.utf8())); |
126 } | 118 } |
127 | 119 |
128 WebCString DevToolsAgent::debuggerScriptSource() { | 120 WebCString DevToolsAgent::debuggerScriptSource() { |
129 base::StringPiece debuggerScriptjs = | 121 base::StringPiece debuggerScriptjs = |
130 webkit_glue::GetDataResource(IDR_DEVTOOLS_DEBUGGER_SCRIPT_JS); | 122 webkit_glue::GetDataResource(IDR_DEVTOOLS_DEBUGGER_SCRIPT_JS); |
131 return WebCString(debuggerScriptjs.data(), debuggerScriptjs.length()); | 123 return WebCString(debuggerScriptjs.data(), debuggerScriptjs.length()); |
132 } | 124 } |
133 | 125 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } | 176 } |
185 | 177 |
186 void DevToolsAgent::OnInspectElement(int x, int y) { | 178 void DevToolsAgent::OnInspectElement(int x, int y) { |
187 WebDevToolsAgent* web_agent = GetWebAgent(); | 179 WebDevToolsAgent* web_agent = GetWebAgent(); |
188 if (web_agent) { | 180 if (web_agent) { |
189 web_agent->attach(); | 181 web_agent->attach(); |
190 web_agent->inspectElementAt(WebPoint(x, y)); | 182 web_agent->inspectElementAt(WebPoint(x, y)); |
191 } | 183 } |
192 } | 184 } |
193 | 185 |
| 186 void DevToolsAgent::OnNavigate() { |
| 187 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 188 if (web_agent) { |
| 189 web_agent->didNavigate(); |
| 190 } |
| 191 } |
| 192 |
194 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { | 193 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { |
195 WebView* web_view = render_view_->webview(); | 194 WebView* web_view = render_view()->webview(); |
196 if (!web_view) | 195 if (!web_view) |
197 return NULL; | 196 return NULL; |
198 return web_view->devToolsAgent(); | 197 return web_view->devToolsAgent(); |
199 } | 198 } |
OLD | NEW |