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 "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;
|
2017-01-19 06:20:15 +03:00
|
|
|
class DOMString;
|
2018-06-18 23:37:21 +03:00
|
|
|
class SendRunnable;
|
|
|
|
class StrongWorkerRef;
|
2018-03-21 12:17:20 +03:00
|
|
|
class WorkerPrivate;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2018-06-18 23:37:21 +03:00
|
|
|
class XMLHttpRequestWorker final : public XMLHttpRequest {
|
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) {}
|
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;
|
2018-03-21 12:17:20 +03:00
|
|
|
WorkerPrivate* mWorkerPrivate;
|
2018-06-18 23:37:21 +03:00
|
|
|
RefPtr<StrongWorkerRef> mWorkerRef;
|
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;
|
|
|
|
|
|
|
|
bool mBackgroundRequest;
|
|
|
|
bool mWithCredentials;
|
|
|
|
bool mCanceled;
|
|
|
|
|
2012-09-17 04:20:16 +04:00
|
|
|
bool mMozAnon;
|
|
|
|
bool mMozSystem;
|
|
|
|
|
2019-04-18 09:15:17 +03:00
|
|
|
nsString mMimeTypeOverride;
|
|
|
|
|
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
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
static already_AddRefed<XMLHttpRequest> Construct(
|
|
|
|
const GlobalObject& aGlobal, const MozXMLHttpRequestParameters& aParams,
|
|
|
|
ErrorResult& aRv);
|
2013-11-05 18:16:26 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
void Unpin();
|
2012-09-07 19:07:12 +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
|
|
|
|
2013-06-13 09:20:10 +04:00
|
|
|
virtual void Open(const nsACString& aMethod, const nsAString& aUrl,
|
2016-09-12 16:48:30 +03:00
|
|
|
bool aAsync, 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
|
|
|
|
2013-06-13 09:20:10 +04:00
|
|
|
virtual void 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 { return mTimeout; }
|
2012-03-31 08:42:20 +04:00
|
|
|
|
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 { return mWithCredentials; }
|
2012-03-31 08:42:20 +04:00
|
|
|
|
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 XMLHttpRequestUpload* GetUpload(ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual void Send(
|
2017-08-25 16:30:33 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-13 09:20:10 +04:00
|
|
|
virtual void 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
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
virtual void 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
|
|
|
|
2017-01-19 06:20:15 +03:00
|
|
|
virtual void GetResponseText(DOMString& aResponseText,
|
|
|
|
ErrorResult& aRv) override;
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
virtual Document* GetResponseXML(ErrorResult& aRv) override {
|
2016-06-27 20:13:41 +03:00
|
|
|
MOZ_CRASH("This method should not be called.");
|
|
|
|
}
|
|
|
|
|
2018-07-18 07:30:38 +03:00
|
|
|
virtual void GetInterface(JSContext* aCx, JS::Handle<JS::Value> aIID,
|
2016-06-27 20:13:41 +03:00
|
|
|
JS::MutableHandle<JS::Value> aRetval,
|
|
|
|
ErrorResult& aRv) override {
|
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.");
|
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
XMLHttpRequestUpload* GetUploadObjectNoCreate() const { return mUpload; }
|
|
|
|
|
2018-03-21 12:17:20 +03:00
|
|
|
void 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 { return mMozAnon; }
|
2012-06-11 03:44:50 +04:00
|
|
|
|
2016-06-27 20:13:41 +03:00
|
|
|
virtual bool MozSystem() const override { return mMozSystem; }
|
2012-06-11 03:44:50 +04:00
|
|
|
|
2014-06-06 15:12:15 +04:00
|
|
|
bool SendInProgress() const { return !!mWorkerRef; }
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
private:
|
2018-03-21 12:17:20 +03:00
|
|
|
explicit XMLHttpRequestWorker(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);
|
|
|
|
|
2018-03-21 12:17:20 +03:00
|
|
|
void MaybePin(ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-05-06 05:15:11 +04:00
|
|
|
void MaybeDispatchPrematureAbortEvents(ErrorResult& aRv);
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2018-03-21 12:17:20 +03:00
|
|
|
void DispatchPrematureAbortEvent(EventTarget* aTarget,
|
2013-11-05 18:16:26 +04:00
|
|
|
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);
|
|
|
|
|
2015-08-27 19:19:13 +03:00
|
|
|
void SendInternal(SendRunnable* aRunnable, 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
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
#endif // mozilla_dom_workers_xmlhttprequest_h__
|