diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-18 22:56:58 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-18 22:56:58 +0000 |
commit | 1f70f0ca51d1c61d3a775507b2b69dcdf60e77df (patch) | |
tree | 41659daa24b3e9af8996b2782dffead89fdcc63c /chrome/renderer/resources/event_bindings.js | |
parent | 11de3e98153ad8dcb9e6628e527f7bfb2ca0a8ed (diff) | |
download | chromium_src-1f70f0ca51d1c61d3a775507b2b69dcdf60e77df.zip chromium_src-1f70f0ca51d1c61d3a775507b2b69dcdf60e77df.tar.gz chromium_src-1f70f0ca51d1c61d3a775507b2b69dcdf60e77df.tar.bz2 |
Send port-closed notification when a frame with ports unloads.
Also add onLoad and onUnload chrome Event to our bindings, so we can add
listeners to these events without needing a DOM. These don't hook into the
window "unload" event, so we no longer prevent Chrome's sudden termination of
tabs on shutdown.
BUG=12686
TEST=no
Review URL: http://codereview.chromium.org/125280
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18765 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/resources/event_bindings.js')
-rw-r--r-- | chrome/renderer/resources/event_bindings.js | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/chrome/renderer/resources/event_bindings.js b/chrome/renderer/resources/event_bindings.js index f11ec78..54dd108 100644 --- a/chrome/renderer/resources/event_bindings.js +++ b/chrome/renderer/resources/event_bindings.js @@ -1,5 +1,5 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
+// Copyright (c) 2009 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. // ----------------------------------------------------------------------------- @@ -29,6 +29,9 @@ var chrome = chrome || {}; // A map of event names to the event object that is registered to that name. chrome.Event.attached_ = {}; + // An array of all attached event objects, used for detaching on unload. + chrome.Event.allAttached_ = []; + // Dispatches a named event with the given JSON array, which is deserialized // before dispatch. The JSON array is the list of arguments that will be // sent with the event callback. @@ -105,8 +108,7 @@ var chrome = chrome || {}; // name. chrome.Event.prototype.attach_ = function() { AttachEvent(this.eventName_); - this.unloadHandler_ = this.detach_.bind(this); - window.addEventListener('unload', this.unloadHandler_, false); + chrome.Event.allAttached_[chrome.Event.allAttached_.length] = this; if (!this.eventName_) return; @@ -120,7 +122,9 @@ var chrome = chrome || {}; // Detaches this event object from its name. chrome.Event.prototype.detach_ = function() { - window.removeEventListener('unload', this.unloadHandler_, false); + var i = chrome.Event.allAttached_.indexOf(this); + if (i >= 0) + delete chrome.Event.allAttached_[i]; DetachEvent(this.eventName_); if (!this.eventName_) return; @@ -132,4 +136,21 @@ var chrome = chrome || {}; delete chrome.Event.attached_[this.eventName_]; }; + + // Load events. Note that onUnload_ might not always fire, since Chrome will + // terminate renderers on shutdown. + chrome.onLoad_ = new chrome.Event(); + chrome.onUnload_ = new chrome.Event(); + + // This is called by native code when the DOM is ready. + chrome.dispatchOnLoad_ = function() { + chrome.onLoad_.dispatch(); + delete chrome.dispatchOnLoad_; + } + + chrome.dispatchOnUnload_ = function() { + chrome.onUnload_.dispatch(); + for (var i in chrome.Event.allAttached_) + chrome.Event.allAttached_[i].detach_(); + } })(); |