diff options
author | cduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-07 06:31:55 +0000 |
---|---|---|
committer | cduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-07 06:31:55 +0000 |
commit | 1e73bb01af4255521f957d3f2a603d179001226b (patch) | |
tree | 7755029f0d11712a807d01c110d9c603c488ccaf /chrome/renderer/resources/extensions/extension_custom_bindings.js | |
parent | d8bc3ecdc9f5f95de468d3b24ec59b124694ae05 (diff) | |
download | chromium_src-1e73bb01af4255521f957d3f2a603d179001226b.zip chromium_src-1e73bb01af4255521f957d3f2a603d179001226b.tar.gz chromium_src-1e73bb01af4255521f957d3f2a603d179001226b.tar.bz2 |
Set up V8 bindings for extension/app APIs when they're first used, not on
context creation. This should gives us a significant reduction in extension/app
startup time and slightly better memory usage.
It also gives us better error messages, the chance to complete the
implementation of API features, and eventually the ability to expose select
extension APIs (e.g. extension.sendMessage) to web pages.
Resubmitting: changes made to resubmit this patch reviewed in: https://codereview.chromium.org/12378077/
BUG=163678,120070,55316,177163
TBR=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11571014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186643 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/resources/extensions/extension_custom_bindings.js')
-rw-r--r-- | chrome/renderer/resources/extensions/extension_custom_bindings.js | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/chrome/renderer/resources/extensions/extension_custom_bindings.js b/chrome/renderer/resources/extensions/extension_custom_bindings.js index 60b4f12..61e5e16b 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(); |