| Index: chrome/renderer/resources/event_bindings.js
|
| ===================================================================
|
| --- chrome/renderer/resources/event_bindings.js (revision 18701)
|
| +++ chrome/renderer/resources/event_bindings.js (working copy)
|
| @@ -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 @@
|
| // 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 @@
|
| // 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 @@
|
|
|
| // 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 @@
|
|
|
| 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_();
|
| + }
|
| })();
|
|
|
| Property changes on: chrome\renderer\resources\event_bindings.js
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|