Bug 1399787 - Part 9. Do not send a message when RemotePrintJobChild have been destroyed. draft
authorcku <cku@mozilla.com>
Mon, 23 Oct 2017 15:57:18 +0800
changeset 684622 3be35a32cf5fbf88ee1a7109a0dbc5ee1da32251
parent 684621 90b851ba5c4c0d1d95996ead1fe36793fc1d14d5
child 684623 11109722b7e25ea9a19b3cb599931344c2c7f762
push id85677
push usercku@mozilla.com
push dateMon, 23 Oct 2017 08:32:27 +0000
bugs1399787
milestone58.0a1
Bug 1399787 - Part 9. Do not send a message when RemotePrintJobChild have been destroyed. If we force nsDeviceContextSpecWin::BeginDocument return NS_ERROR_FAILURE, then the channel between RemotePrintJobParent and RemotePrintJobChild will be close at [1]. We will hit an assertion which tell us that we should not use ipc methods after the channle is close by doing this. Here is a reason why we hit that assertion: At the destructor of nsPrintData, it notifies all IWebProgressListener listeners that the progress is 100% now. Unfortunately, RemotePrintJobChildi is one of those listener, so we will actually use ipc methods after the channel is close since we call Send_delete__ ipc method to close channel beforehand at [1]. PS: We will always hit this assertion if nsDeviceContextSpecWin::BeginDocument returns NS_ERROR_FAILURE. It's not relative to the change 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
@@ -13,16 +13,17 @@
 
 namespace mozilla {
 namespace layout {
 
 NS_IMPL_ISUPPORTS(RemotePrintJobChild,
                   nsIWebProgressListener)
 
 RemotePrintJobChild::RemotePrintJobChild()
+ : mDestroyed(false)
 {
 }
 
 nsresult
 RemotePrintJobChild::InitializePrint(const nsString& aDocumentTitle,
                                      const nsString& aPrintToFile,
                                      const int32_t& aStartPage,
                                      const int32_t& aEndPage)
@@ -100,47 +101,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;
@@ -152,12 +162,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
@@ -55,14 +55,16 @@ 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;
+
+  bool mDestroyed;
 };
 
 } // namespace layout
 } // namespace mozilla
 
 #endif // mozilla_layout_RemotePrintJobChild_h