OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/devtools/devtools_agent.h" | 5 #include "content/renderer/devtools/devtools_agent.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 private: | 69 private: |
70 base::MessageLoop* message_loop_; | 70 base::MessageLoop* message_loop_; |
71 }; | 71 }; |
72 | 72 |
73 typedef std::map<int, DevToolsAgent*> IdToAgentMap; | 73 typedef std::map<int, DevToolsAgent*> IdToAgentMap; |
74 base::LazyInstance<IdToAgentMap>::Leaky | 74 base::LazyInstance<IdToAgentMap>::Leaky |
75 g_agent_for_routing_id = LAZY_INSTANCE_INITIALIZER; | 75 g_agent_for_routing_id = LAZY_INSTANCE_INITIALIZER; |
76 | 76 |
77 } // namespace | 77 } // namespace |
78 | 78 |
79 DevToolsAgent::DevToolsAgent(RenderViewImpl* render_view) | 79 DevToolsAgent::DevToolsAgent(RenderFrame* main_render_frame) |
80 : RenderViewObserver(render_view), | 80 : RenderFrameObserver(main_render_frame), |
81 is_attached_(false), | 81 is_attached_(false), |
82 is_devtools_client_(false), | 82 is_devtools_client_(false), |
83 gpu_route_id_(MSG_ROUTING_NONE), | 83 gpu_route_id_(MSG_ROUTING_NONE), |
84 paused_in_mouse_move_(false) { | 84 paused_in_mouse_move_(false), |
85 main_render_frame_(main_render_frame) { | |
85 g_agent_for_routing_id.Get()[routing_id()] = this; | 86 g_agent_for_routing_id.Get()[routing_id()] = this; |
86 | 87 |
87 render_view->webview()->setDevToolsAgentClient(this); | 88 main_render_frame_->GetRenderView()->GetWebView()->setDevToolsAgentClient( |
89 this); | |
88 } | 90 } |
89 | 91 |
90 DevToolsAgent::~DevToolsAgent() { | 92 DevToolsAgent::~DevToolsAgent() { |
91 g_agent_for_routing_id.Get().erase(routing_id()); | 93 g_agent_for_routing_id.Get().erase(routing_id()); |
92 resetTraceEventCallback(); | 94 resetTraceEventCallback(); |
93 } | 95 } |
94 | 96 |
95 // Called on the Renderer thread. | 97 // Called on the Renderer thread. |
96 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { | 98 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { |
97 bool handled = true; | 99 bool handled = true; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 const blink::WebString& state) { | 147 const blink::WebString& state) { |
146 Send(new DevToolsHostMsg_SaveAgentRuntimeState(routing_id(), state.utf8())); | 148 Send(new DevToolsHostMsg_SaveAgentRuntimeState(routing_id(), state.utf8())); |
147 } | 149 } |
148 | 150 |
149 blink::WebDevToolsAgentClient::WebKitClientMessageLoop* | 151 blink::WebDevToolsAgentClient::WebKitClientMessageLoop* |
150 DevToolsAgent::createClientMessageLoop() { | 152 DevToolsAgent::createClientMessageLoop() { |
151 return new WebKitClientMessageLoopImpl(); | 153 return new WebKitClientMessageLoopImpl(); |
152 } | 154 } |
153 | 155 |
154 void DevToolsAgent::willEnterDebugLoop() { | 156 void DevToolsAgent::willEnterDebugLoop() { |
155 RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view()); | 157 RenderViewImpl* impl = |
158 static_cast<RenderViewImpl*>(main_render_frame_->GetRenderView()); | |
pfeldman
2014/11/24 13:31:19
Introduce GetRenderView?
yurys
2014/11/24 14:08:54
Done.
| |
156 paused_in_mouse_move_ = impl->SendAckForMouseMoveFromDebugger(); | 159 paused_in_mouse_move_ = impl->SendAckForMouseMoveFromDebugger(); |
157 } | 160 } |
158 | 161 |
159 void DevToolsAgent::didExitDebugLoop() { | 162 void DevToolsAgent::didExitDebugLoop() { |
160 RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view()); | 163 RenderViewImpl* impl = |
164 static_cast<RenderViewImpl*>(main_render_frame_->GetRenderView()); | |
161 if (paused_in_mouse_move_) { | 165 if (paused_in_mouse_move_) { |
162 impl->IgnoreAckForMouseMoveFromDebugger(); | 166 impl->IgnoreAckForMouseMoveFromDebugger(); |
163 paused_in_mouse_move_ = false; | 167 paused_in_mouse_move_ = false; |
164 } | 168 } |
165 } | 169 } |
166 | 170 |
167 void DevToolsAgent::resetTraceEventCallback() | 171 void DevToolsAgent::resetTraceEventCallback() |
168 { | 172 { |
169 TraceLog::GetInstance()->SetEventCallbackDisabled(); | 173 TraceLog::GetInstance()->SetEventCallbackDisabled(); |
170 base::subtle::NoBarrier_Store(&event_callback_, 0); | 174 base::subtle::NoBarrier_Store(&event_callback_, 0); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 const GpuTaskInfo& task = tasks[i]; | 255 const GpuTaskInfo& task = tasks[i]; |
252 WebDevToolsAgent::GPUEvent event( | 256 WebDevToolsAgent::GPUEvent event( |
253 task.timestamp, task.phase, task.foreign, task.gpu_memory_used_bytes); | 257 task.timestamp, task.phase, task.foreign, task.gpu_memory_used_bytes); |
254 event.limitGPUMemoryBytes = task.gpu_memory_limit_bytes; | 258 event.limitGPUMemoryBytes = task.gpu_memory_limit_bytes; |
255 web_agent->processGPUEvent(event); | 259 web_agent->processGPUEvent(event); |
256 } | 260 } |
257 } | 261 } |
258 | 262 |
259 void DevToolsAgent::enableDeviceEmulation( | 263 void DevToolsAgent::enableDeviceEmulation( |
260 const blink::WebDeviceEmulationParams& params) { | 264 const blink::WebDeviceEmulationParams& params) { |
261 RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view()); | 265 RenderViewImpl* impl = |
266 static_cast<RenderViewImpl*>(main_render_frame_->GetRenderView()); | |
262 impl->EnableScreenMetricsEmulation(params); | 267 impl->EnableScreenMetricsEmulation(params); |
263 } | 268 } |
264 | 269 |
265 void DevToolsAgent::disableDeviceEmulation() { | 270 void DevToolsAgent::disableDeviceEmulation() { |
266 RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view()); | 271 RenderViewImpl* impl = |
272 static_cast<RenderViewImpl*>(main_render_frame_->GetRenderView()); | |
267 impl->DisableScreenMetricsEmulation(); | 273 impl->DisableScreenMetricsEmulation(); |
268 } | 274 } |
269 | 275 |
270 // static | 276 // static |
271 DevToolsAgent* DevToolsAgent::FromRoutingId(int routing_id) { | 277 DevToolsAgent* DevToolsAgent::FromRoutingId(int routing_id) { |
272 IdToAgentMap::iterator it = g_agent_for_routing_id.Get().find(routing_id); | 278 IdToAgentMap::iterator it = g_agent_for_routing_id.Get().find(routing_id); |
273 if (it != g_agent_for_routing_id.Get().end()) { | 279 if (it != g_agent_for_routing_id.Get().end()) { |
274 return it->second; | 280 return it->second; |
275 } | 281 } |
276 return NULL; | 282 return NULL; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 WebDevToolsAgent* web_agent = GetWebAgent(); | 320 WebDevToolsAgent* web_agent = GetWebAgent(); |
315 if (web_agent) { | 321 if (web_agent) { |
316 web_agent->attach(WebString::fromUTF8(host_id)); | 322 web_agent->attach(WebString::fromUTF8(host_id)); |
317 web_agent->inspectElementAt(WebPoint(x, y)); | 323 web_agent->inspectElementAt(WebPoint(x, y)); |
318 is_attached_ = true; | 324 is_attached_ = true; |
319 } | 325 } |
320 } | 326 } |
321 | 327 |
322 void DevToolsAgent::OnAddMessageToConsole(ConsoleMessageLevel level, | 328 void DevToolsAgent::OnAddMessageToConsole(ConsoleMessageLevel level, |
323 const std::string& message) { | 329 const std::string& message) { |
324 WebView* web_view = render_view()->GetWebView(); | 330 WebView* web_view = main_render_frame_->GetRenderView()->GetWebView(); |
325 if (!web_view) | 331 if (!web_view) |
326 return; | 332 return; |
327 | 333 |
328 WebFrame* main_frame = web_view->mainFrame(); | 334 WebFrame* main_frame = web_view->mainFrame(); |
329 if (!main_frame) | 335 if (!main_frame) |
330 return; | 336 return; |
331 | 337 |
332 WebConsoleMessage::Level target_level = WebConsoleMessage::LevelLog; | 338 WebConsoleMessage::Level target_level = WebConsoleMessage::LevelLog; |
333 switch (level) { | 339 switch (level) { |
334 case CONSOLE_MESSAGE_LEVEL_DEBUG: | 340 case CONSOLE_MESSAGE_LEVEL_DEBUG: |
(...skipping 17 matching lines...) Expand all Loading... | |
352 WebDevToolsAgent* web_agent = GetWebAgent(); | 358 WebDevToolsAgent* web_agent = GetWebAgent(); |
353 if (web_agent) | 359 if (web_agent) |
354 web_agent->continueProgram(); | 360 web_agent->continueProgram(); |
355 } | 361 } |
356 | 362 |
357 void DevToolsAgent::OnSetupDevToolsClient() { | 363 void DevToolsAgent::OnSetupDevToolsClient() { |
358 // We only want to register once per render view. | 364 // We only want to register once per render view. |
359 if (is_devtools_client_) | 365 if (is_devtools_client_) |
360 return; | 366 return; |
361 is_devtools_client_ = true; | 367 is_devtools_client_ = true; |
362 new DevToolsClient(static_cast<RenderViewImpl*>(render_view())); | 368 new DevToolsClient(main_render_frame_); |
363 } | 369 } |
364 | 370 |
365 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { | 371 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { |
366 WebView* web_view = render_view()->GetWebView(); | 372 WebView* web_view = main_render_frame_->GetRenderView()->GetWebView(); |
367 if (!web_view) | 373 if (!web_view) |
368 return NULL; | 374 return NULL; |
369 return web_view->devToolsAgent(); | 375 return web_view->devToolsAgent(); |
370 } | 376 } |
371 | 377 |
372 bool DevToolsAgent::IsAttached() { | 378 bool DevToolsAgent::IsAttached() { |
373 return is_attached_; | 379 return is_attached_; |
374 } | 380 } |
375 | 381 |
376 } // namespace content | 382 } // namespace content |
OLD | NEW |