Bug 663622 - notify the user that session restore was enabled; r=dolske, ui-r=limi
authorTim Taubert <tim.taubert@gmx.de>
Wed, 13 Jul 2011 10:36:13 -0700
changeset 72591 3dba1aa7adc743ac2ede761a28c22f22b37f06ae
parent 72590 ca686ff1621f564524096f466d6a57d3cc34d375
child 72592 8c1f92fdd9fb2533aea0b41bfa813c8ee33962b2
push id29
push usertim.taubert@gmx.de
push dateWed, 13 Jul 2011 17:38:51 +0000
treeherderfx-team@cbeda84b1a5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske, limi
bugs663622
milestone8.0a1
Bug 663622 - notify the user that session restore was enabled; r=dolske, ui-r=limi
browser/base/content/browser-tabview.js
browser/base/content/tabview/tabview.css
browser/base/content/tabview/ui.js
browser/base/content/test/tabview/browser_tabview_bug656778.js
browser/locales/en-US/chrome/browser/tabview.properties
--- a/browser/base/content/browser-tabview.js
+++ b/browser/base/content/browser-tabview.js
@@ -430,12 +430,17 @@ let TabView = {
       return;
 
     // do nothing if we already enabled session restore once
     if (this.sessionRestoreEnabledOnce)
       return;
 
     this.sessionRestoreEnabledOnce = true;
 
-    // enable session restore
-    Services.prefs.setIntPref(this.PREF_STARTUP_PAGE, 3);
+    // enable session restore if necessary
+    if (Services.prefs.getIntPref(this.PREF_STARTUP_PAGE) != 3) {
+      Services.prefs.setIntPref(this.PREF_STARTUP_PAGE, 3);
+
+      // show banner
+      this._window.UI.notifySessionRestoreEnabled();
+    }
   }
 };
--- a/browser/base/content/tabview/tabview.css
+++ b/browser/base/content/tabview/tabview.css
@@ -173,16 +173,30 @@ body {
 .shield {
   left: 0;
   top: 0;
   width: 100%;
   height: 100%;
   position: absolute;
 }
 
+.banner {
+  left: 0;
+  bottom: 0;
+  right: 0;
+  padding: 10px 0;
+  position: absolute;
+  z-index: 1000060;
+  background: #000;
+  color: #fff;
+  opacity: 0;
+  text-align: center;
+  font-weight: 700;
+}
+
 /* Resizable
 ----------------------------------*/
 .resizer {
   position: absolute;
 }
 
 .iq-resizable-handle {
   position: absolute;
--- a/browser/base/content/tabview/ui.js
+++ b/browser/base/content/tabview/ui.js
@@ -1563,13 +1563,42 @@ let UI = {
 
     // use the tab image if it doesn't start with http e.g. data:image/png, chrome://
     if (tab.image && !(/^https?:/.test(tab.image)))
       url = tab.image;
     else
       url = gFavIconService.getFaviconImageForPage(tab.linkedBrowser.currentURI).spec;
 
     return url;
+  },
+
+  // ----------
+  // Function: notifySessionRestoreEnabled
+  // Notify the user that session restore has been automatically enabled
+  // by showing a banner that expects no user interaction. It fades out after
+  // some seconds.
+  notifySessionRestoreEnabled: function UI_notifySessionRestoreEnabled() {
+    let brandBundle = gWindow.document.getElementById("bundle_brand");
+    let brandShortName = brandBundle.getString("brandShortName");
+    let notificationText = tabviewBundle.formatStringFromName(
+      "tabview.notification.sessionStore", [brandShortName], 1);
+
+    let banner = iQ("<div>")
+      .text(notificationText)
+      .addClass("banner")
+      .appendTo("body");
+
+    let onFadeOut = function () {
+      banner.remove();
+    };
+
+    let onFadeIn = function () {
+      setTimeout(function () {
+        banner.animate({opacity: 0}, {duration: 1500, complete: onFadeOut});
+      }, 5000);
+    };
+
+    banner.animate({opacity: 0.7}, {duration: 1500, complete: onFadeIn});
   }
 };
 
 // ----------
 UI.init();
--- a/browser/base/content/test/tabview/browser_tabview_bug656778.js
+++ b/browser/base/content/test/tabview/browser_tabview_bug656778.js
@@ -25,16 +25,26 @@ function test() {
   };
 
   let assertPreferences = function (startupPage, firstRun, enabledOnce) {
     assertIntPref(TabView.PREF_STARTUP_PAGE, startupPage);
     assertBoolPref(TabView.PREF_FIRST_RUN, firstRun);
     assertBoolPref(TabView.PREF_RESTORE_ENABLED_ONCE, enabledOnce);
   };
 
+  let assertNotificationBannerVisible = function (win) {
+    let cw = win.TabView.getContentWindow();
+    is(cw.iQ(".banner").length, 1, "notification banner is visible");
+  };
+
+  let assertNotificationBannerNotVisible = function (win) {
+    let cw = win.TabView.getContentWindow();
+    is(cw.iQ(".banner").length, 0, "notification banner is not visible");
+  };
+
   let next = function () {
     if (tests.length == 0) {
       waitForFocus(finish);
       return;
     }
 
     let test = tests.shift();
     info("running " + test.name + "...");
@@ -47,16 +57,17 @@ function test() {
   //
   // Expected result:
   // When entering Panorma session restore will be enabled and a notification
   // banner is shown.
   let test1 = function test1() {
     setPreferences(1, true, false);
 
     newWindowWithTabView(function (win) {
+      assertNotificationBannerVisible(win);
       assertPreferences(3, true, true);
 
       win.close();
       next();
     });
   };
 
   // State:
@@ -67,20 +78,22 @@ function test() {
   // Expected result:
   // When entering Panorma nothing happens. When we detect that Panorama is
   // really used (firstUseExperienced = true) we notify that session restore
   // is now enabled.
   let test2 = function test2() {
     setPreferences(1, false, false);
 
     newWindowWithTabView(function (win) {
+      assertNotificationBannerNotVisible(win);
       assertPreferences(1, false, false);
 
       win.TabView.firstUseExperienced = true;
 
+      assertNotificationBannerVisible(win);
       assertPreferences(3, true, true);
 
       win.close();
       next();
     });
   };
 
   // State:
@@ -89,16 +102,17 @@ function test() {
   //
   // Expected result:
   // When entering Panorama nothing happens because session store is already
   // enabled so there's no reason to notify.
   let test3 = function test3() {
     setPreferences(3, true, false);
 
     newWindowWithTabView(function (win) {
+      assertNotificationBannerNotVisible(win);
       assertPreferences(3, true, true);
 
       win.close();
       next();
     });
   };
 
   // State:
@@ -106,16 +120,17 @@ function test() {
   // restore has been automatically activated.
   //
   // Expected result:
   // When entering Panorama nothing happens.
   let test4 = function test4() {
     setPreferences(3, true, true);
 
     newWindowWithTabView(function (win) {
+      assertNotificationBannerNotVisible(win);
       assertPreferences(3, true, true);
 
       win.close();
       next();
     });
   };
 
   // State:
@@ -124,16 +139,17 @@ function test() {
   // disabled by the user so we won't touch that again.
   //
   // Expected result:
   // When entering Panorama nothing happens and we didn't enable session restore.
   let test5 = function test5() {
     setPreferences(1, true, true);
 
     newWindowWithTabView(function (win) {
+      assertNotificationBannerNotVisible(win);
       assertPreferences(1, true, true);
 
       win.close();
       next();
     });
   };
 
   let tests = [test1, test2, test3, test4, test5];
--- a/browser/locales/en-US/chrome/browser/tabview.properties
+++ b/browser/locales/en-US/chrome/browser/tabview.properties
@@ -1,4 +1,5 @@
 tabview.groupItem.newTabButton=New tab
 tabview.groupItem.defaultName=Name this tab group…
 tabview.groupItem.undoCloseGroup=Undo Close Group
 tabview.search.otherWindowTabs=Tabs from other windows
+tabview.notification.sessionStore=Tabs and groups will automatically be restored the next time you start %S.