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 <wtf/HashSet.h> | 7 #include <wtf/HashSet.h> |
8 #include <wtf/RefPtr.h> | 8 #include <wtf/RefPtr.h> |
9 #include <wtf/Vector.h> | 9 #include <wtf/Vector.h> |
10 | 10 |
11 #include "Document.h" | 11 #include "Document.h" |
12 #include "Node.h" | 12 #include "Node.h" |
13 #include "Page.h" | 13 #include "Page.h" |
14 #include "PageGroupLoadDeferrer.h" | 14 #include "PageGroupLoadDeferrer.h" |
15 #undef LOG | 15 #undef LOG |
16 | 16 |
17 #include "grit/webkit_resources.h" | 17 #include "grit/webkit_resources.h" |
18 #include "V8Binding.h" | 18 #include "V8Binding.h" |
19 #include "V8DOMWindow.h" | 19 #include "V8DOMWindow.h" |
| 20 #include "v8_binding.h" |
20 #include "v8_index.h" | 21 #include "v8_index.h" |
21 #include "v8_proxy.h" | 22 #include "v8_proxy.h" |
22 #include "webkit/glue/devtools/debugger_agent_impl.h" | 23 #include "webkit/glue/devtools/debugger_agent_impl.h" |
23 #include "webkit/glue/devtools/debugger_agent_manager.h" | 24 #include "webkit/glue/devtools/debugger_agent_manager.h" |
24 #include "webkit/glue/glue_util.h" | 25 #include "webkit/glue/glue_util.h" |
25 #include "webkit/glue/webdevtoolsagent_impl.h" | 26 #include "webkit/glue/webdevtoolsagent_impl.h" |
26 #include "webkit/glue/webkit_glue.h" | 27 #include "webkit/glue/webkit_glue.h" |
27 #include "webkit/glue/webview_impl.h" | 28 #include "webkit/glue/webview_impl.h" |
28 | 29 |
29 using WebCore::DOMWindow; | 30 using WebCore::DOMWindow; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // original context. | 105 // original context. |
105 global->Set(v8::String::New("contentWindow"), window_global); | 106 global->Set(v8::String::New("contentWindow"), window_global); |
106 | 107 |
107 // Inject javascript into the context. | 108 // Inject javascript into the context. |
108 StringPiece basejs = webkit_glue::GetDataResource(IDR_DEVTOOLS_BASE_JS); | 109 StringPiece basejs = webkit_glue::GetDataResource(IDR_DEVTOOLS_BASE_JS); |
109 v8::Script::Compile(v8::String::New(basejs.as_string().c_str()))->Run(); | 110 v8::Script::Compile(v8::String::New(basejs.as_string().c_str()))->Run(); |
110 StringPiece jsonjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_JSON_JS); | 111 StringPiece jsonjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_JSON_JS); |
111 v8::Script::Compile(v8::String::New(jsonjs.as_string().c_str()))->Run(); | 112 v8::Script::Compile(v8::String::New(jsonjs.as_string().c_str()))->Run(); |
112 StringPiece injectjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_INJECT_JS); | 113 StringPiece injectjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_INJECT_JS); |
113 v8::Script::Compile(v8::String::New(injectjs.as_string().c_str()))->Run(); | 114 v8::Script::Compile(v8::String::New(injectjs.as_string().c_str()))->Run(); |
| 115 StringPiece inject_dispatchjs = webkit_glue::GetDataResource( |
| 116 IDR_DEVTOOLS_INJECT_DISPATCH_JS); |
| 117 v8::Script::Compile(v8::String::New( |
| 118 inject_dispatchjs.as_string().c_str()))->Run(); |
114 } | 119 } |
115 | 120 |
116 String DebuggerAgentImpl::ExecuteUtilityFunction( | 121 String DebuggerAgentImpl::ExecuteUtilityFunction( |
117 const String &function_name, | 122 const String &function_name, |
118 Node* node, | 123 Node* node, |
119 const String& json_args) { | 124 const String& json_args, |
| 125 String* exception) { |
120 v8::HandleScope scope; | 126 v8::HandleScope scope; |
121 ASSERT(!context_.IsEmpty()); | 127 ASSERT(!context_.IsEmpty()); |
122 v8::Context::Scope context_scope(context_); | 128 v8::Context::Scope context_scope(context_); |
123 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast( | 129 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast( |
124 context_->Global()->Get(v8::String::New(function_name.utf8().data()))); | 130 context_->Global()->Get(v8::String::New("devtools$$dispatch"))); |
125 | 131 |
126 v8::Handle<v8::Value> node_wrapper = | 132 v8::Handle<v8::Value> node_wrapper = |
127 V8Proxy::ToV8Object(V8ClassIndex::NODE, node); | 133 V8Proxy::ToV8Object(V8ClassIndex::NODE, node); |
| 134 v8::Handle<v8::String> function_name_wrapper = v8::Handle<v8::String>( |
| 135 v8::String::New(function_name.utf8().data())); |
128 v8::Handle<v8::String> json_args_wrapper = v8::Handle<v8::String>( | 136 v8::Handle<v8::String> json_args_wrapper = v8::Handle<v8::String>( |
129 v8::String::New(json_args.utf8().data())); | 137 v8::String::New(json_args.utf8().data())); |
130 v8::Handle<v8::Value> args[] = { | 138 v8::Handle<v8::Value> args[] = { |
| 139 function_name_wrapper, |
131 node_wrapper, | 140 node_wrapper, |
132 json_args_wrapper | 141 json_args_wrapper |
133 }; | 142 }; |
134 | 143 |
135 v8::Handle<v8::Value> res_obj = function->Call( | 144 v8::TryCatch try_catch; |
136 context_->Global(), 2, args); | 145 v8::Handle<v8::Value> res_obj = function->Call(context_->Global(), 3, args); |
137 | 146 if (try_catch.HasCaught()) { |
138 v8::Handle<v8::String> res_json = v8::Handle<v8::String>::Cast(res_obj); | 147 *exception = WebCore::ToWebCoreString(try_catch.Message()->Get()); |
139 return WebCore::toWebCoreString(res_json); | 148 return ""; |
| 149 } else { |
| 150 v8::Handle<v8::String> res_json = v8::Handle<v8::String>::Cast(res_obj); |
| 151 return WebCore::toWebCoreString(res_json); |
| 152 } |
140 } | 153 } |
141 | 154 |
142 void DebuggerAgentImpl::RunWithDeferredMessages( | 155 void DebuggerAgentImpl::RunWithDeferredMessages( |
143 const HashSet<DebuggerAgentImpl*>& agents, | 156 const HashSet<DebuggerAgentImpl*>& agents, |
144 WebDevToolsAgent::MessageLoopDispatchHandler handler) { | 157 WebDevToolsAgent::MessageLoopDispatchHandler handler) { |
145 Vector<PageGroupLoadDeferrer*> deferrers; | 158 Vector<PageGroupLoadDeferrer*> deferrers; |
146 // 1. Disable active objects and input events. | 159 // 1. Disable active objects and input events. |
147 for (HashSet<DebuggerAgentImpl*>::const_iterator ag_it = agents.begin(); | 160 for (HashSet<DebuggerAgentImpl*>::const_iterator ag_it = agents.begin(); |
148 ag_it != agents.end(); ++ag_it) { | 161 ag_it != agents.end(); ++ag_it) { |
149 DebuggerAgentImpl* agent = *ag_it; | 162 DebuggerAgentImpl* agent = *ag_it; |
150 deferrers.append(new PageGroupLoadDeferrer(agent->GetPage(), true)); | 163 deferrers.append(new PageGroupLoadDeferrer(agent->GetPage(), true)); |
151 agent->web_view()->SetIgnoreInputEvents(true); | 164 agent->web_view()->SetIgnoreInputEvents(true); |
152 } | 165 } |
153 | 166 |
154 // 2. Process messages. | 167 // 2. Process messages. |
155 handler(); | 168 handler(); |
156 | 169 |
157 // 3. Bring things back. | 170 // 3. Bring things back. |
158 for (HashSet<DebuggerAgentImpl*>::const_iterator ag_it = agents.begin(); | 171 for (HashSet<DebuggerAgentImpl*>::const_iterator ag_it = agents.begin(); |
159 ag_it != agents.end(); ++ag_it) { | 172 ag_it != agents.end(); ++ag_it) { |
160 (*ag_it)->web_view()->SetIgnoreInputEvents(false); | 173 (*ag_it)->web_view()->SetIgnoreInputEvents(false); |
161 } | 174 } |
162 deleteAllValues(deferrers); | 175 deleteAllValues(deferrers); |
163 } | 176 } |
164 | 177 |
165 WebCore::Page* DebuggerAgentImpl::GetPage() { | 178 WebCore::Page* DebuggerAgentImpl::GetPage() { |
166 return web_view_impl_->page(); | 179 return web_view_impl_->page(); |
167 } | 180 } |
OLD | NEW |