Bug 1134363 - Have Reader Mode use the same tab title as the normal browser view. r=niklas,mtigley

Differential Revision: https://phabricator.services.mozilla.com/D142281
This commit is contained in:
Tyler Kabaker 2022-04-11 20:24:25 +00:00
Родитель 9fa173af5f
Коммит 0736faf568
3 изменённых файлов: 20 добавлений и 4 удалений

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

@ -23,6 +23,7 @@ ChromeUtils.defineModuleGetter(
); );
var gUrlsToDocContentType = new Map(); var gUrlsToDocContentType = new Map();
var gUrlsToDocTitle = new Map();
class AboutReaderChild extends JSWindowActorChild { class AboutReaderChild extends JSWindowActorChild {
constructor() { constructor() {
@ -53,6 +54,7 @@ class AboutReaderChild extends JSWindowActorChild {
this.document.URL, this.document.URL,
this.document.contentType this.document.contentType
); );
gUrlsToDocTitle.set(this.document.URL, this.document.title);
this._articlePromise = ReaderMode.parseDocument(this.document).catch( this._articlePromise = ReaderMode.parseDocument(this.document).catch(
Cu.reportError Cu.reportError
); );
@ -133,10 +135,12 @@ class AboutReaderChild extends JSWindowActorChild {
? "text/plain" ? "text/plain"
: "document"; : "document";
let docTitle = gUrlsToDocTitle.get(url);
this._reader = new AboutReader( this._reader = new AboutReader(
this, this,
this._articlePromise, this._articlePromise,
docContentType docContentType,
docTitle
); );
this._articlePromise = null; this._articlePromise = null;
} }

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

@ -1595,7 +1595,7 @@
}, },
_setTabLabel(aTab, aLabel, { beforeTabOpen, isContentTitle } = {}) { _setTabLabel(aTab, aLabel, { beforeTabOpen, isContentTitle } = {}) {
if (!aLabel) { if (!aLabel || aLabel.includes("about:reader?")) {
return false; return false;
} }

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

@ -47,7 +47,12 @@ const zoomOnMeta =
Services.prefs.getIntPref("mousewheel.with_meta.action", 1) == 3; Services.prefs.getIntPref("mousewheel.with_meta.action", 1) == 3;
const isAppLocaleRTL = Services.locale.isAppLocaleRTL; const isAppLocaleRTL = Services.locale.isAppLocaleRTL;
var AboutReader = function(actor, articlePromise, docContentType = "document") { var AboutReader = function(
actor,
articlePromise,
docContentType = "document",
docTitle = ""
) {
let win = actor.contentWindow; let win = actor.contentWindow;
let url = this._getOriginalUrl(win); let url = this._getOriginalUrl(win);
if ( if (
@ -73,6 +78,8 @@ var AboutReader = function(actor, articlePromise, docContentType = "document") {
} }
doc.documentElement.setAttribute("platform", AppConstants.platform); doc.documentElement.setAttribute("platform", AppConstants.platform);
doc.title = docTitle;
this._actor = actor; this._actor = actor;
this._isLoggedInPocketUser = undefined; this._isLoggedInPocketUser = undefined;
@ -1074,7 +1081,12 @@ AboutReader.prototype = {
article.readingTimeMinsSlow, article.readingTimeMinsSlow,
article.readingTimeMinsFast article.readingTimeMinsFast
); );
// If a document title was not provided in the constructor, we'll fall back
// to using the article title.
if (!this._doc.title) {
this._doc.title = article.title; this._doc.title = article.title;
}
this._containerElement.setAttribute("lang", article.lang); this._containerElement.setAttribute("lang", article.lang);