1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_layout_RemotePrintJobParent_h 8 #define mozilla_layout_RemotePrintJobParent_h 9 10 #include "mozilla/layout/PRemotePrintJobParent.h" 11 #include "mozilla/layout/printing/DrawEventRecorder.h" 12 13 #include "nsCOMArray.h" 14 #include "nsCOMPtr.h" 15 #include "mozilla/RefPtr.h" 16 #include "mozilla/UniquePtr.h" 17 #include "mozilla/gfx/RecordedEvent.h" 18 #include "mozilla/gfx/CrossProcessPaint.h" 19 20 class nsDeviceContext; 21 class nsIPrintSettings; 22 class nsIWebProgressListener; 23 24 namespace mozilla { 25 namespace layout { 26 27 class PrintTranslator; 28 29 class RemotePrintJobParent final : public PRemotePrintJobParent { 30 public: 31 NS_INLINE_DECL_REFCOUNTING(RemotePrintJobParent); 32 33 explicit RemotePrintJobParent(nsIPrintSettings* aPrintSettings); 34 35 void ActorDestroy(ActorDestroyReason aWhy) final; 36 37 mozilla::ipc::IPCResult RecvInitializePrint(const nsString& aDocumentTitle, 38 const nsString& aPrintToFile, 39 const int32_t& aStartPage, 40 const int32_t& aEndPage) final; 41 42 mozilla::ipc::IPCResult RecvProcessPage(nsTArray<uint64_t>&& aDeps) final; 43 44 mozilla::ipc::IPCResult RecvFinalizePrint() final; 45 46 mozilla::ipc::IPCResult RecvAbortPrint(const nsresult& aRv) final; 47 48 mozilla::ipc::IPCResult RecvStateChange(const long& aStateFlags, 49 const nsresult& aStatus) final; 50 51 mozilla::ipc::IPCResult RecvProgressChange( 52 const long& aCurSelfProgress, const long& aMaxSelfProgress, 53 const long& aCurTotalProgress, const long& aMaxTotalProgress) final; 54 55 mozilla::ipc::IPCResult RecvStatusChange(const nsresult& aStatus) final; 56 57 /** 58 * Register a progress listener to receive print progress updates. 59 * 60 * @param aListener the progress listener to register. Must not be null. 61 */ 62 void RegisterListener(nsIWebProgressListener* aListener); 63 64 /** 65 * @return the print settings for this remote print job. 66 */ 67 already_AddRefed<nsIPrintSettings> GetPrintSettings(); 68 69 private: 70 ~RemotePrintJobParent() final; 71 72 nsresult InitializePrintDevice(const nsString& aDocumentTitle, 73 const nsString& aPrintToFile, 74 const int32_t& aStartPage, 75 const int32_t& aEndPage); 76 77 nsresult PrepareNextPageFD(FileDescriptor* aFd); 78 79 nsresult PrintPage( 80 PRFileDescStream& aRecording, 81 gfx::CrossProcessPaint::ResolvedFragmentMap* aFragments = nullptr); 82 void FinishProcessingPage( 83 gfx::CrossProcessPaint::ResolvedFragmentMap* aFragments = nullptr); 84 85 /** 86 * Called to notify our corresponding RemotePrintJobChild once we've 87 * finished printing a page. 88 */ 89 void PageDone(nsresult aResult); 90 91 nsCOMPtr<nsIPrintSettings> mPrintSettings; 92 RefPtr<nsDeviceContext> mPrintDeviceContext; 93 UniquePtr<PrintTranslator> mPrintTranslator; 94 nsCOMArray<nsIWebProgressListener> mPrintProgressListeners; 95 PRFileDescStream mCurrentPageStream; 96 bool mIsDoingPrinting; 97 }; 98 99 } // namespace layout 100 } // namespace mozilla 101 102 #endif // mozilla_layout_RemotePrintJobParent_h 103