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/renderer/devtools_agent.h" | 5 #include "content/renderer/devtools_agent.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" |
10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
11 #include "base/process.h" | 12 #include "base/process.h" |
12 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
13 #include "content/common/devtools_messages.h" | 14 #include "content/common/devtools_messages.h" |
14 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
15 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
16 #include "content/renderer/devtools_agent_filter.h" | 17 #include "content/renderer/devtools_agent_filter.h" |
17 #include "content/renderer/devtools_client.h" | 18 #include "content/renderer/devtools_client.h" |
18 #include "content/renderer/render_view_impl.h" | 19 #include "content/renderer/render_view_impl.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" |
(...skipping 24 matching lines...) Expand all Loading... |
44 message_loop_->Run(); | 45 message_loop_->Run(); |
45 message_loop_->SetNestableTasksAllowed(old_state); | 46 message_loop_->SetNestableTasksAllowed(old_state); |
46 } | 47 } |
47 virtual void quitNow() { | 48 virtual void quitNow() { |
48 message_loop_->QuitNow(); | 49 message_loop_->QuitNow(); |
49 } | 50 } |
50 private: | 51 private: |
51 MessageLoop* message_loop_; | 52 MessageLoop* message_loop_; |
52 }; | 53 }; |
53 | 54 |
| 55 typedef std::map<int, DevToolsAgent*> IdToAgentMap; |
| 56 base::LazyInstance<IdToAgentMap, base::LeakyLazyInstanceTraits<IdToAgentMap> > |
| 57 g_agent_for_routing_id(base::LINKER_INITIALIZED); |
| 58 |
54 } // namespace | 59 } // namespace |
55 | 60 |
56 // static | |
57 std::map<int, DevToolsAgent*> DevToolsAgent::agent_for_routing_id_; | |
58 | |
59 DevToolsAgent::DevToolsAgent(RenderViewImpl* render_view) | 61 DevToolsAgent::DevToolsAgent(RenderViewImpl* render_view) |
60 : content::RenderViewObserver(render_view), | 62 : content::RenderViewObserver(render_view), |
61 is_attached_(false) { | 63 is_attached_(false) { |
62 agent_for_routing_id_[routing_id()] = this; | 64 g_agent_for_routing_id.Get()[routing_id()] = this; |
63 | 65 |
64 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 66 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
65 expose_v8_debugger_protocol_ = cmd->HasSwitch(switches::kRemoteShellPort); | 67 expose_v8_debugger_protocol_ = cmd->HasSwitch(switches::kRemoteShellPort); |
66 | 68 |
67 render_view->webview()->setDevToolsAgentClient(this); | 69 render_view->webview()->setDevToolsAgentClient(this); |
68 render_view->webview()->devToolsAgent()->setProcessId( | 70 render_view->webview()->devToolsAgent()->setProcessId( |
69 base::Process::Current().pid()); | 71 base::Process::Current().pid()); |
70 } | 72 } |
71 | 73 |
72 DevToolsAgent::~DevToolsAgent() { | 74 DevToolsAgent::~DevToolsAgent() { |
73 agent_for_routing_id_.erase(routing_id()); | 75 g_agent_for_routing_id.Get().erase(routing_id()); |
74 } | 76 } |
75 | 77 |
76 // Called on the Renderer thread. | 78 // Called on the Renderer thread. |
77 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { | 79 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { |
78 bool handled = true; | 80 bool handled = true; |
79 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) | 81 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) |
80 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach) | 82 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach) |
81 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Reattach, OnReattach) | 83 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Reattach, OnReattach) |
82 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach) | 84 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach) |
83 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_FrontendLoaded, OnFrontendLoaded) | 85 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_FrontendLoaded, OnFrontendLoaded) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 void DevToolsAgent::clearBrowserCache() { | 131 void DevToolsAgent::clearBrowserCache() { |
130 Send(new DevToolsHostMsg_ClearBrowserCache(routing_id())); | 132 Send(new DevToolsHostMsg_ClearBrowserCache(routing_id())); |
131 } | 133 } |
132 | 134 |
133 void DevToolsAgent::clearBrowserCookies() { | 135 void DevToolsAgent::clearBrowserCookies() { |
134 Send(new DevToolsHostMsg_ClearBrowserCookies(routing_id())); | 136 Send(new DevToolsHostMsg_ClearBrowserCookies(routing_id())); |
135 } | 137 } |
136 | 138 |
137 // static | 139 // static |
138 DevToolsAgent* DevToolsAgent::FromHostId(int host_id) { | 140 DevToolsAgent* DevToolsAgent::FromHostId(int host_id) { |
139 std::map<int, DevToolsAgent*>::iterator it = | 141 IdToAgentMap::iterator it = g_agent_for_routing_id.Get().find(host_id); |
140 agent_for_routing_id_.find(host_id); | 142 if (it != g_agent_for_routing_id.Get().end()) { |
141 if (it != agent_for_routing_id_.end()) { | |
142 return it->second; | 143 return it->second; |
143 } | 144 } |
144 return NULL; | 145 return NULL; |
145 } | 146 } |
146 | 147 |
147 void DevToolsAgent::OnAttach() { | 148 void DevToolsAgent::OnAttach() { |
148 WebDevToolsAgent* web_agent = GetWebAgent(); | 149 WebDevToolsAgent* web_agent = GetWebAgent(); |
149 if (web_agent) { | 150 if (web_agent) { |
150 web_agent->attach(); | 151 web_agent->attach(); |
151 is_attached_ = true; | 152 is_attached_ = true; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { | 203 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { |
203 WebView* web_view = render_view()->GetWebView(); | 204 WebView* web_view = render_view()->GetWebView(); |
204 if (!web_view) | 205 if (!web_view) |
205 return NULL; | 206 return NULL; |
206 return web_view->devToolsAgent(); | 207 return web_view->devToolsAgent(); |
207 } | 208 } |
208 | 209 |
209 bool DevToolsAgent::IsAttached() { | 210 bool DevToolsAgent::IsAttached() { |
210 return is_attached_; | 211 return is_attached_; |
211 } | 212 } |
OLD | NEW |