Bug 1399787 - Part 14. Prevent RemotePrintJobChild using ipc calls after the channel was destroyed. draft
authorcku <cku@mozilla.com>
Mon, 23 Oct 2017 15:57:18 +0800
changeset 710613 0063ec07d5670260bf50809f8931c8e7db9be90f
parent 710612 77613816563a39f6a3f9b1ba6e4ee41d0d90172d
child 710614 119c57ef1da3657d98331c8b052c102abbe91855
push id92855
push usercku@mozilla.com
push dateMon, 11 Dec 2017 02:44:26 +0000
bugs1399787
milestone59.0a1
Bug 1399787 - Part 14. Prevent RemotePrintJobChild using ipc calls after the channel was destroyed. If in the future nsDeviceContextSpecWin::BeginDocument was to return NS_ERROR_FAILURE, then the channel between RemotePrintJobParent and RemotePrintJobChild will be close at [1]. RemotePrintJobChild keep using ipc calls after the channel is broken and hits assertions. PS: We always hits this assertion by forcing nsDeviceContextSpecWin::BeginDocument returning NS_ERROR_FAILURE. It's not relative to the change we made in previous patches. [1] https://hg.mozilla.org/mozilla-central/file/b186fddce27f/layout/printing/ipc/RemotePrintJobParent.cpp#l44 MozReview-Commit-ID: 79mZBf301nb
layout/printing/ipc/RemotePrintJobChild.cpp
layout/printing/ipc/RemotePrintJobChild.h
--- a/layout/printing/ipc/RemotePrintJobChild.cpp
+++ b/layout/printing/ipc/RemotePrintJobChild.cpp
@@ -66,17 +66,19 @@ RemotePrintJobChild::SetNextPageFD(const
 }
 
 void
 RemotePrintJobChild::ProcessPage()
 {
   MOZ_ASSERT(mPagePrintTimer);
 
   mPagePrintTimer->WaitForRemotePrint();
-  Unused << SendProcessPage();
+  if (!mDestroyed) {
+    Unused << SendProcessPage();
+  }
 }
 
 mozilla::ipc::IPCResult
 RemotePrintJobChild::RecvPageProcessed(const mozilla::ipc::FileDescriptor& aFd)
 {
   MOZ_ASSERT(mPagePrintTimer);
   SetNextPageFD(aFd);
 
@@ -111,47 +113,56 @@ RemotePrintJobChild::SetPrintEngine(nsPr
 
 // nsIWebProgressListener
 
 NS_IMETHODIMP
 RemotePrintJobChild::OnStateChange(nsIWebProgress* aProgress,
                                    nsIRequest* aRequest, uint32_t aStateFlags,
                                    nsresult aStatus)
 {
-  Unused << SendStateChange(aStateFlags, aStatus);
+  if (!mDestroyed) {
+    Unused << SendStateChange(aStateFlags, aStatus);
+  }
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 RemotePrintJobChild::OnProgressChange(nsIWebProgress * aProgress,
                                       nsIRequest * aRequest,
                                       int32_t aCurSelfProgress,
                                       int32_t aMaxSelfProgress,
                                       int32_t aCurTotalProgress,
                                       int32_t aMaxTotalProgress)
 {
-  Unused << SendProgressChange(aCurSelfProgress, aMaxSelfProgress,
-                               aCurTotalProgress, aMaxTotalProgress);
+  if (!mDestroyed) {
+    Unused << SendProgressChange(aCurSelfProgress, aMaxSelfProgress,
+                                 aCurTotalProgress, aMaxTotalProgress);
+  }
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 RemotePrintJobChild::OnLocationChange(nsIWebProgress* aProgress,
                                       nsIRequest* aRequest, nsIURI* aURI,
                                       uint32_t aFlags)
 {
   return NS_OK;
 }
 
 NS_IMETHODIMP
 RemotePrintJobChild::OnStatusChange(nsIWebProgress* aProgress,
                                     nsIRequest* aRequest, nsresult aStatus,
                                     const char16_t* aMessage)
 {
-  Unused << SendStatusChange(aStatus);
+  if (!mDestroyed) {
+    Unused << SendStatusChange(aStatus);
+  }
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 RemotePrintJobChild::OnSecurityChange(nsIWebProgress* aProgress,
                                       nsIRequest* aRequest, uint32_t aState)
 {
   return NS_OK;
@@ -163,12 +174,14 @@ RemotePrintJobChild::~RemotePrintJobChil
 {
 }
 
 void
 RemotePrintJobChild::ActorDestroy(ActorDestroyReason aWhy)
 {
   mPagePrintTimer = nullptr;
   mPrintEngine = nullptr;
+
+  mDestroyed = true;
 }
 
 } // namespace layout
 } // namespace mozilla
--- a/layout/printing/ipc/RemotePrintJobChild.h
+++ b/layout/printing/ipc/RemotePrintJobChild.h
@@ -50,16 +50,17 @@ public:
 
   PRFileDesc* GetNextPageFD();
 
 private:
   ~RemotePrintJobChild() final;
   void SetNextPageFD(const mozilla::ipc::FileDescriptor& aFd);
 
   bool mPrintInitialized = false;
+  bool mDestroyed = false;
   nsresult mInitializationResult = NS_OK;
   RefPtr<nsPagePrintTimer> mPagePrintTimer;
   RefPtr<nsPrintEngine> mPrintEngine;
   PRFileDesc* mNextPageFD = nullptr;
 };
 
 } // namespace layout
 } // namespace mozilla