2011-07-17 19:09:13 +00:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-03-31 04:42:20 +00: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 06:16:40 +00:00
|
|
|
|
2011-07-17 19:09:13 +00:00
|
|
|
#ifndef mozilla_dom_workers_xmlhttprequest_h__
|
|
|
|
#define mozilla_dom_workers_xmlhttprequest_h__
|
2008-11-27 06:16:40 +00:00
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
#include "mozilla/dom/workers/bindings/XMLHttpRequestEventTarget.h"
|
|
|
|
#include "mozilla/dom/workers/bindings/WorkerFeature.h"
|
2008-11-27 06:16:40 +00:00
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
// Need this for XMLHttpRequestResponseType.
|
2012-05-03 04:35:38 +00:00
|
|
|
#include "mozilla/dom/XMLHttpRequestBinding.h"
|
2011-07-17 19:09:13 +00:00
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2012-05-25 05:07:03 +00:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
|
2011-07-17 19:09:13 +00:00
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
class Proxy;
|
|
|
|
class XMLHttpRequestUpload;
|
|
|
|
class WorkerPrivate;
|
2011-07-17 19:09:13 +00:00
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
class XMLHttpRequest : public XMLHttpRequestEventTarget,
|
|
|
|
public WorkerFeature
|
2008-11-27 06:16:40 +00:00
|
|
|
{
|
2012-03-31 04:42:20 +00: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 mBackgroundRequest;
|
|
|
|
bool mWithCredentials;
|
|
|
|
bool mCanceled;
|
|
|
|
|
2012-09-17 00:20:16 +00:00
|
|
|
bool mMozAnon;
|
|
|
|
bool mMozSystem;
|
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
protected:
|
|
|
|
XMLHttpRequest(JSContext* aCx, WorkerPrivate* aWorkerPrivate);
|
|
|
|
virtual ~XMLHttpRequest();
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void
|
2012-04-26 20:57:33 +00:00
|
|
|
_trace(JSTracer* aTrc) MOZ_OVERRIDE;
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
virtual void
|
2012-04-26 20:57:33 +00:00
|
|
|
_finalize(JSFreeOp* aFop) MOZ_OVERRIDE;
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
static XMLHttpRequest*
|
2012-12-03 16:07:49 +00:00
|
|
|
Constructor(const WorkerGlobalObject& aGlobal,
|
2012-07-17 16:18:53 +00:00
|
|
|
const MozXMLHttpRequestParametersWorkers& aParams,
|
2012-06-21 07:21:55 +00:00
|
|
|
ErrorResult& aRv);
|
2012-09-07 15:07:12 +00:00
|
|
|
|
|
|
|
static XMLHttpRequest*
|
2012-12-03 16:07:49 +00:00
|
|
|
Constructor(const WorkerGlobalObject& aGlobal, const nsAString& ignored,
|
|
|
|
ErrorResult& aRv)
|
2012-09-07 15:07:12 +00:00
|
|
|
{
|
|
|
|
// Pretend like someone passed null, so we can pick up the default values
|
|
|
|
MozXMLHttpRequestParametersWorkers params;
|
2013-05-03 23:29:08 +00:00
|
|
|
if (!params.Init(aGlobal.GetContext(), JS::NullHandleValue)) {
|
2012-09-07 15:07:12 +00:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-12-03 16:07:49 +00:00
|
|
|
return Constructor(aGlobal, params, aRv);
|
2012-09-07 15:07:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
void
|
|
|
|
Unpin();
|
|
|
|
|
|
|
|
bool
|
|
|
|
Notify(JSContext* aCx, Status aStatus) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
#define IMPL_GETTER_AND_SETTER(_type) \
|
|
|
|
JSObject* \
|
2012-05-31 18:16:48 +00:00
|
|
|
GetOn##_type(JSContext* /* unused */, ErrorResult& aRv) \
|
2012-03-31 04:42:20 +00:00
|
|
|
{ \
|
|
|
|
return GetEventListener(NS_LITERAL_STRING(#_type), aRv); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void \
|
2012-05-31 18:16:48 +00:00
|
|
|
SetOn##_type(JSContext* /* unused */, JSObject* aListener, ErrorResult& aRv) \
|
2012-03-31 04:42:20 +00:00
|
|
|
{ \
|
|
|
|
SetEventListener(NS_LITERAL_STRING(#_type), aListener, aRv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_GETTER_AND_SETTER(readystatechange)
|
|
|
|
|
|
|
|
#undef IMPL_GETTER_AND_SETTER
|
|
|
|
|
|
|
|
uint16_t
|
2012-09-11 19:08:24 +00:00
|
|
|
ReadyState() const
|
2012-03-31 04:42:20 +00:00
|
|
|
{
|
|
|
|
return mStateData.mReadyState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Open(const nsAString& aMethod, const nsAString& aUrl, bool aAsync,
|
2012-05-30 03:45:18 +00:00
|
|
|
const Optional<nsAString>& aUser, const Optional<nsAString>& aPassword,
|
|
|
|
ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SetRequestHeader(const nsAString& aHeader, const nsAString& aValue,
|
2012-05-06 01:15:11 +00:00
|
|
|
ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
uint32_t
|
2012-09-11 19:08:24 +00:00
|
|
|
Timeout() const
|
2012-03-31 04:42:20 +00:00
|
|
|
{
|
|
|
|
return mTimeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
SetTimeout(uint32_t aTimeout, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
bool
|
2012-09-11 19:08:24 +00:00
|
|
|
WithCredentials() const
|
2012-03-31 04:42:20 +00:00
|
|
|
{
|
|
|
|
return mWithCredentials;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
SetWithCredentials(bool aWithCredentials, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
bool
|
2012-09-11 19:08:24 +00:00
|
|
|
MozBackgroundRequest() const
|
2012-03-31 04:42:20 +00:00
|
|
|
{
|
|
|
|
return mBackgroundRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
SetMozBackgroundRequest(bool aBackgroundRequest, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
XMLHttpRequestUpload*
|
2012-05-06 01:15:11 +00:00
|
|
|
GetUpload(ErrorResult& aRv);
|
2008-11-27 06:16:40 +00:00
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
Send(ErrorResult& aRv);
|
2011-07-17 19:09:13 +00:00
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
Send(const nsAString& aBody, ErrorResult& aRv);
|
2011-07-17 19:09:13 +00:00
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
Send(JSObject* aBody, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
2012-12-11 18:09:56 +00:00
|
|
|
void
|
|
|
|
Send(JSObject& aBody, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Send(&aBody, aRv);
|
|
|
|
}
|
|
|
|
|
2012-05-25 05:07:03 +00:00
|
|
|
void
|
|
|
|
Send(ArrayBuffer& aBody, ErrorResult& aRv) {
|
2012-08-01 03:45:20 +00:00
|
|
|
return Send(aBody.Obj(), aRv);
|
2012-05-25 05:07:03 +00:00
|
|
|
}
|
|
|
|
|
2012-12-20 01:47:39 +00:00
|
|
|
void
|
|
|
|
Send(ArrayBufferView& aBody, ErrorResult& aRv) {
|
|
|
|
return Send(aBody.Obj(), aRv);
|
|
|
|
}
|
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
SendAsBinary(const nsAString& aBody, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
Abort(ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
uint16_t
|
2012-05-06 01:15:11 +00:00
|
|
|
GetStatus(ErrorResult& aRv) const
|
2012-03-31 04:42:20 +00: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 01:15:11 +00:00
|
|
|
ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
GetAllResponseHeaders(nsAString& aResponseHeaders, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
XMLHttpRequestResponseType
|
2012-09-11 19:08:24 +00:00
|
|
|
ResponseType() const
|
2012-03-31 04:42:20 +00:00
|
|
|
{
|
|
|
|
return mResponseType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
SetResponseType(XMLHttpRequestResponseType aResponseType, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
jsval
|
2012-05-31 18:16:48 +00:00
|
|
|
GetResponse(JSContext* /* unused */, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
GetResponseText(nsAString& aResponseText, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
JSObject*
|
2012-05-06 01:15:11 +00:00
|
|
|
GetResponseXML() const
|
2012-03-31 04:42:20 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2012-05-06 01:15:11 +00:00
|
|
|
GetChannel() const
|
2012-03-31 04:42:20 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value
|
2013-05-03 23:29:07 +00:00
|
|
|
GetInterface(JSContext* cx, JSObject& aIID, ErrorResult& aRv)
|
2012-03-31 04:42:20 +00:00
|
|
|
{
|
2012-05-06 01:15:11 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2012-03-31 04:42:20 +00: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-17 00:20:16 +00:00
|
|
|
bool MozAnon() const
|
|
|
|
{
|
|
|
|
return mMozAnon;
|
2012-06-10 23:44:50 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 00:20:16 +00:00
|
|
|
bool MozSystem() const
|
|
|
|
{
|
|
|
|
return mMozSystem;
|
2012-06-10 23:44:50 +00:00
|
|
|
}
|
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
private:
|
|
|
|
enum ReleaseType { Default, XHRIsGoingAway, WorkerIsGoingAway };
|
|
|
|
|
|
|
|
void
|
|
|
|
ReleaseProxy(ReleaseType aType = Default);
|
|
|
|
|
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
MaybePin(ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
void
|
2012-05-06 01:15:11 +00:00
|
|
|
MaybeDispatchPrematureAbortEvents(ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
void
|
2013-05-09 07:27:40 +00:00
|
|
|
DispatchPrematureAbortEvent(JS::Handle<JSObject*> aTarget, uint8_t aEventType,
|
2012-05-06 01:15:11 +00:00
|
|
|
bool aUploadTarget, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
SendInProgress() const
|
|
|
|
{
|
|
|
|
return mJSObjectRooted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SendInternal(const nsAString& aStringBody,
|
|
|
|
JSAutoStructuredCloneBuffer& aBody,
|
|
|
|
nsTArray<nsCOMPtr<nsISupports> >& aClonedObjects,
|
2012-05-06 01:15:11 +00:00
|
|
|
ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
};
|
2012-01-18 18:05:38 +00:00
|
|
|
|
2011-07-17 19:09:13 +00:00
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
#endif // mozilla_dom_workers_xmlhttprequest_h__
|