OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // chrome.runtime.messaging API implementation. | 5 // chrome.runtime.messaging API implementation. |
6 | 6 |
7 // TODO(kalman): factor requiring chrome out of here. | 7 // TODO(kalman): factor requiring chrome out of here. |
8 var chrome = requireNative('chrome').GetChrome(); | 8 var chrome = requireNative('chrome').GetChrome(); |
9 var Event = require('event_bindings').Event; | 9 var Event = require('event_bindings').Event; |
10 var lastError = require('lastError'); | 10 var lastError = require('lastError'); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 // the C++ to avoid creating the javascript message for all the contexts that | 95 // the C++ to avoid creating the javascript message for all the contexts that |
96 // don't care about a particular message. | 96 // don't care about a particular message. |
97 function hasPort(portId) { | 97 function hasPort(portId) { |
98 return portId in ports; | 98 return portId in ports; |
99 }; | 99 }; |
100 | 100 |
101 // Hidden port creation function. We don't want to expose an API that lets | 101 // Hidden port creation function. We don't want to expose an API that lets |
102 // people add arbitrary port IDs to the port list. | 102 // people add arbitrary port IDs to the port list. |
103 function createPort(portId, opt_name) { | 103 function createPort(portId, opt_name) { |
104 if (ports[portId]) | 104 if (ports[portId]) |
105 throw new Error("Port '" + portId + "' already exists."); | 105 throw new $Error.self("Port '" + portId + "' already exists."); |
106 var port = new Port(portId, opt_name); | 106 var port = new Port(portId, opt_name); |
107 ports[portId] = port; | 107 ports[portId] = port; |
108 portReleasers[portId] = $Function.bind(messagingNatives.PortRelease, | 108 portReleasers[portId] = $Function.bind(messagingNatives.PortRelease, |
109 this, | 109 this, |
110 portId); | 110 portId); |
111 unloadEvent.addListener(portReleasers[portId]); | 111 unloadEvent.addListener(portReleasers[portId]); |
112 messagingNatives.PortAddRef(portId); | 112 messagingNatives.PortAddRef(portId); |
113 return port; | 113 return port; |
114 }; | 114 }; |
115 | 115 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 port.onDisconnect.addListener(disconnectListener); | 350 port.onDisconnect.addListener(disconnectListener); |
351 port.onMessage.addListener(messageListener); | 351 port.onMessage.addListener(messageListener); |
352 }; | 352 }; |
353 | 353 |
354 function sendMessageUpdateArguments(functionName, hasOptionsArgument) { | 354 function sendMessageUpdateArguments(functionName, hasOptionsArgument) { |
355 // skip functionName and hasOptionsArgument | 355 // skip functionName and hasOptionsArgument |
356 var args = $Array.slice(arguments, 2); | 356 var args = $Array.slice(arguments, 2); |
357 var alignedArgs = messagingUtils.alignSendMessageArguments(args, | 357 var alignedArgs = messagingUtils.alignSendMessageArguments(args, |
358 hasOptionsArgument); | 358 hasOptionsArgument); |
359 if (!alignedArgs) | 359 if (!alignedArgs) |
360 throw new Error('Invalid arguments to ' + functionName + '.'); | 360 throw new $Error.self('Invalid arguments to ' + functionName + '.'); |
not at google - send to devlin
2014/08/19 16:45:56
new Error()
| |
361 return alignedArgs; | 361 return alignedArgs; |
362 } | 362 } |
363 | 363 |
364 var Port = utils.expose('Port', PortImpl, { functions: [ | 364 var Port = utils.expose('Port', PortImpl, { functions: [ |
365 'disconnect', | 365 'disconnect', |
366 'postMessage' | 366 'postMessage' |
367 ], | 367 ], |
368 properties: [ | 368 properties: [ |
369 'name', | 369 'name', |
370 'onDisconnect', | 370 'onDisconnect', |
371 'onMessage' | 371 'onMessage' |
372 ] }); | 372 ] }); |
373 | 373 |
374 exports.kRequestChannel = kRequestChannel; | 374 exports.kRequestChannel = kRequestChannel; |
375 exports.kMessageChannel = kMessageChannel; | 375 exports.kMessageChannel = kMessageChannel; |
376 exports.kNativeMessageChannel = kNativeMessageChannel; | 376 exports.kNativeMessageChannel = kNativeMessageChannel; |
377 exports.Port = Port; | 377 exports.Port = Port; |
378 exports.createPort = createPort; | 378 exports.createPort = createPort; |
379 exports.sendMessageImpl = sendMessageImpl; | 379 exports.sendMessageImpl = sendMessageImpl; |
380 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; | 380 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; |
381 | 381 |
382 // For C++ code to call. | 382 // For C++ code to call. |
383 exports.hasPort = hasPort; | 383 exports.hasPort = hasPort; |
384 exports.dispatchOnConnect = dispatchOnConnect; | 384 exports.dispatchOnConnect = dispatchOnConnect; |
385 exports.dispatchOnDisconnect = dispatchOnDisconnect; | 385 exports.dispatchOnDisconnect = dispatchOnDisconnect; |
386 exports.dispatchOnMessage = dispatchOnMessage; | 386 exports.dispatchOnMessage = dispatchOnMessage; |
OLD | NEW |