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..109be76a1d36e28ecc77509a1f1e79b980444d3e 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,13 @@ 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::Undefined(GetIsolate())); |
| +} |
| + |
| +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); |
| @@ -730,7 +747,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(), |
|
lazyboy
2016/12/21 19:49:58
nit: api_bridge should go before safe builtin comm
Devlin
2016/12/22 01:49:10
Done.
|
| context_->safe_builtins()->GetFunction(), |
| context_->safe_builtins()->GetJSON(), |
| context_->safe_builtins()->GetObjekt(), |