| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Custom binding for the extension API. | 5 // Custom binding for the extension API. |
| 6 | 6 |
| 7 var binding = require('binding').Binding.create('extension'); | 7 var binding = require('binding').Binding.create('extension'); |
| 8 | 8 |
| 9 var extensionNatives = requireNative('extension'); | 9 var extensionNatives = requireNative('extension'); |
| 10 var forEach = require('utils').forEach; | 10 var forEach = require('utils').forEach; |
| 11 var GetExtensionViews = extensionNatives.GetExtensionViews; | 11 var GetExtensionViews = extensionNatives.GetExtensionViews; |
| 12 var miscBindings = require('miscellaneous_bindings'); |
| 12 var runtimeNatives = requireNative('runtime'); | 13 var runtimeNatives = requireNative('runtime'); |
| 13 var OpenChannelToExtension = runtimeNatives.OpenChannelToExtension; | 14 var OpenChannelToExtension = runtimeNatives.OpenChannelToExtension; |
| 14 var OpenChannelToNativeApp = runtimeNatives.OpenChannelToNativeApp; | 15 var OpenChannelToNativeApp = runtimeNatives.OpenChannelToNativeApp; |
| 15 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | |
| 16 var chrome = requireNative('chrome').GetChrome(); | 16 var chrome = requireNative('chrome').GetChrome(); |
| 17 var sendMessageUpdateArguments = | |
| 18 require('miscellaneous_bindings').sendMessageUpdateArguments; | |
| 19 | 17 |
| 20 var inIncognitoContext = requireNative('process').InIncognitoContext(); | 18 var inIncognitoContext = requireNative('process').InIncognitoContext(); |
| 21 var sendRequestIsDisabled = requireNative('process').IsSendRequestDisabled(); | 19 var sendRequestIsDisabled = requireNative('process').IsSendRequestDisabled(); |
| 22 var contextType = requireNative('process').GetContextType(); | 20 var contextType = requireNative('process').GetContextType(); |
| 23 var manifestVersion = requireNative('process').GetManifestVersion(); | 21 var manifestVersion = requireNative('process').GetManifestVersion(); |
| 24 | 22 |
| 25 // This should match chrome.windows.WINDOW_ID_NONE. | 23 // This should match chrome.windows.WINDOW_ID_NONE. |
| 26 // | 24 // |
| 27 // We can't use chrome.windows.WINDOW_ID_NONE directly because the | 25 // We can't use chrome.windows.WINDOW_ID_NONE directly because the |
| 28 // chrome.windows API won't exist unless this extension has permission for it; | 26 // chrome.windows API won't exist unless this extension has permission for it; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 forEach(mayNeedAlias, function(i, alias) { | 80 forEach(mayNeedAlias, function(i, alias) { |
| 83 // Checking existence isn't enough since some functions are disabled via | 81 // Checking existence isn't enough since some functions are disabled via |
| 84 // getters that throw exceptions. Assume that any getter is such a function. | 82 // getters that throw exceptions. Assume that any getter is such a function. |
| 85 if (chrome.runtime.hasOwnProperty(alias) && | 83 if (chrome.runtime.hasOwnProperty(alias) && |
| 86 chrome.runtime.__lookupGetter__(alias) === undefined) { | 84 chrome.runtime.__lookupGetter__(alias) === undefined) { |
| 87 extension[alias] = chrome.runtime[alias]; | 85 extension[alias] = chrome.runtime[alias]; |
| 88 } | 86 } |
| 89 }); | 87 }); |
| 90 | 88 |
| 91 apiFunctions.setUpdateArgumentsPreValidate('sendRequest', | 89 apiFunctions.setUpdateArgumentsPreValidate('sendRequest', |
| 92 sendMessageUpdateArguments.bind(null, 'sendRequest')); | 90 miscBindings.sendMessageUpdateArguments.bind(null, 'sendRequest')); |
| 93 | 91 |
| 94 apiFunctions.setHandleRequest('sendRequest', | 92 apiFunctions.setHandleRequest('sendRequest', |
| 95 function(targetId, request, responseCallback) { | 93 function(targetId, request, responseCallback) { |
| 96 if (sendRequestIsDisabled) | 94 if (sendRequestIsDisabled) |
| 97 throw new Error(sendRequestIsDisabled); | 95 throw new Error(sendRequestIsDisabled); |
| 98 var port = chrome.runtime.connect(targetId || extensionId, | 96 var port = chrome.runtime.connect(targetId || extensionId, |
| 99 {name: chromeHidden.kRequestChannel}); | 97 {name: miscBindings.kRequestChannel}); |
| 100 chromeHidden.Port.sendMessageImpl(port, request, responseCallback); | 98 miscBindings.sendMessageImpl(port, request, responseCallback); |
| 101 }); | 99 }); |
| 102 | 100 |
| 103 if (sendRequestIsDisabled) { | 101 if (sendRequestIsDisabled) { |
| 104 extension.onRequest.addListener = function() { | 102 extension.onRequest.addListener = function() { |
| 105 throw new Error(sendRequestIsDisabled); | 103 throw new Error(sendRequestIsDisabled); |
| 106 }; | 104 }; |
| 107 if (contextType == 'BLESSED_EXTENSION') { | 105 if (contextType == 'BLESSED_EXTENSION') { |
| 108 extension.onRequestExternal.addListener = function() { | 106 extension.onRequestExternal.addListener = function() { |
| 109 throw new Error(sendRequestIsDisabled); | 107 throw new Error(sendRequestIsDisabled); |
| 110 }; | 108 }; |
| 111 } | 109 } |
| 112 } | 110 } |
| 113 }); | 111 }); |
| 114 | 112 |
| 115 exports.binding = binding.generate(); | 113 exports.binding = binding.generate(); |
| OLD | NEW |