forked from mirrors/gecko-dev
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8
This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:
ChromeUtils.import("resource://gre/modules/Services.jsm");
is approximately the same as the following, in the new model:
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs
This was done using the followng script:
https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16750
--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
119 lines
3.6 KiB
JavaScript
119 lines
3.6 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/. */
|
|
|
|
/**
|
|
* 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.import("resource://gre/modules/Log.jsm");
|
|
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;
|
|
}
|
|
|
|
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.");
|
|
gNotificationBox.appendNotification(
|
|
message,
|
|
this._DATA_REPORTING_NOTIFICATION,
|
|
null,
|
|
gNotificationBox.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: ChromeUtils.generateQI([
|
|
Ci.nsIObserver,
|
|
Ci.nsISupportsWeakReference,
|
|
]),
|
|
};
|