| 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/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
| 11 #include "content/browser/devtools/devtools_manager_impl.h" | 11 #include "content/browser/devtools/devtools_manager_impl.h" |
| 12 #include "content/browser/devtools/devtools_protocol.h" | 12 #include "content/browser/devtools/devtools_protocol.h" |
| 13 #include "content/browser/devtools/renderer_overrides_handler.h" | 13 #include "content/browser/devtools/renderer_overrides_handler.h" |
| 14 #include "content/browser/renderer_host/render_process_host_impl.h" | 14 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 15 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 16 #include "content/browser/site_instance_impl.h" | 16 #include "content/browser/site_instance_impl.h" |
| 17 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
| 18 #include "content/common/devtools_messages.h" | 18 #include "content/common/devtools_messages.h" |
| 19 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
| 20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
| 22 #include "content/public/browser/render_widget_host_view.h" | 22 #include "content/public/browser/render_widget_host_view.h" |
| 23 #include "content/public/browser/web_contents_observer.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" |
| 24 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
| 25 #include "ui/gfx/native_widget_types.h" | 26 #include "ui/gfx/native_widget_types.h" |
| 26 #include "ui/snapshot/snapshot.h" | 27 #include "ui/snapshot/snapshot.h" |
| 27 | 28 |
| 28 | 29 |
| 29 namespace content { | 30 namespace content { |
| 30 | 31 |
| 31 typedef std::vector<RenderViewDevToolsAgentHost*> Instances; | 32 typedef std::vector<RenderViewDevToolsAgentHost*> Instances; |
| 32 | 33 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 62 agent_host_->RenderViewHostDestroyed(rvh); | 63 agent_host_->RenderViewHostDestroyed(rvh); |
| 63 } | 64 } |
| 64 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 65 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
| 65 return agent_host_->OnRvhMessageReceived(message); | 66 return agent_host_->OnRvhMessageReceived(message); |
| 66 } | 67 } |
| 67 private: | 68 private: |
| 68 RenderViewDevToolsAgentHost* agent_host_; | 69 RenderViewDevToolsAgentHost* agent_host_; |
| 69 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentHostRvhObserver); | 70 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentHostRvhObserver); |
| 70 }; | 71 }; |
| 71 | 72 |
| 73 class DevToolsAgentHostWebContentsObserver : public WebContentsObserver { |
| 74 public: |
| 75 DevToolsAgentHostWebContentsObserver( |
| 76 WebContents* web_contents, |
| 77 RenderViewDevToolsAgentHost* agent_host) |
| 78 : WebContentsObserver(web_contents), |
| 79 agent_host_(agent_host) { |
| 80 } |
| 81 virtual ~DevToolsAgentHostWebContentsObserver() {} |
| 82 |
| 83 // WebContentsObserver overrides. |
| 84 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE { |
| 85 switch(status) { |
| 86 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 87 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 88 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 89 agent_host_->RenderViewCrashed(); |
| 90 break; |
| 91 default: |
| 92 break; |
| 93 } |
| 94 } |
| 95 private: |
| 96 RenderViewDevToolsAgentHost* agent_host_; |
| 97 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentHostWebContentsObserver); |
| 98 }; |
| 99 |
| 72 // static | 100 // static |
| 73 scoped_refptr<DevToolsAgentHost> | 101 scoped_refptr<DevToolsAgentHost> |
| 74 DevToolsAgentHost::GetOrCreateFor(RenderViewHost* rvh) { | 102 DevToolsAgentHost::GetOrCreateFor(RenderViewHost* rvh) { |
| 75 RenderViewDevToolsAgentHost* result = FindAgentHost(rvh); | 103 RenderViewDevToolsAgentHost* result = FindAgentHost(rvh); |
| 76 if (!result) | 104 if (!result) |
| 77 result = new RenderViewDevToolsAgentHost(rvh); | 105 result = new RenderViewDevToolsAgentHost(rvh); |
| 78 return result; | 106 return result; |
| 79 } | 107 } |
| 80 | 108 |
| 81 // static | 109 // static |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 base::TERMINATION_STATUS_STILL_RUNNING) | 296 base::TERMINATION_STATUS_STILL_RUNNING) |
| 269 return; | 297 return; |
| 270 DisconnectRenderViewHost(); | 298 DisconnectRenderViewHost(); |
| 271 ConnectRenderViewHost(dest_rvh, true); | 299 ConnectRenderViewHost(dest_rvh, true); |
| 272 } | 300 } |
| 273 | 301 |
| 274 void RenderViewDevToolsAgentHost::ConnectRenderViewHost(RenderViewHost* rvh, | 302 void RenderViewDevToolsAgentHost::ConnectRenderViewHost(RenderViewHost* rvh, |
| 275 bool reattach) { | 303 bool reattach) { |
| 276 render_view_host_ = rvh; | 304 render_view_host_ = rvh; |
| 277 rvh_observer_.reset(new DevToolsAgentHostRvhObserver(rvh, this)); | 305 rvh_observer_.reset(new DevToolsAgentHostRvhObserver(rvh, this)); |
| 306 web_contents_observer_.reset(new DevToolsAgentHostWebContentsObserver( |
| 307 WebContents::FromRenderViewHost(rvh), this)); |
| 278 if (reattach) | 308 if (reattach) |
| 279 Reattach(state_); | 309 Reattach(state_); |
| 280 } | 310 } |
| 281 | 311 |
| 282 void RenderViewDevToolsAgentHost::DisconnectRenderViewHost() { | 312 void RenderViewDevToolsAgentHost::DisconnectRenderViewHost() { |
| 283 NotifyClientDetaching(); | 313 NotifyClientDetaching(); |
| 284 rvh_observer_.reset(); | 314 rvh_observer_.reset(); |
| 315 web_contents_observer_.reset(); |
| 285 render_view_host_ = NULL; | 316 render_view_host_ = NULL; |
| 286 } | 317 } |
| 287 | 318 |
| 288 void RenderViewDevToolsAgentHost::RenderViewHostDestroyed( | 319 void RenderViewDevToolsAgentHost::RenderViewHostDestroyed( |
| 289 RenderViewHost* rvh) { | 320 RenderViewHost* rvh) { |
| 290 DCHECK(render_view_host_); | 321 DCHECK(render_view_host_); |
| 291 scoped_refptr<RenderViewDevToolsAgentHost> protect(this); | 322 scoped_refptr<RenderViewDevToolsAgentHost> protect(this); |
| 292 NotifyCloseListener(); | 323 NotifyCloseListener(); |
| 293 render_view_host_ = NULL; | 324 render_view_host_ = NULL; |
| 294 Release(); | 325 Release(); |
| 295 } | 326 } |
| 296 | 327 |
| 328 void RenderViewDevToolsAgentHost::RenderViewCrashed() { |
| 329 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( |
| 330 this, |
| 331 WebDevToolsAgent::inspectorTargetCrashedEvent().utf8()); |
| 332 } |
| 333 |
| 297 bool RenderViewDevToolsAgentHost::OnRvhMessageReceived( | 334 bool RenderViewDevToolsAgentHost::OnRvhMessageReceived( |
| 298 const IPC::Message& message) { | 335 const IPC::Message& message) { |
| 299 bool handled = true; | 336 bool handled = true; |
| 300 IPC_BEGIN_MESSAGE_MAP(RenderViewDevToolsAgentHost, message) | 337 IPC_BEGIN_MESSAGE_MAP(RenderViewDevToolsAgentHost, message) |
| 301 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, | 338 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, |
| 302 OnDispatchOnInspectorFrontend) | 339 OnDispatchOnInspectorFrontend) |
| 303 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, | 340 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, |
| 304 OnSaveAgentRuntimeState) | 341 OnSaveAgentRuntimeState) |
| 305 IPC_MESSAGE_HANDLER(DevToolsHostMsg_ClearBrowserCache, OnClearBrowserCache) | 342 IPC_MESSAGE_HANDLER(DevToolsHostMsg_ClearBrowserCache, OnClearBrowserCache) |
| 306 IPC_MESSAGE_HANDLER(DevToolsHostMsg_ClearBrowserCookies, | 343 IPC_MESSAGE_HANDLER(DevToolsHostMsg_ClearBrowserCookies, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 snapshot_bounds)) | 413 snapshot_bounds)) |
| 377 return false; | 414 return false; |
| 378 | 415 |
| 379 return base::Base64Encode(base::StringPiece( | 416 return base::Base64Encode(base::StringPiece( |
| 380 reinterpret_cast<char*>(&*png.begin()), | 417 reinterpret_cast<char*>(&*png.begin()), |
| 381 png.size()), | 418 png.size()), |
| 382 base_64_data); | 419 base_64_data); |
| 383 } | 420 } |
| 384 | 421 |
| 385 } // namespace content | 422 } // namespace content |
| OLD | NEW |