| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // ----------------------------------------------------------------------------- | 5 // ----------------------------------------------------------------------------- |
| 6 // NOTE: If you change this file you need to touch renderer_resources.grd to | 6 // NOTE: If you change this file you need to touch renderer_resources.grd to |
| 7 // have your change take effect. | 7 // have your change take effect. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 | 9 |
| 10 var chrome = chrome || {}; | 10 var chrome = chrome || {}; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 // Dispatches a named event with the given arguments, supplied as an array. | 54 // Dispatches a named event with the given arguments, supplied as an array. |
| 55 chromeHidden.Event.dispatch = function(name, args) { | 55 chromeHidden.Event.dispatch = function(name, args) { |
| 56 if (attachedNamedEvents[name]) { | 56 if (attachedNamedEvents[name]) { |
| 57 attachedNamedEvents[name].dispatch.apply( | 57 attachedNamedEvents[name].dispatch.apply( |
| 58 attachedNamedEvents[name], args); | 58 attachedNamedEvents[name], args); |
| 59 } | 59 } |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 // Test if a named event has any listeners. |
| 63 chromeHidden.Event.hasListener = function(name) { |
| 64 return (attachedNamedEvents[name] && |
| 65 attachedNamedEvents[name].listeners_.length > 0); |
| 66 } |
| 67 |
| 62 // Registers a callback to be called when this event is dispatched. | 68 // Registers a callback to be called when this event is dispatched. |
| 63 chrome.Event.prototype.addListener = function(cb) { | 69 chrome.Event.prototype.addListener = function(cb) { |
| 64 this.listeners_.push(cb); | 70 this.listeners_.push(cb); |
| 65 if (this.listeners_.length == 1) { | 71 if (this.listeners_.length == 1) { |
| 66 this.attach_(); | 72 this.attach_(); |
| 67 } | 73 } |
| 68 }; | 74 }; |
| 69 | 75 |
| 70 // Unregisters a callback. | 76 // Unregisters a callback. |
| 71 chrome.Event.prototype.removeListener = function(cb) { | 77 chrome.Event.prototype.removeListener = function(cb) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 var sargs = JSON.stringify(args); | 181 var sargs = JSON.stringify(args); |
| 176 var requestId = GetNextRequestId(); | 182 var requestId = GetNextRequestId(); |
| 177 var hasCallback = false; | 183 var hasCallback = false; |
| 178 if (callback) { | 184 if (callback) { |
| 179 hasCallback = true; | 185 hasCallback = true; |
| 180 callbacks[requestId] = callback; | 186 callbacks[requestId] = callback; |
| 181 } | 187 } |
| 182 request(sargs, requestId, hasCallback); | 188 request(sargs, requestId, hasCallback); |
| 183 } | 189 } |
| 184 | 190 |
| 185 // Special unload event: we don't use the DOM unload because that slows | 191 // Special load events: we don't use the DOM unload because that slows |
| 186 // down tab shutdown. On the other hand, this might not always fire, since | 192 // down tab shutdown. On the other hand, onUnload might not always fire, |
| 187 // Chrome will terminate renderers on shutdown (SuddenTermination). | 193 // since Chrome will terminate renderers on shutdown (SuddenTermination). |
| 194 chromeHidden.onLoad = new chrome.Event(); |
| 188 chromeHidden.onUnload = new chrome.Event(); | 195 chromeHidden.onUnload = new chrome.Event(); |
| 189 | 196 |
| 197 chromeHidden.dispatchOnLoad = function(extensionId) { |
| 198 chromeHidden.onLoad.dispatch(extensionId); |
| 199 } |
| 200 |
| 190 chromeHidden.dispatchOnUnload = function() { | 201 chromeHidden.dispatchOnUnload = function() { |
| 191 chromeHidden.onUnload.dispatch(); | 202 chromeHidden.onUnload.dispatch(); |
| 192 for (var i in allAttachedEvents) | 203 for (var i in allAttachedEvents) |
| 193 allAttachedEvents[i].detach_(); | 204 allAttachedEvents[i].detach_(); |
| 194 } | 205 } |
| 195 })(); | 206 })(); |
| OLD | NEW |