Bug 1399787 - Part 14. Prevent RemotePrintJobChild using ipc calls after the channel was destroyed. r=jwatt
☠☠ backed out by f0afedbc68cf ☠ ☠
authorcku <cku@mozilla.com>
Mon, 23 Oct 2017 15:57:18 +0800
changeset 449823 d875e45f591e3a4d445e0fb5c6970ee3cf963d93
parent 449822 8f600ac930ecfa6b064b288f17d7063df2a89247
child 449824 b1457eabd34e5a3a079c32e4809dbe13db5af9c0
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1399787
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1399787 - Part 14. Prevent RemotePrintJobChild using ipc calls after the channel was destroyed. r=jwatt 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