Bug 1342872 - part1: Label the runnable dispatched by NS_DispatchToCurrentThread in nsPrintEngine draft
authorFarmer Tseng <fatseng@mozilla.com>
Tue, 28 Mar 2017 11:50:16 +0800
changeset 553974 da0af734186aa5479524fa491ac993d34c9250e6
parent 489001 69d2cf007cdc13cf2bd33370b1732d4f969fd9af
child 553975 8ed3852fad83e5356869155f452785d11eb507e7
push id51853
push userfatseng@mozilla.com
push dateFri, 31 Mar 2017 05:34:11 +0000
bugs1342872
milestone54.0a1
Bug 1342872 - part1: Label the runnable dispatched by NS_DispatchToCurrentThread in nsPrintEngine MozReview-Commit-ID: BZhRUglmbMW
layout/printing/nsPrintEngine.cpp
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -1866,17 +1866,17 @@ nsPrintEngine::OnStateChange(nsIWebProgr
   if (name.EqualsLiteral("about:document-onload-blocker")) {
     return NS_OK;
   }
   if (aStateFlags & STATE_START) {
     ++mLoadCounter;
   } else if (aStateFlags & STATE_STOP) {
     mDidLoadDataForPrinting = true;
     --mLoadCounter;
-   
+
     // If all resources are loaded, then do a small timeout and if there
     // are still no new requests, then another reflow.
     if (mLoadCounter == 0) {
       AfterNetworkPrint(true);
     }
   }
   return NS_OK;
 }
@@ -3547,19 +3547,25 @@ public:
 private:
   nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
 };
 
 //-----------------------------------------------------------
 void
 nsPrintEngine::FirePrintCompletionEvent()
 {
+  MOZ_ASSERT(NS_IsMainThread());
   nsCOMPtr<nsIRunnable> event = new nsPrintCompletionEvent(mDocViewerPrint);
-  if (NS_FAILED(NS_DispatchToCurrentThread(event)))
-    NS_WARNING("failed to dispatch print completion event");
+  nsCOMPtr<nsIContentViewer> cv = do_QueryInterface(mDocViewerPrint);
+  NS_ENSURE_TRUE_VOID(cv);
+  nsCOMPtr<nsIDocument> doc = cv->GetDocument();
+  NS_ENSURE_TRUE_VOID(doc);
+
+  NS_ENSURE_SUCCESS_VOID(doc->Dispatch("nsPrintCompletionEvent",
+                                       TaskCategory::Other, event.forget()));
 }
 
 void
 nsPrintEngine::DisconnectPagePrintTimer()
 {
   if (mPagePrintTimer) {
     mPagePrintTimer->Disconnect();
     NS_RELEASE(mPagePrintTimer);