| 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 // TODO(robwu): Fix indentation. | 5 // TODO(robwu): Fix indentation. |
| 6 | 6 |
| 7 var exceptionHandler = require('uncaught_exception_handler'); | 7 var exceptionHandler = require('uncaught_exception_handler'); |
| 8 var eventNatives = requireNative('event_natives'); | 8 var eventNatives = requireNative('event_natives'); |
| 9 var logging = requireNative('logging'); | 9 var logging = requireNative('logging'); |
| 10 var schemaRegistry = requireNative('schema_registry'); | 10 var schemaRegistry = requireNative('schema_registry'); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // An attachment strategy for events that aren't attached to the browser. | 47 // An attachment strategy for events that aren't attached to the browser. |
| 48 // This applies to events with the "unmanaged" option and events without | 48 // This applies to events with the "unmanaged" option and events without |
| 49 // names. | 49 // names. |
| 50 function NullAttachmentStrategy(event) { | 50 function NullAttachmentStrategy(event) { |
| 51 this.event_ = event; | 51 this.event_ = event; |
| 52 } | 52 } |
| 53 $Object.setPrototypeOf(NullAttachmentStrategy.prototype, null); | 53 $Object.setPrototypeOf(NullAttachmentStrategy.prototype, null); |
| 54 | 54 |
| 55 NullAttachmentStrategy.prototype.onAddedListener = | 55 NullAttachmentStrategy.prototype.onAddedListener = |
| 56 function(listener) { | 56 function(listener) { |
| 57 // For named events, we still inform the messaging bindings when a listener |
| 58 // is registered to allow for native checking if a listener is registered. |
| 59 if (this.event_.eventName && |
| 60 this.event_.listeners.length == 0) { |
| 61 eventNatives.AttachUnmanagedEvent(this.event_.eventName); |
| 62 } |
| 57 }; | 63 }; |
| 64 |
| 58 NullAttachmentStrategy.prototype.onRemovedListener = | 65 NullAttachmentStrategy.prototype.onRemovedListener = |
| 59 function(listener) { | 66 function(listener) { |
| 67 if (this.event_.eventName && |
| 68 this.event_.listeners.length == 0) { |
| 69 this.detach(true); |
| 70 } |
| 60 }; | 71 }; |
| 72 |
| 61 NullAttachmentStrategy.prototype.detach = function(manual) { | 73 NullAttachmentStrategy.prototype.detach = function(manual) { |
| 74 if (this.event_.eventName) |
| 75 eventNatives.DetachUnmanagedEvent(this.event_.eventName); |
| 62 }; | 76 }; |
| 77 |
| 63 NullAttachmentStrategy.prototype.getListenersByIDs = function(ids) { | 78 NullAttachmentStrategy.prototype.getListenersByIDs = function(ids) { |
| 64 // |ids| is for filtered events only. | 79 // |ids| is for filtered events only. |
| 65 return this.event_.listeners; | 80 return this.event_.listeners; |
| 66 }; | 81 }; |
| 67 | 82 |
| 68 // Handles adding/removing/dispatching listeners for unfiltered events. | 83 // Handles adding/removing/dispatching listeners for unfiltered events. |
| 69 function UnfilteredAttachmentStrategy(event) { | 84 function UnfilteredAttachmentStrategy(event) { |
| 70 this.event_ = event; | 85 this.event_ = event; |
| 71 } | 86 } |
| 72 $Object.setPrototypeOf(UnfilteredAttachmentStrategy.prototype, null); | 87 $Object.setPrototypeOf(UnfilteredAttachmentStrategy.prototype, null); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 'getRules', | 521 'getRules', |
| 507 ], | 522 ], |
| 508 }); | 523 }); |
| 509 | 524 |
| 510 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. | 525 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. |
| 511 exports.$set('Event', Event); | 526 exports.$set('Event', Event); |
| 512 | 527 |
| 513 exports.$set('dispatchEvent', dispatchEvent); | 528 exports.$set('dispatchEvent', dispatchEvent); |
| 514 exports.$set('parseEventOptions', parseEventOptions); | 529 exports.$set('parseEventOptions', parseEventOptions); |
| 515 exports.$set('registerArgumentMassager', registerArgumentMassager); | 530 exports.$set('registerArgumentMassager', registerArgumentMassager); |
| OLD | NEW |