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
--- 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);