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
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.
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 __NSDOMWORKERXHRPROXIEDFUNCTIONS_H__
40 #define __NSDOMWORKERXHRPROXIEDFUNCTIONS_H__
42 #define MAKE_PROXIED_FUNCTION0(_name) \
43 class _name : public SyncEventCapturingRunnable \
46 virtual nsresult RunInternal() \
48 nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
50 return xhr-> _name (); \
56 #define MAKE_PROXIED_FUNCTION1(_name, _arg1) \
57 class _name : public SyncEventCapturingRunnable \
60 _name (_arg1 aArg1) : mArg1(aArg1) { } \
62 virtual nsresult RunInternal() \
64 nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
66 return xhr-> _name (mArg1); \
74 #define MAKE_PROXIED_FUNCTION2(_name, _arg1, _arg2) \
75 class _name : public SyncEventCapturingRunnable \
78 _name (_arg1 aArg1, _arg2 aArg2) : mArg1(aArg1), mArg2(aArg2) { } \
80 virtual nsresult RunInternal() \
82 nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
84 return xhr-> _name (mArg1, mArg2); \
93 namespace nsDOMWorkerProxiedXHRFunctions
95 typedef nsDOMWorkerXHRProxy::SyncEventQueue SyncEventQueue
;
97 class SyncEventCapturingRunnable
: public nsRunnable
100 SyncEventCapturingRunnable()
101 : mXHR(nsnull
), mQueue(nsnull
) { }
103 void Init(nsDOMWorkerXHRProxy
* aXHR
,
104 SyncEventQueue
* aQueue
) {
105 NS_ASSERTION(aXHR
, "Null pointer!");
106 NS_ASSERTION(aQueue
, "Null pointer!");
112 virtual nsresult
RunInternal() = 0;
115 NS_ASSERTION(mXHR
&& mQueue
, "Forgot to call Init!");
117 SyncEventQueue
* oldQueue
= mXHR
->SetSyncEventQueue(mQueue
);
119 nsresult rv
= RunInternal();
121 mXHR
->SetSyncEventQueue(oldQueue
);
127 nsRefPtr
<nsDOMWorkerXHRProxy
> mXHR
;
128 SyncEventQueue
* mQueue
;
131 class Abort
: public SyncEventCapturingRunnable
134 virtual nsresult
RunInternal() {
135 return mXHR
->Abort();
139 class OpenRequest
: public SyncEventCapturingRunnable
142 OpenRequest(const nsACString
& aMethod
, const nsACString
& aUrl
,
143 PRBool aAsync
, const nsAString
& aUser
,
144 const nsAString
& aPassword
)
145 : mMethod(aMethod
), mUrl(aUrl
), mAsync(aAsync
), mUser(aUser
),
146 mPassword(aPassword
) { }
148 virtual nsresult
RunInternal() {
149 return mXHR
->OpenRequest(mMethod
, mUrl
, mAsync
, mUser
, mPassword
);
160 MAKE_PROXIED_FUNCTION1(GetAllResponseHeaders
, char**);
162 MAKE_PROXIED_FUNCTION2(GetResponseHeader
, const nsACString
&, nsACString
&);
164 MAKE_PROXIED_FUNCTION1(Send
, nsIVariant
*);
166 MAKE_PROXIED_FUNCTION1(SendAsBinary
, const nsAString
&);
168 MAKE_PROXIED_FUNCTION2(SetRequestHeader
, const nsACString
&,
171 MAKE_PROXIED_FUNCTION1(OverrideMimeType
, const nsACString
&);
173 MAKE_PROXIED_FUNCTION1(SetMultipart
, PRBool
);
175 MAKE_PROXIED_FUNCTION1(GetMultipart
, PRBool
*);
177 MAKE_PROXIED_FUNCTION1(GetWithCredentials
, PRBool
*);
179 MAKE_PROXIED_FUNCTION1(SetWithCredentials
, PRBool
);
182 #endif /* __NSDOMWORKERXHRPROXIEDFUNCTIONS_H__ */