OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/module_system.h" | 5 #include "chrome/renderer/extensions/module_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedMicrotaskSup
pression.h" | 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedMicrotaskSup
pression.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 func->Call(global, 3, args); | 142 func->Call(global, 3, args); |
143 if (try_catch.HasCaught()) { | 143 if (try_catch.HasCaught()) { |
144 DumpException(try_catch); | 144 DumpException(try_catch); |
145 return v8::Undefined(); | 145 return v8::Undefined(); |
146 } | 146 } |
147 } | 147 } |
148 modules->Set(module_name, exports); | 148 modules->Set(module_name, exports); |
149 return handle_scope.Close(exports); | 149 return handle_scope.Close(exports); |
150 } | 150 } |
151 | 151 |
| 152 void ModuleSystem::CallModuleMethod(const std::string& module_name, |
| 153 const std::string& method_name) { |
| 154 v8::HandleScope handle_scope; |
| 155 v8::Local<v8::Value> module = |
| 156 v8::Local<v8::Value>::New( |
| 157 RequireForJsInner(v8::String::New(module_name.c_str()))); |
| 158 if (module.IsEmpty() || !module->IsObject()) |
| 159 return; |
| 160 v8::Local<v8::Value> value = |
| 161 v8::Handle<v8::Object>::Cast(module)->Get( |
| 162 v8::String::New(method_name.c_str())); |
| 163 if (value.IsEmpty() || !value->IsFunction()) |
| 164 return; |
| 165 v8::Handle<v8::Function> func = |
| 166 v8::Handle<v8::Function>::Cast(value); |
| 167 // TODO(jeremya/koz): refer to context_ here, not the current context. |
| 168 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); |
| 169 { |
| 170 WebKit::WebScopedMicrotaskSuppression suppression; |
| 171 v8::TryCatch try_catch; |
| 172 try_catch.SetCaptureMessage(true); |
| 173 func->Call(global, 0, NULL); |
| 174 if (try_catch.HasCaught()) |
| 175 DumpException(try_catch); |
| 176 } |
| 177 } |
| 178 |
152 void ModuleSystem::RegisterNativeHandler(const std::string& name, | 179 void ModuleSystem::RegisterNativeHandler(const std::string& name, |
153 scoped_ptr<NativeHandler> native_handler) { | 180 scoped_ptr<NativeHandler> native_handler) { |
154 native_handler_map_[name] = | 181 native_handler_map_[name] = |
155 linked_ptr<NativeHandler>(native_handler.release()); | 182 linked_ptr<NativeHandler>(native_handler.release()); |
156 } | 183 } |
157 | 184 |
158 void ModuleSystem::OverrideNativeHandler(const std::string& name) { | 185 void ModuleSystem::OverrideNativeHandler(const std::string& name) { |
159 overridden_native_handlers_.insert(name); | 186 overridden_native_handlers_.insert(name); |
160 } | 187 } |
161 | 188 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 v8::Handle<v8::String> right = v8::String::New("\n})"); | 289 v8::Handle<v8::String> right = v8::String::New("\n})"); |
263 return handle_scope.Close( | 290 return handle_scope.Close( |
264 v8::String::Concat(left, v8::String::Concat(source, right))); | 291 v8::String::Concat(left, v8::String::Concat(source, right))); |
265 } | 292 } |
266 | 293 |
267 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) { | 294 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) { |
268 return v8::ThrowException(v8::String::New(message.c_str())); | 295 return v8::ThrowException(v8::String::New(message.c_str())); |
269 } | 296 } |
270 | 297 |
271 } // extensions | 298 } // extensions |
OLD | NEW |