Bug 1271511 - keep reader mode icon visible when exiting from reader mode to source page. r=ahunt
authordanhuang1202 <danhuang1202@gmail.com>
Tue, 10 May 2016 11:28:07 +0800
changeset 297739 b4173da43e6a3e10ddd2d5d0809dcffc61cf0e6f
parent 297738 1633fe6e9c8159ef9ba25ab9192902a2d8d214ae
child 297740 60657d0353e413b327dcfa38b9af32d0c6af6f48
push id30266
push userryanvm@gmail.com
push dateWed, 18 May 2016 15:57:57 +0000
treeherdermozilla-central@47b83c8478a0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt
bugs1271511
milestone49.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 1271511 - keep reader mode icon visible when exiting from reader mode to source page. r=ahunt MozReview-Commit-ID: JxNRdXCSFGx
mobile/android/chrome/content/content.js
--- a/mobile/android/chrome/content/content.js
+++ b/mobile/android/chrome/content/content.js
@@ -17,16 +17,18 @@ var dump = Cu.import("resource://gre/mod
 
 var global = this;
 
 // This is copied from desktop's tab-content.js. See bug 1153485 about sharing this code somehow.
 var AboutReaderListener = {
 
   _articlePromise: null,
 
+  _isLeavingReaderMode: false,
+
   init: function() {
     addEventListener("AboutReaderContentLoaded", this, false, true);
     addEventListener("DOMContentLoaded", this, false);
     addEventListener("pageshow", this, false);
     addEventListener("pagehide", this, false);
     addMessageListener("Reader:ToggleReaderMode", this);
     addMessageListener("Reader:PushState", this);
   },
@@ -34,16 +36,17 @@ var AboutReaderListener = {
   receiveMessage: function(message) {
     switch (message.name) {
       case "Reader:ToggleReaderMode":
         let url = content.document.location.href;
         if (!this.isAboutReader) {
           this._articlePromise = ReaderMode.parseDocument(content.document).catch(Cu.reportError);
           ReaderMode.enterReaderMode(docShell, content);
         } else {
+          this._isLeavingReaderMode = true;
           ReaderMode.leaveReaderMode(docShell, content);
         }
         break;
 
       case "Reader:PushState":
         this.updateReaderButton(!!(message.data && message.data.isArticle));
         break;
     }
@@ -70,17 +73,23 @@ var AboutReaderListener = {
         // valid message will follow. See bug 925983.
         if (content.document.body) {
           new AboutReader(global, content, this._articlePromise);
           this._articlePromise = null;
         }
         break;
 
       case "pagehide":
-        sendAsyncMessage("Reader:UpdateReaderButton", { isArticle: false });
+        // this._isLeavingReaderMode is used here to keep the Reader Mode icon
+        // visible in the location bar when transitioning from reader-mode page
+        // back to the source page.
+        sendAsyncMessage("Reader:UpdateReaderButton", { isArticle: this._isLeavingReaderMode });
+        if (this._isLeavingReaderMode) {
+          this._isLeavingReaderMode = false;
+        }
         break;
 
       case "pageshow":
         // If a page is loaded from the bfcache, we won't get a "DOMContentLoaded"
         // event, so we need to rely on "pageshow" in this case.
         if (aEvent.persisted) {
           this.updateReaderButton();
         }