2011-07-17 12:09:13 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-03-30 21:42:20 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-11-26 22:16:40 -08:00
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
#ifndef mozilla_dom_workers_xmlhttprequest_h__
|
|
|
|
#define mozilla_dom_workers_xmlhttprequest_h__
|
2008-11-26 22:16:40 -08:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
#include "mozilla/dom/workers/bindings/XMLHttpRequestEventTarget.h"
|
|
|
|
#include "mozilla/dom/workers/bindings/WorkerFeature.h"
|
2008-11-26 22:16:40 -08:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
// Need this for XMLHttpRequestResponseType.
|
2012-05-02 21:35:38 -07:00
|
|
|
#include "mozilla/dom/XMLHttpRequestBinding.h"
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2012-05-24 22:07:03 -07:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
class Proxy;
|
|
|
|
class XMLHttpRequestUpload;
|
|
|
|
class WorkerPrivate;
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
class XMLHttpRequest : public XMLHttpRequestEventTarget,
|
|
|
|
public WorkerFeature
|
2008-11-26 22:16:40 -08:00
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
public:
|
|
|
|
struct StateData
|
|
|
|
{
|
|
|
|
nsString mResponseText;
|
|
|
|
uint32_t mStatus;
|
|
|
|
nsString mStatusText;
|
|
|
|
uint16_t mReadyState;
|
|
|
|
jsval mResponse;
|
|
|
|
nsresult mResponseTextResult;
|
|
|
|
nsresult mStatusResult;
|
|
|
|
nsresult mResponseResult;
|
|
|
|
|
|
|
|
StateData()
|
|
|
|
: mStatus(0), mReadyState(0), mResponse(JSVAL_VOID),
|
|
|
|
mResponseTextResult(NS_OK), mStatusResult(NS_OK),
|
|
|
|
mResponseResult(NS_OK)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSObject* mJSObject;
|
|
|
|
XMLHttpRequestUpload* mUpload;
|
|
|
|
WorkerPrivate* mWorkerPrivate;
|
|
|
|
nsRefPtr<Proxy> mProxy;
|
|
|
|
XMLHttpRequestResponseType mResponseType;
|
|
|
|
StateData mStateData;
|
|
|
|
|
|
|
|
uint32_t mTimeout;
|
|
|
|
|
|
|
|
bool mJSObjectRooted;
|
|
|
|
bool mMultipart;
|
|
|
|
bool mBackgroundRequest;
|
|
|
|
bool mWithCredentials;
|
|
|
|
bool mCanceled;
|
|
|
|
|
2012-09-16 17:20:16 -07:00
|
|
|
bool mMozAnon;
|
|
|
|
bool mMozSystem;
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
protected:
|
|
|
|
XMLHttpRequest(JSContext* aCx, WorkerPrivate* aWorkerPrivate);
|
|
|
|
virtual ~XMLHttpRequest();
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void
|
2012-04-26 13:57:33 -07:00
|
|
|
_trace(JSTracer* aTrc) MOZ_OVERRIDE;
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
virtual void
|
2012-04-26 13:57:33 -07:00
|
|
|
_finalize(JSFreeOp* aFop) MOZ_OVERRIDE;
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
static XMLHttpRequest*
|
2012-12-03 08:07:49 -08:00
|
|
|
Constructor(const WorkerGlobalObject& aGlobal,
|
2012-07-17 09:18:53 -07:00
|
|
|
const MozXMLHttpRequestParametersWorkers& aParams,
|
2012-06-21 00:21:55 -07:00
|
|
|
ErrorResult& aRv);
|
2012-09-07 08:07:12 -07:00
|
|
|
|
|
|
|
static XMLHttpRequest*
|
2012-12-03 08:07:49 -08:00
|
|
|
Constructor(const WorkerGlobalObject& aGlobal, const nsAString& ignored,
|
|
|
|
ErrorResult& aRv)
|
2012-09-07 08:07:12 -07:00
|
|
|
{
|
|
|
|
// Pretend like someone passed null, so we can pick up the default values
|
|
|
|
MozXMLHttpRequestParametersWorkers params;
|
2012-12-03 08:07:49 -08:00
|
|
|
if (!params.Init(aGlobal.GetContext(), nullptr, JS::NullValue())) {
|
2012-09-07 08:07:12 -07:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-12-03 08:07:49 -08:00
|
|
|
return Constructor(aGlobal, params, aRv);
|
2012-09-07 08:07:12 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
|
|
|
Unpin();
|
|
|
|
|
|
|
|
bool
|
|
|
|
Notify(JSContext* aCx, Status aStatus) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
#define IMPL_GETTER_AND_SETTER(_type) \
|
|
|
|
JSObject* \
|
2012-05-31 11:16:48 -07:00
|
|
|
GetOn##_type(JSContext* /* unused */, ErrorResult& aRv) \
|
2012-03-30 21:42:20 -07:00
|
|
|
{ \
|
|
|
|
return GetEventListener(NS_LITERAL_STRING(#_type), aRv); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void \
|
2012-05-31 11:16:48 -07:00
|
|
|
SetOn##_type(JSContext* /* unused */, JSObject* aListener, ErrorResult& aRv) \
|
2012-03-30 21:42:20 -07:00
|
|
|
{ \
|
|
|
|
SetEventListener(NS_LITERAL_STRING(#_type), aListener, aRv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_GETTER_AND_SETTER(readystatechange)
|
|
|
|
|
|
|
|
#undef IMPL_GETTER_AND_SETTER
|
|
|
|
|
|
|
|
uint16_t
|
2012-09-11 12:08:24 -07:00
|
|
|
ReadyState() const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
return mStateData.mReadyState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Open(const nsAString& aMethod, const nsAString& aUrl, bool aAsync,
|
2012-05-29 20:45:18 -07:00
|
|
|
const Optional<nsAString>& aUser, const Optional<nsAString>& aPassword,
|
|
|
|
ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
SetRequestHeader(const nsAString& aHeader, const nsAString& aValue,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
uint32_t
|
2012-09-11 12:08:24 -07:00
|
|
|
Timeout() const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
return mTimeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
SetTimeout(uint32_t aTimeout, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
bool
|
2012-09-11 12:08:24 -07:00
|
|
|
WithCredentials() const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
return mWithCredentials;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
SetWithCredentials(bool aWithCredentials, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
bool
|
2012-09-11 12:08:24 -07:00
|
|
|
Multipart() const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
return mMultipart;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
SetMultipart(bool aMultipart, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
bool
|
2012-09-11 12:08:24 -07:00
|
|
|
MozBackgroundRequest() const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
return mBackgroundRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
SetMozBackgroundRequest(bool aBackgroundRequest, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
XMLHttpRequestUpload*
|
2012-05-05 18:15:11 -07:00
|
|
|
GetUpload(ErrorResult& aRv);
|
2008-11-26 22:16:40 -08:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
Send(ErrorResult& aRv);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
Send(const nsAString& aBody, ErrorResult& aRv);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
Send(JSObject* aBody, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
void
|
|
|
|
Send(JSObject& aBody, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Send(&aBody, aRv);
|
|
|
|
}
|
|
|
|
|
2012-05-24 22:07:03 -07:00
|
|
|
void
|
|
|
|
Send(ArrayBuffer& aBody, ErrorResult& aRv) {
|
2012-07-31 20:45:20 -07:00
|
|
|
return Send(aBody.Obj(), aRv);
|
2012-05-24 22:07:03 -07:00
|
|
|
}
|
|
|
|
|
2012-12-19 17:47:39 -08:00
|
|
|
void
|
|
|
|
Send(ArrayBufferView& aBody, ErrorResult& aRv) {
|
|
|
|
return Send(aBody.Obj(), aRv);
|
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
SendAsBinary(const nsAString& aBody, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
Abort(ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
uint16_t
|
2012-05-05 18:15:11 -07:00
|
|
|
GetStatus(ErrorResult& aRv) const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
aRv = mStateData.mStatusResult;
|
|
|
|
return mStateData.mStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetStatusText(nsAString& aStatusText) const
|
|
|
|
{
|
|
|
|
aStatusText = mStateData.mStatusText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetResponseHeader(const nsAString& aHeader, nsAString& aResponseHeader,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
GetAllResponseHeaders(nsAString& aResponseHeaders, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
XMLHttpRequestResponseType
|
2012-09-11 12:08:24 -07:00
|
|
|
ResponseType() const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
return mResponseType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
SetResponseType(XMLHttpRequestResponseType aResponseType, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
jsval
|
2012-05-31 11:16:48 -07:00
|
|
|
GetResponse(JSContext* /* unused */, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
GetResponseText(nsAString& aResponseText, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
JSObject*
|
2012-05-05 18:15:11 -07:00
|
|
|
GetResponseXML() const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2012-05-05 18:15:11 -07:00
|
|
|
GetChannel() const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value
|
2012-05-31 11:16:48 -07:00
|
|
|
GetInterface(JSContext* cx, JSObject* aIID, ErrorResult& aRv)
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2012-03-30 21:42:20 -07:00
|
|
|
return JSVAL_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLHttpRequestUpload*
|
|
|
|
GetUploadObjectNoCreate() const
|
|
|
|
{
|
|
|
|
return mUpload;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UpdateState(const StateData& aStateData)
|
|
|
|
{
|
|
|
|
mStateData = aStateData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NullResponseText()
|
|
|
|
{
|
|
|
|
mStateData.mResponseText.SetIsVoid(true);
|
|
|
|
mStateData.mResponse = JSVAL_NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-16 17:20:16 -07:00
|
|
|
bool MozAnon() const
|
|
|
|
{
|
|
|
|
return mMozAnon;
|
2012-06-10 16:44:50 -07:00
|
|
|
}
|
|
|
|
|
2012-09-16 17:20:16 -07:00
|
|
|
bool MozSystem() const
|
|
|
|
{
|
|
|
|
return mMozSystem;
|
2012-06-10 16:44:50 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
private:
|
|
|
|
enum ReleaseType { Default, XHRIsGoingAway, WorkerIsGoingAway };
|
|
|
|
|
|
|
|
void
|
|
|
|
ReleaseProxy(ReleaseType aType = Default);
|
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
MaybePin(ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
MaybeDispatchPrematureAbortEvents(ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
DispatchPrematureAbortEvent(JSObject* aTarget, uint8_t aEventType,
|
2012-05-05 18:15:11 -07:00
|
|
|
bool aUploadTarget, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
SendInProgress() const
|
|
|
|
{
|
|
|
|
return mJSObjectRooted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SendInternal(const nsAString& aStringBody,
|
|
|
|
JSAutoStructuredCloneBuffer& aBody,
|
|
|
|
nsTArray<nsCOMPtr<nsISupports> >& aClonedObjects,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
};
|
2012-01-18 10:05:38 -08:00
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
#endif // mozilla_dom_workers_xmlhttprequest_h__
|