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