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

Unified Diff: ui/webui/resources/js/webui_listener_tracker.js

Issue 2935303003: Print Preview: Remove global onPrivetPrintFailed (Closed)
Patch Set: Fix annotations Created 3 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 | « ui/webui/resources/js/compiled_resources2.gyp ('k') | ui/webui/resources/webui_resources.grd » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/js/webui_listener_tracker.js
diff --git a/ui/webui/resources/js/webui_listener_tracker.js b/ui/webui/resources/js/webui_listener_tracker.js
new file mode 100644
index 0000000000000000000000000000000000000000..51ffb08cfb944bb422f41f6d85c0dbf1070bed2b
--- /dev/null
+++ b/ui/webui/resources/js/webui_listener_tracker.js
@@ -0,0 +1,42 @@
+// Copyright 2017 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.
+
+/**
+ * @fileoverview Class that manages the addition and removal of WebUI
+ * listeners.
+ */
+
+/**
+ * Create a WebUIListenerTracker to track a set of Web UI listeners.
+ * @constructor
+ */
+function WebUIListenerTracker() {
+ /**
+ * The Web UI listeners being tracked.
+ * @private {!Array<!WebUIListener>}
+ */
+ this.listeners_ = [];
+}
+
+WebUIListenerTracker.prototype = {
+ /**
+ * Adds a WebUI listener to the array of listeners being tracked, which
+ * will be removed when removeAll() is called.
+ * Do not use this method if the listener will be removed manually.
+ * @param {string} eventName The event to listen to.
+ * @param {!Function} callback The callback to run when the event is fired.
+ */
+ add: function(eventName, callback) {
+ this.listeners_.push(cr.addWebUIListener(eventName, callback));
+ },
+
+ /**
+ * Removes all Web UI listeners that are currently being tracked.
+ */
+ removeAll: function() {
+ while (this.listeners_.length > 0) {
+ cr.removeWebUIListener(this.listeners_.pop());
+ }
+ },
+};
« no previous file with comments | « ui/webui/resources/js/compiled_resources2.gyp ('k') | ui/webui/resources/webui_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698