Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/printing/ipc/RemotePrintJobChild.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "RemotePrintJobChild.h"
8
9
#include "mozilla/Unused.h"
10
#include "nsPagePrintTimer.h"
11
#include "nsPrintJob.h"
12
#include "private/pprio.h"
13
14
namespace mozilla {
15
namespace layout {
16
17
NS_IMPL_ISUPPORTS(RemotePrintJobChild,
18
                  nsIWebProgressListener)
19
20
RemotePrintJobChild::RemotePrintJobChild()
21
0
{
22
0
}
23
24
nsresult
25
RemotePrintJobChild::InitializePrint(const nsString& aDocumentTitle,
26
                                     const nsString& aPrintToFile,
27
                                     const int32_t& aStartPage,
28
                                     const int32_t& aEndPage)
29
0
{
30
0
  // Print initialization can sometimes display a dialog in the parent, so we
31
0
  // need to spin a nested event loop until initialization completes.
32
0
  Unused << SendInitializePrint(aDocumentTitle, aPrintToFile, aStartPage,
33
0
                                aEndPage);
34
0
  mozilla::SpinEventLoopUntil([&]() { return mPrintInitialized; });
35
0
36
0
  return mInitializationResult;
37
0
}
38
39
mozilla::ipc::IPCResult
40
RemotePrintJobChild::RecvPrintInitializationResult(
41
  const nsresult& aRv,
42
  const mozilla::ipc::FileDescriptor& aFd)
43
0
{
44
0
  mPrintInitialized = true;
45
0
  mInitializationResult = aRv;
46
0
  if (NS_SUCCEEDED(aRv)) {
47
0
    SetNextPageFD(aFd);
48
0
  }
49
0
  return IPC_OK();
50
0
}
51
52
PRFileDesc*
53
RemotePrintJobChild::GetNextPageFD()
54
0
{
55
0
  MOZ_ASSERT(mNextPageFD);
56
0
  PRFileDesc* fd = mNextPageFD;
57
0
  mNextPageFD = nullptr;
58
0
  return fd;
59
0
}
60
61
void
62
RemotePrintJobChild::SetNextPageFD(const mozilla::ipc::FileDescriptor& aFd)
63
0
{
64
0
  auto handle = aFd.ClonePlatformHandle();
65
0
  mNextPageFD = PR_ImportFile(PROsfd(handle.release()));
66
0
}
67
68
void
69
RemotePrintJobChild::ProcessPage()
70
0
{
71
0
  MOZ_ASSERT(mPagePrintTimer);
72
0
73
0
  mPagePrintTimer->WaitForRemotePrint();
74
0
  if (!mDestroyed) {
75
0
    Unused << SendProcessPage();
76
0
  }
77
0
}
78
79
mozilla::ipc::IPCResult
80
RemotePrintJobChild::RecvPageProcessed(const mozilla::ipc::FileDescriptor& aFd)
81
0
{
82
0
  MOZ_ASSERT(mPagePrintTimer);
83
0
  SetNextPageFD(aFd);
84
0
85
0
  mPagePrintTimer->RemotePrintFinished();
86
0
  return IPC_OK();
87
0
}
88
89
mozilla::ipc::IPCResult
90
RemotePrintJobChild::RecvAbortPrint(const nsresult& aRv)
91
0
{
92
0
  MOZ_ASSERT(mPrintJob);
93
0
94
0
  mPrintJob->CleanupOnFailure(aRv, true);
95
0
  return IPC_OK();
96
0
}
97
98
void
99
RemotePrintJobChild::SetPagePrintTimer(nsPagePrintTimer* aPagePrintTimer)
100
0
{
101
0
  MOZ_ASSERT(aPagePrintTimer);
102
0
103
0
  mPagePrintTimer = aPagePrintTimer;
104
0
}
105
106
void
107
RemotePrintJobChild::SetPrintJob(nsPrintJob* aPrintJob)
108
0
{
109
0
  MOZ_ASSERT(aPrintJob);
110
0
111
0
  mPrintJob = aPrintJob;
112
0
}
113
114
// nsIWebProgressListener
115
116
NS_IMETHODIMP
117
RemotePrintJobChild::OnStateChange(nsIWebProgress* aProgress,
118
                                   nsIRequest* aRequest, uint32_t aStateFlags,
119
                                   nsresult aStatus)
120
0
{
121
0
  if (!mDestroyed) {
122
0
    Unused << SendStateChange(aStateFlags, aStatus);
123
0
  }
124
0
125
0
  return NS_OK;
126
0
}
127
128
NS_IMETHODIMP
129
RemotePrintJobChild::OnProgressChange(nsIWebProgress * aProgress,
130
                                      nsIRequest * aRequest,
131
                                      int32_t aCurSelfProgress,
132
                                      int32_t aMaxSelfProgress,
133
                                      int32_t aCurTotalProgress,
134
                                      int32_t aMaxTotalProgress)
135
0
{
136
0
  if (!mDestroyed) {
137
0
    Unused << SendProgressChange(aCurSelfProgress, aMaxSelfProgress,
138
0
                                 aCurTotalProgress, aMaxTotalProgress);
139
0
  }
140
0
141
0
  return NS_OK;
142
0
}
143
144
NS_IMETHODIMP
145
RemotePrintJobChild::OnLocationChange(nsIWebProgress* aProgress,
146
                                      nsIRequest* aRequest, nsIURI* aURI,
147
                                      uint32_t aFlags)
148
0
{
149
0
  return NS_OK;
150
0
}
151
152
NS_IMETHODIMP
153
RemotePrintJobChild::OnStatusChange(nsIWebProgress* aProgress,
154
                                    nsIRequest* aRequest, nsresult aStatus,
155
                                    const char16_t* aMessage)
156
0
{
157
0
  if (NS_SUCCEEDED(mInitializationResult) && !mDestroyed) {
158
0
    Unused << SendStatusChange(aStatus);
159
0
  }
160
0
161
0
  return NS_OK;
162
0
}
163
164
NS_IMETHODIMP
165
RemotePrintJobChild::OnSecurityChange(nsIWebProgress* aProgress,
166
                                      nsIRequest* aRequest, uint32_t aState)
167
0
{
168
0
  return NS_OK;
169
0
}
170
171
// End of nsIWebProgressListener
172
173
RemotePrintJobChild::~RemotePrintJobChild()
174
0
{
175
0
}
176
177
void
178
RemotePrintJobChild::ActorDestroy(ActorDestroyReason aWhy)
179
0
{
180
0
  mPagePrintTimer = nullptr;
181
0
  mPrintJob = nullptr;
182
0
183
0
  mDestroyed = true;
184
0
}
185
186
} // namespace layout
187
} // namespace mozilla