Chromium Code Reviews| Index: extensions/renderer/module_system.cc |
| diff --git a/extensions/renderer/module_system.cc b/extensions/renderer/module_system.cc |
| index 3cdf194dbda91af6d7121038256c9dc76474a62a..75c6b77e15238abcb8d998feb5f2683cfb9dc6da 100644 |
| --- a/extensions/renderer/module_system.cc |
| +++ b/extensions/renderer/module_system.cc |
| @@ -542,6 +542,16 @@ void ModuleSystem::SetNativeLazyField(v8::Local<v8::Object> object, |
| &ModuleSystem::NativeLazyFieldGetter); |
| } |
| +void ModuleSystem::OnNativeBindingCreated( |
| + const std::string& api_name, |
| + v8::Local<v8::Value> api_bridge_value) { |
| + v8::HandleScope scope(GetIsolate()); |
| + if (source_map_->Contains(api_name)) { |
| + NativesEnabledScope enabled(this); |
| + LoadModuleWithNativeAPIBridge(api_name, api_bridge_value); |
| + } |
| +} |
| + |
| v8::Local<v8::Value> ModuleSystem::RunString(v8::Local<v8::String> code, |
| v8::Local<v8::String> name) { |
| return context_->RunScript( |
| @@ -622,7 +632,7 @@ v8::Local<v8::String> ModuleSystem::WrapSource(v8::Local<v8::String> source) { |
| v8::Local<v8::String> left = ToV8StringUnsafe( |
| GetIsolate(), |
| "(function(define, require, requireNative, requireAsync, exports, " |
| - "console, privates," |
| + "console, privates, apiBridge," |
| "$Array, $Function, $JSON, $Object, $RegExp, $String, $Error) {" |
| "'use strict';"); |
| v8::Local<v8::String> right = ToV8StringUnsafe(GetIsolate(), "\n})"); |
| @@ -660,6 +670,12 @@ void ModuleSystem::Private(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| } |
| v8::Local<v8::Value> ModuleSystem::LoadModule(const std::string& module_name) { |
| + return LoadModuleWithNativeAPIBridge(module_name, v8::Local<v8::Value>()); |
|
jbroman
2016/12/16 19:00:50
Any reason to pass an empty local here and then ov
Devlin
2016/12/16 20:31:17
Works for me. Done.
|
| +} |
| + |
| +v8::Local<v8::Value> ModuleSystem::LoadModuleWithNativeAPIBridge( |
| + const std::string& module_name, |
| + v8::Local<v8::Value> api_bridge) { |
| v8::EscapableHandleScope handle_scope(GetIsolate()); |
| v8::Local<v8::Context> v8_context = context()->v8_context(); |
| v8::Context::Scope context_scope(v8_context); |
| @@ -713,6 +729,9 @@ v8::Local<v8::Value> ModuleSystem::LoadModule(const std::string& module_name) { |
| v8::Local<v8::Object> natives(NewInstance()); |
| CHECK(!natives.IsEmpty()); // this can fail if v8 has issues |
| + if (api_bridge.IsEmpty()) |
| + api_bridge = v8::Undefined(v8_context->GetIsolate()); |
| + |
| // These must match the argument order in WrapSource. |
| v8::Local<v8::Value> args[] = { |
| // AMD. |
| @@ -730,7 +749,7 @@ v8::Local<v8::Value> ModuleSystem::LoadModule(const std::string& module_name) { |
| GetPropertyUnsafe(v8_context, natives, "privates", |
| v8::NewStringType::kInternalized), |
| // Each safe builtin. Keep in order with the arguments in WrapSource. |
| - context_->safe_builtins()->GetArray(), |
| + api_bridge, context_->safe_builtins()->GetArray(), |
| context_->safe_builtins()->GetFunction(), |
| context_->safe_builtins()->GetJSON(), |
| context_->safe_builtins()->GetObjekt(), |