Bug 1184950 - Use goBack to leave the reader view when possible, r=margaret
☠☠ backed out by d0c2f09a6285 ☠ ☠
authorTimothy Guan-tin Chien <timdream@gmail.com>
Thu, 14 Apr 2016 15:54:53 -0700
changeset 331304 3c369626af41eec1fc9a3f145a6ddb0d4c475c31
parent 331303 a78ccb08a836784ac24b25b68d833af95b96a5bd
child 331305 7b9fbf34a1d6c4a4a54486b64f2be9c8b304401d
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1184950
milestone48.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 1184950 - Use goBack to leave the reader view when possible, r=margaret MozReview-Commit-ID: G9wn4OyUL5q
browser/base/content/tab-content.js
browser/base/content/test/general/browser_bug1124271_readerModePinnedTab.js
browser/base/content/test/general/browser_readerMode.js
browser/modules/ReaderParent.jsm
--- a/browser/base/content/tab-content.js
+++ b/browser/base/content/tab-content.js
@@ -246,25 +246,42 @@ var AboutReaderListener = {
 
   _articlePromise: null,
 
   init: function() {
     addEventListener("AboutReaderContentLoaded", this, false, true);
     addEventListener("DOMContentLoaded", this, false);
     addEventListener("pageshow", this, false);
     addEventListener("pagehide", this, false);
-    addMessageListener("Reader:ParseDocument", this);
+    addMessageListener("Reader:ToggleReaderMode", this);
     addMessageListener("Reader:PushState", this);
   },
 
   receiveMessage: function(message) {
     switch (message.name) {
-      case "Reader:ParseDocument":
-        this._articlePromise = ReaderMode.parseDocument(content.document).catch(Cu.reportError);
-        content.document.location = "about:reader?url=" + encodeURIComponent(message.data.url);
+      case "Reader:ToggleReaderMode":
+        let url = content.document.location.href;
+        if (!this.isAboutReader) {
+          this._articlePromise = ReaderMode.parseDocument(content.document).catch(Cu.reportError);
+          content.document.location = "about:reader?url=" + encodeURIComponent(url);
+        } else {
+          let originalURL = ReaderMode.getOriginalUrl(url);
+          let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
+          let sh = webNav.sessionHistory;
+          if (webNav.canGoBack) {
+            let prevEntry = sh.getEntryAtIndex(sh.index - 1, false);
+            let prevURL = prevEntry.URI.spec;
+            if (prevURL && (prevURL == originalURL || !originalURL)) {
+              webNav.goBack();
+              break;
+            }
+          }
+
+          content.document.location = originalURL;
+        }
         break;
 
       case "Reader:PushState":
         this.updateReaderButton(!!(message.data && message.data.isArticle));
         break;
     }
   },
 
--- a/browser/base/content/test/general/browser_bug1124271_readerModePinnedTab.js
+++ b/browser/base/content/test/general/browser_bug1124271_readerModePinnedTab.js
@@ -33,15 +33,15 @@ add_task(function* () {
 
   readerButton.click();
   yield promiseTabLoadEvent(tab);
 
   // Ensure no new tabs are opened when exiting reader mode in a pinned tab
   is(gBrowser.tabs.length, initialTabsCount, "No additional tabs were opened.");
 
   readerButton.click();
-  yield promiseTabLoadEvent(tab);
+  yield promiseTabLoadEvent(tab, "", "pageshow");
 
   // Ensure no new tabs are opened when exiting reader mode in a pinned tab
   is(gBrowser.tabs.length, initialTabsCount, "No additional tabs were opened.");
 
   gBrowser.removeCurrentTab();
 });
--- a/browser/base/content/test/general/browser_readerMode.js
+++ b/browser/base/content/test/general/browser_readerMode.js
@@ -66,19 +66,21 @@ add_task(function* test_reader_button() 
       gURLBar.focus();
       gURLBar.select();
       goDoCommand("cmd_copy");
     }, resolve, reject);
   });
 
   // Switch page back out of reader mode.
   readerButton.click();
-  yield promiseTabLoadEvent(tab);
+  yield promiseTabLoadEvent(tab, "", "pageshow");
   is(gBrowser.selectedBrowser.currentURI.spec, url,
-    "Original page loaded after clicking active reader mode button");
+    "Back to the original page after clicking active reader mode button");
+  ok(gBrowser.selectedBrowser.canGoForward,
+    "Moved one step back in the session history.");
 
   // Load a new tab that is NOT reader-able.
   let newTab = gBrowser.selectedTab = gBrowser.addTab();
   yield promiseTabLoadEvent(newTab, "about:robots");
   yield promiseWaitForCondition(() => readerButton.hidden);
   is_element_hidden(readerButton, "Reader mode button is not present on a non-reader-able page");
 
   // Switch back to the original tab to make sure reader mode button is still visible.
--- a/browser/modules/ReaderParent.jsm
+++ b/browser/modules/ReaderParent.jsm
@@ -128,28 +128,17 @@ var ReaderParent = {
       return;
     }
     this.toggleReaderMode(event);
   },
 
   toggleReaderMode: function(event) {
     let win = event.target.ownerDocument.defaultView;
     let browser = win.gBrowser.selectedBrowser;
-    let url = browser.currentURI.spec;
-
-    if (url.startsWith("about:reader")) {
-      let originalURL = ReaderMode.getOriginalUrl(url);
-      if (!originalURL) {
-        Cu.reportError("Error finding original URL for about:reader URL: " + url);
-      } else {
-        win.openUILinkIn(originalURL, "current", {"allowPinnedTabHostChange": true});
-      }
-    } else {
-      browser.messageManager.sendAsyncMessage("Reader:ParseDocument", { url: url });
-    }
+    browser.messageManager.sendAsyncMessage("Reader:ToggleReaderMode");
   },
 
   /**
    * Shows an info panel from the UITour for Reader Mode.
    *
    * @param browser The <browser> that the tour should be started for.
    */
   showReaderModeInfoPanel(browser) {