browser/base/content/browser-data-submission-info-bar.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 /**
michael@0 6 * Represents an info bar that shows a data submission notification.
michael@0 7 */
michael@0 8 let gDataNotificationInfoBar = {
michael@0 9 _OBSERVERS: [
michael@0 10 "datareporting:notify-data-policy:request",
michael@0 11 "datareporting:notify-data-policy:close",
michael@0 12 ],
michael@0 13
michael@0 14 _DATA_REPORTING_NOTIFICATION: "data-reporting",
michael@0 15
michael@0 16 get _notificationBox() {
michael@0 17 delete this._notificationBox;
michael@0 18 return this._notificationBox = document.getElementById("global-notificationbox");
michael@0 19 },
michael@0 20
michael@0 21 get _log() {
michael@0 22 let Log = Cu.import("resource://gre/modules/Log.jsm", {}).Log;
michael@0 23 delete this._log;
michael@0 24 return this._log = Log.repository.getLogger("Services.DataReporting.InfoBar");
michael@0 25 },
michael@0 26
michael@0 27 init: function() {
michael@0 28 window.addEventListener("unload", function onUnload() {
michael@0 29 window.removeEventListener("unload", onUnload, false);
michael@0 30
michael@0 31 for (let o of this._OBSERVERS) {
michael@0 32 Services.obs.removeObserver(this, o);
michael@0 33 }
michael@0 34 }.bind(this), false);
michael@0 35
michael@0 36 for (let o of this._OBSERVERS) {
michael@0 37 Services.obs.addObserver(this, o, true);
michael@0 38 }
michael@0 39 },
michael@0 40
michael@0 41 _getDataReportingNotification: function (name=this._DATA_REPORTING_NOTIFICATION) {
michael@0 42 return this._notificationBox.getNotificationWithValue(name);
michael@0 43 },
michael@0 44
michael@0 45 _displayDataPolicyInfoBar: function (request) {
michael@0 46 if (this._getDataReportingNotification()) {
michael@0 47 return;
michael@0 48 }
michael@0 49
michael@0 50 let brandBundle = document.getElementById("bundle_brand");
michael@0 51 let appName = brandBundle.getString("brandShortName");
michael@0 52 let vendorName = brandBundle.getString("vendorShortName");
michael@0 53
michael@0 54 let message = gNavigatorBundle.getFormattedString(
michael@0 55 "dataReportingNotification.message",
michael@0 56 [appName, vendorName]);
michael@0 57
michael@0 58 this._actionTaken = false;
michael@0 59
michael@0 60 let buttons = [{
michael@0 61 label: gNavigatorBundle.getString("dataReportingNotification.button.label"),
michael@0 62 accessKey: gNavigatorBundle.getString("dataReportingNotification.button.accessKey"),
michael@0 63 popup: null,
michael@0 64 callback: function () {
michael@0 65 // Clicking the button to go to the preferences tab constitutes
michael@0 66 // acceptance of the data upload policy for Firefox Health Report.
michael@0 67 // This will ensure the checkbox is checked. The user has the option of
michael@0 68 // unchecking it.
michael@0 69 request.onUserAccept("info-bar-button-pressed");
michael@0 70 this._actionTaken = true;
michael@0 71 window.openAdvancedPreferences("dataChoicesTab");
michael@0 72 }.bind(this),
michael@0 73 }];
michael@0 74
michael@0 75 this._log.info("Creating data reporting policy notification.");
michael@0 76 let notification = this._notificationBox.appendNotification(
michael@0 77 message,
michael@0 78 this._DATA_REPORTING_NOTIFICATION,
michael@0 79 null,
michael@0 80 this._notificationBox.PRIORITY_INFO_HIGH,
michael@0 81 buttons,
michael@0 82 function onEvent(event) {
michael@0 83 if (event == "removed") {
michael@0 84 if (!this._actionTaken) {
michael@0 85 request.onUserAccept("info-bar-dismissed");
michael@0 86 }
michael@0 87
michael@0 88 Services.obs.notifyObservers(null, "datareporting:notify-data-policy:close", null);
michael@0 89 }
michael@0 90 }.bind(this)
michael@0 91 );
michael@0 92
michael@0 93 // Tell the notification request we have displayed the notification.
michael@0 94 request.onUserNotifyComplete();
michael@0 95 },
michael@0 96
michael@0 97 _clearPolicyNotification: function () {
michael@0 98 let notification = this._getDataReportingNotification();
michael@0 99 if (notification) {
michael@0 100 this._log.debug("Closing notification.");
michael@0 101 notification.close();
michael@0 102 }
michael@0 103 },
michael@0 104
michael@0 105 onNotifyDataPolicy: function (request) {
michael@0 106 try {
michael@0 107 this._displayDataPolicyInfoBar(request);
michael@0 108 } catch (ex) {
michael@0 109 request.onUserNotifyFailed(ex);
michael@0 110 }
michael@0 111 },
michael@0 112
michael@0 113 observe: function(subject, topic, data) {
michael@0 114 switch (topic) {
michael@0 115 case "datareporting:notify-data-policy:request":
michael@0 116 this.onNotifyDataPolicy(subject.wrappedJSObject.object);
michael@0 117 break;
michael@0 118
michael@0 119 case "datareporting:notify-data-policy:close":
michael@0 120 // If this observer fires, it means something else took care of
michael@0 121 // responding. Therefore, we don't need to do anything. So, we
michael@0 122 // act like we took action and clear state.
michael@0 123 this._actionTaken = true;
michael@0 124 this._clearPolicyNotification();
michael@0 125 break;
michael@0 126
michael@0 127 default:
michael@0 128 }
michael@0 129 },
michael@0 130
michael@0 131 QueryInterface: XPCOMUtils.generateQI([
michael@0 132 Ci.nsIObserver,
michael@0 133 Ci.nsISupportsWeakReference,
michael@0 134 ]),
michael@0 135 };
michael@0 136

mercurial