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

Unified Diff: extensions/renderer/module_system.cc

Issue 1417513003: [Extensions] Don't allow built-in extensions code to be overridden (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Jochen's Created 5 years, 2 months 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/event_unittest.cc ('k') | extensions/renderer/module_system_unittest.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 e760849602b9f8f4b768abcf519268289ccbb6d9..5005fca5b5e8795e379098f84dd2d076952a3fef 100644
--- a/extensions/renderer/module_system.cc
+++ b/extensions/renderer/module_system.cc
@@ -96,6 +96,20 @@ class DefaultExceptionHandler : public ModuleSystem::ExceptionHandler {
}
};
+// Sets a property on the "exports" object for bindings. Called by JS with
+// exports.$set(<key>, <value>).
+void SetExportsProperty(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ v8::Local<v8::Object> obj = args.This();
+ DCHECK_EQ(2, args.Length());
+ DCHECK(args[0]->IsString());
+ v8::Maybe<bool> result =
+ obj->DefineOwnProperty(args.GetIsolate()->GetCurrentContext(),
+ args[0]->ToString(), args[1], v8::ReadOnly);
+ if (!result.FromMaybe(false))
+ LOG(ERROR) << "Failed to set private property on the export.";
+}
+
} // namespace
std::string ModuleSystem::ExceptionHandler::CreateExceptionString(
@@ -642,7 +656,25 @@ v8::Local<v8::Value> ModuleSystem::LoadModule(const std::string& module_name) {
v8::Local<v8::Object> define_object = v8::Object::New(GetIsolate());
gin::ModuleRegistry::InstallGlobals(GetIsolate(), define_object);
- v8::Local<v8::Value> exports = v8::Object::New(GetIsolate());
+ v8::Local<v8::Object> exports = v8::Object::New(GetIsolate());
+
+ v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(
+ GetIsolate(),
+ &SetExportsProperty);
+ v8::Local<v8::String> v8_key;
+ if (!v8_helpers::ToV8String(GetIsolate(), "$set", &v8_key)) {
+ NOTREACHED();
+ return v8::Undefined(GetIsolate());
+ }
+
+ v8::Local<v8::Function> function;
+ if (!tmpl->GetFunction(v8_context).ToLocal(&function)) {
+ NOTREACHED();
+ return v8::Undefined(GetIsolate());
+ }
+
+ exports->ForceSet(v8_key, function, v8::ReadOnly);
+
v8::Local<v8::Object> natives(NewInstance());
CHECK(!natives.IsEmpty()); // this can fail if v8 has issues
« no previous file with comments | « extensions/renderer/event_unittest.cc ('k') | extensions/renderer/module_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698