| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/debugger/render_view_devtools_agent_host.h" | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "content/browser/renderer_host/render_process_host.h" | |
| 9 #include "content/browser/renderer_host/render_view_host.h" | |
| 10 #include "content/browser/site_instance.h" | |
| 11 #include "content/common/notification_service.h" | |
| 12 | |
| 13 RenderViewDevToolsAgentHost::Instances RenderViewDevToolsAgentHost::instances_; | |
| 14 | |
| 15 DevToolsAgentHost* RenderViewDevToolsAgentHost::FindFor( | |
| 16 RenderViewHost* rvh) { | |
| 17 Instances::iterator it = instances_.find(rvh); | |
| 18 if (it != instances_.end()) | |
| 19 return it->second; | |
| 20 return new RenderViewDevToolsAgentHost(rvh); | |
| 21 } | |
| 22 | |
| 23 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(RenderViewHost* rvh) | |
| 24 : render_view_host_(rvh) { | |
| 25 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, | |
| 26 Source<RenderViewHost>(rvh)); | |
| 27 instances_[rvh] = this; | |
| 28 } | |
| 29 | |
| 30 void RenderViewDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) { | |
| 31 msg->set_routing_id(render_view_host_->routing_id()); | |
| 32 render_view_host_->Send(msg); | |
| 33 } | |
| 34 | |
| 35 void RenderViewDevToolsAgentHost::NotifyClientClosing() { | |
| 36 NotificationService::current()->Notify( | |
| 37 content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, | |
| 38 Source<content::BrowserContext>( | |
| 39 render_view_host_->site_instance()->GetProcess()->browser_context()), | |
| 40 Details<RenderViewHost>(render_view_host_)); | |
| 41 } | |
| 42 | |
| 43 int RenderViewDevToolsAgentHost::GetRenderProcessId() { | |
| 44 return render_view_host_->process()->id(); | |
| 45 } | |
| 46 | |
| 47 void RenderViewDevToolsAgentHost::Observe(int type, | |
| 48 const NotificationSource& source, | |
| 49 const NotificationDetails& details) { | |
| 50 DCHECK(type == content::NOTIFICATION_RENDER_VIEW_HOST_DELETED); | |
| 51 NotifyCloseListener(); | |
| 52 delete this; | |
| 53 } | |
| 54 | |
| 55 RenderViewDevToolsAgentHost::~RenderViewDevToolsAgentHost() { | |
| 56 instances_.erase(render_view_host_); | |
| 57 } | |
| 58 | |
| OLD | NEW |