Files
firefox/layout/printing/ipc/RemotePrintJobParent.cpp
T
Bob Owen fd7c195dd6 Bug 1156742 Part 24: Add new Recorded event to record font data. r=bas
We create and destroy ScaledFonts for every piece of text we write.
That causes a huge amount of duplicated data within the recording.
This splits out the recording of the font data itself from the ScaledFont.
The key generated to determine uniqueness could probably be fairly easily faked, but for our purposes that doesn't matter.
2016-01-05 10:08:58 +00:00

166 lines
4.2 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "RemotePrintJobParent.h"
#include <istream>
#include "gfxContext.h"
#include "mozilla/Attributes.h"
#include "mozilla/unused.h"
#include "nsComponentManagerUtils.h"
#include "nsDeviceContext.h"
#include "nsIDeviceContextSpec.h"
#include "nsIPrintSettings.h"
#include "PrintTranslator.h"
namespace mozilla {
namespace layout {
RemotePrintJobParent::RemotePrintJobParent(nsIPrintSettings* aPrintSettings)
: mPrintSettings(aPrintSettings)
{
MOZ_COUNT_CTOR(RemotePrintJobParent);
}
bool
RemotePrintJobParent::RecvInitializePrint(const nsString& aDocumentTitle,
const nsString& aPrintToFile,
const int32_t& aStartPage,
const int32_t& aEndPage)
{
nsresult rv = InitializePrintDevice(aDocumentTitle, aPrintToFile, aStartPage,
aEndPage);
if (NS_FAILED(rv)) {
Unused << SendPrintInitializationResult(rv);
Unused << Send__delete__(this);
return true;
}
mPrintTranslator.reset(new PrintTranslator(mPrintDeviceContext));
Unused << SendPrintInitializationResult(NS_OK);
return true;
}
nsresult
RemotePrintJobParent::InitializePrintDevice(const nsString& aDocumentTitle,
const nsString& aPrintToFile,
const int32_t& aStartPage,
const int32_t& aEndPage)
{
nsresult rv;
nsCOMPtr<nsIDeviceContextSpec> deviceContextSpec =
do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = deviceContextSpec->Init(nullptr, mPrintSettings, false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mPrintDeviceContext = new nsDeviceContext();
rv = mPrintDeviceContext->InitForPrinting(deviceContextSpec);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = mPrintDeviceContext->BeginDocument(aDocumentTitle, aPrintToFile,
aStartPage, aEndPage);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
bool
RemotePrintJobParent::RecvProcessPage(Shmem&& aStoredPage)
{
nsresult rv = PrintPage(aStoredPage);
// Always deallocate the shared memory no matter what the result.
if (!DeallocShmem(aStoredPage)) {
NS_WARNING("Failed to deallocated shared memory, remote print will abort.");
rv = NS_ERROR_FAILURE;
}
if (NS_FAILED(rv)) {
Unused << SendAbortPrint(rv);
} else {
Unused << SendPageProcessed();
}
return true;
}
nsresult
RemotePrintJobParent::PrintPage(const Shmem& aStoredPage)
{
MOZ_ASSERT(mPrintDeviceContext);
nsresult rv = mPrintDeviceContext->BeginPage();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
std::istringstream recording(std::string(aStoredPage.get<char>(),
aStoredPage.Size<char>()));
mPrintTranslator->TranslateRecording(recording);
rv = mPrintDeviceContext->EndPage();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
bool
RemotePrintJobParent::RecvFinalizePrint()
{
// EndDocument is sometimes called in the child even when BeginDocument has
// not been called. See bug 1223332.
if (mPrintDeviceContext) {
nsresult rv = mPrintDeviceContext->EndDocument();
// Too late to abort the child just log.
NS_WARN_IF(NS_FAILED(rv));
}
Unused << Send__delete__(this);
return true;
}
bool
RemotePrintJobParent::RecvAbortPrint(const nsresult& aRv)
{
if (mPrintDeviceContext) {
Unused << mPrintDeviceContext->AbortDocument();
}
Unused << Send__delete__(this);
return true;
}
RemotePrintJobParent::~RemotePrintJobParent()
{
MOZ_COUNT_DTOR(RemotePrintJobParent);
}
void
RemotePrintJobParent::ActorDestroy(ActorDestroyReason aWhy)
{
}
} // namespace layout
} // namespace mozilla