Loading browser/components/extensions/parent/ext-tabs.js +1 −2 Original line number Diff line number Diff line Loading @@ -1351,8 +1351,7 @@ this.tabs = class extends ExtensionAPI { printSettings.isInitializedFromPrinter = true; printSettings.isInitializedFromPrefs = true; printSettings.outputDestination = Ci.nsIPrintSettings.kOutputDestinationFile; printSettings.printToFile = true; printSettings.toFileName = picker.file.path; printSettings.printSilent = true; Loading gfx/thebes/PrintTargetCG.h +7 −10 Original line number Diff line number Diff line Loading @@ -9,9 +9,8 @@ #include <Carbon/Carbon.h> #include "PrintTarget.h" class nsIOutputStream; namespace mozilla::gfx { namespace mozilla { namespace gfx { /** * CoreGraphics printing target. Loading @@ -19,9 +18,8 @@ namespace mozilla::gfx { class PrintTargetCG final : public PrintTarget { public: static already_AddRefed<PrintTargetCG> CreateOrNull( nsIOutputStream* aOutputStream, PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize); PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize); nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName, int32_t aStartPage, Loading @@ -34,17 +32,16 @@ class PrintTargetCG final : public PrintTarget { already_AddRefed<DrawTarget> GetReferenceDrawTarget() final; private: PrintTargetCG(CGContextRef aPrintToStreamContext, PMPrintSession aPrintSession, PMPageFormat aPageFormat, PrintTargetCG(PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize); ~PrintTargetCG(); CGContextRef mPrintToStreamContext = nullptr; PMPrintSession mPrintSession; PMPageFormat mPageFormat; PMPrintSettings mPrintSettings; }; } // namespace mozilla::gfx } // namespace gfx } // namespace mozilla #endif /* MOZILLA_GFX_PRINTTARGETCG_H */ gfx/thebes/PrintTargetCG.mm +25 −103 Original line number Diff line number Diff line Loading @@ -10,17 +10,13 @@ #include "mozilla/gfx/HelpersCairo.h" #include "nsObjCExceptions.h" #include "nsString.h" #include "nsIOutputStream.h" namespace mozilla::gfx { namespace mozilla { namespace gfx { static size_t PutBytesNull(void* info, const void* buffer, size_t count) { return count; } PrintTargetCG::PrintTargetCG(CGContextRef aPrintToStreamContext, PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize) PrintTargetCG::PrintTargetCG(PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize) : PrintTarget(/* aCairoSurface */ nullptr, aSize), mPrintToStreamContext(aPrintToStreamContext), mPrintSession(aPrintSession), mPageFormat(aPageFormat), mPrintSettings(aPrintSettings) { Loading @@ -45,80 +41,24 @@ PrintTargetCG::~PrintTargetCG() { ::PMRelease(mPageFormat); ::PMRelease(mPrintSettings); if (mPrintToStreamContext) { CGContextRelease(mPrintToStreamContext); } NS_OBJC_END_TRY_IGNORE_BLOCK; } static size_t WriteStreamBytes(void* aInfo, const void* aBuffer, size_t aCount) { auto* stream = static_cast<nsIOutputStream*>(aInfo); auto* data = static_cast<const char*>(aBuffer); size_t remaining = aCount; do { uint32_t wrote = 0; // Handle potential narrowing from size_t to uint32_t. uint32_t toWrite = uint32_t(std::min(remaining, size_t(std::numeric_limits<uint32_t>::max()))); if (NS_WARN_IF(NS_FAILED(stream->Write(data, toWrite, &wrote)))) { break; } data += wrote; remaining -= size_t(wrote); } while (remaining); return aCount; } static void ReleaseStream(void* aInfo) { auto* stream = static_cast<nsIOutputStream*>(aInfo); stream->Close(); NS_RELEASE(stream); } static CGContextRef CreatePrintToStreamContext(nsIOutputStream* aOutputStream, const IntSize& aSize) { MOZ_ASSERT(aOutputStream); NS_ADDREF(aOutputStream); // Matched by the NS_RELEASE in ReleaseStream. CGRect pageBox{{0.0, 0.0}, {CGFloat(aSize.width), CGFloat(aSize.height)}}; CGDataConsumerCallbacks callbacks = {WriteStreamBytes, ReleaseStream}; CGDataConsumerRef consumer = CGDataConsumerCreate(aOutputStream, &callbacks); // This metadata is added by the CorePrinting APIs in the non-stream case. NSString* bundleName = [NSBundle.mainBundle.localizedInfoDictionary objectForKey:(NSString*)kCFBundleNameKey]; CFMutableDictionaryRef auxiliaryInfo = CFDictionaryCreateMutable( kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionaryAddValue(auxiliaryInfo, kCGPDFContextCreator, (__bridge CFStringRef)bundleName); CGContextRef pdfContext = CGPDFContextCreate(consumer, &pageBox, auxiliaryInfo); CGDataConsumerRelease(consumer); CFRelease(auxiliaryInfo); return pdfContext; } /* static */ already_AddRefed<PrintTargetCG> PrintTargetCG::CreateOrNull( nsIOutputStream* aOutputStream, PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize) { PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize) { if (!Factory::CheckSurfaceSize(aSize)) { return nullptr; } CGContextRef printToStreamContext = nullptr; if (aOutputStream) { printToStreamContext = CreatePrintToStreamContext(aOutputStream, aSize); if (!printToStreamContext) { return nullptr; } } RefPtr<PrintTargetCG> target = new PrintTargetCG(printToStreamContext, aPrintSession, aPageFormat, aPrintSettings, aSize); new PrintTargetCG(aPrintSession, aPageFormat, aPrintSettings, aSize); return target.forget(); } static size_t PutBytesNull(void* info, const void* buffer, size_t count) { return count; } already_AddRefed<DrawTarget> PrintTargetCG::GetReferenceDrawTarget() { if (!mRefDT) { const IntSize size(1, 1); Loading Loading @@ -155,10 +95,6 @@ nsresult PrintTargetCG::BeginPrinting(const nsAString& aTitle, const nsAString& int32_t aStartPage, int32_t aEndPage) { NS_OBJC_BEGIN_TRY_BLOCK_RETURN; if (mPrintToStreamContext) { return NS_OK; } // 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) Loading Loading @@ -191,12 +127,6 @@ nsresult PrintTargetCG::BeginPrinting(const nsAString& aTitle, const nsAString& nsresult PrintTargetCG::EndPrinting() { NS_OBJC_BEGIN_TRY_BLOCK_RETURN; if (mPrintToStreamContext) { CGContextFlush(mPrintToStreamContext); CGPDFContextClose(mPrintToStreamContext); return NS_OK; } ::PMSessionEndDocumentNoDialog(mPrintSession); return NS_OK; Loading @@ -213,17 +143,13 @@ nsresult PrintTargetCG::AbortPrinting() { nsresult PrintTargetCG::BeginPage() { NS_OBJC_BEGIN_TRY_BLOCK_RETURN; CGContextRef context; if (mPrintToStreamContext) { CGContextBeginPage(mPrintToStreamContext, nullptr); context = mPrintToStreamContext; } else { PMSessionError(mPrintSession); OSStatus status = ::PMSessionBeginPageNoDialog(mPrintSession, mPageFormat, nullptr); OSStatus status = ::PMSessionBeginPageNoDialog(mPrintSession, mPageFormat, NULL); if (status != noErr) { return NS_ERROR_ABORT; } CGContextRef context; // This call will fail if it wasn't called between the PMSessionBeginPage/ // PMSessionEndPage calls: ::PMSessionGetCGGraphicsContext(mPrintSession, &context); Loading @@ -231,7 +157,6 @@ nsresult PrintTargetCG::BeginPage() { if (!context) { return NS_ERROR_FAILURE; } } unsigned int width = static_cast<unsigned int>(mSize.width); unsigned int height = static_cast<unsigned int>(mSize.height); Loading Loading @@ -260,18 +185,15 @@ nsresult PrintTargetCG::EndPage() { cairo_surface_finish(mCairoSurface); mCairoSurface = nullptr; if (mPrintToStreamContext) { CGContextEndPage(mPrintToStreamContext); } else { OSStatus status = ::PMSessionEndPageNoDialog(mPrintSession); if (status != noErr) { return NS_ERROR_ABORT; } } return PrintTarget::EndPage(); NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE); } } // namespace mozilla::gfx } // namespace gfx } // namespace mozilla layout/printing/nsPrintJob.cpp +6 −4 Original line number Diff line number Diff line Loading @@ -1080,9 +1080,10 @@ nsresult nsPrintJob::SetupToPrintContent() { nsAutoString fileNameStr; // check to see if we are printing to a file if (printData->mPrintSettings->GetOutputDestination() == nsIPrintSettings::kOutputDestinationFile) { // On some platforms the BeginDocument needs to know the name of the file. bool isPrintToFile = false; printData->mPrintSettings->GetPrintToFile(&isPrintToFile); if (isPrintToFile) { // On some platforms The BeginDocument needs to know the name of the file. printData->mPrintSettings->GetToFileName(fileNameStr); } Loading Loading @@ -2331,7 +2332,8 @@ nsresult nsPrintJob::StartPagePrintTimer(const UniquePtr<nsPrintObject>& aPO) { if (!mPagePrintTimer) { // Get the delay time in between the printing of each page // this gives the user more time to press cancel int32_t printPageDelay = mPrt->mPrintSettings->GetPrintPageDelay(); int32_t printPageDelay = 50; mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay); nsCOMPtr<nsIContentViewer> cv = do_QueryInterface(mDocViewerPrint); NS_ENSURE_TRUE(cv, NS_ERROR_FAILURE); Loading layout/tools/reftest/reftest.jsm +1 −1 Original line number Diff line number Diff line Loading @@ -1721,7 +1721,7 @@ function RecvStartPrint(isPrintSelection, printRange) ps.unwriteableMarginRight = 0; ps.unwriteableMarginLeft = 0; ps.unwriteableMarginBottom = 0; ps.outputDestination = Ci.nsIPrintSettings.kOutputDestinationFile; ps.printToFile = true; ps.toFileName = file.path; ps.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF; ps.printSelectionOnly = isPrintSelection; Loading Loading
browser/components/extensions/parent/ext-tabs.js +1 −2 Original line number Diff line number Diff line Loading @@ -1351,8 +1351,7 @@ this.tabs = class extends ExtensionAPI { printSettings.isInitializedFromPrinter = true; printSettings.isInitializedFromPrefs = true; printSettings.outputDestination = Ci.nsIPrintSettings.kOutputDestinationFile; printSettings.printToFile = true; printSettings.toFileName = picker.file.path; printSettings.printSilent = true; Loading
gfx/thebes/PrintTargetCG.h +7 −10 Original line number Diff line number Diff line Loading @@ -9,9 +9,8 @@ #include <Carbon/Carbon.h> #include "PrintTarget.h" class nsIOutputStream; namespace mozilla::gfx { namespace mozilla { namespace gfx { /** * CoreGraphics printing target. Loading @@ -19,9 +18,8 @@ namespace mozilla::gfx { class PrintTargetCG final : public PrintTarget { public: static already_AddRefed<PrintTargetCG> CreateOrNull( nsIOutputStream* aOutputStream, PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize); PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize); nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName, int32_t aStartPage, Loading @@ -34,17 +32,16 @@ class PrintTargetCG final : public PrintTarget { already_AddRefed<DrawTarget> GetReferenceDrawTarget() final; private: PrintTargetCG(CGContextRef aPrintToStreamContext, PMPrintSession aPrintSession, PMPageFormat aPageFormat, PrintTargetCG(PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize); ~PrintTargetCG(); CGContextRef mPrintToStreamContext = nullptr; PMPrintSession mPrintSession; PMPageFormat mPageFormat; PMPrintSettings mPrintSettings; }; } // namespace mozilla::gfx } // namespace gfx } // namespace mozilla #endif /* MOZILLA_GFX_PRINTTARGETCG_H */
gfx/thebes/PrintTargetCG.mm +25 −103 Original line number Diff line number Diff line Loading @@ -10,17 +10,13 @@ #include "mozilla/gfx/HelpersCairo.h" #include "nsObjCExceptions.h" #include "nsString.h" #include "nsIOutputStream.h" namespace mozilla::gfx { namespace mozilla { namespace gfx { static size_t PutBytesNull(void* info, const void* buffer, size_t count) { return count; } PrintTargetCG::PrintTargetCG(CGContextRef aPrintToStreamContext, PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize) PrintTargetCG::PrintTargetCG(PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize) : PrintTarget(/* aCairoSurface */ nullptr, aSize), mPrintToStreamContext(aPrintToStreamContext), mPrintSession(aPrintSession), mPageFormat(aPageFormat), mPrintSettings(aPrintSettings) { Loading @@ -45,80 +41,24 @@ PrintTargetCG::~PrintTargetCG() { ::PMRelease(mPageFormat); ::PMRelease(mPrintSettings); if (mPrintToStreamContext) { CGContextRelease(mPrintToStreamContext); } NS_OBJC_END_TRY_IGNORE_BLOCK; } static size_t WriteStreamBytes(void* aInfo, const void* aBuffer, size_t aCount) { auto* stream = static_cast<nsIOutputStream*>(aInfo); auto* data = static_cast<const char*>(aBuffer); size_t remaining = aCount; do { uint32_t wrote = 0; // Handle potential narrowing from size_t to uint32_t. uint32_t toWrite = uint32_t(std::min(remaining, size_t(std::numeric_limits<uint32_t>::max()))); if (NS_WARN_IF(NS_FAILED(stream->Write(data, toWrite, &wrote)))) { break; } data += wrote; remaining -= size_t(wrote); } while (remaining); return aCount; } static void ReleaseStream(void* aInfo) { auto* stream = static_cast<nsIOutputStream*>(aInfo); stream->Close(); NS_RELEASE(stream); } static CGContextRef CreatePrintToStreamContext(nsIOutputStream* aOutputStream, const IntSize& aSize) { MOZ_ASSERT(aOutputStream); NS_ADDREF(aOutputStream); // Matched by the NS_RELEASE in ReleaseStream. CGRect pageBox{{0.0, 0.0}, {CGFloat(aSize.width), CGFloat(aSize.height)}}; CGDataConsumerCallbacks callbacks = {WriteStreamBytes, ReleaseStream}; CGDataConsumerRef consumer = CGDataConsumerCreate(aOutputStream, &callbacks); // This metadata is added by the CorePrinting APIs in the non-stream case. NSString* bundleName = [NSBundle.mainBundle.localizedInfoDictionary objectForKey:(NSString*)kCFBundleNameKey]; CFMutableDictionaryRef auxiliaryInfo = CFDictionaryCreateMutable( kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionaryAddValue(auxiliaryInfo, kCGPDFContextCreator, (__bridge CFStringRef)bundleName); CGContextRef pdfContext = CGPDFContextCreate(consumer, &pageBox, auxiliaryInfo); CGDataConsumerRelease(consumer); CFRelease(auxiliaryInfo); return pdfContext; } /* static */ already_AddRefed<PrintTargetCG> PrintTargetCG::CreateOrNull( nsIOutputStream* aOutputStream, PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize) { PMPrintSession aPrintSession, PMPageFormat aPageFormat, PMPrintSettings aPrintSettings, const IntSize& aSize) { if (!Factory::CheckSurfaceSize(aSize)) { return nullptr; } CGContextRef printToStreamContext = nullptr; if (aOutputStream) { printToStreamContext = CreatePrintToStreamContext(aOutputStream, aSize); if (!printToStreamContext) { return nullptr; } } RefPtr<PrintTargetCG> target = new PrintTargetCG(printToStreamContext, aPrintSession, aPageFormat, aPrintSettings, aSize); new PrintTargetCG(aPrintSession, aPageFormat, aPrintSettings, aSize); return target.forget(); } static size_t PutBytesNull(void* info, const void* buffer, size_t count) { return count; } already_AddRefed<DrawTarget> PrintTargetCG::GetReferenceDrawTarget() { if (!mRefDT) { const IntSize size(1, 1); Loading Loading @@ -155,10 +95,6 @@ nsresult PrintTargetCG::BeginPrinting(const nsAString& aTitle, const nsAString& int32_t aStartPage, int32_t aEndPage) { NS_OBJC_BEGIN_TRY_BLOCK_RETURN; if (mPrintToStreamContext) { return NS_OK; } // 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) Loading Loading @@ -191,12 +127,6 @@ nsresult PrintTargetCG::BeginPrinting(const nsAString& aTitle, const nsAString& nsresult PrintTargetCG::EndPrinting() { NS_OBJC_BEGIN_TRY_BLOCK_RETURN; if (mPrintToStreamContext) { CGContextFlush(mPrintToStreamContext); CGPDFContextClose(mPrintToStreamContext); return NS_OK; } ::PMSessionEndDocumentNoDialog(mPrintSession); return NS_OK; Loading @@ -213,17 +143,13 @@ nsresult PrintTargetCG::AbortPrinting() { nsresult PrintTargetCG::BeginPage() { NS_OBJC_BEGIN_TRY_BLOCK_RETURN; CGContextRef context; if (mPrintToStreamContext) { CGContextBeginPage(mPrintToStreamContext, nullptr); context = mPrintToStreamContext; } else { PMSessionError(mPrintSession); OSStatus status = ::PMSessionBeginPageNoDialog(mPrintSession, mPageFormat, nullptr); OSStatus status = ::PMSessionBeginPageNoDialog(mPrintSession, mPageFormat, NULL); if (status != noErr) { return NS_ERROR_ABORT; } CGContextRef context; // This call will fail if it wasn't called between the PMSessionBeginPage/ // PMSessionEndPage calls: ::PMSessionGetCGGraphicsContext(mPrintSession, &context); Loading @@ -231,7 +157,6 @@ nsresult PrintTargetCG::BeginPage() { if (!context) { return NS_ERROR_FAILURE; } } unsigned int width = static_cast<unsigned int>(mSize.width); unsigned int height = static_cast<unsigned int>(mSize.height); Loading Loading @@ -260,18 +185,15 @@ nsresult PrintTargetCG::EndPage() { cairo_surface_finish(mCairoSurface); mCairoSurface = nullptr; if (mPrintToStreamContext) { CGContextEndPage(mPrintToStreamContext); } else { OSStatus status = ::PMSessionEndPageNoDialog(mPrintSession); if (status != noErr) { return NS_ERROR_ABORT; } } return PrintTarget::EndPage(); NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE); } } // namespace mozilla::gfx } // namespace gfx } // namespace mozilla
layout/printing/nsPrintJob.cpp +6 −4 Original line number Diff line number Diff line Loading @@ -1080,9 +1080,10 @@ nsresult nsPrintJob::SetupToPrintContent() { nsAutoString fileNameStr; // check to see if we are printing to a file if (printData->mPrintSettings->GetOutputDestination() == nsIPrintSettings::kOutputDestinationFile) { // On some platforms the BeginDocument needs to know the name of the file. bool isPrintToFile = false; printData->mPrintSettings->GetPrintToFile(&isPrintToFile); if (isPrintToFile) { // On some platforms The BeginDocument needs to know the name of the file. printData->mPrintSettings->GetToFileName(fileNameStr); } Loading Loading @@ -2331,7 +2332,8 @@ nsresult nsPrintJob::StartPagePrintTimer(const UniquePtr<nsPrintObject>& aPO) { if (!mPagePrintTimer) { // Get the delay time in between the printing of each page // this gives the user more time to press cancel int32_t printPageDelay = mPrt->mPrintSettings->GetPrintPageDelay(); int32_t printPageDelay = 50; mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay); nsCOMPtr<nsIContentViewer> cv = do_QueryInterface(mDocViewerPrint); NS_ENSURE_TRUE(cv, NS_ERROR_FAILURE); Loading
layout/tools/reftest/reftest.jsm +1 −1 Original line number Diff line number Diff line Loading @@ -1721,7 +1721,7 @@ function RecvStartPrint(isPrintSelection, printRange) ps.unwriteableMarginRight = 0; ps.unwriteableMarginLeft = 0; ps.unwriteableMarginBottom = 0; ps.outputDestination = Ci.nsIPrintSettings.kOutputDestinationFile; ps.printToFile = true; ps.toFileName = file.path; ps.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF; ps.printSelectionOnly = isPrintSelection; Loading