| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/module_system.h" | 5 #include "extensions/renderer/module_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 !exports->IsUndefined()) | 278 !exports->IsUndefined()) |
| 279 return handle_scope.Escape(exports); | 279 return handle_scope.Escape(exports); |
| 280 | 280 |
| 281 exports = LoadModule(*v8::String::Utf8Value(module_name)); | 281 exports = LoadModule(*v8::String::Utf8Value(module_name)); |
| 282 SetPrivateProperty(v8_context, modules, module_name, exports); | 282 SetPrivateProperty(v8_context, modules, module_name, exports); |
| 283 return handle_scope.Escape(exports); | 283 return handle_scope.Escape(exports); |
| 284 } | 284 } |
| 285 | 285 |
| 286 v8::Local<v8::Value> ModuleSystem::CallModuleMethod( | 286 v8::Local<v8::Value> ModuleSystem::CallModuleMethod( |
| 287 const std::string& module_name, | 287 const std::string& module_name, |
| 288 const std::string& method_name) { | |
| 289 v8::EscapableHandleScope handle_scope(GetIsolate()); | |
| 290 v8::Local<v8::Value> no_args; | |
| 291 return handle_scope.Escape( | |
| 292 CallModuleMethod(module_name, method_name, 0, &no_args)); | |
| 293 } | |
| 294 | |
| 295 v8::Local<v8::Value> ModuleSystem::CallModuleMethod( | |
| 296 const std::string& module_name, | |
| 297 const std::string& method_name, | 288 const std::string& method_name, |
| 298 int argc, | 289 int argc, |
| 299 v8::Local<v8::Value> argv[]) { | 290 v8::Local<v8::Value> argv[]) { |
| 300 TRACE_EVENT2("v8", | 291 TRACE_EVENT2("v8", |
| 301 "v8.callModuleMethod", | 292 "v8.callModuleMethod", |
| 302 "module_name", | 293 "module_name", |
| 303 module_name, | 294 module_name, |
| 304 "method_name", | 295 "method_name", |
| 305 method_name); | 296 method_name); |
| 306 | 297 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 325 result = v8::Undefined(GetIsolate()); | 316 result = v8::Undefined(GetIsolate()); |
| 326 } | 317 } |
| 327 } | 318 } |
| 328 return handle_scope.Escape(result); | 319 return handle_scope.Escape(result); |
| 329 } | 320 } |
| 330 | 321 |
| 331 void ModuleSystem::CallModuleMethodSafe(const std::string& module_name, | 322 void ModuleSystem::CallModuleMethodSafe(const std::string& module_name, |
| 332 const std::string& method_name) { | 323 const std::string& method_name) { |
| 333 v8::HandleScope handle_scope(GetIsolate()); | 324 v8::HandleScope handle_scope(GetIsolate()); |
| 334 v8::Local<v8::Value> no_args; | 325 v8::Local<v8::Value> no_args; |
| 335 CallModuleMethodSafe(module_name, method_name, 0, &no_args); | 326 CallModuleMethodSafe(module_name, method_name, 0, &no_args, |
| 327 ScriptInjectionCallback::CompleteCallback()); |
| 336 } | 328 } |
| 337 | 329 |
| 338 void ModuleSystem::CallModuleMethodSafe( | 330 void ModuleSystem::CallModuleMethodSafe( |
| 339 const std::string& module_name, | 331 const std::string& module_name, |
| 340 const std::string& method_name, | 332 const std::string& method_name, |
| 341 std::vector<v8::Local<v8::Value>>* args) { | 333 std::vector<v8::Local<v8::Value>>* args) { |
| 342 CallModuleMethodSafe(module_name, method_name, args->size(), args->data()); | 334 CallModuleMethodSafe(module_name, method_name, args->size(), args->data(), |
| 335 ScriptInjectionCallback::CompleteCallback()); |
| 343 } | 336 } |
| 344 | 337 |
| 345 void ModuleSystem::CallModuleMethodSafe(const std::string& module_name, | 338 void ModuleSystem::CallModuleMethodSafe(const std::string& module_name, |
| 346 const std::string& method_name, | 339 const std::string& method_name, |
| 347 int argc, | 340 int argc, |
| 348 v8::Local<v8::Value> argv[]) { | 341 v8::Local<v8::Value> argv[]) { |
| 342 CallModuleMethodSafe(module_name, method_name, argc, argv, |
| 343 ScriptInjectionCallback::CompleteCallback()); |
| 344 } |
| 345 |
| 346 void ModuleSystem::CallModuleMethodSafe( |
| 347 const std::string& module_name, |
| 348 const std::string& method_name, |
| 349 int argc, |
| 350 v8::Local<v8::Value> argv[], |
| 351 const ScriptInjectionCallback::CompleteCallback& callback) { |
| 349 TRACE_EVENT2("v8", "v8.callModuleMethodSafe", "module_name", module_name, | 352 TRACE_EVENT2("v8", "v8.callModuleMethodSafe", "module_name", module_name, |
| 350 "method_name", method_name); | 353 "method_name", method_name); |
| 351 | 354 |
| 352 v8::HandleScope handle_scope(GetIsolate()); | 355 v8::HandleScope handle_scope(GetIsolate()); |
| 353 v8::Local<v8::Context> v8_context = context()->v8_context(); | 356 v8::Local<v8::Context> v8_context = context()->v8_context(); |
| 354 v8::Context::Scope context_scope(v8_context); | 357 v8::Context::Scope context_scope(v8_context); |
| 355 | 358 |
| 356 v8::Local<v8::Function> function = | 359 v8::Local<v8::Function> function = |
| 357 GetModuleFunction(module_name, method_name); | 360 GetModuleFunction(module_name, method_name); |
| 358 if (function.IsEmpty()) { | 361 if (function.IsEmpty()) { |
| 359 NOTREACHED() << "GetModuleFunction() returns empty function handle"; | 362 NOTREACHED() << "GetModuleFunction() returns empty function handle"; |
| 360 return; | 363 return; |
| 361 } | 364 } |
| 362 | 365 |
| 363 { | 366 { |
| 364 v8::TryCatch try_catch(GetIsolate()); | 367 v8::TryCatch try_catch(GetIsolate()); |
| 365 try_catch.SetCaptureMessage(true); | 368 try_catch.SetCaptureMessage(true); |
| 366 context_->SafeCallFunction(function, argc, argv); | 369 context_->SafeCallFunction(function, argc, argv, callback); |
| 367 if (try_catch.HasCaught()) | 370 if (try_catch.HasCaught()) |
| 368 HandleException(try_catch); | 371 HandleException(try_catch); |
| 369 } | 372 } |
| 370 } | 373 } |
| 371 | 374 |
| 372 void ModuleSystem::RegisterNativeHandler( | 375 void ModuleSystem::RegisterNativeHandler( |
| 373 const std::string& name, | 376 const std::string& name, |
| 374 std::unique_ptr<NativeHandler> native_handler) { | 377 std::unique_ptr<NativeHandler> native_handler) { |
| 375 ClobberExistingNativeHandler(name); | 378 ClobberExistingNativeHandler(name); |
| 376 native_handler_map_[name] = std::move(native_handler); | 379 native_handler_map_[name] = std::move(native_handler); |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 !value->IsFunction()) { | 819 !value->IsFunction()) { |
| 817 Fatal(context_, module_name + "." + method_name + " is not a function"); | 820 Fatal(context_, module_name + "." + method_name + " is not a function"); |
| 818 return function; | 821 return function; |
| 819 } | 822 } |
| 820 | 823 |
| 821 function = v8::Local<v8::Function>::Cast(value); | 824 function = v8::Local<v8::Function>::Cast(value); |
| 822 return function; | 825 return function; |
| 823 } | 826 } |
| 824 | 827 |
| 825 } // namespace extensions | 828 } // namespace extensions |
| OLD | NEW |