Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: content/renderer/devtools/devtools_agent.cc

Issue 744653002: Ignore DevTools messages from the old inspected RVH after navigation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comment Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/devtools/devtools_agent.h ('k') | content/renderer/devtools/devtools_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 paused_in_mouse_move_ =
156 paused_in_mouse_move_ = impl->SendAckForMouseMoveFromDebugger(); 158 GetRenderViewImpl()->SendAckForMouseMoveFromDebugger();
157 } 159 }
158 160
159 void DevToolsAgent::didExitDebugLoop() { 161 void DevToolsAgent::didExitDebugLoop() {
160 RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view());
161 if (paused_in_mouse_move_) { 162 if (paused_in_mouse_move_) {
162 impl->IgnoreAckForMouseMoveFromDebugger(); 163 GetRenderViewImpl()->IgnoreAckForMouseMoveFromDebugger();
163 paused_in_mouse_move_ = false; 164 paused_in_mouse_move_ = false;
164 } 165 }
165 } 166 }
166 167
167 void DevToolsAgent::resetTraceEventCallback() 168 void DevToolsAgent::resetTraceEventCallback()
168 { 169 {
169 TraceLog::GetInstance()->SetEventCallbackDisabled(); 170 TraceLog::GetInstance()->SetEventCallbackDisabled();
170 base::subtle::NoBarrier_Store(&event_callback_, 0); 171 base::subtle::NoBarrier_Store(&event_callback_, 0);
171 } 172 }
172 173
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 const GpuTaskInfo& task = tasks[i]; 252 const GpuTaskInfo& task = tasks[i];
252 WebDevToolsAgent::GPUEvent event( 253 WebDevToolsAgent::GPUEvent event(
253 task.timestamp, task.phase, task.foreign, task.gpu_memory_used_bytes); 254 task.timestamp, task.phase, task.foreign, task.gpu_memory_used_bytes);
254 event.limitGPUMemoryBytes = task.gpu_memory_limit_bytes; 255 event.limitGPUMemoryBytes = task.gpu_memory_limit_bytes;
255 web_agent->processGPUEvent(event); 256 web_agent->processGPUEvent(event);
256 } 257 }
257 } 258 }
258 259
259 void DevToolsAgent::enableDeviceEmulation( 260 void DevToolsAgent::enableDeviceEmulation(
260 const blink::WebDeviceEmulationParams& params) { 261 const blink::WebDeviceEmulationParams& params) {
261 RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view()); 262 GetRenderViewImpl()->EnableScreenMetricsEmulation(params);
262 impl->EnableScreenMetricsEmulation(params);
263 } 263 }
264 264
265 void DevToolsAgent::disableDeviceEmulation() { 265 void DevToolsAgent::disableDeviceEmulation() {
266 RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view()); 266 GetRenderViewImpl()->DisableScreenMetricsEmulation();
267 impl->DisableScreenMetricsEmulation();
268 } 267 }
269 268
270 // static 269 // static
271 DevToolsAgent* DevToolsAgent::FromRoutingId(int routing_id) { 270 DevToolsAgent* DevToolsAgent::FromRoutingId(int routing_id) {
272 IdToAgentMap::iterator it = g_agent_for_routing_id.Get().find(routing_id); 271 IdToAgentMap::iterator it = g_agent_for_routing_id.Get().find(routing_id);
273 if (it != g_agent_for_routing_id.Get().end()) { 272 if (it != g_agent_for_routing_id.Get().end()) {
274 return it->second; 273 return it->second;
275 } 274 }
276 return NULL; 275 return NULL;
277 } 276 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 WebDevToolsAgent* web_agent = GetWebAgent(); 313 WebDevToolsAgent* web_agent = GetWebAgent();
315 if (web_agent) { 314 if (web_agent) {
316 web_agent->attach(WebString::fromUTF8(host_id)); 315 web_agent->attach(WebString::fromUTF8(host_id));
317 web_agent->inspectElementAt(WebPoint(x, y)); 316 web_agent->inspectElementAt(WebPoint(x, y));
318 is_attached_ = true; 317 is_attached_ = true;
319 } 318 }
320 } 319 }
321 320
322 void DevToolsAgent::OnAddMessageToConsole(ConsoleMessageLevel level, 321 void DevToolsAgent::OnAddMessageToConsole(ConsoleMessageLevel level,
323 const std::string& message) { 322 const std::string& message) {
324 WebView* web_view = render_view()->GetWebView(); 323 WebView* web_view = main_render_frame_->GetRenderView()->GetWebView();
325 if (!web_view) 324 if (!web_view)
326 return; 325 return;
327 326
328 WebFrame* main_frame = web_view->mainFrame(); 327 WebFrame* main_frame = web_view->mainFrame();
329 if (!main_frame) 328 if (!main_frame)
330 return; 329 return;
331 330
332 WebConsoleMessage::Level target_level = WebConsoleMessage::LevelLog; 331 WebConsoleMessage::Level target_level = WebConsoleMessage::LevelLog;
333 switch (level) { 332 switch (level) {
334 case CONSOLE_MESSAGE_LEVEL_DEBUG: 333 case CONSOLE_MESSAGE_LEVEL_DEBUG:
(...skipping 17 matching lines...) Expand all
352 WebDevToolsAgent* web_agent = GetWebAgent(); 351 WebDevToolsAgent* web_agent = GetWebAgent();
353 if (web_agent) 352 if (web_agent)
354 web_agent->continueProgram(); 353 web_agent->continueProgram();
355 } 354 }
356 355
357 void DevToolsAgent::OnSetupDevToolsClient() { 356 void DevToolsAgent::OnSetupDevToolsClient() {
358 // We only want to register once per render view. 357 // We only want to register once per render view.
359 if (is_devtools_client_) 358 if (is_devtools_client_)
360 return; 359 return;
361 is_devtools_client_ = true; 360 is_devtools_client_ = true;
362 new DevToolsClient(static_cast<RenderViewImpl*>(render_view())); 361 new DevToolsClient(main_render_frame_);
363 } 362 }
364 363
365 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { 364 WebDevToolsAgent* DevToolsAgent::GetWebAgent() {
366 WebView* web_view = render_view()->GetWebView(); 365 WebView* web_view = main_render_frame_->GetRenderView()->GetWebView();
367 if (!web_view) 366 if (!web_view)
368 return NULL; 367 return NULL;
369 return web_view->devToolsAgent(); 368 return web_view->devToolsAgent();
370 } 369 }
371 370
371 RenderViewImpl* DevToolsAgent::GetRenderViewImpl() {
372 return static_cast<RenderViewImpl*>(main_render_frame_->GetRenderView());
373 }
374
372 bool DevToolsAgent::IsAttached() { 375 bool DevToolsAgent::IsAttached() {
373 return is_attached_; 376 return is_attached_;
374 } 377 }
375 378
376 } // namespace content 379 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/devtools/devtools_agent.h ('k') | content/renderer/devtools/devtools_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698