From 83a4b3aa72d98fe4176b4a54c8cea227ed966570 Mon Sep 17 00:00:00 2001 From: "rdevlin.cronin" Date: Wed, 28 Oct 2015 14:43:58 -0700 Subject: [Extensions] Don't allow built-in extensions code to be overridden BUG=546677 Review URL: https://codereview.chromium.org/1417513003 Cr-Commit-Position: refs/heads/master@{#356654} --- extensions/renderer/api_test_base.cc | 15 ++++---- extensions/renderer/event_unittest.cc | 40 ++++++++++++---------- extensions/renderer/module_system.cc | 34 +++++++++++++++++- extensions/renderer/module_system_unittest.cc | 39 ++++++++++++--------- .../resources/app_runtime_custom_bindings.js | 2 +- .../resources/app_window_custom_bindings.js | 8 ++--- extensions/renderer/resources/binding.js | 2 +- .../browser_test_environment_specific_bindings.js | 4 +-- .../resources/context_menus_custom_bindings.js | 2 +- .../renderer/resources/context_menus_handlers.js | 2 +- .../declarative_webrequest_custom_bindings.js | 2 +- extensions/renderer/resources/entry_id_manager.js | 6 ++-- extensions/renderer/resources/event.js | 8 ++--- .../resources/extension_custom_bindings.js | 2 +- .../extension_options/extension_options.js | 2 +- .../extension_options_constants.js | 3 +- .../extension_options/extension_options_events.js | 2 +- .../guest_view/extension_view/extension_view.js | 2 +- .../extension_view/extension_view_constants.js | 2 +- .../extension_view/extension_view_events.js | 2 +- .../extension_view/extension_view_internal.js | 5 +-- .../renderer/resources/guest_view/guest_view.js | 6 ++-- .../resources/guest_view/guest_view_attributes.js | 2 +- .../resources/guest_view/guest_view_container.js | 2 +- .../resources/guest_view/guest_view_events.js | 4 +-- .../resources/guest_view/web_view/web_view.js | 2 +- .../web_view/web_view_action_requests.js | 2 +- .../guest_view/web_view/web_view_constants.js | 2 +- .../guest_view/web_view/web_view_events.js | 2 +- .../guest_view/web_view/web_view_internal.js | 5 +-- .../web_view/web_view_request_custom_bindings.js | 2 +- .../renderer/resources/i18n_custom_bindings.js | 2 +- extensions/renderer/resources/image_util.js | 4 +-- extensions/renderer/resources/json_schema.js | 2 +- extensions/renderer/resources/last_error.js | 12 +++---- extensions/renderer/resources/messaging.js | 22 ++++++------ extensions/renderer/resources/messaging_utils.js | 2 +- .../mime_handler_private_custom_bindings.js | 2 +- .../resources/mojo_private_custom_bindings.js | 2 +- .../resources/permissions_custom_bindings.js | 2 +- .../resources/printer_provider_custom_bindings.js | 2 +- .../renderer/resources/runtime_custom_bindings.js | 4 +-- extensions/renderer/resources/schema_utils.js | 8 ++--- extensions/renderer/resources/send_request.js | 10 +++--- .../renderer/resources/serial_custom_bindings.js | 2 +- extensions/renderer/resources/set_icon.js | 2 +- extensions/renderer/resources/storage_area.js | 2 +- .../renderer/resources/test_custom_bindings.js | 2 +- .../resources/uncaught_exception_handler.js | 14 ++++---- extensions/renderer/resources/utils.js | 12 +++---- .../resources/web_request_custom_bindings.js | 2 +- .../web_request_internal_custom_bindings.js | 4 +-- extensions/renderer/utils_unittest.cc | 8 ++--- 53 files changed, 189 insertions(+), 146 deletions(-) (limited to 'extensions/renderer') diff --git a/extensions/renderer/api_test_base.cc b/extensions/renderer/api_test_base.cc index 53d6fa4..0315892 100644 --- a/extensions/renderer/api_test_base.cc +++ b/extensions/renderer/api_test_base.cc @@ -140,17 +140,18 @@ void ApiTestEnvironment::RegisterModules() { "unit_test_environment_specific_bindings.js"); env()->OverrideNativeHandler("activityLogger", - "exports.LogAPICall = function() {};"); + "exports.$set('LogAPICall', function() {});"); env()->OverrideNativeHandler( "apiDefinitions", - "exports.GetExtensionAPIDefinitionsForTest = function() { return [] };"); + "exports.$set('GetExtensionAPIDefinitionsForTest'," + "function() { return [] });"); env()->OverrideNativeHandler( "event_natives", - "exports.AttachEvent = function() {};" - "exports.DetachEvent = function() {};" - "exports.AttachFilteredEvent = function() {};" - "exports.AttachFilteredEvent = function() {};" - "exports.MatchAgainstEventFilter = function() { return [] };"); + "exports.$set('AttachEvent', function() {});" + "exports.$set('DetachEvent', function() {});" + "exports.$set('AttachFilteredEvent', function() {});" + "exports.$set('AttachFilteredEvent', function() {});" + "exports.$set('MatchAgainstEventFilter', function() { return [] });"); gin::ModuleRegistry::From(env()->context()->v8_context()) ->AddBuiltinModule(env()->isolate(), diff --git a/extensions/renderer/event_unittest.cc b/extensions/renderer/event_unittest.cc index 9d3b68f..5969462 100644 --- a/extensions/renderer/event_unittest.cc +++ b/extensions/renderer/event_unittest.cc @@ -25,45 +25,47 @@ class EventUnittest : public ModuleSystemTest { env()->OverrideNativeHandler( "event_natives", "var assert = requireNative('assert');" - "var attachedListeners = exports.attachedListeners = {};" - "var attachedFilteredListeners = " - " exports.attachedFilteredListeners = {};" + "exports.$set('attachedListeners', {});" + "var attachedListeners = exports.attachedListeners;" + "exports.$set('attachedFilteredListeners', {});" + "var attachedFilteredListeners = exports.attachedFilteredListeners;" "var nextId = 0;" "var idToName = {};" - "exports.AttachEvent = function(eventName) {" + "exports.$set('AttachEvent', function(eventName) {" " assert.AssertFalse(!!attachedListeners[eventName]);" " attachedListeners[eventName] = 1;" - "};" - "exports.DetachEvent = function(eventName) {" + "});" + "exports.$set('DetachEvent', function(eventName) {" " assert.AssertTrue(!!attachedListeners[eventName]);" " delete attachedListeners[eventName];" - "};" - "exports.IsEventAttached = function(eventName) {" + "});" + "exports.$set('IsEventAttached', function(eventName) {" " return !!attachedListeners[eventName];" - "};" - "exports.AttachFilteredEvent = function(name, filters) {" + "});" + "exports.$set('AttachFilteredEvent', function(name, filters) {" " var id = nextId++;" " idToName[id] = name;" " attachedFilteredListeners[name] =" " attachedFilteredListeners[name] || [];" " attachedFilteredListeners[name][id] = filters;" " return id;" - "};" - "exports.DetachFilteredEvent = function(id, manual) {" + "});" + "exports.$set('DetachFilteredEvent', function(id, manual) {" " var i = attachedFilteredListeners[idToName[id]].indexOf(id);" " attachedFilteredListeners[idToName[id]].splice(i, 1);" - "};" - "exports.HasFilteredListener = function(name) {" + "});" + "exports.$set('HasFilteredListener', function(name) {" " return attachedFilteredListeners[name].length;" - "};"); + "});"); env()->OverrideNativeHandler("sendRequest", - "exports.sendRequest = function() {};"); + "exports.$set('sendRequest', function() {});"); env()->OverrideNativeHandler( "apiDefinitions", - "exports.GetExtensionAPIDefinitionsForTest = function() {};"); - env()->OverrideNativeHandler("logging", "exports.DCHECK = function() {};"); + "exports.$set('GetExtensionAPIDefinitionsForTest', function() {});"); + env()->OverrideNativeHandler("logging", + "exports.$set('DCHECK', function() {});"); env()->OverrideNativeHandler("schema_registry", - "exports.GetSchema = function() {};"); + "exports.$set('GetSchema', function() {});"); } }; diff --git a/extensions/renderer/module_system.cc b/extensions/renderer/module_system.cc index e760849..5005fca 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(, ). +void SetExportsProperty( + const v8::FunctionCallbackInfo& args) { + v8::Local obj = args.This(); + DCHECK_EQ(2, args.Length()); + DCHECK(args[0]->IsString()); + v8::Maybe 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 ModuleSystem::LoadModule(const std::string& module_name) { v8::Local define_object = v8::Object::New(GetIsolate()); gin::ModuleRegistry::InstallGlobals(GetIsolate(), define_object); - v8::Local exports = v8::Object::New(GetIsolate()); + v8::Local exports = v8::Object::New(GetIsolate()); + + v8::Local tmpl = v8::FunctionTemplate::New( + GetIsolate(), + &SetExportsProperty); + v8::Local v8_key; + if (!v8_helpers::ToV8String(GetIsolate(), "$set", &v8_key)) { + NOTREACHED(); + return v8::Undefined(GetIsolate()); + } + + v8::Local function; + if (!tmpl->GetFunction(v8_context).ToLocal(&function)) { + NOTREACHED(); + return v8::Undefined(GetIsolate()); + } + + exports->ForceSet(v8_key, function, v8::ReadOnly); + v8::Local natives(NewInstance()); CHECK(!natives.IsEmpty()); // this can fail if v8 has issues diff --git a/extensions/renderer/module_system_unittest.cc b/extensions/renderer/module_system_unittest.cc index c5c916e..d2cb5f8 100644 --- a/extensions/renderer/module_system_unittest.cc +++ b/extensions/renderer/module_system_unittest.cc @@ -66,7 +66,8 @@ TEST_F(ModuleSystemTest, TestRequire) { ModuleSystem::NativesEnabledScope natives_enabled_scope( env()->module_system()); env()->RegisterModule("add", - "exports.Add = function(x, y) { return x + y; };"); + "exports.$set('Add'," + "function(x, y) { return x + y; });"); env()->RegisterModule("test", "var Add = require('add').Add;" "requireNative('assert').AssertTrue(Add(3, 5) == 8);"); @@ -77,10 +78,12 @@ TEST_F(ModuleSystemTest, TestNestedRequire) { ModuleSystem::NativesEnabledScope natives_enabled_scope( env()->module_system()); env()->RegisterModule("add", - "exports.Add = function(x, y) { return x + y; };"); + "exports.$set('Add'," + "function(x, y) { return x + y; });"); env()->RegisterModule("double", "var Add = require('add').Add;" - "exports.Double = function(x) { return Add(x, x); };"); + "exports.$set('Double'," + "function(x) { return Add(x, x); });"); env()->RegisterModule("test", "var Double = require('double').Double;" "requireNative('assert').AssertTrue(Double(3) == 6);"); @@ -92,11 +95,11 @@ TEST_F(ModuleSystemTest, TestModuleInsulation) { env()->module_system()); env()->RegisterModule("x", "var x = 10;" - "exports.X = function() { return x; };"); + "exports.$set('X', function() { return x; });"); env()->RegisterModule("y", "var x = 15;" "require('x');" - "exports.Y = function() { return x; };"); + "exports.$set('Y', function() { return x; });"); env()->RegisterModule("test", "var Y = require('y').Y;" "var X = require('x').X;" @@ -140,7 +143,7 @@ TEST_F(ModuleSystemTest, TestNativesAreEnabledWithinANativesEnabledScope) { TEST_F(ModuleSystemTest, TestLazyField) { ModuleSystem::NativesEnabledScope natives_enabled_scope( env()->module_system()); - env()->RegisterModule("lazy", "exports.x = 5;"); + env()->RegisterModule("lazy", "exports.$set('x', 5);"); v8::Local object = env()->CreateGlobal("object"); @@ -161,7 +164,7 @@ TEST_F(ModuleSystemTest, TestLazyFieldYieldingObject) { "object.__defineGetter__('z', function() { return 1; });" "object.x = 5;" "object.y = function() { return 10; };" - "exports.object = object;"); + "exports.$set('object', object);"); v8::Local object = env()->CreateGlobal("object"); @@ -183,7 +186,7 @@ TEST_F(ModuleSystemTest, TestLazyFieldIsOnlyEvaledOnce) { scoped_ptr(new CounterNatives(env()->context()))); env()->RegisterModule("lazy", "requireNative('counter').Increment();" - "exports.x = 5;"); + "exports.$set('x', 5);"); v8::Local object = env()->CreateGlobal("object"); @@ -203,7 +206,7 @@ TEST_F(ModuleSystemTest, TestLazyFieldIsOnlyEvaledOnce) { TEST_F(ModuleSystemTest, TestRequireNativesAfterLazyEvaluation) { ModuleSystem::NativesEnabledScope natives_enabled_scope( env()->module_system()); - env()->RegisterModule("lazy", "exports.x = 5;"); + env()->RegisterModule("lazy", "exports.$set('x', 5);"); v8::Local object = env()->CreateGlobal("object"); env()->module_system()->SetLazyField(object, "x", "lazy", "x"); @@ -216,8 +219,9 @@ TEST_F(ModuleSystemTest, TestRequireNativesAfterLazyEvaluation) { TEST_F(ModuleSystemTest, TestTransitiveRequire) { ModuleSystem::NativesEnabledScope natives_enabled_scope( env()->module_system()); - env()->RegisterModule("dependency", "exports.x = 5;"); - env()->RegisterModule("lazy", "exports.output = require('dependency');"); + env()->RegisterModule("dependency", "exports.$set('x', 5);"); + env()->RegisterModule("lazy", + "exports.$set('output', require('dependency'));"); v8::Local object = env()->CreateGlobal("object"); @@ -253,7 +257,8 @@ TEST_F(ModuleSystemTest, TestModulesOnlyGetEvaledOnce) { TEST_F(ModuleSystemTest, TestOverrideNativeHandler) { ModuleSystem::NativesEnabledScope natives_enabled_scope( env()->module_system()); - env()->OverrideNativeHandler("assert", "exports.AssertTrue = function() {};"); + env()->OverrideNativeHandler("assert", + "exports.$set('AssertTrue', function() {});"); env()->RegisterModule("test", "requireNative('assert').AssertTrue(true);"); ExpectNoAssertionsMade(); env()->module_system()->Require("test"); @@ -262,7 +267,7 @@ TEST_F(ModuleSystemTest, TestOverrideNativeHandler) { TEST_F(ModuleSystemTest, TestOverrideNonExistentNativeHandler) { ModuleSystem::NativesEnabledScope natives_enabled_scope( env()->module_system()); - env()->OverrideNativeHandler("thing", "exports.x = 5;"); + env()->OverrideNativeHandler("thing", "exports.$set('x', 5);"); env()->RegisterModule("test", "var assert = requireNative('assert');" "assert.AssertTrue(requireNative('thing').x == 5);"); @@ -303,13 +308,13 @@ TEST_F(ModuleSystemTest, TestRequireAsyncInParallel) { "});"); env()->RegisterModule( "math", - "exports.AddAndSubtract = function(x, y, z) {" + "exports.$set('AddAndSubtract', function(x, y, z) {" " return Promise.all([requireAsync('add')," " requireAsync('subtract')" " ]).then(function(modules) {" " return modules[1].Subtract(modules[0].Add(x, y), z);" " });" - "};"); + "});"); env()->RegisterModule("test", "var AddAndSubtract = require('math').AddAndSubtract;" "AddAndSubtract(3, 5, 2).then(function(result) {" @@ -344,8 +349,8 @@ TEST_F(ModuleSystemTest, TestNestedRequireAsyncs) { TEST_F(ModuleSystemTest, TestRequireFromAMDModule) { ModuleSystem::NativesEnabledScope natives_enabled_scope( env()->module_system()); - env()->RegisterModule("add", - "exports.Add = function(x, y) { return x + y; };"); + env()->RegisterModule( + "add", "exports.$set('Add', function(x, y) { return x + y; });"); env()->RegisterModule("math", "define('math', [], function() {" " var add = require('add');" diff --git a/extensions/renderer/resources/app_runtime_custom_bindings.js b/extensions/renderer/resources/app_runtime_custom_bindings.js index 2b492c5..0364b66 100644 --- a/extensions/renderer/resources/app_runtime_custom_bindings.js +++ b/extensions/renderer/resources/app_runtime_custom_bindings.js @@ -71,4 +71,4 @@ eventBindings.registerArgumentMassager('app.runtime.onLaunched', } }); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/app_window_custom_bindings.js b/extensions/renderer/resources/app_window_custom_bindings.js index cb44642..63f1eae 100644 --- a/extensions/renderer/resources/app_window_custom_bindings.js +++ b/extensions/renderer/resources/app_window_custom_bindings.js @@ -404,7 +404,7 @@ function updateSizeConstraints(boundsType, constraints) { currentWindowInternal.setSizeConstraints(boundsType, constraints); } -exports.binding = appWindow.generate(); -exports.onAppWindowClosed = onAppWindowClosed; -exports.updateAppWindowProperties = updateAppWindowProperties; -exports.appWindowShownForTests = onAppWindowShownForTests; +exports.$set('binding', appWindow.generate()); +exports.$set('onAppWindowClosed', onAppWindowClosed); +exports.$set('updateAppWindowProperties', updateAppWindowProperties); +exports.$set('appWindowShownForTests', onAppWindowShownForTests); diff --git a/extensions/renderer/resources/binding.js b/extensions/renderer/resources/binding.js index cf671cb..d40b18f 100644 --- a/extensions/renderer/resources/binding.js +++ b/extensions/renderer/resources/binding.js @@ -524,4 +524,4 @@ Binding.prototype = { } }; -exports.Binding = Binding; +exports.$set('Binding', Binding); diff --git a/extensions/renderer/resources/browser_test_environment_specific_bindings.js b/extensions/renderer/resources/browser_test_environment_specific_bindings.js index f540862..8574068 100644 --- a/extensions/renderer/resources/browser_test_environment_specific_bindings.js +++ b/extensions/renderer/resources/browser_test_environment_specific_bindings.js @@ -11,5 +11,5 @@ function testDone(runNextTest) { setTimeout(runNextTest, 0); } -exports.registerHooks = registerHooks; -exports.testDone = testDone; +exports.$set('registerHooks', registerHooks); +exports.$set('testDone', testDone); diff --git a/extensions/renderer/resources/context_menus_custom_bindings.js b/extensions/renderer/resources/context_menus_custom_bindings.js index fe5cec9..ec8080f 100644 --- a/extensions/renderer/resources/context_menus_custom_bindings.js +++ b/extensions/renderer/resources/context_menus_custom_bindings.js @@ -23,4 +23,4 @@ binding.registerCustomHook(function(bindingsAPI) { apiFunctions.setCustomCallback('removeAll', handlers.callbacks.removeAll); }); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/context_menus_handlers.js b/extensions/renderer/resources/context_menus_handlers.js index b334900..aef6889 100644 --- a/extensions/renderer/resources/context_menus_handlers.js +++ b/extensions/renderer/resources/context_menus_handlers.js @@ -138,4 +138,4 @@ function createContextMenusHandlers(isWebview) { }; } -exports.create = createContextMenusHandlers; +exports.$set('create', createContextMenusHandlers); diff --git a/extensions/renderer/resources/declarative_webrequest_custom_bindings.js b/extensions/renderer/resources/declarative_webrequest_custom_bindings.js index 641b782..e9da12b 100644 --- a/extensions/renderer/resources/declarative_webrequest_custom_bindings.js +++ b/extensions/renderer/resources/declarative_webrequest_custom_bindings.js @@ -93,4 +93,4 @@ binding.registerCustomHook(function(api) { }; }); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/entry_id_manager.js b/extensions/renderer/resources/entry_id_manager.js index 9fc2c14..8e23942 100644 --- a/extensions/renderer/resources/entry_id_manager.js +++ b/extensions/renderer/resources/entry_id_manager.js @@ -47,6 +47,6 @@ function getEntryById(id) { return idsToEntries[id]; } -exports.registerEntry = registerEntry; -exports.getEntryId = getEntryId; -exports.getEntryById = getEntryById; +exports.$set('registerEntry', registerEntry); +exports.$set('getEntryId', getEntryId); +exports.$set('getEntryById', getEntryById); diff --git a/extensions/renderer/resources/event.js b/extensions/renderer/resources/event.js index bb71297..5f0b912 100644 --- a/extensions/renderer/resources/event.js +++ b/extensions/renderer/resources/event.js @@ -503,8 +503,8 @@ ] }); // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. - exports.Event = Event; + exports.$set('Event', Event); - exports.dispatchEvent = dispatchEvent; - exports.parseEventOptions = parseEventOptions; - exports.registerArgumentMassager = registerArgumentMassager; + exports.$set('dispatchEvent', dispatchEvent); + exports.$set('parseEventOptions', parseEventOptions); + exports.$set('registerArgumentMassager', registerArgumentMassager); diff --git a/extensions/renderer/resources/extension_custom_bindings.js b/extensions/renderer/resources/extension_custom_bindings.js index 155b762..68450d5 100644 --- a/extensions/renderer/resources/extension_custom_bindings.js +++ b/extensions/renderer/resources/extension_custom_bindings.js @@ -108,4 +108,4 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) { } }); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/guest_view/extension_options/extension_options.js b/extensions/renderer/resources/guest_view/extension_options/extension_options.js index 7193607..70e1158 100644 --- a/extensions/renderer/resources/guest_view/extension_options/extension_options.js +++ b/extensions/renderer/resources/guest_view/extension_options/extension_options.js @@ -49,4 +49,4 @@ ExtensionOptionsImpl.prototype.createGuest = function() { GuestViewContainer.registerElement(ExtensionOptionsImpl); // Exports. -exports.ExtensionOptionsImpl = ExtensionOptionsImpl; +exports.$set('ExtensionOptionsImpl', ExtensionOptionsImpl); diff --git a/extensions/renderer/resources/guest_view/extension_options/extension_options_constants.js b/extensions/renderer/resources/guest_view/extension_options/extension_options_constants.js index f9b29ae..c4d9692 100644 --- a/extensions/renderer/resources/guest_view/extension_options/extension_options_constants.js +++ b/extensions/renderer/resources/guest_view/extension_options/extension_options_constants.js @@ -10,4 +10,5 @@ var ExtensionOptionsConstants = { ATTRIBUTE_EXTENSION: 'extension' }; -exports.ExtensionOptionsConstants = $Object.freeze(ExtensionOptionsConstants); +exports.$set('ExtensionOptionsConstants', + $Object.freeze(ExtensionOptionsConstants)); diff --git a/extensions/renderer/resources/guest_view/extension_options/extension_options_events.js b/extensions/renderer/resources/guest_view/extension_options/extension_options_events.js index 590d48a..20a2f1f 100644 --- a/extensions/renderer/resources/guest_view/extension_options/extension_options_events.js +++ b/extensions/renderer/resources/guest_view/extension_options/extension_options_events.js @@ -37,4 +37,4 @@ ExtensionOptionsEvents.prototype.getEvents = function() { }; // Exports. -exports.ExtensionOptionsEvents = ExtensionOptionsEvents; +exports.$set('ExtensionOptionsEvents', ExtensionOptionsEvents); diff --git a/extensions/renderer/resources/guest_view/extension_view/extension_view.js b/extensions/renderer/resources/guest_view/extension_view/extension_view.js index 7858e81..763b554 100644 --- a/extensions/renderer/resources/guest_view/extension_view/extension_view.js +++ b/extensions/renderer/resources/guest_view/extension_view/extension_view.js @@ -136,4 +136,4 @@ ExtensionViewImpl.prototype.loadNextSrc = function() { GuestViewContainer.registerElement(ExtensionViewImpl); // Exports. -exports.ExtensionViewImpl = ExtensionViewImpl; +exports.$set('ExtensionViewImpl', ExtensionViewImpl); diff --git a/extensions/renderer/resources/guest_view/extension_view/extension_view_constants.js b/extensions/renderer/resources/guest_view/extension_view/extension_view_constants.js index b8f0969..80934cf 100644 --- a/extensions/renderer/resources/guest_view/extension_view/extension_view_constants.js +++ b/extensions/renderer/resources/guest_view/extension_view/extension_view_constants.js @@ -11,4 +11,4 @@ var ExtensionViewConstants = { ATTRIBUTE_SRC: 'src', }; -exports.ExtensionViewConstants = $Object.freeze(ExtensionViewConstants); +exports.$set('ExtensionViewConstants', $Object.freeze(ExtensionViewConstants)); diff --git a/extensions/renderer/resources/guest_view/extension_view/extension_view_events.js b/extensions/renderer/resources/guest_view/extension_view/extension_view_events.js index 901085b..db67418 100644 --- a/extensions/renderer/resources/guest_view/extension_view/extension_view_events.js +++ b/extensions/renderer/resources/guest_view/extension_view/extension_view_events.js @@ -29,4 +29,4 @@ ExtensionViewEvents.prototype.handleLoadCommitEvent = function(event) { this.view.onLoadCommit(event.url); }; -exports.ExtensionViewEvents = ExtensionViewEvents; +exports.$set('ExtensionViewEvents', ExtensionViewEvents); diff --git a/extensions/renderer/resources/guest_view/extension_view/extension_view_internal.js b/extensions/renderer/resources/guest_view/extension_view/extension_view_internal.js index a87ee76..07c6dde 100644 --- a/extensions/renderer/resources/guest_view/extension_view/extension_view_internal.js +++ b/extensions/renderer/resources/guest_view/extension_view/extension_view_internal.js @@ -2,5 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -exports.ExtensionViewInternal = - require('binding').Binding.create('extensionViewInternal').generate(); +exports.$set( + 'ExtensionViewInternal', + require('binding').Binding.create('extensionViewInternal').generate()); diff --git a/extensions/renderer/resources/guest_view/guest_view.js b/extensions/renderer/resources/guest_view/guest_view.js index 66d48a2..1f887a7 100644 --- a/extensions/renderer/resources/guest_view/guest_view.js +++ b/extensions/renderer/resources/guest_view/guest_view.js @@ -350,6 +350,6 @@ GuestView.prototype.getId = function() { }; // Exports -exports.GuestView = GuestView; -exports.GuestViewImpl = GuestViewImpl; -exports.ResizeEvent = ResizeEvent; +exports.$set('GuestView', GuestView); +exports.$set('GuestViewImpl', GuestViewImpl); +exports.$set('ResizeEvent', ResizeEvent); diff --git a/extensions/renderer/resources/guest_view/guest_view_attributes.js b/extensions/renderer/resources/guest_view/guest_view_attributes.js index 7bc33b8..6c7f711 100644 --- a/extensions/renderer/resources/guest_view/guest_view_attributes.js +++ b/extensions/renderer/resources/guest_view/guest_view_attributes.js @@ -139,4 +139,4 @@ var GuestViewAttributes = { }; // Exports. -exports.GuestViewAttributes = GuestViewAttributes; +exports.$set('GuestViewAttributes', GuestViewAttributes); diff --git a/extensions/renderer/resources/guest_view/guest_view_container.js b/extensions/renderer/resources/guest_view/guest_view_container.js index 3e471d4..5e1aac9 100644 --- a/extensions/renderer/resources/guest_view/guest_view_container.js +++ b/extensions/renderer/resources/guest_view/guest_view_container.js @@ -306,4 +306,4 @@ function registerGuestViewElement(guestViewContainerType) { } // Exports. -exports.GuestViewContainer = GuestViewContainer; +exports.$set('GuestViewContainer', GuestViewContainer); diff --git a/extensions/renderer/resources/guest_view/guest_view_events.js b/extensions/renderer/resources/guest_view/guest_view_events.js index fda0db1..e3ccde1 100644 --- a/extensions/renderer/resources/guest_view/guest_view_events.js +++ b/extensions/renderer/resources/guest_view/guest_view_events.js @@ -174,5 +174,5 @@ GuestViewEvents.prototype.weakWrapper = function(func) { GuestViewEvents.prototype.getEvents = function() { return {}; }; // Exports. -exports.GuestViewEvents = GuestViewEvents; -exports.CreateEvent = CreateEvent; +exports.$set('GuestViewEvents', GuestViewEvents); +exports.$set('CreateEvent', CreateEvent); diff --git a/extensions/renderer/resources/guest_view/web_view/web_view.js b/extensions/renderer/resources/guest_view/web_view/web_view.js index 6fcf028..6dd4fae 100644 --- a/extensions/renderer/resources/guest_view/web_view/web_view.js +++ b/extensions/renderer/resources/guest_view/web_view/web_view.js @@ -223,4 +223,4 @@ WebViewImpl.prototype.maybeSetupContextMenus = function() {}; GuestViewContainer.registerElement(WebViewImpl); // Exports. -exports.WebViewImpl = WebViewImpl; +exports.$set('WebViewImpl', WebViewImpl); diff --git a/extensions/renderer/resources/guest_view/web_view/web_view_action_requests.js b/extensions/renderer/resources/guest_view/web_view/web_view_action_requests.js index c3cc28e..5f4bf2c 100644 --- a/extensions/renderer/resources/guest_view/web_view/web_view_action_requests.js +++ b/extensions/renderer/resources/guest_view/web_view/web_view_action_requests.js @@ -293,4 +293,4 @@ var WebViewActionRequests = { }; // Exports. -exports.WebViewActionRequests = WebViewActionRequests; +exports.$set('WebViewActionRequests', WebViewActionRequests); diff --git a/extensions/renderer/resources/guest_view/web_view/web_view_constants.js b/extensions/renderer/resources/guest_view/web_view/web_view_constants.js index 528a6fc..09110e1 100644 --- a/extensions/renderer/resources/guest_view/web_view/web_view_constants.js +++ b/extensions/renderer/resources/guest_view/web_view/web_view_constants.js @@ -37,4 +37,4 @@ var WebViewConstants = { 'The permission request for "%1" has been denied.' }; -exports.WebViewConstants = $Object.freeze(WebViewConstants); +exports.$set('WebViewConstants', $Object.freeze(WebViewConstants)); diff --git a/extensions/renderer/resources/guest_view/web_view/web_view_events.js b/extensions/renderer/resources/guest_view/web_view/web_view_events.js index 6dbb16b..1077684 100644 --- a/extensions/renderer/resources/guest_view/web_view/web_view_events.js +++ b/extensions/renderer/resources/guest_view/web_view/web_view_events.js @@ -298,4 +298,4 @@ function DeclarativeWebRequestEvent(opt_eventName, DeclarativeWebRequestEvent.prototype.__proto__ = EventBindings.Event.prototype; // Exports. -exports.WebViewEvents = WebViewEvents; +exports.$set('WebViewEvents', WebViewEvents); diff --git a/extensions/renderer/resources/guest_view/web_view/web_view_internal.js b/extensions/renderer/resources/guest_view/web_view/web_view_internal.js index 03ede9bc..4d2c36c 100644 --- a/extensions/renderer/resources/guest_view/web_view/web_view_internal.js +++ b/extensions/renderer/resources/guest_view/web_view/web_view_internal.js @@ -2,5 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -exports.WebViewInternal = - require('binding').Binding.create('webViewInternal').generate(); +exports.$set( + 'WebViewInternal', + require('binding').Binding.create('webViewInternal').generate()); diff --git a/extensions/renderer/resources/guest_view/web_view/web_view_request_custom_bindings.js b/extensions/renderer/resources/guest_view/web_view/web_view_request_custom_bindings.js index 62f7459..61b553b 100644 --- a/extensions/renderer/resources/guest_view/web_view/web_view_request_custom_bindings.js +++ b/extensions/renderer/resources/guest_view/web_view/web_view_request_custom_bindings.js @@ -52,4 +52,4 @@ binding.registerCustomHook(function(api) { } }); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/i18n_custom_bindings.js b/extensions/renderer/resources/i18n_custom_bindings.js index 4ee5206..de69fa2 100644 --- a/extensions/renderer/resources/i18n_custom_bindings.js +++ b/extensions/renderer/resources/i18n_custom_bindings.js @@ -46,4 +46,4 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) { }); }); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/image_util.js b/extensions/renderer/resources/image_util.js index b6cd1b1..a7a27a6 100644 --- a/extensions/renderer/resources/image_util.js +++ b/extensions/renderer/resources/image_util.js @@ -78,5 +78,5 @@ function loadAllImages(imageSpecs, callbacks) { } } -exports.loadImageData = loadImageData; -exports.loadAllImages = loadAllImages; +exports.$set('loadImageData', loadImageData); +exports.$set('loadAllImages', loadAllImages); diff --git a/extensions/renderer/resources/json_schema.js b/extensions/renderer/resources/json_schema.js index 147dd67..135b0ee 100644 --- a/extensions/renderer/resources/json_schema.js +++ b/extensions/renderer/resources/json_schema.js @@ -522,4 +522,4 @@ JSONSchemaValidator.prototype.resetErrors = function() { this.errors = []; }; -exports.JSONSchemaValidator = JSONSchemaValidator; +exports.$set('JSONSchemaValidator', JSONSchemaValidator); diff --git a/extensions/renderer/resources/last_error.js b/extensions/renderer/resources/last_error.js index 9b5b3c0..a205ab3 100644 --- a/extensions/renderer/resources/last_error.js +++ b/extensions/renderer/resources/last_error.js @@ -134,9 +134,9 @@ function reportIfUnchecked(name, targetChrome, stack) { (name || "unknown") + ": " + message + (stack ? "\n" + stack : "")); } -exports.clear = clear; -exports.hasAccessed = hasAccessed; -exports.hasError = hasError; -exports.set = set; -exports.run = run; -exports.reportIfUnchecked = reportIfUnchecked; +exports.$set('clear', clear); +exports.$set('hasAccessed', hasAccessed); +exports.$set('hasError', hasError); +exports.$set('set', set); +exports.$set('run', run); +exports.$set('reportIfUnchecked', reportIfUnchecked); diff --git a/extensions/renderer/resources/messaging.js b/extensions/renderer/resources/messaging.js index 5fe9920..5a7ec1e 100644 --- a/extensions/renderer/resources/messaging.js +++ b/extensions/renderer/resources/messaging.js @@ -377,16 +377,16 @@ var Port = utils.expose('Port', PortImpl, { functions: [ 'onMessage' ] }); -exports.kRequestChannel = kRequestChannel; -exports.kMessageChannel = kMessageChannel; -exports.kNativeMessageChannel = kNativeMessageChannel; -exports.Port = Port; -exports.createPort = createPort; -exports.sendMessageImpl = sendMessageImpl; -exports.sendMessageUpdateArguments = sendMessageUpdateArguments; +exports.$set('kRequestChannel', kRequestChannel); +exports.$set('kMessageChannel', kMessageChannel); +exports.$set('kNativeMessageChannel', kNativeMessageChannel); +exports.$set('Port', Port); +exports.$set('createPort', createPort); +exports.$set('sendMessageImpl', sendMessageImpl); +exports.$set('sendMessageUpdateArguments', sendMessageUpdateArguments); // For C++ code to call. -exports.hasPort = hasPort; -exports.dispatchOnConnect = dispatchOnConnect; -exports.dispatchOnDisconnect = dispatchOnDisconnect; -exports.dispatchOnMessage = dispatchOnMessage; +exports.$set('hasPort', hasPort); +exports.$set('dispatchOnConnect', dispatchOnConnect); +exports.$set('dispatchOnDisconnect', dispatchOnDisconnect); +exports.$set('dispatchOnMessage', dispatchOnMessage); diff --git a/extensions/renderer/resources/messaging_utils.js b/extensions/renderer/resources/messaging_utils.js index d1b563d..381fbeb 100644 --- a/extensions/renderer/resources/messaging_utils.js +++ b/extensions/renderer/resources/messaging_utils.js @@ -50,4 +50,4 @@ function alignSendMessageArguments(args, hasOptionsArgument) { return [targetId, request, responseCallback]; } -exports.alignSendMessageArguments = alignSendMessageArguments; +exports.$set('alignSendMessageArguments', alignSendMessageArguments); diff --git a/extensions/renderer/resources/mime_handler_private_custom_bindings.js b/extensions/renderer/resources/mime_handler_private_custom_bindings.js index 83a41af..bd7eddd 100644 --- a/extensions/renderer/resources/mime_handler_private_custom_bindings.js +++ b/extensions/renderer/resources/mime_handler_private_custom_bindings.js @@ -72,4 +72,4 @@ binding.registerCustomHook(function(bindingsAPI) { }); }); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/mojo_private_custom_bindings.js b/extensions/renderer/resources/mojo_private_custom_bindings.js index f898c07..18d6016 100644 --- a/extensions/renderer/resources/mojo_private_custom_bindings.js +++ b/extensions/renderer/resources/mojo_private_custom_bindings.js @@ -20,4 +20,4 @@ binding.registerCustomHook(function(bindingsAPI) { }); }); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/permissions_custom_bindings.js b/extensions/renderer/resources/permissions_custom_bindings.js index 43b436e..492360a 100644 --- a/extensions/renderer/resources/permissions_custom_bindings.js +++ b/extensions/renderer/resources/permissions_custom_bindings.js @@ -89,4 +89,4 @@ binding.registerCustomHook(function(api) { permissions.onAdded.dispatchToListener; }); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/printer_provider_custom_bindings.js b/extensions/renderer/resources/printer_provider_custom_bindings.js index 061029b..4bf6f12 100644 --- a/extensions/renderer/resources/printer_provider_custom_bindings.js +++ b/extensions/renderer/resources/printer_provider_custom_bindings.js @@ -120,4 +120,4 @@ handleEvent('onGetUsbPrinterInfoRequested', function(args, callback) { callback(true); }, printerProviderInternal.reportUsbPrinterInfo); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/runtime_custom_bindings.js b/extensions/renderer/resources/runtime_custom_bindings.js index 2b0e44a..1f829d4 100644 --- a/extensions/renderer/resources/runtime_custom_bindings.js +++ b/extensions/renderer/resources/runtime_custom_bindings.js @@ -202,5 +202,5 @@ binding.registerCustomHook(function(binding, id, contextType) { bindDirectoryEntryCallback('getPackageDirectoryEntry', apiFunctions); }); -exports.bindDirectoryEntryCallback = bindDirectoryEntryCallback; -exports.binding = binding.generate(); +exports.$set('bindDirectoryEntryCallback', bindDirectoryEntryCallback); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/schema_utils.js b/extensions/renderer/resources/schema_utils.js index 3d7e929..f778275 100644 --- a/extensions/renderer/resources/schema_utils.js +++ b/extensions/renderer/resources/schema_utils.js @@ -153,7 +153,7 @@ function isFunctionSignatureAmbiguous(functionDef) { return false; }; -exports.isFunctionSignatureAmbiguous = isFunctionSignatureAmbiguous; -exports.normalizeArgumentsAndValidate = normalizeArgumentsAndValidate; -exports.schemaValidator = schemaValidator; -exports.validate = validate; +exports.$set('isFunctionSignatureAmbiguous', isFunctionSignatureAmbiguous); +exports.$set('normalizeArgumentsAndValidate', normalizeArgumentsAndValidate); +exports.$set('schemaValidator', schemaValidator); +exports.$set('validate', validate); diff --git a/extensions/renderer/resources/send_request.js b/extensions/renderer/resources/send_request.js index 3dc523c..1692aaa 100644 --- a/extensions/renderer/resources/send_request.js +++ b/extensions/renderer/resources/send_request.js @@ -140,10 +140,10 @@ function clearCalledSendRequest() { calledSendRequest = false; } -exports.sendRequest = sendRequest; -exports.getCalledSendRequest = getCalledSendRequest; -exports.clearCalledSendRequest = clearCalledSendRequest; -exports.safeCallbackApply = safeCallbackApply; +exports.$set('sendRequest', sendRequest); +exports.$set('getCalledSendRequest', getCalledSendRequest); +exports.$set('clearCalledSendRequest', clearCalledSendRequest); +exports.$set('safeCallbackApply', safeCallbackApply); // Called by C++. -exports.handleResponse = handleResponse; +exports.$set('handleResponse', handleResponse); diff --git a/extensions/renderer/resources/serial_custom_bindings.js b/extensions/renderer/resources/serial_custom_bindings.js index 20d669a..d77631c 100644 --- a/extensions/renderer/resources/serial_custom_bindings.js +++ b/extensions/renderer/resources/serial_custom_bindings.js @@ -114,4 +114,4 @@ binding.registerCustomHook(function(bindingsAPI) { }); }); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/set_icon.js b/extensions/renderer/resources/set_icon.js index 83f5a80..5b66d6b 100644 --- a/extensions/renderer/resources/set_icon.js +++ b/extensions/renderer/resources/set_icon.js @@ -133,4 +133,4 @@ function setIcon(details, callback) { throw new Error('Either the path or imageData property must be specified.'); } -exports.setIcon = setIcon; +exports.$set('setIcon', setIcon); diff --git a/extensions/renderer/resources/storage_area.js b/extensions/renderer/resources/storage_area.js index de737ab..b5353ae 100644 --- a/extensions/renderer/resources/storage_area.js +++ b/extensions/renderer/resources/storage_area.js @@ -37,4 +37,4 @@ function StorageArea(namespace, schema) { $Array.forEach(apiFunctions, bindApiFunction); } -exports.StorageArea = StorageArea; +exports.$set('StorageArea', StorageArea); diff --git a/extensions/renderer/resources/test_custom_bindings.js b/extensions/renderer/resources/test_custom_bindings.js index 7310f06..6538efa 100644 --- a/extensions/renderer/resources/test_custom_bindings.js +++ b/extensions/renderer/resources/test_custom_bindings.js @@ -361,4 +361,4 @@ binding.registerCustomHook(function(api) { environmentSpecificBindings.registerHooks(api); }); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/uncaught_exception_handler.js b/extensions/renderer/resources/uncaught_exception_handler.js index f87efbc..de4d71e 100644 --- a/extensions/renderer/resources/uncaught_exception_handler.js +++ b/extensions/renderer/resources/uncaught_exception_handler.js @@ -95,16 +95,16 @@ function safeErrorToString(e, omitType) { * @param {string=} priorStackTrace - Error message suffix. * @see formatErrorMessage */ -exports.handle = function(message, e, priorStackTrace) { +exports.$set('handle', function(message, e, priorStackTrace) { message = formatErrorMessage(message, e, priorStackTrace); handler(message, e); -}; +}); // |newHandler| A function which matches |handler|. -exports.setHandler = function(newHandler) { +exports.$set('setHandler', function(newHandler) { handler = newHandler; -}; +}); -exports.getStackTrace = getStackTrace; -exports.getExtensionStackTrace = getExtensionStackTrace; -exports.safeErrorToString = safeErrorToString; +exports.$set('getStackTrace', getStackTrace); +exports.$set('getExtensionStackTrace', getExtensionStackTrace); +exports.$set('safeErrorToString', safeErrorToString); diff --git a/extensions/renderer/resources/utils.js b/extensions/renderer/resources/utils.js index ba14e8d..66094b90 100644 --- a/extensions/renderer/resources/utils.js +++ b/extensions/renderer/resources/utils.js @@ -166,9 +166,9 @@ function promise(func) { }); } -exports.forEach = forEach; -exports.loadTypeSchema = loadTypeSchema; -exports.lookup = lookup; -exports.expose = expose; -exports.deepCopy = deepCopy; -exports.promise = promise; +exports.$set('forEach', forEach); +exports.$set('loadTypeSchema', loadTypeSchema); +exports.$set('lookup', lookup); +exports.$set('expose', expose); +exports.$set('deepCopy', deepCopy); +exports.$set('promise', promise); diff --git a/extensions/renderer/resources/web_request_custom_bindings.js b/extensions/renderer/resources/web_request_custom_bindings.js index 045fe96..2dd7ce4 100644 --- a/extensions/renderer/resources/web_request_custom_bindings.js +++ b/extensions/renderer/resources/web_request_custom_bindings.js @@ -20,4 +20,4 @@ binding.registerCustomHook(function(api) { binding.registerCustomEvent(WebRequestEvent); -exports.binding = binding.generate(); +exports.$set('binding', binding.generate()); diff --git a/extensions/renderer/resources/web_request_internal_custom_bindings.js b/extensions/renderer/resources/web_request_internal_custom_bindings.js index 76460ee..7c9e279 100644 --- a/extensions/renderer/resources/web_request_internal_custom_bindings.js +++ b/extensions/renderer/resources/web_request_internal_custom_bindings.js @@ -188,5 +188,5 @@ var WebRequestEvent = utils.expose('WebRequestEvent', ] }); webRequestInternal = binding.generate(); -exports.binding = webRequestInternal; -exports.WebRequestEvent = WebRequestEvent; +exports.$set('binding', webRequestInternal); +exports.$set('WebRequestEvent', WebRequestEvent); diff --git a/extensions/renderer/utils_unittest.cc b/extensions/renderer/utils_unittest.cc index 06e20f6..485c214 100644 --- a/extensions/renderer/utils_unittest.cc +++ b/extensions/renderer/utils_unittest.cc @@ -18,11 +18,11 @@ class UtilsUnittest : public ModuleSystemTest { env()->RegisterModule("utils", IDR_UTILS_JS); env()->RegisterTestFile("utils_unittest", "utils_unittest.js"); env()->OverrideNativeHandler("schema_registry", - "exports.GetSchema = function() {};"); + "exports.$set('GetSchema', function() {});"); env()->OverrideNativeHandler("logging", - "exports.CHECK = function() {};\n" - "exports.DCHECK = function() {};\n" - "exports.WARNING = function() {};"); + "exports.$set('CHECK', function() {});\n" + "exports.$set('DCHECK', function() {});\n" + "exports.$set('WARNING', function() {});"); env()->OverrideNativeHandler("v8_context", ""); gin::Dictionary chrome(env()->isolate(), env()->CreateGlobal("chrome")); gin::Dictionary chrome_runtime( -- cgit v1.1