Bug 1706027 - Perform readability check immediately when coming from the BFCache. r=Gijs

Pages that come from the BFCache are already laid out and so a
main-thread paint is not guaranteed to happen.

Before the Fission+BFCache implementation, browser_readerMode.js didn't
trigger the bfcache codepath, so we were getting a paint fast enough
when leaving reader mode.

Differential Revision: https://phabricator.services.mozilla.com/D112527
This commit is contained in:
Emilio Cobos Álvarez 2021-04-19 10:27:13 +00:00
Родитель 468eca32ee
Коммит b063ff13cb
1 изменённых файлов: 19 добавлений и 13 удалений

Просмотреть файл

@ -127,16 +127,14 @@ class AboutReaderChild extends JSWindowActorChild {
this.sendAsyncMessage("Reader:UpdateReaderButton", { this.sendAsyncMessage("Reader:UpdateReaderButton", {
isArticle: this._isLeavingReaderableReaderMode, isArticle: this._isLeavingReaderableReaderMode,
}); });
if (this._isLeavingReaderableReaderMode) { this._isLeavingReaderableReaderMode = false;
this._isLeavingReaderableReaderMode = false;
}
break; break;
case "pageshow": case "pageshow":
// If a page is loaded from the bfcache, we won't get a "DOMContentLoaded" // 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. // event, so we need to rely on "pageshow" in this case.
if (aEvent.persisted) { if (aEvent.persisted && this.canDoReadabilityCheck()) {
this.updateReaderButton(); this.performReadabilityCheckNow();
} }
break; break;
} }
@ -149,20 +147,24 @@ class AboutReaderChild extends JSWindowActorChild {
* painted is not going to work. * painted is not going to work.
*/ */
updateReaderButton(forceNonArticle) { updateReaderButton(forceNonArticle) {
if ( if (!this.canDoReadabilityCheck()) {
!Readerable.isEnabledForParseOnLoad ||
this.isAboutReader ||
!this.contentWindow ||
!this.contentWindow.windowRoot ||
!(this.document instanceof this.contentWindow.HTMLDocument) ||
this.document.mozSyntheticDocument
) {
return; return;
} }
this.scheduleReadabilityCheckPostPaint(forceNonArticle); this.scheduleReadabilityCheckPostPaint(forceNonArticle);
} }
canDoReadabilityCheck() {
return (
Readerable.isEnabledForParseOnLoad &&
!this.isAboutReader &&
this.contentWindow &&
this.contentWindow.windowRoot &&
this.document instanceof this.contentWindow.HTMLDocument &&
!this.document.mozSyntheticDocument
);
}
cancelPotentialPendingReadabilityCheck() { cancelPotentialPendingReadabilityCheck() {
if (this._pendingReadabilityCheck) { if (this._pendingReadabilityCheck) {
if (this._listenerWindow) { if (this._listenerWindow) {
@ -204,6 +206,10 @@ class AboutReaderChild extends JSWindowActorChild {
return; return;
} }
this.performReadabilityCheckNow(forceNonArticle);
}
performReadabilityCheckNow(forceNonArticle) {
this.cancelPotentialPendingReadabilityCheck(); this.cancelPotentialPendingReadabilityCheck();
// Ignore errors from actors that have been unloaded before the // Ignore errors from actors that have been unloaded before the