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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 487 |
488 // Ok for it to be undefined, among other things it's how bindings signify | 488 // Ok for it to be undefined, among other things it's how bindings signify |
489 // that the extension doesn't have permission to use them. | 489 // that the extension doesn't have permission to use them. |
490 CHECK(!new_field.IsEmpty()); | 490 CHECK(!new_field.IsEmpty()); |
491 | 491 |
492 // Delete the getter and set this field to |new_field| so the same object is | 492 // Delete the getter and set this field to |new_field| so the same object is |
493 // returned every time a certain API is accessed. | 493 // returned every time a certain API is accessed. |
494 v8::Local<v8::Value> val = info.This(); | 494 v8::Local<v8::Value> val = info.This(); |
495 if (val->IsObject()) { | 495 if (val->IsObject()) { |
496 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(val); | 496 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(val); |
497 object->Delete(context, property); | 497 auto maybe = object->Delete(context, property); |
| 498 CHECK(IsTrue(maybe)); |
498 SetProperty(context, object, property, new_field); | 499 SetProperty(context, object, property, new_field); |
499 } else { | 500 } else { |
500 NOTREACHED(); | 501 NOTREACHED(); |
501 } | 502 } |
502 info.GetReturnValue().Set(new_field); | 503 info.GetReturnValue().Set(new_field); |
503 | 504 |
504 UMA_HISTOGRAM_TIMES("Extensions.ApiBindingGenerationTime", timer.Elapsed()); | 505 UMA_HISTOGRAM_TIMES("Extensions.ApiBindingGenerationTime", timer.Elapsed()); |
505 } | 506 } |
506 | 507 |
507 void ModuleSystem::SetLazyField(v8::Local<v8::Object> object, | 508 void ModuleSystem::SetLazyField(v8::Local<v8::Object> object, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 v8::Local<v8::Context> v8_context = context_->v8_context(); | 622 v8::Local<v8::Context> v8_context = context_->v8_context(); |
622 v8::Local<v8::Promise::Resolver> resolver( | 623 v8::Local<v8::Promise::Resolver> resolver( |
623 v8::Promise::Resolver::New(v8_context).ToLocalChecked()); | 624 v8::Promise::Resolver::New(v8_context).ToLocalChecked()); |
624 args.GetReturnValue().Set(resolver->GetPromise()); | 625 args.GetReturnValue().Set(resolver->GetPromise()); |
625 std::unique_ptr<v8::Global<v8::Promise::Resolver>> global_resolver( | 626 std::unique_ptr<v8::Global<v8::Promise::Resolver>> global_resolver( |
626 new v8::Global<v8::Promise::Resolver>(GetIsolate(), resolver)); | 627 new v8::Global<v8::Promise::Resolver>(GetIsolate(), resolver)); |
627 gin::ModuleRegistry* module_registry = | 628 gin::ModuleRegistry* module_registry = |
628 gin::ModuleRegistry::From(v8_context); | 629 gin::ModuleRegistry::From(v8_context); |
629 if (!module_registry) { | 630 if (!module_registry) { |
630 Warn(GetIsolate(), "Extension view no longer exists"); | 631 Warn(GetIsolate(), "Extension view no longer exists"); |
631 resolver->Reject(v8_context, v8::Exception::Error(ToV8StringUnsafe( | 632 auto maybe = resolver->Reject( |
632 GetIsolate(), "Extension view no longer exists"))); | 633 v8_context, |
| 634 v8::Exception::Error(ToV8StringUnsafe( |
| 635 GetIsolate(), |
| 636 "Extension view no longer exists"))); |
| 637 CHECK(IsTrue(maybe)); |
633 return; | 638 return; |
634 } | 639 } |
635 module_registry->LoadModule( | 640 module_registry->LoadModule( |
636 GetIsolate(), module_name, | 641 GetIsolate(), module_name, |
637 base::Bind(&ModuleSystem::OnModuleLoaded, weak_factory_.GetWeakPtr(), | 642 base::Bind(&ModuleSystem::OnModuleLoaded, weak_factory_.GetWeakPtr(), |
638 base::Passed(&global_resolver))); | 643 base::Passed(&global_resolver))); |
639 if (module_registry->available_modules().count(module_name) == 0) | 644 if (module_registry->available_modules().count(module_name) == 0) |
640 LoadModule(module_name); | 645 LoadModule(module_name); |
641 } | 646 } |
642 | 647 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 } | 833 } |
829 | 834 |
830 void ModuleSystem::OnModuleLoaded( | 835 void ModuleSystem::OnModuleLoaded( |
831 std::unique_ptr<v8::Global<v8::Promise::Resolver>> resolver, | 836 std::unique_ptr<v8::Global<v8::Promise::Resolver>> resolver, |
832 v8::Local<v8::Value> value) { | 837 v8::Local<v8::Value> value) { |
833 if (!is_valid()) | 838 if (!is_valid()) |
834 return; | 839 return; |
835 v8::HandleScope handle_scope(GetIsolate()); | 840 v8::HandleScope handle_scope(GetIsolate()); |
836 v8::Local<v8::Promise::Resolver> resolver_local( | 841 v8::Local<v8::Promise::Resolver> resolver_local( |
837 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); | 842 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); |
838 resolver_local->Resolve(context()->v8_context(), value); | 843 auto maybe = resolver_local->Resolve(context()->v8_context(), value); |
| 844 CHECK(IsTrue(maybe)); |
839 } | 845 } |
840 | 846 |
841 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { | 847 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { |
842 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); | 848 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); |
843 if (existing_handler != native_handler_map_.end()) { | 849 if (existing_handler != native_handler_map_.end()) { |
844 clobbered_native_handlers_.push_back(std::move(existing_handler->second)); | 850 clobbered_native_handlers_.push_back(std::move(existing_handler->second)); |
845 native_handler_map_.erase(existing_handler); | 851 native_handler_map_.erase(existing_handler); |
846 } | 852 } |
847 } | 853 } |
848 | 854 |
(...skipping 26 matching lines...) Expand all Loading... |
875 !value->IsFunction()) { | 881 !value->IsFunction()) { |
876 Fatal(context_, module_name + "." + method_name + " is not a function"); | 882 Fatal(context_, module_name + "." + method_name + " is not a function"); |
877 return function; | 883 return function; |
878 } | 884 } |
879 | 885 |
880 function = v8::Local<v8::Function>::Cast(value); | 886 function = v8::Local<v8::Function>::Cast(value); |
881 return function; | 887 return function; |
882 } | 888 } |
883 | 889 |
884 } // namespace extensions | 890 } // namespace extensions |
OLD | NEW |