fune/browser/base/content/browser-data-submission-info-bar.js
Ricky Chien daac97d466 Bug 1349689 - Remove old preferences fork r=jaws
MozReview-Commit-ID: GNPcQGUTUKJ

--HG--
rename : browser/components/preferences/in-content-new/findInPage.js => browser/components/preferences/in-content/findInPage.js
rename : browser/components/preferences/in-content-new/searchResults.xul => browser/components/preferences/in-content/searchResults.xul
rename : browser/components/preferences/in-content-new/tests/browser_checkspelling.js => browser/components/preferences/in-content/tests/browser_checkspelling.js
rename : browser/components/preferences/in-content-new/tests/browser_engines.js => browser/components/preferences/in-content/tests/browser_engines.js
rename : browser/components/preferences/in-content-new/tests/browser_layersacceleration.js => browser/components/preferences/in-content/tests/browser_layersacceleration.js
rename : browser/components/preferences/in-content-new/tests/browser_masterpassword.js => browser/components/preferences/in-content/tests/browser_masterpassword.js
rename : browser/components/preferences/in-content-new/tests/browser_permissions_dialog.js => browser/components/preferences/in-content/tests/browser_permissions_dialog.js
rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_1.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_1.js
rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_2.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_2.js
rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_3.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_3.js
rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_4.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_4.js
rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_5.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_5.js
rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_6.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_6.js
rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_7.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_7.js
rename : browser/components/preferences/in-content-new/tests/browser_search_subdialogs_within_preferences_8.js => browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_8.js
rename : browser/components/preferences/in-content-new/tests/browser_search_within_preferences_2.js => browser/components/preferences/in-content/tests/browser_search_within_preferences_2.js
rename : browser/components/preferences/in-content-new/tests/browser_search_within_preferences_command.js => browser/components/preferences/in-content/tests/browser_search_within_preferences_command.js
rename : browser/components/preferences/in-content-new/tests/browser_security-1.js => browser/components/preferences/in-content/tests/browser_security-1.js
rename : browser/components/preferences/in-content-new/tests/browser_security-2.js => browser/components/preferences/in-content/tests/browser_security-2.js
extra : rebase_source : 9adc8231c896f93f7f262a09482b44a2875bd5fd
2017-08-21 17:48:18 +08:00

125 lines
3.8 KiB
JavaScript

/* 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/. */
const LOGGER_NAME = "Toolkit.Telemetry";
const LOGGER_PREFIX = "DataNotificationInfoBar::";
/**
* 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 _notificationBox() {
delete this._notificationBox;
return this._notificationBox = document.getElementById("global-notificationbox");
},
get _log() {
let Log = Cu.import("resource://gre/modules/Log.jsm", {}).Log;
delete this._log;
return this._log = Log.repository.getLoggerWithMessagePrefix(LOGGER_NAME, LOGGER_PREFIX);
},
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 this._notificationBox.getNotificationWithValue(name);
},
_displayDataPolicyInfoBar(request) {
if (this._getDataReportingNotification()) {
return;
}
let brandBundle = document.getElementById("bundle_brand");
let appName = brandBundle.getString("brandShortName");
let vendorName = brandBundle.getString("vendorShortName");
let message = gNavigatorBundle.getFormattedString(
"dataReportingNotification.message",
[appName, vendorName]);
this._actionTaken = false;
let buttons = [{
label: gNavigatorBundle.getString("dataReportingNotification.button.label"),
accessKey: gNavigatorBundle.getString("dataReportingNotification.button.accessKey"),
popup: null,
callback: () => {
this._actionTaken = true;
window.openPreferences("privacy-reports", {origin: "dataReporting"});
},
}];
this._log.info("Creating data reporting policy notification.");
this._notificationBox.appendNotification(
message,
this._DATA_REPORTING_NOTIFICATION,
null,
this._notificationBox.PRIORITY_INFO_HIGH,
buttons,
event => {
if (event == "removed") {
Services.obs.notifyObservers(null, "datareporting:notify-data-policy:close");
}
}
);
// 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: XPCOMUtils.generateQI([
Ci.nsIObserver,
Ci.nsISupportsWeakReference,
]),
};