Bug 1412643 - revert part 3 of the changes from 1319423 to fix print selection; r=bobowen

This will be re-landed with a real fix for print-selection after we branch for 58.

MozReview-Commit-ID: JjhBEiEviVB

--HG--
extra : rebase_source : 15b9a2eccdc5ce001bacb776e15f98f4d368c436
This commit is contained in:
Alex Gaynor 2017-11-03 14:03:02 -04:00
Родитель 7aa5013aef
Коммит 016a127546
9 изменённых файлов: 116 добавлений и 97 удалений

Просмотреть файл

@ -19,6 +19,12 @@ DrawEventRecorderPRFileDesc::RecordEvent(const gfx::RecordedEvent& aEvent)
Flush();
}
DrawEventRecorderPRFileDesc::DrawEventRecorderPRFileDesc(const char* aFilename)
{
mOutputStream.Open(aFilename);
WriteHeader(mOutputStream);
}
DrawEventRecorderPRFileDesc::~DrawEventRecorderPRFileDesc()
{
if (IsOpen()) {
@ -39,11 +45,11 @@ DrawEventRecorderPRFileDesc::IsOpen()
}
void
DrawEventRecorderPRFileDesc::OpenFD(PRFileDesc* aFd)
DrawEventRecorderPRFileDesc::OpenNew(const char* aFilename)
{
MOZ_ASSERT(!IsOpen());
mOutputStream.OpenFD(aFd);
mOutputStream.Open(aFilename);
WriteHeader(mOutputStream);
}

Просмотреть файл

@ -25,9 +25,9 @@ public:
PRFileDescStream() : mFd(nullptr), mBuffer(nullptr), mBufferPos(0),
mGood(true) {}
void OpenFD(PRFileDesc* aFd) {
void Open(const char* aFilename) {
MOZ_ASSERT(!IsOpen());
mFd = aFd;
mFd = PR_Open(aFilename, PR_RDWR | PR_CREATE_FILE, PR_IRUSR | PR_IWUSR);
mGood = true;
mBuffer.reset(new uint8_t[kBufferSize]);
mBufferPos = 0;
@ -115,7 +115,7 @@ class DrawEventRecorderPRFileDesc : public gfx::DrawEventRecorderPrivate
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorderPRFileDesc, override)
explicit DrawEventRecorderPRFileDesc() { };
explicit DrawEventRecorderPRFileDesc(const char* aFilename);
~DrawEventRecorderPRFileDesc();
void RecordEvent(const gfx::RecordedEvent& aEvent) override;
@ -126,9 +126,11 @@ public:
bool IsOpen();
/**
* Opens the recorder with the provided PRFileDesc *.
* Opens new file with the provided name. The recorder does NOT forget which
* objects it has recorded. This can be used with Close, so that a recording
* can be processed in chunks. The file must not already be open.
*/
void OpenFD(PRFileDesc* aFd);
void OpenNew(const char* aFilename);
/**
* Closes the file so that it can be processed. The recorder does NOT forget

Просмотреть файл

@ -22,9 +22,9 @@ parent:
async InitializePrint(nsString aDocumentTitle, nsString aPrintToFile,
int32_t aStartPage, int32_t aEndPage);
// Translate the page recording writen into |fd| and play back the events to
// the real print device.
async ProcessPage();
// Translate the stored page recording and play back the events to the real
// print device.
async ProcessPage(nsCString aPageFileName);
// This informs the real print device that we've finished, so it can trigger
// the actual print.
@ -45,13 +45,11 @@ parent:
child:
// Inform the child that the print has been initialized in the parent or has
// failed with result aRv. Includes a file descriptor which the first page
// can be written to.
async PrintInitializationResult(nsresult aRv, FileDescriptor aFd);
// failed with result aRv.
async PrintInitializationResult(nsresult aRv);
// Inform the child that the latest page has been processed remotely. Inclues
// a file descriptor which the next page can be written to.
async PageProcessed(FileDescriptor aFd);
// Inform the child that the latest page has been processed remotely.
async PageProcessed();
async __delete__();
};

Просмотреть файл

@ -9,7 +9,6 @@
#include "mozilla/Unused.h"
#include "nsPagePrintTimer.h"
#include "nsPrintEngine.h"
#include "private/pprio.h"
namespace mozilla {
namespace layout {
@ -37,37 +36,26 @@ RemotePrintJobChild::InitializePrint(const nsString& aDocumentTitle,
}
mozilla::ipc::IPCResult
RemotePrintJobChild::RecvPrintInitializationResult(const nsresult& aRv,
const mozilla::ipc::FileDescriptor& aFd)
RemotePrintJobChild::RecvPrintInitializationResult(const nsresult& aRv)
{
mPrintInitialized = true;
mInitializationResult = aRv;
if (NS_SUCCEEDED(aRv)) {
SetNextPageFD(aFd);
}
return IPC_OK();
}
void RemotePrintJobChild::SetNextPageFD(const mozilla::ipc::FileDescriptor& aFd)
{
auto handle = aFd.ClonePlatformHandle();
mNextPageFD = PR_ImportFile(PROsfd(handle.release()));
}
void
RemotePrintJobChild::ProcessPage()
RemotePrintJobChild::ProcessPage(const nsCString& aPageFileName)
{
MOZ_ASSERT(mPagePrintTimer);
mPagePrintTimer->WaitForRemotePrint();
Unused << SendProcessPage();
Unused << SendProcessPage(aPageFileName);
}
mozilla::ipc::IPCResult
RemotePrintJobChild::RecvPageProcessed(const mozilla::ipc::FileDescriptor& aFd)
RemotePrintJobChild::RecvPageProcessed()
{
MOZ_ASSERT(mPagePrintTimer);
SetNextPageFD(aFd);
mPagePrintTimer->RemotePrintFinished();
return IPC_OK();

Просмотреть файл

@ -34,12 +34,11 @@ public:
const int32_t& aStartPage,
const int32_t& aEndPage);
mozilla::ipc::IPCResult RecvPrintInitializationResult(const nsresult& aRv,
const FileDescriptor& aFd) final;
mozilla::ipc::IPCResult RecvPrintInitializationResult(const nsresult& aRv) final;
void ProcessPage();
void ProcessPage(const nsCString& aPageFileName);
mozilla::ipc::IPCResult RecvPageProcessed(const FileDescriptor& aFd) final;
mozilla::ipc::IPCResult RecvPageProcessed() final;
mozilla::ipc::IPCResult RecvAbortPrint(const nsresult& aRv) final;
@ -47,19 +46,13 @@ public:
void SetPrintEngine(nsPrintEngine* aPrintEngine);
PRFileDesc *GetNextPageFD() {
return mNextPageFD;
}
private:
~RemotePrintJobChild() final;
void SetNextPageFD(const mozilla::ipc::FileDescriptor& aFd);
bool mPrintInitialized = false;
nsresult mInitializationResult = NS_OK;
RefPtr<nsPagePrintTimer> mPagePrintTimer;
RefPtr<nsPrintEngine> mPrintEngine;
PRFileDesc* mNextPageFD;
};
} // namespace layout

Просмотреть файл

@ -19,8 +19,6 @@
#include "nsIPrintSettings.h"
#include "nsIWebProgressListener.h"
#include "PrintTranslator.h"
#include "private/pprio.h"
#include "nsAnonymousTemporaryFile.h"
namespace mozilla {
namespace layout {
@ -40,21 +38,14 @@ RemotePrintJobParent::RecvInitializePrint(const nsString& aDocumentTitle,
nsresult rv = InitializePrintDevice(aDocumentTitle, aPrintToFile, aStartPage,
aEndPage);
if (NS_FAILED(rv)) {
Unused << SendPrintInitializationResult(rv, FileDescriptor());
Unused << SendPrintInitializationResult(rv);
Unused << Send__delete__(this);
return IPC_OK();
}
mPrintTranslator.reset(new PrintTranslator(mPrintDeviceContext));
FileDescriptor fd;
rv = PrepareNextPageFD(&fd);
if (NS_FAILED(rv)) {
Unused << SendPrintInitializationResult(rv, FileDescriptor());
Unused << Send__delete__(this);
return IPC_OK();
}
Unused << SendPrintInitializationResult(NS_OK);
Unused << SendPrintInitializationResult(NS_OK, fd);
return IPC_OK();
}
@ -91,47 +82,22 @@ RemotePrintJobParent::InitializePrintDevice(const nsString& aDocumentTitle,
return NS_OK;
}
nsresult RemotePrintJobParent::PrepareNextPageFD(FileDescriptor* aFd) {
PRFileDesc *prFd = nullptr;
nsresult rv = NS_OpenAnonymousTemporaryFile(&prFd);
if (NS_FAILED(rv)) {
return rv;
}
*aFd = FileDescriptor(
FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(prFd)));
mCurrentPageStream.OpenFD(prFd);
return NS_OK;
}
mozilla::ipc::IPCResult
RemotePrintJobParent::RecvProcessPage()
RemotePrintJobParent::RecvProcessPage(const nsCString& aPageFileName)
{
if (!mCurrentPageStream.IsOpen()) {
Unused << SendAbortPrint(NS_ERROR_FAILURE);
return IPC_OK();
}
mCurrentPageStream.Seek(0, PR_SEEK_SET);
nsresult rv = PrintPage(mCurrentPageStream);
mCurrentPageStream.Close();
nsresult rv = PrintPage(aPageFileName);
if (NS_FAILED(rv)) {
Unused << SendAbortPrint(rv);
return IPC_OK();
} else {
Unused << SendPageProcessed();
}
FileDescriptor fd;
rv = PrepareNextPageFD(&fd);
if (NS_FAILED(rv)) {
Unused << SendAbortPrint(rv);
return IPC_OK();
}
Unused << SendPageProcessed(fd);
return IPC_OK();
}
nsresult
RemotePrintJobParent::PrintPage(PRFileDescStream& aRecording)
RemotePrintJobParent::PrintPage(const nsCString& aPageFileName)
{
MOZ_ASSERT(mPrintDeviceContext);
@ -139,7 +105,29 @@ RemotePrintJobParent::PrintPage(PRFileDescStream& aRecording)
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (!mPrintTranslator->TranslateRecording(aRecording)) {
nsCOMPtr<nsIFile> recordingFile;
rv = NS_GetSpecialDirectory(NS_APP_CONTENT_PROCESS_TEMP_DIR,
getter_AddRefs(recordingFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = recordingFile->AppendNative(aPageFileName);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsAutoCString recordingPath;
rv = recordingFile->GetNativePath(recordingPath);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
PRFileDescStream recording;
recording.Open(recordingPath.get());
MOZ_ASSERT(recording.IsOpen());
if (!mPrintTranslator->TranslateRecording(recording)) {
return NS_ERROR_FAILURE;
}
@ -148,6 +136,12 @@ RemotePrintJobParent::PrintPage(PRFileDescStream& aRecording)
return rv;
}
recording.Close();
rv = recordingFile->Remove(/* recursive= */ false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}

Просмотреть файл

@ -8,13 +8,11 @@
#define mozilla_layout_RemotePrintJobParent_h
#include "mozilla/layout/PRemotePrintJobParent.h"
#include "mozilla/layout/printing/DrawEventRecorder.h"
#include "nsCOMArray.h"
#include "nsCOMPtr.h"
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/gfx/RecordedEvent.h"
class nsDeviceContext;
class nsIPrintSettings;
@ -36,7 +34,7 @@ public:
const int32_t& aStartPage,
const int32_t& aEndPage) final;
mozilla::ipc::IPCResult RecvProcessPage() final;
mozilla::ipc::IPCResult RecvProcessPage(const nsCString& aPageFileName) final;
mozilla::ipc::IPCResult RecvFinalizePrint() final;
@ -72,15 +70,12 @@ private:
const int32_t& aStartPage,
const int32_t& aEndPage);
nsresult PrepareNextPageFD(FileDescriptor* aFd);
nsresult PrintPage(PRFileDescStream& aRecording);
nsresult PrintPage(const nsCString& aPageFileName);
nsCOMPtr<nsIPrintSettings> mPrintSettings;
RefPtr<nsDeviceContext> mPrintDeviceContext;
UniquePtr<PrintTranslator> mPrintTranslator;
nsCOMArray<nsIWebProgressListener> mPrintProgressListeners;
PRFileDescStream mCurrentPageStream;
};
} // namespace layout

Просмотреть файл

@ -145,8 +145,7 @@ nsPagePrintTimer::Notify(nsITimer *timer)
if (mDocViewerPrint) {
bool donePrePrint = true;
// Don't start to pre-print if we're waiting on the parent still.
if (mPrintEngine && !mWaitingForRemotePrint) {
if (mPrintEngine) {
donePrePrint = mPrintEngine->PrePrintPage();
}

Просмотреть файл

@ -19,7 +19,6 @@
#include "nsIPrintSession.h"
#include "nsIPrintSettings.h"
#include "nsIUUIDGenerator.h"
#include "private/pprio.h"
using mozilla::Unused;
@ -144,12 +143,48 @@ nsDeviceContextSpecProxy::GetPrintingScale()
return mRealDeviceContextSpec->GetPrintingScale();
}
nsresult
nsDeviceContextSpecProxy::CreateUniqueTempPath(nsACString& aFilePath)
{
MOZ_ASSERT(mRecordingDir);
MOZ_ASSERT(mUuidGenerator);
nsID uuid;
nsresult rv = mUuidGenerator->GenerateUUIDInPlace(&uuid);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
char uuidChars[NSID_LENGTH];
uuid.ToProvidedString(uuidChars);
mRecordingFileName.AssignASCII(uuidChars);
nsCOMPtr<nsIFile> recordingFile;
rv = mRecordingDir->Clone(getter_AddRefs(recordingFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = recordingFile->AppendNative(mRecordingFileName);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return recordingFile->GetNativePath(aFilePath);
}
NS_IMETHODIMP
nsDeviceContextSpecProxy::BeginDocument(const nsAString& aTitle,
const nsAString& aPrintToFileName,
int32_t aStartPage, int32_t aEndPage)
{
mRecorder = new mozilla::layout::DrawEventRecorderPRFileDesc();
nsAutoCString recordingPath;
nsresult rv = CreateUniqueTempPath(recordingPath);
if (NS_FAILED(rv)) {
return rv;
}
mRecorder = new mozilla::layout::DrawEventRecorderPRFileDesc(recordingPath.get());
return mRemotePrintJob->InitializePrint(nsString(aTitle),
nsString(aPrintToFileName),
aStartPage, aEndPage);
@ -172,7 +207,16 @@ nsDeviceContextSpecProxy::AbortDocument()
NS_IMETHODIMP
nsDeviceContextSpecProxy::BeginPage()
{
mRecorder->OpenFD(mRemotePrintJob->GetNextPageFD());
// Reopen the file, if necessary, ready for the next page.
if (!mRecorder->IsOpen()) {
nsAutoCString recordingPath;
nsresult rv = CreateUniqueTempPath(recordingPath);
if (NS_FAILED(rv)) {
return rv;
}
mRecorder->OpenNew(recordingPath.get());
}
return NS_OK;
}
@ -182,7 +226,7 @@ nsDeviceContextSpecProxy::EndPage()
{
// Send the page recording to the parent.
mRecorder->Close();
mRemotePrintJob->ProcessPage();
mRemotePrintJob->ProcessPage(mRecordingFileName);
return NS_OK;
}