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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 | 450 |
451 // Ok for it to be undefined, among other things it's how bindings signify | 451 // Ok for it to be undefined, among other things it's how bindings signify |
452 // that the extension doesn't have permission to use them. | 452 // that the extension doesn't have permission to use them. |
453 CHECK(!new_field.IsEmpty()); | 453 CHECK(!new_field.IsEmpty()); |
454 | 454 |
455 // Delete the getter and set this field to |new_field| so the same object is | 455 // Delete the getter and set this field to |new_field| so the same object is |
456 // returned every time a certain API is accessed. | 456 // returned every time a certain API is accessed. |
457 v8::Local<v8::Value> val = info.This(); | 457 v8::Local<v8::Value> val = info.This(); |
458 if (val->IsObject()) { | 458 if (val->IsObject()) { |
459 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(val); | 459 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(val); |
460 object->Delete(context, property); | 460 if (object->Delete(context, property).IsNothing()) { |
461 NOTREACHED(); | |
462 } | |
461 SetProperty(context, object, property, new_field); | 463 SetProperty(context, object, property, new_field); |
462 } else { | 464 } else { |
463 NOTREACHED(); | 465 NOTREACHED(); |
464 } | 466 } |
465 info.GetReturnValue().Set(new_field); | 467 info.GetReturnValue().Set(new_field); |
466 | 468 |
467 UMA_HISTOGRAM_TIMES("Extensions.ApiBindingGenerationTime", timer.Elapsed()); | 469 UMA_HISTOGRAM_TIMES("Extensions.ApiBindingGenerationTime", timer.Elapsed()); |
468 } | 470 } |
469 | 471 |
470 void ModuleSystem::SetLazyField(v8::Local<v8::Object> object, | 472 void ModuleSystem::SetLazyField(v8::Local<v8::Object> object, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 v8::Local<v8::Context> v8_context = context_->v8_context(); | 572 v8::Local<v8::Context> v8_context = context_->v8_context(); |
571 v8::Local<v8::Promise::Resolver> resolver( | 573 v8::Local<v8::Promise::Resolver> resolver( |
572 v8::Promise::Resolver::New(v8_context).ToLocalChecked()); | 574 v8::Promise::Resolver::New(v8_context).ToLocalChecked()); |
573 args.GetReturnValue().Set(resolver->GetPromise()); | 575 args.GetReturnValue().Set(resolver->GetPromise()); |
574 std::unique_ptr<v8::Global<v8::Promise::Resolver>> global_resolver( | 576 std::unique_ptr<v8::Global<v8::Promise::Resolver>> global_resolver( |
575 new v8::Global<v8::Promise::Resolver>(GetIsolate(), resolver)); | 577 new v8::Global<v8::Promise::Resolver>(GetIsolate(), resolver)); |
576 gin::ModuleRegistry* module_registry = | 578 gin::ModuleRegistry* module_registry = |
577 gin::ModuleRegistry::From(v8_context); | 579 gin::ModuleRegistry::From(v8_context); |
578 if (!module_registry) { | 580 if (!module_registry) { |
579 Warn(GetIsolate(), "Extension view no longer exists"); | 581 Warn(GetIsolate(), "Extension view no longer exists"); |
580 resolver->Reject(v8_context, v8::Exception::Error(ToV8StringUnsafe( | 582 if (resolver->Reject(v8_context, v8::Exception::Error(ToV8StringUnsafe( |
581 GetIsolate(), "Extension view no longer exists"))); | 583 GetIsolate(), "Extension view no longer exists"))).IsNothing()) { |
584 // TODO: What action, if any, should be taken here? | |
haraken
2016/07/15 02:38:41
I think we should just crash.
| |
585 } | |
582 return; | 586 return; |
583 } | 587 } |
584 module_registry->LoadModule( | 588 module_registry->LoadModule( |
585 GetIsolate(), module_name, | 589 GetIsolate(), module_name, |
586 base::Bind(&ModuleSystem::OnModuleLoaded, weak_factory_.GetWeakPtr(), | 590 base::Bind(&ModuleSystem::OnModuleLoaded, weak_factory_.GetWeakPtr(), |
587 base::Passed(&global_resolver))); | 591 base::Passed(&global_resolver))); |
588 if (module_registry->available_modules().count(module_name) == 0) | 592 if (module_registry->available_modules().count(module_name) == 0) |
589 LoadModule(module_name); | 593 LoadModule(module_name); |
590 } | 594 } |
591 | 595 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
745 } | 749 } |
746 | 750 |
747 void ModuleSystem::OnModuleLoaded( | 751 void ModuleSystem::OnModuleLoaded( |
748 std::unique_ptr<v8::Global<v8::Promise::Resolver>> resolver, | 752 std::unique_ptr<v8::Global<v8::Promise::Resolver>> resolver, |
749 v8::Local<v8::Value> value) { | 753 v8::Local<v8::Value> value) { |
750 if (!is_valid()) | 754 if (!is_valid()) |
751 return; | 755 return; |
752 v8::HandleScope handle_scope(GetIsolate()); | 756 v8::HandleScope handle_scope(GetIsolate()); |
753 v8::Local<v8::Promise::Resolver> resolver_local( | 757 v8::Local<v8::Promise::Resolver> resolver_local( |
754 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); | 758 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); |
755 resolver_local->Resolve(context()->v8_context(), value); | 759 if (resolver_local->Resolve(context()->v8_context(), value).IsNothing()) { |
760 // TODO: What action, if any, should be taken here? | |
haraken
2016/07/15 02:38:40
Ditto.
| |
761 } | |
756 } | 762 } |
757 | 763 |
758 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { | 764 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { |
759 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); | 765 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); |
760 if (existing_handler != native_handler_map_.end()) { | 766 if (existing_handler != native_handler_map_.end()) { |
761 clobbered_native_handlers_.push_back(std::move(existing_handler->second)); | 767 clobbered_native_handlers_.push_back(std::move(existing_handler->second)); |
762 native_handler_map_.erase(existing_handler); | 768 native_handler_map_.erase(existing_handler); |
763 } | 769 } |
764 } | 770 } |
765 | 771 |
766 } // namespace extensions | 772 } // namespace extensions |
OLD | NEW |