blob: 753c2f0100f3ecfab314fd2588f274d3c95d9ce6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Special unload event. We don't use the DOM unload because that slows down
// tab shutdown. On the other hand, onUnload might not always fire, since
// Chrome will terminate renderers on shutdown (SuddenTermination).
// Implement a primitive subset of the Event interface as needed, since if this
// was to use the real event object there would be a circular dependency.
var listeners = [];
exports.addListener = function(listener) {
$Array.push(listeners, listener);
};
exports.removeListener = function(listener) {
for (var i = 0; i < listeners.length; ++i) {
if (listeners[i] == listener) {
$Array.splice(listeners, i, 1);
return;
}
}
};
exports.wasDispatched = false;
// dispatch() is called from C++.
exports.dispatch = function() {
exports.wasDispatched = true;
for (var i = 0; i < listeners.length; ++i)
listeners[i]();
};
|