OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "Frame.h" | 7 #include "Frame.h" |
8 #include "PageGroupLoadDeferrer.h" | 8 #include "PageGroupLoadDeferrer.h" |
9 #include "V8Proxy.h" | 9 #include "V8Proxy.h" |
10 #include <wtf/HashSet.h> | 10 #include <wtf/HashSet.h> |
11 #undef LOG | 11 #undef LOG |
12 | 12 |
13 #include "base/string_util.h" | |
14 #include "webkit/api/public/WebDevToolsAgent.h" | 13 #include "webkit/api/public/WebDevToolsAgent.h" |
15 #include "webkit/glue/devtools/debugger_agent_impl.h" | 14 #include "webkit/glue/devtools/debugger_agent_impl.h" |
16 #include "webkit/glue/devtools/debugger_agent_manager.h" | 15 #include "webkit/glue/devtools/debugger_agent_manager.h" |
17 #include "webkit/glue/webdevtoolsagent_impl.h" | 16 #include "webkit/glue/webdevtoolsagent_impl.h" |
18 #include "webkit/glue/webview_impl.h" | 17 #include "webkit/glue/webview_impl.h" |
19 | 18 |
20 #if USE(V8) | 19 #if USE(V8) |
21 #include "v8/include/v8-debug.h" | 20 #include "v8/include/v8-debug.h" |
22 #endif | 21 #endif |
23 | 22 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 109 |
111 // static | 110 // static |
112 void DebuggerAgentManager::DebugAttach(DebuggerAgentImpl* debugger_agent) { | 111 void DebuggerAgentManager::DebugAttach(DebuggerAgentImpl* debugger_agent) { |
113 if (!attached_agents_map_) { | 112 if (!attached_agents_map_) { |
114 attached_agents_map_ = new AttachedAgentsMap(); | 113 attached_agents_map_ = new AttachedAgentsMap(); |
115 v8::Debug::SetMessageHandler2(&DebuggerAgentManager::OnV8DebugMessage); | 114 v8::Debug::SetMessageHandler2(&DebuggerAgentManager::OnV8DebugMessage); |
116 v8::Debug::SetHostDispatchHandler( | 115 v8::Debug::SetHostDispatchHandler( |
117 &DebuggerAgentManager::V8DebugHostDispatchHandler, 100 /* ms */); | 116 &DebuggerAgentManager::V8DebugHostDispatchHandler, 100 /* ms */); |
118 } | 117 } |
119 int host_id = debugger_agent->webdevtools_agent()->host_id(); | 118 int host_id = debugger_agent->webdevtools_agent()->host_id(); |
120 DCHECK(host_id != 0); | 119 ASSERT(host_id != 0); |
121 attached_agents_map_->set(host_id, debugger_agent); | 120 attached_agents_map_->set(host_id, debugger_agent); |
122 } | 121 } |
123 | 122 |
124 // static | 123 // static |
125 void DebuggerAgentManager::DebugDetach(DebuggerAgentImpl* debugger_agent) { | 124 void DebuggerAgentManager::DebugDetach(DebuggerAgentImpl* debugger_agent) { |
126 if (!attached_agents_map_) { | 125 if (!attached_agents_map_) { |
127 NOTREACHED(); | 126 ASSERT_NOT_REACHED(); |
128 return; | 127 return; |
129 } | 128 } |
130 int host_id = debugger_agent->webdevtools_agent()->host_id(); | 129 int host_id = debugger_agent->webdevtools_agent()->host_id(); |
131 DCHECK(attached_agents_map_->get(host_id) == debugger_agent); | 130 ASSERT(attached_agents_map_->get(host_id) == debugger_agent); |
132 bool is_on_breakpoint = (FindAgentForCurrentV8Context() == debugger_agent); | 131 bool is_on_breakpoint = (FindAgentForCurrentV8Context() == debugger_agent); |
133 attached_agents_map_->remove(host_id); | 132 attached_agents_map_->remove(host_id); |
134 | 133 |
135 if (attached_agents_map_->isEmpty()) { | 134 if (attached_agents_map_->isEmpty()) { |
136 delete attached_agents_map_; | 135 delete attached_agents_map_; |
137 attached_agents_map_ = NULL; | 136 attached_agents_map_ = NULL; |
138 // Note that we do not empty handlers while in dispatch - we schedule | 137 // Note that we do not empty handlers while in dispatch - we schedule |
139 // continue and do removal once we are out of the dispatch. Also there is | 138 // continue and do removal once we are out of the dispatch. Also there is |
140 // no need to send continue command in this case since removing message | 139 // no need to send continue command in this case since removing message |
141 // handler will cause debugger unload and all breakpoints will be cleared. | 140 // handler will cause debugger unload and all breakpoints will be cleared. |
(...skipping 14 matching lines...) Expand all Loading... |
156 // debugger was paused on a breakpoint(as long as there are other | 155 // debugger was paused on a breakpoint(as long as there are other |
157 // attached agents v8 will wait for explicit'continue' message). | 156 // attached agents v8 will wait for explicit'continue' message). |
158 SendContinueCommandToV8(); | 157 SendContinueCommandToV8(); |
159 } | 158 } |
160 } | 159 } |
161 } | 160 } |
162 | 161 |
163 // static | 162 // static |
164 void DebuggerAgentManager::DebugBreak(DebuggerAgentImpl* debugger_agent) { | 163 void DebuggerAgentManager::DebugBreak(DebuggerAgentImpl* debugger_agent) { |
165 #if USE(V8) | 164 #if USE(V8) |
166 DCHECK(DebuggerAgentForHostId(debugger_agent->webdevtools_agent()->host_id()) | 165 ASSERT(DebuggerAgentForHostId(debugger_agent->webdevtools_agent()->host_id()) |
167 == debugger_agent); | 166 == debugger_agent); |
168 if (in_utility_context_) { | 167 if (in_utility_context_) { |
169 debug_break_delayed_ = true; | 168 debug_break_delayed_ = true; |
170 } else { | 169 } else { |
171 v8::Debug::DebugBreak(); | 170 v8::Debug::DebugBreak(); |
172 } | 171 } |
173 #endif | 172 #endif |
174 } | 173 } |
175 | 174 |
176 // static | 175 // static |
(...skipping 12 matching lines...) Expand all Loading... |
189 DebuggerAgentImpl* debugger_agent = | 188 DebuggerAgentImpl* debugger_agent = |
190 DebuggerAgentForHostId(wrapper->caller_id()); | 189 DebuggerAgentForHostId(wrapper->caller_id()); |
191 if (debugger_agent) { | 190 if (debugger_agent) { |
192 debugger_agent->DebuggerOutput(out); | 191 debugger_agent->DebuggerOutput(out); |
193 } else if (!message.WillStartRunning()) { | 192 } else if (!message.WillStartRunning()) { |
194 // Autocontinue execution if there is no handler. | 193 // Autocontinue execution if there is no handler. |
195 SendContinueCommandToV8(); | 194 SendContinueCommandToV8(); |
196 } | 195 } |
197 return; | 196 return; |
198 } // Otherwise it's an event message. | 197 } // Otherwise it's an event message. |
199 DCHECK(message.IsEvent()); | 198 ASSERT(message.IsEvent()); |
200 | 199 |
201 // Ignore unsupported event types. | 200 // Ignore unsupported event types. |
202 if (message.GetEvent() != v8::AfterCompile && | 201 if (message.GetEvent() != v8::AfterCompile && |
203 message.GetEvent() != v8::Break && | 202 message.GetEvent() != v8::Break && |
204 message.GetEvent() != v8::Exception) { | 203 message.GetEvent() != v8::Exception) { |
205 return; | 204 return; |
206 } | 205 } |
207 | 206 |
208 v8::Handle<v8::Context> context = message.GetEventContext(); | 207 v8::Handle<v8::Context> context = message.GetEventContext(); |
209 // If the context is from one of the inpected tabs it should have its context | 208 // If the context is from one of the inpected tabs it should have its context |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 246 } |
248 | 247 |
249 // static | 248 // static |
250 void DebuggerAgentManager::SetMessageLoopDispatchHandler( | 249 void DebuggerAgentManager::SetMessageLoopDispatchHandler( |
251 WebDevToolsAgent::MessageLoopDispatchHandler handler) { | 250 WebDevToolsAgent::MessageLoopDispatchHandler handler) { |
252 message_loop_dispatch_handler_ = handler; | 251 message_loop_dispatch_handler_ = handler; |
253 } | 252 } |
254 | 253 |
255 // static | 254 // static |
256 void DebuggerAgentManager::SetHostId(WebFrameImpl* webframe, int host_id) { | 255 void DebuggerAgentManager::SetHostId(WebFrameImpl* webframe, int host_id) { |
257 DCHECK(host_id > 0); | 256 ASSERT(host_id > 0); |
258 WebCore::V8Proxy* proxy = WebCore::V8Proxy::retrieve(webframe->frame()); | 257 WebCore::V8Proxy* proxy = WebCore::V8Proxy::retrieve(webframe->frame()); |
259 if (proxy) { | 258 if (proxy) { |
260 proxy->setContextDebugId(host_id); | 259 proxy->setContextDebugId(host_id); |
261 } | 260 } |
262 } | 261 } |
263 | 262 |
264 // static | 263 // static |
265 void DebuggerAgentManager::OnWebViewClosed(WebViewImpl* webview) { | 264 void DebuggerAgentManager::OnWebViewClosed(WebViewImpl* webview) { |
266 if (page_deferrers_.contains(webview)) { | 265 if (page_deferrers_.contains(webview)) { |
267 delete page_deferrers_.get(webview); | 266 delete page_deferrers_.get(webview); |
(...skipping 22 matching lines...) Expand all Loading... |
290 String continue_cmd( | 289 String continue_cmd( |
291 "{\"seq\":1,\"type\":\"request\",\"command\":\"continue\"}"); | 290 "{\"seq\":1,\"type\":\"request\",\"command\":\"continue\"}"); |
292 SendCommandToV8(continue_cmd, new CallerIdWrapper()); | 291 SendCommandToV8(continue_cmd, new CallerIdWrapper()); |
293 } | 292 } |
294 | 293 |
295 // static | 294 // static |
296 DebuggerAgentImpl* DebuggerAgentManager::FindAgentForCurrentV8Context() { | 295 DebuggerAgentImpl* DebuggerAgentManager::FindAgentForCurrentV8Context() { |
297 if (!attached_agents_map_) { | 296 if (!attached_agents_map_) { |
298 return NULL; | 297 return NULL; |
299 } | 298 } |
300 DCHECK(!attached_agents_map_->isEmpty()); | 299 ASSERT(!attached_agents_map_->isEmpty()); |
301 | 300 |
302 WebCore::Frame* frame = WebCore::V8Proxy::retrieveFrameForEnteredContext(); | 301 WebCore::Frame* frame = WebCore::V8Proxy::retrieveFrameForEnteredContext(); |
303 if (!frame) { | 302 if (!frame) { |
304 return NULL; | 303 return NULL; |
305 } | 304 } |
306 WebCore::Page* page = frame->page(); | 305 WebCore::Page* page = frame->page(); |
307 for (AttachedAgentsMap::iterator it = attached_agents_map_->begin(); | 306 for (AttachedAgentsMap::iterator it = attached_agents_map_->begin(); |
308 it != attached_agents_map_->end(); ++it) { | 307 it != attached_agents_map_->end(); ++it) { |
309 if (it->second->GetPage() == page) { | 308 if (it->second->GetPage() == page) { |
310 return it->second; | 309 return it->second; |
311 } | 310 } |
312 } | 311 } |
313 return NULL; | 312 return NULL; |
314 } | 313 } |
315 | 314 |
316 // static | 315 // static |
317 DebuggerAgentImpl* DebuggerAgentManager::DebuggerAgentForHostId(int host_id) { | 316 DebuggerAgentImpl* DebuggerAgentManager::DebuggerAgentForHostId(int host_id) { |
318 if (!attached_agents_map_) { | 317 if (!attached_agents_map_) { |
319 return NULL; | 318 return NULL; |
320 } | 319 } |
321 return attached_agents_map_->get(host_id); | 320 return attached_agents_map_->get(host_id); |
322 } | 321 } |
OLD | NEW |