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/browser/devtools/render_view_devtools_agent_host.h" | 5 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "content/browser/child_process_security_policy_impl.h" | 9 #include "content/browser/child_process_security_policy_impl.h" |
10 #include "content/browser/devtools/devtools_manager_impl.h" | 10 #include "content/browser/devtools/devtools_manager_impl.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 static_cast<WebContentsImpl*>(web_contents); | 46 static_cast<WebContentsImpl*>(web_contents); |
47 for (Instances::iterator it = g_instances.Get().begin(); | 47 for (Instances::iterator it = g_instances.Get().begin(); |
48 it != g_instances.Get().end(); ++it) { | 48 it != g_instances.Get().end(); ++it) { |
49 RenderViewHost* rvh = (*it)->render_view_host(); | 49 RenderViewHost* rvh = (*it)->render_view_host(); |
50 if (rvh && rvh->GetDelegate() == delegate) | 50 if (rvh && rvh->GetDelegate() == delegate) |
51 return *it; | 51 return *it; |
52 } | 52 } |
53 return NULL; | 53 return NULL; |
54 } | 54 } |
55 | 55 |
56 static RenderViewDevToolsAgentHost* FindAgentHost(RenderViewHost* rvh) { | |
57 if (g_instances == NULL) | |
58 return NULL; | |
59 for (Instances::iterator it = g_instances.Get().begin(); | |
60 it != g_instances.Get().end(); ++it) { | |
61 if (rvh == (*it)->render_view_host()) | |
62 return *it; | |
63 } | |
64 return NULL; | |
65 } | |
66 | |
67 } // namespace | 56 } // namespace |
68 | 57 |
69 scoped_refptr<DevToolsAgentHost> | 58 scoped_refptr<DevToolsAgentHost> |
70 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { | 59 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { |
71 RenderViewDevToolsAgentHost* result = FindAgentHost(web_contents); | 60 RenderViewDevToolsAgentHost* result = FindAgentHost(web_contents); |
72 if (!result) | 61 if (!result) |
73 result = new RenderViewDevToolsAgentHost(web_contents->GetRenderViewHost()); | 62 result = new RenderViewDevToolsAgentHost(web_contents->GetRenderViewHost()); |
74 return result; | 63 return result; |
75 } | 64 } |
76 | 65 |
77 // static | 66 // static |
78 scoped_refptr<DevToolsAgentHost> | 67 bool DevToolsAgentHost::HasFor(WebContents* web_contents) { |
79 DevToolsAgentHost::GetOrCreateFor(RenderViewHost* rvh) { | 68 return FindAgentHost(web_contents) != NULL; |
80 RenderViewDevToolsAgentHost* result = FindAgentHost(rvh); | |
81 if (!result) | |
82 result = new RenderViewDevToolsAgentHost(rvh); | |
83 return result; | |
84 } | 69 } |
85 | 70 |
86 // static | 71 // static |
87 bool DevToolsAgentHost::HasFor(RenderViewHost* rvh) { | |
88 return FindAgentHost(rvh) != NULL; | |
89 } | |
90 | |
91 // static | |
92 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { | 72 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { |
93 if (g_instances == NULL) | 73 if (g_instances == NULL) |
94 return false; | 74 return false; |
95 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | 75 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
96 if (!devtools_manager) | 76 if (!devtools_manager) |
97 return false; | 77 return false; |
98 RenderViewHostDelegate* delegate = | 78 RenderViewHostDelegate* delegate = |
99 static_cast<WebContentsImpl*>(web_contents); | 79 static_cast<WebContentsImpl*>(web_contents); |
100 for (Instances::iterator it = g_instances.Get().begin(); | 80 for (Instances::iterator it = g_instances.Get().begin(); |
101 it != g_instances.Get().end(); ++it) { | 81 it != g_instances.Get().end(); ++it) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 119 |
140 result.push_back(rvh); | 120 result.push_back(rvh); |
141 } | 121 } |
142 return result; | 122 return result; |
143 } | 123 } |
144 | 124 |
145 // static | 125 // static |
146 void RenderViewDevToolsAgentHost::OnCancelPendingNavigation( | 126 void RenderViewDevToolsAgentHost::OnCancelPendingNavigation( |
147 RenderViewHost* pending, | 127 RenderViewHost* pending, |
148 RenderViewHost* current) { | 128 RenderViewHost* current) { |
149 RenderViewDevToolsAgentHost* agent_host = FindAgentHost(pending); | 129 WebContents* web_contents = WebContents::FromRenderViewHost(pending); |
| 130 RenderViewDevToolsAgentHost* agent_host = FindAgentHost(web_contents); |
150 if (!agent_host) | 131 if (!agent_host) |
151 return; | 132 return; |
152 agent_host->DisconnectRenderViewHost(); | 133 agent_host->DisconnectRenderViewHost(); |
153 agent_host->ConnectRenderViewHost(current); | 134 agent_host->ConnectRenderViewHost(current); |
154 } | 135 } |
155 | 136 |
156 // static | |
157 bool RenderViewDevToolsAgentHost::DispatchIPCMessage( | |
158 RenderViewHost* source, | |
159 const IPC::Message& message) { | |
160 RenderViewDevToolsAgentHost* agent_host = FindAgentHost(source); | |
161 return agent_host && agent_host->DispatchIPCMessage(message); | |
162 } | |
163 | |
164 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(RenderViewHost* rvh) | 137 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(RenderViewHost* rvh) |
165 : render_view_host_(NULL), | 138 : render_view_host_(NULL), |
166 overrides_handler_(new RendererOverridesHandler(this)), | 139 overrides_handler_(new RendererOverridesHandler(this)), |
167 tracing_handler_( | 140 tracing_handler_( |
168 new DevToolsTracingHandler(DevToolsTracingHandler::Renderer)), | 141 new DevToolsTracingHandler(DevToolsTracingHandler::Renderer)), |
169 power_handler_(new DevToolsPowerHandler()), | 142 power_handler_(new DevToolsPowerHandler()), |
170 reattaching_(false) { | 143 reattaching_(false) { |
171 SetRenderViewHost(rvh); | 144 SetRenderViewHost(rvh); |
172 DevToolsProtocol::Notifier notifier(base::Bind( | 145 DevToolsProtocol::Notifier notifier(base::Bind( |
173 &RenderViewDevToolsAgentHost::OnDispatchOnInspectorFrontend, | 146 &RenderViewDevToolsAgentHost::OnDispatchOnInspectorFrontend, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 #if defined(OS_ANDROID) | 329 #if defined(OS_ANDROID) |
357 case base::TERMINATION_STATUS_OOM_PROTECTED: | 330 case base::TERMINATION_STATUS_OOM_PROTECTED: |
358 #endif | 331 #endif |
359 RenderViewCrashed(); | 332 RenderViewCrashed(); |
360 break; | 333 break; |
361 default: | 334 default: |
362 break; | 335 break; |
363 } | 336 } |
364 } | 337 } |
365 | 338 |
| 339 bool RenderViewDevToolsAgentHost::OnMessageReceived( |
| 340 const IPC::Message& message, |
| 341 RenderFrameHost* render_frame_host) { |
| 342 return DispatchIPCMessage(message); |
| 343 } |
| 344 |
| 345 bool RenderViewDevToolsAgentHost::OnMessageReceived( |
| 346 const IPC::Message& message) { |
| 347 return DispatchIPCMessage(message); |
| 348 } |
| 349 |
366 void RenderViewDevToolsAgentHost::DidAttachInterstitialPage() { | 350 void RenderViewDevToolsAgentHost::DidAttachInterstitialPage() { |
367 if (!render_view_host_) | 351 if (!render_view_host_) |
368 return; | 352 return; |
369 // The rvh set in AboutToNavigateRenderView turned out to be interstitial. | 353 // The rvh set in AboutToNavigateRenderView turned out to be interstitial. |
370 // Connect back to the real one. | 354 // Connect back to the real one. |
371 WebContents* web_contents = | 355 WebContents* web_contents = |
372 WebContents::FromRenderViewHost(render_view_host_); | 356 WebContents::FromRenderViewHost(render_view_host_); |
373 if (!web_contents) | 357 if (!web_contents) |
374 return; | 358 return; |
375 DisconnectRenderViewHost(); | 359 DisconnectRenderViewHost(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 DevToolsProtocol::ParseNotification(message); | 466 DevToolsProtocol::ParseNotification(message); |
483 | 467 |
484 if (notification) { | 468 if (notification) { |
485 tracing_handler_->HandleNotification(notification); | 469 tracing_handler_->HandleNotification(notification); |
486 } | 470 } |
487 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( | 471 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( |
488 this, message); | 472 this, message); |
489 } | 473 } |
490 | 474 |
491 } // namespace content | 475 } // namespace content |
OLD | NEW |