Bug 1602103. Set the print job name before initialization of the print session on macOS. r=bobowen
authorJonathan Watt <jwatt@jwatt.org>
Mon, 09 Dec 2019 08:46:56 +0000
changeset 568160 524128dc119c459bdca6b02cd2090d88fca9e4b9
parent 568159 bfd693dd19efbcd529be28bcfebb2522c88ecf35
child 568161 7f8a7ac4bfe49199d34e8581d1fbbce4e25b9650
push id12493
push userffxbld-merge
push dateMon, 06 Jan 2020 15:38:57 +0000
treeherdermozilla-beta@63ae456b848d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbobowen
bugs1602103
milestone73.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 1602103. Set the print job name before initialization of the print session on macOS. r=bobowen For a PMSession to be given a job name, the job name must be set on the PMPrintSettings before it is passed to PMSessionBeginCGDocumentNoDialog. However, since nsDeviceContext::BeginDocument calls PrintTarget::BeginPrinting before calling nsDeviceContextSpec::BeginDocument, the setting of the job name in nsDeviceContextSpecX::BeginDocument was happening after the PMSessionBeginCGDocumentNoDialog call in PrintTargetCG::BeginPrinting, and was doing us no good. This moves the job name setting into PrintTargetCG::BeginPrinting so that the job name is set first. Note: The job name is shown if your printer/OS has software to manage the list of queued jobs waiting to print. Differential Revision: https://phabricator.services.mozilla.com/D56241
gfx/thebes/PrintTargetCG.mm
widget/cocoa/nsDeviceContextSpecX.mm
--- a/gfx/thebes/PrintTargetCG.mm
+++ b/gfx/thebes/PrintTargetCG.mm
@@ -83,16 +83,32 @@ already_AddRefed<DrawTarget> PrintTarget
 
   return do_AddRef(mRefDT);
 }
 
 nsresult PrintTargetCG::BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName,
                                       int32_t aStartPage, int32_t aEndPage) {
   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 (!adjustedTitle.IsEmpty()) {
+    CFStringRef cfString = ::CFStringCreateWithCharacters(
+        NULL, reinterpret_cast<const UniChar*>(adjustedTitle.BeginReading()),
+        adjustedTitle.Length());
+    if (cfString) {
+      ::PMPrintSettingsSetJobName(mPrintSettings, cfString);
+      ::CFRelease(cfString);
+    }
+  }
+
   OSStatus status;
   status = ::PMSetFirstPage(mPrintSettings, aStartPage, false);
   NS_ASSERTION(status == noErr, "PMSetFirstPage failed");
   status = ::PMSetLastPage(mPrintSettings, aEndPage, false);
   NS_ASSERTION(status == noErr, "PMSetLastPage failed");
 
   status = ::PMSessionBeginCGDocumentNoDialog(mPrintSession, mPrintSettings, mPageFormat);
 
--- a/widget/cocoa/nsDeviceContextSpecX.mm
+++ b/widget/cocoa/nsDeviceContextSpecX.mm
@@ -114,32 +114,16 @@ NS_IMETHODIMP nsDeviceContextSpecX::Init
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(const nsAString& aTitle,
                                                   const nsAString& aPrintToFileName,
                                                   int32_t aStartPage, int32_t aEndPage) {
   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 (!adjustedTitle.IsEmpty()) {
-    CFStringRef cfString = ::CFStringCreateWithCharacters(
-        NULL, reinterpret_cast<const UniChar*>(adjustedTitle.BeginReading()),
-        adjustedTitle.Length());
-    if (cfString) {
-      ::PMPrintSettingsSetJobName(mPrintSettings, cfString);
-      ::CFRelease(cfString);
-    }
-  }
-
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 NS_IMETHODIMP nsDeviceContextSpecX::EndDocument() {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;