OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/debugger/render_view_devtools_agent_host.h" | 5 #include "content/browser/debugger/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/debugger/devtools_manager.h" | 9 #include "content/browser/debugger/devtools_manager_impl.h" |
10 #include "content/browser/debugger/render_view_devtools_agent_host.h" | 10 #include "content/browser/debugger/render_view_devtools_agent_host.h" |
11 #include "content/browser/renderer_host/render_process_host_impl.h" | 11 #include "content/browser/renderer_host/render_process_host_impl.h" |
12 #include "content/browser/renderer_host/render_view_host.h" | 12 #include "content/browser/renderer_host/render_view_host.h" |
13 #include "content/browser/site_instance.h" | 13 #include "content/browser/site_instance.h" |
14 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
15 #include "content/common/devtools_messages.h" | 15 #include "content/common/devtools_messages.h" |
| 16 #include "content/public/browser/devtools/devtools_agent_host_registry.h" |
16 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
19 | 20 |
| 21 namespace content { |
| 22 |
20 typedef std::map<RenderViewHost*, RenderViewDevToolsAgentHost*> Instances; | 23 typedef std::map<RenderViewHost*, RenderViewDevToolsAgentHost*> Instances; |
21 | 24 |
22 namespace { | 25 namespace { |
23 base::LazyInstance<Instances, | 26 base::LazyInstance<Instances, |
24 base::LeakyLazyInstanceTraits<Instances> > | 27 base::LeakyLazyInstanceTraits<Instances> > |
25 g_instances = LAZY_INSTANCE_INITIALIZER; | 28 g_instances = LAZY_INSTANCE_INITIALIZER; |
26 } // namespace | 29 } // namespace |
27 | 30 |
28 DevToolsAgentHost* RenderViewDevToolsAgentHost::FindFor( | 31 |
| 32 // static |
| 33 DevToolsAgentHost* DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
29 RenderViewHost* rvh) { | 34 RenderViewHost* rvh) { |
30 Instances::iterator it = g_instances.Get().find(rvh); | 35 Instances::iterator it = g_instances.Get().find(rvh); |
31 if (it != g_instances.Get().end()) | 36 if (it != g_instances.Get().end()) |
32 return it->second; | 37 return it->second; |
33 return new RenderViewDevToolsAgentHost(rvh); | 38 return new RenderViewDevToolsAgentHost(rvh); |
34 } | 39 } |
35 | 40 |
36 bool RenderViewDevToolsAgentHost::IsDebuggerAttached( | 41 // static |
37 TabContents* tab_contents) { | 42 bool DevToolsAgentHostRegistry::HasDevToolsAgentHost(RenderViewHost* rvh) { |
| 43 if (g_instances == NULL) |
| 44 return false; |
| 45 Instances::iterator it = g_instances.Get().find(rvh); |
| 46 return it != g_instances.Get().end(); |
| 47 } |
| 48 |
| 49 bool DevToolsAgentHostRegistry::IsDebuggerAttached(TabContents* tab_contents) { |
| 50 if (g_instances == NULL) |
| 51 return false; |
38 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | 52 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
39 if (!devtools_manager) | 53 if (!devtools_manager) |
40 return false; | 54 return false; |
41 RenderViewHostDelegate* delegate = tab_contents; | 55 RenderViewHostDelegate* delegate = tab_contents; |
42 for (Instances::iterator it = g_instances.Get().begin(); | 56 for (Instances::iterator it = g_instances.Get().begin(); |
43 it != g_instances.Get().end(); ++it) { | 57 it != g_instances.Get().end(); ++it) { |
44 if (it->first->delegate() != delegate) | 58 if (it->first->delegate() != delegate) |
45 continue; | 59 continue; |
46 if (devtools_manager->GetDevToolsClientHostFor(it->second)) | 60 if (devtools_manager->GetDevToolsClientHostFor(it->second)) |
47 return true; | 61 return true; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 IPC_MESSAGE_HANDLER(DevToolsHostMsg_ClearBrowserCache, OnClearBrowserCache) | 106 IPC_MESSAGE_HANDLER(DevToolsHostMsg_ClearBrowserCache, OnClearBrowserCache) |
93 IPC_MESSAGE_HANDLER(DevToolsHostMsg_ClearBrowserCookies, | 107 IPC_MESSAGE_HANDLER(DevToolsHostMsg_ClearBrowserCookies, |
94 OnClearBrowserCookies) | 108 OnClearBrowserCookies) |
95 IPC_MESSAGE_UNHANDLED(handled = false) | 109 IPC_MESSAGE_UNHANDLED(handled = false) |
96 IPC_END_MESSAGE_MAP() | 110 IPC_END_MESSAGE_MAP() |
97 return handled; | 111 return handled; |
98 } | 112 } |
99 | 113 |
100 void RenderViewDevToolsAgentHost::OnSaveAgentRuntimeState( | 114 void RenderViewDevToolsAgentHost::OnSaveAgentRuntimeState( |
101 const std::string& state) { | 115 const std::string& state) { |
102 DevToolsManager::GetInstance()->SaveAgentRuntimeState(this, state); | 116 DevToolsManagerImpl::GetInstance()->SaveAgentRuntimeState(this, state); |
103 } | 117 } |
104 | 118 |
105 void RenderViewDevToolsAgentHost::OnForwardToClient( | 119 void RenderViewDevToolsAgentHost::OnForwardToClient( |
106 const IPC::Message& message) { | 120 const IPC::Message& message) { |
107 DevToolsManager::GetInstance()->ForwardToDevToolsClient( | 121 DevToolsManagerImpl::GetInstance()->ForwardToDevToolsClient( |
108 this, message); | 122 this, message); |
109 } | 123 } |
110 | 124 |
111 void RenderViewDevToolsAgentHost::OnClearBrowserCache() { | 125 void RenderViewDevToolsAgentHost::OnClearBrowserCache() { |
112 content::GetContentClient()->browser()->ClearCache(render_view_host_); | 126 content::GetContentClient()->browser()->ClearCache(render_view_host_); |
113 } | 127 } |
114 | 128 |
115 void RenderViewDevToolsAgentHost::OnClearBrowserCookies() { | 129 void RenderViewDevToolsAgentHost::OnClearBrowserCookies() { |
116 content::GetContentClient()->browser()->ClearCookies(render_view_host_); | 130 content::GetContentClient()->browser()->ClearCookies(render_view_host_); |
117 } | 131 } |
118 | 132 |
| 133 } // namespace content |
| 134 |
OLD | NEW |