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 263438 d6f1397b35639de21d82e599ae439f45226d7b3d
parent 263437 911e01832a4aec58d23b255d99217a64a07dcb23
child 263439 920b6513a1260fc115df17a7a5648a3c9c6b093e
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1145259
milestone39.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 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 });
     }