1 : /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is Web Workers.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * The Mozilla Foundation.
19 : * Portions created by the Initial Developer are Copyright (C) 2011
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Ben Turner <bent.mozilla@gmail.com> (Original Author)
24 : *
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.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef mozilla_dom_workers_xmlhttprequestprivate_h__
40 : #define mozilla_dom_workers_xmlhttprequestprivate_h__
41 :
42 : #include "Workers.h"
43 :
44 : #include "jspubtd.h"
45 : #include "nsAutoPtr.h"
46 :
47 : #include "EventTarget.h"
48 : #include "WorkerFeature.h"
49 : #include "WorkerPrivate.h"
50 :
51 : BEGIN_WORKERS_NAMESPACE
52 :
53 : namespace xhr {
54 :
55 : class Proxy;
56 :
57 : class XMLHttpRequestPrivate : public events::EventTarget,
58 : public WorkerFeature
59 : {
60 : JSObject* mJSObject;
61 : JSObject* mUploadJSObject;
62 : WorkerPrivate* mWorkerPrivate;
63 : nsRefPtr<Proxy> mProxy;
64 :
65 : bool mJSObjectRooted;
66 : bool mMultipart;
67 : bool mBackgroundRequest;
68 : bool mWithCredentials;
69 : bool mCanceled;
70 : PRUint32 mTimeout;
71 :
72 : public:
73 : XMLHttpRequestPrivate(JSObject* aObj, WorkerPrivate* aWorkerPrivate);
74 : ~XMLHttpRequestPrivate();
75 :
76 : void
77 0 : FinalizeInstance(JSContext* aCx)
78 : {
79 0 : ReleaseProxy(XHRIsGoingAway);
80 0 : events::EventTarget::FinalizeInstance(aCx);
81 0 : }
82 :
83 : void
84 : Unpin(JSContext* aCx);
85 :
86 : JSObject*
87 0 : GetJSObject()
88 : {
89 0 : mWorkerPrivate->AssertIsOnWorkerThread();
90 0 : return mJSObject;
91 : }
92 :
93 : JSObject*
94 0 : GetUploadJSObject()
95 : {
96 0 : mWorkerPrivate->AssertIsOnWorkerThread();
97 0 : return mUploadJSObject;
98 : }
99 :
100 : void
101 0 : SetUploadObject(JSObject* aUploadObj)
102 : {
103 0 : mWorkerPrivate->AssertIsOnWorkerThread();
104 0 : mUploadJSObject = aUploadObj;
105 0 : }
106 :
107 : using events::EventTarget::TraceInstance;
108 : using events::EventTarget::GetEventListenerOnEventTarget;
109 : using events::EventTarget::SetEventListenerOnEventTarget;
110 :
111 : bool
112 : Notify(JSContext* aCx, Status aStatus);
113 :
114 : bool
115 : SetMultipart(JSContext* aCx, jsval aOldVal, jsval *aVp);
116 :
117 : bool
118 : SetMozBackgroundRequest(JSContext* aCx, jsval aOldVal, jsval *aVp);
119 :
120 : bool
121 : SetWithCredentials(JSContext* aCx, jsval aOldVal, jsval *aVp);
122 :
123 : bool
124 : SetResponseType(JSContext* aCx, jsval aOldVal, jsval *aVp);
125 :
126 : bool
127 : SetTimeout(JSContext* aCx, jsval aOldVal, jsval *aVp);
128 :
129 : bool
130 : Abort(JSContext* aCx);
131 :
132 : JSString*
133 : GetAllResponseHeaders(JSContext* aCx);
134 :
135 : JSString*
136 : GetResponseHeader(JSContext* aCx, JSString* aHeader);
137 :
138 : bool
139 : Open(JSContext* aCx, JSString* aMethod, JSString* aURL, bool aAsync,
140 : JSString* aUser, JSString* aPassword);
141 :
142 : bool
143 : Send(JSContext* aCx, bool aHasBody, jsval aBody);
144 :
145 : bool
146 : SendAsBinary(JSContext* aCx, JSString* aBody);
147 :
148 : bool
149 : SetRequestHeader(JSContext* aCx, JSString* aHeader, JSString* aValue);
150 :
151 : bool
152 : OverrideMimeType(JSContext* aCx, JSString* aMimeType);
153 :
154 : private:
155 : enum ReleaseType { Default, XHRIsGoingAway, WorkerIsGoingAway };
156 :
157 : void
158 : ReleaseProxy(ReleaseType aType = Default);
159 :
160 : bool
161 : MaybePin(JSContext* aCx);
162 :
163 : bool
164 : MaybeDispatchPrematureAbortEvents(JSContext* aCx);
165 :
166 : bool
167 : DispatchPrematureAbortEvent(JSContext* aCx, JSObject* aTarget,
168 : PRUint64 aEventType, bool aUploadTarget);
169 :
170 : bool
171 0 : SendInProgress() const
172 : {
173 0 : return mJSObjectRooted;
174 : }
175 : };
176 :
177 : } // namespace xhr
178 :
179 : END_WORKERS_NAMESPACE
180 :
181 : #endif // mozilla_dom_workers_xmlhttprequestprivate_h__
|