Bug 1246244 - Allow non-CPOW documents to pass through saveImageURL properly. r=margaret,jaws draft
authorMike Conley <mconley@mozilla.com>
Fri, 05 Feb 2016 18:19:59 -0500
changeset 330458 c19ccd3eb1c3fedd48b0bb714f0740434fa5e45c
parent 330448 306cf0271d3e3a344fcbfd2baf75e0450c288cf1
child 330459 c13ff8c5a97a6a65f23deb51b1d4553be644f2a3
push id10761
push usermconley@mozilla.com
push dateThu, 11 Feb 2016 20:09:49 +0000
reviewersmargaret, jaws
bugs1246244
milestone47.0a1
Bug 1246244 - Allow non-CPOW documents to pass through saveImageURL properly. r=margaret,jaws MozReview-Commit-ID: 1SbM2n3PNI1
toolkit/content/contentAreaUtils.js
--- a/toolkit/content/contentAreaUtils.js
+++ b/toolkit/content/contentAreaUtils.js
@@ -105,17 +105,17 @@ const nsISupportsCString = Components.in
  * Offers to save an image URL to the file system.
  *
  * @param aURL (string)
  *        The URL of the image to be saved.
  * @param aFileName (string)
  *        The suggested filename for the saved file.
  * @param aFilePickerTitleKey (string, optional)
  *        Localized string key for an alternate title for the file
- *        picker. If set to null
+ *        picker. If set to null, this will default to something sensible.
  * @param aShouldBypassCache (bool)
  *        If true, the image will always be retrieved from the server instead
  *        of the network or image caches.
  * @param aSkipPrompt (bool)
  *        If true, we will attempt to save the file with the suggested
  *        filename to the default downloads folder without showing the
  *        file picker.
  * @param aReferrer (nsIURI, optional)
@@ -133,33 +133,31 @@ const nsISupportsCString = Components.in
  *        Does not need to be provided is aDoc is passed.
  */
 function saveImageURL(aURL, aFileName, aFilePickerTitleKey, aShouldBypassCache,
                       aSkipPrompt, aReferrer, aDoc, aContentType, aContentDisp,
                       aIsContentWindowPrivate)
 {
   forbidCPOW(aURL, "saveImageURL", "aURL");
   forbidCPOW(aReferrer, "saveImageURL", "aReferrer");
-  // Allow aSourceDocument to be a CPOW, but warn about it. Add-ons that are not
-  // marked multi-process compatible can pass a document CPOW, but in-browser
-  // consumers and multi-process compatible add-ons cannot when e10s is enabled.
-  if (aDoc && Components.utils.isCrossProcessWrapper(aDoc)) {
-    Deprecated.warning("saveImageURL should not be passed document CPOWs. " +
-                       "The caller should pass in the content type and " +
-                       "disposition themselves",
+
+  if (aDoc && aIsContentWindowPrivate == undefined) {
+    if (Components.utils.isCrossProcessWrapper(aDoc)) {
+      Deprecated.warning("saveImageURL should not be passed document CPOWs. " +
+                         "The caller should pass in the content type and " +
+                         "disposition themselves",
+                         "https://bugzilla.mozilla.org/show_bug.cgi?id=1243643");
+    }
+    // This will definitely not work for in-browser code or multi-process compatible
+    // add-ons due to bug 1233497, which makes unsafe CPOW usage throw by default.
+    Deprecated.warning("saveImageURL should be passed the private state of " +
+                       "the containing window.",
                        "https://bugzilla.mozilla.org/show_bug.cgi?id=1243643");
-    if (aIsContentWindowPrivate == undefined) {
-      // This will definitely not work for in-browser code or multi-process compatible
-      // add-ons due to bug 1233497, which makes unsafe CPOW usage throw by default.
-      Deprecated.warning("saveImageURL should be passed the private state of " +
-                         "the containing window.",
-                         "https://bugzilla.mozilla.org/show_bug.cgi?id=1243643");
-      aIsContentWindowPrivate =
-        PrivateBrowsingUtils.isContentWindowPrivate(aDoc.defaultView);
-    }
+    aIsContentWindowPrivate =
+      PrivateBrowsingUtils.isContentWindowPrivate(aDoc.defaultView);
   }
 
   // We'd better have the private state by now.
   if (aIsContentWindowPrivate == undefined) {
     throw new Error("saveImageURL couldn't compute private state of content window");
   }
 
   if (!aShouldBypassCache && (aDoc && !Components.utils.isCrossProcessWrapper(aDoc)) &&