embedding/components/printingui/src/win/nsPrintProgress.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsPrintProgress.h"
michael@0 7
michael@0 8 #include "nsIBaseWindow.h"
michael@0 9 #include "nsISupportsArray.h"
michael@0 10 #include "nsXPCOM.h"
michael@0 11 #include "nsISupportsPrimitives.h"
michael@0 12 #include "nsIComponentManager.h"
michael@0 13 #include "nsIServiceManager.h"
michael@0 14
michael@0 15 #if 0
michael@0 16 NS_IMPL_ADDREF(nsPrintProgress)
michael@0 17 NS_IMPL_RELEASE(nsPrintProgress)
michael@0 18 #else
michael@0 19 NS_IMETHODIMP_(MozExternalRefCountType) nsPrintProgress::AddRef(void)
michael@0 20 {
michael@0 21 NS_PRECONDITION(int32_t(mRefCnt) >= 0, "illegal refcnt");
michael@0 22 nsrefcnt count;
michael@0 23 count = ++mRefCnt;
michael@0 24 //NS_LOG_ADDREF(this, count, "nsPrintProgress", sizeof(*this));
michael@0 25 return count;
michael@0 26 }
michael@0 27
michael@0 28 NS_IMETHODIMP_(MozExternalRefCountType) nsPrintProgress::Release(void)
michael@0 29 {
michael@0 30 nsrefcnt count;
michael@0 31 NS_PRECONDITION(0 != mRefCnt, "dup release");
michael@0 32 count = --mRefCnt;
michael@0 33 //NS_LOG_RELEASE(this, count, "nsPrintProgress");
michael@0 34 if (0 == count) {
michael@0 35 mRefCnt = 1; /* stabilize */
michael@0 36 /* enable this to find non-threadsafe destructors: */
michael@0 37 /* NS_ASSERT_OWNINGTHREAD(nsPrintProgress); */
michael@0 38 delete this;
michael@0 39 return 0;
michael@0 40 }
michael@0 41 return count;
michael@0 42 }
michael@0 43
michael@0 44 #endif
michael@0 45
michael@0 46 NS_INTERFACE_MAP_BEGIN(nsPrintProgress)
michael@0 47 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrintStatusFeedback)
michael@0 48 NS_INTERFACE_MAP_ENTRY(nsIPrintProgress)
michael@0 49 NS_INTERFACE_MAP_ENTRY(nsIPrintStatusFeedback)
michael@0 50 NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
michael@0 51 NS_INTERFACE_MAP_END_THREADSAFE
michael@0 52
michael@0 53
michael@0 54 nsPrintProgress::nsPrintProgress()
michael@0 55 {
michael@0 56 m_closeProgress = false;
michael@0 57 m_processCanceled = false;
michael@0 58 m_pendingStateFlags = -1;
michael@0 59 m_pendingStateValue = NS_OK;
michael@0 60 }
michael@0 61
michael@0 62 nsPrintProgress::~nsPrintProgress()
michael@0 63 {
michael@0 64 (void)ReleaseListeners();
michael@0 65 }
michael@0 66
michael@0 67 /* void openProgressDialog (in nsIDOMWindow parent, in string dialogURL, in nsISupports parameters); */
michael@0 68 NS_IMETHODIMP nsPrintProgress::OpenProgressDialog(nsIDOMWindow *parent,
michael@0 69 const char *dialogURL,
michael@0 70 nsISupports *parameters,
michael@0 71 nsIObserver *openDialogObserver,
michael@0 72 bool *notifyOnOpen)
michael@0 73 {
michael@0 74 *notifyOnOpen = true;
michael@0 75 m_observer = openDialogObserver;
michael@0 76
michael@0 77 nsresult rv = NS_ERROR_FAILURE;
michael@0 78
michael@0 79 if (m_dialog)
michael@0 80 return NS_ERROR_ALREADY_INITIALIZED;
michael@0 81
michael@0 82 if (!dialogURL || !*dialogURL)
michael@0 83 return NS_ERROR_INVALID_ARG;
michael@0 84
michael@0 85 if (parent)
michael@0 86 {
michael@0 87 // Set up window.arguments[0]...
michael@0 88 nsCOMPtr<nsISupportsArray> array;
michael@0 89 rv = NS_NewISupportsArray(getter_AddRefs(array));
michael@0 90 NS_ENSURE_SUCCESS(rv, rv);
michael@0 91
michael@0 92 nsCOMPtr<nsISupportsInterfacePointer> ifptr =
michael@0 93 do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
michael@0 94 NS_ENSURE_SUCCESS(rv, rv);
michael@0 95
michael@0 96 ifptr->SetData(static_cast<nsIPrintProgress*>(this));
michael@0 97 ifptr->SetDataIID(&NS_GET_IID(nsIPrintProgress));
michael@0 98
michael@0 99 array->AppendElement(ifptr);
michael@0 100
michael@0 101 array->AppendElement(parameters);
michael@0 102
michael@0 103 // Open the dialog.
michael@0 104 nsCOMPtr<nsIDOMWindow> newWindow;
michael@0 105 rv = parent->OpenDialog(NS_ConvertASCIItoUTF16(dialogURL),
michael@0 106 NS_LITERAL_STRING("_blank"),
michael@0 107 NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
michael@0 108 array, getter_AddRefs(newWindow));
michael@0 109 }
michael@0 110
michael@0 111 return rv;
michael@0 112 }
michael@0 113
michael@0 114 /* void closeProgressDialog (in boolean forceClose); */
michael@0 115 NS_IMETHODIMP nsPrintProgress::CloseProgressDialog(bool forceClose)
michael@0 116 {
michael@0 117 m_closeProgress = true;
michael@0 118 // XXX Casting from bool to nsresult
michael@0 119 return OnStateChange(nullptr, nullptr, nsIWebProgressListener::STATE_STOP,
michael@0 120 static_cast<nsresult>(forceClose));
michael@0 121 }
michael@0 122
michael@0 123 /* nsIPrompt GetPrompter (); */
michael@0 124 NS_IMETHODIMP nsPrintProgress::GetPrompter(nsIPrompt **_retval)
michael@0 125 {
michael@0 126 NS_ENSURE_ARG_POINTER(_retval);
michael@0 127 *_retval = nullptr;
michael@0 128
michael@0 129 if (! m_closeProgress && m_dialog)
michael@0 130 return m_dialog->GetPrompter(_retval);
michael@0 131
michael@0 132 return NS_ERROR_FAILURE;
michael@0 133 }
michael@0 134
michael@0 135 /* attribute boolean processCanceledByUser; */
michael@0 136 NS_IMETHODIMP nsPrintProgress::GetProcessCanceledByUser(bool *aProcessCanceledByUser)
michael@0 137 {
michael@0 138 NS_ENSURE_ARG_POINTER(aProcessCanceledByUser);
michael@0 139 *aProcessCanceledByUser = m_processCanceled;
michael@0 140 return NS_OK;
michael@0 141 }
michael@0 142 NS_IMETHODIMP nsPrintProgress::SetProcessCanceledByUser(bool aProcessCanceledByUser)
michael@0 143 {
michael@0 144 m_processCanceled = aProcessCanceledByUser;
michael@0 145 OnStateChange(nullptr, nullptr, nsIWebProgressListener::STATE_STOP, NS_OK);
michael@0 146 return NS_OK;
michael@0 147 }
michael@0 148
michael@0 149 /* void RegisterListener (in nsIWebProgressListener listener); */
michael@0 150 NS_IMETHODIMP nsPrintProgress::RegisterListener(nsIWebProgressListener * listener)
michael@0 151 {
michael@0 152 if (!listener) //Nothing to do with a null listener!
michael@0 153 return NS_OK;
michael@0 154
michael@0 155 m_listenerList.AppendObject(listener);
michael@0 156 if (m_closeProgress || m_processCanceled)
michael@0 157 listener->OnStateChange(nullptr, nullptr,
michael@0 158 nsIWebProgressListener::STATE_STOP, NS_OK);
michael@0 159 else
michael@0 160 {
michael@0 161 listener->OnStatusChange(nullptr, nullptr, NS_OK, m_pendingStatus.get());
michael@0 162 if (m_pendingStateFlags != -1)
michael@0 163 listener->OnStateChange(nullptr, nullptr, m_pendingStateFlags, m_pendingStateValue);
michael@0 164 }
michael@0 165
michael@0 166 return NS_OK;
michael@0 167 }
michael@0 168
michael@0 169 /* void UnregisterListener (in nsIWebProgressListener listener); */
michael@0 170 NS_IMETHODIMP nsPrintProgress::UnregisterListener(nsIWebProgressListener *listener)
michael@0 171 {
michael@0 172 if (listener)
michael@0 173 m_listenerList.RemoveObject(listener);
michael@0 174
michael@0 175 return NS_OK;
michael@0 176 }
michael@0 177
michael@0 178 /* void doneIniting (); */
michael@0 179 NS_IMETHODIMP nsPrintProgress::DoneIniting()
michael@0 180 {
michael@0 181 if (m_observer) {
michael@0 182 m_observer->Observe(nullptr, nullptr, nullptr);
michael@0 183 }
michael@0 184 return NS_OK;
michael@0 185 }
michael@0 186
michael@0 187 /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */
michael@0 188 NS_IMETHODIMP nsPrintProgress::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, uint32_t aStateFlags, nsresult aStatus)
michael@0 189 {
michael@0 190 m_pendingStateFlags = aStateFlags;
michael@0 191 m_pendingStateValue = aStatus;
michael@0 192
michael@0 193 uint32_t count = m_listenerList.Count();
michael@0 194 for (uint32_t i = count - 1; i < count; i --)
michael@0 195 {
michael@0 196 nsCOMPtr<nsIWebProgressListener> progressListener = m_listenerList.SafeObjectAt(i);
michael@0 197 if (progressListener)
michael@0 198 progressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
michael@0 199 }
michael@0 200
michael@0 201 return NS_OK;
michael@0 202 }
michael@0 203
michael@0 204 /* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
michael@0 205 NS_IMETHODIMP nsPrintProgress::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, int32_t aCurSelfProgress, int32_t aMaxSelfProgress, int32_t aCurTotalProgress, int32_t aMaxTotalProgress)
michael@0 206 {
michael@0 207 uint32_t count = m_listenerList.Count();
michael@0 208 for (uint32_t i = count - 1; i < count; i --)
michael@0 209 {
michael@0 210 nsCOMPtr<nsIWebProgressListener> progressListener = m_listenerList.SafeObjectAt(i);
michael@0 211 if (progressListener)
michael@0 212 progressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
michael@0 213 }
michael@0 214
michael@0 215 return NS_OK;
michael@0 216 }
michael@0 217
michael@0 218 /* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location, in unsigned long aFlags); */
michael@0 219 NS_IMETHODIMP nsPrintProgress::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location, uint32_t aFlags)
michael@0 220 {
michael@0 221 return NS_OK;
michael@0 222 }
michael@0 223
michael@0 224 /* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
michael@0 225 NS_IMETHODIMP nsPrintProgress::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const char16_t *aMessage)
michael@0 226 {
michael@0 227 if (aMessage && *aMessage)
michael@0 228 m_pendingStatus = aMessage;
michael@0 229
michael@0 230 uint32_t count = m_listenerList.Count();
michael@0 231 for (uint32_t i = count - 1; i < count; i --)
michael@0 232 {
michael@0 233 nsCOMPtr<nsIWebProgressListener> progressListener = m_listenerList.SafeObjectAt(i);
michael@0 234 if (progressListener)
michael@0 235 progressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
michael@0 236 }
michael@0 237
michael@0 238 return NS_OK;
michael@0 239 }
michael@0 240
michael@0 241 /* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
michael@0 242 NS_IMETHODIMP nsPrintProgress::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, uint32_t state)
michael@0 243 {
michael@0 244 return NS_OK;
michael@0 245 }
michael@0 246
michael@0 247 nsresult nsPrintProgress::ReleaseListeners()
michael@0 248 {
michael@0 249 m_listenerList.Clear();
michael@0 250 return NS_OK;
michael@0 251 }
michael@0 252
michael@0 253 NS_IMETHODIMP nsPrintProgress::ShowStatusString(const char16_t *status)
michael@0 254 {
michael@0 255 return OnStatusChange(nullptr, nullptr, NS_OK, status);
michael@0 256 }
michael@0 257
michael@0 258 /* void startMeteors (); */
michael@0 259 NS_IMETHODIMP nsPrintProgress::StartMeteors()
michael@0 260 {
michael@0 261 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 262 }
michael@0 263
michael@0 264 /* void stopMeteors (); */
michael@0 265 NS_IMETHODIMP nsPrintProgress::StopMeteors()
michael@0 266 {
michael@0 267 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 268 }
michael@0 269
michael@0 270 /* void showProgress (in long percent); */
michael@0 271 NS_IMETHODIMP nsPrintProgress::ShowProgress(int32_t percent)
michael@0 272 {
michael@0 273 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 274 }
michael@0 275
michael@0 276 /* [noscript] void setDocShell (in nsIDocShell shell, in nsIDOMWindow window); */
michael@0 277 NS_IMETHODIMP nsPrintProgress::SetDocShell(nsIDocShell *shell, nsIDOMWindow *window)
michael@0 278 {
michael@0 279 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 280 }
michael@0 281
michael@0 282 /* void closeWindow (); */
michael@0 283 NS_IMETHODIMP nsPrintProgress::CloseWindow()
michael@0 284 {
michael@0 285 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 286 }

mercurial