Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9957)

Unified Diff: chrome/renderer/resources/event_bindings.js

Issue 125280: Send port-closed notification when a frame with ports unloads.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/renderer_resources.grd ('k') | chrome/renderer/resources/extension_process_bindings.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « chrome/renderer/renderer_resources.grd ('k') | chrome/renderer/resources/extension_process_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698