Bug 1516180 - Provide principal when saving content. r=IanN
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Sun, 06 Jan 2019 23:21:44 +0100
changeset 33274 4b28c50a8eea
parent 33273 6b7c8000a821
child 33275 c4e9d5d84940
push id2368
push userclokep@gmail.com
push dateMon, 28 Jan 2019 21:12:50 +0000
treeherdercomm-beta@56d23c07d815 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN
bugs1516180, 1469916
Bug 1516180 - Provide principal when saving content. r=IanN Port Bug 1469916.
suite/base/content/nsContextMenu.js
suite/browser/pageinfo/pageInfo.js
suite/components/shell/nsMacShellService.cpp
--- a/suite/base/content/nsContextMenu.js
+++ b/suite/base/content/nsContextMenu.js
@@ -962,17 +962,18 @@ nsContextMenu.prototype = {
     var canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
     canvas.width = video.videoWidth;
     canvas.height = video.videoHeight;
     var ctxDraw = canvas.getContext("2d");
     ctxDraw.drawImage(video, 0, 0);
     saveImageURL(canvas.toDataURL("image/jpeg", ""), name, "SaveImageTitle",
                                   true, true,
                                   this.target.ownerDocument.documentURIObject,
-                                  null, null, null, (gPrivate ? true : false));
+                                  null, null, null, (gPrivate ? true : false),
+                                  this.target.ownerDocument.nodePrincipal);
   },
 
   // Full screen video playback
   fullScreenVideo: function() {
     var isPaused = this.target.paused && this.target.currentTime > 0;
     this.target.pause();
 
     openDialog("chrome://communicator/content/fullscreen-video.xhtml",
@@ -1138,22 +1139,24 @@ nsContextMenu.prototype = {
   saveMedia: function() {
     var doc = this.target.ownerDocument;
     let referrerURI = doc.documentURIObject;
 
     if (this.onCanvas)
       // Bypass cache, since it's a data: URL.
       saveImageURL(this.target.toDataURL(), "canvas.png", "SaveImageTitle",
                    true, false, referrerURI, null, null, null,
-                   (gPrivate ? true : false));
+                   (gPrivate ? true : false),
+                   doc.nodePrincipal /* system, because blob: */);
     else if (this.onImage) {
       saveImageURL(this.mediaURL, null, "SaveImageTitle", false,
                    false, referrerURI, null, gContextMenuContentData.contentType,
                    gContextMenuContentData.contentDisposition,
-                   (gPrivate ? true : false));
+                   (gPrivate ? true : false),
+                   doc.nodePrincipal);
     }
     else if (this.onVideo || this.onAudio) {
       var dialogTitle = this.onVideo ? "SaveVideoTitle" : "SaveAudioTitle";
       this.saveHelper(this.mediaURL, null, dialogTitle, false, doc);
     }
   },
 
   // Backwards-compatibility wrapper
--- a/suite/browser/pageinfo/pageInfo.js
+++ b/suite/browser/pageinfo/pageInfo.js
@@ -911,26 +911,28 @@ function saveMedia()
       let titleKey = "SaveImageTitle";
 
       if (item instanceof HTMLVideoElement)
         titleKey = "SaveVideoTitle";
       else if (item instanceof HTMLAudioElement)
         titleKey = "SaveAudioTitle";
 
       saveURL(url, null, titleKey, false, false, makeURI(item.baseURI),
-              null, (opener.gPrivate ? true : false));
+              null, (opener.gPrivate ? true : false),
+              gDocument.nodePrincipal);
     }
   } else {
     selectSaveFolder(function(aDirectory) {
       if (aDirectory) {
         var saveAnImage = function(aURIString, aChosenData, aBaseURI) {
           uniqueFile(aChosenData.file);
           internalSave(aURIString, null, null, null, null, false,
                        "SaveImageTitle", aChosenData, aBaseURI, null, false,
-                       null, (opener.gPrivate ? true : false));
+                       null, (opener.gPrivate ? true : false),
+                       gDocument.nodePrincipal);
         };
 
         for (var i = 0; i < rowArray.length; i++) {
           let v = rowArray[i];
           let dir = aDirectory.clone();
           let item = gImageView.data[v][COL_IMAGE_NODE];
           let uriString = gImageView.data[v][COL_IMAGE_ADDRESS];
           let uri = makeURI(uriString);
--- a/suite/components/shell/nsMacShellService.cpp
+++ b/suite/components/shell/nsMacShellService.cpp
@@ -168,17 +168,17 @@ nsMacShellService::SetDesktopBackground(
   nsCOMPtr<nsILoadContext> loadContext;
   nsCOMPtr<nsISupports> container = aElement->OwnerDoc()->GetContainer();
   nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(container);
   if (docShell)
   {
     loadContext = do_QueryInterface(docShell);
   }
 
-  return wbp->SaveURI(imageURI, 0,
+  return wbp->SaveURI(imageURI, aElement->NodePrincipal(), 0,
                       docURI, aElement->OwnerDoc()->GetReferrerPolicy(),
                       nullptr, nullptr,
                       mBackgroundFile, loadContext);
 }
 
 NS_IMETHODIMP
 nsMacShellService::OnProgressChange(nsIWebProgress* aWebProgress,
                                     nsIRequest* aRequest,