| 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 runtime API. | 5 // Custom bindings for the runtime API. |
| 6 | 6 |
| 7 var runtimeNatives = requireNative('runtime'); | 7 var runtimeNatives = requireNative('runtime'); |
| 8 var extensionNatives = requireNative('extension'); | 8 var extensionNatives = requireNative('extension'); |
| 9 var GetExtensionViews = extensionNatives.GetExtensionViews; | 9 var GetExtensionViews = extensionNatives.GetExtensionViews; |
| 10 var OpenChannelToExtension = runtimeNatives.OpenChannelToExtension; | 10 var OpenChannelToExtension = runtimeNatives.OpenChannelToExtension; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 apiFunctions.setHandleRequest('sendMessage', | 41 apiFunctions.setHandleRequest('sendMessage', |
| 42 function(targetId, message, responseCallback) { | 42 function(targetId, message, responseCallback) { |
| 43 var port = chrome.runtime.connect(targetId || chrome.runtime.id, | 43 var port = chrome.runtime.connect(targetId || chrome.runtime.id, |
| 44 {name: chromeHidden.kMessageChannel}); | 44 {name: chromeHidden.kMessageChannel}); |
| 45 chromeHidden.Port.sendMessageImpl(port, message, responseCallback); | 45 chromeHidden.Port.sendMessageImpl(port, message, responseCallback); |
| 46 }); | 46 }); |
| 47 | 47 |
| 48 apiFunctions.setHandleRequest('sendNativeMessage', | 48 apiFunctions.setHandleRequest('sendNativeMessage', |
| 49 function(targetId, message, responseCallback) { | 49 function(targetId, message, responseCallback) { |
| 50 var port = chrome.runtime.connectNative( | 50 var port = chrome.runtime.connectNative( |
| 51 targetId, message, chromeHidden.kNativeMessageChannel); | 51 targetId, chromeHidden.kNativeMessageChannel); |
| 52 chromeHidden.Port.sendMessageImpl(port, '', responseCallback); | 52 chromeHidden.Port.sendMessageImpl(port, message, responseCallback); |
| 53 }); | 53 }); |
| 54 | 54 |
| 55 apiFunctions.setUpdateArgumentsPreValidate('connect', function() { | 55 apiFunctions.setUpdateArgumentsPreValidate('connect', function() { |
| 56 // Align missing (optional) function arguments with the arguments that | 56 // Align missing (optional) function arguments with the arguments that |
| 57 // schema validation is expecting, e.g. | 57 // schema validation is expecting, e.g. |
| 58 // runtime.connect() -> runtime.connect(null, null) | 58 // runtime.connect() -> runtime.connect(null, null) |
| 59 // runtime.connect({}) -> runtime.connect(null, {}) | 59 // runtime.connect({}) -> runtime.connect(null, {}) |
| 60 var nextArg = 0; | 60 var nextArg = 0; |
| 61 | 61 |
| 62 // targetId (first argument) is optional. | 62 // targetId (first argument) is optional. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // Privileged APIs. | 110 // Privileged APIs. |
| 111 // | 111 // |
| 112 if (contextType != 'BLESSED_EXTENSION') | 112 if (contextType != 'BLESSED_EXTENSION') |
| 113 return; | 113 return; |
| 114 | 114 |
| 115 apiFunctions.setHandleRequest('connectNative', | 115 apiFunctions.setHandleRequest('connectNative', |
| 116 function(nativeAppName, connectInfo) { | 116 function(nativeAppName, connectInfo) { |
| 117 // Turn the object into a string here, because it eventually will be. | 117 // Turn the object into a string here, because it eventually will be. |
| 118 var portId = OpenChannelToNativeApp(chrome.runtime.id, | 118 var portId = OpenChannelToNativeApp(chrome.runtime.id, |
| 119 nativeAppName, | 119 nativeAppName, |
| 120 connectInfo.name, | 120 connectInfo.name); |
| 121 JSON.stringify(connectInfo.message)); | |
| 122 if (portId >= 0) { | 121 if (portId >= 0) { |
| 123 return chromeHidden.Port.createPort(portId, connectInfo.name); | 122 return chromeHidden.Port.createPort(portId, connectInfo.name); |
| 124 } | 123 } |
| 125 throw new Error('Error connecting to native app: ' + nativeAppName); | 124 throw new Error('Error connecting to native app: ' + nativeAppName); |
| 126 }); | 125 }); |
| 127 | 126 |
| 128 apiFunctions.setCustomCallback('getBackgroundPage', | 127 apiFunctions.setCustomCallback('getBackgroundPage', |
| 129 function(name, request, response) { | 128 function(name, request, response) { |
| 130 if (request.callback) { | 129 if (request.callback) { |
| 131 var bg = GetExtensionViews(-1, 'BACKGROUND')[0] || null; | 130 var bg = GetExtensionViews(-1, 'BACKGROUND')[0] || null; |
| 132 request.callback(bg); | 131 request.callback(bg); |
| 133 } | 132 } |
| 134 request.callback = null; | 133 request.callback = null; |
| 135 }); | 134 }); |
| 136 | 135 |
| 137 }); | 136 }); |
| OLD | NEW |