Bug 1221050 - part 5: create page for use with tabview migration, r=ttaubert
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 01 Dec 2015 10:48:10 +0000
changeset 309114 ecab64eb36359dd64f24632b8618b35249790ba8
parent 309113 375c7e394908716ec15c56d018a31a8886f74f23
child 309115 c7e233816aaad80639b32fbc79c8b5a1470f0778
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert
bugs1221050
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1221050 - part 5: create page for use with tabview migration, r=ttaubert
browser/base/content/aboutTabGroupsMigration.js
browser/base/content/aboutTabGroupsMigration.xhtml
browser/base/jar.mn
browser/components/sessionstore/content/aboutSessionRestore.js
browser/locales/en-US/chrome/browser/aboutSessionRestore.dtd
browser/modules/TabGroupsMigrator.jsm
new file mode 100644
--- /dev/null
+++ b/browser/base/content/aboutTabGroupsMigration.js
@@ -0,0 +1,63 @@
+/* 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/. */
+
+"use strict";
+
+
+Cu.import("resource:///modules/TabGroupsMigrator.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
+  "resource://gre/modules/PlacesUtils.jsm");
+
+const SUPPORT_URL = "https://support.mozilla.org/kb/tab-groups-removal";
+
+function fillInDescription() {
+  let descElement = document.getElementById("mainDescription");
+  let text = descElement.getAttribute("_description_label");
+  let learnMoreText = descElement.getAttribute("_learnmore_label");
+  let link = document.createElement("a");
+  link.href = SUPPORT_URL;
+  link.target = "_blank";
+  link.textContent = learnMoreText;
+  // We don't want to assign the label (plaintext, because we took it out of
+  // getAttribute, so html entities have been resolved) directly to innerHTML.
+  // Using a separate element and then using innerHTML on that would mean we
+  // depend on the HTML encoding (or lack thereof) of %S, which l10n tools
+  // might change.
+  // So instead, split the plaintext we have and create textNodes:
+  let nodes = text.split(/%S/).map(document.createTextNode.bind(document));
+  // then insert the link:
+  nodes.splice(1, 0, link);
+  // then append all of these in turn:
+  for (let node of nodes) {
+    descElement.appendChild(node);
+  }
+}
+
+let loadPromise = new Promise(resolve => {
+  let loadHandler = e => {
+    window.removeEventListener("DOMContentLoaded", loadHandler);
+    fillInDescription();
+    resolve();
+  };
+  window.addEventListener("DOMContentLoaded", loadHandler, false);
+});
+
+let tabGroupsBookmarkItemId;
+// If the session wasn't restored this run/session, this might be null.
+// Then we shouldn't show the button:
+if (TabGroupsMigrator.bookmarkedGroupsPromise) {
+  let bookmarkPromise = TabGroupsMigrator.bookmarkedGroupsPromise.then(bm => {
+    return PlacesUtils.promiseItemId(bm.guid);
+  }).then(itemId => { tabGroupsBookmarkItemId = itemId });
+
+  Promise.all([bookmarkPromise, loadPromise]).then(function() {
+    document.getElementById("show-migrated-bookmarks-button").style.removeProperty("display");
+  });
+}
+
+function showMigratedGroups() {
+  let browserWin = getBrowserWindow();
+  browserWin.PlacesCommandHook.showPlacesOrganizer(["BookmarksMenu", tabGroupsBookmarkItemId]);
+}
+
copy from browser/components/sessionstore/content/aboutSessionRestore.xhtml
copy to browser/base/content/aboutTabGroupsMigration.xhtml
--- a/browser/components/sessionstore/content/aboutSessionRestore.xhtml
+++ b/browser/base/content/aboutTabGroupsMigration.xhtml
@@ -12,41 +12,39 @@
   <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
   %globalDTD;
   <!ENTITY % restorepageDTD SYSTEM "chrome://browser/locale/aboutSessionRestore.dtd">
   %restorepageDTD;
 ]>
 
 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <head>
-    <title>&restorepage.tabtitle;</title>
+    <title>&tabgroupsmigration.tabtitle;</title>
     <link rel="stylesheet" href="chrome://global/skin/in-content/info-pages.css" type="text/css" media="all"/>
     <link rel="stylesheet" href="chrome://browser/skin/aboutSessionRestore.css" type="text/css" media="all"/>
     <link rel="icon" type="image/png" href="chrome://global/skin/icons/warning-16.png"/>
 
     <script type="application/javascript;version=1.8" src="chrome://browser/content/aboutSessionRestore.js"/>
+    <script type="application/javascript;version=1.8" src="chrome://browser/content/aboutTabGroupsMigration.js"/>
   </head>
 
   <body dir="&locale.dir;">
 
     <div class="container restore-chosen">
 
       <div class="title">
-        <h1 class="title-text">&restorepage.errorTitle;</h1>
+        <h1 class="title-text">&tabgroupsmigration.pagetitle;</h1>
       </div>
       <div class="description">
-        <p>&restorepage.problemDesc;</p>
+        <p id="mainDescription"
+           _learnmore_label="&tabgroupsmigration.learnMoreLink;"
+           _description_label="&tabgroupsmigration.description;"></p>
+        <button id="show-migrated-bookmarks-button" style="display:none" onclick="showMigratedGroups()">&tabgroupsmigration.bookmarkbutton;</button>
 
-        <div id="errorLongDesc">
-          <p>&restorepage.tryThis;</p>
-          <ul>
-            <li>&restorepage.restoreSome;</li>
-            <li>&restorepage.startNew;</li>
-          </ul>
-        </div>
+        <p>&tabgroupsmigration.restoredescription;</p>
       </div>
       <div class="tree-container" available="true">
         <xul:tree id="tabList" seltype="single" hidecolumnpicker="true"
               onclick="onListClick(event);" onkeydown="onListKeyDown(event);"
               _window_label="&restorepage.windowLabel;">
           <xul:treecols>
             <xul:treecol cycler="true" id="restore" type="checkbox" label="&restorepage.restoreHeader;"/>
             <xul:splitter class="tree-splitter"/>
--- a/browser/base/jar.mn
+++ b/browser/base/jar.mn
@@ -67,16 +67,18 @@ browser.jar:
 
         content/browser/aboutRobots-icon.png          (content/aboutRobots-icon.png)
         content/browser/aboutRobots-widget-left.png   (content/aboutRobots-widget-left.png)
         content/browser/aboutSocialError.xhtml        (content/aboutSocialError.xhtml)
         content/browser/aboutProviderDirectory.xhtml  (content/aboutProviderDirectory.xhtml)
         content/browser/aboutTabCrashed.css           (content/aboutTabCrashed.css)
         content/browser/aboutTabCrashed.js            (content/aboutTabCrashed.js)
         content/browser/aboutTabCrashed.xhtml         (content/aboutTabCrashed.xhtml)
+*       content/browser/aboutTabGroupsMigration.xhtml (content/aboutTabGroupsMigration.xhtml)
+        content/browser/aboutTabGroupsMigration.js    (content/aboutTabGroupsMigration.js)
 *       content/browser/browser.css                   (content/browser.css)
 *       content/browser/browser.js                    (content/browser.js)
 *       content/browser/browser.xul                   (content/browser.xul)
         content/browser/browser-addons.js             (content/browser-addons.js)
         content/browser/browser-ctrlTab.js            (content/browser-ctrlTab.js)
 *       content/browser/browser-customization.js      (content/browser-customization.js)
         content/browser/browser-data-submission-info-bar.js (content/browser-data-submission-info-bar.js)
 *       content/browser/browser-devedition.js         (content/browser-devedition.js)
--- a/browser/components/sessionstore/content/aboutSessionRestore.js
+++ b/browser/components/sessionstore/content/aboutSessionRestore.js
@@ -65,17 +65,17 @@ function initTreeView() {
     return;
   }
   var tabList = document.getElementById("tabList");
   var winLabel = tabList.getAttribute("_window_label");
 
   gTreeData = [];
   gStateObject.windows.forEach(function(aWinData, aIx) {
     var winState = {
-      label: winLabel.replace("%S", (aIx + 1)),
+      label: aWinData.tabGroupsMigrationTitle || winLabel.replace("%S", (aIx + 1)),
       open: true,
       checked: true,
       ix: aIx
     };
     winState.tabs = aWinData.tabs.map(function(aTabData) {
       var entry = aTabData.entries[aTabData.index - 1] || { url: "about:blank" };
       var iconURL = aTabData.attributes && aTabData.attributes.image || null;
       // don't initiate a connection just to fetch a favicon (see bug 462863)
--- a/browser/locales/en-US/chrome/browser/aboutSessionRestore.dtd
+++ b/browser/locales/en-US/chrome/browser/aboutSessionRestore.dtd
@@ -43,8 +43,22 @@ welcomeback2.afterlink.pageInfo2): these
 before and after the the "learn more" link (welcomeback2.link.pageInfo2).
 Localizers can use one of them, or both, to better adapt this sentence to
 their language.
 -->
 <!ENTITY welcomeback2.beforelink.pageInfo2  "Your add-ons and customizations have been removed and your browser settings have been restored to their defaults. If this didn't fix your issue, ">
 <!ENTITY welcomeback2.afterlink.pageInfo2   "">
 
 <!ENTITY welcomeback2.link.pageInfo2        "learn more about what you can do.">
+
+<!-- LOCALIZATION NOTE: The following 'tabgroupsmigration' strings are for
+     the tab groups (panorama) migration page, not about:sessionrestore -->
+<!ENTITY tabgroupsmigration.tabtitle            "Migrate your other Tab Groups">
+<!ENTITY tabgroupsmigration.pagetitle           "Tab Groups are no more. Sorry.">
+<!-- LOCALIZATION NOTE (tabgroupsmigration.learnMoreLink):
+     This is inserted into tabgroupsmigration.description. -->
+<!ENTITY tabgroupsmigration.learnMoreLink       "Learn More">
+<!-- LOCALIZATION NOTE (tabgroupsmigration.description):
+     &#37;S will be replaced with a link labeled with tabgroupsmigration.learnMoreLink -->
+<!ENTITY tabgroupsmigration.description         "&brandShortName; has bookmarked all your groups, so you have not lost anything. &#37;S">
+<!ENTITY tabgroupsmigration.bookmarkbutton      "Show Bookmarked Tab Groups">
+<!ENTITY tabgroupsmigration.restoredescription  "You can also choose to restore some or all background groups into windows now:">
+
--- a/browser/modules/TabGroupsMigrator.jsm
+++ b/browser/modules/TabGroupsMigrator.jsm
@@ -15,16 +15,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "AsyncShutdown", "resource://gre/modules/AsyncShutdown.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "gBrowserBundle", function() {
   return Services.strings.createBundle('chrome://browser/locale/browser.properties');
 });
 
+const RECOVERY_URL = "chrome://browser/content/aboutTabGroupsMigration.xhtml";
+
 
 this.TabGroupsMigrator = {
   bookmarkedGroupsPromise: null,
 
   /**
    * If this state contains tab groups, migrate the user's data. This means:
    * - make a backup of the user's data.
    * - create bookmarks of all the user's tab groups in a single folder
@@ -230,12 +232,16 @@ this.TabGroupsMigrator = {
           delete win.extData;
         }
       }
     }
     return stateToReturn;
   },
 
   _createBackgroundTabGroupRestorationPage(state, backgroundData) {
-    // TODO
+    let win = state.windows[(state.selectedWindow || 1) - 1];
+    let formdata = {id: {sessionData: JSON.stringify(backgroundData)}, url: RECOVERY_URL};
+    let newTab = { entries: [{url: RECOVERY_URL}], formdata, index: 1 };
+    // Add tab and mark it as selected:
+    win.selected = win.tabs.push(newTab);
   },
 };