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/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-05-24 22:07:03 -07:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
|
2013-08-19 23:43:47 -07:00
|
|
|
#include "js/StructuredClone.h"
|
2013-11-05 06:16:26 -08:00
|
|
|
#include "nsXMLHttpRequest.h"
|
2013-08-19 23:43:47 -07:00
|
|
|
|
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
|
|
|
|
2013-10-23 06:16:49 -07:00
|
|
|
class XMLHttpRequest MOZ_FINAL: public nsXHREventTarget,
|
|
|
|
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;
|
2013-06-12 22:20:10 -07:00
|
|
|
nsCString mStatusText;
|
2012-03-30 21:42:20 -07:00
|
|
|
uint16_t mReadyState;
|
2013-07-23 02:58:27 -07:00
|
|
|
JS::Heap<JS::Value> mResponse;
|
2012-03-30 21:42:20 -07: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 06:16:26 -08:00
|
|
|
nsRefPtr<XMLHttpRequestUpload> mUpload;
|
2012-03-30 21:42:20 -07:00
|
|
|
WorkerPrivate* mWorkerPrivate;
|
|
|
|
nsRefPtr<Proxy> mProxy;
|
|
|
|
XMLHttpRequestResponseType mResponseType;
|
|
|
|
StateData mStateData;
|
|
|
|
|
|
|
|
uint32_t mTimeout;
|
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
bool mRooted;
|
2012-03-30 21:42:20 -07:00
|
|
|
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
|
|
|
public:
|
2013-11-05 06:16:26 -08:00
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(XMLHttpRequest,
|
|
|
|
nsXHREventTarget)
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2013-11-05 06:16:26 -08: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-22 22:17:08 -07:00
|
|
|
Constructor(const GlobalObject& aGlobal,
|
2013-08-22 22:17:09 -07:00
|
|
|
const MozXMLHttpRequestParameters& aParams,
|
2012-06-21 00:21:55 -07:00
|
|
|
ErrorResult& aRv);
|
2012-09-07 08:07:12 -07:00
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
static already_AddRefed<XMLHttpRequest>
|
2013-08-22 22:17:08 -07:00
|
|
|
Constructor(const GlobalObject& aGlobal, const nsAString& ignored,
|
2012-12-03 08:07:49 -08:00
|
|
|
ErrorResult& aRv)
|
2012-09-07 08:07:12 -07:00
|
|
|
{
|
|
|
|
// Pretend like someone passed null, so we can pick up the default values
|
2013-08-22 22:17:09 -07:00
|
|
|
MozXMLHttpRequestParameters params;
|
2013-05-03 16:29:08 -07:00
|
|
|
if (!params.Init(aGlobal.GetContext(), JS::NullHandleValue)) {
|
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;
|
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
IMPL_EVENT_HANDLER(readystatechange)
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
uint16_t
|
2012-09-11 12:08:24 -07:00
|
|
|
ReadyState() const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
return mStateData.mReadyState;
|
|
|
|
}
|
|
|
|
|
2013-10-11 09:28:24 -07:00
|
|
|
void Open(const nsACString& aMethod, const nsAString& aUrl, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Open(aMethod, aUrl, true, Optional<nsAString>(),
|
|
|
|
Optional<nsAString>(), aRv);
|
|
|
|
}
|
2012-03-30 21:42:20 -07:00
|
|
|
void
|
2013-06-12 22:20:10 -07:00
|
|
|
Open(const nsACString& 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
|
2013-06-12 22:20:10 -07:00
|
|
|
SetRequestHeader(const nsACString& aHeader, const nsACString& 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
|
|
|
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
|
2013-12-20 11:28:18 -08:00
|
|
|
Send(JS::Handle<JSObject*> aBody, ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
void
|
2013-12-20 11:28:18 -08:00
|
|
|
Send(const ArrayBuffer& aBody, ErrorResult& aRv);
|
2012-05-24 22:07:03 -07:00
|
|
|
|
2012-12-19 17:47:39 -08:00
|
|
|
void
|
2013-12-20 11:28:18 -08:00
|
|
|
Send(const ArrayBufferView& aBody, ErrorResult& aRv);
|
2012-12-19 17:47:39 -08:00
|
|
|
|
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
|
2013-06-12 22:20:10 -07:00
|
|
|
GetStatusText(nsACString& aStatusText) const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
|
|
|
aStatusText = mStateData.mStatusText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-12 22:20:10 -07:00
|
|
|
GetResponseHeader(const nsACString& aHeader, nsACString& aResponseHeader,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
void
|
2013-06-12 22:20:10 -07:00
|
|
|
GetAllResponseHeaders(nsACString& 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
|
|
|
{
|
2013-10-28 07:04:47 -07:00
|
|
|
return nullptr;
|
2012-03-30 21:42:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2012-05-05 18:15:11 -07:00
|
|
|
GetChannel() const
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
2013-10-28 07:04:47 -07:00
|
|
|
return nullptr;
|
2012-03-30 21:42:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value
|
2013-05-16 09:36:55 -07:00
|
|
|
GetInterface(JSContext* cx, JS::Handle<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
|
2013-11-05 06:16:26 -08:00
|
|
|
UpdateState(const StateData& aStateData);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
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:
|
2013-10-23 06:16:49 -07:00
|
|
|
XMLHttpRequest(WorkerPrivate* aWorkerPrivate);
|
|
|
|
~XMLHttpRequest();
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
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
|
2013-11-05 06:16:26 -08:00
|
|
|
DispatchPrematureAbortEvent(EventTarget* aTarget,
|
|
|
|
const nsAString& aEventType, bool aUploadTarget,
|
|
|
|
ErrorResult& aRv);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
SendInProgress() const
|
|
|
|
{
|
2013-11-05 06:16:26 -08:00
|
|
|
return mRooted;
|
2012-03-30 21:42:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SendInternal(const nsAString& aStringBody,
|
2014-01-31 18:50:07 -08:00
|
|
|
JSAutoStructuredCloneBuffer&& aBody,
|
2012-03-30 21:42:20 -07:00
|
|
|
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__
|