| 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 // TODO(robwu): Fix this indentation. | 6 // TODO(robwu): Fix this indentation. |
| 7 | 7 |
| 8 // TODO(kalman): factor requiring chrome out of here. | 8 // TODO(kalman): factor requiring chrome out of here. |
| 9 var chrome = requireNative('chrome').GetChrome(); | 9 var chrome = requireNative('chrome').GetChrome(); |
| 10 var lastError = require('lastError'); | 10 var lastError = require('lastError'); |
| 11 var logActivity = requireNative('activityLogger'); | 11 var logActivity = requireNative('activityLogger'); |
| 12 var logging = requireNative('logging'); | 12 var logging = requireNative('logging'); |
| 13 var messagingNatives = requireNative('messaging_natives'); | 13 var messagingNatives = requireNative('messaging_natives'); |
| 14 var processNatives = requireNative('process'); | 14 var processNatives = requireNative('process'); |
| 15 var utils = require('utils'); | 15 var utils = require('utils'); |
| 16 var messagingUtils = require('messaging_utils'); | 16 var messagingUtils = require('messaging_utils'); |
| 17 | 17 |
| 18 // The reserved channel name for the sendRequest/send(Native)Message APIs. | 18 // The reserved channel name for the sendRequest/send(Native)Message APIs. |
| 19 // Note: sendRequest is deprecated. | 19 // Note: sendRequest is deprecated. |
| 20 var kRequestChannel = "chrome.extension.sendRequest"; | 20 var kRequestChannel = "chrome.extension.sendRequest"; |
| 21 var kMessageChannel = "chrome.runtime.sendMessage"; | 21 var kMessageChannel = "chrome.runtime.sendMessage"; |
| 22 var kNativeMessageChannel = "chrome.runtime.sendNativeMessage"; | 22 var kNativeMessageChannel = "chrome.runtime.sendNativeMessage"; |
| 23 var kPortClosedError = 'Attempting to use a disconnected port object'; | 23 var kPortClosedError = 'Attempting to use a disconnected port object'; |
| 24 | 24 |
| 25 var jsEvent; | 25 var jsEvent; |
| 26 function createAnonymousEvent(schema, options) { | 26 function createAnonymousEvent(schema) { |
| 27 if (bindingUtil) { | 27 if (bindingUtil) { |
| 28 // Native custom events ignore schema. | 28 // Native custom events ignore schema. |
| 29 return bindingUtil.createCustomEvent(undefined, undefined, options); | 29 var supportsFilters = false; |
| 30 return bindingUtil.createCustomEvent(undefined, undefined, |
| 31 supportsFilters); |
| 30 } | 32 } |
| 33 var options = { |
| 34 __proto__: null, |
| 35 unmanaged: true, |
| 36 }; |
| 31 if (!jsEvent) | 37 if (!jsEvent) |
| 32 jsEvent = require('event_bindings').Event; | 38 jsEvent = require('event_bindings').Event; |
| 33 return new jsEvent(undefined, schema, options); | 39 return new jsEvent(undefined, schema, options); |
| 34 } | 40 } |
| 35 | 41 |
| 36 function invalidateEvent(event) { | 42 function invalidateEvent(event) { |
| 37 if (bindingUtil) | 43 if (bindingUtil) |
| 38 bindingUtil.invalidateEvent(event); | 44 bindingUtil.invalidateEvent(event); |
| 39 else | 45 else |
| 40 privates(event).impl.destroy_(); | 46 privates(event).impl.destroy_(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 54 __proto__: null, | 60 __proto__: null, |
| 55 name: 'port', | 61 name: 'port', |
| 56 $ref: 'runtime.Port', | 62 $ref: 'runtime.Port', |
| 57 }; | 63 }; |
| 58 var messageSchema = { | 64 var messageSchema = { |
| 59 __proto__: null, | 65 __proto__: null, |
| 60 name: 'message', | 66 name: 'message', |
| 61 type: 'any', | 67 type: 'any', |
| 62 optional: true, | 68 optional: true, |
| 63 }; | 69 }; |
| 64 var options = { | 70 this.onDisconnect = createAnonymousEvent([portSchema]); |
| 65 __proto__: null, | 71 this.onMessage = createAnonymousEvent([messageSchema, portSchema]); |
| 66 unmanaged: true, | |
| 67 }; | |
| 68 this.onDisconnect = createAnonymousEvent([portSchema], options); | |
| 69 this.onMessage = createAnonymousEvent([messageSchema, portSchema], options); | |
| 70 } | 72 } |
| 71 $Object.setPrototypeOf(PortImpl.prototype, null); | 73 $Object.setPrototypeOf(PortImpl.prototype, null); |
| 72 | 74 |
| 73 // Sends a message asynchronously to the context on the other end of this | 75 // Sends a message asynchronously to the context on the other end of this |
| 74 // port. | 76 // port. |
| 75 PortImpl.prototype.postMessage = function(msg) { | 77 PortImpl.prototype.postMessage = function(msg) { |
| 76 if (!$Object.hasOwnProperty(ports, this.portId_)) | 78 if (!$Object.hasOwnProperty(ports, this.portId_)) |
| 77 throw new Error(kPortClosedError); | 79 throw new Error(kPortClosedError); |
| 78 | 80 |
| 79 // JSON.stringify doesn't support a root object which is undefined. | 81 // JSON.stringify doesn't support a root object which is undefined. |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 exports.$set('kNativeMessageChannel', kNativeMessageChannel); | 435 exports.$set('kNativeMessageChannel', kNativeMessageChannel); |
| 434 exports.$set('Port', Port); | 436 exports.$set('Port', Port); |
| 435 exports.$set('createPort', createPort); | 437 exports.$set('createPort', createPort); |
| 436 exports.$set('sendMessageImpl', sendMessageImpl); | 438 exports.$set('sendMessageImpl', sendMessageImpl); |
| 437 exports.$set('sendMessageUpdateArguments', sendMessageUpdateArguments); | 439 exports.$set('sendMessageUpdateArguments', sendMessageUpdateArguments); |
| 438 | 440 |
| 439 // For C++ code to call. | 441 // For C++ code to call. |
| 440 exports.$set('dispatchOnConnect', dispatchOnConnect); | 442 exports.$set('dispatchOnConnect', dispatchOnConnect); |
| 441 exports.$set('dispatchOnDisconnect', dispatchOnDisconnect); | 443 exports.$set('dispatchOnDisconnect', dispatchOnDisconnect); |
| 442 exports.$set('dispatchOnMessage', dispatchOnMessage); | 444 exports.$set('dispatchOnMessage', dispatchOnMessage); |
| OLD | NEW |