Commit a67536f8 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 cde48fd0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -788,6 +788,7 @@ AboutReader.prototype = {
      try {
        article = await ReaderMode.downloadAndParseDocument(
          url,
          { ...this._doc.nodePrincipal?.originAttributes },
          docContentType
        );
      } catch (e) {
+13 −4
Original line number Diff line number Diff line
@@ -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 => {