Bug 1397986 - Save to PDF doesn't work with content sandbox. r=haik
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Sun, 10 Sep 2017 17:49:30 +0900
changeset 430287 e3f4a1ad4928e9fc3a3ec03dbb4b59fdd4a52e57
parent 430286 fd638dbfa55d4057781a83aa1bb3066c8e26ee73
child 430288 60f6c456364517795ccc0ccfdbf981e57c224e25
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershaik
bugs1397986
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1397986 - Save to PDF doesn't work with content sandbox. r=haik Due to content sandbox, NSPrintJobSavingURL will throws an exception on content process. So we don't use NSPrintJobSavingURL on content process and print.print_via_parent=true. Also, even if chrome process, SetToFileName should store file name to mToFileName. Because SetToFileName uses mToFileName. MozReview-Commit-ID: J7vlOG0gyGP
widget/cocoa/nsPrintSettingsX.mm
--- a/widget/cocoa/nsPrintSettingsX.mm
+++ b/widget/cocoa/nsPrintSettingsX.mm
@@ -327,25 +327,38 @@ nsPrintSettingsX::GetScaling(double *aSc
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 NS_IMETHODIMP
 nsPrintSettingsX::SetToFileName(const char16_t *aToFileName)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
+  if (XRE_IsContentProcess() &&
+      Preferences::GetBool("print.print_via_parent")) {
+    // On content sandbox, NSPrintJobSavingURL will returns error since
+    // sandbox disallows file access.
+    return nsPrintSettings::SetToFileName(aToFileName);
+  }
+
   NSMutableDictionary* printInfoDict = [mPrintInfo dictionary];
-  nsString filename = nsDependentString(aToFileName);
 
-  NSURL* jobSavingURL =
-      [NSURL fileURLWithPath: nsCocoaUtils::ToNSString(filename)];
-  if (jobSavingURL) {
-    [printInfoDict setObject: NSPrintSaveJob forKey: NSPrintJobDisposition];
-    [printInfoDict setObject: jobSavingURL forKey: NSPrintJobSavingURL];
+  if (aToFileName && aToFileName[0]) {
+    NSURL* jobSavingURL =
+        [NSURL fileURLWithPath: nsCocoaUtils::ToNSString(
+                                  nsDependentString(aToFileName))];
+    if (jobSavingURL) {
+      [printInfoDict setObject: NSPrintSaveJob forKey: NSPrintJobDisposition];
+      [printInfoDict setObject: jobSavingURL forKey: NSPrintJobSavingURL];
+    }
+    mToFileName = aToFileName;
+  } else {
+    mToFileName.Truncate();
   }
+
   NSPrintInfo* newPrintInfo =
       [[NSPrintInfo alloc] initWithDictionary: printInfoDict];
   if (NS_WARN_IF(!newPrintInfo)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   SetCocoaPrintInfo(newPrintInfo);
   [newPrintInfo release];