Skip to content
Snippets Groups Projects
Verified Commit 679f44da authored by cypherpunks1's avatar cypherpunks1 Committed by Pier Angelo Vendrame
Browse files

Bug 40175: Add origin attributes to about:reader top-level requests

parent 6bc20ba1
Branches
Tags
1 merge request!889Bug 42366: Tor Browser 115.7.0esr alpha rebase
......@@ -788,6 +788,7 @@ AboutReader.prototype = {
try {
article = await ReaderMode.downloadAndParseDocument(
url,
{ ...this._doc.nodePrincipal?.originAttributes },
docContentType
);
} catch (e) {
......
......@@ -231,11 +231,12 @@ export var ReaderMode = {
* Downloads and parses a document from a URL.
*
* @param url URL to download and parse.
* @param attrs OriginAttributes to use for the request.
* @return {Promise}
* @resolves JS object representing the article, or null if no article is found.
*/
async downloadAndParseDocument(url, docContentType = "document") {
let result = await this._downloadDocument(url, docContentType);
async downloadAndParseDocument(url, attrs = {}, docContentType = "document") {
let result = await this._downloadDocument(url, attrs, docContentType);
if (!result?.doc) {
return null;
}
......@@ -258,9 +259,11 @@ export var ReaderMode = {
return article;
},
_downloadDocument(url, docContentType = "document") {
_downloadDocument(url, attrs = {}, docContentType = "document") {
let uri;
try {
if (!lazy.Readerable.shouldCheckUri(Services.io.newURI(url))) {
uri = Services.io.newURI(url);
if (!lazy.Readerable.shouldCheckUri(uri)) {
return null;
}
} catch (ex) {
......@@ -272,9 +275,15 @@ export var ReaderMode = {
let histogram = Services.telemetry.getHistogramById(
"READER_MODE_DOWNLOAD_RESULT"
);
try {
attrs.firstPartyDomain = Services.eTLD.getSchemelessSite(uri);
} catch (e) {
console.error("Failed to get first party domain for about:reader", e);
}
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setOriginAttributes(attrs);
xhr.onerror = evt => reject(evt.error);
xhr.responseType = docContentType === "text/plain" ? "text" : "document";
xhr.onload = evt => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment