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 <string> | 7 #include <string> |
8 | 8 |
9 #include "Document.h" | 9 #include "Document.h" |
10 #include "EventListener.h" | 10 #include "EventListener.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 debugger_agent_delegate_stub_.set(new DebuggerAgentDelegateStub(this)); | 49 debugger_agent_delegate_stub_.set(new DebuggerAgentDelegateStub(this)); |
50 dom_agent_delegate_stub_.set(new DomAgentDelegateStub(this)); | 50 dom_agent_delegate_stub_.set(new DomAgentDelegateStub(this)); |
51 net_agent_delegate_stub_.set(new NetAgentDelegateStub(this)); | 51 net_agent_delegate_stub_.set(new NetAgentDelegateStub(this)); |
52 tools_agent_delegate_stub_.set(new ToolsAgentDelegateStub(this)); | 52 tools_agent_delegate_stub_.set(new ToolsAgentDelegateStub(this)); |
53 | 53 |
54 // Sniff for requests from the beginning, do not wait for attach. | 54 // Sniff for requests from the beginning, do not wait for attach. |
55 net_agent_impl_.set(new NetAgentImpl(net_agent_delegate_stub_.get())); | 55 net_agent_impl_.set(new NetAgentImpl(net_agent_delegate_stub_.get())); |
56 } | 56 } |
57 | 57 |
58 WebDevToolsAgentImpl::~WebDevToolsAgentImpl() { | 58 WebDevToolsAgentImpl::~WebDevToolsAgentImpl() { |
| 59 if (!utility_context_.IsEmpty()) { |
| 60 utility_context_.Dispose(); |
| 61 } |
59 } | 62 } |
60 | 63 |
61 void WebDevToolsAgentImpl::Attach() { | 64 void WebDevToolsAgentImpl::Attach() { |
62 if (attached_) { | 65 if (attached_) { |
63 return; | 66 return; |
64 } | 67 } |
65 debugger_agent_impl_.set( | 68 debugger_agent_impl_.set( |
66 new DebuggerAgentImpl(web_view_impl_, | 69 new DebuggerAgentImpl(web_view_impl_, |
67 debugger_agent_delegate_stub_.get(), | 70 debugger_agent_delegate_stub_.get(), |
68 this)); | 71 this)); |
69 dom_agent_impl_.set(new DomAgentImpl(dom_agent_delegate_stub_.get())); | 72 dom_agent_impl_.set(new DomAgentImpl(dom_agent_delegate_stub_.get())); |
70 | 73 |
71 // We are potentially attaching to the running page -> init agents with | 74 // We are potentially attaching to the running page -> init agents with |
72 // Document if any. | 75 // Document if any. |
73 Page* page = web_view_impl_->page(); | 76 Page* page = web_view_impl_->page(); |
74 Document* doc = page->mainFrame()->document(); | 77 Document* doc = page->mainFrame()->document(); |
75 if (doc) { | 78 if (doc) { |
76 debugger_agent_impl_->SetDocument(doc); | 79 // Reuse existing context in case detached/attached. |
| 80 if (utility_context_.IsEmpty()) { |
| 81 debugger_agent_impl_->CreateUtilityContext(doc, &utility_context_); |
| 82 } |
77 dom_agent_impl_->SetDocument(doc); | 83 dom_agent_impl_->SetDocument(doc); |
78 net_agent_impl_->SetDocument(doc); | 84 net_agent_impl_->SetDocument(doc); |
79 } | 85 } |
80 | 86 |
81 // Populate console. | 87 // Populate console. |
82 for (Vector<ConsoleMessage>::iterator it = console_log_.begin(); | 88 for (Vector<ConsoleMessage>::iterator it = console_log_.begin(); |
83 it != console_log_.end(); ++it) { | 89 it != console_log_.end(); ++it) { |
84 DictionaryValue message; | 90 DictionaryValue message; |
85 Serialize(*it, &message); | 91 Serialize(*it, &message); |
86 tools_agent_delegate_stub_->AddMessageToConsole(message); | 92 tools_agent_delegate_stub_->AddMessageToConsole(message); |
(...skipping 16 matching lines...) Expand all Loading... |
103 } | 109 } |
104 | 110 |
105 // We were attached prior to the page load -> init agents with Document. | 111 // We were attached prior to the page load -> init agents with Document. |
106 Document* doc; | 112 Document* doc; |
107 if (ready) { | 113 if (ready) { |
108 Page* page = web_view_impl_->page(); | 114 Page* page = web_view_impl_->page(); |
109 doc = page->mainFrame()->document(); | 115 doc = page->mainFrame()->document(); |
110 } else { | 116 } else { |
111 doc = NULL; | 117 doc = NULL; |
112 } | 118 } |
113 debugger_agent_impl_->SetDocument(doc); | 119 debugger_agent_impl_->CreateUtilityContext(doc, &utility_context_); |
114 dom_agent_impl_->SetDocument(doc); | 120 dom_agent_impl_->SetDocument(doc); |
115 net_agent_impl_->SetDocument(doc); | 121 net_agent_impl_->SetDocument(doc); |
116 } | 122 } |
117 | 123 |
118 void WebDevToolsAgentImpl::DidCommitLoadForFrame( | 124 void WebDevToolsAgentImpl::DidCommitLoadForFrame( |
119 WebViewImpl* webview, | 125 WebViewImpl* webview, |
120 WebFrame* frame, | 126 WebFrame* frame, |
121 bool is_new_navigation) { | 127 bool is_new_navigation) { |
122 if (webview->GetMainFrame() == frame) { | 128 if (webview->GetMainFrame() == frame) { |
123 net_agent_impl_->DidCommitMainResourceLoad(); | 129 net_agent_impl_->DidCommitMainResourceLoad(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 196 |
191 void WebDevToolsAgentImpl::ExecuteUtilityFunction( | 197 void WebDevToolsAgentImpl::ExecuteUtilityFunction( |
192 int call_id, | 198 int call_id, |
193 const String& function_name, | 199 const String& function_name, |
194 int node_id, | 200 int node_id, |
195 const String& json_args) { | 201 const String& json_args) { |
196 Node* node = dom_agent_impl_->GetNodeForId(node_id); | 202 Node* node = dom_agent_impl_->GetNodeForId(node_id); |
197 String result; | 203 String result; |
198 String exception; | 204 String exception; |
199 if (node) { | 205 if (node) { |
200 result = debugger_agent_impl_->ExecuteUtilityFunction(function_name, node, | 206 result = debugger_agent_impl_->ExecuteUtilityFunction(utility_context_, |
201 json_args, &exception); | 207 function_name, node, json_args, &exception); |
202 } | 208 } |
203 tools_agent_delegate_stub_->DidExecuteUtilityFunction(call_id, | 209 tools_agent_delegate_stub_->DidExecuteUtilityFunction(call_id, |
204 result, exception); | 210 result, exception); |
205 } | 211 } |
206 | 212 |
207 void WebDevToolsAgentImpl::ClearConsoleMessages() { | 213 void WebDevToolsAgentImpl::ClearConsoleMessages() { |
208 console_log_.clear(); | 214 console_log_.clear(); |
209 } | 215 } |
210 | 216 |
211 void WebDevToolsAgentImpl::DispatchMessageFromClient( | 217 void WebDevToolsAgentImpl::DispatchMessageFromClient( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 const std::string& command, | 271 const std::string& command, |
266 int caller_id) { | 272 int caller_id) { |
267 DebuggerAgentManager::ExecuteDebuggerCommand(command, caller_id); | 273 DebuggerAgentManager::ExecuteDebuggerCommand(command, caller_id); |
268 } | 274 } |
269 | 275 |
270 // static | 276 // static |
271 void WebDevToolsAgent::SetMessageLoopDispatchHandler( | 277 void WebDevToolsAgent::SetMessageLoopDispatchHandler( |
272 MessageLoopDispatchHandler handler) { | 278 MessageLoopDispatchHandler handler) { |
273 DebuggerAgentManager::SetMessageLoopDispatchHandler(handler); | 279 DebuggerAgentManager::SetMessageLoopDispatchHandler(handler); |
274 } | 280 } |
OLD | NEW |