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/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
|
|
|
|
2012-05-25 09:07:03 +04:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
|
2013-08-20 10:43:47 +04:00
|
|
|
#include "js/StructuredClone.h"
|
2013-11-05 18:16:26 +04:00
|
|
|
#include "nsXMLHttpRequest.h"
|
2013-08-20 10:43:47 +04:00
|
|
|
|
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
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
class XMLHttpRequest MOZ_FINAL: public nsXHREventTarget,
|
|
|
|
public WorkerFeature
|
2008-11-27 09:16:40 +03:00
|
|
|
{
|
2012-03-31 08:42:20 +04:00
|
|
|
public:
|
|
|
|
struct StateData
|
|
|
|
{
|
|
|
|
nsString mResponseText;
|
2014-05-17 04:24:37 +04:00
|
|
|
nsString mResponseURL;
|
2012-03-31 08:42:20 +04:00
|
|
|
uint32_t mStatus;
|
2013-06-13 09:20:10 +04:00
|
|
|
nsCString mStatusText;
|
2012-03-31 08:42:20 +04:00
|
|
|
uint16_t mReadyState;
|
2013-07-23 13:58:27 +04:00
|
|
|
JS::Heap<JS::Value> mResponse;
|
2012-03-31 08:42:20 +04: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 18:16:26 +04:00
|
|
|
nsRefPtr<XMLHttpRequestUpload> mUpload;
|
2012-03-31 08:42:20 +04:00
|
|
|
WorkerPrivate* mWorkerPrivate;
|
|
|
|
nsRefPtr<Proxy> mProxy;
|
|
|
|
XMLHttpRequestResponseType mResponseType;
|
|
|
|
StateData mStateData;
|
|
|
|
|
|
|
|
uint32_t mTimeout;
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
bool mRooted;
|
2012-03-31 08:42:20 +04:00
|
|
|
bool mBackgroundRequest;
|
|
|
|
bool mWithCredentials;
|
|
|
|
bool mCanceled;
|
|
|
|
|
2012-09-17 04:20:16 +04:00
|
|
|
bool mMozAnon;
|
|
|
|
bool mMozSystem;
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
public:
|
2013-11-05 18:16:26 +04:00
|
|
|
virtual JSObject*
|
2014-04-09 02:27:18 +04:00
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(XMLHttpRequest,
|
|
|
|
nsXHREventTarget)
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2013-11-05 18:16:26 +04: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 09:17:08 +04:00
|
|
|
Constructor(const GlobalObject& aGlobal,
|
2013-08-23 09:17:09 +04:00
|
|
|
const MozXMLHttpRequestParameters& aParams,
|
2012-06-21 11:21:55 +04:00
|
|
|
ErrorResult& aRv);
|
2012-09-07 19:07:12 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
static already_AddRefed<XMLHttpRequest>
|
2013-08-23 09:17:08 +04:00
|
|
|
Constructor(const GlobalObject& aGlobal, const nsAString& ignored,
|
2012-12-03 20:07:49 +04:00
|
|
|
ErrorResult& aRv)
|
2012-09-07 19:07:12 +04:00
|
|
|
{
|
|
|
|
// Pretend like someone passed null, so we can pick up the default values
|
2013-08-23 09:17:09 +04:00
|
|
|
MozXMLHttpRequestParameters params;
|
2013-05-04 03:29:08 +04:00
|
|
|
if (!params.Init(aGlobal.GetContext(), JS::NullHandleValue)) {
|
2012-09-07 19:07:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-12-03 20:07:49 +04:00
|
|
|
return Constructor(aGlobal, params, aRv);
|
2012-09-07 19:07:12 +04:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
|
|
|
Unpin();
|
|
|
|
|
|
|
|
bool
|
|
|
|
Notify(JSContext* aCx, Status aStatus) MOZ_OVERRIDE;
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
IMPL_EVENT_HANDLER(readystatechange)
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
uint16_t
|
2012-09-11 23:08:24 +04:00
|
|
|
ReadyState() const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mStateData.mReadyState;
|
|
|
|
}
|
|
|
|
|
2013-10-11 20:28:24 +04:00
|
|
|
void Open(const nsACString& aMethod, const nsAString& aUrl, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Open(aMethod, aUrl, true, Optional<nsAString>(),
|
|
|
|
Optional<nsAString>(), aRv);
|
|
|
|
}
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2013-06-13 09:20:10 +04:00
|
|
|
Open(const nsACString& aMethod, const nsAString& aUrl, bool aAsync,
|
2012-05-30 07:45:18 +04:00
|
|
|
const Optional<nsAString>& aUser, const Optional<nsAString>& aPassword,
|
|
|
|
ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2013-06-13 09:20:10 +04:00
|
|
|
SetRequestHeader(const nsACString& aHeader, const nsACString& aValue,
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
uint32_t
|
2012-09-11 23:08:24 +04:00
|
|
|
Timeout() const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mTimeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
SetTimeout(uint32_t aTimeout, ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
bool
|
2012-09-11 23:08:24 +04:00
|
|
|
WithCredentials() const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mWithCredentials;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
SetWithCredentials(bool aWithCredentials, ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
bool
|
2012-09-11 23:08:24 +04:00
|
|
|
MozBackgroundRequest() const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mBackgroundRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
SetMozBackgroundRequest(bool aBackgroundRequest, ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
XMLHttpRequestUpload*
|
2012-05-06 05:15:11 +04:00
|
|
|
GetUpload(ErrorResult& aRv);
|
2008-11-27 09:16:40 +03:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
Send(ErrorResult& aRv);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
Send(const nsAString& aBody, ErrorResult& aRv);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2013-12-20 23:28:18 +04:00
|
|
|
Send(JS::Handle<JSObject*> aBody, ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-12-11 22:09:56 +04:00
|
|
|
void
|
2013-12-20 23:28:18 +04:00
|
|
|
Send(const ArrayBuffer& aBody, ErrorResult& aRv);
|
2012-05-25 09:07:03 +04:00
|
|
|
|
2012-12-20 05:47:39 +04:00
|
|
|
void
|
2013-12-20 23:28:18 +04:00
|
|
|
Send(const ArrayBufferView& aBody, ErrorResult& aRv);
|
2012-12-20 05:47:39 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
SendAsBinary(const nsAString& aBody, ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
Abort(ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2014-05-17 04:24:37 +04:00
|
|
|
void
|
|
|
|
GetResponseURL(nsAString& aUrl) const
|
|
|
|
{
|
|
|
|
aUrl = mStateData.mResponseURL;
|
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
uint16_t
|
2012-05-06 05:15:11 +04:00
|
|
|
GetStatus(ErrorResult& aRv) const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
aRv = mStateData.mStatusResult;
|
|
|
|
return mStateData.mStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-13 09:20:10 +04:00
|
|
|
GetStatusText(nsACString& aStatusText) const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
aStatusText = mStateData.mStatusText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-13 09:20:10 +04:00
|
|
|
GetResponseHeader(const nsACString& aHeader, nsACString& aResponseHeader,
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2013-06-13 09:20:10 +04:00
|
|
|
GetAllResponseHeaders(nsACString& aResponseHeaders, ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
XMLHttpRequestResponseType
|
2012-09-11 23:08:24 +04:00
|
|
|
ResponseType() const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mResponseType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
SetResponseType(XMLHttpRequestResponseType aResponseType, ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void
|
|
|
|
GetResponse(JSContext* /* unused */, JS::MutableHandle<JS::Value> aResponse,
|
|
|
|
ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
GetResponseText(nsAString& aResponseText, ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
JSObject*
|
2012-05-06 05:15:11 +04:00
|
|
|
GetResponseXML() const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
2013-10-28 18:04:47 +04:00
|
|
|
return nullptr;
|
2012-03-31 08:42:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2012-05-06 05:15:11 +04:00
|
|
|
GetChannel() const
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
2013-10-28 18:04:47 +04:00
|
|
|
return nullptr;
|
2012-03-31 08:42:20 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void
|
|
|
|
GetInterface(JSContext* cx, JS::Handle<JSObject*> aIID,
|
|
|
|
JS::MutableHandle<JS::Value> aRetval, ErrorResult& aRv)
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
2012-05-06 05:15:11 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2012-03-31 08:42:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
XMLHttpRequestUpload*
|
|
|
|
GetUploadObjectNoCreate() const
|
|
|
|
{
|
|
|
|
return mUpload;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-06 15:17:57 +04:00
|
|
|
UpdateState(const StateData& aStateData, bool aUseCachedArrayBufferResponse);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
NullResponseText()
|
|
|
|
{
|
|
|
|
mStateData.mResponseText.SetIsVoid(true);
|
|
|
|
mStateData.mResponse = JSVAL_NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-17 04:20:16 +04:00
|
|
|
bool MozAnon() const
|
|
|
|
{
|
|
|
|
return mMozAnon;
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
|
|
|
|
2012-09-17 04:20:16 +04:00
|
|
|
bool MozSystem() const
|
|
|
|
{
|
|
|
|
return mMozSystem;
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
|
|
|
|
2014-06-06 15:12:15 +04:00
|
|
|
bool
|
|
|
|
SendInProgress() const
|
|
|
|
{
|
|
|
|
return mRooted;
|
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
private:
|
2013-10-23 17:16:49 +04:00
|
|
|
XMLHttpRequest(WorkerPrivate* aWorkerPrivate);
|
|
|
|
~XMLHttpRequest();
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
enum ReleaseType { Default, XHRIsGoingAway, WorkerIsGoingAway };
|
|
|
|
|
|
|
|
void
|
|
|
|
ReleaseProxy(ReleaseType aType = Default);
|
|
|
|
|
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
MaybePin(ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2012-05-06 05:15:11 +04:00
|
|
|
MaybeDispatchPrematureAbortEvents(ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
2013-11-05 18:16:26 +04:00
|
|
|
DispatchPrematureAbortEvent(EventTarget* aTarget,
|
|
|
|
const nsAString& aEventType, bool aUploadTarget,
|
|
|
|
ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
SendInternal(const nsAString& aStringBody,
|
2014-02-01 06:50:07 +04:00
|
|
|
JSAutoStructuredCloneBuffer&& aBody,
|
2012-03-31 08:42:20 +04:00
|
|
|
nsTArray<nsCOMPtr<nsISupports> >& aClonedObjects,
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult& 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__
|