Commit cc96c015 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1759494 - Remove some dead code introduced for PDFium. r=dholbert

IsSyncPagePrinting() only had one implementation which unconditionally
returned true.

So, any code that was conditioned on !IsSyncPagePrinting() is necessarily
dead/unreachable.

These are also crashing due to a null deref in mPrintTarget which might
happen if print is aborted.

Differential Revision: https://phabricator.services.mozilla.com/D140988
parent 2246a606
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -479,19 +479,3 @@ DesktopToLayoutDeviceScale nsDeviceContext::GetDesktopToDeviceScale() {

  return DesktopToLayoutDeviceScale(1.0);
}

bool nsDeviceContext::IsSyncPagePrinting() const {
  MOZ_ASSERT(mPrintTarget);
  return mPrintTarget->IsSyncPagePrinting();
}

void nsDeviceContext::RegisterPageDoneCallback(
    PrintTarget::PageDoneCallback&& aCallback) {
  MOZ_ASSERT(mPrintTarget && aCallback && !IsSyncPagePrinting());
  mPrintTarget->RegisterPageDoneCallback(std::move(aCallback));
}
void nsDeviceContext::UnregisterPageDoneCallback() {
  if (mPrintTarget) {
    mPrintTarget->UnregisterPageDoneCallback();
  }
}
+0 −4
Original line number Diff line number Diff line
@@ -233,10 +233,6 @@ class nsDeviceContext final {

  mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale();

  bool IsSyncPagePrinting() const;
  void RegisterPageDoneCallback(PrintTarget::PageDoneCallback&& aCallback);
  void UnregisterPageDoneCallback();

 private:
  // Private destructor, to discourage deletion outside of Release():
  ~nsDeviceContext();
+0 −7
Original line number Diff line number Diff line
@@ -186,11 +186,4 @@ void PrintTarget::Finish() {
  cairo_surface_finish(mCairoSurface);
}

void PrintTarget::RegisterPageDoneCallback(PageDoneCallback&& aCallback) {
  MOZ_ASSERT(aCallback && !IsSyncPagePrinting());
  mPageDoneCallback = std::move(aCallback);
}

void PrintTarget::UnregisterPageDoneCallback() { mPageDoneCallback = nullptr; }

}  // namespace mozilla::gfx
+0 −15
Original line number Diff line number Diff line
@@ -28,8 +28,6 @@ class DrawEventRecorder;
 */
class PrintTarget {
 public:
  typedef std::function<void(nsresult)> PageDoneCallback;

  NS_INLINE_DECL_REFCOUNTING(PrintTarget);

  /// Must be matched 1:1 by an EndPrinting/AbortPrinting call.
@@ -130,17 +128,6 @@ class PrintTarget {
   */
  virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget();

  /**
   * If IsSyncPagePrinting returns true, then a user can assume the content of
   * a page was already printed after EndPage().
   * If IsSyncPagePrinting returns false, then a user should register a
   * callback function using RegisterPageDoneCallback to receive page print
   * done notifications.
   */
  virtual bool IsSyncPagePrinting() const { return true; }
  void RegisterPageDoneCallback(PageDoneCallback&& aCallback);
  void UnregisterPageDoneCallback();

  static void AdjustPrintJobNameForIPP(const nsAString& aJobName,
                                       nsCString& aAdjustedJobName);
  static void AdjustPrintJobNameForIPP(const nsAString& aJobName,
@@ -164,8 +151,6 @@ class PrintTarget {
#ifdef DEBUG
  bool mHasActivePage;
#endif

  PageDoneCallback mPageDoneCallback;
};

}  // namespace gfx
+1 −18
Original line number Diff line number Diff line
@@ -87,11 +87,6 @@ nsresult RemotePrintJobParent::InitializePrintDevice(
    return rv;
  }

  if (!mPrintDeviceContext->IsSyncPagePrinting()) {
    mPrintDeviceContext->RegisterPageDoneCallback(
        [self = RefPtr{this}](nsresult aResult) { self->PageDone(aResult); });
  }

  mIsDoingPrinting = true;

  return NS_OK;
@@ -147,10 +142,8 @@ void RemotePrintJobParent::FinishProcessingPage(

  mCurrentPageStream.Close();

  if (mPrintDeviceContext->IsSyncPagePrinting()) {
  PageDone(rv);
}
}

nsresult RemotePrintJobParent::PrintPage(
    PRFileDescStream& aRecording,
@@ -202,11 +195,6 @@ mozilla::ipc::IPCResult RemotePrintJobParent::RecvFinalizePrint() {

    // Too late to abort the child just log.
    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EndDocument failed");

    // Since RecvFinalizePrint is called after all page printed, there should
    // be no more page-done callbacks after that, in theory. Unregistering
    // page-done callback is not must have, but we still do this for safety.
    mPrintDeviceContext->UnregisterPageDoneCallback();
  }

  mIsDoingPrinting = false;
@@ -219,7 +207,6 @@ mozilla::ipc::IPCResult RemotePrintJobParent::RecvAbortPrint(
    const nsresult& aRv) {
  if (mPrintDeviceContext) {
    Unused << mPrintDeviceContext->AbortDocument();
    mPrintDeviceContext->UnregisterPageDoneCallback();
  }

  mIsDoingPrinting = false;
@@ -281,10 +268,6 @@ RemotePrintJobParent::~RemotePrintJobParent() {
}

void RemotePrintJobParent::ActorDestroy(ActorDestroyReason aWhy) {
  if (mPrintDeviceContext) {
    mPrintDeviceContext->UnregisterPageDoneCallback();
  }

  mIsDoingPrinting = false;

  // If progress dialog is opened, notify closing it.
Loading