Bug 1679325 - Part 1: Making contentAreaUtils.saveURL to accept cookieJarSettings. r=smaug, a=RyanVM
authorTim Huang <tihuang@mozilla.com>
Thu, 03 Dec 2020 20:10:36 +0000
changeset 623962 11f96ee5c8d9b13cc55fc72be2b8891ea4973b05
parent 623961 c679e893d55bffe66262ed522cfda4d5dcde18ff
child 623963 ed9b072ec4e02696eef6931a06fe6831684363b7
push id14923
push userryanvm@gmail.com
push dateSun, 06 Dec 2020 18:29:52 +0000
treeherdermozilla-beta@ef2a14df18d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, RyanVM
bugs1679325
milestone84.0
Bug 1679325 - Part 1: Making contentAreaUtils.saveURL to accept cookieJarSettings. r=smaug, a=RyanVM This patch makes the contentAreaUtils.saveURL to be aware of the cookieJarSettings, and updates all callers. This also updates the documentation of the persistArgs 'cookieJarSettings' for internalPersist(). Differential Revision: https://phabricator.services.mozilla.com/D98455
browser/base/content/browser.js
browser/base/content/nsContextMenu.js
browser/base/content/pageinfo/pageInfo.js
browser/base/content/utilityOverlay.js
browser/components/downloads/content/indicator.js
toolkit/components/pdfjs/content/PdfjsParent.jsm
toolkit/content/contentAreaUtils.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -7078,16 +7078,17 @@ function handleLinkClick(event, href, li
   if (where == "save") {
     saveURL(
       href,
       linkNode ? gatherTextUnder(linkNode) : "",
       null,
       true,
       true,
       referrerInfo,
+      doc.cookieJarSettings,
       doc
     );
     event.preventDefault();
     return true;
   }
 
   // if the mixedContentChannel is present and the referring URI passes
   // a same origin check with the target URI, we can preserve the users
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -1421,16 +1421,17 @@ class nsContextMenu {
   // then prompt the user with a file picker
   saveHelper(
     linkURL,
     linkText,
     dialogTitle,
     bypassCache,
     doc,
     referrerInfo,
+    cookieJarSettings,
     windowID,
     linkDownload,
     isContentWindowPrivate
   ) {
     // canonical def in nsURILoader.h
     const NS_ERROR_SAVE_LINK_AS_TIMEOUT = 0x805d0020;
 
     // an object to proxy the data through to
@@ -1489,16 +1490,17 @@ class nsContextMenu {
           // it can without waiting.
           saveURL(
             linkURL,
             linkText,
             dialogTitle,
             bypassCache,
             false,
             referrerInfo,
+            cookieJarSettings,
             doc,
             isContentWindowPrivate,
             this._triggeringPrincipal
           );
         }
         if (this.extListener) {
           this.extListener.onStopRequest(aRequest, aStatusCode);
         }
@@ -1574,16 +1576,18 @@ class nsContextMenu {
 
     channel.loadFlags |= flags;
 
     if (channel instanceof Ci.nsIHttpChannel) {
       channel.referrerInfo = referrerInfo;
       if (channel instanceof Ci.nsIHttpChannelInternal) {
         channel.forceAllowThirdPartyCookie = true;
       }
+
+      channel.loadInfo.cookieJarSettings = cookieJarSettings;
     }
 
     // fallback to the old way if we don't see the headers quickly
     var timeToWait = Services.prefs.getIntPref(
       "browser.download.saveLinkAsFilenameTimeout"
     );
     var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     timer.initWithCallback(
@@ -1605,16 +1609,17 @@ class nsContextMenu {
     let isContentWindowPrivate = this.ownerDoc.isPrivate;
     this.saveHelper(
       this.linkURL,
       this.linkTextStr,
       null,
       true,
       this.ownerDoc,
       referrerInfo,
+      this.contentData.cookieJarSettings,
       this.frameOuterWindowID,
       this.linkDownload,
       isContentWindowPrivate
     );
   }
 
   // Backwards-compatibility wrapper
   saveImage() {
--- a/browser/base/content/pageinfo/pageInfo.js
+++ b/browser/base/content/pageinfo/pageInfo.js
@@ -715,16 +715,17 @@ function saveMedia() {
       saveURL(
         url,
         null,
         titleKey,
         false,
         false,
         referrerInfo,
         null,
+        null,
         gDocInfo.isContentWindowPrivate,
         gDocInfo.principal
       );
     }
   } else {
     selectSaveFolder(function(aDirectory) {
       if (aDirectory) {
         var saveAnImage = function(aURIString, aChosenData, aBaseURI) {
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -393,28 +393,29 @@ function openLinkIn(url, where, params) 
       saveURL(
         url,
         null,
         null,
         true,
         true,
         aReferrerInfo,
         null,
+        null,
         params.isContentWindowPrivate,
         aPrincipal
       );
     } else {
       if (!aInitiatingDoc) {
         Cu.reportError(
           "openUILink/openLinkIn was called with " +
             "where == 'save' but without initiatingDoc.  See bug 814264."
         );
         return;
       }
-      saveURL(url, null, null, true, true, aReferrerInfo, aInitiatingDoc);
+      saveURL(url, null, null, true, true, aReferrerInfo, null, aInitiatingDoc);
     }
     return;
   }
 
   // Establish which window we'll load the link in.
   let w;
   if (where == "current" && params.targetBrowser) {
     w = params.targetBrowser.ownerGlobal;
--- a/browser/components/downloads/content/indicator.js
+++ b/browser/components/downloads/content/indicator.js
@@ -601,17 +601,17 @@ const DownloadsIndicatorView = {
     let sourceDoc = dt.mozSourceNode
       ? dt.mozSourceNode.ownerDocument
       : document;
     let handled = false;
     for (let link of links) {
       if (link.url.startsWith("about:")) {
         continue;
       }
-      saveURL(link.url, link.name, null, true, true, null, sourceDoc);
+      saveURL(link.url, link.name, null, true, true, null, null, sourceDoc);
       handled = true;
     }
     if (handled) {
       aEvent.preventDefault();
     }
   },
 
   _indicator: null,
--- a/toolkit/components/pdfjs/content/PdfjsParent.jsm
+++ b/toolkit/components/pdfjs/content/PdfjsParent.jsm
@@ -100,16 +100,17 @@ class PdfjsParent extends JSWindowActorP
     const data = aMsg.data;
     this.browser.ownerGlobal.saveURL(
       data.blobUrl /* aURL */,
       data.filename /* aFileName */,
       null /* aFilePickerTitleKey */,
       true /* aShouldBypassCache */,
       false /* aSkipPrompt */,
       null /* aReferrerInfo */,
+      null /* aCookieJarSettings*/,
       null /* aSourceDocument */,
       PrivateBrowsingUtils.isBrowserPrivate(
         this.browser
       ) /* aIsContentWindowPrivate */,
       Services.scriptSecurityManager.getSystemPrincipal() /* aPrincipal */
     );
   }
 
--- a/toolkit/content/contentAreaUtils.js
+++ b/toolkit/content/contentAreaUtils.js
@@ -55,31 +55,32 @@ function urlSecurityCheck(aURL, aPrincip
 //
 function saveURL(
   aURL,
   aFileName,
   aFilePickerTitleKey,
   aShouldBypassCache,
   aSkipPrompt,
   aReferrerInfo,
+  aCookieJarSettings,
   aSourceDocument,
   aIsContentWindowPrivate,
   aPrincipal
 ) {
   internalSave(
     aURL,
     null,
     aFileName,
     null,
     null,
     aShouldBypassCache,
     aFilePickerTitleKey,
     null,
     aReferrerInfo,
-    null,
+    aCookieJarSettings,
     aSourceDocument,
     aSkipPrompt,
     null,
     aIsContentWindowPrivate,
     aPrincipal
   );
 }
 
@@ -389,18 +390,20 @@ function internalSave(
  *        Required and used only when persistArgs.sourceDocument is NOT present,
  *        represents the POST data to be sent along with the HTTP request, and
  *        must be null if no POST data should be sent.
  * @param persistArgs.targetFile
  *        The nsIFile of the file to create
  * @param persistArgs.contentPolicyType
  *        The type of content we're saving. Will be used to determine what
  *        content is accepted, enforce sniffing restrictions, etc.
- * @param persistArgs.cookieJarSettings
- *        The nsICookieJarSettings that we need to use.
+ * @param persistArgs.cookieJarSettings [optional]
+ *        The nsICookieJarSettings that will be used for the saving channel, or
+ *        null that savePrivacyAwareURI will create one based on the current
+ *        state of the prefs/permissions
  * @param persistArgs.targetContentType
  *        Required and used only when persistArgs.sourceDocument is present,
  *        determines the final content type of the saved file, or null to use
  *        the same content type as the source document. Currently only
  *        "text/plain" is meaningful.
  * @param persistArgs.bypassCache
  *        If true, the document will always be refetched from the server
  * @param persistArgs.isPrivate