Bug 458160 - Enable downloadable .otf fonts under Windows. r=roc, sr=vlad.
[wine-gecko.git] / dom / src / threads / nsDOMWorkerXHRProxiedFunctions.h
blob962e4ae853392eb4cf31948bfbd565ff0860bf72
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 __NSDOMWORKERXHRPROXIEDFUNCTIONS_H__
40 #define __NSDOMWORKERXHRPROXIEDFUNCTIONS_H__
42 #define MAKE_PROXIED_FUNCTION0(_name) \
43 class _name : public SyncEventCapturingRunnable \
44 { \
45 public: \
46 virtual nsresult RunInternal() \
47 { \
48 nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
49 if (xhr) { \
50 return xhr-> _name (); \
51 } \
52 return NS_OK; \
53 } \
56 #define MAKE_PROXIED_FUNCTION1(_name, _arg1) \
57 class _name : public SyncEventCapturingRunnable \
58 { \
59 public: \
60 _name (_arg1 aArg1) : mArg1(aArg1) { } \
62 virtual nsresult RunInternal() \
63 { \
64 nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
65 if (xhr) { \
66 return xhr-> _name (mArg1); \
67 } \
68 return NS_OK; \
69 } \
70 private: \
71 _arg1 mArg1; \
74 #define MAKE_PROXIED_FUNCTION2(_name, _arg1, _arg2) \
75 class _name : public SyncEventCapturingRunnable \
76 { \
77 public: \
78 _name (_arg1 aArg1, _arg2 aArg2) : mArg1(aArg1), mArg2(aArg2) { } \
80 virtual nsresult RunInternal() \
81 { \
82 nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
83 if (xhr) { \
84 return xhr-> _name (mArg1, mArg2); \
85 } \
86 return NS_OK; \
87 } \
88 private: \
89 _arg1 mArg1; \
90 _arg2 mArg2; \
93 namespace nsDOMWorkerProxiedXHRFunctions
95 typedef nsDOMWorkerXHRProxy::SyncEventQueue SyncEventQueue;
97 class SyncEventCapturingRunnable : public nsRunnable
99 public:
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!");
108 mXHR = aXHR;
109 mQueue = aQueue;
112 virtual nsresult RunInternal() = 0;
114 NS_IMETHOD Run() {
115 NS_ASSERTION(mXHR && mQueue, "Forgot to call Init!");
117 SyncEventQueue* oldQueue = mXHR->SetSyncEventQueue(mQueue);
119 nsresult rv = RunInternal();
121 mXHR->SetSyncEventQueue(oldQueue);
123 return rv;
126 protected:
127 nsRefPtr<nsDOMWorkerXHRProxy> mXHR;
128 SyncEventQueue* mQueue;
131 class Abort : public SyncEventCapturingRunnable
133 public:
134 virtual nsresult RunInternal() {
135 return mXHR->Abort();
139 class OpenRequest : public SyncEventCapturingRunnable
141 public:
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);
152 private:
153 nsCString mMethod;
154 nsCString mUrl;
155 PRBool mAsync;
156 nsString mUser;
157 nsString 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&,
169 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__ */