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/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-05-25 05:07:03 +00:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
|
2013-08-20 06:43:47 +00:00
|
|
|
#include "js/StructuredClone.h"
|
2013-11-05 14:16:26 +00:00
|
|
|
#include "nsXMLHttpRequest.h"
|
2013-08-20 06:43:47 +00:00
|
|
|
|
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
|
|
|
|
2013-10-23 13:16:49 +00:00
|
|
|
class XMLHttpRequest MOZ_FINAL: public nsXHREventTarget,
|
|
|
|
public WorkerFeature
|
2008-11-27 06:16:40 +00:00
|
|
|
{
|
2012-03-31 04:42:20 +00:00
|
|
|
public:
|
|
|
|
struct StateData
|
|
|
|
{
|
|
|
|
nsString mResponseText;
|
2014-05-17 00:24:37 +00:00
|
|
|
nsString mResponseURL;
|
2012-03-31 04:42:20 +00:00
|
|
|
uint32_t mStatus;
|
2013-06-13 05:20:10 +00:00
|
|
|
nsCString mStatusText;
|
2012-03-31 04:42:20 +00:00
|
|
|
uint16_t mReadyState;
|
2013-07-23 09:58:27 +00:00
|
|
|
JS::Heap<JS::Value> mResponse;
|
2012-03-31 04:42:20 +00:00
|
|
|
nsresult mResponseTextResult;
|
|
|
|
nsresult mStatusResult;
|
|
|
|
nsresult mResponseResult;
|
|
|
|
|
|
|
|
StateData()
|
|
|
|
: mStatus(0), mReadyState(0), mResponse(JSVAL_VOID),
|
|
|
|
mResponseTextResult(NS_OK), mStatusResult(NS_OK),
|
|
|
|
mResponseResult(NS_OK)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2013-11-05 14:16:26 +00:00
|
|
|
nsRefPtr<XMLHttpRequestUpload> mUpload;
|
2012-03-31 04:42:20 +00:00
|
|
|
WorkerPrivate* mWorkerPrivate;
|
|
|
|
nsRefPtr<Proxy> mProxy;
|
|
|
|
XMLHttpRequestResponseType mResponseType;
|
|
|
|
StateData mStateData;
|
|
|
|
|
|
|
|
uint32_t mTimeout;
|
|
|
|
|
2013-11-05 14:16:26 +00:00
|
|
|
bool mRooted;
|
2012-03-31 04:42:20 +00:00
|
|
|
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
|
|
|
public:
|
2013-11-05 14:16:26 +00:00
|
|
|
virtual JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2012-03-31 04:42:20 +00:00
|
|
|
|
2013-11-05 14:16:26 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(XMLHttpRequest,
|
|
|
|
nsXHREventTarget)
|
2012-03-31 04:42:20 +00:00
|
|
|
|
2013-11-05 14:16:26 +00:00
|
|
|
nsISupports*
|
|
|
|
GetParentObject() const
|
|
|
|
{
|
|
|
|
// There's only one global on a worker, so we don't need to specify.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<XMLHttpRequest>
|
2013-08-23 05:17:08 +00:00
|
|
|
Constructor(const GlobalObject& aGlobal,
|
2013-08-23 05:17:09 +00:00
|
|
|
const MozXMLHttpRequestParameters& aParams,
|
2012-06-21 07:21:55 +00:00
|
|
|
ErrorResult& aRv);
|
2012-09-07 15:07:12 +00:00
|
|
|
|
2013-11-05 14:16:26 +00:00
|
|
|
static already_AddRefed<XMLHttpRequest>
|
2013-08-23 05:17:08 +00:00
|
|
|
Constructor(const GlobalObject& aGlobal, const nsAString& ignored,
|
2012-12-03 16:07:49 +00:00
|
|
|
ErrorResult& aRv)
|
2012-09-07 15:07:12 +00:00
|
|
|
{
|
|
|
|
// Pretend like someone passed null, so we can pick up the default values
|
2013-08-23 05:17:09 +00:00
|
|
|
MozXMLHttpRequestParameters params;
|
2014-06-16 18:08:00 +00:00
|
|
|
if (!params.Init(aGlobal.Context(), 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;
|
|
|
|
|
2013-11-05 14:16:26 +00:00
|
|
|
IMPL_EVENT_HANDLER(readystatechange)
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
uint16_t
|
2012-09-11 19:08:24 +00:00
|
|
|
ReadyState() const
|
2012-03-31 04:42:20 +00:00
|
|
|
{
|
|
|
|
return mStateData.mReadyState;
|
|
|
|
}
|
|
|
|
|
2013-10-11 16:28:24 +00:00
|
|
|
void Open(const nsACString& aMethod, const nsAString& aUrl, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Open(aMethod, aUrl, true, Optional<nsAString>(),
|
|
|
|
Optional<nsAString>(), aRv);
|
|
|
|
}
|
2012-03-31 04:42:20 +00:00
|
|
|
void
|
2013-06-13 05:20:10 +00:00
|
|
|
Open(const nsACString& 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
|
2013-06-13 05:20:10 +00:00
|
|
|
SetRequestHeader(const nsACString& aHeader, const nsACString& 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
|
2013-12-20 19:28:18 +00:00
|
|
|
Send(JS::Handle<JSObject*> aBody, ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
2012-12-11 18:09:56 +00:00
|
|
|
void
|
2013-12-20 19:28:18 +00:00
|
|
|
Send(const ArrayBuffer& aBody, ErrorResult& aRv);
|
2012-05-25 05:07:03 +00:00
|
|
|
|
2012-12-20 01:47:39 +00:00
|
|
|
void
|
2013-12-20 19:28:18 +00:00
|
|
|
Send(const ArrayBufferView& aBody, ErrorResult& aRv);
|
2012-12-20 01:47:39 +00:00
|
|
|
|
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
|
|
|
|
2014-05-17 00:24:37 +00:00
|
|
|
void
|
|
|
|
GetResponseURL(nsAString& aUrl) const
|
|
|
|
{
|
|
|
|
aUrl = mStateData.mResponseURL;
|
|
|
|
}
|
|
|
|
|
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
|
2013-06-13 05:20:10 +00:00
|
|
|
GetStatusText(nsACString& aStatusText) const
|
2012-03-31 04:42:20 +00:00
|
|
|
{
|
|
|
|
aStatusText = mStateData.mStatusText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-13 05:20:10 +00:00
|
|
|
GetResponseHeader(const nsACString& aHeader, nsACString& aResponseHeader,
|
2012-05-06 01:15:11 +00:00
|
|
|
ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
void
|
2013-06-13 05:20:10 +00:00
|
|
|
GetAllResponseHeaders(nsACString& 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
|
|
|
|
2014-06-11 20:26:52 +00:00
|
|
|
void
|
|
|
|
GetResponse(JSContext* /* unused */, JS::MutableHandle<JS::Value> aResponse,
|
|
|
|
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
|
|
|
|
2014-06-11 20:26:52 +00:00
|
|
|
void
|
|
|
|
GetInterface(JSContext* cx, JS::Handle<JSObject*> aIID,
|
|
|
|
JS::MutableHandle<JS::Value> aRetval, 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
|
|
|
}
|
|
|
|
|
|
|
|
XMLHttpRequestUpload*
|
|
|
|
GetUploadObjectNoCreate() const
|
|
|
|
{
|
|
|
|
return mUpload;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-06 11:17:57 +00:00
|
|
|
UpdateState(const StateData& aStateData, bool aUseCachedArrayBufferResponse);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-06-06 11:12:15 +00:00
|
|
|
bool
|
|
|
|
SendInProgress() const
|
|
|
|
{
|
|
|
|
return mRooted;
|
|
|
|
}
|
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
private:
|
2013-10-23 13:16:49 +00:00
|
|
|
XMLHttpRequest(WorkerPrivate* aWorkerPrivate);
|
|
|
|
~XMLHttpRequest();
|
|
|
|
|
2012-03-31 04:42:20 +00:00
|
|
|
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-11-05 14:16:26 +00:00
|
|
|
DispatchPrematureAbortEvent(EventTarget* aTarget,
|
|
|
|
const nsAString& aEventType, bool aUploadTarget,
|
|
|
|
ErrorResult& aRv);
|
2012-03-31 04:42:20 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SendInternal(const nsAString& aStringBody,
|
2014-02-01 02:50:07 +00:00
|
|
|
JSAutoStructuredCloneBuffer&& aBody,
|
2012-03-31 04:42:20 +00:00
|
|
|
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__
|