| 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 // This contains unprivileged javascript APIs for extensions and apps. It | 5 // This contains unprivileged javascript APIs for extensions and apps. It |
| 6 // can be loaded by any extension-related context, such as content scripts or | 6 // can be loaded by any extension-related context, such as content scripts or |
| 7 // background pages. See user_script_slave.cc for script that is loaded by | 7 // background pages. See user_script_slave.cc for script that is loaded by |
| 8 // content scripts only. | 8 // content scripts only. |
| 9 | 9 |
| 10 require('json_schema'); | 10 require('json_schema'); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 chromeHidden.Port.dispatchOnMessage = function(msg, portId) { | 248 chromeHidden.Port.dispatchOnMessage = function(msg, portId) { |
| 249 var port = ports[portId]; | 249 var port = ports[portId]; |
| 250 if (port) { | 250 if (port) { |
| 251 if (msg) { | 251 if (msg) { |
| 252 msg = chromeHidden.JSON.parse(msg); | 252 msg = chromeHidden.JSON.parse(msg); |
| 253 } | 253 } |
| 254 port.onMessage.dispatch(msg, port); | 254 port.onMessage.dispatch(msg, port); |
| 255 } | 255 } |
| 256 }; | 256 }; |
| 257 | 257 |
| 258 // Shared implementation used by tabs.sendMessage and extension.sendMessage. | 258 // Shared implementation used by tabs.sendMessage and runtime.sendMessage. |
| 259 chromeHidden.Port.sendMessageImpl = function(port, request, | 259 chromeHidden.Port.sendMessageImpl = function(port, request, |
| 260 responseCallback) { | 260 responseCallback) { |
| 261 if (port.name != chromeHidden.kNativeMessageChannel) | 261 if (port.name != chromeHidden.kNativeMessageChannel) |
| 262 port.postMessage(request); | 262 port.postMessage(request); |
| 263 | 263 |
| 264 if (port.name == chromeHidden.kMessageChannel && !responseCallback) { | 264 if (port.name == chromeHidden.kMessageChannel && !responseCallback) { |
| 265 // TODO(mpcomplete): Do this for the old sendRequest API too, after | 265 // TODO(mpcomplete): Do this for the old sendRequest API too, after |
| 266 // verifying it doesn't break anything. | 266 // verifying it doesn't break anything. |
| 267 // Go ahead and disconnect immediately if the sender is not expecting | 267 // Go ahead and disconnect immediately if the sender is not expecting |
| 268 // a response. | 268 // a response. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 var targetId = null; | 313 var targetId = null; |
| 314 if (lastArg >= 0) | 314 if (lastArg >= 0) |
| 315 targetId = args[lastArg--]; | 315 targetId = args[lastArg--]; |
| 316 | 316 |
| 317 if (lastArg != -1) | 317 if (lastArg != -1) |
| 318 throw new Error('Invalid arguments to ' + functionName + '.'); | 318 throw new Error('Invalid arguments to ' + functionName + '.'); |
| 319 return [targetId, request, responseCallback]; | 319 return [targetId, request, responseCallback]; |
| 320 } | 320 } |
| 321 | 321 |
| 322 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; | 322 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; |
| OLD | NEW |