2011-07-17 23:09:13 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-03-31 08:42:20 +04: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-27 09:16:40 +03:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
#ifndef mozilla_dom_workers_xmlhttprequest_h__
|
|
|
|
#define mozilla_dom_workers_xmlhttprequest_h__
|
2008-11-27 09:16:40 +03:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
#include "mozilla/dom/workers/bindings/XMLHttpRequestEventTarget.h"
|
|
|
|
#include "mozilla/dom/workers/bindings/WorkerFeature.h"
|
2008-11-27 09:16:40 +03:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
// Need this for XMLHttpRequestResponseType.
|
2012-05-03 08:35:38 +04:00
|
|
|
#include "mozilla/dom/XMLHttpRequestBinding.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
class Proxy;
|
|
|
|
class XMLHttpRequestUpload;
|
|
|
|
class WorkerPrivate;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
class XMLHttpRequest : public XMLHttpRequestEventTarget,
|
|
|
|
public WorkerFeature
|
2008-11-27 09:16:40 +03:00
|
|
|
{
|
2012-03-31 08:42:20 +04: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;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
XMLHttpRequest(JSContext* aCx, WorkerPrivate* aWorkerPrivate);
|
|
|
|
virtual ~XMLHttpRequest();
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void
|
|
|
|
_Trace(JSTracer* aTrc) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void
|
2012-03-19 18:34:55 +04:00
|
|
|
_Finalize(JSFreeOp* aFop) MOZ_OVERRIDE;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
static XMLHttpRequest*
|
2012-05-06 07:33:59 +04:00
|
|
|
_Constructor(JSContext* aCx, JSObject* aGlobal, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
Unpin();
|
|
|
|
|
|
|
|
bool
|
|
|
|
Notify(JSContext* aCx, Status aStatus) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
#define IMPL_GETTER_AND_SETTER(_type) \
|
|
|
|
JSObject* \
|
2012-05-06 07:33:59 +04:00
|
|
|
GetOn##_type(nsresult& aRv) \
|
2012-03-31 08:42:20 +04:00
|
|
|
{ \
|
|
|
|
return GetEventListener(NS_LITERAL_STRING(#_type), aRv); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void \
|
2012-05-06 07:33:59 +04:00
|
|
|
SetOn##_type(JSObject* aListener, nsresult& aRv) \
|
2012-03-31 08:42:20 +04:00
|
|
|
{ \
|
|
|
|
SetEventListener(NS_LITERAL_STRING(#_type), aListener, aRv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_GETTER_AND_SETTER(readystatechange)
|
|
|
|
|
|
|
|
#undef IMPL_GETTER_AND_SETTER
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
GetReadyState() const
|
|
|
|
{
|
|
|
|
return mStateData.mReadyState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Open(const nsAString& aMethod, const nsAString& aUrl, bool aAsync,
|
2012-05-06 07:33:59 +04:00
|
|
|
const nsAString& aUser, const nsAString& aPassword, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
SetRequestHeader(const nsAString& aHeader, const nsAString& aValue,
|
2012-05-06 07:33:59 +04:00
|
|
|
nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
uint32_t
|
2012-05-06 07:33:59 +04:00
|
|
|
GetTimeout(nsresult& aRv) const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mTimeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
SetTimeout(uint32_t aTimeout, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
bool
|
2012-05-06 07:33:59 +04:00
|
|
|
GetWithCredentials(nsresult& aRv) const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mWithCredentials;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
SetWithCredentials(bool aWithCredentials, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
bool
|
2012-05-06 07:33:59 +04:00
|
|
|
GetMultipart(nsresult& aRv) const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mMultipart;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
SetMultipart(bool aMultipart, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
bool
|
2012-05-06 07:33:59 +04:00
|
|
|
GetMozBackgroundRequest(nsresult& aRv) const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mBackgroundRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
SetMozBackgroundRequest(bool aBackgroundRequest, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
XMLHttpRequestUpload*
|
2012-05-06 07:33:59 +04:00
|
|
|
GetUpload(nsresult& aRv);
|
2008-11-27 09:16:40 +03:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
Send(nsresult& aRv);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
Send(const nsAString& aBody, nsresult& aRv);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
Send(JSObject* aBody, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
SendAsBinary(const nsAString& aBody, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
Abort(nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
uint16_t
|
2012-05-06 07:33:59 +04:00
|
|
|
GetStatus(nsresult& aRv) const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
aRv = mStateData.mStatusResult;
|
|
|
|
return mStateData.mStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetStatusText(nsAString& aStatusText) const
|
|
|
|
{
|
|
|
|
aStatusText = mStateData.mStatusText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetResponseHeader(const nsAString& aHeader, nsAString& aResponseHeader,
|
2012-05-06 07:33:59 +04:00
|
|
|
nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
GetAllResponseHeaders(nsAString& aResponseHeaders, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
OverrideMimeType(const nsAString& aMimeType, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
XMLHttpRequestResponseType
|
2012-05-06 07:33:59 +04:00
|
|
|
GetResponseType(nsresult& aRv) const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mResponseType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
SetResponseType(XMLHttpRequestResponseType aResponseType, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
jsval
|
2012-05-06 07:33:59 +04:00
|
|
|
GetResponse(nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
GetResponseText(nsAString& aResponseText, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
JSObject*
|
2012-05-06 07:33:59 +04:00
|
|
|
GetResponseXML(nsresult& aRv) const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2012-05-06 07:33:59 +04:00
|
|
|
GetChannel(nsresult& aRv) const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value
|
2012-05-06 07:33:59 +04:00
|
|
|
GetInterface(JSObject* aIID, nsresult& aRv)
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
2012-05-06 07:33:59 +04:00
|
|
|
aRv = NS_ERROR_FAILURE;
|
2012-03-31 08:42:20 +04: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum ReleaseType { Default, XHRIsGoingAway, WorkerIsGoingAway };
|
|
|
|
|
|
|
|
void
|
|
|
|
ReleaseProxy(ReleaseType aType = Default);
|
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
MaybePin(nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2012-05-06 07:33:59 +04:00
|
|
|
MaybeDispatchPrematureAbortEvents(nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
DispatchPrematureAbortEvent(JSObject* aTarget, uint8_t aEventType,
|
2012-05-06 07:33:59 +04:00
|
|
|
bool aUploadTarget, nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
SendInProgress() const
|
|
|
|
{
|
|
|
|
return mJSObjectRooted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SendInternal(const nsAString& aStringBody,
|
|
|
|
JSAutoStructuredCloneBuffer& aBody,
|
|
|
|
nsTArray<nsCOMPtr<nsISupports> >& aClonedObjects,
|
2012-05-06 07:33:59 +04:00
|
|
|
nsresult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
};
|
2012-01-18 22:05:38 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
#endif // mozilla_dom_workers_xmlhttprequest_h__
|