Bug 1289231 - part 2: remove notification after it's been displayed for 3 days, r?dolske
MozReview-Commit-ID: CFARPDu3FnI
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1476,16 +1476,19 @@ pref("toolkit.pageThumbs.minHeight", 190
// Enable speech synthesis
pref("media.webspeech.synth.enabled", true);
pref("browser.esedbreader.loglevel", "Error");
pref("browser.laterrun.enabled", false);
pref("browser.migrate.automigrate.enabled", false);
+// 4 here means the suggestion notification will be automatically
+// hidden the 4th day, so it will actually be shown on 3 different days.
+pref("browser.migrate.automigrate.daysToOfferUndo", 4);
// Enable browser frames for use on desktop. Only exposed to chrome callers.
pref("dom.mozBrowserFramesEnabled", true);
pref("extensions.pocket.enabled", true);
pref("signon.schemeUpgrades", true);
--- a/browser/components/migration/AutoMigrate.jsm
+++ b/browser/components/migration/AutoMigrate.jsm
@@ -9,16 +9,19 @@ this.EXPORTED_SYMBOLS = ["AutoMigrate"];
const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
const kAutoMigrateEnabledPref = "browser.migrate.automigrate.enabled";
const kAutoMigrateStartedPref = "browser.migrate.automigrate.started";
const kAutoMigrateFinishedPref = "browser.migrate.automigrate.finished";
const kAutoMigrateBrowserPref = "browser.migrate.automigrate.browser";
+const kAutoMigrateLastUndoPromptDatePref = "browser.migrate.automigrate.lastUndoPromptDate";
+const kAutoMigrateDaysToOfferUndoPref = "browser.migrate.automigrate.daysToOfferUndo";
+
const kPasswordManagerTopic = "passwordmgr-storage-changed";
const kPasswordManagerTopicTypes = new Set([
"addLogin",
"modifyLogin",
]);
const kNotificationId = "abouthome-automigration-undo";
@@ -282,16 +285,24 @@ const AutoMigrate = {
return;
}
let win = target.ownerGlobal;
let notificationBox = win.gBrowser.getNotificationBox(target);
if (!notificationBox || notificationBox.getNotificationWithValue("abouthome-automigration-undo")) {
return;
}
+ // At this stage we're committed to show the prompt - unless we shouldn't,
+ // in which case we remove the undo prefs (which will cause canUndo() to
+ // return false from now on.):
+ if (!this.shouldStillShowUndoPrompt()) {
+ this.removeUndoOption();
+ return;
+ }
+
let removeNotification = () => {
let notification = notificationBox.getNotificationWithValue(kNotificationId);
notificationBox.removeNotification(notification, true);
};
let browserName = this.getBrowserUsedForMigration();
let message;
if (browserName) {
message = MigrationUtils.getLocalizedString("automigration.undo.message",
@@ -319,14 +330,31 @@ const AutoMigrate = {
},
];
notificationBox.appendNotification(
message, kNotificationId, null, notificationBox.PRIORITY_INFO_HIGH, buttons
);
});
},
+ shouldStillShowUndoPrompt() {
+ let date = new Date();
+ // Round down to midnight:
+ date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
+ let previousDateStr = Preferences.get(kAutoMigrateLastUndoPromptDatePref, "0");
+ let previousDate = new Date(parseInt(previousDateStr, 10));
+ if (previousDate < date) {
+ let remainingDays = Preferences.get(kAutoMigrateDaysToOfferUndoPref, 4) - 1;
+ Preferences.set(kAutoMigrateDaysToOfferUndoPref, remainingDays);
+ Preferences.set(kAutoMigrateLastUndoPromptDatePref, date.valueOf().toString());
+ if (remainingDays <= 0) {
+ return false;
+ }
+ }
+ return true;
+ },
+
QueryInterface: XPCOMUtils.generateQI(
[Ci.nsIObserver, Ci.nsINavBookmarkObserver, Ci.nsISupportsWeakReference]
),
};
AutoMigrate.init();