Bug 1271511 - keep reader mode icon visible when exiting from reader mode to source page. r?Margaret draft
authordanhuang1202 <danhuang1202@gmail.com>
Tue, 10 May 2016 11:28:07 +0800
changeset 365113 5ef2bcf779aeb185da7c408b2e98fbb1591abde0
parent 364815 043082cb7bd8490c60815f67fbd1f33323ad7663
child 520465 4792e3c84d297823d09628468756f38904f886a4
push id17646
push userbmo:dhuang@mozilla.com
push dateTue, 10 May 2016 04:00:25 +0000
reviewersMargaret
bugs1271511
milestone49.0a1
Bug 1271511 - keep reader mode icon visible when exiting from reader mode to source page. r?Margaret 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();
         }