Bug 1185236 - Shorten print job name on Cocoa. r=mstange
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Fri, 13 Oct 2017 15:48:40 +0900
changeset 386093 672c5ee7b8e4fb261294f4b73fb60175df73921c
parent 386092 fb2b1aa5bb5e0521012c3c0bab7f7feb9da13b70
child 386094 51a852b856dc35ed68a65cc8795ec76f9f550e65
push id32675
push userarchaeopteryx@coole-files.de
push dateFri, 13 Oct 2017 21:36:21 +0000
treeherdermozilla-central@684b9ee0468e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1185236, 34428043
milestone58.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 1185236 - Shorten print job name on Cocoa. r=mstange Gecko set job using by PMPrintSettingsSetJobName regardless of job name length. But IPP allow job-name length up to 255 bytes. (RFC 2911, Section 4.3.1) This patch will shorten print job name. It is workaround until fixed the Core Printing[1]. [1] https://openradar.appspot.com/34428043 MozReview-Commit-ID: 6nCwZuD43O9
widget/cocoa/nsDeviceContextSpecX.mm
widget/cocoa/nsPrintDialogX.mm
--- a/widget/cocoa/nsDeviceContextSpecX.mm
+++ b/widget/cocoa/nsDeviceContextSpecX.mm
@@ -118,36 +118,43 @@ NS_IMETHODIMP nsDeviceContextSpecX::Init
   }
 #endif
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
-NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(const nsAString& aTitle, 
+NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(const nsAString& aTitle,
                                                   const nsAString& aPrintToFileName,
-                                                  int32_t          aStartPage, 
+                                                  int32_t          aStartPage,
                                                   int32_t          aEndPage)
 {
-    NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
+  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
+
+  // Print Core of Application Service sent print job with names exceeding
+  // 255 bytes. This is a workaround until fix it.
+  // (https://openradar.appspot.com/34428043)
+  nsAutoString adjustedTitle;
+  PrintTarget::AdjustPrintJobNameForIPP(aTitle, adjustedTitle);
 
-    if (!aTitle.IsEmpty()) {
-      CFStringRef cfString =
-        ::CFStringCreateWithCharacters(NULL, reinterpret_cast<const UniChar*>(aTitle.BeginReading()),
-                                             aTitle.Length());
-      if (cfString) {
-        ::PMPrintSettingsSetJobName(mPrintSettings, cfString);
-        ::CFRelease(cfString);
-      }
+  if (!adjustedTitle.IsEmpty()) {
+    CFStringRef cfString =
+      ::CFStringCreateWithCharacters(NULL,
+                                     reinterpret_cast<const UniChar*>(adjustedTitle.BeginReading()),
+                                     adjustedTitle.Length());
+    if (cfString) {
+      ::PMPrintSettingsSetJobName(mPrintSettings, cfString);
+      ::CFRelease(cfString);
     }
+  }
 
-    return NS_OK;
+  return NS_OK;
 
-    NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
+  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 NS_IMETHODIMP nsDeviceContextSpecX::EndDocument()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
 #ifdef MOZ_ENABLE_SKIA_PDF
   if (mPrintViaSkPDF) {
--- a/widget/cocoa/nsPrintDialogX.mm
+++ b/widget/cocoa/nsPrintDialogX.mm
@@ -54,18 +54,26 @@ nsPrintDialogServiceX::Show(nsPIDOMWindo
   nsCOMPtr<nsIPrintSettingsService> printSettingsSvc
     = do_GetService("@mozilla.org/gfx/printsettings-service;1");
 
   // Set the print job title
   char16_t** docTitles;
   uint32_t titleCount;
   nsresult rv = aWebBrowserPrint->EnumerateDocumentNames(&titleCount, &docTitles);
   if (NS_SUCCEEDED(rv) && titleCount > 0) {
-    CFStringRef cfTitleString = CFStringCreateWithCharacters(NULL, reinterpret_cast<const UniChar*>(docTitles[0]),
-                                                             NS_strlen(docTitles[0]));
+    // Print Core of Application Service sent print job with names exceeding
+    // 255 bytes. This is a workaround until fix it.
+    // (https://openradar.appspot.com/34428043)
+    nsAutoString adjustedTitle;
+    PrintTarget::AdjustPrintJobNameForIPP(nsDependentString(docTitles[0]),
+                                          adjustedTitle);
+    CFStringRef cfTitleString =
+      CFStringCreateWithCharacters(NULL,
+                                   reinterpret_cast<const UniChar*>(adjustedTitle.BeginReading()),
+                                   adjustedTitle.Length());
     if (cfTitleString) {
       ::PMPrintSettingsSetJobName(settingsX->GetPMPrintSettings(), cfTitleString);
       CFRelease(cfTitleString);
     }
     for (int32_t i = titleCount - 1; i >= 0; i--) {
       free(docTitles[i]);
     }
     free(docTitles);