Bug 462525 - username truncation code is unnecessarily duplicated in nsLoginManagerP...
[wine-gecko.git] / dom / src / threads / nsDOMWorkerXHRProxy.h
blob9f85f2c037d7153bdf6bd4db2570d1f69181ba08
1 /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is worker threads.
17 * The Initial Developer of the Original Code is
18 * Mozilla Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2008
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Ben Turner <bent.mozilla@gmail.com> (Original Author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef __NSDOMWORKERXHRPROXY_H__
40 #define __NSDOMWORKERXHRPROXY_H__
42 // Bases
43 #include "nsThreadUtils.h"
44 #include "nsIDOMEventListener.h"
45 #include "nsIRequestObserver.h"
47 // Other includes
48 #include "nsCOMPtr.h"
49 #include "nsStringGlue.h"
50 #include "nsTArray.h"
52 // DOMWorker includes
53 #include "nsDOMWorkerXHR.h"
55 class nsIJSXMLHttpRequest;
56 class nsIThread;
57 class nsIVariant;
58 class nsIXMLHttpRequest;
59 class nsDOMWorkerXHREvent;
60 class nsDOMWorkerXHRFinishSyncXHRRunnable;
61 class nsDOMWorkerXHRWrappedListener;
62 class nsXMLHttpRequest;
64 class nsDOMWorkerXHRProxy : public nsIRunnable,
65 public nsIDOMEventListener,
66 public nsIRequestObserver
68 friend class nsDOMWorkerXHRAttachUploadListenersRunnable;
69 friend class nsDOMWorkerXHREvent;
70 friend class nsDOMWorkerXHRFinishSyncXHRRunnable;
71 friend class nsDOMWorkerXHRLastProgressOrLoadEvent;
72 friend class nsDOMWorkerXHR;
73 friend class nsDOMWorkerXHRUpload;
75 typedef nsCOMPtr<nsIDOMEventListener> Listener;
76 typedef nsTArray<Listener> ListenerArray;
78 typedef nsRefPtr<nsDOMWorkerXHRWrappedListener> WrappedListener;
80 typedef nsresult (NS_STDCALL nsIDOMEventTarget::*EventListenerFunction)
81 (const nsAString&, nsIDOMEventListener*, PRBool);
83 public:
84 typedef nsAutoTArray<nsCOMPtr<nsIRunnable>, 5> SyncEventQueue;
86 NS_DECL_ISUPPORTS
87 NS_DECL_NSIDOMEVENTLISTENER
88 NS_DECL_NSIRUNNABLE
89 NS_DECL_NSIREQUESTOBSERVER
91 nsDOMWorkerXHRProxy(nsDOMWorkerXHR* aWorkerXHR);
92 virtual ~nsDOMWorkerXHRProxy();
94 nsresult Init();
96 nsIXMLHttpRequest* GetXMLHttpRequest();
98 nsresult OpenRequest(const nsACString& aMethod,
99 const nsACString& aUrl,
100 PRBool aAsync,
101 const nsAString& aUser,
102 const nsAString& aPassword);
104 nsresult Abort();
106 SyncEventQueue* SetSyncEventQueue(SyncEventQueue* aQueue);
108 PRInt32 ChannelID() {
109 return mChannelID;
112 protected:
113 nsresult InitInternal();
114 void DestroyInternal();
116 nsresult Destroy();
118 void AddRemoveXHRListeners(PRBool aAdd);
119 void FlipOwnership();
121 nsresult AddEventListener(PRUint32 aType,
122 nsIDOMEventListener* aListener,
123 PRBool aOnXListener,
124 PRBool aUploadListener);
126 nsresult RemoveEventListener(PRUint32 aType,
127 nsIDOMEventListener* aListener,
128 PRBool aUploadListener);
130 already_AddRefed<nsIDOMEventListener> GetOnXListener(PRUint32 aType,
131 PRBool aUploadListener);
133 nsresult HandleWorkerEvent(nsDOMWorkerXHREvent* aEvent, PRBool aUploadEvent);
135 nsresult HandleWorkerEvent(nsIDOMEvent* aEvent, PRBool aUploadEvent);
137 nsresult HandleEventInternal(PRUint32 aType,
138 nsIDOMEvent* aEvent,
139 PRBool aUploadEvent);
141 void ClearEventListeners();
143 // Methods of nsIXMLHttpRequest that we implement
144 nsresult GetAllResponseHeaders(char** _retval);
145 nsresult GetResponseHeader(const nsACString& aHeader,
146 nsACString& _retval);
147 nsresult Send(nsIVariant* aBody);
148 nsresult SendAsBinary(const nsAString& aBody);
149 nsresult GetResponseText(nsAString& _retval);
150 nsresult GetStatusText(nsACString& _retval);
151 nsresult GetStatus(nsresult* _retval);
152 nsresult GetReadyState(PRInt32* _retval);
153 nsresult SetRequestHeader(const nsACString& aHeader,
154 const nsACString& aValue);
155 nsresult OverrideMimeType(const nsACString& aMimetype);
156 nsresult GetMultipart(PRBool* aMultipart);
157 nsresult SetMultipart(PRBool aMultipart);
158 nsresult GetWithCredentials(PRBool* aWithCredentials);
159 nsresult SetWithCredentials(PRBool aWithCredentials);
161 nsresult RunSyncEventLoop();
163 // aEvent is used to see if we should check upload listeners as well. If left
164 // unset we always check upload listeners.
165 PRBool HasListenersForType(PRUint32 aType, nsIDOMEvent* aEvent = nsnull);
167 // May be weak or strong, check mOwnedByXHR.
168 nsDOMWorkerXHR* mWorkerXHR;
170 // May be weak or strong, check mOwnedByXHR.
171 nsIXMLHttpRequest* mXHR;
173 // Always weak!
174 nsXMLHttpRequest* mConcreteXHR;
175 nsIXMLHttpRequestUpload* mUpload;
177 nsCOMPtr<nsIThread> mMainThread;
179 nsRefPtr<nsDOMWorkerXHREvent> mLastXHREvent;
180 nsRefPtr<nsDOMWorkerXHREvent> mLastProgressOrLoadEvent;
182 nsTArray<ListenerArray> mXHRListeners;
183 nsTArray<WrappedListener> mXHROnXListeners;
185 nsTArray<ListenerArray> mUploadListeners;
186 nsTArray<WrappedListener> mUploadOnXListeners;
188 SyncEventQueue* mSyncEventQueue;
190 PRInt32 mChannelID;
192 // Only touched on the worker thread!
193 nsCOMPtr<nsIThread> mSyncXHRThread;
195 // Touched on more than one thread, protected by the worker's lock.
196 nsRefPtr<nsDOMWorkerXHRFinishSyncXHRRunnable> mSyncFinishedRunnable;
198 // Whether or not this object is owned by the real XHR object.
199 PRPackedBool mOwnedByXHR;
201 PRPackedBool mWantUploadListeners;
202 PRPackedBool mCanceled;
204 PRPackedBool mSyncRequest;
207 #endif /* __NSDOMWORKERXHRPROXY_H__ */