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/child_process_security_policy.h" | |
9 #include "content/browser/debugger/devtools_client_host.h" | |
10 #include "content/browser/debugger/devtools_manager.h" | |
11 #include "content/browser/renderer_host/render_process_host.h" | |
12 #include "content/browser/renderer_host/render_view_host.h" | |
13 #include "content/browser/site_instance.h" | |
14 #include "content/common/notification_service.h" | |
15 | |
16 RenderViewDevToolsAgentHost::Instances RenderViewDevToolsAgentHost::instances_; | |
17 | |
18 DevToolsAgentHost* RenderViewDevToolsAgentHost::FindFor( | |
19 RenderViewHost* rvh) { | |
20 Instances::iterator it = instances_.find(rvh); | |
21 if (it != instances_.end()) | |
22 return it->second; | |
23 return NULL; | |
24 } | |
25 | |
26 DevToolsAgentHost* RenderViewDevToolsAgentHost::CreateFor( | |
27 RenderViewHost* rvh) { | |
28 DCHECK(!FindFor(rvh)); | |
29 RenderViewDevToolsAgentHost* result = new RenderViewDevToolsAgentHost(rvh); | |
30 return result; | |
31 } | |
32 | |
33 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(RenderViewHost* rvh) | |
34 : DevToolsAgentHost(rvh->routing_id()), | |
35 render_view_host_(rvh) { | |
36 ChildProcessSecurityPolicy::GetInstance()->GrantReadRawCookies( | |
37 rvh->process()->id()); | |
38 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, | |
39 Source<RenderViewHost>(rvh)); | |
40 instances_[rvh] = this; | |
41 } | |
42 | |
43 void RenderViewDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) { | |
44 render_view_host_->Send(msg); | |
45 } | |
46 | |
47 void RenderViewDevToolsAgentHost::NotifyClientClosing() { | |
48 NotificationService::current()->Notify( | |
49 content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, | |
50 Source<content::BrowserContext>( | |
51 render_view_host_->site_instance()->GetProcess()->browser_context()), | |
52 Details<RenderViewHost>(render_view_host_)); | |
53 } | |
54 | |
55 void RenderViewDevToolsAgentHost::ClientDetached() { | |
56 delete this; | |
57 } | |
58 | |
59 void RenderViewDevToolsAgentHost::Observe(int type, | |
60 const NotificationSource& source, | |
61 const NotificationDetails& details) { | |
62 DCHECK(type == content::NOTIFICATION_RENDER_VIEW_HOST_DELETED); | |
63 DevToolsManager::GetInstance()->UnregisterDevToolsClientHostFor(this); | |
pfeldman
2011/08/16 06:48:57
I'd copy the DevToolsClientHost's NotifyCloseListe
yurys
2011/08/16 08:14:48
Done.
| |
64 } | |
65 | |
66 RenderViewDevToolsAgentHost::~RenderViewDevToolsAgentHost() { | |
67 instances_.erase(render_view_host_); | |
68 | |
69 int process_id = render_view_host_->process()->id(); | |
70 for (Instances::iterator it = instances_.begin(); | |
71 it != instances_.end(); | |
72 ++it) { | |
73 if (it->first->process()->id() == process_id) | |
74 return; | |
75 } | |
76 // We've disconnected from the last renderer -> revoke cookie permissions. | |
77 ChildProcessSecurityPolicy::GetInstance()->RevokeReadRawCookies(process_id); | |
78 } | |
79 | |
OLD | NEW |