Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: extensions/renderer/module_system.cc

Issue 2575173002: [Extensions Bindings] Add a bridge to use current custom bindings (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/module_system.h ('k') | extensions/renderer/native_extension_bindings_system.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/module_system.cc
diff --git a/extensions/renderer/module_system.cc b/extensions/renderer/module_system.cc
index 3cdf194dbda91af6d7121038256c9dc76474a62a..3d7128ad513a6d01ecd8b627436c0fc42dd5d1e9 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);
@@ -729,6 +746,7 @@ v8::Local<v8::Value> ModuleSystem::LoadModule(const std::string& module_name) {
console::AsV8Object(GetIsolate()),
GetPropertyUnsafe(v8_context, natives, "privates",
v8::NewStringType::kInternalized),
+ api_bridge, // exposed as apiBridge.
// Each safe builtin. Keep in order with the arguments in WrapSource.
context_->safe_builtins()->GetArray(),
context_->safe_builtins()->GetFunction(),
« no previous file with comments | « extensions/renderer/module_system.h ('k') | extensions/renderer/native_extension_bindings_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698