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

Unified Diff: chrome/renderer/resources/extensions/extension_custom_bindings.js

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android compilation Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/extension_custom_bindings.js
diff --git a/chrome/renderer/resources/extensions/extension_custom_bindings.js b/chrome/renderer/resources/extensions/extension_custom_bindings.js
index 60b4f12ad175e1e8aba23357493b61d0f0899db7..61e5e16b3c68c1a70ae255958fb999431e07cac1 100644
--- a/chrome/renderer/resources/extensions/extension_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/extension_custom_bindings.js
@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Custom bindings for the extension API.
+// Custom binding for the extension API.
+
+var binding = require('binding').Binding.create('extension');
var extensionNatives = requireNative('extension');
var GetExtensionViews = extensionNatives.GetExtensionViews;
@@ -10,22 +12,14 @@ 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.
//
@@ -34,8 +28,14 @@ chrome.extension.inIncognitoContext = inIncognitoContext;
// which may not be the case.
var WINDOW_ID_NONE = -1;
-chromeHidden.registerCustomHook('extension',
- function(bindingsAPI, extensionId) {
+binding.registerCustomHook(function(bindingsAPI, extensionId) {
+ var extension = bindingsAPI.compiledApi;
+ if (manifestVersion < 2) {
+ chrome.self = extension;
+ extension.inIncognitoTab = inIncognitoContext;
+ }
+ extension.inIncognitoContext = inIncognitoContext;
+
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setHandleRequest('getViews', function(properties) {
@@ -83,7 +83,7 @@ chromeHidden.registerCustomHook('extension',
// getters that throw exceptions. Assume that any getter is such a function.
if (chrome.runtime.hasOwnProperty(alias) &&
chrome.runtime.__lookupGetter__(alias) === undefined) {
- chrome.extension[alias] = chrome.runtime[alias];
+ extension[alias] = chrome.runtime[alias];
}
});
@@ -100,14 +100,15 @@ chromeHidden.registerCustomHook('extension',
});
if (sendRequestIsDisabled) {
- chrome.extension.onRequest.addListener = function() {
+ extension.onRequest.addListener = function() {
throw new Error(sendRequestIsDisabled);
};
if (contextType == 'BLESSED_EXTENSION') {
- chrome.extension.onRequestExternal.addListener = function() {
+ extension.onRequestExternal.addListener = function() {
throw new Error(sendRequestIsDisabled);
};
}
}
-
});
+
+exports.binding = binding.generate();

Powered by Google App Engine
This is Rietveld 408576698