diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/base/content/browser-data-submission-info-bar.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/browser-data-submission-info-bar.js')
-rw-r--r-- | browser/base/content/browser-data-submission-info-bar.js | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/browser/base/content/browser-data-submission-info-bar.js b/browser/base/content/browser-data-submission-info-bar.js new file mode 100644 index 0000000000..896542796c --- /dev/null +++ b/browser/base/content/browser-data-submission-info-bar.js @@ -0,0 +1,122 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * Represents an info bar that shows a data submission notification. + */ +var gDataNotificationInfoBar = { + _OBSERVERS: [ + "datareporting:notify-data-policy:request", + "datareporting:notify-data-policy:close", + ], + + _DATA_REPORTING_NOTIFICATION: "data-reporting", + + get _log() { + let { Log } = ChromeUtils.importESModule( + "resource://gre/modules/Log.sys.mjs" + ); + delete this._log; + return (this._log = Log.repository.getLoggerWithMessagePrefix( + "Toolkit.Telemetry", + "DataNotificationInfoBar::" + )); + }, + + init() { + window.addEventListener("unload", () => { + for (let o of this._OBSERVERS) { + Services.obs.removeObserver(this, o); + } + }); + + for (let o of this._OBSERVERS) { + Services.obs.addObserver(this, o, true); + } + }, + + _getDataReportingNotification(name = this._DATA_REPORTING_NOTIFICATION) { + return gNotificationBox.getNotificationWithValue(name); + }, + + _displayDataPolicyInfoBar(request) { + if (this._getDataReportingNotification()) { + return; + } + + this._actionTaken = false; + + let buttons = [ + { + "l10n-id": "data-reporting-notification-button", + popup: null, + callback: () => { + this._actionTaken = true; + window.openPreferences("privacy-reports"); + }, + }, + ]; + + this._log.info("Creating data reporting policy notification."); + gNotificationBox.appendNotification( + this._DATA_REPORTING_NOTIFICATION, + { + label: { + "l10n-id": "data-reporting-notification-message", + }, + priority: gNotificationBox.PRIORITY_INFO_HIGH, + eventCallback: event => { + if (event == "removed") { + Services.obs.notifyObservers( + null, + "datareporting:notify-data-policy:close" + ); + } + }, + }, + buttons + ); + // It is important to defer calling onUserNotifyComplete() until we're + // actually sure the notification was displayed. If we ever called + // onUserNotifyComplete() without showing anything to the user, that + // would be very good for user choice. It may also have legal impact. + request.onUserNotifyComplete(); + }, + + _clearPolicyNotification() { + let notification = this._getDataReportingNotification(); + if (notification) { + this._log.debug("Closing notification."); + notification.close(); + } + }, + + observe(subject, topic, data) { + switch (topic) { + case "datareporting:notify-data-policy:request": + let request = subject.wrappedJSObject.object; + try { + this._displayDataPolicyInfoBar(request); + } catch (ex) { + request.onUserNotifyFailed(ex); + } + break; + + case "datareporting:notify-data-policy:close": + // If this observer fires, it means something else took care of + // responding. Therefore, we don't need to do anything. So, we + // act like we took action and clear state. + this._actionTaken = true; + this._clearPolicyNotification(); + break; + + default: + } + }, + + QueryInterface: ChromeUtils.generateQI([ + "nsIObserver", + "nsISupportsWeakReference", + ]), +}; |