| 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 bindings for the extension API. | 5 // Custom bindings for the extension API. |
| 6 | 6 |
| 7 var extensionNatives = requireNative('extension'); | 7 var extensionNatives = requireNative('extension'); |
| 8 var GetExtensionViews = extensionNatives.GetExtensionViews; | 8 var GetExtensionViews = extensionNatives.GetExtensionViews; |
| 9 var runtimeNatives = requireNative('runtime'); | 9 var runtimeNatives = requireNative('runtime'); |
| 10 var OpenChannelToExtension = runtimeNatives.OpenChannelToExtension; | 10 var OpenChannelToExtension = runtimeNatives.OpenChannelToExtension; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 }); | 63 }); |
| 64 | 64 |
| 65 apiFunctions.setHandleRequest('getURL', function(path) { | 65 apiFunctions.setHandleRequest('getURL', function(path) { |
| 66 path = String(path); | 66 path = String(path); |
| 67 if (!path.length || path[0] != '/') | 67 if (!path.length || path[0] != '/') |
| 68 path = '/' + path; | 68 path = '/' + path; |
| 69 return 'chrome-extension://' + extensionId + path; | 69 return 'chrome-extension://' + extensionId + path; |
| 70 }); | 70 }); |
| 71 | 71 |
| 72 // Alias several messaging deprecated APIs to their runtime counterparts. | 72 // Alias several messaging deprecated APIs to their runtime counterparts. |
| 73 chrome.extension.connect = chrome.runtime.connect; | 73 var mayNeedAlias = [ |
| 74 chrome.extension.sendMessage = chrome.runtime.sendMessage; | 74 // Types. |
| 75 chrome.extension.onConnect = chrome.runtime.onConnect; | 75 'Port', |
| 76 chrome.extension.onMessage = chrome.runtime.onMessage; | 76 // Functions. |
| 77 if (contextType == 'BLESSED_EXTENSION') { | 77 'connect', 'sendMessage', 'connectNative', 'sendNativeMessage', |
| 78 chrome.extension.connectNative = chrome.runtime.connectNative; | 78 // Events |
| 79 chrome.extension.sendNativeMessage = chrome.runtime.sendNativeMessage; | 79 'onConnect', 'onConnectExternal', 'onMessage', 'onMessageExternal' |
| 80 chrome.extension.onConnectExternal = chrome.runtime.onConnectExternal; | 80 ]; |
| 81 chrome.extension.onMessageExternal = chrome.runtime.onMessageExternal; | 81 mayNeedAlias.forEach(function(alias) { |
| 82 } | 82 if (chrome.runtime.hasOwnProperty(alias)) |
| 83 chrome.extension[alias] = chrome.runtime[alias]; |
| 84 }); |
| 83 | 85 |
| 84 apiFunctions.setUpdateArgumentsPreValidate('sendRequest', | 86 apiFunctions.setUpdateArgumentsPreValidate('sendRequest', |
| 85 sendMessageUpdateArguments.bind(null, 'sendRequest')); | 87 sendMessageUpdateArguments.bind(null, 'sendRequest')); |
| 86 | 88 |
| 87 apiFunctions.setHandleRequest('sendRequest', | 89 apiFunctions.setHandleRequest('sendRequest', |
| 88 function(targetId, request, responseCallback) { | 90 function(targetId, request, responseCallback) { |
| 89 if (sendRequestIsDisabled) | 91 if (sendRequestIsDisabled) |
| 90 throw new Error(sendRequestIsDisabled); | 92 throw new Error(sendRequestIsDisabled); |
| 91 var port = chrome.runtime.connect(targetId || extensionId, | 93 var port = chrome.runtime.connect(targetId || extensionId, |
| 92 {name: chromeHidden.kRequestChannel}); | 94 {name: chromeHidden.kRequestChannel}); |
| 93 chromeHidden.Port.sendMessageImpl(port, request, responseCallback); | 95 chromeHidden.Port.sendMessageImpl(port, request, responseCallback); |
| 94 }); | 96 }); |
| 95 | 97 |
| 96 if (sendRequestIsDisabled) { | 98 if (sendRequestIsDisabled) { |
| 97 chrome.extension.onRequest.addListener = function() { | 99 chrome.extension.onRequest.addListener = function() { |
| 98 throw new Error(sendRequestIsDisabled); | 100 throw new Error(sendRequestIsDisabled); |
| 99 }; | 101 }; |
| 100 if (contextType == 'BLESSED_EXTENSION') { | 102 if (contextType == 'BLESSED_EXTENSION') { |
| 101 chrome.extension.onRequestExternal.addListener = function() { | 103 chrome.extension.onRequestExternal.addListener = function() { |
| 102 throw new Error(sendRequestIsDisabled); | 104 throw new Error(sendRequestIsDisabled); |
| 103 }; | 105 }; |
| 104 } | 106 } |
| 105 } | 107 } |
| 106 | 108 |
| 107 }); | 109 }); |
| OLD | NEW |