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

Unified Diff: chrome/renderer/resources/extensions/unload_event.js

Issue 15855010: Make ExtensionMsg_MessageInvoke run a module system function rather than a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test compile Created 7 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
Index: chrome/renderer/resources/extensions/unload_event.js
diff --git a/chrome/renderer/resources/extensions/unload_event.js b/chrome/renderer/resources/extensions/unload_event.js
new file mode 100644
index 0000000000000000000000000000000000000000..85a54658c93257d0e1bb4bccea95104c615e8c86
--- /dev/null
+++ b/chrome/renderer/resources/extensions/unload_event.js
@@ -0,0 +1,33 @@
+// Copyright 2013 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) {
+ listeners.push(listener);
+};
+
+exports.removeListener = function(listener) {
+ for (var i = 0; i < listeners.length; ++i) {
+ if (listeners[i] == listener) {
+ listeners.splice(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]();
+};

Powered by Google App Engine
This is Rietveld 408576698