Bug 1145259 - Add pageshow listener to check whether or not to show reader button when DOMContentLoaded doesn't fire. r=Gijs
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Thu, 19 Mar 2015 11:44:07 -0700
changeset 251842 d6f1397b35639de21d82e599ae439f45226d7b3d
parent 251841 911e01832a4aec58d23b255d99217a64a07dcb23
child 251845 920b6513a1260fc115df17a7a5648a3c9c6b093e
push id1156
push userpbrosset@mozilla.com
push dateFri, 20 Mar 2015 16:00:24 +0000
reviewersGijs
bugs1145259
milestone39.0a1
Bug 1145259 - Add pageshow listener to check whether or not to show reader button when DOMContentLoaded doesn't fire. r=Gijs
browser/base/content/content.js
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -481,16 +481,17 @@ AboutHomeListener.init(this);
 
 let 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);
   },
 
   receiveMessage: function(message) {
     switch (message.name) {
       case "Reader:ParseDocument":
         this._articlePromise = ReaderMode.parseDocument(content.document).catch(Cu.reportError);
@@ -520,16 +521,23 @@ let AboutReaderListener = {
           new AboutReader(global, content, this._articlePromise);
         }
         break;
 
       case "pagehide":
         sendAsyncMessage("Reader:UpdateReaderButton", { isArticle: 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) {
+          break;
+        }
+        // Fall through.
       case "DOMContentLoaded":
         if (!ReaderMode.isEnabledForParseOnLoad || this.isAboutReader) {
           return;
         }
 
         let isArticle = ReaderMode.isProbablyReaderable(content.document);
         sendAsyncMessage("Reader:UpdateReaderButton", { isArticle: isArticle });
     }