forked from mirrors/gecko-dev
Bug 1892046 - Add origin attributes to about:reader requests. r=reader-mode-reviewers,cmkm
Differential Revision: https://phabricator.services.mozilla.com/D207759
This commit is contained in:
parent
bacd7db5ed
commit
85fe8c4f60
2 changed files with 14 additions and 4 deletions
|
|
@ -1274,6 +1274,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({ mozAnon: false });
|
||||
xhr.open("GET", url, true);
|
||||
xhr.setOriginAttributes(attrs);
|
||||
xhr.onerror = evt => reject(evt.error);
|
||||
xhr.responseType = docContentType === "text/plain" ? "text" : "document";
|
||||
xhr.onload = () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue