зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset a4b0052954d2 (bug 1279699) for causing various crash regressions.
--HG-- extra : rebase_source : bf9223381149f34a7b3513eda05fe197ae2db876
This commit is contained in:
Родитель
d830e33e68
Коммит
21ece8d83a
|
@ -36,8 +36,7 @@ DrawEventRecorderPrivate::RecordEvent(const RecordedEvent &aEvent)
|
|||
}
|
||||
|
||||
DrawEventRecorderFile::DrawEventRecorderFile(const char *aFilename)
|
||||
: DrawEventRecorderPrivate(nullptr)
|
||||
, mOutputFilename(aFilename)
|
||||
: DrawEventRecorderPrivate(nullptr)
|
||||
, mOutputFile(aFilename, ofstream::binary)
|
||||
{
|
||||
mOutputStream = &mOutputFile;
|
||||
|
@ -56,25 +55,6 @@ DrawEventRecorderFile::Flush()
|
|||
mOutputFile.flush();
|
||||
}
|
||||
|
||||
void
|
||||
DrawEventRecorderFile::OpenAndTruncate()
|
||||
{
|
||||
if (mOutputFile.is_open()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mOutputFile.open(mOutputFilename.c_str(), ofstream::binary | ofstream::trunc);
|
||||
WriteHeader();
|
||||
}
|
||||
|
||||
void
|
||||
DrawEventRecorderFile::Close()
|
||||
{
|
||||
MOZ_ASSERT(mOutputFile.is_open());
|
||||
|
||||
mOutputFile.close();
|
||||
}
|
||||
|
||||
DrawEventRecorderMemory::DrawEventRecorderMemory()
|
||||
: DrawEventRecorderPrivate(nullptr)
|
||||
{
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "RecordedEvent.h"
|
||||
#include <ostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include <unordered_set>
|
||||
|
@ -79,24 +78,9 @@ public:
|
|||
explicit DrawEventRecorderFile(const char *aFilename);
|
||||
~DrawEventRecorderFile();
|
||||
|
||||
/**
|
||||
* Re-opens and truncates the file. 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. If the file is already open this does nothing.
|
||||
*/
|
||||
void OpenAndTruncate();
|
||||
|
||||
/**
|
||||
* Closes the file so that it can be processed. The recorder does NOT forget
|
||||
* which objects it has recorded. This can be used with OpenAndTruncate, so
|
||||
* that a recording can be processed in chunks. The file must be open.
|
||||
*/
|
||||
void Close();
|
||||
|
||||
private:
|
||||
virtual void Flush();
|
||||
|
||||
std::string mOutputFilename;
|
||||
std::ofstream mOutputFile;
|
||||
};
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@ parent:
|
|||
|
||||
// Translate the stored page recording and play back the events to the real
|
||||
// print device.
|
||||
async ProcessPage(nsCString aPageFileName);
|
||||
// This will always deallocate the shared memory.
|
||||
async ProcessPage(Shmem aStoredPage);
|
||||
|
||||
// This informs the real print device that we've finished, so it can trigger
|
||||
// the actual print.
|
||||
|
|
|
@ -47,12 +47,12 @@ RemotePrintJobChild::RecvPrintInitializationResult(const nsresult& aRv)
|
|||
}
|
||||
|
||||
void
|
||||
RemotePrintJobChild::ProcessPage(const nsCString& aPageFileName)
|
||||
RemotePrintJobChild::ProcessPage(Shmem& aStoredPage)
|
||||
{
|
||||
MOZ_ASSERT(mPagePrintTimer);
|
||||
|
||||
mPagePrintTimer->WaitForRemotePrint();
|
||||
Unused << SendProcessPage(aPageFileName);
|
||||
Unused << SendProcessPage(aStoredPage);
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
|
||||
mozilla::ipc::IPCResult RecvPrintInitializationResult(const nsresult& aRv) final;
|
||||
|
||||
void ProcessPage(const nsCString& aPageFileName);
|
||||
void ProcessPage(Shmem& aStoredPage);
|
||||
|
||||
mozilla::ipc::IPCResult RecvPageProcessed() final;
|
||||
|
||||
|
|
|
@ -6,14 +6,12 @@
|
|||
|
||||
#include "RemotePrintJobParent.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <istream>
|
||||
|
||||
#include "gfxContext.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsDeviceContext.h"
|
||||
#include "nsIDeviceContextSpec.h"
|
||||
#include "nsIPrintSettings.h"
|
||||
|
@ -83,9 +81,15 @@ RemotePrintJobParent::InitializePrintDevice(const nsString& aDocumentTitle,
|
|||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
RemotePrintJobParent::RecvProcessPage(const nsCString& aPageFileName)
|
||||
RemotePrintJobParent::RecvProcessPage(Shmem&& aStoredPage)
|
||||
{
|
||||
nsresult rv = PrintPage(aPageFileName);
|
||||
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);
|
||||
|
@ -97,7 +101,7 @@ RemotePrintJobParent::RecvProcessPage(const nsCString& aPageFileName)
|
|||
}
|
||||
|
||||
nsresult
|
||||
RemotePrintJobParent::PrintPage(const nsCString& aPageFileName)
|
||||
RemotePrintJobParent::PrintPage(const Shmem& aStoredPage)
|
||||
{
|
||||
MOZ_ASSERT(mPrintDeviceContext);
|
||||
|
||||
|
@ -106,25 +110,8 @@ RemotePrintJobParent::PrintPage(const nsCString& aPageFileName)
|
|||
return rv;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
std::ifstream recording(recordingPath.get(), std::ifstream::binary);
|
||||
std::istringstream recording(std::string(aStoredPage.get<char>(),
|
||||
aStoredPage.Size<char>()));
|
||||
if (!mPrintTranslator->TranslateRecording(recording)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -134,12 +121,6 @@ RemotePrintJobParent::PrintPage(const nsCString& aPageFileName)
|
|||
return rv;
|
||||
}
|
||||
|
||||
recording.close();
|
||||
rv = recordingFile->Remove(/* recursive= */ false);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
const int32_t& aStartPage,
|
||||
const int32_t& aEndPage) final;
|
||||
|
||||
mozilla::ipc::IPCResult RecvProcessPage(const nsCString& aPageFileName) final;
|
||||
mozilla::ipc::IPCResult RecvProcessPage(Shmem&& aStoredPage) final;
|
||||
|
||||
mozilla::ipc::IPCResult RecvFinalizePrint() final;
|
||||
|
||||
|
@ -70,7 +70,7 @@ private:
|
|||
const int32_t& aStartPage,
|
||||
const int32_t& aEndPage);
|
||||
|
||||
nsresult PrintPage(const nsCString& aPageFileName);
|
||||
nsresult PrintPage(const Shmem& aStoredPage);
|
||||
|
||||
nsCOMPtr<nsIPrintSettings> mPrintSettings;
|
||||
RefPtr<nsDeviceContext> mPrintDeviceContext;
|
||||
|
|
|
@ -14,11 +14,8 @@
|
|||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsIPrintSession.h"
|
||||
#include "nsIPrintSettings.h"
|
||||
#include "nsIUUIDGenerator.h"
|
||||
|
||||
using mozilla::Unused;
|
||||
|
||||
|
@ -137,37 +134,7 @@ nsDeviceContextSpecProxy::BeginDocument(const nsAString& aTitle,
|
|||
const nsAString& aPrintToFileName,
|
||||
int32_t aStartPage, int32_t aEndPage)
|
||||
{
|
||||
nsCOMPtr<nsIFile> recordingFile;
|
||||
nsresult rv = NS_GetSpecialDirectory(NS_APP_CONTENT_PROCESS_TEMP_DIR,
|
||||
getter_AddRefs(recordingFile));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIUUIDGenerator> uuidgen =
|
||||
do_GetService("@mozilla.org/uuid-generator;1", &rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsID uuid;
|
||||
rv = uuidgen->GenerateUUIDInPlace(&uuid);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
char uuidChars[NSID_LENGTH];
|
||||
uuid.ToProvidedString(uuidChars);
|
||||
mRecorderFile.AssignASCII(uuidChars);
|
||||
rv = recordingFile->AppendNative(mRecorderFile);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsAutoCString recordingPath;
|
||||
rv = recordingFile->GetNativePath(recordingPath);
|
||||
|
||||
mRecorder = new mozilla::gfx::DrawEventRecorderFile(recordingPath.get());
|
||||
mRecorder = new mozilla::gfx::DrawEventRecorderMemory();
|
||||
return mRemotePrintJob->InitializePrint(nsString(aTitle),
|
||||
nsString(aPrintToFileName),
|
||||
aStartPage, aEndPage);
|
||||
|
@ -190,18 +157,34 @@ nsDeviceContextSpecProxy::AbortDocument()
|
|||
NS_IMETHODIMP
|
||||
nsDeviceContextSpecProxy::BeginPage()
|
||||
{
|
||||
// Reopen the file, if necessary, ready for the next page.
|
||||
mRecorder->OpenAndTruncate();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDeviceContextSpecProxy::EndPage()
|
||||
{
|
||||
// Save the current page recording to shared memory.
|
||||
mozilla::ipc::Shmem storedPage;
|
||||
size_t recordingSize = mRecorder->RecordingSize();
|
||||
if (!mRemotePrintJob->AllocShmem(recordingSize,
|
||||
mozilla::ipc::SharedMemory::TYPE_BASIC,
|
||||
&storedPage)) {
|
||||
NS_WARNING("Failed to create shared memory for remote printing.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
bool success = mRecorder->CopyRecording(storedPage.get<char>(), recordingSize);
|
||||
if (!success) {
|
||||
NS_WARNING("Copying recording to shared memory was not succesful.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Wipe the recording to free memory. The recorder does not forget which data
|
||||
// backed objects that it has stored.
|
||||
mRecorder->WipeRecording();
|
||||
|
||||
// Send the page recording to the parent.
|
||||
mRecorder->Close();
|
||||
mRemotePrintJob->ProcessPage(mRecorderFile);
|
||||
mRemotePrintJob->ProcessPage(storedPage);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -9,13 +9,12 @@
|
|||
|
||||
#include "nsIDeviceContextSpec.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIPrintSession;
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
class DrawEventRecorderFile;
|
||||
class DrawEventRecorderMemory;
|
||||
}
|
||||
|
||||
namespace layout {
|
||||
|
@ -58,8 +57,7 @@ private:
|
|||
nsCOMPtr<nsIPrintSession> mPrintSession;
|
||||
nsCOMPtr<nsIDeviceContextSpec> mRealDeviceContextSpec;
|
||||
RefPtr<mozilla::layout::RemotePrintJobChild> mRemotePrintJob;
|
||||
RefPtr<mozilla::gfx::DrawEventRecorderFile> mRecorder;
|
||||
nsCString mRecorderFile;
|
||||
RefPtr<mozilla::gfx::DrawEventRecorderMemory> mRecorder;
|
||||
};
|
||||
|
||||
#endif // nsDeviceContextSpecProxy_h
|
||||
|
|
|
@ -110,9 +110,6 @@
|
|||
// NS_APP_CONTENT_PROCESS_TEMP_DIR, but that should not be relied upon.
|
||||
//
|
||||
#define NS_APP_CONTENT_PROCESS_TEMP_DIR "ContentTmpD"
|
||||
#else
|
||||
// Otherwise NS_APP_CONTENT_PROCESS_TEMP_DIR must match NS_OS_TEMP_DIR.
|
||||
#define NS_APP_CONTENT_PROCESS_TEMP_DIR "TmpD"
|
||||
#endif // (defined(XP_WIN) || defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX)
|
||||
|
||||
#endif // nsAppDirectoryServiceDefs_h___
|
||||
|
|
Загрузка…
Ссылка в новой задаче