/src/mozilla-central/toolkit/components/printingui/ipc/PrintProgressDialogParent.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | #include "mozilla/Unused.h" |
6 | | #include "nsIPrintProgressParams.h" |
7 | | #include "nsIWebProgressListener.h" |
8 | | #include "PrintProgressDialogParent.h" |
9 | | |
10 | | using mozilla::Unused; |
11 | | |
12 | | namespace mozilla { |
13 | | namespace embedding { |
14 | | |
15 | | NS_IMPL_ISUPPORTS(PrintProgressDialogParent, nsIObserver) |
16 | | |
17 | | PrintProgressDialogParent::PrintProgressDialogParent() : |
18 | | mActive(true) |
19 | 0 | { |
20 | 0 | } |
21 | | |
22 | | PrintProgressDialogParent::~PrintProgressDialogParent() |
23 | 0 | { |
24 | 0 | } |
25 | | |
26 | | void |
27 | | PrintProgressDialogParent::SetWebProgressListener(nsIWebProgressListener* aListener) |
28 | 0 | { |
29 | 0 | mWebProgressListener = aListener; |
30 | 0 | } |
31 | | |
32 | | void |
33 | | PrintProgressDialogParent::SetPrintProgressParams(nsIPrintProgressParams* aParams) |
34 | 0 | { |
35 | 0 | mPrintProgressParams = aParams; |
36 | 0 | } |
37 | | |
38 | | mozilla::ipc::IPCResult |
39 | | PrintProgressDialogParent::RecvStateChange(const long& stateFlags, |
40 | | const nsresult& status) |
41 | 0 | { |
42 | 0 | if (mWebProgressListener) { |
43 | 0 | mWebProgressListener->OnStateChange(nullptr, nullptr, stateFlags, status); |
44 | 0 | } |
45 | 0 | return IPC_OK(); |
46 | 0 | } |
47 | | |
48 | | mozilla::ipc::IPCResult |
49 | | PrintProgressDialogParent::RecvProgressChange(const long& curSelfProgress, |
50 | | const long& maxSelfProgress, |
51 | | const long& curTotalProgress, |
52 | | const long& maxTotalProgress) |
53 | 0 | { |
54 | 0 | if (mWebProgressListener) { |
55 | 0 | mWebProgressListener->OnProgressChange(nullptr, nullptr, curSelfProgress, |
56 | 0 | maxSelfProgress, curTotalProgress, |
57 | 0 | maxTotalProgress); |
58 | 0 | } |
59 | 0 | return IPC_OK(); |
60 | 0 | } |
61 | | |
62 | | mozilla::ipc::IPCResult |
63 | | PrintProgressDialogParent::RecvDocTitleChange(const nsString& newTitle) |
64 | 0 | { |
65 | 0 | if (mPrintProgressParams) { |
66 | 0 | mPrintProgressParams->SetDocTitle(newTitle); |
67 | 0 | } |
68 | 0 | return IPC_OK(); |
69 | 0 | } |
70 | | |
71 | | mozilla::ipc::IPCResult |
72 | | PrintProgressDialogParent::RecvDocURLChange(const nsString& newURL) |
73 | 0 | { |
74 | 0 | if (mPrintProgressParams) { |
75 | 0 | mPrintProgressParams->SetDocURL(newURL); |
76 | 0 | } |
77 | 0 | return IPC_OK(); |
78 | 0 | } |
79 | | |
80 | | void |
81 | | PrintProgressDialogParent::ActorDestroy(ActorDestroyReason aWhy) |
82 | 0 | { |
83 | 0 | // If IPC actor is destroyed, we can't send to child via IPC. |
84 | 0 | mActive = false; |
85 | 0 | } |
86 | | |
87 | | mozilla::ipc::IPCResult |
88 | | PrintProgressDialogParent::Recv__delete__() |
89 | 0 | { |
90 | 0 | // The child has requested that we tear down the connection, so we set a |
91 | 0 | // member to make sure we don't try to contact it after the fact. |
92 | 0 | mActive = false; |
93 | 0 | return IPC_OK(); |
94 | 0 | } |
95 | | |
96 | | // nsIObserver |
97 | | NS_IMETHODIMP |
98 | | PrintProgressDialogParent::Observe(nsISupports *aSubject, const char *aTopic, |
99 | | const char16_t *aData) |
100 | 0 | { |
101 | 0 | if (mActive) { |
102 | 0 | if (aTopic) { |
103 | 0 | if (!strcmp(aTopic, "cancelled")) { |
104 | 0 | Unused << SendCancelledCurrentJob(); |
105 | 0 | if (!mDialogOpenedSent) { |
106 | 0 | // We haven't already called SendDialogOpened, so call it now or it |
107 | 0 | // might never get sent and block the child from new printing requests. |
108 | 0 | // Also set mActive to false because we don't want to send it twice |
109 | 0 | // and our PrintProgressDialogChild will get deleted anyway. |
110 | 0 | Unused << SendDialogOpened(); |
111 | 0 | mActive = false; |
112 | 0 | } |
113 | 0 | } else if (!strcmp(aTopic, "completed")) { |
114 | 0 | // Once printing is complete don't send any messages to the child. |
115 | 0 | mActive = false; |
116 | 0 | } |
117 | 0 | } else { |
118 | 0 | Unused << SendDialogOpened(); |
119 | 0 | mDialogOpenedSent = true; |
120 | 0 | } |
121 | 0 | } else { |
122 | 0 | NS_WARNING("The print progress dialog finished opening, but communications " |
123 | 0 | "with the child have been closed."); |
124 | 0 | } |
125 | 0 |
|
126 | 0 | return NS_OK; |
127 | 0 | } |
128 | | |
129 | | |
130 | | } // namespace embedding |
131 | | } // namespace mozilla |