summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/resources/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer/resources/extensions')
-rw-r--r--chrome/renderer/resources/extensions/apitest.js (renamed from chrome/renderer/resources/extensions/test_custom_bindings.js)161
-rw-r--r--chrome/renderer/resources/extensions/app_custom_bindings.js17
-rw-r--r--chrome/renderer/resources/extensions/app_runtime_custom_bindings.js7
-rw-r--r--chrome/renderer/resources/extensions/app_window_custom_bindings.js16
-rw-r--r--chrome/renderer/resources/extensions/binding.js407
-rw-r--r--chrome/renderer/resources/extensions/bluetooth_custom_bindings.js11
-rw-r--r--chrome/renderer/resources/extensions/browser_action_custom_bindings.js9
-rw-r--r--chrome/renderer/resources/extensions/content_settings_custom_bindings.js9
-rw-r--r--chrome/renderer/resources/extensions/context_menus_custom_bindings.js8
-rw-r--r--chrome/renderer/resources/extensions/declarative_content_custom_bindings.js26
-rw-r--r--chrome/renderer/resources/extensions/declarative_webrequest_custom_bindings.js58
-rw-r--r--chrome/renderer/resources/extensions/event.js46
-rw-r--r--chrome/renderer/resources/extensions/experimental.media_galleries_custom_bindings.js11
-rw-r--r--chrome/renderer/resources/extensions/experimental.offscreenTabs_custom_bindings.js10
-rw-r--r--chrome/renderer/resources/extensions/extension_custom_bindings.js33
-rw-r--r--chrome/renderer/resources/extensions/file_browser_handler_custom_bindings.js12
-rw-r--r--chrome/renderer/resources/extensions/file_browser_private_custom_bindings.js10
-rw-r--r--chrome/renderer/resources/extensions/file_system_custom_bindings.js23
-rw-r--r--chrome/renderer/resources/extensions/i18n_custom_bindings.js8
-rw-r--r--chrome/renderer/resources/extensions/input.ime_custom_bindings.js22
-rw-r--r--chrome/renderer/resources/extensions/json_schema.js3
-rw-r--r--chrome/renderer/resources/extensions/last_error.js5
-rw-r--r--chrome/renderer/resources/extensions/media_galleries_custom_bindings.js11
-rw-r--r--chrome/renderer/resources/extensions/miscellaneous_bindings.js2
-rw-r--r--chrome/renderer/resources/extensions/notification_custom_bindings.js13
-rw-r--r--chrome/renderer/resources/extensions/omnibox_custom_bindings.js8
-rw-r--r--chrome/renderer/resources/extensions/page_action_custom_bindings.js9
-rw-r--r--chrome/renderer/resources/extensions/page_actions_custom_bindings.js14
-rw-r--r--chrome/renderer/resources/extensions/page_capture_custom_bindings.js10
-rw-r--r--chrome/renderer/resources/extensions/permissions_custom_bindings.js18
-rw-r--r--chrome/renderer/resources/extensions/runtime_custom_bindings.js23
-rw-r--r--chrome/renderer/resources/extensions/schema_generated_bindings.js437
-rw-r--r--chrome/renderer/resources/extensions/schema_utils.js1
-rw-r--r--chrome/renderer/resources/extensions/send_request.js4
-rw-r--r--chrome/renderer/resources/extensions/storage_custom_bindings.js11
-rw-r--r--chrome/renderer/resources/extensions/sync_file_system_custom_bindings.js8
-rw-r--r--chrome/renderer/resources/extensions/system_indicator_custom_bindings.js9
-rw-r--r--chrome/renderer/resources/extensions/tab_capture_custom_bindings.js10
-rw-r--r--chrome/renderer/resources/extensions/tabs_custom_bindings.js13
-rw-r--r--chrome/renderer/resources/extensions/tts_custom_bindings.js11
-rw-r--r--chrome/renderer/resources/extensions/tts_engine_custom_bindings.js6
-rw-r--r--chrome/renderer/resources/extensions/types_custom_bindings.js10
-rw-r--r--chrome/renderer/resources/extensions/utils.js13
-rw-r--r--chrome/renderer/resources/extensions/web_request_custom_bindings.js19
-rw-r--r--chrome/renderer/resources/extensions/web_request_internal_custom_bindings.js9
-rw-r--r--chrome/renderer/resources/extensions/web_view.js4
-rw-r--r--chrome/renderer/resources/extensions/web_view_experimental.js2
-rw-r--r--chrome/renderer/resources/extensions/webstore_custom_bindings.js6
48 files changed, 728 insertions, 865 deletions
diff --git a/chrome/renderer/resources/extensions/test_custom_bindings.js b/chrome/renderer/resources/extensions/apitest.js
index 300ba42..52414c2 100644
--- a/chrome/renderer/resources/extensions/test_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/apitest.js
@@ -2,20 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// test_custom_bindings.js
+// extension_apitest.js
// mini-framework for ExtensionApiTest browser tests
-var binding = require('binding').Binding.create('test');
+ chrome.test = chrome.test || {};
-var chrome = requireNative('chrome').GetChrome();
-var GetExtensionAPIDefinition =
- requireNative('apiDefinitions').GetExtensionAPIDefinition;
-
-binding.registerCustomHook(function(api) {
- var chromeTest = api.compiledApi;
- var apiFunctions = api.apiFunctions;
-
- chromeTest.tests = chromeTest.tests || [];
+ chrome.test.tests = chrome.test.tests || [];
var currentTest = null;
var lastTest = null;
@@ -32,14 +24,14 @@ binding.registerCustomHook(function(api) {
function testDone() {
// Use setTimeout here to allow previous test contexts to be
// eligible for garbage collection.
- setTimeout(chromeTest.runNextTest, 0);
+ setTimeout(chrome.test.runNextTest, 0);
}
function allTestsDone() {
if (testsFailed == 0) {
- chromeTest.notifyPass();
+ chrome.test.notifyPass();
} else {
- chromeTest.notifyFail('Failed ' + testsFailed + ' of ' +
+ chrome.test.notifyFail('Failed ' + testsFailed + ' of ' +
testCount + ' tests');
}
@@ -50,28 +42,28 @@ binding.registerCustomHook(function(api) {
var pendingCallbacks = 0;
- apiFunctions.setHandleRequest('callbackAdded', function() {
+ chrome.test.callbackAdded = function() {
pendingCallbacks++;
var called = false;
return function() {
- chromeTest.assertFalse(called, 'callback has already been run');
+ chrome.test.assertFalse(called, 'callback has already been run');
called = true;
pendingCallbacks--;
if (pendingCallbacks == 0) {
- chromeTest.succeed();
+ chrome.test.succeed();
}
};
- });
+ };
- apiFunctions.setHandleRequest('runNextTest', function() {
+ chrome.test.runNextTest = function() {
// There may have been callbacks which were interrupted by failure
// exceptions.
pendingCallbacks = 0;
lastTest = currentTest;
- currentTest = chromeTest.tests.shift();
+ currentTest = chrome.test.tests.shift();
if (!currentTest) {
allTestsDone();
@@ -79,19 +71,19 @@ binding.registerCustomHook(function(api) {
}
try {
- chromeTest.log("( RUN ) " + testName(currentTest));
+ chrome.test.log("( RUN ) " + testName(currentTest));
currentTest.call();
} catch (e) {
if (e !== failureException)
- chromeTest.fail('uncaught exception: ' + e);
+ chrome.test.fail('uncaught exception: ' + e);
}
- });
+ };
- apiFunctions.setHandleRequest('fail', function(message) {
- chromeTest.log("( FAILED ) " + testName(currentTest));
+ chrome.test.fail = function(message) {
+ chrome.test.log("( FAILED ) " + testName(currentTest));
var stack = {};
- Error.captureStackTrace(stack, chromeTest.fail);
+ Error.captureStackTrace(stack, chrome.test.fail);
if (!message)
message = "FAIL (no message)";
@@ -103,24 +95,23 @@ binding.registerCustomHook(function(api) {
// Interrupt the rest of the test.
throw failureException;
- });
+ };
- apiFunctions.setHandleRequest('succeed', function() {
+ chrome.test.succeed = function() {
console.log("[SUCCESS] " + testName(currentTest));
- chromeTest.log("( SUCCESS )");
+ chrome.test.log("( SUCCESS )");
testDone();
- });
+ };
- apiFunctions.setHandleRequest('assertTrue', function(test, message) {
- chromeTest.assertBool(test, true, message);
- });
+ chrome.test.assertTrue = function(test, message) {
+ chrome.test.assertBool(test, true, message);
+ };
- apiFunctions.setHandleRequest('assertFalse', function(test, message) {
- chromeTest.assertBool(test, false, message);
- });
+ chrome.test.assertFalse = function(test, message) {
+ chrome.test.assertBool(test, false, message);
+ };
- apiFunctions.setHandleRequest('assertBool',
- function(test, expected, message) {
+ chrome.test.assertBool = function(test, expected, message) {
if (test !== expected) {
if (typeof(test) == "string") {
if (message)
@@ -128,11 +119,11 @@ binding.registerCustomHook(function(api) {
else
message = test;
}
- chromeTest.fail(message);
+ chrome.test.fail(message);
}
- });
+ };
- apiFunctions.setHandleRequest('checkDeepEq', function(expected, actual) {
+ chrome.test.checkDeepEq = function (expected, actual) {
if ((expected === null) != (actual === null))
return false;
@@ -155,7 +146,7 @@ binding.registerCustomHook(function(api) {
var eq = true;
switch (typeof(expected[p])) {
case 'object':
- eq = chromeTest.checkDeepEq(expected[p], actual[p]);
+ eq = chrome.test.checkDeepEq(expected[p], actual[p]);
break;
case 'function':
eq = (typeof(actual[p]) != 'undefined' &&
@@ -170,45 +161,44 @@ binding.registerCustomHook(function(api) {
return false;
}
return true;
- });
+ };
- apiFunctions.setHandleRequest('assertEq',
- function(expected, actual, message) {
+ chrome.test.assertEq = function(expected, actual, message) {
var error_msg = "API Test Error in " + testName(currentTest);
if (message)
error_msg += ": " + message;
if (typeof(expected) == 'object') {
- if (!chromeTest.checkDeepEq(expected, actual)) {
- chromeTest.fail(error_msg +
+ if (!chrome.test.checkDeepEq(expected, actual)) {
+ chrome.test.fail(error_msg +
"\nActual: " + JSON.stringify(actual) +
"\nExpected: " + JSON.stringify(expected));
}
return;
}
if (expected != actual) {
- chromeTest.fail(error_msg +
+ chrome.test.fail(error_msg +
"\nActual: " + actual + "\nExpected: " + expected);
}
if (typeof(expected) != typeof(actual)) {
- chromeTest.fail(error_msg +
+ chrome.test.fail(error_msg +
" (type mismatch)\nActual Type: " + typeof(actual) +
"\nExpected Type:" + typeof(expected));
}
- });
+ };
- apiFunctions.setHandleRequest('assertNoLastError', function() {
+ chrome.test.assertNoLastError = function() {
if (chrome.runtime.lastError != undefined) {
- chromeTest.fail("lastError.message == " +
+ chrome.test.fail("lastError.message == " +
chrome.runtime.lastError.message);
}
- });
+ };
- apiFunctions.setHandleRequest('assertLastError', function(expectedError) {
- chromeTest.assertEq(typeof(expectedError), 'string');
- chromeTest.assertTrue(chrome.runtime.lastError != undefined,
+ chrome.test.assertLastError = function(expectedError) {
+ chrome.test.assertEq(typeof(expectedError), 'string');
+ chrome.test.assertTrue(chrome.runtime.lastError != undefined,
"No lastError, but expected " + expectedError);
- chromeTest.assertEq(expectedError, chrome.runtime.lastError.message);
- });
+ chrome.test.assertEq(expectedError, chrome.runtime.lastError.message);
+ }
function safeFunctionApply(func, args) {
try {
@@ -216,23 +206,23 @@ binding.registerCustomHook(function(api) {
func.apply(null, args);
} catch (e) {
var msg = "uncaught exception " + e;
- chromeTest.fail(msg);
+ chrome.test.fail(msg);
}
};
// Wrapper for generating test functions, that takes care of calling
// assertNoLastError() and (optionally) succeed() for you.
- apiFunctions.setHandleRequest('callback', function(func, expectedError) {
+ chrome.test.callback = function(func, expectedError) {
if (func) {
- chromeTest.assertEq(typeof(func), 'function');
+ chrome.test.assertEq(typeof(func), 'function');
}
- var callbackCompleted = chromeTest.callbackAdded();
+ var callbackCompleted = chrome.test.callbackAdded();
return function() {
if (expectedError == null) {
- chromeTest.assertNoLastError();
+ chrome.test.assertNoLastError();
} else {
- chromeTest.assertLastError(expectedError);
+ chrome.test.assertLastError(expectedError);
}
if (func) {
@@ -241,20 +231,20 @@ binding.registerCustomHook(function(api) {
callbackCompleted();
};
- });
+ };
- apiFunctions.setHandleRequest('listenOnce', function(event, func) {
- var callbackCompleted = chromeTest.callbackAdded();
+ chrome.test.listenOnce = function(event, func) {
+ var callbackCompleted = chrome.test.callbackAdded();
var listener = function() {
event.removeListener(listener);
safeFunctionApply(func, arguments);
callbackCompleted();
};
event.addListener(listener);
- });
+ };
- apiFunctions.setHandleRequest('listenForever', function(event, func) {
- var callbackCompleted = chromeTest.callbackAdded();
+ chrome.test.listenForever = function(event, func) {
+ var callbackCompleted = chrome.test.callbackAdded();
var listener = function() {
safeFunctionApply(func, arguments);
@@ -267,25 +257,18 @@ binding.registerCustomHook(function(api) {
event.addListener(listener);
return done;
- });
-
- apiFunctions.setHandleRequest('callbackPass', function(func) {
- return chromeTest.callback(func);
- });
-
- apiFunctions.setHandleRequest('callbackFail', function(expectedError, func) {
- return chromeTest.callback(func, expectedError);
- });
+ };
- apiFunctions.setHandleRequest('runTests', function(tests) {
- chromeTest.tests = tests;
- testCount = chromeTest.tests.length;
- chromeTest.runNextTest();
- });
+ chrome.test.callbackPass = function(func) {
+ return chrome.test.callback(func);
+ };
- apiFunctions.setHandleRequest('getApiDefinitions', function(apiNames) {
- return GetExtensionAPIDefinition();
- });
-});
+ chrome.test.callbackFail = function(expectedError, func) {
+ return chrome.test.callback(func, expectedError);
+ };
-exports.binding = binding.generate();
+ chrome.test.runTests = function(tests) {
+ chrome.test.tests = tests;
+ testCount = chrome.test.tests.length;
+ chrome.test.runNextTest();
+ };
diff --git a/chrome/renderer/resources/extensions/app_custom_bindings.js b/chrome/renderer/resources/extensions/app_custom_bindings.js
index 0b9dd89..1a8bbcc 100644
--- a/chrome/renderer/resources/extensions/app_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/app_custom_bindings.js
@@ -2,11 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the app API.
+// Custom bindings for the app API.
var appNatives = requireNative('app');
-var chrome = requireNative('chrome').GetChrome();
-var GetAvailability = requireNative('v8_context').GetAvailability;
// This becomes chrome.app
var app = {
@@ -45,7 +43,7 @@ var chromeHiddenApp = {
// appNotification stuff.
//
-// TODO(kalman): move this stuff to its own custom binding.
+// TODO(kalman): move this stuff to its own custom bindings.
// It will be bit tricky since I'll need to look into why there are
// permissions defined for app notifications, yet this always sets it up?
var callbacks = {};
@@ -69,11 +67,8 @@ app.installState = function getInstallState(callback) {
appNatives.GetInstallState(callbackId);
};
-// These must match the names in InstallAppbinding() in
+// These must match the names in InstallAppBindings() in
// chrome/renderer/extensions/dispatcher.cc.
-var availability = GetAvailability('app');
-if (availability.is_available) {
- exports.chromeApp = app;
- exports.chromeAppNotifications = appNotifications;
- exports.chromeHiddenApp = chromeHiddenApp;
-}
+exports.chromeApp = app;
+exports.chromeAppNotifications = appNotifications;
+exports.chromeHiddenApp = chromeHiddenApp;
diff --git a/chrome/renderer/resources/extensions/app_runtime_custom_bindings.js b/chrome/renderer/resources/extensions/app_runtime_custom_bindings.js
index a50c964..0a70fc4 100644
--- a/chrome/renderer/resources/extensions/app_runtime_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/app_runtime_custom_bindings.js
@@ -2,12 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the chrome.app.runtime API.
-
-var binding = require('binding').Binding.create('app.runtime');
+// Custom bindings for the chrome.app.runtime API.
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var chrome = requireNative('chrome').GetChrome();
var fileSystemHelpers = requireNative('file_system_natives');
var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem;
var appNatives = requireNative('app_runtime');
@@ -52,5 +49,3 @@ chromeHidden.Event.registerArgumentMassager('app.runtime.onLaunched',
dispatch([]);
}
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/app_window_custom_bindings.js b/chrome/renderer/resources/extensions/app_window_custom_bindings.js
index a145f67..1bb5bef 100644
--- a/chrome/renderer/resources/extensions/app_window_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/app_window_custom_bindings.js
@@ -2,21 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the app_window API.
+// Custom bindings for the app_window API.
-var Binding = require('binding').Binding;
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var chrome = requireNative('chrome').GetChrome();
var sendRequest = require('sendRequest').sendRequest;
var appWindowNatives = requireNative('app_window');
var forEach = require('utils').forEach;
var GetView = appWindowNatives.GetView;
var OnContextReady = appWindowNatives.OnContextReady;
-var appWindow = Binding.create('app.window');
-appWindow.registerCustomHook(function(bindingsAPI) {
+chromeHidden.registerCustomHook('app.window', function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
-
apiFunctions.setCustomCallback('create',
function(name, request, windowParams) {
var view = null;
@@ -85,12 +81,10 @@ appWindow.registerCustomHook(function(bindingsAPI) {
// This is an internal function, but needs to be bound with setHandleRequest
// because it is called from a different JS context.
apiFunctions.setHandleRequest('initializeAppWindow', function(params) {
- var currentWindowInternal =
- Binding.create('app.currentWindowInternal').generate();
var AppWindow = function() {};
- forEach(currentWindowInternal, function(fn) {
+ forEach(chromeHidden.internalAPIs.app.currentWindowInternal, function(fn) {
AppWindow.prototype[fn] =
- currentWindowInternal[fn];
+ chromeHidden.internalAPIs.app.currentWindowInternal[fn];
});
AppWindow.prototype.moveTo = window.moveTo.bind(window);
AppWindow.prototype.resizeTo = window.resizeTo.bind(window);
@@ -154,5 +148,3 @@ chromeHidden.updateAppWindowProperties = function(update) {
(oldData.maximized && !update.maximized))
currentWindow["onRestored"].dispatch();
};
-
-exports.binding = appWindow.generate();
diff --git a/chrome/renderer/resources/extensions/binding.js b/chrome/renderer/resources/extensions/binding.js
deleted file mode 100644
index d6fb4df..0000000
--- a/chrome/renderer/resources/extensions/binding.js
+++ /dev/null
@@ -1,407 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-require('json_schema');
-require('event_bindings');
-var schemaRegistry = requireNative('schema_registry');
-var sendRequest = require('sendRequest').sendRequest;
-var utils = require('utils');
-var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var chrome = requireNative('chrome').GetChrome();
-var schemaUtils = require('schemaUtils');
-var process = requireNative('process');
-var manifestVersion = process.GetManifestVersion();
-var extensionId = process.GetExtensionId();
-var contextType = process.GetContextType();
-var GetAvailability = requireNative('v8_context').GetAvailability;
-var logging = requireNative('logging');
-
-// Stores the name and definition of each API function, with methods to
-// modify their behaviour (such as a custom way to handle requests to the
-// API, a custom callback, etc).
-function APIFunctions() {
- this.apiFunctions_ = {};
- this.unavailableApiFunctions_ = {};
-}
-
-APIFunctions.prototype.register = function(apiName, apiFunction) {
- this.apiFunctions_[apiName] = apiFunction;
-};
-
-// Registers a function as existing but not available, meaning that calls to
-// the set* methods that reference this function should be ignored rather
-// than throwing Errors.
-APIFunctions.prototype.registerUnavailable = function(apiName) {
- this.unavailableApiFunctions_[apiName] = apiName;
-};
-
-APIFunctions.prototype.setHook_ =
- function(apiName, propertyName, customizedFunction) {
- if (this.unavailableApiFunctions_.hasOwnProperty(apiName))
- return;
- if (!this.apiFunctions_.hasOwnProperty(apiName))
- throw new Error('Tried to set hook for unknown API "' + apiName + '"');
- this.apiFunctions_[apiName][propertyName] = customizedFunction;
-};
-
-APIFunctions.prototype.setHandleRequest =
- function(apiName, customizedFunction) {
- return this.setHook_(apiName, 'handleRequest', customizedFunction);
-};
-
-APIFunctions.prototype.setUpdateArgumentsPostValidate =
- function(apiName, customizedFunction) {
- return this.setHook_(
- apiName, 'updateArgumentsPostValidate', customizedFunction);
-};
-
-APIFunctions.prototype.setUpdateArgumentsPreValidate =
- function(apiName, customizedFunction) {
- return this.setHook_(
- apiName, 'updateArgumentsPreValidate', customizedFunction);
-};
-
-APIFunctions.prototype.setCustomCallback =
- function(apiName, customizedFunction) {
- return this.setHook_(apiName, 'customCallback', customizedFunction);
-};
-
-function CustomBindingsObject() {
-}
-
-CustomBindingsObject.prototype.setSchema = function(schema) {
- // The functions in the schema are in list form, so we move them into a
- // dictionary for easier access.
- var self = this;
- self.functionSchemas = {};
- schema.functions.forEach(function(f) {
- self.functionSchemas[f.name] = {
- name: f.name,
- definition: f
- }
- });
-};
-
-// Get the platform from navigator.appVersion.
-function getPlatform() {
- var platforms = [
- [/CrOS Touch/, "chromeos touch"],
- [/CrOS/, "chromeos"],
- [/Linux/, "linux"],
- [/Mac/, "mac"],
- [/Win/, "win"],
- ];
-
- for (var i = 0; i < platforms.length; i++) {
- if (platforms[i][0].test(navigator.appVersion)) {
- return platforms[i][1];
- }
- }
- return "unknown";
-}
-
-function isPlatformSupported(schemaNode, platform) {
- return !schemaNode.platforms ||
- schemaNode.platforms.indexOf(platform) > -1;
-}
-
-function isManifestVersionSupported(schemaNode, manifestVersion) {
- return !schemaNode.maximumManifestVersion ||
- manifestVersion <= schemaNode.maximumManifestVersion;
-}
-
-function isSchemaNodeSupported(schemaNode, platform, manifestVersion) {
- return isPlatformSupported(schemaNode, platform) &&
- isManifestVersionSupported(schemaNode, manifestVersion);
-}
-
-var platform = getPlatform();
-
-function Binding(schema) {
- this.schema_ = schema;
- this.apiFunctions_ = new APIFunctions();
- this.customEvent_ = null;
- this.customTypes_ = {};
- this.customHooks_ = [];
-};
-
-Binding.create = function(apiName) {
- return new Binding(schemaRegistry.GetSchema(apiName));
-};
-
-Binding.prototype = {
- // The API through which the ${api_name}_custom_bindings.js files customize
- // their API bindings beyond what can be generated.
- //
- // There are 2 types of customizations available: those which are required in
- // order to do the schema generation (registerCustomEvent and
- // registerCustomType), and those which can only run after the bindings have
- // been generated (registerCustomHook).
- //
-
- // Registers a custom type referenced via "$ref" fields in the API schema
- // JSON.
- registerCustomType: function(typeName, customTypeFactory) {
- var customType = customTypeFactory();
- customType.prototype = new CustomBindingsObject();
- this.customTypes_[typeName] = customType;
- },
-
- // Registers a custom event type for the API identified by |namespace|.
- // |event| is the event's constructor.
- registerCustomEvent: function(event) {
- this.customEvent_ = event;
- },
-
- // Registers a function |hook| to run after the schema for all APIs has been
- // generated. The hook is passed as its first argument an "API" object to
- // interact with, and second the current extension ID. See where
- // |customHooks| is used.
- registerCustomHook: function(fn) {
- this.customHooks_.push(fn);
- },
-
- // TODO(kalman/cduvall): Refactor this so |runHooks_| is not needed.
- runHooks_: function(api) {
- this.customHooks_.forEach(function(hook) {
- if (!isSchemaNodeSupported(this.schema_, platform, manifestVersion))
- return;
-
- if (!hook)
- return;
-
- hook({
- apiFunctions: this.apiFunctions_,
- schema: this.schema_,
- compiledApi: api
- }, extensionId, contextType);
- }, this);
- },
-
- // Generates the bindings from |this.schema_| and integrates any custom
- // bindings that might be present.
- generate: function() {
- var schema = this.schema_;
- var customTypes = this.customTypes_;
-
- // TODO(kalman/cduvall): Make GetAvailability handle this, then delete the
- // supporting code.
- if (!isSchemaNodeSupported(schema, platform, manifestVersion))
- return;
-
- var availability = GetAvailability(schema.namespace);
- if (!availability.is_available) {
- console.error('chrome.' + schema.namespace + ' is not available: ' +
- availability.message);
- return;
- }
-
- // See comment on internalAPIs at the top.
- var mod = {};
-
- var namespaces = schema.namespace.split('.');
- for (var index = 0, name; name = namespaces[index]; index++) {
- mod[name] = mod[name] || {};
- mod = mod[name];
- }
-
- // Add types to global schemaValidator
- if (schema.types) {
- schema.types.forEach(function(t) {
- if (!isSchemaNodeSupported(t, platform, manifestVersion))
- return;
-
- schemaUtils.schemaValidator.addTypes(t);
- if (t.type == 'object' && this.customTypes_[t.id]) {
- var parts = t.id.split(".");
- this.customTypes_[t.id].prototype.setSchema(t);
- mod[parts[parts.length - 1]] = this.customTypes_[t.id];
- }
- }, this);
- }
-
- // Returns whether access to the content of a schema should be denied,
- // based on the presence of "unprivileged" and whether this is an
- // extension process (versus e.g. a content script).
- function isSchemaAccessAllowed(itemSchema) {
- return (contextType == 'BLESSED_EXTENSION') ||
- schema.unprivileged ||
- itemSchema.unprivileged;
- };
-
- // Adds a getter that throws an access denied error to object |mod|
- // for property |name|.
- function addUnprivilegedAccessGetter(mod, name) {
- mod.__defineGetter__(name, function() {
- throw new Error(
- '"' + name + '" can only be used in extension processes. See ' +
- 'the content scripts documentation for more details.');
- });
- }
-
- // Setup Functions.
- if (schema.functions) {
- schema.functions.forEach(function(functionDef) {
- if (functionDef.name in mod) {
- throw new Error('Function ' + functionDef.name +
- ' already defined in ' + schema.namespace);
- }
-
- if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) {
- this.apiFunctions_.registerUnavailable(functionDef.name);
- return;
- }
- if (!isSchemaAccessAllowed(functionDef)) {
- this.apiFunctions_.registerUnavailable(functionDef.name);
- addUnprivilegedAccessGetter(mod, functionDef.name);
- return;
- }
-
- var apiFunction = {};
- apiFunction.definition = functionDef;
- apiFunction.name = schema.namespace + '.' + functionDef.name;
-
- // TODO(aa): It would be best to run this in a unit test, but in order
- // to do that we would need to better factor this code so that it
- // doesn't depend on so much v8::Extension machinery.
- if (chromeHidden.validateAPI &&
- schemaUtils.isFunctionSignatureAmbiguous(
- apiFunction.definition)) {
- throw new Error(
- apiFunction.name + ' has ambiguous optional arguments. ' +
- 'To implement custom disambiguation logic, add ' +
- '"allowAmbiguousOptionalArguments" to the function\'s schema.');
- }
-
- this.apiFunctions_.register(functionDef.name, apiFunction);
-
- mod[functionDef.name] = (function() {
- var args = Array.prototype.slice.call(arguments);
- if (this.updateArgumentsPreValidate)
- args = this.updateArgumentsPreValidate.apply(this, args);
-
- args = schemaUtils.normalizeArgumentsAndValidate(args, this);
- if (this.updateArgumentsPostValidate)
- args = this.updateArgumentsPostValidate.apply(this, args);
-
- var retval;
- if (this.handleRequest) {
- retval = this.handleRequest.apply(this, args);
- } else {
- var optArgs = {
- customCallback: this.customCallback
- };
- retval = sendRequest(this.name, args,
- this.definition.parameters,
- optArgs);
- }
-
- // Validate return value if defined - only in debug.
- if (chromeHidden.validateCallbacks &&
- this.definition.returns) {
- schemaUtils.validate([retval], [this.definition.returns]);
- }
- return retval;
- }).bind(apiFunction);
- }, this);
- }
-
- // Setup Events
- if (schema.events) {
- schema.events.forEach(function(eventDef) {
- if (eventDef.name in mod) {
- throw new Error('Event ' + eventDef.name +
- ' already defined in ' + schema.namespace);
- }
- if (!isSchemaNodeSupported(eventDef, platform, manifestVersion))
- return;
- if (!isSchemaAccessAllowed(eventDef)) {
- addUnprivilegedAccessGetter(mod, eventDef.name);
- return;
- }
-
- var eventName = schema.namespace + "." + eventDef.name;
- var options = eventDef.options || {};
-
- if (eventDef.filters && eventDef.filters.length > 0)
- options.supportsFilters = true;
-
- if (this.customEvent_) {
- mod[eventDef.name] = new this.customEvent_(
- eventName, eventDef.parameters, eventDef.extraParameters,
- options);
- } else if (eventDef.anonymous) {
- mod[eventDef.name] = new chrome.Event();
- } else {
- mod[eventDef.name] = new chrome.Event(
- eventName, eventDef.parameters, options);
- }
- }, this);
- }
-
- function addProperties(m, parentDef) {
- var properties = parentDef.properties;
- if (!properties)
- return;
-
- utils.forEach(properties, function(propertyName, propertyDef) {
- if (propertyName in m)
- return; // TODO(kalman): be strict like functions/events somehow.
- if (!isSchemaNodeSupported(propertyDef, platform, manifestVersion))
- return;
- if (!isSchemaAccessAllowed(propertyDef)) {
- addUnprivilegedAccessGetter(m, propertyName);
- return;
- }
-
- var value = propertyDef.value;
- if (value) {
- // Values may just have raw types as defined in the JSON, such
- // as "WINDOW_ID_NONE": { "value": -1 }. We handle this here.
- // TODO(kalman): enforce that things with a "value" property can't
- // define their own types.
- var type = propertyDef.type || typeof(value);
- if (type === 'integer' || type === 'number') {
- value = parseInt(value);
- } else if (type === 'boolean') {
- value = value === 'true';
- } else if (propertyDef['$ref']) {
- if (propertyDef['$ref'] in customTypes) {
- var constructor = customTypes[propertyDef['$ref']];
- } else {
- var refParts = propertyDef['$ref'].split('.');
- // This should never try to load a $ref in the current namespace.
- var constructor = utils.loadRefDependency(
- propertyDef['$ref'])[refParts[refParts.length - 1]];
- }
- if (!constructor)
- throw new Error('No custom binding for ' + propertyDef['$ref']);
- var args = value;
- // For an object propertyDef, |value| is an array of constructor
- // arguments, but we want to pass the arguments directly (i.e.
- // not as an array), so we have to fake calling |new| on the
- // constructor.
- value = { __proto__: constructor.prototype };
- constructor.apply(value, args);
- // Recursively add properties.
- addProperties(value, propertyDef);
- } else if (type === 'object') {
- // Recursively add properties.
- addProperties(value, propertyDef);
- } else if (type !== 'string') {
- throw new Error('NOT IMPLEMENTED (extension_api.json error): ' +
- 'Cannot parse values for type "' + type + '"');
- }
- m[propertyName] = value;
- }
- });
- };
-
- addProperties(mod, schema);
- this.runHooks_(mod);
- return mod;
- }
-};
-
-exports.Binding = Binding;
diff --git a/chrome/renderer/resources/extensions/bluetooth_custom_bindings.js b/chrome/renderer/resources/extensions/bluetooth_custom_bindings.js
index 9531b3a..e1f75f5 100644
--- a/chrome/renderer/resources/extensions/bluetooth_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/bluetooth_custom_bindings.js
@@ -2,19 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the Bluetooth API.
-
-var binding = require('binding').Binding.create('bluetooth');
+// Custom bindings for the Bluetooth API.
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var chrome = requireNative('chrome').GetChrome();
var sendRequest = require('sendRequest').sendRequest;
var lastError = require('lastError');
-// Use custom binding to create an undocumented event listener that will
+// Use custom bindings to create an undocumented event listener that will
// receive events about device discovery and call the event listener that was
// provided with the request to begin discovery.
-binding.registerCustomHook(function(api) {
+chromeHidden.registerCustomHook('bluetooth', function(api) {
var apiFunctions = api.apiFunctions;
chromeHidden.bluetooth = {};
@@ -157,5 +154,3 @@ binding.registerCustomHook(function(api) {
return args;
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/browser_action_custom_bindings.js b/chrome/renderer/resources/extensions/browser_action_custom_bindings.js
index d90ab18..9d1d92e 100644
--- a/chrome/renderer/resources/extensions/browser_action_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/browser_action_custom_bindings.js
@@ -2,13 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the browserAction API.
-
-var binding = require('binding').Binding.create('browserAction');
+// Custom bindings for the browserAction API.
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var setIcon = require('setIcon').setIcon;
-binding.registerCustomHook(function(bindingsAPI) {
+chromeHidden.registerCustomHook('browserAction', function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setHandleRequest('setIcon', function(details, callback) {
@@ -16,5 +15,3 @@ binding.registerCustomHook(function(bindingsAPI) {
'browser action');
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/content_settings_custom_bindings.js b/chrome/renderer/resources/extensions/content_settings_custom_bindings.js
index 8347078..d92efc1 100644
--- a/chrome/renderer/resources/extensions/content_settings_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/content_settings_custom_bindings.js
@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the contentSettings API.
-
-var binding = require('binding').Binding.create('contentSettings');
+// Custom bindings for the contentSettings API.
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var sendRequest = require('sendRequest').sendRequest;
var validate = require('schemaUtils').validate;
-binding.registerCustomType('contentSettings.ContentSetting', function() {
+chromeHidden.registerCustomType('contentSettings.ContentSetting', function() {
function extendSchema(schema) {
var extendedSchema = schema.slice();
extendedSchema.unshift({'type': 'string'});
@@ -52,5 +51,3 @@ binding.registerCustomType('contentSettings.ContentSetting', function() {
return ContentSetting;
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/context_menus_custom_bindings.js b/chrome/renderer/resources/extensions/context_menus_custom_bindings.js
index 4b0a936..e2629f7 100644
--- a/chrome/renderer/resources/extensions/context_menus_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/context_menus_custom_bindings.js
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the contextMenus API.
-
-var binding = require('binding').Binding.create('contextMenus');
+// Custom bindings for the contextMenus API.
var contextMenus = requireNative('context_menus');
var GetNextContextMenuId = contextMenus.GetNextContextMenuId;
@@ -12,7 +10,7 @@ var sendRequest = require('sendRequest').sendRequest;
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-binding.registerCustomHook(function(bindingsAPI) {
+chromeHidden.registerCustomHook('contextMenus', function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
chromeHidden.contextMenus = {};
@@ -100,5 +98,3 @@ binding.registerCustomHook(function(bindingsAPI) {
chromeHidden.contextMenus.stringIdHandlers = {};
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/declarative_content_custom_bindings.js b/chrome/renderer/resources/extensions/declarative_content_custom_bindings.js
index 066413e..3655c46 100644
--- a/chrome/renderer/resources/extensions/declarative_content_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/declarative_content_custom_bindings.js
@@ -2,21 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the declarativeContent API.
-
-var binding = require('binding').Binding.create('declarativeContent');
+// Custom bindings for the declarativeContent API.
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var utils = require('utils');
var validate = require('schemaUtils').validate;
-binding.registerCustomHook( function(api) {
- var declarativeContent = api.compiledApi;
-
+chromeHidden.registerCustomHook('declarativeContent', function(api) {
// Returns the schema definition of type |typeId| defined in |namespace|.
- function getSchema(typeId) {
- return utils.lookup(api.schema.types,
- 'id',
- 'declarativeContent.' + typeId);
+ function getSchema(namespace, typeId) {
+ var apiSchema = utils.lookup(api.apiDefinitions, 'namespace', namespace);
+ var resultSchema = utils.lookup(
+ apiSchema.types, 'id', namespace + '.' + typeId);
+ return resultSchema;
}
// Helper function for the constructor of concrete datatypes of the
@@ -31,17 +29,15 @@ binding.registerCustomHook( function(api) {
}
}
instance.instanceType = 'declarativeContent.' + typeId;
- var schema = getSchema(typeId);
+ var schema = getSchema('declarativeContent', typeId);
validate([instance], [schema]);
}
// Setup all data types for the declarative content API.
- declarativeContent.PageStateMatcher = function(parameters) {
+ chrome.declarativeContent.PageStateMatcher = function(parameters) {
setupInstance(this, parameters, 'PageStateMatcher');
};
- declarativeContent.ShowPageAction = function(parameters) {
+ chrome.declarativeContent.ShowPageAction = function(parameters) {
setupInstance(this, parameters, 'ShowPageAction');
};
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/declarative_webrequest_custom_bindings.js b/chrome/renderer/resources/extensions/declarative_webrequest_custom_bindings.js
index 9d0c3c5..f015bf7 100644
--- a/chrome/renderer/resources/extensions/declarative_webrequest_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/declarative_webrequest_custom_bindings.js
@@ -2,23 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the declarativeWebRequest API.
-
-var binding = require('binding').Binding.create('declarativeWebRequest');
+// Custom bindings for the declarativeWebRequest API.
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var chrome = requireNative('chrome').GetChrome();
var utils = require('utils');
var validate = require('schemaUtils').validate;
-binding.registerCustomHook(function(api) {
- var declarativeWebRequest = api.compiledApi;
-
+chromeHidden.registerCustomHook('declarativeWebRequest', function(api) {
// Returns the schema definition of type |typeId| defined in |namespace|.
- function getSchema(typeId) {
- return utils.lookup(api.schema.types,
- 'id',
- 'declarativeWebRequest.' + typeId);
+ function getSchema(namespace, typeId) {
+ var apiSchema = utils.lookup(api.apiDefinitions, 'namespace', namespace);
+ var resultSchema = utils.lookup(
+ apiSchema.types, 'id', namespace + '.' + typeId);
+ return resultSchema;
}
// Helper function for the constructor of concrete datatypes of the
@@ -33,66 +29,64 @@ binding.registerCustomHook(function(api) {
}
}
instance.instanceType = 'declarativeWebRequest.' + typeId;
- var schema = getSchema(typeId);
+ var schema = getSchema('declarativeWebRequest', typeId);
validate([instance], [schema]);
}
// Setup all data types for the declarative webRequest API.
- declarativeWebRequest.RequestMatcher = function(parameters) {
+ chrome.declarativeWebRequest.RequestMatcher = function(parameters) {
setupInstance(this, parameters, 'RequestMatcher');
};
- declarativeWebRequest.CancelRequest = function(parameters) {
+ chrome.declarativeWebRequest.CancelRequest = function(parameters) {
setupInstance(this, parameters, 'CancelRequest');
};
- declarativeWebRequest.RedirectRequest = function(parameters) {
+ chrome.declarativeWebRequest.RedirectRequest = function(parameters) {
setupInstance(this, parameters, 'RedirectRequest');
};
- declarativeWebRequest.SetRequestHeader = function(parameters) {
+ chrome.declarativeWebRequest.SetRequestHeader = function(parameters) {
setupInstance(this, parameters, 'SetRequestHeader');
};
- declarativeWebRequest.RemoveRequestHeader = function(parameters) {
+ chrome.declarativeWebRequest.RemoveRequestHeader = function(parameters) {
setupInstance(this, parameters, 'RemoveRequestHeader');
};
- declarativeWebRequest.AddResponseHeader = function(parameters) {
+ chrome.declarativeWebRequest.AddResponseHeader = function(parameters) {
setupInstance(this, parameters, 'AddResponseHeader');
};
- declarativeWebRequest.RemoveResponseHeader = function(parameters) {
+ chrome.declarativeWebRequest.RemoveResponseHeader = function(parameters) {
setupInstance(this, parameters, 'RemoveResponseHeader');
};
- declarativeWebRequest.RedirectToTransparentImage =
+ chrome.declarativeWebRequest.RedirectToTransparentImage =
function(parameters) {
setupInstance(this, parameters, 'RedirectToTransparentImage');
};
- declarativeWebRequest.RedirectToEmptyDocument = function(parameters) {
+ chrome.declarativeWebRequest.RedirectToEmptyDocument = function(parameters) {
setupInstance(this, parameters, 'RedirectToEmptyDocument');
};
- declarativeWebRequest.RedirectByRegEx = function(parameters) {
+ chrome.declarativeWebRequest.RedirectByRegEx = function(parameters) {
setupInstance(this, parameters, 'RedirectByRegEx');
};
- declarativeWebRequest.IgnoreRules = function(parameters) {
+ chrome.declarativeWebRequest.IgnoreRules = function(parameters) {
setupInstance(this, parameters, 'IgnoreRules');
};
- declarativeWebRequest.AddRequestCookie = function(parameters) {
+ chrome.declarativeWebRequest.AddRequestCookie = function(parameters) {
setupInstance(this, parameters, 'AddRequestCookie');
};
- declarativeWebRequest.AddResponseCookie = function(parameters) {
+ chrome.declarativeWebRequest.AddResponseCookie = function(parameters) {
setupInstance(this, parameters, 'AddResponseCookie');
};
- declarativeWebRequest.EditRequestCookie = function(parameters) {
+ chrome.declarativeWebRequest.EditRequestCookie = function(parameters) {
setupInstance(this, parameters, 'EditRequestCookie');
};
- declarativeWebRequest.EditResponseCookie = function(parameters) {
+ chrome.declarativeWebRequest.EditResponseCookie = function(parameters) {
setupInstance(this, parameters, 'EditResponseCookie');
};
- declarativeWebRequest.RemoveRequestCookie = function(parameters) {
+ chrome.declarativeWebRequest.RemoveRequestCookie = function(parameters) {
setupInstance(this, parameters, 'RemoveRequestCookie');
};
- declarativeWebRequest.RemoveResponseCookie = function(parameters) {
+ chrome.declarativeWebRequest.RemoveResponseCookie = function(parameters) {
setupInstance(this, parameters, 'RemoveResponseCookie');
};
- declarativeWebRequest.SendMessageToExtension = function(parameters) {
+ chrome.declarativeWebRequest.SendMessageToExtension = function(parameters) {
setupInstance(this, parameters, 'SendMessageToExtension');
};
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/event.js b/chrome/renderer/resources/extensions/event.js
index 59e04d5..4e99256 100644
--- a/chrome/renderer/resources/extensions/event.js
+++ b/chrome/renderer/resources/extensions/event.js
@@ -3,8 +3,6 @@
// found in the LICENSE file.
var DCHECK = requireNative('logging').DCHECK;
- // TODO(cduvall/kalman): json_schema shouldn't put things on chromeHidden.
- require('json_schema');
var eventBindingsNatives = requireNative('event_bindings');
var AttachEvent = eventBindingsNatives.AttachEvent;
var DetachEvent = eventBindingsNatives.DetachEvent;
@@ -16,8 +14,8 @@
var validate = require('schemaUtils').validate;
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
- var chrome = requireNative('chrome').GetChrome();
- var schemaRegistry = requireNative('schema_registry');
+ var GetExtensionAPIDefinition =
+ requireNative('apiDefinitions').GetExtensionAPIDefinition;
// Schemas for the rule-style functions on the events API that
// only need to be generated occasionally, so populate them lazily.
@@ -32,7 +30,7 @@
function ensureRuleSchemasLoaded() {
if (ruleFunctionSchemas.addRules)
return;
- var eventsSchema = schemaRegistry.GetSchema("events");
+ var eventsSchema = GetExtensionAPIDefinition("events")[0];
var eventType = utils.lookup(eventsSchema.types, 'id', 'events.Event');
ruleFunctionSchemas.addRules =
@@ -153,7 +151,7 @@
//
// If opt_eventOptions exists, it is a dictionary that contains the boolean
// entries "supportsListeners" and "supportsRules".
- var Event = function(opt_eventName, opt_argSchemas, opt_eventOptions) {
+ chrome.Event = function(opt_eventName, opt_argSchemas, opt_eventOptions) {
this.eventName_ = opt_eventName;
this.listeners_ = [];
this.eventOptions_ = chromeHidden.parseEventOptions(opt_eventOptions);
@@ -229,7 +227,7 @@
};
// Registers a callback to be called when this event is dispatched.
- Event.prototype.addListener = function(cb, filters) {
+ chrome.Event.prototype.addListener = function(cb, filters) {
if (!this.eventOptions_.supportsListeners)
throw new Error("This event does not support listeners.");
if (this.eventOptions_.maxListeners &&
@@ -246,7 +244,7 @@
this.listeners_.push(listener);
};
- Event.prototype.attach_ = function(listener) {
+ chrome.Event.prototype.attach_ = function(listener) {
this.attachmentStrategy_.onAddedListener(listener);
if (this.listeners_.length == 0) {
allAttachedEvents[allAttachedEvents.length] = this;
@@ -263,7 +261,7 @@
};
// Unregisters a callback.
- Event.prototype.removeListener = function(cb) {
+ chrome.Event.prototype.removeListener = function(cb) {
if (!this.eventOptions_.supportsListeners)
throw new Error("This event does not support listeners.");
var idx = this.findListener_(cb);
@@ -291,19 +289,19 @@
};
// Test if the given callback is registered for this event.
- Event.prototype.hasListener = function(cb) {
+ chrome.Event.prototype.hasListener = function(cb) {
if (!this.eventOptions_.supportsListeners)
throw new Error("This event does not support listeners.");
return this.findListener_(cb) > -1;
};
// Test if any callbacks are registered for this event.
- Event.prototype.hasListeners = function() {
+ chrome.Event.prototype.hasListeners = function() {
return this.getListenerCount() > 0;
};
// Return the number of listeners on this event.
- Event.prototype.getListenerCount = function() {
+ chrome.Event.prototype.getListenerCount = function() {
if (!this.eventOptions_.supportsListeners)
throw new Error("This event does not support listeners.");
return this.listeners_.length;
@@ -311,7 +309,7 @@
// Returns the index of the given callback if registered, or -1 if not
// found.
- Event.prototype.findListener_ = function(cb) {
+ chrome.Event.prototype.findListener_ = function(cb) {
for (var i = 0; i < this.listeners_.length; i++) {
if (this.listeners_[i].callback == cb) {
return i;
@@ -321,7 +319,7 @@
return -1;
};
- Event.prototype.dispatch_ = function(args, listenerIDs) {
+ chrome.Event.prototype.dispatch_ = function(args, listenerIDs) {
if (!this.eventOptions_.supportsListeners)
throw new Error("This event does not support listeners.");
var validationErrors = this.validateEventArgs_(args);
@@ -351,28 +349,28 @@
}
// Can be overridden to support custom dispatching.
- Event.prototype.dispatchToListener = function(callback, args) {
+ chrome.Event.prototype.dispatchToListener = function(callback, args) {
return callback.apply(null, args);
}
// Dispatches this event object to all listeners, passing all supplied
// arguments to this function each listener.
- Event.prototype.dispatch = function(varargs) {
+ chrome.Event.prototype.dispatch = function(varargs) {
return this.dispatch_(Array.prototype.slice.call(arguments), undefined);
};
// Detaches this event object from its name.
- Event.prototype.detach_ = function() {
+ chrome.Event.prototype.detach_ = function() {
this.attachmentStrategy_.detach(false);
};
- Event.prototype.destroy_ = function() {
+ chrome.Event.prototype.destroy_ = function() {
this.listeners_ = [];
this.validateEventArgs_ = [];
this.detach_(false);
};
- Event.prototype.addRules = function(rules, opt_cb) {
+ chrome.Event.prototype.addRules = function(rules, opt_cb) {
if (!this.eventOptions_.supportsRules)
throw new Error("This event does not support rules.");
@@ -422,7 +420,7 @@
ruleFunctionSchemas.addRules.parameters);
}
- Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) {
+ chrome.Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) {
if (!this.eventOptions_.supportsRules)
throw new Error("This event does not support rules.");
ensureRuleSchemasLoaded();
@@ -435,7 +433,7 @@
ruleFunctionSchemas.removeRules.parameters);
}
- Event.prototype.getRules = function(ruleIdentifiers, cb) {
+ chrome.Event.prototype.getRules = function(ruleIdentifiers, cb) {
if (!this.eventOptions_.supportsRules)
throw new Error("This event does not support rules.");
ensureRuleSchemasLoaded();
@@ -452,8 +450,8 @@
// Special load events: we don't use the DOM unload because that slows
// down tab shutdown. On the other hand, onUnload might not always fire,
// since Chrome will terminate renderers on shutdown (SuddenTermination).
- chromeHidden.onLoad = new Event();
- chromeHidden.onUnload = new Event();
+ chromeHidden.onLoad = new chrome.Event();
+ chromeHidden.onUnload = new chrome.Event();
chromeHidden.dispatchOnLoad =
chromeHidden.onLoad.dispatch.bind(chromeHidden.onLoad);
@@ -473,4 +471,4 @@
console.error(msg);
};
- chrome.Event = Event;
+ exports.Event = chrome.Event;
diff --git a/chrome/renderer/resources/extensions/experimental.media_galleries_custom_bindings.js b/chrome/renderer/resources/extensions/experimental.media_galleries_custom_bindings.js
index 8f82c4e..07b33d4 100644
--- a/chrome/renderer/resources/extensions/experimental.media_galleries_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/experimental.media_galleries_custom_bindings.js
@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the Media Gallery API.
-
-var binding = require('binding').Binding.create('experimental.mediaGalleries');
+// Custom bindings for the Media Gallery API.
var mediaGalleriesNatives = requireNative('mediaGalleries');
-binding.registerCustomHook(function(bindingsAPI, extensionId) {
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
+
+chromeHidden.registerCustomHook('experimental.mediaGalleries',
+ function(bindingsAPI, extensionId) {
var apiFunctions = bindingsAPI.apiFunctions;
// extractEmbeddedThumbnails uses a renderer side handler so that it can
@@ -19,5 +20,3 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
return mediaGalleriesNatives.ExtractEmbeddedThumbnails(fileEntry);
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/experimental.offscreenTabs_custom_bindings.js b/chrome/renderer/resources/extensions/experimental.offscreenTabs_custom_bindings.js
index 7903a3d..3635a2c 100644
--- a/chrome/renderer/resources/extensions/experimental.offscreenTabs_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/experimental.offscreenTabs_custom_bindings.js
@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the experimental offscreenTabs API.
+// Custom bindings for the experimental offscreenTabs API.
-var binding = require('binding').Binding.create('experimental.offscreenTabs');
+(function() {
-binding.registerCustomHook(
+native function GetChromeHidden();
+
+GetChromeHidden().registerCustomHook(
'experimental.offscreenTabs', function(api) {
var apiFunctions = api.apiFunctions;
@@ -58,4 +60,4 @@ binding.registerCustomHook(
function() { return validate(arguments, mouseEventFilter); });
});
-exports.binding = binding.generate();
+})();
diff --git a/chrome/renderer/resources/extensions/extension_custom_bindings.js b/chrome/renderer/resources/extensions/extension_custom_bindings.js
index 61e5e16b..60b4f12 100644
--- a/chrome/renderer/resources/extensions/extension_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/extension_custom_bindings.js
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the extension API.
-
-var binding = require('binding').Binding.create('extension');
+// Custom bindings for the extension API.
var extensionNatives = requireNative('extension');
var GetExtensionViews = extensionNatives.GetExtensionViews;
@@ -12,14 +10,22 @@ var runtimeNatives = requireNative('runtime');
var OpenChannelToExtension = runtimeNatives.OpenChannelToExtension;
var OpenChannelToNativeApp = runtimeNatives.OpenChannelToNativeApp;
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var chrome = requireNative('chrome').GetChrome();
var sendMessageUpdateArguments =
require('miscellaneous_bindings').sendMessageUpdateArguments;
var inIncognitoContext = requireNative('process').InIncognitoContext();
var sendRequestIsDisabled = requireNative('process').IsSendRequestDisabled();
var contextType = requireNative('process').GetContextType();
+
+chrome.extension = chrome.extension || {};
+
var manifestVersion = requireNative('process').GetManifestVersion();
+if (manifestVersion < 2) {
+ chrome.self = chrome.extension;
+ chrome.extension.inIncognitoTab = inIncognitoContext;
+}
+
+chrome.extension.inIncognitoContext = inIncognitoContext;
// This should match chrome.windows.WINDOW_ID_NONE.
//
@@ -28,14 +34,8 @@ var manifestVersion = requireNative('process').GetManifestVersion();
// which may not be the case.
var WINDOW_ID_NONE = -1;
-binding.registerCustomHook(function(bindingsAPI, extensionId) {
- var extension = bindingsAPI.compiledApi;
- if (manifestVersion < 2) {
- chrome.self = extension;
- extension.inIncognitoTab = inIncognitoContext;
- }
- extension.inIncognitoContext = inIncognitoContext;
-
+chromeHidden.registerCustomHook('extension',
+ function(bindingsAPI, extensionId) {
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setHandleRequest('getViews', function(properties) {
@@ -83,7 +83,7 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
// getters that throw exceptions. Assume that any getter is such a function.
if (chrome.runtime.hasOwnProperty(alias) &&
chrome.runtime.__lookupGetter__(alias) === undefined) {
- extension[alias] = chrome.runtime[alias];
+ chrome.extension[alias] = chrome.runtime[alias];
}
});
@@ -100,15 +100,14 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
});
if (sendRequestIsDisabled) {
- extension.onRequest.addListener = function() {
+ chrome.extension.onRequest.addListener = function() {
throw new Error(sendRequestIsDisabled);
};
if (contextType == 'BLESSED_EXTENSION') {
- extension.onRequestExternal.addListener = function() {
+ chrome.extension.onRequestExternal.addListener = function() {
throw new Error(sendRequestIsDisabled);
};
}
}
-});
-exports.binding = binding.generate();
+});
diff --git a/chrome/renderer/resources/extensions/file_browser_handler_custom_bindings.js b/chrome/renderer/resources/extensions/file_browser_handler_custom_bindings.js
index 1fbe7b08c..17af969 100644
--- a/chrome/renderer/resources/extensions/file_browser_handler_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/file_browser_handler_custom_bindings.js
@@ -2,16 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the fileBrowserHandler API.
-
-var binding = require('binding').Binding.create('fileBrowserHandler');
+// Custom bindings for the fileBrowserHandler API.
var fileBrowserNatives = requireNative('file_browser_handler');
var GetExternalFileEntry = fileBrowserNatives.GetExternalFileEntry;
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var fileBrowserHandlerInternal = require('binding').Binding.create(
- 'fileBrowserHandlerInternal').generate();
chromeHidden.Event.registerArgumentMassager('fileBrowserHandler.onExecute',
function(args, dispatch) {
@@ -32,7 +28,7 @@ chromeHidden.Event.registerArgumentMassager('fileBrowserHandler.onExecute',
dispatch(args);
});
-binding.registerCustomHook(function(bindingsAPI) {
+chromeHidden.registerCustomHook('fileBrowserHandler', function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setHandleRequest('selectFile',
@@ -50,9 +46,7 @@ binding.registerCustomHook(function(bindingsAPI) {
externalCallback(result);
}
- return fileBrowserHandlerInternal.selectFile(
+ return chromeHidden.internalAPIs.fileBrowserHandlerInternal.selectFile(
selectionParams, internalCallback.bind(null, callback));
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/file_browser_private_custom_bindings.js b/chrome/renderer/resources/extensions/file_browser_private_custom_bindings.js
index 10c616e..0d9369d 100644
--- a/chrome/renderer/resources/extensions/file_browser_private_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/file_browser_private_custom_bindings.js
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the fileBrowserPrivate API.
-
-var binding = require('binding').Binding.create('fileBrowserPrivate');
+// Custom bindings for the fileBrowserPrivate API.
var fileBrowserPrivateNatives = requireNative('file_browser_private');
var GetLocalFileSystem = fileBrowserPrivateNatives.GetLocalFileSystem;
@@ -12,7 +10,9 @@ var GetLocalFileSystem = fileBrowserPrivateNatives.GetLocalFileSystem;
var fileBrowserNatives = requireNative('file_browser_handler');
var GetExternalFileEntry = fileBrowserNatives.GetExternalFileEntry;
-binding.registerCustomHook(function(bindingsAPI) {
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
+
+chromeHidden.registerCustomHook('fileBrowserPrivate', function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setCustomCallback('requestLocalFileSystem',
@@ -61,5 +61,3 @@ binding.registerCustomHook(function(bindingsAPI) {
request.callback = null;
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/file_system_custom_bindings.js b/chrome/renderer/resources/extensions/file_system_custom_bindings.js
index 058a423..29e20e7 100644
--- a/chrome/renderer/resources/extensions/file_system_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/file_system_custom_bindings.js
@@ -2,19 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the fileSystem API.
-
-var binding = require('binding').Binding.create('fileSystem');
+// Custom bindings for the fileSystem API.
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var fileSystemNatives = requireNative('file_system_natives');
var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem;
var lastError = require('lastError');
var entryIdManager = require('entryIdManager');
-binding.registerCustomHook(function(bindingsAPI) {
+chromeHidden.registerCustomHook('fileSystem', function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
- var fileSystem = bindingsAPI.compiledApi;
-
function bindFileEntryFunction(functionName) {
apiFunctions.setUpdateArgumentsPostValidate(
functionName, function(fileEntry, callback) {
@@ -68,23 +65,21 @@ binding.registerCustomHook(function(bindingsAPI) {
});
// TODO(benwells): Remove these deprecated versions of the functions.
- fileSystem.getWritableFileEntry = function() {
+ chrome.fileSystem.getWritableFileEntry = function() {
console.log("chrome.fileSystem.getWritableFileEntry is deprecated");
console.log("Please use chrome.fileSystem.getWritableEntry instead");
- fileSystem.getWritableEntry.apply(this, arguments);
+ chrome.fileSystem.getWritableEntry.apply(this, arguments);
};
- fileSystem.isWritableFileEntry = function() {
+ chrome.fileSystem.isWritableFileEntry = function() {
console.log("chrome.fileSystem.isWritableFileEntry is deprecated");
console.log("Please use chrome.fileSystem.isWritableEntry instead");
- fileSystem.isWritableEntry.apply(this, arguments);
+ chrome.fileSystem.isWritableEntry.apply(this, arguments);
};
- fileSystem.chooseFile = function() {
+ chrome.fileSystem.chooseFile = function() {
console.log("chrome.fileSystem.chooseFile is deprecated");
console.log("Please use chrome.fileSystem.chooseEntry instead");
- fileSystem.chooseEntry.apply(this, arguments);
+ chrome.fileSystem.chooseEntry.apply(this, arguments);
};
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/i18n_custom_bindings.js b/chrome/renderer/resources/extensions/i18n_custom_bindings.js
index 39f5a7d..14120af 100644
--- a/chrome/renderer/resources/extensions/i18n_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/i18n_custom_bindings.js
@@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the i18n API.
-
-var binding = require('binding').Binding.create('i18n');
+// Custom bindings for the i18n API.
var i18nNatives = requireNative('i18n');
var GetL10nMessage = i18nNatives.GetL10nMessage;
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-binding.registerCustomHook(function(bindingsAPI, extensionId) {
+chromeHidden.registerCustomHook('i18n', function(bindingsAPI, extensionId) {
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setUpdateArgumentsPreValidate('getMessage', function() {
@@ -34,5 +32,3 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
return GetL10nMessage(messageName, substitutions, extensionId);
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/input.ime_custom_bindings.js b/chrome/renderer/resources/extensions/input.ime_custom_bindings.js
index 79ab4a3..60b0105 100644
--- a/chrome/renderer/resources/extensions/input.ime_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/input.ime_custom_bindings.js
@@ -2,15 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the input ime API. Only injected into the
+// Custom bindings for the input ime API. Only injected into the
// v8 contexts for extensions which have permission for the API.
-var binding = require('binding').Binding.create('input.ime');
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-binding.registerCustomHook(function(api) {
- var input_ime = api.compiledApi;
-
- input_ime.onKeyEvent.dispatchToListener = function(callback, args) {
+chromeHidden.registerCustomHook('input.ime', function() {
+ chrome.input.ime.onKeyEvent.dispatchToListener = function(callback, args) {
var engineID = args[0];
var keyData = args[1];
@@ -20,21 +18,19 @@ binding.registerCustomHook(function(api) {
} catch (e) {
console.error('Error in event handler for onKeyEvent: ' + e.stack);
}
- if (!input_ime.onKeyEvent.async)
- input_ime.keyEventHandled(keyData.requestId, result);
+ if (!chrome.input.ime.onKeyEvent.async)
+ chrome.input.ime.keyEventHandled(keyData.requestId, result);
};
- input_ime.onKeyEvent.addListener = function(cb, opt_extraInfo) {
- input_ime.onKeyEvent.async = false;
+ chrome.input.ime.onKeyEvent.addListener = function(cb, opt_extraInfo) {
+ chrome.input.ime.onKeyEvent.async = false;
if (opt_extraInfo instanceof Array) {
for (var i = 0; i < opt_extraInfo.length; ++i) {
if (opt_extraInfo[i] == "async") {
- input_ime.onKeyEvent.async = true;
+ chrome.input.ime.onKeyEvent.async = true;
}
}
}
chrome.Event.prototype.addListener.call(this, cb, null);
};
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/json_schema.js b/chrome/renderer/resources/extensions/json_schema.js
index 44ea2a06..414356c 100644
--- a/chrome/renderer/resources/extensions/json_schema.js
+++ b/chrome/renderer/resources/extensions/json_schema.js
@@ -38,9 +38,7 @@
// additional properties will be validated.
//==============================================================================
-// TODO(cduvall): Make this file not depend on chromeHidden.
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var loadRefDependency = require('utils').loadRefDependency;
function isInstanceOfClass(instance, className) {
if (!instance)
@@ -242,7 +240,6 @@ chromeHidden.JSONSchemaValidator.prototype.validate =
// If the schema has a $ref property, the instance must validate against
// that schema too. It must be present in this.types to be referenced.
if (schema["$ref"]) {
- loadRefDependency(schema["$ref"]);
if (!this.types[schema["$ref"]])
this.addError(path, "unknownSchemaReference", [ schema["$ref"] ]);
else
diff --git a/chrome/renderer/resources/extensions/last_error.js b/chrome/renderer/resources/extensions/last_error.js
index 5eb5c01..2b38a29 100644
--- a/chrome/renderer/resources/extensions/last_error.js
+++ b/chrome/renderer/resources/extensions/last_error.js
@@ -3,17 +3,16 @@
// found in the LICENSE file.
requireNative('runtime');
-var GetAvailability = requireNative('v8_context').GetAvailability;
function set(message) {
var errorObject = { 'message': message };
- if (GetAvailability('extension').is_available)
+ if (chrome.extension)
chrome.extension.lastError = errorObject;
chrome.runtime.lastError = errorObject;
};
function clear() {
- if (GetAvailability('extension').is_available)
+ if (chrome.extension)
delete chrome.extension.lastError;
delete chrome.runtime.lastError;
};
diff --git a/chrome/renderer/resources/extensions/media_galleries_custom_bindings.js b/chrome/renderer/resources/extensions/media_galleries_custom_bindings.js
index 60ac567..f1f9edfe 100644
--- a/chrome/renderer/resources/extensions/media_galleries_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/media_galleries_custom_bindings.js
@@ -2,15 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the Media Gallery API.
-
-var binding = require('binding').Binding.create('mediaGalleries');
+// Custom bindings for the Media Gallery API.
var mediaGalleriesNatives = requireNative('mediaGalleries');
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
+
var mediaGalleriesMetadata = {};
-binding.registerCustomHook(function(bindingsAPI, extensionId) {
+chromeHidden.registerCustomHook('mediaGalleries',
+ function(bindingsAPI, extensionId) {
var apiFunctions = bindingsAPI.apiFunctions;
// getMediaFileSystems uses a custom callback so that it can instantiate and
@@ -47,5 +48,3 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
return {};
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/miscellaneous_bindings.js b/chrome/renderer/resources/extensions/miscellaneous_bindings.js
index e1469f8..147528c 100644
--- a/chrome/renderer/resources/extensions/miscellaneous_bindings.js
+++ b/chrome/renderer/resources/extensions/miscellaneous_bindings.js
@@ -8,10 +8,10 @@
// content scripts only.
require('json_schema');
+ require('event_bindings');
var json = require('json');
var lastError = require('lastError');
var miscNatives = requireNative('miscellaneous_bindings');
- var chrome = requireNative('chrome').GetChrome();
var CloseChannel = miscNatives.CloseChannel;
var PortAddRef = miscNatives.PortAddRef;
var PortRelease = miscNatives.PortRelease;
diff --git a/chrome/renderer/resources/extensions/notification_custom_bindings.js b/chrome/renderer/resources/extensions/notification_custom_bindings.js
index 0e2cd13..b88be09 100644
--- a/chrome/renderer/resources/extensions/notification_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/notification_custom_bindings.js
@@ -4,12 +4,10 @@
// Custom bindings for the notification API.
-var binding = require('binding').Binding.create('experimental.notification');
-
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var sendRequest = require('sendRequest').sendRequest;
var imageUtil = require('imageUtil');
var lastError = require('lastError');
-var json = require('json');
function url_getter(context, key) {
var f = function() {
@@ -101,8 +99,8 @@ function genHandle(failure_function) {
return function(id, input_notification_details, callback) {
// TODO(dewittj): Remove this hack. This is used as a way to deep
// copy a complex JSON object.
- var notification_details = json.parse(
- json.stringify(input_notification_details));
+ var notification_details = JSON.parse(
+ JSON.stringify(input_notification_details));
var that = this;
replaceNotificationOptionURLs(notification_details, function(success) {
if (success) {
@@ -126,6 +124,5 @@ var experimentalNotificationCustomHook = function(bindingsAPI, extensionId) {
apiFunctions.setHandleRequest('update', handleCreate);
};
-binding.registerCustomHook(experimentalNotificationCustomHook);
-
-exports.binding = binding.generate();
+chromeHidden.registerCustomHook('experimental.notification',
+ experimentalNotificationCustomHook);
diff --git a/chrome/renderer/resources/extensions/omnibox_custom_bindings.js b/chrome/renderer/resources/extensions/omnibox_custom_bindings.js
index fa0ced3..04ae181 100644
--- a/chrome/renderer/resources/extensions/omnibox_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/omnibox_custom_bindings.js
@@ -2,11 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the omnibox API. Only injected into the v8 contexts
+// Custom bindings for the omnibox API. Only injected into the v8 contexts
// for extensions which have permission for the omnibox API.
-var binding = require('binding').Binding.create('omnibox');
-
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var sendRequest = require('sendRequest').sendRequest;
@@ -81,7 +79,7 @@ function parseOmniboxDescription(input) {
return result;
}
-binding.registerCustomHook(function(bindingsAPI) {
+chromeHidden.registerCustomHook('omnibox', function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setHandleRequest('setDefaultSuggestion', function(details) {
@@ -111,5 +109,3 @@ chromeHidden.Event.registerArgumentMassager('omnibox.onInputChanged',
};
dispatch([text, suggestCallback]);
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/page_action_custom_bindings.js b/chrome/renderer/resources/extensions/page_action_custom_bindings.js
index 97a308e..b527374 100644
--- a/chrome/renderer/resources/extensions/page_action_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/page_action_custom_bindings.js
@@ -2,13 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the pageAction API.
-
-var binding = require('binding').Binding.create('pageAction');
+// Custom bindings for the pageAction API.
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var setIcon = require('setIcon').setIcon;
-binding.registerCustomHook(function(bindingsAPI) {
+chromeHidden.registerCustomHook('pageAction', function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setHandleRequest('setIcon', function(details, callback) {
@@ -16,5 +15,3 @@ binding.registerCustomHook(function(bindingsAPI) {
'page action');
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/page_actions_custom_bindings.js b/chrome/renderer/resources/extensions/page_actions_custom_bindings.js
index 0b72e07..d5ec888 100644
--- a/chrome/renderer/resources/extensions/page_actions_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/page_actions_custom_bindings.js
@@ -2,21 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the pageActions API.
-
-var binding = require('binding').Binding.create('pageActions');
+// Custom bindings for the pageActions API.
var pageActionsNatives = requireNative('page_actions');
var GetCurrentPageActions = pageActionsNatives.GetCurrentPageActions;
-binding.registerCustomHook(function(bindingsAPI, extensionId) {
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
+
+chromeHidden.registerCustomHook('pageActions',
+ function(bindingsAPI, extensionId) {
var pageActions = GetCurrentPageActions(extensionId);
- var pageActionsApi = bindingsAPI.compiledApi;
var oldStyleEventName = 'pageActions';
for (var i = 0; i < pageActions.length; ++i) {
// Setup events for each extension_id/page_action_id string we find.
- pageActionsApi[pageActions[i]] = new chrome.Event(oldStyleEventName);
+ chrome.pageActions[pageActions[i]] = new chrome.Event(oldStyleEventName);
}
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/page_capture_custom_bindings.js b/chrome/renderer/resources/extensions/page_capture_custom_bindings.js
index f9147d7..15b82f9 100644
--- a/chrome/renderer/resources/extensions/page_capture_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/page_capture_custom_bindings.js
@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the pageCapture API.
-
-var binding = require('binding').Binding.create('pageCapture');
+// Custom bindings for the pageCapture API.
var pageCaptureNatives = requireNative('page_capture');
var CreateBlob = pageCaptureNatives.CreateBlob;
var SendResponseAck = pageCaptureNatives.SendResponseAck;
-binding.registerCustomHook(function(bindingsAPI) {
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
+
+chromeHidden.registerCustomHook('pageCapture', function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setCustomCallback('saveAsMHTML',
@@ -27,5 +27,3 @@ binding.registerCustomHook(function(bindingsAPI) {
SendResponseAck(request.id);
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/permissions_custom_bindings.js b/chrome/renderer/resources/extensions/permissions_custom_bindings.js
index e728080..b32a57d 100644
--- a/chrome/renderer/resources/extensions/permissions_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/permissions_custom_bindings.js
@@ -2,23 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the Permissions API.
-
-var binding = require('binding').Binding.create('permissions');
+// Custom bindings for the Permissions API.
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var sendRequest = require('sendRequest').sendRequest;
var lastError = require('lastError');
-// These custom binding are only necessary because it is not currently
+// These custom bindings are only necessary because it is not currently
// possible to have a union of types as the type of the items in an array.
// Once that is fixed, this entire file should go away.
// See,
// https://code.google.com/p/chromium/issues/detail?id=162044
// https://code.google.com/p/chromium/issues/detail?id=162042
// TODO(bryeung): delete this file.
-binding.registerCustomHook(function(api) {
+chromeHidden.registerCustomHook('permissions', function(api) {
var apiFunctions = api.apiFunctions;
- var permissions = api.compiledApi;
function maybeConvertToObject(str) {
var parts = str.split('|');
@@ -82,14 +80,12 @@ binding.registerCustomHook(function(api) {
// dispatchToListener call happens after argument validation, which works
// around the problem that Permissions.permissions is supposed to be a list
// of strings.
- permissions.onAdded.dispatchToListener = function(callback, args) {
+ chrome.permissions.onAdded.dispatchToListener = function(callback, args) {
for (var i = 0; i < args[0].permissions.length; i += 1) {
args[0].permissions[i] = maybeConvertToObject(args[0].permissions[i]);
}
chrome.Event.prototype.dispatchToListener(callback, args);
};
- permissions.onRemoved.dispatchToListener =
- permissions.onAdded.dispatchToListener;
+ chrome.permissions.onRemoved.dispatchToListener =
+ chrome.permissions.onAdded.dispatchToListener;
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/runtime_custom_bindings.js b/chrome/renderer/resources/extensions/runtime_custom_bindings.js
index 61be155..91d402b 100644
--- a/chrome/renderer/resources/extensions/runtime_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/runtime_custom_bindings.js
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the runtime API.
-
-var binding = require('binding').Binding.create('runtime');
+// Custom bindings for the runtime API.
var runtimeNatives = requireNative('runtime');
var extensionNatives = requireNative('extension');
@@ -15,15 +13,14 @@ var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var sendMessageUpdateArguments =
require('miscellaneous_bindings').sendMessageUpdateArguments;
-binding.registerCustomHook(function(binding, id, contextType) {
- var apiFunctions = binding.apiFunctions;
- var runtime = binding.compiledApi;
+chromeHidden.registerCustomHook('runtime', function(bindings, id, contextType) {
+ var apiFunctions = bindings.apiFunctions;
//
// Unprivileged APIs.
//
- runtime.id = id;
+ chrome.runtime.id = id;
apiFunctions.setHandleRequest('getManifest', function() {
return runtimeNatives.GetManifest();
@@ -43,14 +40,14 @@ binding.registerCustomHook(function(binding, id, contextType) {
apiFunctions.setHandleRequest('sendMessage',
function(targetId, message, responseCallback) {
- var port = runtime.connect(targetId || runtime.id,
+ var port = chrome.runtime.connect(targetId || chrome.runtime.id,
{name: chromeHidden.kMessageChannel});
chromeHidden.Port.sendMessageImpl(port, message, responseCallback);
});
apiFunctions.setHandleRequest('sendNativeMessage',
function(targetId, message, responseCallback) {
- var port = runtime.connectNative(targetId);
+ var port = chrome.runtime.connectNative(targetId);
chromeHidden.Port.sendMessageImpl(port, message, responseCallback);
});
@@ -86,7 +83,7 @@ binding.registerCustomHook(function(binding, id, contextType) {
apiFunctions.setHandleRequest('connect', function(targetId, connectInfo) {
if (!targetId)
- targetId = runtime.id;
+ targetId = chrome.runtime.id;
var name = '';
if (connectInfo && connectInfo.name)
name = connectInfo.name;
@@ -94,7 +91,7 @@ binding.registerCustomHook(function(binding, id, contextType) {
// Don't let orphaned content scripts communicate with their extension.
// http://crbug.com/168263
if (!chromeHidden.wasUnloaded) {
- var portId = OpenChannelToExtension(runtime.id, targetId, name);
+ var portId = OpenChannelToExtension(chrome.runtime.id, targetId, name);
if (portId >= 0)
return chromeHidden.Port.createPort(portId, name);
}
@@ -110,7 +107,7 @@ binding.registerCustomHook(function(binding, id, contextType) {
apiFunctions.setHandleRequest('connectNative',
function(nativeAppName) {
if (!chromeHidden.wasUnloaded) {
- var portId = OpenChannelToNativeApp(runtime.id, nativeAppName);
+ var portId = OpenChannelToNativeApp(chrome.runtime.id, nativeAppName);
if (portId >= 0)
return chromeHidden.Port.createPort(portId, '');
}
@@ -127,5 +124,3 @@ binding.registerCustomHook(function(binding, id, contextType) {
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/schema_generated_bindings.js b/chrome/renderer/resources/extensions/schema_generated_bindings.js
new file mode 100644
index 0000000..65d5cad
--- /dev/null
+++ b/chrome/renderer/resources/extensions/schema_generated_bindings.js
@@ -0,0 +1,437 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Generates the chrome.* API bindings from a list of schemas.
+
+ // TODO(battre): cleanup the usage of packages everywhere, as described here
+ // http://codereview.chromium.org/10392008/diff/38/chrome/renderer/resources/extensions/schema_generated_bindings.js
+
+ require('json_schema');
+ require('event_bindings');
+ var GetExtensionAPIDefinition =
+ requireNative('apiDefinitions').GetExtensionAPIDefinition;
+ var sendRequest = require('sendRequest').sendRequest;
+ var utils = require('utils');
+ var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
+ var schemaUtils = require('schemaUtils');
+
+ // The object to generate the bindings for "internal" APIs in, so that
+ // extensions can't directly call them (without access to chromeHidden),
+ // but are still needed for internal mechanisms of extensions (e.g. events).
+ //
+ // This is distinct to the "*Private" APIs which are controlled via
+ // having strict permissions and aren't generated *anywhere* unless needed.
+ var internalAPIs = {};
+ chromeHidden.internalAPIs = internalAPIs;
+
+ // Stores the name and definition of each API function, with methods to
+ // modify their behaviour (such as a custom way to handle requests to the
+ // API, a custom callback, etc).
+ function APIFunctions() {
+ this._apiFunctions = {};
+ this._unavailableApiFunctions = {};
+ }
+ APIFunctions.prototype.register = function(apiName, apiFunction) {
+ this._apiFunctions[apiName] = apiFunction;
+ };
+ // Registers a function as existing but not available, meaning that calls to
+ // the set* methods that reference this function should be ignored rather
+ // than throwing Errors.
+ APIFunctions.prototype.registerUnavailable = function(apiName) {
+ this._unavailableApiFunctions[apiName] = apiName;
+ };
+ APIFunctions.prototype._setHook =
+ function(apiName, propertyName, customizedFunction) {
+ if (this._unavailableApiFunctions.hasOwnProperty(apiName))
+ return;
+ if (!this._apiFunctions.hasOwnProperty(apiName))
+ throw new Error('Tried to set hook for unknown API "' + apiName + '"');
+ this._apiFunctions[apiName][propertyName] = customizedFunction;
+ };
+ APIFunctions.prototype.setHandleRequest =
+ function(apiName, customizedFunction) {
+ return this._setHook(apiName, 'handleRequest', customizedFunction);
+ };
+ APIFunctions.prototype.setUpdateArgumentsPostValidate =
+ function(apiName, customizedFunction) {
+ return this._setHook(
+ apiName, 'updateArgumentsPostValidate', customizedFunction);
+ };
+ APIFunctions.prototype.setUpdateArgumentsPreValidate =
+ function(apiName, customizedFunction) {
+ return this._setHook(
+ apiName, 'updateArgumentsPreValidate', customizedFunction);
+ };
+ APIFunctions.prototype.setCustomCallback =
+ function(apiName, customizedFunction) {
+ return this._setHook(apiName, 'customCallback', customizedFunction);
+ };
+
+ var apiFunctions = new APIFunctions();
+
+ // Wraps the calls to the set* methods of APIFunctions with the namespace of
+ // an API, and validates that all calls to set* methods aren't prefixed with
+ // a namespace.
+ //
+ // For example, if constructed with 'browserAction', a call to
+ // handleRequest('foo') will be transformed into
+ // handleRequest('browserAction.foo').
+ //
+ // Likewise, if a call to handleRequest is called with 'browserAction.foo',
+ // it will throw an error.
+ //
+ // These help with isolating custom bindings from each other.
+ function NamespacedAPIFunctions(namespace, delegate) {
+ var self = this;
+ function wrap(methodName) {
+ self[methodName] = function(apiName, customizedFunction) {
+ var prefix = namespace + '.';
+ if (apiName.indexOf(prefix) === 0) {
+ throw new Error(methodName + ' called with "' + apiName +
+ '" which has a "' + prefix + '" prefix. ' +
+ 'This is unnecessary and must be left out.');
+ }
+ return delegate[methodName].call(delegate,
+ prefix + apiName, customizedFunction);
+ };
+ }
+
+ wrap('contains');
+ wrap('setHandleRequest');
+ wrap('setUpdateArgumentsPostValidate');
+ wrap('setUpdateArgumentsPreValidate');
+ wrap('setCustomCallback');
+ }
+
+ //
+ // The API through which the ${api_name}_custom_bindings.js files customize
+ // their API bindings beyond what can be generated.
+ //
+ // There are 2 types of customizations available: those which are required in
+ // order to do the schema generation (registerCustomEvent and
+ // registerCustomType), and those which can only run after the bindings have
+ // been generated (registerCustomHook).
+ //
+
+ // Registers a custom event type for the API identified by |namespace|.
+ // |event| is the event's constructor.
+ var customEvents = {};
+ chromeHidden.registerCustomEvent = function(namespace, event) {
+ if (typeof(namespace) !== 'string') {
+ throw new Error("registerCustomEvent requires the namespace of the " +
+ "API as its first argument");
+ }
+ customEvents[namespace] = event;
+ };
+
+ // Registers a function |hook| to run after the schema for all APIs has been
+ // generated. The hook is passed as its first argument an "API" object to
+ // interact with, and second the current extension ID. See where
+ // |customHooks| is used.
+ var customHooks = {};
+ chromeHidden.registerCustomHook = function(namespace, fn) {
+ if (typeof(namespace) !== 'string') {
+ throw new Error("registerCustomHook requires the namespace of the " +
+ "API as its first argument");
+ }
+ customHooks[namespace] = fn;
+ };
+
+ function CustomBindingsObject() {
+ }
+ CustomBindingsObject.prototype.setSchema = function(schema) {
+ // The functions in the schema are in list form, so we move them into a
+ // dictionary for easier access.
+ var self = this;
+ self.functionSchemas = {};
+ schema.functions.forEach(function(f) {
+ self.functionSchemas[f.name] = {
+ name: f.name,
+ definition: f
+ }
+ });
+ };
+
+ // Registers a custom type referenced via "$ref" fields in the API schema
+ // JSON.
+ var customTypes = {};
+ chromeHidden.registerCustomType = function(typeName, customTypeFactory) {
+ var customType = customTypeFactory();
+ customType.prototype = new CustomBindingsObject();
+ customTypes[typeName] = customType;
+ };
+
+ // Get the platform from navigator.appVersion.
+ function getPlatform() {
+ var platforms = [
+ [/CrOS Touch/, "chromeos touch"],
+ [/CrOS/, "chromeos"],
+ [/Linux/, "linux"],
+ [/Mac/, "mac"],
+ [/Win/, "win"],
+ ];
+
+ for (var i = 0; i < platforms.length; i++) {
+ if (platforms[i][0].test(navigator.appVersion)) {
+ return platforms[i][1];
+ }
+ }
+ return "unknown";
+ }
+
+ function isPlatformSupported(schemaNode, platform) {
+ return !schemaNode.platforms ||
+ schemaNode.platforms.indexOf(platform) > -1;
+ }
+
+ function isManifestVersionSupported(schemaNode, manifestVersion) {
+ return !schemaNode.maximumManifestVersion ||
+ manifestVersion <= schemaNode.maximumManifestVersion;
+ }
+
+ function isSchemaNodeSupported(schemaNode, platform, manifestVersion) {
+ return isPlatformSupported(schemaNode, platform) &&
+ isManifestVersionSupported(schemaNode, manifestVersion);
+ }
+
+ chromeHidden.onLoad.addListener(function(extensionId,
+ contextType,
+ isIncognitoProcess,
+ manifestVersion) {
+ var apiDefinitions = GetExtensionAPIDefinition();
+
+ // Read api definitions and setup api functions in the chrome namespace.
+ var platform = getPlatform();
+
+ apiDefinitions.forEach(function(apiDef) {
+ // TODO(kalman): Remove this, or refactor schema_generated_bindings.js so
+ // that it isn't necessary. For now, chrome.app and chrome.webstore are
+ // entirely handwritten.
+ if (['app', 'webstore'].indexOf(apiDef.namespace) >= 0)
+ return;
+
+ if (!isSchemaNodeSupported(apiDef, platform, manifestVersion))
+ return;
+
+ // See comment on internalAPIs at the top.
+ var mod = apiDef.internal ? internalAPIs : chrome;
+
+ var namespaces = apiDef.namespace.split('.');
+ for (var index = 0, name; name = namespaces[index]; index++) {
+ mod[name] = mod[name] || {};
+ mod = mod[name];
+ }
+
+ // Add types to global schemaValidator
+ if (apiDef.types) {
+ apiDef.types.forEach(function(t) {
+ if (!isSchemaNodeSupported(t, platform, manifestVersion))
+ return;
+
+ schemaUtils.schemaValidator.addTypes(t);
+ if (t.type == 'object' && customTypes[t.id]) {
+ customTypes[t.id].prototype.setSchema(t);
+ }
+ });
+ }
+
+ // Returns whether access to the content of a schema should be denied,
+ // based on the presence of "unprivileged" and whether this is an
+ // extension process (versus e.g. a content script).
+ function isSchemaAccessAllowed(itemSchema) {
+ return (contextType == 'BLESSED_EXTENSION') ||
+ apiDef.unprivileged ||
+ itemSchema.unprivileged;
+ }
+
+ // Adds a getter that throws an access denied error to object |mod|
+ // for property |name|.
+ function addUnprivilegedAccessGetter(mod, name) {
+ mod.__defineGetter__(name, function() {
+ throw new Error(
+ '"' + name + '" can only be used in extension processes. See ' +
+ 'the content scripts documentation for more details.');
+ });
+ }
+
+ // Setup Functions.
+ if (apiDef.functions) {
+ apiDef.functions.forEach(function(functionDef) {
+ if (functionDef.name in mod) {
+ throw new Error('Function ' + functionDef.name +
+ ' already defined in ' + apiDef.namespace);
+ }
+
+ var apiFunctionName = apiDef.namespace + "." + functionDef.name;
+
+ if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) {
+ apiFunctions.registerUnavailable(apiFunctionName);
+ return;
+ }
+ if (!isSchemaAccessAllowed(functionDef)) {
+ apiFunctions.registerUnavailable(apiFunctionName);
+ addUnprivilegedAccessGetter(mod, functionDef.name);
+ return;
+ }
+
+ var apiFunction = {};
+ apiFunction.definition = functionDef;
+ apiFunction.name = apiFunctionName;
+
+ // TODO(aa): It would be best to run this in a unit test, but in order
+ // to do that we would need to better factor this code so that it
+ // doesn't depend on so much v8::Extension machinery.
+ if (chromeHidden.validateAPI &&
+ schemaUtils.isFunctionSignatureAmbiguous(
+ apiFunction.definition)) {
+ throw new Error(
+ apiFunction.name + ' has ambiguous optional arguments. ' +
+ 'To implement custom disambiguation logic, add ' +
+ '"allowAmbiguousOptionalArguments" to the function\'s schema.');
+ }
+
+ apiFunctions.register(apiFunction.name, apiFunction);
+
+ mod[functionDef.name] = (function() {
+ var args = Array.prototype.slice.call(arguments);
+ if (this.updateArgumentsPreValidate)
+ args = this.updateArgumentsPreValidate.apply(this, args);
+
+ args = schemaUtils.normalizeArgumentsAndValidate(args, this);
+ if (this.updateArgumentsPostValidate)
+ args = this.updateArgumentsPostValidate.apply(this, args);
+
+ var retval;
+ if (this.handleRequest) {
+ retval = this.handleRequest.apply(this, args);
+ } else {
+ var optArgs = {
+ customCallback: this.customCallback
+ };
+ retval = sendRequest(this.name, args,
+ this.definition.parameters,
+ optArgs);
+ }
+
+ // Validate return value if defined - only in debug.
+ if (chromeHidden.validateCallbacks &&
+ this.definition.returns) {
+ schemaUtils.validate([retval], [this.definition.returns]);
+ }
+ return retval;
+ }).bind(apiFunction);
+ });
+ }
+
+ // Setup Events
+ if (apiDef.events) {
+ apiDef.events.forEach(function(eventDef) {
+ if (eventDef.name in mod) {
+ throw new Error('Event ' + eventDef.name +
+ ' already defined in ' + apiDef.namespace);
+ }
+ if (!isSchemaNodeSupported(eventDef, platform, manifestVersion))
+ return;
+ if (!isSchemaAccessAllowed(eventDef)) {
+ addUnprivilegedAccessGetter(mod, eventDef.name);
+ return;
+ }
+
+ var eventName = apiDef.namespace + "." + eventDef.name;
+ var customEvent = customEvents[apiDef.namespace];
+ var options = eventDef.options || {};
+
+ if (eventDef.filters && eventDef.filters.length > 0)
+ options.supportsFilters = true;
+
+ if (customEvent) {
+ mod[eventDef.name] = new customEvent(
+ eventName, eventDef.parameters, eventDef.extraParameters,
+ options);
+ } else if (eventDef.anonymous) {
+ mod[eventDef.name] = new chrome.Event();
+ } else {
+ mod[eventDef.name] = new chrome.Event(
+ eventName, eventDef.parameters, options);
+ }
+ });
+ }
+
+ function addProperties(m, parentDef) {
+ var properties = parentDef.properties;
+ if (!properties)
+ return;
+
+ utils.forEach(properties, function(propertyName, propertyDef) {
+ if (propertyName in m)
+ return; // TODO(kalman): be strict like functions/events somehow.
+ if (!isSchemaNodeSupported(propertyDef, platform, manifestVersion))
+ return;
+ if (!isSchemaAccessAllowed(propertyDef)) {
+ addUnprivilegedAccessGetter(m, propertyName);
+ return;
+ }
+
+ var value = propertyDef.value;
+ if (value) {
+ // Values may just have raw types as defined in the JSON, such
+ // as "WINDOW_ID_NONE": { "value": -1 }. We handle this here.
+ // TODO(kalman): enforce that things with a "value" property can't
+ // define their own types.
+ var type = propertyDef.type || typeof(value);
+ if (type === 'integer' || type === 'number') {
+ value = parseInt(value);
+ } else if (type === 'boolean') {
+ value = value === "true";
+ } else if (propertyDef["$ref"]) {
+ var constructor = customTypes[propertyDef["$ref"]];
+ if (!constructor)
+ throw new Error("No custom binding for " + propertyDef["$ref"]);
+ var args = value;
+ // For an object propertyDef, |value| is an array of constructor
+ // arguments, but we want to pass the arguments directly (i.e.
+ // not as an array), so we have to fake calling |new| on the
+ // constructor.
+ value = { __proto__: constructor.prototype };
+ constructor.apply(value, args);
+ // Recursively add properties.
+ addProperties(value, propertyDef);
+ } else if (type === 'object') {
+ // Recursively add properties.
+ addProperties(value, propertyDef);
+ } else if (type !== 'string') {
+ throw new Error("NOT IMPLEMENTED (extension_api.json error): " +
+ "Cannot parse values for type \"" + type + "\"");
+ }
+ m[propertyName] = value;
+ }
+ });
+ }
+
+ addProperties(mod, apiDef);
+ });
+
+ // Run the non-declarative custom hooks after all the schemas have been
+ // generated, in case hooks depend on other APIs being available.
+ apiDefinitions.forEach(function(apiDef) {
+ if (!isSchemaNodeSupported(apiDef, platform, manifestVersion))
+ return;
+
+ var hook = customHooks[apiDef.namespace];
+ if (!hook)
+ return;
+
+ // Pass through the public API of schema_generated_bindings, to be used
+ // by custom bindings JS files. Create a new one so that bindings can't
+ // interfere with each other.
+ hook({
+ apiFunctions: new NamespacedAPIFunctions(apiDef.namespace,
+ apiFunctions),
+ apiDefinitions: apiDefinitions,
+ }, extensionId, contextType);
+ });
+
+ if (chrome.test)
+ chrome.test.getApiDefinitions = GetExtensionAPIDefinition;
+ });
diff --git a/chrome/renderer/resources/extensions/schema_utils.js b/chrome/renderer/resources/extensions/schema_utils.js
index 31531f9..8cd0212 100644
--- a/chrome/renderer/resources/extensions/schema_utils.js
+++ b/chrome/renderer/resources/extensions/schema_utils.js
@@ -5,7 +5,6 @@
// Routines used to validate and normalize arguments.
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var chrome = requireNative('chrome').GetChrome();
// TODO(benwells): unit test this file.
// JSONSchemaValidator is not loaded in unit tests.
diff --git a/chrome/renderer/resources/extensions/send_request.js b/chrome/renderer/resources/extensions/send_request.js
index 1e5746f..d689a5b 100644
--- a/chrome/renderer/resources/extensions/send_request.js
+++ b/chrome/renderer/resources/extensions/send_request.js
@@ -3,7 +3,6 @@
// found in the LICENSE file.
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var DCHECK = requireNative('logging').DCHECK;
var json = require('json');
var lastError = require('lastError');
var natives = requireNative('sendRequest');
@@ -15,7 +14,6 @@ chromeHidden.handleResponse = function(requestId, name,
success, responseList, error) {
try {
var request = requests[requestId];
- DCHECK(request != null);
if (success) {
lastError.clear();
} else {
@@ -34,7 +32,7 @@ chromeHidden.handleResponse = function(requestId, name,
if (request.callback) {
// Validate callback in debug only -- and only when the
// caller has provided a callback. Implementations of api
- // calls may not return data if they observe the caller
+ // calls my not return data if they observe the caller
// has not provided a callback.
if (chromeHidden.validateCallbacks && !error) {
try {
diff --git a/chrome/renderer/resources/extensions/storage_custom_bindings.js b/chrome/renderer/resources/extensions/storage_custom_bindings.js
index 869a555..d230099 100644
--- a/chrome/renderer/resources/extensions/storage_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/storage_custom_bindings.js
@@ -2,15 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the storage API.
-
-var binding = require('binding').Binding.create('storage');
+// Custom bindings for the storage API.
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var normalizeArgumentsAndValidate =
require('schemaUtils').normalizeArgumentsAndValidate
var sendRequest = require('sendRequest').sendRequest;
-binding.registerCustomType('storage.StorageArea', function() {
+chromeHidden.registerCustomType('storage.StorageArea', function() {
function extendSchema(schema) {
var extendedSchema = schema.slice();
extendedSchema.unshift({'type': 'string'});
@@ -22,7 +21,7 @@ binding.registerCustomType('storage.StorageArea', function() {
// storage.sync.get('foo') -> (binds to) ->
// storage.get('sync', 'foo').
//
- // TODO(kalman): Put as a method on CustombindingObject and re-use (or
+ // TODO(kalman): Put as a method on CustomBindingsObject and re-use (or
// even generate) for other APIs that need to do this. Same for other
// callers of registerCustomType().
var self = this;
@@ -44,5 +43,3 @@ binding.registerCustomType('storage.StorageArea', function() {
return StorageArea;
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/sync_file_system_custom_bindings.js b/chrome/renderer/resources/extensions/sync_file_system_custom_bindings.js
index bcb1219..03c6caa 100644
--- a/chrome/renderer/resources/extensions/sync_file_system_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/sync_file_system_custom_bindings.js
@@ -2,15 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the syncFileSystem API.
-
-var binding = require('binding').Binding.create('syncFileSystem');
+// Custom bindings for the syncFileSystem API.
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var fileSystemNatives = requireNative('file_system_natives');
var syncFileSystemNatives = requireNative('sync_file_system');
-binding.registerCustomHook(function(bindingsAPI) {
+chromeHidden.registerCustomHook('syncFileSystem', function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
// Functions which take in an [instanceOf=FileEntry].
@@ -69,5 +67,3 @@ chromeHidden.Event.registerArgumentMassager(
}
dispatch([fileInfo]);
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/system_indicator_custom_bindings.js b/chrome/renderer/resources/extensions/system_indicator_custom_bindings.js
index 0551a83..0d58de1 100644
--- a/chrome/renderer/resources/extensions/system_indicator_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/system_indicator_custom_bindings.js
@@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the systemIndicator API.
-// TODO(dewittj) Refactor custom binding to reduce redundancy between the
+// Custom bindings for the systemIndicator API.
+// TODO(dewittj) Refactor custom bindings to reduce redundancy between the
// extension action APIs.
-var binding = require('binding').Binding.create('systemIndicator');
-
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var setIcon = require('setIcon').setIcon;
-binding.registerCustomHook(function(bindingsAPI) {
+chromeHidden.registerCustomHook('systemIndicator', function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setHandleRequest('setIcon', function(details, callback) {
@@ -20,4 +18,3 @@ binding.registerCustomHook(function(bindingsAPI) {
});
});
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/tab_capture_custom_bindings.js b/chrome/renderer/resources/extensions/tab_capture_custom_bindings.js
index a75d36d..f458a2f 100644
--- a/chrome/renderer/resources/extensions/tab_capture_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/tab_capture_custom_bindings.js
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the Tab Capture API.
+// Custom bindings for the Tab Capture API.
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var binding = require('binding').Binding.create('tabCapture');
-
-binding.registerCustomHook(function(bindingsAPI, extensionId) {
+chromeHidden.registerCustomHook('tabCapture',
+ function(bindingsAPI, extensionId) {
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setCustomCallback('capture',
@@ -33,5 +33,3 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
request.callback = null;
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/tabs_custom_bindings.js b/chrome/renderer/resources/extensions/tabs_custom_bindings.js
index 0d7c405..90e5912 100644
--- a/chrome/renderer/resources/extensions/tabs_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/tabs_custom_bindings.js
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the tabs API.
-
-var binding = require('binding').Binding.create('tabs');
+// Custom bindings for the tabs API.
var tabsNatives = requireNative('tabs');
var OpenChannelToTab = tabsNatives.OpenChannelToTab;
@@ -12,9 +10,8 @@ var sendRequestIsDisabled = requireNative('process').IsSendRequestDisabled();
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-binding.registerCustomHook(function(bindingsAPI, extensionId) {
+chromeHidden.registerCustomHook('tabs', function(bindingsAPI, extensionId) {
var apiFunctions = bindingsAPI.apiFunctions;
- var tabs = bindingsAPI.compiledApi;
apiFunctions.setHandleRequest('connect', function(tabId, connectInfo) {
var name = '';
@@ -29,15 +26,13 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
function(tabId, request, responseCallback) {
if (sendRequestIsDisabled)
throw new Error(sendRequestIsDisabled);
- var port = tabs.connect(tabId, {name: chromeHidden.kRequestChannel});
+ var port = chrome.tabs.connect(tabId, {name: chromeHidden.kRequestChannel});
chromeHidden.Port.sendMessageImpl(port, request, responseCallback);
});
apiFunctions.setHandleRequest('sendMessage',
function(tabId, message, responseCallback) {
- var port = tabs.connect(tabId, {name: chromeHidden.kMessageChannel});
+ var port = chrome.tabs.connect(tabId, {name: chromeHidden.kMessageChannel});
chromeHidden.Port.sendMessageImpl(port, message, responseCallback);
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/tts_custom_bindings.js b/chrome/renderer/resources/extensions/tts_custom_bindings.js
index 5c74666..634ee38 100644
--- a/chrome/renderer/resources/extensions/tts_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/tts_custom_bindings.js
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the tts API.
-
-var binding = require('binding').Binding.create('tts');
+// Custom bindings for the tts API.
var ttsNatives = requireNative('tts');
var GetNextTTSEventId = ttsNatives.GetNextTTSEventId;
@@ -13,9 +11,8 @@ var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var sendRequest = require('sendRequest').sendRequest;
var lazyBG = requireNative('lazy_background_page');
-binding.registerCustomHook(function(api) {
+chromeHidden.registerCustomHook('tts', function(api) {
var apiFunctions = api.apiFunctions;
- var tts = api.compiledApi;
chromeHidden.tts = {
handlers: {}
@@ -42,7 +39,7 @@ binding.registerCustomHook(function(api) {
// add a listener to chrome.tts.onEvent will fail.
// See http://crbug.com/122474.
try {
- tts.onEvent.addListener(ttsEventListener);
+ chrome.tts.onEvent.addListener(ttsEventListener);
} catch (e) {}
apiFunctions.setHandleRequest('speak', function() {
@@ -59,5 +56,3 @@ binding.registerCustomHook(function(api) {
return id;
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/tts_engine_custom_bindings.js b/chrome/renderer/resources/extensions/tts_engine_custom_bindings.js
index 1d19cea..f16f143 100644
--- a/chrome/renderer/resources/extensions/tts_engine_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/tts_engine_custom_bindings.js
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the ttsEngine API.
-
-var binding = require('binding').Binding.create('ttsEngine');
+// Custom bindings for the ttsEngine API.
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
@@ -18,5 +16,3 @@ chromeHidden.Event.registerArgumentMassager('ttsEngine.onSpeak',
};
dispatch([text, options, sendTtsEvent]);
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/types_custom_bindings.js b/chrome/renderer/resources/extensions/types_custom_bindings.js
index 1c386f4..4af67b4d 100644
--- a/chrome/renderer/resources/extensions/types_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/types_custom_bindings.js
@@ -2,15 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the types API.
+// Custom bindings for the types API.
-var binding = require('binding').Binding.create('types');
-
-var chrome = requireNative('chrome').GetChrome();
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var sendRequest = require('sendRequest').sendRequest;
var validate = require('schemaUtils').validate;
-binding.registerCustomType('types.ChromeSetting', function() {
+chromeHidden.registerCustomType('types.ChromeSetting', function() {
function extendSchema(schema) {
var extendedSchema = schema.slice();
@@ -47,5 +45,3 @@ binding.registerCustomType('types.ChromeSetting', function() {
return ChromeSetting;
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/utils.js b/chrome/renderer/resources/extensions/utils.js
index ed35e15..beb9a51 100644
--- a/chrome/renderer/resources/extensions/utils.js
+++ b/chrome/renderer/resources/extensions/utils.js
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-var chrome = requireNative('chrome').GetChrome();
-
function forEach(dict, f) {
for (var key in dict) {
if (dict.hasOwnProperty(key))
@@ -27,16 +25,5 @@ function lookup(array_of_dictionaries, field, value) {
}
}
-// Specify |currentApi| if this should return an API for $refs in the current
-// namespace.
-function loadRefDependency(ref, currentApi) {
- var parts = ref.split(".");
- if (parts.length > 1)
- return chrome[parts.slice(0, parts.length - 1).join(".")];
- else
- return currentApi;
-}
-
exports.forEach = forEach;
-exports.loadRefDependency = loadRefDependency;
exports.lookup = lookup;
diff --git a/chrome/renderer/resources/extensions/web_request_custom_bindings.js b/chrome/renderer/resources/extensions/web_request_custom_bindings.js
index 135da99..9a458de 100644
--- a/chrome/renderer/resources/extensions/web_request_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/web_request_custom_bindings.js
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the webRequest API.
-
-var binding = require('binding').Binding.create('webRequest');
+// Custom bindings for the webRequest API.
var webRequestNatives = requireNative('web_request');
var GetUniqueSubEventName = webRequestNatives.GetUniqueSubEventName;
@@ -12,7 +10,6 @@ var GetUniqueSubEventName = webRequestNatives.GetUniqueSubEventName;
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var sendRequest = require('sendRequest').sendRequest;
var validate = require('schemaUtils').validate;
-var webRequestInternal = require('webRequestInternal').binding;
// WebRequestEvent object. This is used for special webRequest events with
// extra parameters. Each invocation of addListener creates a new named
@@ -69,7 +66,7 @@ WebRequestEvent.prototype.addListener =
// Note: this could fail to validate, in which case we would not add the
// subEvent listener.
validate(Array.prototype.slice.call(arguments, 1), this.extraArgSchemas_);
- webRequestInternal.addEventListener(
+ chromeHidden.internalAPIs.webRequestInternal.addEventListener(
cb, opt_filter, opt_extraInfo, this.eventName_, subEventName);
var subEvent = new chrome.Event(subEventName, this.argSchemas_);
@@ -80,10 +77,10 @@ WebRequestEvent.prototype.addListener =
var requestId = arguments[0].requestId;
try {
var result = cb.apply(null, arguments);
- webRequestInternal.eventHandled(
+ chromeHidden.internalAPIs.webRequestInternal.eventHandled(
eventName, subEventName, requestId, result);
} catch (e) {
- webRequestInternal.eventHandled(
+ chromeHidden.internalAPIs.webRequestInternal.eventHandled(
eventName, subEventName, requestId);
throw e;
}
@@ -94,7 +91,7 @@ WebRequestEvent.prototype.addListener =
var details = arguments[0];
var requestId = details.requestId;
var handledCallback = function(response) {
- webRequestInternal.eventHandled(
+ chromeHidden.internalAPIs.webRequestInternal.eventHandled(
eventName, subEventName, requestId, response);
};
cb.apply(null, [details, handledCallback]);
@@ -152,9 +149,9 @@ WebRequestEvent.prototype.getRules = function(ruleIdentifiers, cb) {
this.eventForRules_.getRules(ruleIdentifiers, cb);
}
-binding.registerCustomEvent(WebRequestEvent);
+chromeHidden.registerCustomEvent('webRequest', WebRequestEvent);
-binding.registerCustomHook(function(api) {
+chromeHidden.registerCustomHook('webRequest', function(api) {
var apiFunctions = api.apiFunctions;
apiFunctions.setHandleRequest('handlerBehaviorChanged', function() {
@@ -163,5 +160,3 @@ binding.registerCustomHook(function(api) {
{forIOThread: true});
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/web_request_internal_custom_bindings.js b/chrome/renderer/resources/extensions/web_request_internal_custom_bindings.js
index 584be5f..a33599c 100644
--- a/chrome/renderer/resources/extensions/web_request_internal_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/web_request_internal_custom_bindings.js
@@ -2,13 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the webRequestInternal API.
-
-var binding = require('binding').Binding.create('webRequestInternal');
+// Custom bindings for the webRequestInternal API.
+var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var sendRequest = require('sendRequest').sendRequest;
-binding.registerCustomHook(function(api) {
+chromeHidden.registerCustomHook('webRequestInternal', function(api) {
var apiFunctions = api.apiFunctions;
apiFunctions.setHandleRequest('addEventListener', function() {
@@ -23,5 +22,3 @@ binding.registerCustomHook(function(api) {
{forIOThread: true});
});
});
-
-exports.binding = binding.generate();
diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js
index 2fcf058..43c6dc4 100644
--- a/chrome/renderer/resources/extensions/web_view.js
+++ b/chrome/renderer/resources/extensions/web_view.js
@@ -7,9 +7,7 @@
// The actual tag is implemented via the browser plugin. The internals of this
// are hidden via Shadow DOM.
-var watchForTag = require('tagWatcher').watchForTag;
-
-var chrome = requireNative('chrome').GetChrome();
+var watchForTag = require("tagWatcher").watchForTag;
var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight',
'minwidth', 'maxheight', 'maxwidth'];
diff --git a/chrome/renderer/resources/extensions/web_view_experimental.js b/chrome/renderer/resources/extensions/web_view_experimental.js
index fd7226e..c5fa217 100644
--- a/chrome/renderer/resources/extensions/web_view_experimental.js
+++ b/chrome/renderer/resources/extensions/web_view_experimental.js
@@ -11,7 +11,7 @@
// permission API would only be available for channels CHANNEL_DEV and
// CHANNEL_CANARY.
-var WebView = require('webView').WebView;
+var WebView = require('webview').WebView;
/** @type {string} */
var REQUEST_TYPE_MEDIA = 'media';
diff --git a/chrome/renderer/resources/extensions/webstore_custom_bindings.js b/chrome/renderer/resources/extensions/webstore_custom_bindings.js
index 8ef9935..19c8f0f 100644
--- a/chrome/renderer/resources/extensions/webstore_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/webstore_custom_bindings.js
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom binding for the webstore API.
+// Custom bindings for the webstore API.
var webstoreNatives = requireNative('webstore');
@@ -49,14 +49,14 @@ var chromeWebstore = {
}
};
-// Called by webstore_binding.cc.
+// Called by webstore_bindings.cc.
var chromeHiddenWebstore = {
onInstallResponse: function(installId, success, error) {
installer.onInstallResponse(installId, success, error);
}
};
-// These must match the names in InstallWebstorebinding in
+// These must match the names in InstallWebstoreBindings in
// chrome/renderer/extensions/dispatcher.cc.
exports.chromeWebstore = chromeWebstore;
exports.chromeHiddenWebstore = chromeHiddenWebstore;