This is an automated email from the git hooks/post-receive script.
richard pushed a commit to branch tor-browser-91.9esr-11.0-1 in repository tor-browser.
commit 9b1a5a12a081a1115244a4cfc3b0968e7b973a10 Author: Gijs Kruitbosch gijskruitbosch@gmail.com AuthorDate: Mon Apr 25 20:05:55 2022 +0000
Bug 1692655. r=nika,mtigley,smaug a=RyanVM
Differential Revision: https://phabricator.services.mozilla.com/D144618 --- browser/actors/AboutReaderParent.jsm | 7 +++ toolkit/components/reader/AboutReader.jsm | 7 ++- toolkit/components/reader/ReaderMode.jsm | 73 +++++++++---------------------- 3 files changed, 33 insertions(+), 54 deletions(-)
diff --git a/browser/actors/AboutReaderParent.jsm b/browser/actors/AboutReaderParent.jsm index 8c01daf1df2dd..8f45088d4bed1 100644 --- a/browser/actors/AboutReaderParent.jsm +++ b/browser/actors/AboutReaderParent.jsm @@ -157,6 +157,13 @@ class AboutReaderParent extends JSWindowActorParent { break; }
+ case "RedirectTo": { + gCachedArticles.set(message.data.newURL, message.data.article); + // This is setup as a query so we can navigate the page after we've + // cached the relevant info in the parent. + return true; + } + default: this.callListeners(message); break; diff --git a/toolkit/components/reader/AboutReader.jsm b/toolkit/components/reader/AboutReader.jsm index 0da0ab1b0ace9..73b00bfe6f92a 100644 --- a/toolkit/components/reader/AboutReader.jsm +++ b/toolkit/components/reader/AboutReader.jsm @@ -767,7 +767,12 @@ AboutReader.prototype = { try { article = await ReaderMode.downloadAndParseDocument(url); } catch (e) { - if (e && e.newURL) { + if (e?.newURL && this._actor) { + await this._actor.sendQuery("RedirectTo", { + newURL: e.newURL, + article: e.article, + }); + let readerURL = "about:reader?url=" + encodeURIComponent(e.newURL); this._win.location.replace(readerURL); return; diff --git a/toolkit/components/reader/ReaderMode.jsm b/toolkit/components/reader/ReaderMode.jsm index 7422b036ca652..e36816c10ed76 100644 --- a/toolkit/components/reader/ReaderMode.jsm +++ b/toolkit/components/reader/ReaderMode.jsm @@ -135,7 +135,7 @@ var ReaderMode = { });
let url = win.document.location.href; - let originalURL = ReaderMode.getOriginalUrl(url); + let originalURL = this.getOriginalUrl(url); let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
if (!Services.appinfo.sessionHistoryInParent) { @@ -219,7 +219,7 @@ var ReaderMode = { },
getOriginalUrlObjectForDisplay(url) { - let originalUrl = ReaderMode.getOriginalUrl(url); + let originalUrl = this.getOriginalUrl(url); if (originalUrl) { let uriObj; try { @@ -264,10 +264,11 @@ var ReaderMode = { * @resolves JS object representing the article, or null if no article is found. */ async downloadAndParseDocument(url) { - let doc = await this._downloadDocument(url); - if (!doc) { + let result = await this._downloadDocument(url); + if (!result?.doc) { return null; } + let { doc, newURL } = result; if ( !Readerable.shouldCheckUri(doc.documentURIObject) || !Readerable.shouldCheckUri(doc.baseURIObject, true) @@ -276,7 +277,14 @@ var ReaderMode = { return null; }
- return this._readerParse(doc); + let article = await this._readerParse(doc); + // If we have to redirect, reject to the caller with the parsed article, + // so we can update the URL before displaying it. + if (newURL) { + return Promise.reject({ newURL, article }); + } + // Otherwise, we can just continue with the article. + return article; },
_downloadDocument(url) { @@ -312,48 +320,6 @@ var ReaderMode = { return; }
- // Manually follow a meta refresh tag if one exists. - let meta = doc.querySelector("meta[http-equiv=refresh]"); - if (meta) { - let content = meta.getAttribute("content"); - if (content) { - let urlIndex = content.toUpperCase().indexOf("URL="); - if (urlIndex > -1) { - let baseURI = Services.io.newURI(url); - let newURI = Services.io.newURI( - content.substring(urlIndex + 4), - null, - baseURI - ); - let newURL = newURI.spec; - let ssm = Services.scriptSecurityManager; - let flags = - ssm.LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT | - ssm.DISALLOW_INHERIT_PRINCIPAL; - try { - ssm.checkLoadURIStrWithPrincipal( - doc.nodePrincipal, - newURL, - flags - ); - } catch (ex) { - let errorMsg = - "Reader mode disallowed meta refresh (reason: " + ex + ")."; - - if (Services.prefs.getBoolPref("reader.errors.includeURLs")) { - errorMsg += " Refresh target URI: '" + newURL + "'."; - } - reject(errorMsg); - return; - } - // Otherwise, pass an object indicating our new URL: - if (!baseURI.equalsExceptRef(newURI)) { - reject({ newURL }); - return; - } - } - } - } let responseURL = xhr.responseURL; let givenURL = url; // Convert these to real URIs to make sure the escaping (or lack @@ -369,14 +335,15 @@ var ReaderMode = { /* Ignore errors - we'll use what we had before */ }
+ // We treat redirects as download successes here: + histogram.add(DOWNLOAD_SUCCESS); + + let result = { doc }; if (responseURL != givenURL) { - // We were redirected without a meta refresh tag. - // Force redirect to the correct place: - reject({ newURL: xhr.responseURL }); - return; + result.newURL = xhr.responseURL; } - resolve(doc); - histogram.add(DOWNLOAD_SUCCESS); + + resolve(result); }; xhr.send(); });