| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 tracing_handler_->SetNotifier(notifier); | 120 tracing_handler_->SetNotifier(notifier); |
| 121 power_handler_->SetNotifier(notifier); | 121 power_handler_->SetNotifier(notifier); |
| 122 g_instances.Get().push_back(this); | 122 g_instances.Get().push_back(this); |
| 123 AddRef(); // Balanced in RenderViewHostDestroyed. | 123 AddRef(); // Balanced in RenderViewHostDestroyed. |
| 124 } | 124 } |
| 125 | 125 |
| 126 WebContents* RenderViewDevToolsAgentHost::GetWebContents() { | 126 WebContents* RenderViewDevToolsAgentHost::GetWebContents() { |
| 127 return web_contents(); | 127 return web_contents(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void RenderViewDevToolsAgentHost::DispatchOnInspectorBackend( | 130 void RenderViewDevToolsAgentHost::DispatchProtocolMessage( |
| 131 const std::string& message) { | 131 const std::string& message) { |
| 132 std::string error_message; | 132 std::string error_message; |
| 133 | 133 |
| 134 scoped_ptr<base::DictionaryValue> message_dict( | 134 scoped_ptr<base::DictionaryValue> message_dict( |
| 135 DevToolsProtocol::ParseMessage(message, &error_message)); | 135 DevToolsProtocol::ParseMessage(message, &error_message)); |
| 136 scoped_refptr<DevToolsProtocol::Command> command = | 136 scoped_refptr<DevToolsProtocol::Command> command = |
| 137 DevToolsProtocol::ParseCommand(message_dict.get(), &error_message); | 137 DevToolsProtocol::ParseCommand(message_dict.get(), &error_message); |
| 138 | 138 |
| 139 if (command) { | 139 if (command) { |
| 140 scoped_refptr<DevToolsProtocol::Response> overridden_response; | 140 scoped_refptr<DevToolsProtocol::Response> overridden_response; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 154 overridden_response = tracing_handler_->HandleCommand(command); | 154 overridden_response = tracing_handler_->HandleCommand(command); |
| 155 if (!overridden_response) | 155 if (!overridden_response) |
| 156 overridden_response = power_handler_->HandleCommand(command); | 156 overridden_response = power_handler_->HandleCommand(command); |
| 157 if (overridden_response) { | 157 if (overridden_response) { |
| 158 if (!overridden_response->is_async_promise()) | 158 if (!overridden_response->is_async_promise()) |
| 159 OnDispatchOnInspectorFrontend(overridden_response->Serialize()); | 159 OnDispatchOnInspectorFrontend(overridden_response->Serialize()); |
| 160 return; | 160 return; |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 | 163 |
| 164 IPCDevToolsAgentHost::DispatchOnInspectorBackend(message); | 164 IPCDevToolsAgentHost::DispatchProtocolMessage(message); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void RenderViewDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) { | 167 void RenderViewDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) { |
| 168 if (!render_view_host_) | 168 if (!render_view_host_) |
| 169 return; | 169 return; |
| 170 msg->set_routing_id(render_view_host_->GetRoutingID()); | 170 msg->set_routing_id(render_view_host_->GetRoutingID()); |
| 171 render_view_host_->Send(msg); | 171 render_view_host_->Send(msg); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void RenderViewDevToolsAgentHost::OnClientAttached() { | 174 void RenderViewDevToolsAgentHost::OnClientAttached() { |
| 175 if (!render_view_host_) | 175 if (!render_view_host_) |
| 176 return; | 176 return; |
| 177 | 177 |
| 178 InnerOnClientAttached(); | 178 InnerOnClientAttached(); |
| 179 | 179 |
| 180 // TODO(kaznacheev): Move this call back to DevToolsManagerImpl when | 180 // TODO(kaznacheev): Move this call back to DevToolsManagerImpl when |
| 181 // extensions::ProcessManager no longer relies on this notification. | 181 // extensions::ProcessManager no longer relies on this notification. |
| 182 if (!reattaching_) | 182 if (!reattaching_) |
| 183 DevToolsManagerImpl::GetInstance()->NotifyObservers(this, true); | 183 DevToolsAgentHostImpl::NotifyCallbacks(this, true); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void RenderViewDevToolsAgentHost::InnerOnClientAttached() { | 186 void RenderViewDevToolsAgentHost::InnerOnClientAttached() { |
| 187 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( | 187 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( |
| 188 render_view_host_->GetProcess()->GetID()); | 188 render_view_host_->GetProcess()->GetID()); |
| 189 | 189 |
| 190 #if defined(OS_ANDROID) | 190 #if defined(OS_ANDROID) |
| 191 power_save_blocker_.reset( | 191 power_save_blocker_.reset( |
| 192 static_cast<PowerSaveBlockerImpl*>( | 192 static_cast<PowerSaveBlockerImpl*>( |
| 193 PowerSaveBlocker::Create( | 193 PowerSaveBlocker::Create( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 205 power_save_blocker_.reset(); | 205 power_save_blocker_.reset(); |
| 206 #endif | 206 #endif |
| 207 overrides_handler_->OnClientDetached(); | 207 overrides_handler_->OnClientDetached(); |
| 208 tracing_handler_->OnClientDetached(); | 208 tracing_handler_->OnClientDetached(); |
| 209 power_handler_->OnClientDetached(); | 209 power_handler_->OnClientDetached(); |
| 210 ClientDetachedFromRenderer(); | 210 ClientDetachedFromRenderer(); |
| 211 | 211 |
| 212 // TODO(kaznacheev): Move this call back to DevToolsManagerImpl when | 212 // TODO(kaznacheev): Move this call back to DevToolsManagerImpl when |
| 213 // extensions::ProcessManager no longer relies on this notification. | 213 // extensions::ProcessManager no longer relies on this notification. |
| 214 if (!reattaching_) | 214 if (!reattaching_) |
| 215 DevToolsManagerImpl::GetInstance()->NotifyObservers(this, false); | 215 DevToolsAgentHostImpl::NotifyCallbacks(this, false); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void RenderViewDevToolsAgentHost::ClientDetachedFromRenderer() { | 218 void RenderViewDevToolsAgentHost::ClientDetachedFromRenderer() { |
| 219 if (!render_view_host_) | 219 if (!render_view_host_) |
| 220 return; | 220 return; |
| 221 | 221 |
| 222 InnerClientDetachedFromRenderer(); | 222 InnerClientDetachedFromRenderer(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void RenderViewDevToolsAgentHost::InnerClientDetachedFromRenderer() { | 225 void RenderViewDevToolsAgentHost::InnerClientDetachedFromRenderer() { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 ConnectRenderViewHost(rvh); | 279 ConnectRenderViewHost(rvh); |
| 280 reattaching_ = false; | 280 reattaching_ = false; |
| 281 } | 281 } |
| 282 | 282 |
| 283 void RenderViewDevToolsAgentHost::RenderViewDeleted(RenderViewHost* rvh) { | 283 void RenderViewDevToolsAgentHost::RenderViewDeleted(RenderViewHost* rvh) { |
| 284 if (rvh != render_view_host_) | 284 if (rvh != render_view_host_) |
| 285 return; | 285 return; |
| 286 | 286 |
| 287 DCHECK(render_view_host_); | 287 DCHECK(render_view_host_); |
| 288 scoped_refptr<RenderViewDevToolsAgentHost> protect(this); | 288 scoped_refptr<RenderViewDevToolsAgentHost> protect(this); |
| 289 NotifyCloseListener(); | 289 HostClosed(); |
| 290 ClearRenderViewHost(); | 290 ClearRenderViewHost(); |
| 291 Release(); | 291 Release(); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void RenderViewDevToolsAgentHost::RenderProcessGone( | 294 void RenderViewDevToolsAgentHost::RenderProcessGone( |
| 295 base::TerminationStatus status) { | 295 base::TerminationStatus status) { |
| 296 switch(status) { | 296 switch(status) { |
| 297 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 297 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 298 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 298 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 299 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 299 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 | 379 |
| 380 void RenderViewDevToolsAgentHost::DisconnectRenderViewHost() { | 380 void RenderViewDevToolsAgentHost::DisconnectRenderViewHost() { |
| 381 ClientDetachedFromRenderer(); | 381 ClientDetachedFromRenderer(); |
| 382 ClearRenderViewHost(); | 382 ClearRenderViewHost(); |
| 383 } | 383 } |
| 384 | 384 |
| 385 void RenderViewDevToolsAgentHost::RenderViewCrashed() { | 385 void RenderViewDevToolsAgentHost::RenderViewCrashed() { |
| 386 scoped_refptr<DevToolsProtocol::Notification> notification = | 386 scoped_refptr<DevToolsProtocol::Notification> notification = |
| 387 DevToolsProtocol::CreateNotification( | 387 DevToolsProtocol::CreateNotification( |
| 388 devtools::Inspector::targetCrashed::kName, NULL); | 388 devtools::Inspector::targetCrashed::kName, NULL); |
| 389 DevToolsManagerImpl::GetInstance()-> | 389 SendMessageToClient(notification->Serialize()); |
| 390 DispatchOnInspectorFrontend(this, notification->Serialize()); | |
| 391 } | 390 } |
| 392 | 391 |
| 393 bool RenderViewDevToolsAgentHost::DispatchIPCMessage( | 392 bool RenderViewDevToolsAgentHost::DispatchIPCMessage( |
| 394 const IPC::Message& msg) { | 393 const IPC::Message& msg) { |
| 395 if (!render_view_host_) | 394 if (!render_view_host_) |
| 396 return false; | 395 return false; |
| 397 | 396 |
| 398 bool handled = true; | 397 bool handled = true; |
| 399 IPC_BEGIN_MESSAGE_MAP(RenderViewDevToolsAgentHost, msg) | 398 IPC_BEGIN_MESSAGE_MAP(RenderViewDevToolsAgentHost, msg) |
| 400 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, | 399 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 const std::string& message) { | 440 const std::string& message) { |
| 442 if (!render_view_host_) | 441 if (!render_view_host_) |
| 443 return; | 442 return; |
| 444 | 443 |
| 445 scoped_refptr<DevToolsProtocol::Notification> notification = | 444 scoped_refptr<DevToolsProtocol::Notification> notification = |
| 446 DevToolsProtocol::ParseNotification(message); | 445 DevToolsProtocol::ParseNotification(message); |
| 447 | 446 |
| 448 if (notification) { | 447 if (notification) { |
| 449 tracing_handler_->HandleNotification(notification); | 448 tracing_handler_->HandleNotification(notification); |
| 450 } | 449 } |
| 451 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( | 450 SendMessageToClient(message); |
| 452 this, message); | |
| 453 } | 451 } |
| 454 | 452 |
| 455 } // namespace content | 453 } // namespace content |
| OLD | NEW |