mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Bug 1146666 - fix reader mode button's dealing with history.pushState, r=margaret
--HG-- extra : rebase_source : 7e319675091bebc7f48d0683058195cfdecbeabe
This commit is contained in:
parent
0d23218b13
commit
332d99565c
@ -4553,8 +4553,12 @@ var TabsProgressListener = {
|
||||
aFlags) {
|
||||
// Filter out location changes caused by anchor navigation
|
||||
// or history.push/pop/replaceState.
|
||||
if (aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT)
|
||||
if (aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT) {
|
||||
// Reader mode actually cares about these:
|
||||
let mm = gBrowser.selectedBrowser.messageManager;
|
||||
mm.sendAsyncMessage("Reader:PushState");
|
||||
return;
|
||||
}
|
||||
|
||||
// Filter out location changes in sub documents.
|
||||
if (!aWebProgress.isTopLevel)
|
||||
|
@ -489,6 +489,7 @@ let AboutReaderListener = {
|
||||
addEventListener("pageshow", this, false);
|
||||
addEventListener("pagehide", this, false);
|
||||
addMessageListener("Reader:ParseDocument", this);
|
||||
addMessageListener("Reader:PushState", this);
|
||||
},
|
||||
|
||||
receiveMessage: function(message) {
|
||||
@ -497,6 +498,10 @@ let AboutReaderListener = {
|
||||
this._articlePromise = ReaderMode.parseDocument(content.document).catch(Cu.reportError);
|
||||
content.document.location = "about:reader?url=" + encodeURIComponent(message.data.url);
|
||||
break;
|
||||
|
||||
case "Reader:PushState":
|
||||
this.updateReaderButton();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
@ -530,19 +535,23 @@ let AboutReaderListener = {
|
||||
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;
|
||||
if (aEvent.persisted) {
|
||||
this.updateReaderButton();
|
||||
}
|
||||
// Fall through.
|
||||
break;
|
||||
case "DOMContentLoaded":
|
||||
if (!ReaderMode.isEnabledForParseOnLoad || this.isAboutReader) {
|
||||
return;
|
||||
}
|
||||
this.updateReaderButton();
|
||||
break;
|
||||
|
||||
let isArticle = ReaderMode.isProbablyReaderable(content.document);
|
||||
sendAsyncMessage("Reader:UpdateReaderButton", { isArticle: isArticle });
|
||||
}
|
||||
}
|
||||
},
|
||||
updateReaderButton: function() {
|
||||
if (!ReaderMode.isEnabledForParseOnLoad || this.isAboutReader) {
|
||||
return;
|
||||
}
|
||||
let isArticle = ReaderMode.isProbablyReaderable(content.document);
|
||||
sendAsyncMessage("Reader:UpdateReaderButton", { isArticle: isArticle });
|
||||
},
|
||||
};
|
||||
AboutReaderListener.init();
|
||||
|
||||
|
@ -68,7 +68,7 @@ this.ReaderMode = {
|
||||
* @return boolean Whether or not we should show the reader mode button.
|
||||
*/
|
||||
isProbablyReaderable: function(doc) {
|
||||
let uri = Services.io.newURI(doc.documentURI, null, null);
|
||||
let uri = Services.io.newURI(doc.location.href, null, null);
|
||||
|
||||
if (!this._shouldCheckUri(uri)) {
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user