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

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: comments/TODOs Created 7 years, 11 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 4311ee9e386632c86935d8f9627f24b79f60dcfc..bf74a0ad127e954c07d0eb96f1bb1822206b2fa4 100644
--- a/chrome/renderer/resources/extensions/extension_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/extension_custom_bindings.js
@@ -4,28 +4,24 @@
// Custom bindings for the extension API.
+var bindings = new (require('schema_binding_generator').Bindings)('extension');
+
var extensionNatives = requireNative('extension');
var GetExtensionViews = extensionNatives.GetExtensionViews;
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;
+var DCHECK = requireNative('logging').DCHECK;
// This should match chrome.windows.WINDOW_ID_NONE.
//
@@ -34,8 +30,14 @@ chrome.extension.inIncognitoContext = inIncognitoContext;
// which may not be the case.
var WINDOW_ID_NONE = -1;
-chromeHidden.registerCustomHook('extension',
- function(bindingsAPI, extensionId) {
+bindings.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) {
@@ -84,7 +86,7 @@ chromeHidden.registerCustomHook('extension',
// existence, since accessing may throw an exception if this context
// doesn't have access.
if (chrome.runtime[alias])
- chrome.extension[alias] = chrome.runtime[alias];
+ extension[alias] = chrome.runtime[alias];
} catch(e) {}
});
@@ -101,14 +103,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.bindings = bindings.generate();

Powered by Google App Engine
This is Rietveld 408576698