2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
#ifndef mozilla_dom_XMLHttpRequestWorker_h
|
|
|
|
#define mozilla_dom_XMLHttpRequestWorker_h
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
#include "WorkerHolder.h"
|
|
|
|
#include "XMLHttpRequest.h"
|
2016-09-12 10:06:33 +03:00
|
|
|
#include "XMLHttpRequestString.h"
|
2012-05-25 09:07:03 +04:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
|
2014-10-08 20:15:22 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
class Proxy;
|
2015-08-27 19:19:13 +03:00
|
|
|
class SendRunnable;
|
2017-01-19 06:20:15 +03:00
|
|
|
class DOMString;
|
2016-06-27 20:13:41 +03:00
|
|
|
|
|
|
|
namespace workers {
|
2012-03-31 08:42:20 +04:00
|
|
|
class WorkerPrivate;
|
2016-06-27 20:13:41 +03:00
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
class XMLHttpRequestWorker final : public XMLHttpRequest,
|
2016-06-27 20:25:11 +03:00
|
|
|
public workers::WorkerHolder
|
2008-11-27 09:16:40 +03:00
|
|
|
{
|
2012-03-31 08:42:20 +04:00
|
|
|
public:
|
|
|
|
struct StateData
|
|
|
|
{
|
2016-09-12 10:06:33 +03:00
|
|
|
XMLHttpRequestStringSnapshot 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;
|
2016-11-21 09:30:00 +03:00
|
|
|
bool mFlagSend;
|
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()
|
2016-11-21 09:30:00 +03:00
|
|
|
: mStatus(0), mReadyState(0), mFlagSend(false),
|
|
|
|
mResponse(JS::UndefinedValue()), mResponseTextResult(NS_OK),
|
|
|
|
mStatusResult(NS_OK), mResponseResult(NS_OK)
|
2012-03-31 08:42:20 +04:00
|
|
|
{ }
|
2016-02-27 05:16:17 +03:00
|
|
|
|
|
|
|
void trace(JSTracer* trc);
|
2012-03-31 08:42:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2016-06-27 20:13:41 +03:00
|
|
|
RefPtr<XMLHttpRequestUpload> mUpload;
|
2016-06-27 20:13:41 +03:00
|
|
|
workers::WorkerPrivate* mWorkerPrivate;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Proxy> mProxy;
|
2012-03-31 08:42:20 +04:00
|
|
|
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
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2016-06-27 20:13:40 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(XMLHttpRequestWorker,
|
2016-06-27 20:13:41 +03:00
|
|
|
XMLHttpRequest)
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
static already_AddRefed<XMLHttpRequest>
|
|
|
|
Construct(const GlobalObject& aGlobal,
|
|
|
|
const MozXMLHttpRequestParameters& aParams,
|
|
|
|
ErrorResult& aRv);
|
2012-09-07 19:07:12 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
|
|
|
Unpin();
|
|
|
|
|
|
|
|
bool
|
2016-06-27 20:13:41 +03:00
|
|
|
Notify(workers::Status aStatus) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual uint16_t
|
|
|
|
ReadyState() const override
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mStateData.mReadyState;
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
Open(const nsACString& aMethod, const nsAString& aUrl,
|
|
|
|
ErrorResult& aRv) override
|
2013-10-11 20:28:24 +04:00
|
|
|
{
|
|
|
|
Open(aMethod, aUrl, true, Optional<nsAString>(),
|
|
|
|
Optional<nsAString>(), aRv);
|
|
|
|
}
|
2016-06-27 20:13:41 +03:00
|
|
|
|
|
|
|
virtual void
|
2013-06-13 09:20:10 +04:00
|
|
|
Open(const nsACString& aMethod, const nsAString& aUrl, bool aAsync,
|
2016-09-12 16:48:30 +03:00
|
|
|
const nsAString& aUsername, const nsAString& aPassword,
|
|
|
|
ErrorResult& aRv) override
|
|
|
|
{
|
|
|
|
Optional<nsAString> username;
|
|
|
|
username = &aUsername;
|
|
|
|
Optional<nsAString> password;
|
|
|
|
password = &aPassword;
|
|
|
|
Open(aMethod, aUrl, aAsync, username, password, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Open(const nsACString& aMethod, const nsAString& aUrl,
|
|
|
|
bool aAsync, const Optional<nsAString>& aUser,
|
|
|
|
const Optional<nsAString>& aPassword, ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
2013-06-13 09:20:10 +04:00
|
|
|
SetRequestHeader(const nsACString& aHeader, const nsACString& aValue,
|
2016-06-27 20:13:41 +03:00
|
|
|
ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual uint32_t
|
|
|
|
Timeout() const override
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mTimeout;
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
SetTimeout(uint32_t aTimeout, ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual bool
|
|
|
|
WithCredentials() const override
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mWithCredentials;
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
SetWithCredentials(bool aWithCredentials, ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual bool
|
|
|
|
MozBackgroundRequest() const override
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mBackgroundRequest;
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
SetMozBackgroundRequest(bool aBackgroundRequest, ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual nsIChannel*
|
|
|
|
GetChannel() const override
|
|
|
|
{
|
|
|
|
MOZ_CRASH("This method cannot be called on workers.");
|
|
|
|
}
|
2008-11-27 09:16:40 +03:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
GetNetworkInterfaceId(nsACString& aId) const override
|
|
|
|
{
|
|
|
|
MOZ_CRASH("This method cannot be called on workers.");
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
SetNetworkInterfaceId(const nsACString& aId) override
|
|
|
|
{
|
|
|
|
MOZ_CRASH("This method cannot be called on workers.");
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual XMLHttpRequestUpload*
|
|
|
|
GetUpload(ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
2017-08-25 16:30:33 +03:00
|
|
|
Send(JSContext* aCx,
|
|
|
|
const Nullable<DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString>& aData,
|
|
|
|
ErrorResult& aRv) override;
|
2016-06-27 20:13:41 +03:00
|
|
|
|
2017-08-25 16:31:15 +03:00
|
|
|
virtual void
|
|
|
|
SendInputStream(nsIInputStream* aInputStream, ErrorResult& aRv) override
|
|
|
|
{
|
|
|
|
MOZ_CRASH("nsIInputStream is not a valid argument for XHR in workers.");
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
Abort(ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
GetResponseURL(nsAString& aUrl) override
|
2014-05-17 04:24:37 +04:00
|
|
|
{
|
|
|
|
aUrl = mStateData.mResponseURL;
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
uint32_t
|
|
|
|
GetStatus(ErrorResult& aRv) override
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
aRv = mStateData.mStatusResult;
|
|
|
|
return mStateData.mStatus;
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
GetStatusText(nsACString& aStatusText, ErrorResult& aRv) override
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
aStatusText = mStateData.mStatusText;
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
2013-06-13 09:20:10 +04:00
|
|
|
GetResponseHeader(const nsACString& aHeader, nsACString& aResponseHeader,
|
2016-06-27 20:13:41 +03:00
|
|
|
ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
GetAllResponseHeaders(nsACString& aResponseHeaders,
|
|
|
|
ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual XMLHttpRequestResponseType
|
|
|
|
ResponseType() const override
|
2012-03-31 08:42:20 +04:00
|
|
|
{
|
|
|
|
return mResponseType;
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
|
|
|
SetResponseType(XMLHttpRequestResponseType aResponseType,
|
|
|
|
ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
2014-06-12 00:26:52 +04:00
|
|
|
GetResponse(JSContext* /* unused */, JS::MutableHandle<JS::Value> aResponse,
|
2016-06-27 20:13:41 +03:00
|
|
|
ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void
|
2017-01-19 06:20:15 +03:00
|
|
|
GetResponseText(DOMString& aResponseText, ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual nsIDocument*
|
|
|
|
GetResponseXML(ErrorResult& aRv) override
|
|
|
|
{
|
|
|
|
MOZ_CRASH("This method should not be called.");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
GetInterface(JSContext* aCx, nsIJSID* aIID,
|
|
|
|
JS::MutableHandle<JS::Value> aRetval,
|
|
|
|
ErrorResult& aRv) override
|
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
|
|
|
}
|
|
|
|
|
2016-07-06 07:06:25 +03:00
|
|
|
virtual void
|
|
|
|
SetOriginAttributes(const mozilla::dom::OriginAttributesDictionary& aAttrs) override
|
|
|
|
{
|
|
|
|
MOZ_CRASH("This method cannot be called on workers.");
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
XMLHttpRequestUpload*
|
2012-03-31 08:42:20 +04:00
|
|
|
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()
|
|
|
|
{
|
2016-09-12 10:06:33 +03:00
|
|
|
mStateData.mResponseText.SetVoid();
|
2015-06-30 04:36:44 +03:00
|
|
|
mStateData.mResponse.setNull();
|
2012-03-31 08:42:20 +04:00
|
|
|
}
|
|
|
|
|
2017-05-24 15:52:15 +03:00
|
|
|
virtual uint16_t ErrorCode() const override
|
|
|
|
{
|
|
|
|
return 0; // eOK
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual bool MozAnon() const override
|
2012-09-17 04:20:16 +04:00
|
|
|
{
|
|
|
|
return mMozAnon;
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual bool MozSystem() const override
|
2012-09-17 04:20:16 +04:00
|
|
|
{
|
|
|
|
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:
|
2016-06-27 20:13:41 +03:00
|
|
|
explicit XMLHttpRequestWorker(workers::WorkerPrivate* aWorkerPrivate);
|
2016-06-27 20:13:40 +03:00
|
|
|
~XMLHttpRequestWorker();
|
2013-10-23 17:16:49 +04:00
|
|
|
|
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
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
void
|
|
|
|
Send(JSContext* aCx, JS::Handle<JSObject*> aBody, ErrorResult& aRv);
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
void
|
2015-08-27 19:19:13 +03:00
|
|
|
SendInternal(SendRunnable* aRunnable,
|
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
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
} // dom namespace
|
|
|
|
} // mozilla namespace
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
#endif // mozilla_dom_workers_xmlhttprequest_h__
|