Merge inbound to mozilla-central r=merge a=merge
authorCsoregi Natalia <ncsoregi@mozilla.com>
Sat, 16 Dec 2017 11:37:48 +0200
changeset 448364 4780efa5f11052cfe775e1d1e76d85cfc0bfc1ea
parent 448354 c7b12687881472ccc90138690863000dcfa5856a (current diff)
parent 448363 31be43353751a97126b1676ea36d11b7ef71fa5c (diff)
child 448365 625f7e9eb46b5d0331c89742b1368b9add862ec9
child 448368 26b2e4c281724cac2e09826c5ece56e29359af53
child 448381 26d3df5b58fb60facb9057dc1e86576127c9e1f5
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge, merge
milestone59.0a1
first release with
nightly linux32
4780efa5f110 / 59.0a1 / 20171216100407 / files
nightly linux64
4780efa5f110 / 59.0a1 / 20171216100407 / files
nightly mac
4780efa5f110 / 59.0a1 / 20171216100407 / files
nightly win32
4780efa5f110 / 59.0a1 / 20171216100407 / files
nightly win64
4780efa5f110 / 59.0a1 / 20171216100407 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge inbound to mozilla-central r=merge a=merge
layout/painting/nsDisplayList.cpp
layout/printing/nsPrintEngine.cpp
layout/printing/nsPrintEngine.h
--- a/docshell/base/nsIContentViewerContainer.idl
+++ b/docshell/base/nsIContentViewerContainer.idl
@@ -8,13 +8,13 @@
 
 interface nsIContentViewer;
 
 [scriptable, uuid(ea2ce7a0-5c3d-11d4-90c2-0050041caf44)]
 interface nsIContentViewerContainer : nsISupports {
 	void embed(in nsIContentViewer aDocViewer, in string aCommand, in nsISupports aExtraInfo);
 
   /**
-   * Allows the PrintEngine to make this call on 
-   * an internal interface to the DocShell
+   * Allows nsPrintJob to make this call on an internal interface to the
+   * DocShell.
    */
   void setIsPrinting(in boolean aIsPrinting);
 };
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -1287,23 +1287,32 @@ protected:
                    GLsizei rawHeight, GLsizei rawDepth, GLint border,
                    const TexImageSource& src, const Maybe<GLsizei>& expectedImageSize);
 
 // -----------------------------------------------------------------------------
 // Vertices Feature (WebGLContextVertices.cpp)
     GLenum mPrimRestartTypeBytes;
 
 public:
-    void DrawArrays(GLenum mode, GLint first, GLsizei count);
-    void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count,
-                             GLsizei primcount);
+    void DrawArrays(GLenum mode, GLint first, GLsizei count) {
+        DrawArraysInstanced(mode, first, count, 1, "drawArrays");
+    }
+
     void DrawElements(GLenum mode, GLsizei count, GLenum type,
-                      WebGLintptr byteOffset, const char* funcName = nullptr);
-    void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
-                               WebGLintptr byteOffset, GLsizei primcount);
+                      WebGLintptr byteOffset, const char* funcName = "drawElements")
+    {
+        DrawElementsInstanced(mode, count, type, byteOffset, 1, funcName);
+    }
+
+    void DrawArraysInstanced(GLenum mode, GLint first, GLsizei vertexCount,
+                             GLsizei instanceCount,
+                             const char* funcName = "drawArraysInstanced");
+    void DrawElementsInstanced(GLenum mode, GLsizei vertexCount, GLenum type,
+                               WebGLintptr byteOffset, GLsizei instanceCount,
+                               const char* funcName = "drawElementsInstanced");
 
     void EnableVertexAttribArray(GLuint index);
     void DisableVertexAttribArray(GLuint index);
 
     JS::Value GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
                               ErrorResult& rv);
 
     void GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
--- a/dom/canvas/WebGLContextDraw.cpp
+++ b/dom/canvas/WebGLContextDraw.cpp
@@ -464,16 +464,23 @@ public:
     void Advance() const {
         if (!mWithTF)
             return;
 
         mTFO->mActive_VertPosition += mUsedVerts;
     }
 };
 
+static bool
+HasInstancedDrawing(const WebGLContext& webgl)
+{
+    return webgl.IsWebGL2() ||
+           webgl.IsExtensionEnabled(WebGLExtensionID::ANGLE_instanced_arrays);
+}
+
 ////////////////////////////////////////
 
 bool
 WebGLContext::DrawArrays_check(const char* const funcName, const GLint first,
                                const GLsizei vertCount, const GLsizei instanceCount,
                                Maybe<uint32_t>* const out_lastVert)
 {
     if (!ValidateNonNegative(funcName, "first", first) ||
@@ -502,63 +509,20 @@ WebGLContext::DrawArrays_check(const cha
             return false;
         }
         *out_lastVert = Some(lastVert_checked.value());
     }
     return true;
 }
 
 void
-WebGLContext::DrawArrays(GLenum mode, GLint first, GLsizei vertCount)
-{
-    AUTO_PROFILER_LABEL("WebGLContext::DrawArrays", GRAPHICS);
-    const char funcName[] = "drawArrays";
-    if (IsContextLost())
-        return;
-
-    MakeContextCurrent();
-
-    bool error = false;
-    ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error);
-    if (error)
-        return;
-
-    const GLsizei instanceCount = 1;
-    Maybe<uint32_t> lastVert;
-    if (!DrawArrays_check(funcName, first, vertCount, instanceCount, &lastVert))
-        return;
-
-    const ScopedDrawHelper scopedHelper(this, funcName, mode, lastVert, instanceCount,
-                                        &error);
-    if (error)
-        return;
-
-    const ScopedDrawWithTransformFeedback scopedTF(this, funcName, mode, vertCount,
-                                                   instanceCount, &error);
-    if (error)
-        return;
-
-    {
-        ScopedDrawCallWrapper wrapper(*this);
-        if (vertCount) {
-            AUTO_PROFILER_LABEL("glDrawArrays", GRAPHICS);
-            gl->fDrawArrays(mode, first, vertCount);
-        }
-    }
-
-    Draw_cleanup(funcName);
-    scopedTF.Advance();
-}
-
-void
 WebGLContext::DrawArraysInstanced(GLenum mode, GLint first, GLsizei vertCount,
-                                  GLsizei instanceCount)
+                                  GLsizei instanceCount, const char* const funcName)
 {
     AUTO_PROFILER_LABEL("WebGLContext::DrawArraysInstanced", GRAPHICS);
-    const char funcName[] = "drawArraysInstanced";
     if (IsContextLost())
         return;
 
     MakeContextCurrent();
 
     bool error = false;
     ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error);
     if (error)
@@ -577,17 +541,22 @@ WebGLContext::DrawArraysInstanced(GLenum
                                                    instanceCount, &error);
     if (error)
         return;
 
     {
         ScopedDrawCallWrapper wrapper(*this);
         if (vertCount && instanceCount) {
             AUTO_PROFILER_LABEL("glDrawArraysInstanced", GRAPHICS);
-            gl->fDrawArraysInstanced(mode, first, vertCount, instanceCount);
+            if (HasInstancedDrawing(*this)) {
+                gl->fDrawArraysInstanced(mode, first, vertCount, instanceCount);
+            } else {
+                MOZ_ASSERT(instanceCount == 1);
+                gl->fDrawArrays(mode, first, vertCount);
+            }
         }
     }
 
     Draw_cleanup(funcName);
     scopedTF.Advance();
 }
 
 ////////////////////////////////////////
@@ -697,76 +666,21 @@ HandleDrawElementsErrors(WebGLContext* w
         webgl->ErrorImplementationBug("%s: Unexpected driver error during indexed draw"
                                       " call. Please file a bug.",
                                       funcName);
         return;
     }
 }
 
 void
-WebGLContext::DrawElements(GLenum mode, GLsizei indexCount, GLenum type,
-                           WebGLintptr byteOffset, const char* funcName)
-{
-    AUTO_PROFILER_LABEL("WebGLContext::DrawElements", GRAPHICS);
-    if (!funcName) {
-        funcName = "drawElements";
-    }
-    if (IsContextLost())
-        return;
-
-    MakeContextCurrent();
-
-    bool error = false;
-    ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error);
-    if (error)
-        return;
-
-    const GLsizei instanceCount = 1;
-    Maybe<uint32_t> lastVert;
-    if (!DrawElements_check(funcName, indexCount, type, byteOffset, instanceCount,
-                            &lastVert))
-    {
-        return;
-    }
-
-    const ScopedDrawHelper scopedHelper(this, funcName, mode, lastVert, instanceCount,
-                                        &error);
-    if (error)
-        return;
-
-    {
-        ScopedDrawCallWrapper wrapper(*this);
-        {
-            UniquePtr<gl::GLContext::LocalErrorScope> errorScope;
-
-            if (gl->IsANGLE()) {
-                errorScope.reset(new gl::GLContext::LocalErrorScope(*gl));
-            }
-
-            if (indexCount) {
-                AUTO_PROFILER_LABEL("glDrawElements", GRAPHICS);
-                gl->fDrawElements(mode, indexCount, type,
-                                  reinterpret_cast<GLvoid*>(byteOffset));
-            }
-
-            if (errorScope) {
-                HandleDrawElementsErrors(this, funcName, *errorScope);
-            }
-        }
-    }
-
-    Draw_cleanup(funcName);
-}
-
-void
 WebGLContext::DrawElementsInstanced(GLenum mode, GLsizei indexCount, GLenum type,
-                                    WebGLintptr byteOffset, GLsizei instanceCount)
+                                    WebGLintptr byteOffset, GLsizei instanceCount,
+                                    const char* const funcName)
 {
     AUTO_PROFILER_LABEL("WebGLContext::DrawElementsInstanced", GRAPHICS);
-    const char funcName[] = "drawElementsInstanced";
     if (IsContextLost())
         return;
 
     MakeContextCurrent();
 
     bool error = false;
     ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error);
     if (error)
@@ -790,19 +704,25 @@ WebGLContext::DrawElementsInstanced(GLen
             UniquePtr<gl::GLContext::LocalErrorScope> errorScope;
 
             if (gl->IsANGLE()) {
                 errorScope.reset(new gl::GLContext::LocalErrorScope(*gl));
             }
 
             if (indexCount && instanceCount) {
                 AUTO_PROFILER_LABEL("glDrawElementsInstanced", GRAPHICS);
-                gl->fDrawElementsInstanced(mode, indexCount, type,
-                                           reinterpret_cast<GLvoid*>(byteOffset),
-                                           instanceCount);
+                if (HasInstancedDrawing(*this)) {
+                    gl->fDrawElementsInstanced(mode, indexCount, type,
+                                               reinterpret_cast<GLvoid*>(byteOffset),
+                                               instanceCount);
+                } else {
+                    MOZ_ASSERT(instanceCount == 1);
+                    gl->fDrawElements(mode, indexCount, type,
+                                      reinterpret_cast<GLvoid*>(byteOffset));
+                }
             }
 
             if (errorScope) {
                 HandleDrawElementsErrors(this, funcName, *errorScope);
             }
         }
     }
 
--- a/dom/plugins/base/moz.build
+++ b/dom/plugins/base/moz.build
@@ -52,17 +52,19 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     UNIFIED_SOURCES += [
         'nsPluginDirServiceProvider.cpp',
         'nsPluginNativeWindowWin.cpp',
         'nsPluginsDirWin.cpp',
     ]
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     UNIFIED_SOURCES += [
         'nsPluginNativeWindow.cpp',
-        'nsPluginsDirDarwin.cpp',
+    ]
+    SOURCES += [
+        'nsPluginsDirDarwin.cpp', # conflict with mozilla::EventPriority
     ]
 else:
     UNIFIED_SOURCES += [
         'nsPluginNativeWindow.cpp',
         'nsPluginsDirUnix.cpp',
     ]
 
 LOCAL_INCLUDES += [
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -91,17 +91,17 @@
 
 //--------------------------
 // Printing Include
 //---------------------------
 #ifdef NS_PRINTING
 
 #include "nsIWebBrowserPrint.h"
 
-#include "nsPrintEngine.h"
+#include "nsPrintJob.h"
 
 // Print Options
 #include "nsIPrintSettings.h"
 #include "nsIPrintSettingsService.h"
 #include "nsISimpleEnumerator.h"
 
 #include "nsIPluginDocument.h"
 
@@ -215,17 +215,17 @@ class nsDocumentViewer final : public ns
 
 #ifdef NS_PRINTING
                              , public nsIWebBrowserPrint
 #endif
 
 {
   friend class nsDocViewerSelectionListener;
   friend class nsPagePrintTimer;
-  friend class nsPrintEngine;
+  friend class nsPrintJob;
 
 public:
   nsDocumentViewer();
 
   // nsISupports interface...
   NS_DECL_ISUPPORTS
 
   // nsIContentViewer interface...
@@ -375,17 +375,17 @@ protected:
   unsigned                         mPrintPreviewZoomed : 1;
 
   // These data members support delayed printing when the document is loading
   unsigned                         mPrintIsPending : 1;
   unsigned                         mPrintDocIsFullyLoaded : 1;
   nsCOMPtr<nsIPrintSettings>       mCachedPrintSettings;
   nsCOMPtr<nsIWebProgressListener> mCachedPrintWebProgressListner;
 
-  RefPtr<nsPrintEngine>          mPrintEngine;
+  RefPtr<nsPrintJob>               mPrintJob;
   float                            mOriginalPrintPreviewScale;
   float                            mPrintPreviewZoom;
   nsAutoPtr<AutoPrintEventDispatcher> mAutoBeforeAndAfterPrint;
 #endif // NS_PRINT_PREVIEW
 
 #endif // NS_PRINTING
 
   /* character set member data */
@@ -478,19 +478,19 @@ void nsDocumentViewer::PrepareToStartLoa
   mDeferredWindowClose = false;
 
 #ifdef NS_PRINTING
   mPrintIsPending        = false;
   mPrintDocIsFullyLoaded = false;
   mClosingWhilePrinting  = false;
 
   // Make sure we have destroyed it and cleared the data member
-  if (mPrintEngine) {
-    mPrintEngine->Destroy();
-    mPrintEngine = nullptr;
+  if (mPrintJob) {
+    mPrintJob->Destroy();
+    mPrintJob = nullptr;
 #ifdef NS_PRINT_PREVIEW
     SetIsPrintPreview(false);
 #endif
   }
 
 #endif // NS_PRINTING
 }
 
@@ -544,19 +544,19 @@ NS_INTERFACE_MAP_END
 
 nsDocumentViewer::~nsDocumentViewer()
 {
   if (mDocument) {
     Close(nullptr);
     mDocument->Destroy();
   }
 
-  if (mPrintEngine) {
-    mPrintEngine->Destroy();
-    mPrintEngine = nullptr;
+  if (mPrintJob) {
+    mPrintJob->Destroy();
+    mPrintJob = nullptr;
   }
 
   MOZ_RELEASE_ASSERT(mDestroyRefCount == 0);
   NS_ASSERTION(!mPresShell && !mPresContext,
                "User did not call nsIContentViewer::Destroy");
   if (mPresShell || mPresContext) {
     // Make sure we don't hand out a reference to the content viewer to
     // the SHEntry!
@@ -1574,26 +1574,26 @@ nsDocumentViewer::Close(nsISHEntry *aSHE
   // to disable scripts during paint suppression.
 
   if (!mDocument)
     return NS_OK;
 
 #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
   // Turn scripting back on
   // after PrintPreview had turned it off
-  if (GetIsPrintPreview() && mPrintEngine) {
-    mPrintEngine->TurnScriptingOn(true);
+  if (GetIsPrintPreview() && mPrintJob) {
+    mPrintJob->TurnScriptingOn(true);
   }
 #endif
 
 #ifdef NS_PRINTING
   // A Close was called while we were printing
   // so don't clear the ScriptGlobalObject
   // or clear the mDocument below
-  if (mPrintEngine && !mClosingWhilePrinting) {
+  if (mPrintJob && !mClosingWhilePrinting) {
     mClosingWhilePrinting = true;
   } else
 #endif
     {
       // out of band cleanup of docshell
       mDocument->SetScriptGlobalObject(nullptr);
 
       if (!mSHEntry && mDocument)
@@ -1656,18 +1656,18 @@ nsDocumentViewer::Destroy()
 #ifdef NS_PRINTING
   // Here is where we check to see if the document was still being prepared
   // for printing when it was asked to be destroy from someone externally
   // This usually happens if the document is unloaded while the user is in the
   // Print Dialog
   //
   // So we flip the bool to remember that the document is going away
   // and we can clean up and abort later after returning from the Print Dialog
-  if (mPrintEngine) {
-    if (mPrintEngine->CheckBeforeDestroy()) {
+  if (mPrintJob) {
+    if (mPrintJob->CheckBeforeDestroy()) {
       return NS_OK;
     }
   }
   // Dispatch the 'afterprint' event now, if pending:
   mAutoBeforeAndAfterPrint = nullptr;
 #endif
 
   // Don't let the document get unloaded while we are printing.
@@ -1786,28 +1786,28 @@ nsDocumentViewer::Destroy()
   }
 
   // All callers are supposed to call destroy to break circular
   // references.  If we do this stuff in the destructor, the
   // destructor might never be called (especially if we're being
   // used from JS.
 
 #ifdef NS_PRINTING
-  if (mPrintEngine) {
-    RefPtr<nsPrintEngine> printEngine = mozilla::Move(mPrintEngine);
+  if (mPrintJob) {
+    RefPtr<nsPrintJob> printJob = mozilla::Move(mPrintJob);
 #ifdef NS_PRINT_PREVIEW
     bool doingPrintPreview;
-    printEngine->GetDoingPrintPreview(&doingPrintPreview);
+    printJob->GetDoingPrintPreview(&doingPrintPreview);
     if (doingPrintPreview) {
-      printEngine->FinishPrintPreview();
+      printJob->FinishPrintPreview();
     }
 #endif
-    printEngine->Destroy();
-    MOZ_ASSERT(!mPrintEngine,
-               "mPrintEngine shouldn't be recreated while destroying it");
+    printJob->Destroy();
+    MOZ_ASSERT(!mPrintJob,
+               "mPrintJob shouldn't be recreated while destroying it");
   }
 #endif
 
   // Avoid leaking the old viewer.
   if (mPreviousViewer) {
     mPreviousViewer->Destroy();
     mPreviousViewer = nullptr;
   }
@@ -2304,17 +2304,17 @@ nsDocumentViewer::SetSticky(bool aSticky
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::RequestWindowClose(bool* aCanClose)
 {
 #ifdef NS_PRINTING
-  if (mPrintIsPending || (mPrintEngine && mPrintEngine->GetIsPrinting())) {
+  if (mPrintIsPending || (mPrintJob && mPrintJob->GetIsPrinting())) {
     *aCanClose = false;
     mDeferredWindowClose = true;
   } else
 #endif
     *aCanClose = true;
 
   return NS_OK;
 }
@@ -3910,18 +3910,18 @@ nsDocumentViewer::Print(nsIPrintSettings
   // if we are printing another URL, then exit
   // the reason we check here is because this method can be called while
   // another is still in here (the printing dialog is a good example).
   // the only time we can print more than one job at a time is the regression tests
   if (GetIsPrinting()) {
     // Let the user know we are not ready to print.
     rv = NS_ERROR_NOT_AVAILABLE;
 
-    if (mPrintEngine) {
-      mPrintEngine->FirePrintingErrorEvent(rv);
+    if (mPrintJob) {
+      mPrintJob->FirePrintingErrorEvent(rv);
     }
 
     return rv;
   }
 
   // Dispatch 'beforeprint' event and ensure 'afterprint' will be dispatched:
   MOZ_ASSERT(!mAutoBeforeAndAfterPrint,
              "We don't want to dispatch nested beforeprint/afterprint");
@@ -3929,44 +3929,44 @@ nsDocumentViewer::Print(nsIPrintSettings
     new AutoPrintEventDispatcher(mDocument));
   NS_ENSURE_STATE(!GetIsPrinting());
   // If we are hosting a full-page plugin, tell it to print
   // first. It shows its own native print UI.
   nsCOMPtr<nsIPluginDocument> pDoc(do_QueryInterface(mDocument));
   if (pDoc)
     return pDoc->Print();
 
-  // Our call to nsPrintEngine::Print() may cause mPrintEngine to be
+  // Our call to nsPrintJob::Print() may cause mPrintJob to be
   // Release()'d in Destroy().  Therefore, we need to grab the instance with
   // a local variable, so that it won't be deleted during its own method.
-  RefPtr<nsPrintEngine> printEngine = mPrintEngine;
-  if (!printEngine) {
+  RefPtr<nsPrintJob> printJob = mPrintJob;
+  if (!printJob) {
     NS_ENSURE_STATE(mDeviceContext);
-    printEngine = new nsPrintEngine();
-
-    rv = printEngine->Initialize(this, mContainer, mDocument,
-                                 float(mDeviceContext->AppUnitsPerCSSInch()) /
-                                 float(mDeviceContext->AppUnitsPerDevPixel()) /
-                                 mPageZoom);
+    printJob = new nsPrintJob();
+
+    rv = printJob->Initialize(this, mContainer, mDocument,
+                              float(mDeviceContext->AppUnitsPerCSSInch()) /
+                              float(mDeviceContext->AppUnitsPerDevPixel()) /
+                              mPageZoom);
     if (NS_FAILED(rv)) {
-      printEngine->Destroy();
+      printJob->Destroy();
       return rv;
     }
-    mPrintEngine = printEngine;
+    mPrintJob = printJob;
   }
-  if (printEngine->HasPrintCallbackCanvas()) {
+  if (printJob->HasPrintCallbackCanvas()) {
     // Postpone the 'afterprint' event until after the mozPrintCallback
     // callbacks have been called:
     mAutoBeforeAndAfterPrint = autoBeforeAndAfterPrint;
   }
   dom::Element* root = mDocument->GetRootElement();
   if (root && root->HasAttr(kNameSpaceID_None, nsGkAtoms::mozdisallowselectionprint)) {
-    printEngine->SetDisallowSelectionPrint(true);
+    printJob->SetDisallowSelectionPrint(true);
   }
-  rv = printEngine->Print(aPrintSettings, aWebProgressListener);
+  rv = printJob->Print(aPrintSettings, aWebProgressListener);
   if (NS_FAILED(rv)) {
     OnDonePrinting();
   }
   return rv;
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::PrintPreview(nsIPrintSettings* aPrintSettings,
@@ -3977,24 +3977,24 @@ nsDocumentViewer::PrintPreview(nsIPrintS
   NS_WARNING_ASSERTION(
     IsInitializedForPrintPreview(),
     "Using docshell.printPreview is the preferred way for print previewing!");
 
   NS_ENSURE_ARG_POINTER(aChildDOMWin);
   nsresult rv = NS_OK;
 
   if (GetIsPrinting()) {
-    nsPrintEngine::CloseProgressDialog(aWebProgressListener);
+    nsPrintJob::CloseProgressDialog(aWebProgressListener);
     return NS_ERROR_FAILURE;
   }
 
   // Printing XUL documents is not supported.
   nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
   if (xulDoc) {
-    nsPrintEngine::CloseProgressDialog(aWebProgressListener);
+    nsPrintJob::CloseProgressDialog(aWebProgressListener);
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIDocShell> docShell(mContainer);
   if (!docShell || !mDeviceContext) {
     PR_PL(("Can't Print Preview without device context and docshell"));
     return NS_ERROR_FAILURE;
   }
@@ -4016,81 +4016,81 @@ nsDocumentViewer::PrintPreview(nsIPrintS
   if (!mAutoBeforeAndAfterPrint) {
     autoBeforeAndAfterPrint = new AutoPrintEventDispatcher(doc);
   }
   NS_ENSURE_STATE(!GetIsPrinting());
   // beforeprint event may have caused ContentViewer to be shutdown.
   NS_ENSURE_STATE(mContainer);
   NS_ENSURE_STATE(mDeviceContext);
 
-  // Our call to nsPrintEngine::PrintPreview() may cause mPrintEngine to be
+  // Our call to nsPrintJob::PrintPreview() may cause mPrintJob to be
   // Release()'d in Destroy().  Therefore, we need to grab the instance with
   // a local variable, so that it won't be deleted during its own method.
-  RefPtr<nsPrintEngine> printEngine = mPrintEngine;
-  if (!printEngine) {
-    printEngine = new nsPrintEngine();
-
-    rv = printEngine->Initialize(this, mContainer, doc,
-                                 float(mDeviceContext->AppUnitsPerCSSInch()) /
-                                 float(mDeviceContext->AppUnitsPerDevPixel()) /
-                                 mPageZoom);
+  RefPtr<nsPrintJob> printJob = mPrintJob;
+  if (!printJob) {
+    printJob = new nsPrintJob();
+
+    rv = printJob->Initialize(this, mContainer, doc,
+                              float(mDeviceContext->AppUnitsPerCSSInch()) /
+                              float(mDeviceContext->AppUnitsPerDevPixel()) /
+                              mPageZoom);
     if (NS_FAILED(rv)) {
-      printEngine->Destroy();
+      printJob->Destroy();
       return rv;
     }
-    mPrintEngine = printEngine;
+    mPrintJob = printJob;
   }
   if (autoBeforeAndAfterPrint &&
-      printEngine->HasPrintCallbackCanvas()) {
+      printJob->HasPrintCallbackCanvas()) {
     // Postpone the 'afterprint' event until after the mozPrintCallback
     // callbacks have been called:
     mAutoBeforeAndAfterPrint = autoBeforeAndAfterPrint;
   }
   dom::Element* root = doc->GetRootElement();
   if (root && root->HasAttr(kNameSpaceID_None, nsGkAtoms::mozdisallowselectionprint)) {
     PR_PL(("PrintPreview: found mozdisallowselectionprint"));
-    printEngine->SetDisallowSelectionPrint(true);
+    printJob->SetDisallowSelectionPrint(true);
   }
-  rv = printEngine->PrintPreview(aPrintSettings, aChildDOMWin,
-                                 aWebProgressListener);
+  rv = printJob->PrintPreview(aPrintSettings, aChildDOMWin,
+                              aWebProgressListener);
   mPrintPreviewZoomed = false;
   if (NS_FAILED(rv)) {
     OnDonePrinting();
   }
   return rv;
 #else
   return NS_ERROR_FAILURE;
 #endif
 }
 
 //----------------------------------------------------------------------
 NS_IMETHODIMP
 nsDocumentViewer::PrintPreviewNavigate(int16_t aType, int32_t aPageNum)
 {
   if (!GetIsPrintPreview() ||
-      mPrintEngine->GetIsCreatingPrintPreview())
+      mPrintJob->GetIsCreatingPrintPreview())
     return NS_ERROR_FAILURE;
 
   nsIScrollableFrame* sf =
-    mPrintEngine->GetPrintPreviewPresShell()->GetRootScrollFrameAsScrollable();
+    mPrintJob->GetPrintPreviewPresShell()->GetRootScrollFrameAsScrollable();
   if (!sf)
     return NS_OK;
 
   // Check to see if we can short circut scrolling to the top
   if (aType == nsIWebBrowserPrint::PRINTPREVIEW_HOME ||
       (aType == nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM && aPageNum == 1)) {
     sf->ScrollTo(nsPoint(0, 0), nsIScrollableFrame::INSTANT);
     return NS_OK;
   }
 
   // Finds the SimplePageSequencer frame
   // in PP mPrtPreview->mPrintObject->mSeqFrame is null
   nsIFrame* seqFrame  = nullptr;
   int32_t   pageCount = 0;
-  if (NS_FAILED(mPrintEngine->GetSeqFrameAndCountPages(seqFrame, pageCount))) {
+  if (NS_FAILED(mPrintJob->GetSeqFrameAndCountPages(seqFrame, pageCount))) {
     return NS_ERROR_FAILURE;
   }
 
   // Figure where we are currently scrolled to
   nsPoint pt = sf->GetScrollPosition();
 
   int32_t    pageNum = 1;
   nsIFrame * fndPageFrame  = nullptr;
@@ -4137,173 +4137,173 @@ nsDocumentViewer::PrintPreviewNavigate(i
   } else { // If we get here we are doing "GoTo"
     if (aPageNum < 0 || aPageNum > pageCount) {
       return NS_OK;
     }
   }
 
   if (fndPageFrame) {
     nscoord newYPosn =
-      nscoord(mPrintEngine->GetPrintPreviewScale() * fndPageFrame->GetPosition().y);
+      nscoord(mPrintJob->GetPrintPreviewScale() * fndPageFrame->GetPosition().y);
     sf->ScrollTo(nsPoint(pt.x, newYPosn), nsIScrollableFrame::INSTANT);
   }
   return NS_OK;
 
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings)
 {
-  return nsPrintEngine::GetGlobalPrintSettings(aGlobalPrintSettings);
+  return nsPrintJob::GetGlobalPrintSettings(aGlobalPrintSettings);
 }
 
 // XXX This always returns false for subdocuments
 NS_IMETHODIMP
 nsDocumentViewer::GetDoingPrint(bool *aDoingPrint)
 {
   NS_ENSURE_ARG_POINTER(aDoingPrint);
 
   *aDoingPrint = false;
-  if (mPrintEngine) {
+  if (mPrintJob) {
     // XXX shouldn't this be GetDoingPrint() ?
-    return mPrintEngine->GetDoingPrintPreview(aDoingPrint);
+    return mPrintJob->GetDoingPrintPreview(aDoingPrint);
   }
   return NS_OK;
 }
 
 // XXX This always returns false for subdocuments
 NS_IMETHODIMP
 nsDocumentViewer::GetDoingPrintPreview(bool *aDoingPrintPreview)
 {
   NS_ENSURE_ARG_POINTER(aDoingPrintPreview);
 
   *aDoingPrintPreview = false;
-  if (mPrintEngine) {
-    return mPrintEngine->GetDoingPrintPreview(aDoingPrintPreview);
+  if (mPrintJob) {
+    return mPrintJob->GetDoingPrintPreview(aDoingPrintPreview);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::GetCurrentPrintSettings(nsIPrintSettings * *aCurrentPrintSettings)
 {
   NS_ENSURE_ARG_POINTER(aCurrentPrintSettings);
 
   *aCurrentPrintSettings = nullptr;
-  NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
-
-  return mPrintEngine->GetCurrentPrintSettings(aCurrentPrintSettings);
+  NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE);
+
+  return mPrintJob->GetCurrentPrintSettings(aCurrentPrintSettings);
 }
 
 
 NS_IMETHODIMP
 nsDocumentViewer::GetCurrentChildDOMWindow(mozIDOMWindowProxy** aCurrentChildDOMWindow)
 {
   NS_ENSURE_ARG_POINTER(aCurrentChildDOMWindow);
   *aCurrentChildDOMWindow = nullptr;
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::Cancel()
 {
-  NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
-  return mPrintEngine->Cancelled();
+  NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE);
+  return mPrintJob->Cancelled();
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::ExitPrintPreview()
 {
   if (GetIsPrinting())
     return NS_ERROR_FAILURE;
-  NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
+  NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE);
 
   if (GetIsPrintPreview()) {
     ReturnToGalleyPresentation();
   }
   return NS_OK;
 }
 
 //----------------------------------------------------------------------------------
 // Enumerate all the documents for their titles
 NS_IMETHODIMP
 nsDocumentViewer::EnumerateDocumentNames(uint32_t* aCount,
                                            char16_t*** aResult)
 {
 #ifdef NS_PRINTING
   NS_ENSURE_ARG(aCount);
   NS_ENSURE_ARG_POINTER(aResult);
-  NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
-
-  return mPrintEngine->EnumerateDocumentNames(aCount, aResult);
+  NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE);
+
+  return mPrintJob->EnumerateDocumentNames(aCount, aResult);
 #else
   return NS_ERROR_FAILURE;
 #endif
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::GetIsFramesetFrameSelected(bool *aIsFramesetFrameSelected)
 {
 #ifdef NS_PRINTING
   *aIsFramesetFrameSelected = false;
-  NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
-
-  return mPrintEngine->GetIsFramesetFrameSelected(aIsFramesetFrameSelected);
+  NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE);
+
+  return mPrintJob->GetIsFramesetFrameSelected(aIsFramesetFrameSelected);
 #else
   return NS_ERROR_FAILURE;
 #endif
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::GetPrintPreviewNumPages(int32_t *aPrintPreviewNumPages)
 {
 #ifdef NS_PRINTING
   NS_ENSURE_ARG_POINTER(aPrintPreviewNumPages);
-  NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
-
-  return mPrintEngine->GetPrintPreviewNumPages(aPrintPreviewNumPages);
+  NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE);
+
+  return mPrintJob->GetPrintPreviewNumPages(aPrintPreviewNumPages);
 #else
   return NS_ERROR_FAILURE;
 #endif
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::GetIsFramesetDocument(bool *aIsFramesetDocument)
 {
 #ifdef NS_PRINTING
   *aIsFramesetDocument = false;
-  NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
-
-  return mPrintEngine->GetIsFramesetDocument(aIsFramesetDocument);
+  NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE);
+
+  return mPrintJob->GetIsFramesetDocument(aIsFramesetDocument);
 #else
   return NS_ERROR_FAILURE;
 #endif
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::GetIsIFrameSelected(bool *aIsIFrameSelected)
 {
 #ifdef NS_PRINTING
   *aIsIFrameSelected = false;
-  NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
-
-  return mPrintEngine->GetIsIFrameSelected(aIsIFrameSelected);
+  NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE);
+
+  return mPrintJob->GetIsIFrameSelected(aIsIFrameSelected);
 #else
   return NS_ERROR_FAILURE;
 #endif
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::GetIsRangeSelection(bool *aIsRangeSelection)
 {
 #ifdef NS_PRINTING
   *aIsRangeSelection = false;
-  NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
-
-  return mPrintEngine->GetIsRangeSelection(aIsRangeSelection);
+  NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE);
+
+  return mPrintJob->GetIsRangeSelection(aIsRangeSelection);
 #else
   return NS_ERROR_FAILURE;
 #endif
 }
 
 //----------------------------------------------------------------------------------
 // Printing/Print Preview Helpers
 //----------------------------------------------------------------------------------
@@ -4389,25 +4389,25 @@ nsDocumentViewer::ShouldAttachToTopLevel
 }
 
 //------------------------------------------------------------
 // XXX this always returns false for subdocuments
 bool
 nsDocumentViewer::GetIsPrinting()
 {
 #ifdef NS_PRINTING
-  if (mPrintEngine) {
-    return mPrintEngine->GetIsPrinting();
+  if (mPrintJob) {
+    return mPrintJob->GetIsPrinting();
   }
 #endif
   return false;
 }
 
 //------------------------------------------------------------
-// Notification from the PrintEngine of the current Printing status
+// Notification from the PrintJob of the current Printing status
 void
 nsDocumentViewer::SetIsPrinting(bool aIsPrinting)
 {
 #ifdef NS_PRINTING
   // Set all the docShells in the docshell tree to be printing.
   // that way if anyone of them tries to "navigate" it can't
   nsCOMPtr<nsIDocShell> docShell(mContainer);
   if (docShell || !aIsPrinting) {
@@ -4419,32 +4419,32 @@ nsDocumentViewer::SetIsPrinting(bool aIs
   if (!aIsPrinting) {
     // Dispatch the 'afterprint' event now, if pending:
     mAutoBeforeAndAfterPrint = nullptr;
   }
 #endif
 }
 
 //------------------------------------------------------------
-// The PrintEngine holds the current value
+// The PrintJob holds the current value
 // this called from inside the DocViewer.
 // XXX it always returns false for subdocuments
 bool
 nsDocumentViewer::GetIsPrintPreview()
 {
 #ifdef NS_PRINTING
-  if (mPrintEngine) {
-    return mPrintEngine->GetIsPrintPreview();
+  if (mPrintJob) {
+    return mPrintJob->GetIsPrintPreview();
   }
 #endif
   return false;
 }
 
 //------------------------------------------------------------
-// Notification from the PrintEngine of the current PP status
+// Notification from the PrintJob of the current PP status
 void
 nsDocumentViewer::SetIsPrintPreview(bool aIsPrintPreview)
 {
 #ifdef NS_PRINTING
   // Set all the docShells in the docshell tree to be printing.
   // that way if anyone of them tries to "navigate" it can't
   nsCOMPtr<nsIDocShell> docShell(mContainer);
   if (docShell || !aIsPrintPreview) {
@@ -4516,59 +4516,59 @@ nsDocumentViewer::ReturnToGalleyPresenta
 #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
   if (!GetIsPrintPreview()) {
     NS_ERROR("Wow, we should never get here!");
     return;
   }
 
   SetIsPrintPreview(false);
 
-  mPrintEngine->TurnScriptingOn(true);
-  mPrintEngine->Destroy();
-  mPrintEngine = nullptr;
+  mPrintJob->TurnScriptingOn(true);
+  mPrintJob->Destroy();
+  mPrintJob = nullptr;
 
   nsCOMPtr<nsIDocShell> docShell(mContainer);
   ResetFocusState(docShell);
 
   SetTextZoom(mTextZoom);
   SetFullZoom(mPageZoom);
   SetOverrideDPPX(mOverrideDPPX);
   SetMinFontSize(mMinFontSize);
   Show();
 
 #endif // NS_PRINTING && NS_PRINT_PREVIEW
 }
 
 //------------------------------------------------------------
 // This called ONLY when printing has completed and the DV
-// is being notified that it should get rid of the PrintEngine.
+// is being notified that it should get rid of the nsPrintJob.
 //
 // BUT, if we are in Print Preview then we want to ignore the
-// notification (we do not get rid of the PrintEngine)
+// notification (we do not get rid of the nsPrintJob)
 //
 // One small caveat:
 //   This IS called from two places in this module for cleaning
 //   up when an error occurred during the start up printing
 //   and print preview
 //
 void
 nsDocumentViewer::OnDonePrinting()
 {
 #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
-  // If Destroy() has been called during calling nsPrintEngine::Print() or
-  // nsPrintEngine::PrintPreview(), mPrintEngine is already nullptr here.
+  // If Destroy() has been called during calling nsPrintJob::Print() or
+  // nsPrintJob::PrintPreview(), mPrintJob is already nullptr here.
   // So, the following clean up does nothing in such case.
   // (Do we need some of this for that case?)
-  if (mPrintEngine) {
-    RefPtr<nsPrintEngine> pe = mPrintEngine;
+  if (mPrintJob) {
+    RefPtr<nsPrintJob> printJob = mPrintJob;
     if (GetIsPrintPreview()) {
-      pe->DestroyPrintingData();
+      printJob->DestroyPrintingData();
     } else {
-      mPrintEngine = nullptr;
-      pe->Destroy();
+      mPrintJob = nullptr;
+      printJob->Destroy();
     }
 
     // We are done printing, now cleanup
     if (mDeferredWindowClose) {
       mDeferredWindowClose = false;
       if (mContainer) {
         if (nsCOMPtr<nsPIDOMWindowOuter> win = do_QueryInterface(mContainer->GetWindow())) {
           win->Close();
--- a/layout/base/nsIDocumentViewerPrint.h
+++ b/layout/base/nsIDocumentViewerPrint.h
@@ -18,17 +18,17 @@ class nsViewManager;
 
 // {c6f255cf-cadd-4382-b57f-cd2a9874169b}
 #define NS_IDOCUMENT_VIEWER_PRINT_IID \
 { 0xc6f255cf, 0xcadd, 0x4382, \
   { 0xb5, 0x7f, 0xcd, 0x2a, 0x98, 0x74, 0x16, 0x9b } }
 
 /**
  * A DocumentViewerPrint is an INTERNAL Interface used for interaction
- * between the DocumentViewer and the PrintEngine
+ * between the DocumentViewer and nsPrintJob.
  */
 class nsIDocumentViewerPrint : public nsISupports
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_VIEWER_PRINT_IID)
 
   virtual void SetIsPrinting(bool aIsPrinting) = 0;
   virtual bool GetIsPrinting() = 0;
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -1680,17 +1680,17 @@ nsDisplayImage::BuildLayer(nsDisplayList
 {
   uint32_t flags = imgIContainer::FLAG_ASYNC_NOTIFY;
   if (aBuilder->ShouldSyncDecodeImages()) {
     flags |= imgIContainer::FLAG_SYNC_DECODE;
   }
 
   RefPtr<ImageContainer> container =
     mImage->GetImageContainer(aManager, flags);
-  if (!container) {
+  if (!container || !container->HasCurrentImage()) {
     return nullptr;
   }
 
   RefPtr<ImageLayer> layer = static_cast<ImageLayer*>
     (aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, this));
   if (!layer) {
     layer = aManager->CreateImageLayer();
     if (!layer)
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -4556,17 +4556,22 @@ nsDisplayImageContainer::GetContainer(La
     return nullptr;
   }
 
   uint32_t flags = imgIContainer::FLAG_ASYNC_NOTIFY;
   if (aBuilder->ShouldSyncDecodeImages()) {
     flags |= imgIContainer::FLAG_SYNC_DECODE;
   }
 
-  return image->GetImageContainer(aManager, flags);
+  RefPtr<ImageContainer> container = image->GetImageContainer(aManager, flags);
+  if (!container || !container->HasCurrentImage()) {
+    return nullptr;
+  }
+
+  return container.forget();
 }
 
 bool
 nsDisplayImageContainer::CanOptimizeToImageLayer(LayerManager* aManager,
                                                  nsDisplayListBuilder* aBuilder)
 {
   uint32_t flags = aBuilder->ShouldSyncDecodeImages()
                  ? imgIContainer::FLAG_SYNC_DECODE
--- a/layout/printing/ipc/RemotePrintJobChild.cpp
+++ b/layout/printing/ipc/RemotePrintJobChild.cpp
@@ -3,17 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "RemotePrintJobChild.h"
 
 #include "mozilla/Unused.h"
 #include "nsPagePrintTimer.h"
-#include "nsPrintEngine.h"
+#include "nsPrintJob.h"
 #include "private/pprio.h"
 
 namespace mozilla {
 namespace layout {
 
 NS_IMPL_ISUPPORTS(RemotePrintJobChild,
                   nsIWebProgressListener)
 
@@ -84,36 +84,36 @@ RemotePrintJobChild::RecvPageProcessed(c
 
   mPagePrintTimer->RemotePrintFinished();
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 RemotePrintJobChild::RecvAbortPrint(const nsresult& aRv)
 {
-  MOZ_ASSERT(mPrintEngine);
+  MOZ_ASSERT(mPrintJob);
 
-  mPrintEngine->CleanupOnFailure(aRv, true);
+  mPrintJob->CleanupOnFailure(aRv, true);
   return IPC_OK();
 }
 
 void
 RemotePrintJobChild::SetPagePrintTimer(nsPagePrintTimer* aPagePrintTimer)
 {
   MOZ_ASSERT(aPagePrintTimer);
 
   mPagePrintTimer = aPagePrintTimer;
 }
 
 void
-RemotePrintJobChild::SetPrintEngine(nsPrintEngine* aPrintEngine)
+RemotePrintJobChild::SetPrintJob(nsPrintJob* aPrintJob)
 {
-  MOZ_ASSERT(aPrintEngine);
+  MOZ_ASSERT(aPrintJob);
 
-  mPrintEngine = aPrintEngine;
+  mPrintJob = aPrintJob;
 }
 
 // nsIWebProgressListener
 
 NS_IMETHODIMP
 RemotePrintJobChild::OnStateChange(nsIWebProgress* aProgress,
                                    nsIRequest* aRequest, uint32_t aStateFlags,
                                    nsresult aStatus)
@@ -173,15 +173,15 @@ RemotePrintJobChild::OnSecurityChange(ns
 RemotePrintJobChild::~RemotePrintJobChild()
 {
 }
 
 void
 RemotePrintJobChild::ActorDestroy(ActorDestroyReason aWhy)
 {
   mPagePrintTimer = nullptr;
-  mPrintEngine = nullptr;
+  mPrintJob = nullptr;
 
   mDestroyed = true;
 }
 
 } // namespace layout
 } // namespace mozilla
--- a/layout/printing/ipc/RemotePrintJobChild.h
+++ b/layout/printing/ipc/RemotePrintJobChild.h
@@ -8,17 +8,17 @@
 #define mozilla_layout_RemotePrintJobChild_h
 
 #include "mozilla/layout/PRemotePrintJobChild.h"
 
 #include "mozilla/RefPtr.h"
 #include "nsIWebProgressListener.h"
 
 class nsPagePrintTimer;
-class nsPrintEngine;
+class nsPrintJob;
 
 namespace mozilla {
 namespace layout {
 
 class RemotePrintJobChild final : public PRemotePrintJobChild
                                 , public nsIWebProgressListener
 {
 public:
@@ -41,28 +41,28 @@ public:
   void ProcessPage();
 
   mozilla::ipc::IPCResult RecvPageProcessed(const FileDescriptor& aFd) final;
 
   mozilla::ipc::IPCResult RecvAbortPrint(const nsresult& aRv) final;
 
   void SetPagePrintTimer(nsPagePrintTimer* aPagePrintTimer);
 
-  void SetPrintEngine(nsPrintEngine* aPrintEngine);
+  void SetPrintJob(nsPrintJob* aPrintJob);
 
   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;
+  RefPtr<nsPrintJob> mPrintJob;
   PRFileDesc* mNextPageFD = nullptr;
 };
 
 } // namespace layout
 } // namespace mozilla
 
 #endif // mozilla_layout_RemotePrintJobChild_h
--- a/layout/printing/moz.build
+++ b/layout/printing/moz.build
@@ -22,17 +22,17 @@ EXPORTS.mozilla.layout.printing += [
 XPIDL_MODULE = 'layout_printing'
 
 UNIFIED_SOURCES += [
     'DrawEventRecorder.cpp',
     'ipc/RemotePrintJobChild.cpp',
     'ipc/RemotePrintJobParent.cpp',
     'nsPagePrintTimer.cpp',
     'nsPrintData.cpp',
-    'nsPrintEngine.cpp',
+    'nsPrintJob.cpp',
     'nsPrintObject.cpp',
     'nsPrintPreviewListener.cpp',
     'PrintTranslator.cpp',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
--- a/layout/printing/nsPagePrintTimer.cpp
+++ b/layout/printing/nsPagePrintTimer.cpp
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsPagePrintTimer.h"
 
 #include "mozilla/Unused.h"
 #include "nsIContentViewer.h"
 #include "nsIServiceManager.h"
-#include "nsPrintEngine.h"
+#include "nsPrintJob.h"
 
 using namespace mozilla;
 
 NS_IMPL_ISUPPORTS_INHERITED(nsPagePrintTimer, mozilla::Runnable, nsITimerCallback)
 
 nsPagePrintTimer::~nsPagePrintTimer()
 {
   // "Destroy" the document viewer; this normally doesn't actually
@@ -74,39 +74,39 @@ nsPagePrintTimer::Run()
   bool initNewTimer = true;
   // Check to see if we are done
   // inRange will be true if a page is actually printed
   bool inRange;
   bool donePrinting;
 
   // donePrinting will be true if it completed successfully or
   // if the printing was cancelled
-  donePrinting = !mPrintEngine || mPrintEngine->PrintPage(mPrintObj, inRange);
+  donePrinting = !mPrintJob || mPrintJob->PrintPage(mPrintObj, inRange);
   if (donePrinting) {
 
     if (mWaitingForRemotePrint ||
         // If we are not waiting for the remote printing, it is the time to
         // end printing task by calling DonePrintingPages.
-        (!mPrintEngine || mPrintEngine->DonePrintingPages(mPrintObj, NS_OK))) {
+        (!mPrintJob || mPrintJob->DonePrintingPages(mPrintObj, NS_OK))) {
       initNewTimer = false;
       mDone = true;
     }
   }
 
   // Note that the Stop() destroys this after the print job finishes
-  // (The PrintEngine stops holding a reference when DonePrintingPages
+  // (The nsPrintJob stops holding a reference when DonePrintingPages
   // returns true.)
   Stop();
   if (initNewTimer) {
     ++mFiringCount;
     nsresult result = StartTimer(inRange);
     if (NS_FAILED(result)) {
       mDone = true;     // had a failure.. we are finished..
-      if (mPrintEngine) {
-        mPrintEngine->SetIsPrinting(false);
+      if (mPrintJob) {
+        mPrintJob->SetIsPrinting(false);
       }
     }
   }
   return NS_OK;
 }
 
 // nsITimerCallback
 NS_IMETHODIMP
@@ -144,18 +144,18 @@ nsPagePrintTimer::Notify(nsITimer *timer
       Fail();
       return NS_OK;
     }
   }
 
   if (mDocViewerPrint) {
     bool donePrePrint = true;
     // Don't start to pre-print if we're waiting on the parent still.
-    if (mPrintEngine && !mWaitingForRemotePrint) {
-      donePrePrint = mPrintEngine->PrePrintPage();
+    if (mPrintJob && !mWaitingForRemotePrint) {
+      donePrePrint = mPrintJob->PrePrintPage();
     }
 
     if (donePrePrint && !mWaitingForRemotePrint) {
       StopWatchDogTimer();
       // Pass nullptr here since name already was set in constructor.
       mDocument->Dispatch(TaskCategory::Other, do_AddRef(this));
     } else {
       // Start the watch dog if we're waiting for preprint to ensure that if any
@@ -180,18 +180,18 @@ nsPagePrintTimer::WaitForRemotePrint()
 void
 nsPagePrintTimer::RemotePrintFinished()
 {
   if (!mWaitingForRemotePrint) {
     return;
   }
 
   // now clean up print or print the next webshell
-  if (mDone && mPrintEngine) {
-    mDone = mPrintEngine->DonePrintingPages(mPrintObj, NS_OK);
+  if (mDone && mPrintJob) {
+    mDone = mPrintJob->DonePrintingPages(mPrintObj, NS_OK);
   }
 
   mWaitingForRemotePrint->SetTarget(
     mDocument->EventTargetFor(mozilla::TaskCategory::Other));
   mozilla::Unused <<
     mWaitingForRemotePrint->InitWithCallback(this, 0, nsITimer::TYPE_ONE_SHOT);
 }
 
@@ -216,12 +216,12 @@ nsPagePrintTimer::Stop()
 
 void
 nsPagePrintTimer::Fail()
 {
   NS_WARNING("nsPagePrintTimer::Fail called");
 
   mDone = true;
   Stop();
-  if (mPrintEngine) {
-    mPrintEngine->CleanupOnFailure(NS_OK, false);
+  if (mPrintJob) {
+    mPrintJob->CleanupOnFailure(NS_OK, false);
   }
 }
--- a/layout/printing/nsPagePrintTimer.h
+++ b/layout/printing/nsPagePrintTimer.h
@@ -9,35 +9,35 @@
 // Timer Includes
 #include "nsITimer.h"
 
 #include "nsIDocumentViewerPrint.h"
 #include "nsPrintObject.h"
 #include "mozilla/Attributes.h"
 #include "nsThreadUtils.h"
 
-class nsPrintEngine;
+class nsPrintJob;
 class nsIDocument;
 
 //---------------------------------------------------
 //-- Page Timer Class
 //---------------------------------------------------
 class nsPagePrintTimer final : public mozilla::Runnable,
                                public nsITimerCallback
 {
 public:
 
   NS_DECL_ISUPPORTS_INHERITED
 
-  nsPagePrintTimer(nsPrintEngine* aPrintEngine,
+  nsPagePrintTimer(nsPrintJob* aPrintJob,
                    nsIDocumentViewerPrint* aDocViewerPrint,
                    nsIDocument* aDocument,
                    uint32_t aDelay)
     : Runnable("nsPagePrintTimer")
-    , mPrintEngine(aPrintEngine)
+    , mPrintJob(aPrintJob)
     , mDocViewerPrint(aDocViewerPrint)
     , mDocument(aDocument)
     , mDelay(aDelay)
     , mFiringCount(0)
     , mPrintObj(nullptr)
     , mWatchDogCount(0)
     , mDone(false)
   {
@@ -53,29 +53,29 @@ public:
 
   void Stop();
 
   void WaitForRemotePrint();
   void RemotePrintFinished();
 
   void Disconnect()
   {
-    mPrintEngine = nullptr;
+    mPrintJob = nullptr;
     mPrintObj = nullptr;
   }
 
 private:
   ~nsPagePrintTimer();
 
   nsresult StartTimer(bool aUseDelay);
   nsresult StartWatchDogTimer();
   void     StopWatchDogTimer();
   void     Fail();
 
-  nsPrintEngine*             mPrintEngine;
+  nsPrintJob*                mPrintJob;
   nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
   nsCOMPtr<nsIDocument>      mDocument;
   nsCOMPtr<nsITimer>         mTimer;
   nsCOMPtr<nsITimer>         mWatchDogTimer;
   nsCOMPtr<nsITimer>         mWaitingForRemotePrint;
   uint32_t                   mDelay;
   uint32_t                   mFiringCount;
   nsPrintObject *            mPrintObj;
rename from layout/printing/nsPrintEngine.cpp
rename to layout/printing/nsPrintJob.cpp
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -1,15 +1,15 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsPrintEngine.h"
+#include "nsPrintJob.h"
 
 #include "nsIStringBundle.h"
 #include "nsReadableUtils.h"
 #include "nsCRT.h"
 
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/dom/CustomEvent.h"
@@ -173,143 +173,148 @@ static void DumpPrintObjectsTreeLayout(n
 #define DUMP_DOC_LIST(_title)
 #define DUMP_DOC_TREE
 #define DUMP_DOC_TREELAYOUT
 #endif
 
 class nsScriptSuppressor
 {
 public:
-  explicit nsScriptSuppressor(nsPrintEngine* aPrintEngine)
-  : mPrintEngine(aPrintEngine), mSuppressed(false) {}
+  explicit nsScriptSuppressor(nsPrintJob* aPrintJob)
+    : mPrintJob(aPrintJob)
+    , mSuppressed(false)
+  {}
 
   ~nsScriptSuppressor() { Unsuppress(); }
 
   void Suppress()
   {
-    if (mPrintEngine) {
+    if (mPrintJob) {
       mSuppressed = true;
-      mPrintEngine->TurnScriptingOn(false);
+      mPrintJob->TurnScriptingOn(false);
     }
   }
 
   void Unsuppress()
   {
-    if (mPrintEngine && mSuppressed) {
-      mPrintEngine->TurnScriptingOn(true);
+    if (mPrintJob && mSuppressed) {
+      mPrintJob->TurnScriptingOn(true);
     }
     mSuppressed = false;
   }
 
-  void Disconnect() { mPrintEngine = nullptr; }
+  void Disconnect() { mPrintJob = nullptr; }
 protected:
-  RefPtr<nsPrintEngine> mPrintEngine;
+  RefPtr<nsPrintJob>      mPrintJob;
   bool                    mSuppressed;
 };
 
-NS_IMPL_ISUPPORTS(nsPrintEngine, nsIWebProgressListener,
+NS_IMPL_ISUPPORTS(nsPrintJob, nsIWebProgressListener,
                   nsISupportsWeakReference, nsIObserver)
 
 //---------------------------------------------------
-//-- nsPrintEngine Class Impl
+//-- nsPrintJob Class Impl
 //---------------------------------------------------
-nsPrintEngine::nsPrintEngine()
+nsPrintJob::nsPrintJob()
   : mIsCreatingPrintPreview(false)
   , mIsDoingPrinting(false)
   , mIsDoingPrintPreview(false)
   , mProgressDialogIsShown(false)
   , mScreenDPI(115.0f)
   , mPagePrintTimer(nullptr)
   , mLoadCounter(0)
   , mDidLoadDataForPrinting(false)
   , mIsDestroying(false)
   , mDisallowSelectionPrint(false)
 {
 }
 
 //-------------------------------------------------------
-nsPrintEngine::~nsPrintEngine()
+nsPrintJob::~nsPrintJob()
 {
   Destroy(); // for insurance
   DisconnectPagePrintTimer();
 }
 
 //-------------------------------------------------------
-void nsPrintEngine::Destroy()
+void
+nsPrintJob::Destroy()
 {
   if (mIsDestroying) {
     return;
   }
   mIsDestroying = true;
 
   mPrt = nullptr;
 
 #ifdef NS_PRINT_PREVIEW
   mPrtPreview = nullptr;
   mOldPrtPreview = nullptr;
 #endif
   mDocViewerPrint = nullptr;
 }
 
 //-------------------------------------------------------
-void nsPrintEngine::DestroyPrintingData()
+void
+nsPrintJob::DestroyPrintingData()
 {
   mPrt = nullptr;
 }
 
 //---------------------------------------------------------------------------------
 //-- Section: Methods needed by the DocViewer
 //---------------------------------------------------------------------------------
 
 //--------------------------------------------------------
-nsresult nsPrintEngine::Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
-                                   nsIDocShell*            aContainer,
-                                   nsIDocument*            aDocument,
-                                   float                   aScreenDPI)
+nsresult
+nsPrintJob::Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
+                       nsIDocShell*            aContainer,
+                       nsIDocument*            aDocument,
+                       float                   aScreenDPI)
 {
   NS_ENSURE_ARG_POINTER(aDocViewerPrint);
   NS_ENSURE_ARG_POINTER(aContainer);
   NS_ENSURE_ARG_POINTER(aDocument);
 
   mDocViewerPrint = aDocViewerPrint;
   mContainer      = do_GetWeakReference(aContainer);
   mDocument       = aDocument;
   mScreenDPI      = aScreenDPI;
 
   return NS_OK;
 }
 
 //-------------------------------------------------------
 bool
-nsPrintEngine::CheckBeforeDestroy()
+nsPrintJob::CheckBeforeDestroy()
 {
   if (mPrt && mPrt->mPreparingForPrint) {
     mPrt->mDocWasToBeDestroyed = true;
     return true;
   }
   return false;
 }
 
 //-------------------------------------------------------
 nsresult
-nsPrintEngine::Cancelled()
+nsPrintJob::Cancelled()
 {
   if (mPrt && mPrt->mPrintSettings) {
     return mPrt->mPrintSettings->SetIsCancelled(true);
   }
   return NS_ERROR_FAILURE;
 }
 
 //-------------------------------------------------------
 // Install our event listeners on the document to prevent
 // some events from being processed while in PrintPreview
 //
 // No return code - if this fails, there isn't much we can do
 void
-nsPrintEngine::InstallPrintPreviewListener()
+nsPrintJob::InstallPrintPreviewListener()
 {
   if (!mPrt->mPPEventListeners) {
     nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mContainer);
     if (!docShell) {
       return;
     }
 
     if (nsPIDOMWindowOuter* win = docShell->GetWindow()) {
@@ -317,19 +322,19 @@ nsPrintEngine::InstallPrintPreviewListen
       mPrt->mPPEventListeners = new nsPrintPreviewListener(target);
       mPrt->mPPEventListeners->AddListeners();
     }
   }
 }
 
 //----------------------------------------------------------------------
 nsresult
-nsPrintEngine::GetSeqFrameAndCountPagesInternal(const UniquePtr<nsPrintObject>& aPO,
-                                                nsIFrame*&    aSeqFrame,
-                                                int32_t&      aCount)
+nsPrintJob::GetSeqFrameAndCountPagesInternal(const UniquePtr<nsPrintObject>& aPO,
+                                             nsIFrame*&    aSeqFrame,
+                                             int32_t&      aCount)
 {
   NS_ENSURE_ARG_POINTER(aPO);
 
   // This is sometimes incorrectly called before the pres shell has been created
   // (bug 1141756). MOZ_DIAGNOSTIC_ASSERT so we'll still see the crash in
   // Nightly/Aurora in case the other patch fixes this.
   if (!aPO->mPresShell) {
     MOZ_DIAGNOSTIC_ASSERT(false,
@@ -346,17 +351,18 @@ nsPrintEngine::GetSeqFrameAndCountPagesI
 
   // count the total number of pages
   aCount = aSeqFrame->PrincipalChildList().GetLength();
 
   return NS_OK;
 }
 
 //-----------------------------------------------------------------
-nsresult nsPrintEngine::GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, int32_t& aCount)
+nsresult
+nsPrintJob::GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, int32_t& aCount)
 {
   MOZ_ASSERT(mPrtPreview);
   // Guarantee that mPrintPreview->mPrintObject won't be deleted during a call
   // of GetSeqFrameAndCountPagesInternal().
   RefPtr<nsPrintData> printDataForPrintPreview = mPrtPreview;
   return GetSeqFrameAndCountPagesInternal(
            printDataForPrintPreview->mPrintObject, aSeqFrame, aCount);
 }
@@ -381,20 +387,20 @@ static void DumpLayoutData(char* aTitleS
                            nsPresContext* aPresContext,
                            nsDeviceContext * aDC, nsIFrame * aRootFrame,
                            nsIDocShell * aDocShell, FILE* aFD);
 #endif
 
 //--------------------------------------------------------------------------------
 
 nsresult
-nsPrintEngine::CommonPrint(bool                    aIsPrintPreview,
-                           nsIPrintSettings*       aPrintSettings,
-                           nsIWebProgressListener* aWebProgressListener,
-                           nsIDOMDocument* aDoc)
+nsPrintJob::CommonPrint(bool                    aIsPrintPreview,
+                        nsIPrintSettings*       aPrintSettings,
+                        nsIWebProgressListener* aWebProgressListener,
+                        nsIDOMDocument* aDoc)
 {
   // Callers must hold a strong reference to |this| to ensure that we stay
   // alive for the duration of this method, because our main owning reference
   // (on nsDocumentViewer) might be cleared during this function (if we cause
   // script to run and it cancels the print operation).
 
   nsresult rv = DoCommonPrint(aIsPrintPreview, aPrintSettings,
                               aWebProgressListener, aDoc);
@@ -412,20 +418,20 @@ nsPrintEngine::CommonPrint(bool         
     }
     mPrt = nullptr;
   }
 
   return rv;
 }
 
 nsresult
-nsPrintEngine::DoCommonPrint(bool                    aIsPrintPreview,
-                             nsIPrintSettings*       aPrintSettings,
-                             nsIWebProgressListener* aWebProgressListener,
-                             nsIDOMDocument*         aDoc)
+nsPrintJob::DoCommonPrint(bool                    aIsPrintPreview,
+                          nsIPrintSettings*       aPrintSettings,
+                          nsIWebProgressListener* aWebProgressListener,
+                          nsIDOMDocument*         aDoc)
 {
   nsresult rv;
 
   if (aIsPrintPreview) {
     // The WebProgressListener can be QI'ed to nsIPrintingPromptService
     // then that means the progress dialog is already being shown.
     nsCOMPtr<nsIPrintingPromptService> pps(do_QueryInterface(aWebProgressListener));
     mProgressDialogIsShown = pps != nullptr;
@@ -678,17 +684,17 @@ nsPrintEngine::DoCommonPrint(bool       
   rv = devspec->Init(nullptr, printData->mPrintSettings, aIsPrintPreview);
   NS_ENSURE_SUCCESS(rv, rv);
 
   printData->mPrintDC = new nsDeviceContext();
   rv = printData->mPrintDC->InitForPrinting(devspec);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (XRE_IsParentProcess() && !printData->mPrintDC->IsSyncPagePrinting()) {
-    RefPtr<nsPrintEngine> self(this);
+    RefPtr<nsPrintJob> self(this);
     printData->mPrintDC->RegisterPageDoneCallback([self](nsresult aResult) { self->PageDone(aResult); });
   }
 
   if (aIsPrintPreview) {
     printData->mPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs);
 
     // override any UI that wants to PrintPreview any selection or page range
     // we want to view every page in PrintPreview each time
@@ -790,33 +796,33 @@ nsPrintEngine::DoCommonPrint(bool       
   // We will enable scripting later after printing has finished.
   scriptSuppressor.Disconnect();
 
   return NS_OK;
 }
 
 //---------------------------------------------------------------------------------
 NS_IMETHODIMP
-nsPrintEngine::Print(nsIPrintSettings*       aPrintSettings,
-                     nsIWebProgressListener* aWebProgressListener)
+nsPrintJob::Print(nsIPrintSettings*       aPrintSettings,
+                  nsIWebProgressListener* aWebProgressListener)
 {
   // If we have a print preview document, use that instead of the original
   // mDocument. That way animated images etc. get printed using the same state
   // as in print preview.
   nsCOMPtr<nsIDOMDocument> doc =
     do_QueryInterface(mPrtPreview && mPrtPreview->mPrintObject ?
                         mPrtPreview->mPrintObject->mDocument : mDocument);
 
   return CommonPrint(false, aPrintSettings, aWebProgressListener, doc);
 }
 
 NS_IMETHODIMP
-nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings,
-                            mozIDOMWindowProxy* aChildDOMWin,
-                            nsIWebProgressListener* aWebProgressListener)
+nsPrintJob::PrintPreview(nsIPrintSettings* aPrintSettings,
+                         mozIDOMWindowProxy* aChildDOMWin,
+                         nsIWebProgressListener* aWebProgressListener)
 {
   // Get the DocShell and see if it is busy
   // (We can't Print Preview this document if it is still busy)
   nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
   NS_ENSURE_STATE(docShell);
 
   uint32_t busyFlags = nsIDocShell::BUSY_FLAGS_NONE;
   if (NS_FAILED(docShell->GetBusyFlags(&busyFlags)) ||
@@ -834,26 +840,26 @@ nsPrintEngine::PrintPreview(nsIPrintSett
   MOZ_ASSERT(domDoc);
 
   // Document is not busy -- go ahead with the Print Preview
   return CommonPrint(true, aPrintSettings, aWebProgressListener, domDoc);
 }
 
 //----------------------------------------------------------------------------------
 NS_IMETHODIMP
-nsPrintEngine::GetIsFramesetDocument(bool *aIsFramesetDocument)
+nsPrintJob::GetIsFramesetDocument(bool* aIsFramesetDocument)
 {
   nsCOMPtr<nsIDocShell> webContainer(do_QueryReferent(mContainer));
   *aIsFramesetDocument = IsParentAFrameSet(webContainer);
   return NS_OK;
 }
 
 //----------------------------------------------------------------------------------
 NS_IMETHODIMP
-nsPrintEngine::GetIsIFrameSelected(bool *aIsIFrameSelected)
+nsPrintJob::GetIsIFrameSelected(bool* aIsIFrameSelected)
 {
   *aIsIFrameSelected = false;
 
   // Get the docshell for this documentviewer
   nsCOMPtr<nsIDocShell> webContainer(do_QueryReferent(mContainer));
   // Get the currently focused window
   nsCOMPtr<nsPIDOMWindowOuter> currentFocusWin = FindFocusedDOMWindow();
   if (currentFocusWin && webContainer) {
@@ -863,37 +869,37 @@ nsPrintEngine::GetIsIFrameSelected(bool 
     bool isParentFrameSet;
     *aIsIFrameSelected = IsThereAnIFrameSelected(webContainer, currentFocusWin, isParentFrameSet);
   }
   return NS_OK;
 }
 
 //----------------------------------------------------------------------------------
 NS_IMETHODIMP
-nsPrintEngine::GetIsRangeSelection(bool *aIsRangeSelection)
+nsPrintJob::GetIsRangeSelection(bool* aIsRangeSelection)
 {
   // Get the currently focused window
   nsCOMPtr<nsPIDOMWindowOuter> currentFocusWin = FindFocusedDOMWindow();
   *aIsRangeSelection = IsThereARangeSelection(currentFocusWin);
   return NS_OK;
 }
 
 //----------------------------------------------------------------------------------
 NS_IMETHODIMP
-nsPrintEngine::GetIsFramesetFrameSelected(bool *aIsFramesetFrameSelected)
+nsPrintJob::GetIsFramesetFrameSelected(bool* aIsFramesetFrameSelected)
 {
   // Get the currently focused window
   nsCOMPtr<nsPIDOMWindowOuter> currentFocusWin = FindFocusedDOMWindow();
   *aIsFramesetFrameSelected = currentFocusWin != nullptr;
   return NS_OK;
 }
 
 //----------------------------------------------------------------------------------
 NS_IMETHODIMP
-nsPrintEngine::GetPrintPreviewNumPages(int32_t *aPrintPreviewNumPages)
+nsPrintJob::GetPrintPreviewNumPages(int32_t* aPrintPreviewNumPages)
 {
   NS_ENSURE_ARG_POINTER(aPrintPreviewNumPages);
 
   nsIFrame* seqFrame  = nullptr;
   *aPrintPreviewNumPages = 0;
 
   // When calling this function, the FinishPrintPreview() function might not
   // been called as there are still some
@@ -908,18 +914,18 @@ nsPrintEngine::GetPrintPreviewNumPages(i
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
 //----------------------------------------------------------------------------------
 // Enumerate all the documents for their titles
 NS_IMETHODIMP
-nsPrintEngine::EnumerateDocumentNames(uint32_t* aCount,
-                                      char16_t*** aResult)
+nsPrintJob::EnumerateDocumentNames(uint32_t* aCount,
+                                   char16_t*** aResult)
 {
   NS_ENSURE_ARG(aCount);
   NS_ENSURE_ARG_POINTER(aResult);
 
   *aCount = 0;
   *aResult = nullptr;
 
   int32_t     numDocs = mPrt->mPrintDocList.Length();
@@ -944,50 +950,50 @@ nsPrintEngine::EnumerateDocumentNames(ui
   *aResult = array;
 
   return NS_OK;
 
 }
 
 //----------------------------------------------------------------------------------
 nsresult
-nsPrintEngine::GetGlobalPrintSettings(nsIPrintSettings **aGlobalPrintSettings)
+nsPrintJob::GetGlobalPrintSettings(nsIPrintSettings** aGlobalPrintSettings)
 {
   NS_ENSURE_ARG_POINTER(aGlobalPrintSettings);
 
   nsresult rv = NS_ERROR_FAILURE;
   nsCOMPtr<nsIPrintSettingsService> printSettingsService =
     do_GetService(sPrintSettingsServiceContractID, &rv);
   if (NS_SUCCEEDED(rv)) {
     rv = printSettingsService->GetGlobalPrintSettings(aGlobalPrintSettings);
   }
   return rv;
 }
 
 //----------------------------------------------------------------------------------
 NS_IMETHODIMP
-nsPrintEngine::GetDoingPrint(bool *aDoingPrint)
+nsPrintJob::GetDoingPrint(bool* aDoingPrint)
 {
   NS_ENSURE_ARG_POINTER(aDoingPrint);
   *aDoingPrint = mIsDoingPrinting;
   return NS_OK;
 }
 
 //----------------------------------------------------------------------------------
 NS_IMETHODIMP
-nsPrintEngine::GetDoingPrintPreview(bool *aDoingPrintPreview)
+nsPrintJob::GetDoingPrintPreview(bool* aDoingPrintPreview)
 {
   NS_ENSURE_ARG_POINTER(aDoingPrintPreview);
   *aDoingPrintPreview = mIsDoingPrintPreview;
   return NS_OK;
 }
 
 //----------------------------------------------------------------------------------
 NS_IMETHODIMP
-nsPrintEngine::GetCurrentPrintSettings(nsIPrintSettings * *aCurrentPrintSettings)
+nsPrintJob::GetCurrentPrintSettings(nsIPrintSettings** aCurrentPrintSettings)
 {
   NS_ENSURE_ARG_POINTER(aCurrentPrintSettings);
 
   if (mPrt) {
     *aCurrentPrintSettings = mPrt->mPrintSettings;
 
   } else if (mPrtPreview) {
     *aCurrentPrintSettings = mPrtPreview->mPrintSettings;
@@ -1003,17 +1009,17 @@ nsPrintEngine::GetCurrentPrintSettings(n
 //-- Section: Pre-Reflow Methods
 //-----------------------------------------------------------------
 
 //---------------------------------------------------------------------
 // This method checks to see if there is at least one printer defined
 // and if so, it sets the first printer in the list as the default name
 // in the PrintSettings which is then used for Printer Preview
 nsresult
-nsPrintEngine::CheckForPrinters(nsIPrintSettings* aPrintSettings)
+nsPrintJob::CheckForPrinters(nsIPrintSettings* aPrintSettings)
 {
 #if defined(XP_MACOSX) || defined(ANDROID)
   // Mac doesn't support retrieving a printer list.
   return NS_OK;
 #else
 #if defined(MOZ_X11)
   // On Linux, default printer name should be requested on the parent side.
   // Unless we are in the parent, we ignore this function
@@ -1041,17 +1047,17 @@ nsPrintEngine::CheckForPrinters(nsIPrint
   }
   return rv;
 #endif
 }
 
 //----------------------------------------------------------------------
 // Set up to use the "pluggable" Print Progress Dialog
 void
-nsPrintEngine::ShowPrintProgress(bool aIsForPrinting, bool& aDoNotify)
+nsPrintJob::ShowPrintProgress(bool aIsForPrinting, bool& aDoNotify)
 {
   // default to not notifying, that if something here goes wrong
   // or we aren't going to show the progress dialog we can straight into
   // reflowing the doc for printing.
   aDoNotify = false;
 
   // Assume we can't do progress and then see if we can
   bool showProgresssDialog = false;
@@ -1118,17 +1124,17 @@ nsPrintEngine::ShowPrintProgress(bool aI
         }
       }
     }
   }
 }
 
 //---------------------------------------------------------------------
 bool
-nsPrintEngine::IsThereARangeSelection(nsPIDOMWindowOuter* aDOMWin)
+nsPrintJob::IsThereARangeSelection(nsPIDOMWindowOuter* aDOMWin)
 {
   if (mDisallowSelectionPrint)
     return false;
 
   nsCOMPtr<nsIPresShell> presShell;
   if (aDOMWin) {
     presShell = aDOMWin->GetDocShell()->GetPresShell();
   }
@@ -1153,17 +1159,17 @@ nsPrintEngine::IsThereARangeSelection(ns
   }
 
   // check to make sure it isn't an insertion selection
   return selection->GetRangeAt(0) && !selection->IsCollapsed();
 }
 
 //---------------------------------------------------------------------
 bool
-nsPrintEngine::IsParentAFrameSet(nsIDocShell * aParent)
+nsPrintJob::IsParentAFrameSet(nsIDocShell* aParent)
 {
   // See if the incoming doc is the root document
   if (!aParent) return false;
 
   // When it is the top level document we need to check
   // to see if it contains a frameset. If it does, then
   // we only want to print the doc's children and not the document itself
   // For anything else we always print all the children and the document
@@ -1188,19 +1194,19 @@ nsPrintEngine::IsParentAFrameSet(nsIDocS
   return isFrameSet;
 }
 
 
 //---------------------------------------------------------------------
 // Recursively build a list of sub documents to be printed
 // that mirrors the document tree
 void
-nsPrintEngine::BuildDocTree(nsIDocShell *      aParentNode,
-                            nsTArray<nsPrintObject*> * aDocList,
-                            const UniquePtr<nsPrintObject>& aPO)
+nsPrintJob::BuildDocTree(nsIDocShell*      aParentNode,
+                         nsTArray<nsPrintObject*>* aDocList,
+                         const UniquePtr<nsPrintObject>& aPO)
 {
   NS_ASSERTION(aParentNode, "Pointer is null!");
   NS_ASSERTION(aDocList, "Pointer is null!");
   NS_ASSERTION(aPO, "Pointer is null!");
 
   int32_t childWebshellCount;
   aParentNode->GetChildCount(&childWebshellCount);
   if (childWebshellCount > 0) {
@@ -1223,19 +1229,19 @@ nsPrintEngine::BuildDocTree(nsIDocShell 
         BuildDocTree(childAsShell, aDocList, aPO->mKids.LastElement());
       }
     }
   }
 }
 
 //---------------------------------------------------------------------
 void
-nsPrintEngine::GetDocumentTitleAndURL(nsIDocument* aDoc,
-                                      nsAString&   aTitle,
-                                      nsAString&   aURLStr)
+nsPrintJob::GetDocumentTitleAndURL(nsIDocument* aDoc,
+                                   nsAString&   aTitle,
+                                   nsAString&   aURLStr)
 {
   NS_ASSERTION(aDoc, "Pointer is null!");
 
   aTitle.Truncate();
   aURLStr.Truncate();
 
   nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(aDoc);
   doc->GetTitle(aTitle);
@@ -1265,18 +1271,18 @@ nsPrintEngine::GetDocumentTitleAndURL(ns
 
 //---------------------------------------------------------------------
 // The walks the PO tree and for each document it walks the content
 // tree looking for any content that are sub-shells
 //
 // It then sets the mContent pointer in the "found" PO object back to the
 // the document that contained it.
 void
-nsPrintEngine::MapContentToWebShells(const UniquePtr<nsPrintObject>& aRootPO,
-                                     const UniquePtr<nsPrintObject>& aPO)
+nsPrintJob::MapContentToWebShells(const UniquePtr<nsPrintObject>& aRootPO,
+                                  const UniquePtr<nsPrintObject>& aPO)
 {
   NS_ASSERTION(aRootPO, "Pointer is null!");
   NS_ASSERTION(aPO, "Pointer is null!");
 
   // Recursively walk the content from the root item
   // XXX Would be faster to enumerate the subdocuments, although right now
   //     nsIDocument doesn't expose quite what would be needed.
   nsCOMPtr<nsIContentViewer> viewer;
@@ -1312,17 +1318,17 @@ nsPrintEngine::MapContentToWebShells(con
 //
 // This method walks the PO tree and checks to see if the PrintObject is
 // an eFrame and has children that are eFrames (meaning it's a Frame containing a FrameSet)
 // If so, then the mFrameType need to be changed to eFrameSet
 //
 // Also note: We only want to call this we are printing "Each Frame Separately"
 //            when printing "As Is" leave it as an eFrame
 void
-nsPrintEngine::CheckForChildFrameSets(const UniquePtr<nsPrintObject>& aPO)
+nsPrintJob::CheckForChildFrameSets(const UniquePtr<nsPrintObject>& aPO)
 {
   NS_ASSERTION(aPO, "Pointer is null!");
 
   // Continue recursively walking the chilren of this PO
   bool hasChildFrames = false;
   for (const UniquePtr<nsPrintObject>& po : aPO->mKids) {
     if (po->mFrameType == eFrame) {
       hasChildFrames = true;
@@ -1346,18 +1352,18 @@ nsPrintEngine::CheckForChildFrameSets(co
 // This is used later to (after reflow) to find the absolute location
 // of the sub-doc on its parent's page frame so it can be
 // printed in the correct location.
 //
 // This method recursvely "walks" the content for a document finding
 // all the Frames and IFrames, then sets the "mFrameType" data member
 // which tells us what type of PO we have
 void
-nsPrintEngine::MapContentForPO(const UniquePtr<nsPrintObject>& aPO,
-                               nsIContent*      aContent)
+nsPrintJob::MapContentForPO(const UniquePtr<nsPrintObject>& aPO,
+                            nsIContent* aContent)
 {
   NS_PRECONDITION(aPO && aContent, "Null argument");
 
   nsIDocument* doc = aContent->GetComposedDoc();
 
   NS_ASSERTION(doc, "Content without a document from a document tree?");
 
   nsIDocument* subDoc = doc->GetSubDocumentFor(aContent);
@@ -1397,19 +1403,19 @@ nsPrintEngine::MapContentForPO(const Uni
        child;
        child = child->GetNextSibling()) {
     MapContentForPO(aPO, child);
   }
 }
 
 //---------------------------------------------------------------------
 bool
-nsPrintEngine::IsThereAnIFrameSelected(nsIDocShell* aDocShell,
-                                       nsPIDOMWindowOuter* aDOMWin,
-                                       bool& aIsParentFrameSet)
+nsPrintJob::IsThereAnIFrameSelected(nsIDocShell* aDocShell,
+                                    nsPIDOMWindowOuter* aDOMWin,
+                                    bool& aIsParentFrameSet)
 {
   aIsParentFrameSet = IsParentAFrameSet(aDocShell);
   bool iFrameIsSelected = false;
   if (mPrt && mPrt->mPrintObject) {
     nsPrintObject* po = FindPrintObjectByDOMWin(mPrt->mPrintObject.get(), aDOMWin);
     iFrameIsSelected = po && po->mFrameType == eIFrame;
   } else {
     // First, check to see if we are a frameset
@@ -1430,17 +1436,17 @@ nsPrintEngine::IsThereAnIFrameSelected(n
 
   return iFrameIsSelected;
 }
 
 //---------------------------------------------------------------------
 // Recursively sets all the PO items to be printed
 // from the given item down into the tree
 void
-nsPrintEngine::SetPrintPO(nsPrintObject* aPO, bool aPrint)
+nsPrintJob::SetPrintPO(nsPrintObject* aPO, bool aPrint)
 {
   NS_ASSERTION(aPO, "Pointer is null!");
 
   // Set whether to print flag
   aPO->mDontPrint = !aPrint;
 
   for (const UniquePtr<nsPrintObject>& kid : aPO->mKids) {
     SetPrintPO(kid.get(), aPrint);
@@ -1448,20 +1454,20 @@ nsPrintEngine::SetPrintPO(nsPrintObject*
 }
 
 //---------------------------------------------------------------------
 // This will first use a Title and/or URL from the PrintSettings
 // if one isn't set then it uses the one from the document
 // then if not title is there we will make sure we send something back
 // depending on the situation.
 void
-nsPrintEngine::GetDisplayTitleAndURL(const UniquePtr<nsPrintObject>& aPO,
-                                     nsAString&       aTitle,
-                                     nsAString&       aURLStr,
-                                     eDocTitleDefault aDefType)
+nsPrintJob::GetDisplayTitleAndURL(const UniquePtr<nsPrintObject>& aPO,
+                                  nsAString& aTitle,
+                                  nsAString& aURLStr,
+                                  eDocTitleDefault aDefType)
 {
   NS_ASSERTION(aPO, "Pointer is null!");
 
   if (!mPrt)
     return;
 
   aTitle.Truncate();
   aURLStr.Truncate();
@@ -1492,17 +1498,18 @@ nsPrintEngine::GetDisplayTitleAndURL(con
           aTitle = mPrt->mBrandName;
         }
       }
     }
   }
 }
 
 //---------------------------------------------------------------------
-nsresult nsPrintEngine::DocumentReadyForPrinting()
+nsresult
+nsPrintJob::DocumentReadyForPrinting()
 {
   if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) {
     // Guarantee that mPrt->mPrintObject won't be deleted during a call of
     // CheckForChildFrameSets().
     RefPtr<nsPrintData> printData = mPrt;
     CheckForChildFrameSets(printData->mPrintObject);
   }
 
@@ -1516,17 +1523,18 @@ nsresult nsPrintEngine::DocumentReadyFor
     DonePrintingPages(nullptr, rv);
   }
   return rv;
 }
 
 /** ---------------------------------------------------
  *  Cleans up when an error occurred
  */
-nsresult nsPrintEngine::CleanupOnFailure(nsresult aResult, bool aIsPrinting)
+nsresult
+nsPrintJob::CleanupOnFailure(nsresult aResult, bool aIsPrinting)
 {
   PR_PL(("****  Failed %s - rv 0x%" PRIX32, aIsPrinting?"Printing":"Print Preview",
          static_cast<uint32_t>(aResult)));
 
   /* cleanup... */
   if (mPagePrintTimer) {
     mPagePrintTimer->Stop();
     DisconnectPagePrintTimer();
@@ -1552,17 +1560,17 @@ nsresult nsPrintEngine::CleanupOnFailure
   FirePrintCompletionEvent();
 
   return aResult;
 
 }
 
 //---------------------------------------------------------------------
 void
-nsPrintEngine::FirePrintingErrorEvent(nsresult aPrintError)
+nsPrintJob::FirePrintingErrorEvent(nsresult aPrintError)
 {
   nsCOMPtr<nsIContentViewer> cv = do_QueryInterface(mDocViewerPrint);
   if (NS_WARN_IF(!cv)) {
     return;
   }
 
   nsCOMPtr<nsIDocument> doc = cv->GetDocument();
   RefPtr<CustomEvent> event =
@@ -1593,17 +1601,17 @@ nsPrintEngine::FirePrintingErrorEvent(ns
   }
 }
 
 //-----------------------------------------------------------------
 //-- Section: Reflow Methods
 //-----------------------------------------------------------------
 
 nsresult
-nsPrintEngine::ReconstructAndReflow(bool doSetPixelScale)
+nsPrintJob::ReconstructAndReflow(bool doSetPixelScale)
 {
   if (NS_WARN_IF(!mPrt)) {
     return NS_ERROR_FAILURE;
   }
 
 #if defined(XP_WIN) && defined(EXTENDED_DEBUG_PRINTING)
   // We need to clear all the output files here
   // because they will be re-created with second reflow of the docs
@@ -1677,17 +1685,17 @@ nsPrintEngine::ReconstructAndReflow(bool
     nsresult rv = UpdateSelectionAndShrinkPrintObject(po, documentIsTopLevel);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 //-------------------------------------------------------
 nsresult
-nsPrintEngine::SetupToPrintContent()
+nsPrintJob::SetupToPrintContent()
 {
   // This method may be called while DoCommonPrint() initializes the instance
   // when its script blocker goes out of scope.  In such case, this cannot do
   // its job as expected because some objects in mPrt have not been initialized
   // yet but they are necessary.
   // Note: it shouldn't be possible for mPrt->mPrintObject to be null; we check
   // it for good measure (after we check its owner) before we start
   // dereferencing it below.
@@ -1886,18 +1894,18 @@ nsPrintEngine::SetupToPrintContent()
 
   return rv;
 }
 
 //-------------------------------------------------------
 // Recursively reflow each sub-doc and then calc
 // all the frame locations of the sub-docs
 nsresult
-nsPrintEngine::ReflowDocList(const UniquePtr<nsPrintObject>& aPO,
-                             bool aSetPixelScale)
+nsPrintJob::ReflowDocList(const UniquePtr<nsPrintObject>& aPO,
+                          bool aSetPixelScale)
 {
   NS_ENSURE_ARG_POINTER(aPO);
 
   // Check to see if the subdocument's element has been hidden by the parent document
   if (aPO->mParent && aPO->mParent->mPresShell) {
     nsIFrame* frame = aPO->mContent ? aPO->mContent->GetPrimaryFrame() : nullptr;
     if (!frame || !frame->StyleVisibility()->IsVisible()) {
       SetPrintPO(aPO.get(), false);
@@ -1916,30 +1924,30 @@ nsPrintEngine::ReflowDocList(const Uniqu
   for (const UniquePtr<nsPrintObject>& kid : aPO->mKids) {
     rv = ReflowDocList(kid, aSetPixelScale);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 void
-nsPrintEngine::FirePrintPreviewUpdateEvent()
+nsPrintJob::FirePrintPreviewUpdateEvent()
 {
   // Dispatch the event only while in PrintPreview. When printing, there is no
   // listener bound to this event and therefore no need to dispatch it.
   if (mIsDoingPrintPreview && !mIsDoingPrinting) {
     nsCOMPtr<nsIContentViewer> cv = do_QueryInterface(mDocViewerPrint);
     (new AsyncEventDispatcher(
        cv->GetDocument(), NS_LITERAL_STRING("printPreviewUpdate"), true, true)
     )->RunDOMEventWhenSafe();
   }
 }
 
 nsresult
-nsPrintEngine::InitPrintDocConstruction(bool aHandleError)
+nsPrintJob::InitPrintDocConstruction(bool aHandleError)
 {
   nsresult rv;
   // Guarantee that mPrt->mPrintObject won't be deleted.  It's owned by mPrt.
   // So, we should grab it with local variable.
   RefPtr<nsPrintData> printData = mPrt;
   rv = ReflowDocList(printData->mPrintObject, DoSetPixelScale());
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -1947,17 +1955,17 @@ nsPrintEngine::InitPrintDocConstruction(
 
   if (mLoadCounter == 0) {
     AfterNetworkPrint(aHandleError);
   }
   return rv;
 }
 
 nsresult
-nsPrintEngine::AfterNetworkPrint(bool aHandleError)
+nsPrintJob::AfterNetworkPrint(bool aHandleError)
 {
   // If Destroy() has already been called, mPtr is nullptr.  Then, the instance
   // needs to do nothing anymore in this method.
   // Note: it shouldn't be possible for mPrt->mPrintObject to be null; we
   // just check it for good measure, as we check its owner.
   // Note: it shouldn't be possible for mPrt->mPrintObject->mDocShell to be
   // null; we just check it for good measure, as we check its owner.
   if (!mPrt ||
@@ -1975,31 +1983,31 @@ nsPrintEngine::AfterNetworkPrint(bool aH
   if (mIsDoingPrinting) {
     rv = DocumentReadyForPrinting();
   } else {
     rv = FinishPrintPreview();
   }
 
   /* cleaup on failure + notify user */
   if (aHandleError && NS_FAILED(rv)) {
-    NS_WARNING("nsPrintEngine::AfterNetworkPrint failed");
+    NS_WARNING("nsPrintJob::AfterNetworkPrint failed");
     CleanupOnFailure(rv, !mIsDoingPrinting);
   }
 
   return rv;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIWebProgressListener
 
 NS_IMETHODIMP
-nsPrintEngine::OnStateChange(nsIWebProgress* aWebProgress,
-                             nsIRequest* aRequest,
-                             uint32_t aStateFlags,
-                             nsresult aStatus)
+nsPrintJob::OnStateChange(nsIWebProgress* aWebProgress,
+                          nsIRequest* aRequest,
+                          uint32_t aStateFlags,
+                          nsresult aStatus)
 {
   nsAutoCString name;
   aRequest->GetName(name);
   if (name.EqualsLiteral("about:document-onload-blocker")) {
     return NS_OK;
   }
   if (aStateFlags & STATE_START) {
     ++mLoadCounter;
@@ -2012,62 +2020,61 @@ nsPrintEngine::OnStateChange(nsIWebProgr
     if (mLoadCounter == 0) {
       AfterNetworkPrint(true);
     }
   }
   return NS_OK;
 }
 
 
-
 NS_IMETHODIMP
-nsPrintEngine::OnProgressChange(nsIWebProgress* aWebProgress,
-                                 nsIRequest* aRequest,
-                                 int32_t aCurSelfProgress,
-                                 int32_t aMaxSelfProgress,
-                                 int32_t aCurTotalProgress,
-                                 int32_t aMaxTotalProgress)
+nsPrintJob::OnProgressChange(nsIWebProgress* aWebProgress,
+                             nsIRequest* aRequest,
+                             int32_t aCurSelfProgress,
+                             int32_t aMaxSelfProgress,
+                             int32_t aCurTotalProgress,
+                             int32_t aMaxTotalProgress)
 {
   NS_NOTREACHED("notification excluded in AddProgressListener(...)");
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintEngine::OnLocationChange(nsIWebProgress* aWebProgress,
-                                nsIRequest* aRequest,
-                                nsIURI* aLocation,
-                                uint32_t aFlags)
+nsPrintJob::OnLocationChange(nsIWebProgress* aWebProgress,
+                             nsIRequest* aRequest,
+                             nsIURI* aLocation,
+                             uint32_t aFlags)
 {
   NS_NOTREACHED("notification excluded in AddProgressListener(...)");
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintEngine::OnStatusChange(nsIWebProgress *aWebProgress,
-                              nsIRequest *aRequest,
-                              nsresult aStatus,
-                              const char16_t *aMessage)
+nsPrintJob::OnStatusChange(nsIWebProgress* aWebProgress,
+                           nsIRequest* aRequest,
+                           nsresult aStatus,
+                           const char16_t* aMessage)
 {
   NS_NOTREACHED("notification excluded in AddProgressListener(...)");
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintEngine::OnSecurityChange(nsIWebProgress *aWebProgress,
-                                  nsIRequest *aRequest,
-                                  uint32_t aState)
+nsPrintJob::OnSecurityChange(nsIWebProgress* aWebProgress,
+                             nsIRequest* aRequest,
+                             uint32_t aState)
 {
   NS_NOTREACHED("notification excluded in AddProgressListener(...)");
   return NS_OK;
 }
 
 //-------------------------------------------------------
 
 void
-nsPrintEngine::UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale)
+nsPrintJob::UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale)
 {
   // Here is where we set the shrinkage value into the DC
   // and this is what actually makes it shrink
   if (aSetPixelScale && aPO->mFrameType != eIFrame) {
     float ratio;
     if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs || mPrt->mPrintFrameType == nsIPrintSettings::kNoFrames) {
       ratio = mPrt->mShrinkRatio - 0.005f; // round down
     } else {
@@ -2077,18 +2084,18 @@ nsPrintEngine::UpdateZoomRatio(nsPrintOb
   } else if (!mPrt->mShrinkToFit) {
     double scaling;
     mPrt->mPrintSettings->GetScaling(&scaling);
     aPO->mZoomRatio = float(scaling);
   }
 }
 
 nsresult
-nsPrintEngine::UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO,
-                                                   bool aDocumentIsTopLevel)
+nsPrintJob::UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO,
+                                                bool aDocumentIsTopLevel)
 {
   nsCOMPtr<nsIPresShell> displayShell = aPO->mDocShell->GetPresShell();
   // Transfer Selection Ranges to the new Print PresShell
   RefPtr<Selection> selection, selectionPS;
   // It's okay if there is no display shell, just skip copying the selection
   if (displayShell) {
     selection = displayShell->GetCurrentSelection(SelectionType::eNormal);
   }
@@ -2128,17 +2135,17 @@ nsPrintEngine::UpdateSelectionAndShrinkP
       float minShrinkRatio = float(limitPercent) / 100;
       aPO->mShrinkRatio = std::max(aPO->mShrinkRatio, minShrinkRatio);
     }
   }
   return NS_OK;
 }
 
 bool
-nsPrintEngine::DoSetPixelScale()
+nsPrintJob::DoSetPixelScale()
 {
   // This is an Optimization
   // If we are in PP then we already know all the shrinkage information
   // so just transfer it to the PrintData and we will skip the extra shrinkage reflow
   //
   // doSetPixelScale tells Reflow whether to set the shrinkage value into the DC
   // The first time we do not want to do this, the second time through we do
   bool doSetPixelScale = false;
@@ -2146,34 +2153,32 @@ nsPrintEngine::DoSetPixelScale()
   if (ppIsShrinkToFit) {
     mPrt->mShrinkRatio = mPrtPreview->mShrinkRatio;
     doSetPixelScale = true;
   }
   return doSetPixelScale;
 }
 
 nsView*
-nsPrintEngine::GetParentViewForRoot()
+nsPrintJob::GetParentViewForRoot()
 {
   if (mIsCreatingPrintPreview) {
     nsCOMPtr<nsIContentViewer> cv = do_QueryInterface(mDocViewerPrint);
     if (cv) {
       return cv->FindContainerView();
     }
   }
   return nullptr;
 }
 
 nsresult
-nsPrintEngine::SetRootView(
-    nsPrintObject* aPO,
-    bool& doReturn,
-    bool& documentIsTopLevel,
-    nsSize& adjSize
-)
+nsPrintJob::SetRootView(nsPrintObject* aPO,
+                        bool& doReturn,
+                        bool& documentIsTopLevel,
+                        nsSize& adjSize)
 {
   bool canCreateScrollbars = true;
 
   nsView* rootView;
   nsView* parentView = nullptr;
 
   doReturn = false;
 
@@ -2231,17 +2236,17 @@ nsPrintEngine::SetRootView(
   // Setup hierarchical relationship in view manager
   aPO->mViewManager->SetRootView(rootView);
 
   return NS_OK;
 }
 
 // Reflow a nsPrintObject
 nsresult
-nsPrintEngine::ReflowPrintObject(const UniquePtr<nsPrintObject>& aPO)
+nsPrintJob::ReflowPrintObject(const UniquePtr<nsPrintObject>& aPO)
 {
   NS_ENSURE_STATE(aPO);
 
   if (!aPO->IsPrintable()) {
     return NS_OK;
   }
 
   NS_ASSERTION(!aPO->mPresContext, "Recreating prescontext");
@@ -2392,17 +2397,17 @@ nsPrintEngine::ReflowPrintObject(const U
 #endif
 
   return NS_OK;
 }
 
 //-------------------------------------------------------
 // Figure out how many documents and how many total pages we are printing
 void
-nsPrintEngine::CalcNumPrintablePages(int32_t& aNumPages)
+nsPrintJob::CalcNumPrintablePages(int32_t& aNumPages)
 {
   aNumPages = 0;
   // Count the number of printable documents
   // and printable pages
   for (uint32_t i=0; i<mPrt->mPrintDocList.Length(); i++) {
     nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i);
     NS_ASSERTION(po, "nsPrintObject can't be null!");
     // Note: The po->mPresContext null-check below is necessary, because it's
@@ -2425,18 +2430,18 @@ nsPrintEngine::CalcNumPrintablePages(int
 
 //-----------------------------------------------------------------
 //-- Section: Printing Methods
 //-----------------------------------------------------------------
 
 //-------------------------------------------------------
 // Called for each DocShell that needs to be printed
 bool
-nsPrintEngine::PrintDocContent(const UniquePtr<nsPrintObject>& aPO,
-                               nsresult& aStatus)
+nsPrintJob::PrintDocContent(const UniquePtr<nsPrintObject>& aPO,
+                            nsresult& aStatus)
 {
   NS_ASSERTION(aPO, "Pointer is null!");
   aStatus = NS_OK;
 
   if (!aPO->mHasBeenPrinted && aPO->IsPrintable()) {
     aStatus = DoPrint(aPO);
     return true;
   }
@@ -2565,17 +2570,17 @@ DeleteUnselectedNodes(nsIDocument* aOrig
   }
 
   selection->DeleteFromDocument();
   return NS_OK;
 }
 
 //-------------------------------------------------------
 nsresult
-nsPrintEngine::DoPrint(const UniquePtr<nsPrintObject>& aPO)
+nsPrintJob::DoPrint(const UniquePtr<nsPrintObject>& aPO)
 {
   PR_PL(("\n"));
   PR_PL(("**************************** %s ****************************\n", gFrameTypesStr[aPO->mFrameType]));
   PR_PL(("****** In DV::DoPrint   PO: %p \n", aPO.get()));
 
   nsIPresShell*   poPresShell   = aPO->mPresShell;
   nsPresContext*  poPresContext = aPO->mPresContext;
 
@@ -2636,18 +2641,18 @@ nsPrintEngine::DoPrint(const UniquePtr<n
     StartPagePrintTimer(aPO);
   }
 
   return NS_OK;
 }
 
 //---------------------------------------------------------------------
 void
-nsPrintEngine::SetDocAndURLIntoProgress(const UniquePtr<nsPrintObject>& aPO,
-                                        nsIPrintProgressParams* aParams)
+nsPrintJob::SetDocAndURLIntoProgress(const UniquePtr<nsPrintObject>& aPO,
+                                     nsIPrintProgressParams* aParams)
 {
   NS_ASSERTION(aPO, "Must have valid nsPrintObject");
   NS_ASSERTION(aParams, "Must have valid nsIPrintProgressParams");
 
   if (!aPO || !aPO->mDocShell || !aParams) {
     return;
   }
   const uint32_t kTitleLength = 64;
@@ -2661,17 +2666,17 @@ nsPrintEngine::SetDocAndURLIntoProgress(
   EllipseLongString(docURLStr, kTitleLength, true);
 
   aParams->SetDocTitle(docTitleStr);
   aParams->SetDocURL(docURLStr);
 }
 
 //---------------------------------------------------------------------
 void
-nsPrintEngine::EllipseLongString(nsAString& aStr, const uint32_t aLen, bool aDoFront)
+nsPrintJob::EllipseLongString(nsAString& aStr, const uint32_t aLen, bool aDoFront)
 {
   // Make sure the URLS don't get too long for the progress dialog
   if (aLen >= 3 && aStr.Length() > aLen) {
     if (aDoFront) {
       nsAutoString newStr;
       newStr.AppendLiteral("...");
       newStr += Substring(aStr, aStr.Length() - (aLen - 3), aLen - 3);
       aStr = newStr;
@@ -2717,31 +2722,31 @@ DocHasPrintCallbackCanvas(nsIDocument* a
 }
 
 /**
  * Checks to see if the document this print engine is associated with has any
  * canvases that have a mozPrintCallback.
  * https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement#Properties
  */
 bool
-nsPrintEngine::HasPrintCallbackCanvas()
+nsPrintJob::HasPrintCallbackCanvas()
 {
   if (!mDocument) {
     return false;
   }
   // First check this mDocument.
   bool result = false;
   DocHasPrintCallbackCanvas(mDocument, static_cast<void*>(&result));
   // Also check the sub documents.
   return result || DocHasPrintCallbackCanvas(mDocument);
 }
 
 //-------------------------------------------------------
 bool
-nsPrintEngine::PrePrintPage()
+nsPrintJob::PrePrintPage()
 {
   NS_ASSERTION(mPageSeqFrame.IsAlive(), "mPageSeqFrame is not alive!");
   NS_ASSERTION(mPrt,           "mPrt is null!");
 
   // Although these should NEVER be nullptr
   // This is added insurance, to make sure we don't crash in optimized builds
   if (!mPrt || !mPageSeqFrame.IsAlive()) {
     return true; // means we are done preparing the page.
@@ -2772,18 +2777,18 @@ nsPrintEngine::PrePrintPage()
       printData->mIsAborted = true;
     }
     done = true;
   }
   return done;
 }
 
 bool
-nsPrintEngine::PrintPage(nsPrintObject*    aPO,
-                         bool&           aInRange)
+nsPrintJob::PrintPage(nsPrintObject* aPO,
+                      bool& aInRange)
 {
   NS_ASSERTION(aPO,            "aPO is null!");
   NS_ASSERTION(mPageSeqFrame.IsAlive(), "mPageSeqFrame is not alive!");
   NS_ASSERTION(mPrt,           "mPrt is null!");
 
   // Although these should NEVER be nullptr
   // This is added insurance, to make sure we don't crash in optimized builds
   if (!mPrt || !aPO || !mPageSeqFrame.IsAlive()) {
@@ -2874,17 +2879,17 @@ nsPrintEngine::PrintPage(nsPrintObject* 
   }
 
   pageSeqFrame->DoPageEnd();
 
   return donePrinting;
 }
 
 void
-nsPrintEngine::PageDone(nsresult aResult)
+nsPrintJob::PageDone(nsresult aResult)
 {
   MOZ_ASSERT(mIsDoingPrinting);
 
   // mPagePrintTimer might be released during RemotePrintFinished, keep a
   // reference here to make sure it lives long enough.
   RefPtr<nsPagePrintTimer> timer = mPagePrintTimer;
   timer->RemotePrintFinished();
 }
@@ -2894,54 +2899,57 @@ nsPrintEngine::PageDone(nsresult aResult
 //-----------------------------------------------------------------
 
 
 //-----------------------------------------------------------------
 //-- Section: Misc Support Methods
 //-----------------------------------------------------------------
 
 //---------------------------------------------------------------------
-void nsPrintEngine::SetIsPrinting(bool aIsPrinting)
+void
+nsPrintJob::SetIsPrinting(bool aIsPrinting)
 {
   mIsDoingPrinting = aIsPrinting;
   // Calling SetIsPrinting while in print preview confuses the document viewer
   // This is safe because we prevent exiting print preview while printing
   if (!mIsDoingPrintPreview && mDocViewerPrint) {
     mDocViewerPrint->SetIsPrinting(aIsPrinting);
   }
   if (mPrt && aIsPrinting) {
     mPrt->mPreparingForPrint = true;
   }
 }
 
 //---------------------------------------------------------------------
-void nsPrintEngine::SetIsPrintPreview(bool aIsPrintPreview)
+void
+nsPrintJob::SetIsPrintPreview(bool aIsPrintPreview)
 {
   mIsDoingPrintPreview = aIsPrintPreview;
 
   if (mDocViewerPrint) {
     mDocViewerPrint->SetIsPrintPreview(aIsPrintPreview);
   }
 }
 
 //---------------------------------------------------------------------
 void
-nsPrintEngine::CleanupDocTitleArray(char16_t**& aArray, int32_t& aCount)
+nsPrintJob::CleanupDocTitleArray(char16_t**& aArray, int32_t& aCount)
 {
   for (int32_t i = aCount - 1; i >= 0; i--) {
     free(aArray[i]);
   }
   free(aArray);
   aArray = nullptr;
   aCount = 0;
 }
 
 //---------------------------------------------------------------------
 // static
-bool nsPrintEngine::HasFramesetChild(nsIContent* aContent)
+bool
+nsPrintJob::HasFramesetChild(nsIContent* aContent)
 {
   if (!aContent) {
     return false;
   }
 
   // do a breadth search across all siblings
   for (nsIContent* child = aContent->GetFirstChild();
        child;
@@ -2955,17 +2963,17 @@ bool nsPrintEngine::HasFramesetChild(nsI
 }
 
 
 
 /** ---------------------------------------------------
  *  Get the Focused Frame for a documentviewer
  */
 already_AddRefed<nsPIDOMWindowOuter>
-nsPrintEngine::FindFocusedDOMWindow()
+nsPrintJob::FindFocusedDOMWindow()
 {
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   NS_ENSURE_TRUE(fm, nullptr);
 
   nsPIDOMWindowOuter* window = mDocument->GetWindow();
   NS_ENSURE_TRUE(window, nullptr);
 
   nsCOMPtr<nsPIDOMWindowOuter> rootWindow = window->GetPrivateRoot();
@@ -2981,17 +2989,17 @@ nsPrintEngine::FindFocusedDOMWindow()
     return focusedWindow.forget();
   }
 
   return nullptr;
 }
 
 //---------------------------------------------------------------------
 bool
-nsPrintEngine::IsWindowsInOurSubTree(nsPIDOMWindowOuter* window)
+nsPrintJob::IsWindowsInOurSubTree(nsPIDOMWindowOuter* window)
 {
   bool found = false;
 
   // now check to make sure it is in "our" tree of docshells
   if (window) {
     nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
 
     if (docShell) {
@@ -3013,17 +3021,17 @@ nsPrintEngine::IsWindowsInOurSubTree(nsP
     }
   } // scriptobj
 
   return found;
 }
 
 //-------------------------------------------------------
 bool
-nsPrintEngine::DonePrintingPages(nsPrintObject* aPO, nsresult aResult)
+nsPrintJob::DonePrintingPages(nsPrintObject* aPO, nsresult aResult)
 {
   //NS_ASSERTION(aPO, "Pointer is null!");
   PR_PL(("****** In DV::DonePrintingPages PO: %p (%s)\n", aPO, aPO?gFrameTypesStr[aPO->mFrameType]:""));
 
   // If there is a pageSeqFrame, make sure there are no more printCanvas active
   // that might call |Notify| on the pagePrintTimer after things are cleaned up
   // and printing was marked as being done.
   if (mPageSeqFrame.IsAlive()) {
@@ -3063,31 +3071,31 @@ nsPrintEngine::DonePrintingPages(nsPrint
 
   return true;
 }
 
 //-------------------------------------------------------
 // Recursively sets the PO items to be printed "As Is"
 // from the given item down into the tree
 void
-nsPrintEngine::SetPrintAsIs(nsPrintObject* aPO, bool aAsIs)
+nsPrintJob::SetPrintAsIs(nsPrintObject* aPO, bool aAsIs)
 {
   NS_ASSERTION(aPO, "Pointer is null!");
 
   aPO->mPrintAsIs = aAsIs;
   for (const UniquePtr<nsPrintObject>& kid : aPO->mKids) {
     SetPrintAsIs(kid.get(), aAsIs);
   }
 }
 
 //-------------------------------------------------------
 // Given a DOMWindow it recursively finds the PO object that matches
 nsPrintObject*
-nsPrintEngine::FindPrintObjectByDOMWin(nsPrintObject* aPO,
-                                       nsPIDOMWindowOuter* aDOMWin)
+nsPrintJob::FindPrintObjectByDOMWin(nsPrintObject* aPO,
+                                    nsPIDOMWindowOuter* aDOMWin)
 {
   NS_ASSERTION(aPO, "Pointer is null!");
 
   // Often the CurFocused DOMWindow is passed in
   // andit is valid for it to be null, so short circut
   if (!aDOMWin) {
     return nullptr;
   }
@@ -3104,17 +3112,17 @@ nsPrintEngine::FindPrintObjectByDOMWin(n
     }
   }
 
   return nullptr;
 }
 
 //-------------------------------------------------------
 nsresult
-nsPrintEngine::EnablePOsForPrinting()
+nsPrintJob::EnablePOsForPrinting()
 {
   // Guarantee that mPrt and the objects it owns won't be deleted.
   RefPtr<nsPrintData> printData = mPrt;
 
   // NOTE: All POs have been "turned off" for printing
   // this is where we decided which POs get printed.
 
   if (!printData->mPrintSettings) {
@@ -3126,17 +3134,17 @@ nsPrintEngine::EnablePOsForPrinting()
 
   int16_t printHowEnable = nsIPrintSettings::kFrameEnableNone;
   printData->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable);
 
   int16_t printRangeType = nsIPrintSettings::kRangeAllPages;
   printData->mPrintSettings->GetPrintRange(&printRangeType);
 
   PR_PL(("\n"));
-  PR_PL(("********* nsPrintEngine::EnablePOsForPrinting *********\n"));
+  PR_PL(("********* nsPrintJob::EnablePOsForPrinting *********\n"));
   PR_PL(("PrintFrameType:     %s \n",
          gPrintFrameTypeStr[printData->mPrintFrameType]));
   PR_PL(("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable]));
   PR_PL(("PrintRange:         %s \n", gPrintRangeStr[printRangeType]));
   PR_PL(("----\n"));
 
   // ***** This is the ultimate override *****
   // if we are printing the selection (either an IFrame or selection range)
@@ -3315,17 +3323,17 @@ nsPrintEngine::EnablePOsForPrinting()
 
   return NS_OK;
 }
 
 //-------------------------------------------------------
 // Return the nsPrintObject with that is XMost (The widest frameset frame) AND
 // contains the XMost (widest) layout frame
 nsPrintObject*
-nsPrintEngine::FindSmallestSTF()
+nsPrintJob::FindSmallestSTF()
 {
   float smallestRatio = 1.0f;
   nsPrintObject* smallestPO = nullptr;
 
   for (uint32_t i=0;i<mPrt->mPrintDocList.Length();i++) {
     nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i);
     NS_ASSERTION(po, "nsPrintObject can't be null!");
     if (po->mFrameType != eFrameSet && po->mFrameType != eIFrame) {
@@ -3339,17 +3347,17 @@ nsPrintEngine::FindSmallestSTF()
 #ifdef EXTENDED_DEBUG_PRINTING
   if (smallestPO) printf("*PO: %p  Type: %d  %10.3f\n", smallestPO, smallestPO->mFrameType, smallestPO->mShrinkRatio);
 #endif
   return smallestPO;
 }
 
 //-------------------------------------------------------
 void
-nsPrintEngine::TurnScriptingOn(bool aDoTurnOn)
+nsPrintJob::TurnScriptingOn(bool aDoTurnOn)
 {
   if (mIsDoingPrinting && aDoTurnOn && mDocViewerPrint &&
       mDocViewerPrint->GetIsPrintPreview()) {
     // We don't want to turn scripting on if print preview is shown still after
     // printing.
     return;
   }
 
@@ -3412,26 +3420,26 @@ nsPrintEngine::TurnScriptingOn(bool aDoT
 
 
 //-----------------------------------------------------------------
 //-- Section: Finishing up or Cleaning up
 //-----------------------------------------------------------------
 
 //-----------------------------------------------------------------
 void
-nsPrintEngine::CloseProgressDialog(nsIWebProgressListener* aWebProgressListener)
+nsPrintJob::CloseProgressDialog(nsIWebProgressListener* aWebProgressListener)
 {
   if (aWebProgressListener) {
     aWebProgressListener->OnStateChange(nullptr, nullptr, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT, NS_OK);
   }
 }
 
 //-----------------------------------------------------------------
 nsresult
-nsPrintEngine::FinishPrintPreview()
+nsPrintJob::FinishPrintPreview()
 {
   nsresult rv = NS_OK;
 
 #ifdef NS_PRINT_PREVIEW
 
   if (!mPrt) {
     /* we're already finished with print preview */
     return rv;
@@ -3485,17 +3493,17 @@ nsPrintEngine::FinishPrintPreview()
 
 //-----------------------------------------------------------------
 //-- Done: Finishing up or Cleaning up
 //-----------------------------------------------------------------
 
 
 /*=============== Timer Related Code ======================*/
 nsresult
-nsPrintEngine::StartPagePrintTimer(const UniquePtr<nsPrintObject>& aPO)
+nsPrintJob::StartPagePrintTimer(const UniquePtr<nsPrintObject>& aPO)
 {
   if (!mPagePrintTimer) {
     // Get the delay time in between the printing of each page
     // this gives the user more time to press cancel
     int32_t printPageDelay = 50;
     mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay);
 
     nsCOMPtr<nsIContentViewer> cv = do_QueryInterface(mDocViewerPrint);
@@ -3509,27 +3517,27 @@ nsPrintEngine::StartPagePrintTimer(const
 
     nsCOMPtr<nsIPrintSession> printSession;
     nsresult rv = mPrt->mPrintSettings->GetPrintSession(getter_AddRefs(printSession));
     if (NS_SUCCEEDED(rv) && printSession) {
       RefPtr<mozilla::layout::RemotePrintJobChild> remotePrintJob;
       printSession->GetRemotePrintJob(getter_AddRefs(remotePrintJob));
       if (NS_SUCCEEDED(rv) && remotePrintJob) {
         remotePrintJob->SetPagePrintTimer(mPagePrintTimer);
-        remotePrintJob->SetPrintEngine(this);
+        remotePrintJob->SetPrintJob(this);
       }
     }
   }
 
   return mPagePrintTimer->Start(aPO.get());
 }
 
 /*=============== nsIObserver Interface ======================*/
 NS_IMETHODIMP
-nsPrintEngine::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *aData)
+nsPrintJob::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
 {
   nsresult rv = NS_ERROR_FAILURE;
 
   rv = InitPrintDocConstruction(true);
   if (!mIsDoingPrinting && mPrtPreview) {
     RefPtr<nsPrintData> printDataOfPrintPreview = mPrtPreview;
     printDataOfPrintPreview->OnEndPrinting();
   }
@@ -3557,30 +3565,30 @@ public:
   }
 
 private:
   nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
 };
 
 //-----------------------------------------------------------
 void
-nsPrintEngine::FirePrintCompletionEvent()
+nsPrintJob::FirePrintCompletionEvent()
 {
   MOZ_ASSERT(NS_IsMainThread());
   nsCOMPtr<nsIRunnable> event = new nsPrintCompletionEvent(mDocViewerPrint);
   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(TaskCategory::Other, event.forget()));
 }
 
 void
-nsPrintEngine::DisconnectPagePrintTimer()
+nsPrintJob::DisconnectPagePrintTimer()
 {
   if (mPagePrintTimer) {
     mPagePrintTimer->Disconnect();
     NS_RELEASE(mPagePrintTimer);
   }
 }
 
 //---------------------------------------------------------------
@@ -3704,17 +3712,17 @@ static void DumpFrames(FILE*            
 static void
 DumpViews(nsIDocShell* aDocShell, FILE* out)
 {
   NS_ASSERTION(aDocShell, "Pointer is null!");
   NS_ASSERTION(out, "Pointer is null!");
 
   if (nullptr != aDocShell) {
     fprintf(out, "docshell=%p \n", aDocShell);
-    nsIPresShell* shell = nsPrintEngine::GetPresShellFor(aDocShell);
+    nsIPresShell* shell = nsPrintJob::GetPresShellFor(aDocShell);
     if (shell) {
       nsViewManager* vm = shell->GetViewManager();
       if (vm) {
         nsView* root = vm->GetRootView();
         if (root) {
           root->List(out);
         }
       }
@@ -3852,19 +3860,19 @@ static void DumpPrintObjectsTree(nsPrint
 
 //-------------------------------------------------------------
 static void GetDocTitleAndURL(const UniquePtr<nsPrintObject>& aPO,
                               nsACString& aDocStr,
                               nsACString& aURLStr)
 {
   nsAutoString docTitleStr;
   nsAutoString docURLStr;
-  nsPrintEngine::GetDisplayTitleAndURL(aPO,
-                                       docTitleStr, docURLStr,
-                                       nsPrintEngine::eDocTitleDefURLDoc);
+  nsPrintJob::GetDisplayTitleAndURL(aPO,
+                                    docTitleStr, docURLStr,
+                                    nsPrintJob::eDocTitleDefURLDoc);
   aDocStr = NS_ConvertUTF16toUTF8(docTitleStr);
   aURLStr = NS_ConvertUTF16toUTF8(docURLStr);
 }
 
 //-------------------------------------------------------------
 static void DumpPrintObjectsTreeLayout(nsPrintObject * aPO,
                                        nsDeviceContext * aDC,
                                        int aLevel, FILE * aFD)
rename from layout/printing/nsPrintEngine.h
rename to layout/printing/nsPrintJob.h
--- a/layout/printing/nsPrintEngine.h
+++ b/layout/printing/nsPrintJob.h
@@ -1,15 +1,15 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef nsPrintEngine_h___
-#define nsPrintEngine_h___
+#ifndef nsPrintJob_h
+#define nsPrintJob_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/UniquePtr.h"
 
 #include "nsCOMPtr.h"
 
 #include "nsPrintObject.h"
 #include "nsPrintData.h"
@@ -27,23 +27,23 @@
 class nsPagePrintTimer;
 class nsIDocShell;
 class nsIDocument;
 class nsIDocumentViewerPrint;
 class nsPrintObject;
 class nsIDocShell;
 class nsIPageSequenceFrame;
 
-//------------------------------------------------------------------------
-// nsPrintEngine Class
-//
-//------------------------------------------------------------------------
-class nsPrintEngine final : public nsIObserver,
-                            public nsIWebProgressListener,
-                            public nsSupportsWeakReference
+/**
+ * A print job may be instantiated either for printing to an actual physical
+ * printer, or for creating a print preview.
+ */
+class nsPrintJob final : public nsIObserver
+                       , public nsIWebProgressListener
+                       , public nsSupportsWeakReference
 {
 public:
   // nsISupports interface...
   NS_DECL_ISUPPORTS
 
   // nsIObserver
   NS_DECL_NSIOBSERVER
 
@@ -69,17 +69,17 @@ public:
 
   // This enum tells indicates what the default should be for the title
   // if the title from the document is null
   enum eDocTitleDefault {
     eDocTitleDefBlank,
     eDocTitleDefURLDoc
   };
 
-  nsPrintEngine();
+  nsPrintJob();
 
   void Destroy();
   void DestroyPrintingData();
 
   nsresult Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
                       nsIDocShell*            aContainer,
                       nsIDocument*            aDocument,
                       float                   aScreenDPI);
@@ -153,19 +153,16 @@ public:
                                bool& aIsParentFrameSet);
 
   static nsPrintObject* FindPrintObjectByDOMWin(nsPrintObject* aParentObject,
                                                 nsPIDOMWindowOuter* aDOMWin);
 
   // get the currently infocus frame for the document viewer
   already_AddRefed<nsPIDOMWindowOuter> FindFocusedDOMWindow();
 
-  //---------------------------------------------------------------------
-  // Static Methods
-  //---------------------------------------------------------------------
   static void GetDocumentTitleAndURL(nsIDocument* aDoc,
                                      nsAString&   aTitle,
                                      nsAString&   aURLStr);
   void GetDisplayTitleAndURL(const mozilla::UniquePtr<nsPrintObject>& aPO,
                              nsAString&       aTitle,
                              nsAString&       aURLStr,
                              eDocTitleDefault aDefType);
 
@@ -201,18 +198,20 @@ public:
     return mIsCreatingPrintPreview;
   }
 
   void SetDisallowSelectionPrint(bool aDisallowSelectionPrint)
   {
     mDisallowSelectionPrint = aDisallowSelectionPrint;
   }
 
-protected:
-  ~nsPrintEngine();
+private:
+  nsPrintJob& operator=(const nsPrintJob& aOther) = delete;
+
+  ~nsPrintJob();
 
   nsresult CommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings,
                        nsIWebProgressListener* aWebProgressListener,
                        nsIDOMDocument* aDoc);
 
   nsresult DoCommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings,
                          nsIWebProgressListener* aWebProgressListener,
                          nsIDOMDocument* aDoc);
@@ -227,59 +226,59 @@ protected:
 
   static void MapContentToWebShells(const mozilla::UniquePtr<nsPrintObject>& aRootPO,
                                     const mozilla::UniquePtr<nsPrintObject>& aPO);
 
   static void SetPrintAsIs(nsPrintObject* aPO, bool aAsIs = true);
 
   void DisconnectPagePrintTimer();
 
-  // Static member variables
+  nsresult AfterNetworkPrint(bool aHandleError);
+
+  nsresult SetRootView(nsPrintObject* aPO,
+                       bool& aDoReturn,
+                       bool& aDocumentIsTopLevel,
+                       nsSize& aAdjSize);
+  nsView* GetParentViewForRoot();
+  bool DoSetPixelScale();
+  void UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale);
+  nsresult ReconstructAndReflow(bool aDoSetPixelScale);
+  nsresult UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO,
+                                               bool aDocumentIsTopLevel);
+  nsresult InitPrintDocConstruction(bool aHandleError);
+  void FirePrintPreviewUpdateEvent();
+
+  void PageDone(nsresult aResult);
+
+
   bool mIsCreatingPrintPreview;
   bool mIsDoingPrinting;
-  bool mIsDoingPrintPreview; // per DocumentViewer
+  bool mIsDoingPrintPreview;
   bool mProgressDialogIsShown;
 
   nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
   nsWeakPtr               mContainer;
   float                   mScreenDPI;
 
   // We are the primary owner of our nsPrintData member vars.  These vars
   // are refcounted so that functions (e.g. nsPrintData methods) can create
   // temporary owning references when they need to fire a callback that
-  // could conceivably destroy this nsPrintEngine owner object and all its
+  // could conceivably destroy this nsPrintJob owner object and all its
   // member-data.
   RefPtr<nsPrintData> mPrt;
 
   nsPagePrintTimer*       mPagePrintTimer;
   WeakFrame               mPageSeqFrame;
 
   // Print Preview
   RefPtr<nsPrintData> mPrtPreview;
   RefPtr<nsPrintData> mOldPrtPreview;
 
   nsCOMPtr<nsIDocument>   mDocument;
 
   int32_t mLoadCounter;
   bool mDidLoadDataForPrinting;
   bool mIsDestroying;
   bool mDisallowSelectionPrint;
-
-  nsresult AfterNetworkPrint(bool aHandleError);
-
-  nsresult SetRootView(nsPrintObject* aPO,
-                       bool& aDoReturn,
-                       bool& aDocumentIsTopLevel,
-                       nsSize& aAdjSize);
-  nsView* GetParentViewForRoot();
-  bool DoSetPixelScale();
-  void UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale);
-  nsresult ReconstructAndReflow(bool aDoSetPixelScale);
-  nsresult UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO,
-                                               bool aDocumentIsTopLevel);
-  nsresult InitPrintDocConstruction(bool aHandleError);
-  void FirePrintPreviewUpdateEvent();
-private:
-  nsPrintEngine& operator=(const nsPrintEngine& aOther) = delete;
-  void PageDone(nsresult aResult);
 };
 
-#endif /* nsPrintEngine_h___ */
+#endif // nsPrintJob_h
+
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -1771,17 +1771,17 @@ pref("network.http.spdy.default-concurre
 pref("network.http.spdy.default-hpack-buffer", 65536); // 64k
 
 // alt-svc allows separation of transport routing from
 // the origin host without using a proxy.
 pref("network.http.altsvc.enabled", true);
 pref("network.http.altsvc.oe", true);
 
 // Turn on 0RTT data for TLS 1.3
-pref("security.tls.enable_0rtt_data", false);
+pref("security.tls.enable_0rtt_data", true);
 
 // the origin extension impacts h2 coalescing
 pref("network.http.originextension", true);
 
 pref("network.http.diagnostics", false);
 
 pref("network.http.pacing.requests.enabled", true);
 pref("network.http.pacing.requests.min-parallelism", 6);
--- a/toolkit/components/extensions/ext-browser-content.js
+++ b/toolkit/components/extensions/ext-browser-content.js
@@ -245,19 +245,35 @@ const BrowserListener = {
       // If we're in a fixed-width area (namely a slide-in subview of the main
       // menu panel), we need to calculate the view height based on the
       // preferred height of the content document's root scrollable element at the
       // current width, rather than the complete preferred dimensions of the
       // content window.
 
       // Compensate for any offsets (margin, padding, ...) between the scroll
       // area of the body and the outer height of the document.
+      // This calculation is hard to get right for all cases, so take the lower
+      // number of the combination of all padding and margins of the document
+      // and body elements, or the difference between their heights.
       let getHeight = elem => elem.getBoundingClientRect(elem).height;
       let bodyPadding = getHeight(doc.documentElement) - getHeight(body);
 
+      if (body !== doc.documentElement) {
+        let bs = content.getComputedStyle(body);
+        let ds = content.getComputedStyle(doc.documentElement);
+
+        let p = (parseFloat(bs.marginTop) +
+                 parseFloat(bs.marginBottom) +
+                 parseFloat(ds.marginTop) +
+                 parseFloat(ds.marginBottom) +
+                 parseFloat(ds.paddingTop) +
+                 parseFloat(ds.paddingBottom));
+        bodyPadding = Math.min(p, bodyPadding);
+      }
+
       let height = Math.ceil(body.scrollHeight + bodyPadding);
 
       result = {height, detail};
     } else {
       let background = doc.defaultView.getComputedStyle(body).backgroundColor;
       if (!isOpaque(background)) {
         // Ignore non-opaque backgrounds.
         background = null;
--- a/toolkit/components/printingui/ipc/PrintProgressDialogChild.cpp
+++ b/toolkit/components/printingui/ipc/PrintProgressDialogChild.cpp
@@ -33,17 +33,17 @@ PrintProgressDialogChild::~PrintProgress
   // the parent to decrement its refcount, as well as prevent it from attempting
   // to contact us further.
   Unused << Send__delete__(this);
 }
 
 mozilla::ipc::IPCResult
 PrintProgressDialogChild::RecvDialogOpened()
 {
-  // nsPrintEngine's observer, which we're reporting to here, doesn't care
+  // nsPrintJob's observer, which we're reporting to here, doesn't care
   // what gets passed as the subject, topic or data, so we'll just send
   // nullptrs.
   mOpenObserver->Observe(nullptr, nullptr, nullptr);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 PrintProgressDialogChild::RecvCancelledCurrentJob()
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -492,17 +492,17 @@ PopupBlocking.init();
 
 XPCOMUtils.defineLazyGetter(this, "console", () => {
   // Set up console.* for frame scripts.
   let Console = Components.utils.import("resource://gre/modules/Console.jsm", {});
   return new Console.ConsoleAPI();
 });
 
 var Printing = {
-  // Bug 1088061: nsPrintEngine's DoCommonPrint currently expects the
+  // Bug 1088061: nsPrintJob's DoCommonPrint currently expects the
   // progress listener passed to it to QI to an nsIPrintingPromptService
   // in order to know that a printing progress dialog has been shown. That's
   // really all the interface is used for, hence the fact that I don't actually
   // implement the interface here. Bug 1088061 has been filed to remove
   // this hackery.
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
                                          Ci.nsIPrintingPromptService]),
 
--- a/widget/cocoa/nsCursorManager.mm
+++ b/widget/cocoa/nsCursorManager.mm
@@ -190,44 +190,47 @@ static const nsCursor sCustomCursor = eC
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
 }
 
 - (nsresult) setCursor: (enum nsCursor) aCursor
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
-  // Some plugins mess with our cursors and set a cursor that even
-  // [NSCursor currentCursor] doesn't know about. In case that happens, just
-  // reset the state.
-  [[NSCursor currentCursor] set];
-
   nsCursor oldType = [mCurrentMacCursor type];
-  if (oldType != aCursor) {
-    if (aCursor == eCursor_none) {
-      [NSCursor hide];
-    } else if (oldType == eCursor_none) {
-      [NSCursor unhide];
-    }
-  }
   [self setMacCursor:[self getCursor:aCursor]];
 
   // if a custom cursor was previously set, release sCursorImgContainer
   if (oldType == sCustomCursor) {
     NS_IF_RELEASE(sCursorImgContainer);
   }
   return NS_OK;
   
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 - (nsresult) setMacCursor: (nsMacCursor*) aMacCursor
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
+  // Some plugins mess with our cursors and set a cursor that even
+  // [NSCursor currentCursor] doesn't know about. In case that happens, just
+  // reset the state.
+  [[NSCursor currentCursor] set];
+
+  nsCursor oldType = [mCurrentMacCursor type];
+  nsCursor newType = [aMacCursor type];
+  if (oldType != newType) {
+    if (newType == eCursor_none) {
+      [NSCursor hide];
+    } else if (oldType == eCursor_none) {
+      [NSCursor unhide];
+    }
+  }
+
   if (mCurrentMacCursor != aMacCursor || ![mCurrentMacCursor isSet]) {
     [aMacCursor retain];
     [mCurrentMacCursor unset];
     [aMacCursor set];
     [mCurrentMacCursor release];
     mCurrentMacCursor = aMacCursor;
   }
 
@@ -239,18 +242,17 @@ static const nsCursor sCustomCursor = eC
 - (nsresult) setCursorWithImage: (imgIContainer*) aCursorImage hotSpotX: (uint32_t) aHotspotX hotSpotY: (uint32_t) aHotspotY scaleFactor: (CGFloat) scaleFactor
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
   // As the user moves the mouse, this gets called repeatedly with the same aCursorImage
   if (sCursorImgContainer == aCursorImage && sCursorScaleFactor == scaleFactor && mCurrentMacCursor) {
     [self setMacCursor:mCurrentMacCursor];
     return NS_OK;
   }
-  
-  [[NSCursor currentCursor] set];
+
   int32_t width = 0, height = 0;
   aCursorImage->GetWidth(&width);
   aCursorImage->GetHeight(&height);
   // prevent DoS attacks
   if (width > 128 || height > 128) {
     return NS_OK;
   }
 
--- a/xpcom/threads/AbstractEventQueue.h
+++ b/xpcom/threads/AbstractEventQueue.h
@@ -14,17 +14,19 @@ class nsIRunnable;
 
 namespace mozilla {
 
 enum class EventPriority
 {
   High,
   Input,
   Normal,
-  Idle
+  Idle,
+
+  Count
 };
 
 // AbstractEventQueue is an abstract base class for all our unsynchronized event
 // queue implementations:
 // - EventQueue: A queue of runnables. Used for non-main threads.
 // - PrioritizedEventQueue: Contains a queue for each priority level.
 //       Has heuristics to decide which queue to pop from. Events are
 //       pushed into the queue corresponding to their priority.
--- a/xpcom/threads/EventQueue.cpp
+++ b/xpcom/threads/EventQueue.cpp
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/EventQueue.h"
 #include "nsIRunnable.h"
 
 using namespace mozilla;
 
-EventQueue::EventQueue()
+EventQueue::EventQueue(EventPriority aPriority)
 {
 }
 
 void
 EventQueue::PutEvent(already_AddRefed<nsIRunnable>&& aEvent,
                      EventPriority aPriority,
                      const MutexAutoLock& aProofOfLock)
 {
--- a/xpcom/threads/EventQueue.h
+++ b/xpcom/threads/EventQueue.h
@@ -13,17 +13,18 @@
 
 class nsIRunnable;
 
 namespace mozilla {
 
 class EventQueue final : public AbstractEventQueue
 {
 public:
-  EventQueue();
+  EventQueue() {}
+  explicit EventQueue(EventPriority aPriority);
 
   void PutEvent(already_AddRefed<nsIRunnable>&& aEvent,
                 EventPriority aPriority,
                 const MutexAutoLock& aProofOfLock) final;
   already_AddRefed<nsIRunnable> GetEvent(EventPriority* aPriority,
                                          const MutexAutoLock& aProofOfLock) final;
 
   bool IsEmpty(const MutexAutoLock& aProofOfLock) final;
--- a/xpcom/threads/LabeledEventQueue.cpp
+++ b/xpcom/threads/LabeledEventQueue.cpp
@@ -8,21 +8,24 @@
 #include "mozilla/dom/TabChild.h"
 #include "mozilla/dom/TabGroup.h"
 #include "mozilla/Scheduler.h"
 #include "mozilla/SchedulerGroup.h"
 #include "nsQueryObject.h"
 
 using namespace mozilla::dom;
 
+using EpochQueueEntry = SchedulerGroup::EpochQueueEntry;
+
 LinkedList<SchedulerGroup>* LabeledEventQueue::sSchedulerGroups;
 size_t LabeledEventQueue::sLabeledEventQueueCount;
 SchedulerGroup* LabeledEventQueue::sCurrentSchedulerGroup;
 
-LabeledEventQueue::LabeledEventQueue()
+LabeledEventQueue::LabeledEventQueue(EventPriority aPriority)
+  : mPriority(aPriority)
 {
   // LabeledEventQueue should only be used by one consumer since it uses a
   // single static sSchedulerGroups field. It's hard to assert this, though, so
   // we assert NS_IsMainThread(), which is a reasonable proxy.
   MOZ_ASSERT(NS_IsMainThread());
 
   if (sLabeledEventQueueCount++ == 0) {
     sSchedulerGroups = new LinkedList<SchedulerGroup>();
@@ -72,16 +75,18 @@ IsReadyToRun(nsIRunnable* aEvent, Schedu
   return labelable->IsReadyToRun();
 }
 
 void
 LabeledEventQueue::PutEvent(already_AddRefed<nsIRunnable>&& aEvent,
                             EventPriority aPriority,
                             const MutexAutoLock& aProofOfLock)
 {
+  MOZ_ASSERT(aPriority == mPriority);
+
   nsCOMPtr<nsIRunnable> event(aEvent);
 
   MOZ_ASSERT(event.get());
 
   SchedulerGroup* group = GetSchedulerGroup(event);
   bool isLabeled = !!group;
 
   // Create a new epoch if necessary.
@@ -95,18 +100,18 @@ LabeledEventQueue::PutEvent(already_AddR
     } else {
       epoch = &lastEpoch;
     }
   }
 
   mNumEvents++;
   epoch->mNumEvents++;
 
-  RunnableEpochQueue* queue = isLabeled ? mLabeled.LookupOrAdd(group) : &mUnlabeled;
-  queue->Push(QueueEntry(event.forget(), epoch->mEpochNumber));
+  RunnableEpochQueue& queue = isLabeled ? group->GetQueue(aPriority) : mUnlabeled;
+  queue.Push(EpochQueueEntry(event.forget(), epoch->mEpochNumber));
 
   if (group && group->EnqueueEvent() == SchedulerGroup::NewlyQueued) {
     // This group didn't have any events before. Add it to the
     // sSchedulerGroups list.
     MOZ_ASSERT(!group->isInList());
     sSchedulerGroups->insertBack(group);
     if (!sCurrentSchedulerGroup) {
       sCurrentSchedulerGroup = group;
@@ -145,23 +150,23 @@ LabeledEventQueue::GetEvent(EventPriorit
                             const MutexAutoLock& aProofOfLock)
 {
   if (mEpochs.IsEmpty()) {
     return nullptr;
   }
 
   Epoch epoch = mEpochs.FirstElement();
   if (!epoch.IsLabeled()) {
-    QueueEntry& first = mUnlabeled.FirstElement();
+    EpochQueueEntry& first = mUnlabeled.FirstElement();
     if (!IsReadyToRun(first.mRunnable, nullptr)) {
       return nullptr;
     }
 
     PopEpoch();
-    QueueEntry entry = mUnlabeled.Pop();
+    EpochQueueEntry entry = mUnlabeled.Pop();
     MOZ_ASSERT(entry.mEpochNumber == epoch.mEpochNumber);
     MOZ_ASSERT(entry.mRunnable.get());
     return entry.mRunnable.forget();
   }
 
   if (!sCurrentSchedulerGroup) {
     return nullptr;
   }
@@ -192,27 +197,25 @@ LabeledEventQueue::GetEvent(EventPriorit
   }
 
   // Iterate over each SchedulerGroup once, starting at sCurrentSchedulerGroup.
   SchedulerGroup* firstGroup = sCurrentSchedulerGroup;
   SchedulerGroup* group = firstGroup;
   do {
     mAvoidActiveTabCount--;
 
-    auto queueEntry = mLabeled.Lookup(group);
-    if (!queueEntry) {
+    RunnableEpochQueue& queue = group->GetQueue(mPriority);
+
+    if (queue.IsEmpty()) {
       // This can happen if |group| is in a different LabeledEventQueue than |this|.
       group = NextSchedulerGroup(group);
       continue;
     }
 
-    RunnableEpochQueue* queue = queueEntry.Data();
-    MOZ_ASSERT(!queue->IsEmpty());
-
-    QueueEntry& first = queue->FirstElement();
+    EpochQueueEntry& first = queue.FirstElement();
     if (first.mEpochNumber == epoch.mEpochNumber &&
         IsReadyToRun(first.mRunnable, group)) {
       sCurrentSchedulerGroup = NextSchedulerGroup(group);
 
       PopEpoch();
 
       if (group->DequeueEvent() == SchedulerGroup::NoLongerQueued) {
         // Now we can take group out of sSchedulerGroups.
@@ -221,20 +224,17 @@ LabeledEventQueue::GetEvent(EventPriorit
           // if |group| was the only element in sSchedulerGroups. In that case
           // set sCurrentSchedulerGroup to null.
           MOZ_ASSERT(group->getNext() == nullptr);
           MOZ_ASSERT(group->getPrevious() == nullptr);
           sCurrentSchedulerGroup = nullptr;
         }
         group->removeFrom(*sSchedulerGroups);
       }
-      QueueEntry entry = queue->Pop();
-      if (queue->IsEmpty()) {
-        queueEntry.Remove();
-      }
+      EpochQueueEntry entry = queue.Pop();
       return entry.mRunnable.forget();
     }
 
     group = NextSchedulerGroup(group);
   } while (group != firstGroup);
 
   return nullptr;
 }
@@ -256,32 +256,34 @@ LabeledEventQueue::HasReadyEvent(const M
 {
   if (mEpochs.IsEmpty()) {
     return false;
   }
 
   Epoch& frontEpoch = mEpochs.FirstElement();
 
   if (!frontEpoch.IsLabeled()) {
-    QueueEntry& entry = mUnlabeled.FirstElement();
+    EpochQueueEntry& entry = mUnlabeled.FirstElement();
     return IsReadyToRun(entry.mRunnable, nullptr);
   }
 
-  // Go through the labeled queues and look for one whose head is from the
-  // current epoch and is allowed to run.
+  // Go through the scheduler groups and look for one that has events
+  // for the priority of this labeled queue that is in the current
+  // epoch and is allowed to run.
   uintptr_t currentEpoch = frontEpoch.mEpochNumber;
-  for (auto iter = mLabeled.Iter(); !iter.Done(); iter.Next()) {
-    SchedulerGroup* key = iter.Key();
-    RunnableEpochQueue* queue = iter.Data();
-    MOZ_ASSERT(!queue->IsEmpty());
+  for (SchedulerGroup* group : *sSchedulerGroups) {
+    RunnableEpochQueue& queue = group->GetQueue(mPriority);
+    if (queue.IsEmpty()) {
+      continue;
+    }
 
-    QueueEntry& entry = queue->FirstElement();
+    EpochQueueEntry& entry = queue.FirstElement();
     if (entry.mEpochNumber != currentEpoch) {
       continue;
     }
 
-    if (IsReadyToRun(entry.mRunnable, key)) {
+    if (IsReadyToRun(entry.mRunnable, group)) {
       return true;
     }
   }
 
   return false;
 }
--- a/xpcom/threads/LabeledEventQueue.h
+++ b/xpcom/threads/LabeledEventQueue.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_LabeledEventQueue_h
 #define mozilla_LabeledEventQueue_h
 
 #include <stdint.h>
 #include "mozilla/AbstractEventQueue.h"
 #include "mozilla/LinkedList.h"
+#include "mozilla/SchedulerGroup.h"
 #include "mozilla/Queue.h"
 #include "nsClassHashtable.h"
 #include "nsHashKeys.h"
 
 namespace mozilla {
 
 class SchedulerGroup;
 
@@ -25,17 +26,17 @@ class SchedulerGroup;
 // event is fetched, we heuristically pick a SchedulerGroup and return an event
 // from its queue. Ideally the heuristic should give precedence to
 // SchedulerGroups corresponding to the foreground tabs. The correctness of this
 // data structure relies on the invariant that events from different
 // SchedulerGroups cannot affect each other.
 class LabeledEventQueue final : public AbstractEventQueue
 {
 public:
-  LabeledEventQueue();
+  explicit LabeledEventQueue(EventPriority aPriority);
   ~LabeledEventQueue();
 
   void PutEvent(already_AddRefed<nsIRunnable>&& aEvent,
                 EventPriority aPriority,
                 const MutexAutoLock& aProofOfLock) final;
   already_AddRefed<nsIRunnable> GetEvent(EventPriority* aPriority,
                                          const MutexAutoLock& aProofOfLock) final;
 
@@ -78,27 +79,16 @@ private:
   // runnable and the epoch number into the appopriate queue.
   //
   // To pop an event, we look at the epoch at the front of the epoch queue. If
   // it is unlabeled, then we pop the first event in the unlabeled queue. If it
   // is labeled, we can pop from any of the SchedulerGroup queues. Then we
   // decrement the number of events in the current epoch. If this number reaches
   // zero, we pop from the epoch queue.
 
-  struct QueueEntry
-  {
-    nsCOMPtr<nsIRunnable> mRunnable;
-    uintptr_t mEpochNumber;
-
-    QueueEntry(already_AddRefed<nsIRunnable> aRunnable, uintptr_t aEpoch)
-      : mRunnable(aRunnable)
-      , mEpochNumber(aEpoch)
-    {}
-  };
-
   struct Epoch
   {
     static Epoch First(bool aIsLabeled)
     {
       // Odd numbers are labeled, even are unlabeled.
       uintptr_t number = aIsLabeled ? 1 : 0;
       return Epoch(number, aIsLabeled);
     }
@@ -126,36 +116,35 @@ private:
       MOZ_ASSERT(aIsLabeled == !IsLabeled());
       return Epoch(mEpochNumber + 1, aIsLabeled);
     }
   };
 
   void PopEpoch();
   static SchedulerGroup* NextSchedulerGroup(SchedulerGroup* aGroup);
 
-  using RunnableEpochQueue = Queue<QueueEntry, 32>;
-  using LabeledMap = nsClassHashtable<nsRefPtrHashKey<SchedulerGroup>, RunnableEpochQueue>;
+  using RunnableEpochQueue = SchedulerGroup::RunnableEpochQueue;
   using EpochQueue = Queue<Epoch, 8>;
 
   // List of SchedulerGroups that might have events. This is static, so it
   // covers all LabeledEventQueues. If a SchedulerGroup is in this list, it may
   // not have an event in *this* LabeledEventQueue (although it will have an
   // event in *some* LabeledEventQueue). sCurrentSchedulerGroup cycles through
   // the elements of sSchedulerGroups in order.
   static LinkedList<SchedulerGroup>* sSchedulerGroups;
   static size_t sLabeledEventQueueCount;
   static SchedulerGroup* sCurrentSchedulerGroup;
 
-  LabeledMap mLabeled;
   RunnableEpochQueue mUnlabeled;
   EpochQueue mEpochs;
   size_t mNumEvents = 0;
 
   // Number of SchedulerGroups that must be processed before we prioritize an
   // active tab. This field is designed to guarantee a 1:1 interleaving between
   // foreground and background SchedulerGroups. For details, see its usage in
   // LabeledEventQueue.cpp.
   int64_t mAvoidActiveTabCount = 0;
+  EventPriority mPriority;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_LabeledEventQueue_h
--- a/xpcom/threads/MainThreadQueue.h
+++ b/xpcom/threads/MainThreadQueue.h
@@ -18,20 +18,20 @@ namespace mozilla {
 
 template<typename SynchronizedQueueT, typename InnerQueueT>
 inline already_AddRefed<nsThread>
 CreateMainThread(nsIIdlePeriod* aIdlePeriod, SynchronizedQueueT** aSynchronizedQueue = nullptr)
 {
   using MainThreadQueueT = PrioritizedEventQueue<InnerQueueT>;
 
   auto queue = MakeUnique<MainThreadQueueT>(
-    MakeUnique<InnerQueueT>(),
-    MakeUnique<InnerQueueT>(),
-    MakeUnique<InnerQueueT>(),
-    MakeUnique<InnerQueueT>(),
+    MakeUnique<InnerQueueT>(EventPriority::High),
+    MakeUnique<InnerQueueT>(EventPriority::Input),
+    MakeUnique<InnerQueueT>(EventPriority::Normal),
+    MakeUnique<InnerQueueT>(EventPriority::Idle),
     do_AddRef(aIdlePeriod));
 
   MainThreadQueueT* prioritized = queue.get();
 
   RefPtr<SynchronizedQueueT> synchronizedQueue = new SynchronizedQueueT(Move(queue));
 
   prioritized->SetMutexRef(synchronizedQueue->MutexRef());
 
--- a/xpcom/threads/PrioritizedEventQueue.cpp
+++ b/xpcom/threads/PrioritizedEventQueue.cpp
@@ -60,16 +60,19 @@ PrioritizedEventQueue<InnerQueueT>::PutE
     mInputQueue->PutEvent(event.forget(), priority, aProofOfLock);
     break;
   case EventPriority::Normal:
     mNormalQueue->PutEvent(event.forget(), priority, aProofOfLock);
     break;
   case EventPriority::Idle:
     mIdleQueue->PutEvent(event.forget(), priority, aProofOfLock);
     break;
+  case EventPriority::Count:
+    MOZ_CRASH("EventPriority::Count isn't a valid priority");
+    break;
   }
 }
 
 template<class InnerQueueT>
 TimeStamp
 PrioritizedEventQueue<InnerQueueT>::GetIdleDeadline()
 {
   // If we are shutting down, we won't honor the idle period, and we will
--- a/xpcom/threads/SchedulerGroup.h
+++ b/xpcom/threads/SchedulerGroup.h
@@ -2,18 +2,20 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_SchedulerGroup_h
 #define mozilla_SchedulerGroup_h
 
+#include "mozilla/AbstractEventQueue.h"
 #include "mozilla/AlreadyAddRefed.h"
 #include "mozilla/LinkedList.h"
+#include "mozilla/Queue.h"
 #include "mozilla/TaskCategory.h"
 #include "mozilla/ThreadLocal.h"
 #include "mozilla/TimeStamp.h"
 #include "nsCOMPtr.h"
 #include "nsILabelableRunnable.h"
 #include "nsISupportsImpl.h"
 #include "nsThreadUtils.h"
 
@@ -163,16 +165,35 @@ public:
   bool IsRunning() const { return mIsRunning; }
 
   enum ValidationType {
     StartValidation,
     EndValidation,
   };
   static void SetValidatingAccess(ValidationType aType);
 
+  struct EpochQueueEntry
+  {
+    nsCOMPtr<nsIRunnable> mRunnable;
+    uintptr_t mEpochNumber;
+
+    EpochQueueEntry(already_AddRefed<nsIRunnable> aRunnable, uintptr_t aEpoch)
+      : mRunnable(aRunnable)
+      , mEpochNumber(aEpoch)
+    {
+    }
+  };
+
+  using RunnableEpochQueue = Queue<EpochQueueEntry, 32>;
+
+  RunnableEpochQueue& GetQueue(mozilla::EventPriority aPriority)
+  {
+    return mEventQueues[size_t(aPriority)];
+  }
+
 protected:
   static nsresult InternalUnlabeledDispatch(TaskCategory aCategory,
                                             already_AddRefed<Runnable>&& aRunnable);
 
   // Implementations are guaranteed that this method is called on the main
   // thread.
   virtual AbstractThread* AbstractMainThreadForImpl(TaskCategory aCategory);
 
@@ -198,15 +219,16 @@ protected:
   bool mIsRunning;
 
   // Number of events that are currently enqueued for this SchedulerGroup
   // (across all queues).
   size_t mEventCount = 0;
 
   nsCOMPtr<nsISerialEventTarget> mEventTargets[size_t(TaskCategory::Count)];
   RefPtr<AbstractThread> mAbstractThreads[size_t(TaskCategory::Count)];
+  RunnableEpochQueue mEventQueues[size_t(mozilla::EventPriority::Count)];
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(SchedulerGroup::Runnable, NS_SCHEDULERGROUPRUNNABLE_IID);
 
 } // namespace mozilla
 
 #endif // mozilla_SchedulerGroup_h