| 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 if (try_catch.HasCaught()) { | 330 if (try_catch.HasCaught()) { |
| 331 HandleException(try_catch); | 331 HandleException(try_catch); |
| 332 result = v8::Undefined(GetIsolate()); | 332 result = v8::Undefined(GetIsolate()); |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 return handle_scope.Escape(result); | 335 return handle_scope.Escape(result); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void ModuleSystem::RegisterNativeHandler( | 338 void ModuleSystem::RegisterNativeHandler( |
| 339 const std::string& name, | 339 const std::string& name, |
| 340 scoped_ptr<NativeHandler> native_handler) { | 340 std::unique_ptr<NativeHandler> native_handler) { |
| 341 ClobberExistingNativeHandler(name); | 341 ClobberExistingNativeHandler(name); |
| 342 native_handler_map_[name] = std::move(native_handler); | 342 native_handler_map_[name] = std::move(native_handler); |
| 343 } | 343 } |
| 344 | 344 |
| 345 void ModuleSystem::OverrideNativeHandlerForTest(const std::string& name) { | 345 void ModuleSystem::OverrideNativeHandlerForTest(const std::string& name) { |
| 346 ClobberExistingNativeHandler(name); | 346 ClobberExistingNativeHandler(name); |
| 347 overridden_native_handlers_.insert(name); | 347 overridden_native_handlers_.insert(name); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void ModuleSystem::RunString(const std::string& code, const std::string& name) { | 350 void ModuleSystem::RunString(const std::string& code, const std::string& name) { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 } | 559 } |
| 560 | 560 |
| 561 void ModuleSystem::RequireAsync( | 561 void ModuleSystem::RequireAsync( |
| 562 const v8::FunctionCallbackInfo<v8::Value>& args) { | 562 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 563 CHECK_EQ(1, args.Length()); | 563 CHECK_EQ(1, args.Length()); |
| 564 std::string module_name = *v8::String::Utf8Value(args[0]); | 564 std::string module_name = *v8::String::Utf8Value(args[0]); |
| 565 v8::Local<v8::Context> v8_context = context_->v8_context(); | 565 v8::Local<v8::Context> v8_context = context_->v8_context(); |
| 566 v8::Local<v8::Promise::Resolver> resolver( | 566 v8::Local<v8::Promise::Resolver> resolver( |
| 567 v8::Promise::Resolver::New(v8_context).ToLocalChecked()); | 567 v8::Promise::Resolver::New(v8_context).ToLocalChecked()); |
| 568 args.GetReturnValue().Set(resolver->GetPromise()); | 568 args.GetReturnValue().Set(resolver->GetPromise()); |
| 569 scoped_ptr<v8::Global<v8::Promise::Resolver>> global_resolver( | 569 std::unique_ptr<v8::Global<v8::Promise::Resolver>> global_resolver( |
| 570 new v8::Global<v8::Promise::Resolver>(GetIsolate(), resolver)); | 570 new v8::Global<v8::Promise::Resolver>(GetIsolate(), resolver)); |
| 571 gin::ModuleRegistry* module_registry = | 571 gin::ModuleRegistry* module_registry = |
| 572 gin::ModuleRegistry::From(v8_context); | 572 gin::ModuleRegistry::From(v8_context); |
| 573 if (!module_registry) { | 573 if (!module_registry) { |
| 574 Warn(GetIsolate(), "Extension view no longer exists"); | 574 Warn(GetIsolate(), "Extension view no longer exists"); |
| 575 resolver->Reject(v8_context, v8::Exception::Error(ToV8StringUnsafe( | 575 resolver->Reject(v8_context, v8::Exception::Error(ToV8StringUnsafe( |
| 576 GetIsolate(), "Extension view no longer exists"))); | 576 GetIsolate(), "Extension view no longer exists"))); |
| 577 return; | 577 return; |
| 578 } | 578 } |
| 579 module_registry->LoadModule( | 579 module_registry->LoadModule( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 // responsible for loading their module dependencies when required. | 728 // responsible for loading their module dependencies when required. |
| 729 if (registry->available_modules().count(dependency) == 0 && | 729 if (registry->available_modules().count(dependency) == 0 && |
| 730 (module_system_managed || source_map_->Contains(dependency))) { | 730 (module_system_managed || source_map_->Contains(dependency))) { |
| 731 LoadModule(dependency); | 731 LoadModule(dependency); |
| 732 } | 732 } |
| 733 } | 733 } |
| 734 registry->AttemptToLoadMoreModules(GetIsolate()); | 734 registry->AttemptToLoadMoreModules(GetIsolate()); |
| 735 } | 735 } |
| 736 | 736 |
| 737 void ModuleSystem::OnModuleLoaded( | 737 void ModuleSystem::OnModuleLoaded( |
| 738 scoped_ptr<v8::Global<v8::Promise::Resolver>> resolver, | 738 std::unique_ptr<v8::Global<v8::Promise::Resolver>> resolver, |
| 739 v8::Local<v8::Value> value) { | 739 v8::Local<v8::Value> value) { |
| 740 if (!is_valid()) | 740 if (!is_valid()) |
| 741 return; | 741 return; |
| 742 v8::HandleScope handle_scope(GetIsolate()); | 742 v8::HandleScope handle_scope(GetIsolate()); |
| 743 v8::Local<v8::Promise::Resolver> resolver_local( | 743 v8::Local<v8::Promise::Resolver> resolver_local( |
| 744 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); | 744 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); |
| 745 resolver_local->Resolve(context()->v8_context(), value); | 745 resolver_local->Resolve(context()->v8_context(), value); |
| 746 } | 746 } |
| 747 | 747 |
| 748 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { | 748 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { |
| 749 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); | 749 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); |
| 750 if (existing_handler != native_handler_map_.end()) { | 750 if (existing_handler != native_handler_map_.end()) { |
| 751 clobbered_native_handlers_.push_back(std::move(existing_handler->second)); | 751 clobbered_native_handlers_.push_back(std::move(existing_handler->second)); |
| 752 native_handler_map_.erase(existing_handler); | 752 native_handler_map_.erase(existing_handler); |
| 753 } | 753 } |
| 754 } | 754 } |
| 755 | 755 |
| 756 } // namespace extensions | 756 } // namespace extensions |
| OLD | NEW |