mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Backed out changeset 0f81334efa0a (bug 1445883) for crashes (bug 1446902). a=backout
This commit is contained in:
parent
5fe3417f0b
commit
144671581e
@ -24,7 +24,6 @@
|
||||
#include "mozilla/dom/URLSearchParams.h"
|
||||
#include "mozilla/dom/WorkerScope.h"
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
#include "mozilla/dom/WorkerRef.h"
|
||||
#include "mozilla/dom/WorkerRunnable.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
@ -242,8 +241,9 @@ class SendRunnable final
|
||||
bool mHasUploadListeners;
|
||||
|
||||
public:
|
||||
SendRunnable(Proxy* aProxy, const nsAString& aStringBody)
|
||||
: WorkerThreadProxySyncRunnable(GetCurrentThreadWorkerPrivate(), aProxy)
|
||||
SendRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
|
||||
const nsAString& aStringBody)
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy)
|
||||
, StructuredCloneHolder(CloningSupported, TransferringNotSupported,
|
||||
StructuredCloneScope::SameProcessDifferentThread)
|
||||
, mStringBody(aStringBody)
|
||||
@ -541,8 +541,8 @@ private:
|
||||
class SyncTeardownRunnable final : public WorkerThreadProxySyncRunnable
|
||||
{
|
||||
public:
|
||||
explicit SyncTeardownRunnable(Proxy* aProxy)
|
||||
: WorkerThreadProxySyncRunnable(GetCurrentThreadWorkerPrivate(), aProxy)
|
||||
SyncTeardownRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy)
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy)
|
||||
{ }
|
||||
|
||||
private:
|
||||
@ -563,8 +563,9 @@ class SetBackgroundRequestRunnable final :
|
||||
bool mValue;
|
||||
|
||||
public:
|
||||
SetBackgroundRequestRunnable(Proxy* aProxy, bool aValue)
|
||||
: WorkerThreadProxySyncRunnable(GetCurrentThreadWorkerPrivate(), aProxy)
|
||||
SetBackgroundRequestRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
|
||||
bool aValue)
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy)
|
||||
, mValue(aValue)
|
||||
{ }
|
||||
|
||||
@ -585,8 +586,9 @@ class SetWithCredentialsRunnable final :
|
||||
bool mValue;
|
||||
|
||||
public:
|
||||
SetWithCredentialsRunnable(Proxy* aProxy, bool aValue)
|
||||
: WorkerThreadProxySyncRunnable(GetCurrentThreadWorkerPrivate(), aProxy)
|
||||
SetWithCredentialsRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
|
||||
bool aValue)
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy)
|
||||
, mValue(aValue)
|
||||
{ }
|
||||
|
||||
@ -606,9 +608,9 @@ class SetResponseTypeRunnable final : public WorkerThreadProxySyncRunnable
|
||||
XMLHttpRequestResponseType mResponseType;
|
||||
|
||||
public:
|
||||
SetResponseTypeRunnable(Proxy* aProxy,
|
||||
SetResponseTypeRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
|
||||
XMLHttpRequestResponseType aResponseType)
|
||||
: WorkerThreadProxySyncRunnable(GetCurrentThreadWorkerPrivate(), aProxy),
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy),
|
||||
mResponseType(aResponseType)
|
||||
{ }
|
||||
|
||||
@ -637,8 +639,9 @@ class SetTimeoutRunnable final : public WorkerThreadProxySyncRunnable
|
||||
uint32_t mTimeout;
|
||||
|
||||
public:
|
||||
SetTimeoutRunnable(Proxy* aProxy, uint32_t aTimeout)
|
||||
: WorkerThreadProxySyncRunnable(GetCurrentThreadWorkerPrivate(), aProxy),
|
||||
SetTimeoutRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
|
||||
uint32_t aTimeout)
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy),
|
||||
mTimeout(aTimeout)
|
||||
{ }
|
||||
|
||||
@ -656,8 +659,8 @@ private:
|
||||
class AbortRunnable final : public WorkerThreadProxySyncRunnable
|
||||
{
|
||||
public:
|
||||
explicit AbortRunnable(Proxy* aProxy)
|
||||
: WorkerThreadProxySyncRunnable(GetCurrentThreadWorkerPrivate(), aProxy)
|
||||
AbortRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy)
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy)
|
||||
{ }
|
||||
|
||||
private:
|
||||
@ -674,8 +677,9 @@ class GetAllResponseHeadersRunnable final :
|
||||
nsCString& mResponseHeaders;
|
||||
|
||||
public:
|
||||
GetAllResponseHeadersRunnable(Proxy* aProxy, nsCString& aResponseHeaders)
|
||||
: WorkerThreadProxySyncRunnable(GetCurrentThreadWorkerPrivate(), aProxy),
|
||||
GetAllResponseHeadersRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
|
||||
nsCString& aResponseHeaders)
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy),
|
||||
mResponseHeaders(aResponseHeaders)
|
||||
{ }
|
||||
|
||||
@ -696,9 +700,9 @@ class GetResponseHeaderRunnable final : public WorkerThreadProxySyncRunnable
|
||||
nsCString& mValue;
|
||||
|
||||
public:
|
||||
GetResponseHeaderRunnable(Proxy* aProxy, const nsACString& aHeader,
|
||||
nsCString& aValue)
|
||||
: WorkerThreadProxySyncRunnable(GetCurrentThreadWorkerPrivate(), aProxy),
|
||||
GetResponseHeaderRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
|
||||
const nsACString& aHeader, nsCString& aValue)
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy),
|
||||
mHeader(aHeader),
|
||||
mValue(aValue)
|
||||
{ }
|
||||
@ -775,10 +779,9 @@ class SetRequestHeaderRunnable final : public WorkerThreadProxySyncRunnable
|
||||
nsCString mValue;
|
||||
|
||||
public:
|
||||
SetRequestHeaderRunnable(Proxy* aProxy,
|
||||
const nsACString& aHeader,
|
||||
const nsACString& aValue)
|
||||
: WorkerThreadProxySyncRunnable(GetCurrentThreadWorkerPrivate(), aProxy),
|
||||
SetRequestHeaderRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
|
||||
const nsACString& aHeader, const nsACString& aValue)
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy),
|
||||
mHeader(aHeader),
|
||||
mValue(aValue)
|
||||
{ }
|
||||
@ -799,8 +802,9 @@ class OverrideMimeTypeRunnable final : public WorkerThreadProxySyncRunnable
|
||||
nsString mMimeType;
|
||||
|
||||
public:
|
||||
OverrideMimeTypeRunnable(Proxy* aProxy, const nsAString& aMimeType)
|
||||
: WorkerThreadProxySyncRunnable(GetCurrentThreadWorkerPrivate(), aProxy),
|
||||
OverrideMimeTypeRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
|
||||
const nsAString& aMimeType)
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy),
|
||||
mMimeType(aMimeType)
|
||||
{ }
|
||||
|
||||
@ -1303,7 +1307,7 @@ EventRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
|
||||
state->mResponseURL = mResponseURL;
|
||||
|
||||
XMLHttpRequestWorker* xhr = mProxy->mXMLHttpRequestPrivate;
|
||||
xhr->UpdateState(aCx, *state.get(), mUseCachedArrayBufferResponse);
|
||||
xhr->UpdateState(*state.get(), mUseCachedArrayBufferResponse);
|
||||
|
||||
if (mType.EqualsASCII(sEventStrings[STRING_readystatechange])) {
|
||||
if (mReadyState == 4 && !mUploadEvent && !mProxy->mSeenLoadStart) {
|
||||
@ -1539,27 +1543,24 @@ SendRunnable::RunOnMainThread(ErrorResult& aRv)
|
||||
}
|
||||
}
|
||||
|
||||
XMLHttpRequestWorker::XMLHttpRequestWorker()
|
||||
: mResponseType(XMLHttpRequestResponseType::Text)
|
||||
, mTimeout(0)
|
||||
, mBackgroundRequest(false)
|
||||
, mWithCredentials(false)
|
||||
, mCanceled(false)
|
||||
, mMozAnon(false)
|
||||
, mMozSystem(false)
|
||||
XMLHttpRequestWorker::XMLHttpRequestWorker(WorkerPrivate* aWorkerPrivate)
|
||||
: WorkerHolder("XMLHttpRequestWorker"), mWorkerPrivate(aWorkerPrivate),
|
||||
mResponseType(XMLHttpRequestResponseType::Text), mTimeout(0),
|
||||
mRooted(false), mBackgroundRequest(false), mWithCredentials(false),
|
||||
mCanceled(false), mMozAnon(false), mMozSystem(false)
|
||||
{
|
||||
MOZ_ASSERT(IsCurrentThreadRunningWorker());
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
mozilla::HoldJSObjects(this);
|
||||
}
|
||||
|
||||
XMLHttpRequestWorker::~XMLHttpRequestWorker()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
ReleaseProxy(XHRIsGoingAway);
|
||||
|
||||
MOZ_ASSERT(!mWorkerRef);
|
||||
MOZ_ASSERT(!mRooted);
|
||||
|
||||
mozilla::DropJSObjects(this);
|
||||
}
|
||||
@ -1594,12 +1595,12 @@ XMLHttpRequestWorker::Construct(const GlobalObject& aGlobal,
|
||||
const MozXMLHttpRequestParameters& aParams,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
RefPtr<XMLHttpRequestWorker> xhr = new XMLHttpRequestWorker();
|
||||
|
||||
JSContext* cx = aGlobal.Context();
|
||||
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
|
||||
RefPtr<XMLHttpRequestWorker> xhr = new XMLHttpRequestWorker(workerPrivate);
|
||||
|
||||
if (workerPrivate->XHRParamsAllowed()) {
|
||||
if (aParams.mMozSystem)
|
||||
xhr->mMozAnon = true;
|
||||
@ -1614,7 +1615,8 @@ XMLHttpRequestWorker::Construct(const GlobalObject& aGlobal,
|
||||
void
|
||||
XMLHttpRequestWorker::ReleaseProxy(ReleaseType aType)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
// Can't assert that we're on the worker thread here because mWorkerPrivate
|
||||
// may be gone.
|
||||
|
||||
if (mProxy) {
|
||||
if (aType == XHRIsGoingAway) {
|
||||
@ -1624,10 +1626,7 @@ XMLHttpRequestWorker::ReleaseProxy(ReleaseType aType)
|
||||
new AsyncTeardownRunnable(mProxy);
|
||||
mProxy = nullptr;
|
||||
|
||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
|
||||
if (NS_FAILED(workerPrivate->DispatchToMainThread(runnable.forget()))) {
|
||||
if (NS_FAILED(mWorkerPrivate->DispatchToMainThread(runnable.forget()))) {
|
||||
NS_ERROR("Failed to dispatch teardown runnable!");
|
||||
}
|
||||
} else {
|
||||
@ -1639,7 +1638,8 @@ XMLHttpRequestWorker::ReleaseProxy(ReleaseType aType)
|
||||
}
|
||||
|
||||
// We need to make a sync call here.
|
||||
RefPtr<SyncTeardownRunnable> runnable = new SyncTeardownRunnable(mProxy);
|
||||
RefPtr<SyncTeardownRunnable> runnable =
|
||||
new SyncTeardownRunnable(mWorkerPrivate, mProxy);
|
||||
mProxy = nullptr;
|
||||
|
||||
IgnoredErrorResult forAssertionsOnly;
|
||||
@ -1650,43 +1650,31 @@ XMLHttpRequestWorker::ReleaseProxy(ReleaseType aType)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
XMLHttpRequestWorker::MaybePin()
|
||||
void
|
||||
XMLHttpRequestWorker::MaybePin(ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mWorkerRef) {
|
||||
return true;
|
||||
if (mRooted) {
|
||||
return;
|
||||
}
|
||||
|
||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
|
||||
RefPtr<XMLHttpRequestWorker> self = this;
|
||||
mWorkerRef =
|
||||
StrongWorkerRef::Create(workerPrivate, "XMLHttpRequestWorker", [self] {
|
||||
self->mCanceled = true;
|
||||
self->ReleaseProxy(WorkerIsGoingAway);
|
||||
});
|
||||
|
||||
if (NS_WARN_IF(!mWorkerRef)) {
|
||||
return false;
|
||||
if (!HoldWorker(mWorkerPrivate, Canceling)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
return true;
|
||||
|
||||
mRooted = true;
|
||||
}
|
||||
|
||||
void
|
||||
XMLHttpRequestWorker::MaybeDispatchPrematureAbortEvents(ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(mProxy);
|
||||
|
||||
// The worker can be closed during the dispatching of the following events.
|
||||
// Let's keep the proxy alive.
|
||||
RefPtr<Proxy> proxy = mProxy;
|
||||
|
||||
// Only send readystatechange event when state changed.
|
||||
bool isStateChanged = false;
|
||||
if ((mStateData.mReadyState == 1 && mStateData.mFlagSend) ||
|
||||
@ -1696,61 +1684,58 @@ XMLHttpRequestWorker::MaybeDispatchPrematureAbortEvents(ErrorResult& aRv)
|
||||
mStateData.mReadyState = 4;
|
||||
}
|
||||
|
||||
if (proxy->mSeenUploadLoadStart) {
|
||||
if (mProxy->mSeenUploadLoadStart) {
|
||||
MOZ_ASSERT(mUpload);
|
||||
|
||||
DispatchPrematureAbortEvent(mUpload, proxy, NS_LITERAL_STRING("abort"),
|
||||
true, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DispatchPrematureAbortEvent(mUpload, proxy, NS_LITERAL_STRING("loadend"),
|
||||
true, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
proxy->mSeenUploadLoadStart = false;
|
||||
}
|
||||
|
||||
if (proxy->mSeenLoadStart) {
|
||||
if (isStateChanged) {
|
||||
DispatchPrematureAbortEvent(this, proxy,
|
||||
NS_LITERAL_STRING("readystatechange"), false,
|
||||
aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DispatchPrematureAbortEvent(this, proxy, NS_LITERAL_STRING("abort"), false,
|
||||
DispatchPrematureAbortEvent(mUpload, NS_LITERAL_STRING("abort"), true,
|
||||
aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DispatchPrematureAbortEvent(this, proxy, NS_LITERAL_STRING("loadend"),
|
||||
false, aRv);
|
||||
DispatchPrematureAbortEvent(mUpload, NS_LITERAL_STRING("loadend"), true,
|
||||
aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
proxy->mSeenLoadStart = false;
|
||||
mProxy->mSeenUploadLoadStart = false;
|
||||
}
|
||||
|
||||
if (mProxy->mSeenLoadStart) {
|
||||
if (isStateChanged) {
|
||||
DispatchPrematureAbortEvent(this, NS_LITERAL_STRING("readystatechange"),
|
||||
false, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DispatchPrematureAbortEvent(this, NS_LITERAL_STRING("abort"), false, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DispatchPrematureAbortEvent(this, NS_LITERAL_STRING("loadend"), false,
|
||||
aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mProxy->mSeenLoadStart = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
XMLHttpRequestWorker::DispatchPrematureAbortEvent(EventTarget* aTarget,
|
||||
Proxy* aProxy,
|
||||
const nsAString& aEventType,
|
||||
bool aUploadTarget,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(aTarget);
|
||||
|
||||
if (!aProxy) {
|
||||
if (!mProxy) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
@ -1765,14 +1750,14 @@ XMLHttpRequestWorker::DispatchPrematureAbortEvent(EventTarget* aTarget,
|
||||
init.mBubbles = false;
|
||||
init.mCancelable = false;
|
||||
if (aUploadTarget) {
|
||||
init.mLengthComputable = aProxy->mLastUploadLengthComputable;
|
||||
init.mLoaded = aProxy->mLastUploadLoaded;
|
||||
init.mTotal = aProxy->mLastUploadTotal;
|
||||
init.mLengthComputable = mProxy->mLastUploadLengthComputable;
|
||||
init.mLoaded = mProxy->mLastUploadLoaded;
|
||||
init.mTotal = mProxy->mLastUploadTotal;
|
||||
}
|
||||
else {
|
||||
init.mLengthComputable = aProxy->mLastLengthComputable;
|
||||
init.mLoaded = aProxy->mLastLoaded;
|
||||
init.mTotal = aProxy->mLastTotal;
|
||||
init.mLengthComputable = mProxy->mLastLengthComputable;
|
||||
init.mLoaded = mProxy->mLastLoaded;
|
||||
init.mTotal = mProxy->mLastTotal;
|
||||
}
|
||||
event = ProgressEvent::Constructor(aTarget, aEventType, init);
|
||||
}
|
||||
@ -1791,11 +1776,13 @@ XMLHttpRequestWorker::DispatchPrematureAbortEvent(EventTarget* aTarget,
|
||||
void
|
||||
XMLHttpRequestWorker::Unpin()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
MOZ_ASSERT(mWorkerRef, "Mismatched calls to Unpin!");
|
||||
MOZ_ASSERT(mRooted, "Mismatched calls to Unpin!");
|
||||
|
||||
mWorkerRef = nullptr;
|
||||
ReleaseWorker();
|
||||
|
||||
mRooted = false;
|
||||
|
||||
NS_RELEASE_THIS();
|
||||
}
|
||||
@ -1805,7 +1792,7 @@ XMLHttpRequestWorker::SendInternal(SendRunnable* aRunnable,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(aRunnable);
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
// No send() calls when open is running.
|
||||
if (mProxy->mOpenCount) {
|
||||
@ -1815,21 +1802,18 @@ XMLHttpRequestWorker::SendInternal(SendRunnable* aRunnable,
|
||||
|
||||
bool hasUploadListeners = mUpload ? mUpload->HasListeners() : false;
|
||||
|
||||
if (NS_WARN_IF(!MaybePin())) {
|
||||
// Worker is shutting down. Let's ignore this send request.
|
||||
MaybePin(aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AutoUnpinXHR autoUnpin(this);
|
||||
Maybe<AutoSyncLoopHolder> autoSyncLoop;
|
||||
|
||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
|
||||
nsCOMPtr<nsIEventTarget> syncLoopTarget;
|
||||
bool isSyncXHR = mProxy->mIsSyncXHR;
|
||||
if (isSyncXHR) {
|
||||
autoSyncLoop.emplace(workerPrivate, Terminating);
|
||||
autoSyncLoop.emplace(mWorkerPrivate, Terminating);
|
||||
syncLoopTarget = autoSyncLoop->GetEventTarget();
|
||||
if (!syncLoopTarget) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
@ -1848,7 +1832,7 @@ XMLHttpRequestWorker::SendInternal(SendRunnable* aRunnable,
|
||||
if (aRv.Failed()) {
|
||||
// Dispatch() may have spun the event loop and we may have already unrooted.
|
||||
// If so we don't want autoUnpin to try again.
|
||||
if (!mWorkerRef) {
|
||||
if (!mRooted) {
|
||||
autoUnpin.Clear();
|
||||
}
|
||||
return;
|
||||
@ -1875,6 +1859,19 @@ XMLHttpRequestWorker::SendInternal(SendRunnable* aRunnable,
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
XMLHttpRequestWorker::Notify(WorkerStatus aStatus)
|
||||
{
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (aStatus >= Canceling && !mCanceled) {
|
||||
mCanceled = true;
|
||||
ReleaseProxy(WorkerIsGoingAway);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
XMLHttpRequestWorker::Open(const nsACString& aMethod,
|
||||
const nsAString& aUrl, bool aAsync,
|
||||
@ -1882,10 +1879,7 @@ XMLHttpRequestWorker::Open(const nsACString& aMethod,
|
||||
const Optional<nsAString>& aPassword,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
|
||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -1894,19 +1888,19 @@ XMLHttpRequestWorker::Open(const nsACString& aMethod,
|
||||
|
||||
if (mProxy) {
|
||||
MaybeDispatchPrematureAbortEvents(aRv);
|
||||
if (aRv.Failed() || !mProxy) {
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
mProxy = new Proxy(this, workerPrivate->GetClientInfo(),
|
||||
workerPrivate->GetController(), mMozAnon, mMozSystem);
|
||||
mProxy = new Proxy(this, mWorkerPrivate->GetClientInfo(),
|
||||
mWorkerPrivate->GetController(), mMozAnon, mMozSystem);
|
||||
}
|
||||
|
||||
mProxy->mOuterEventStreamId++;
|
||||
|
||||
RefPtr<OpenRunnable> runnable =
|
||||
new OpenRunnable(workerPrivate, mProxy, aMethod, aUrl, aUser, aPassword,
|
||||
new OpenRunnable(mWorkerPrivate, mProxy, aMethod, aUrl, aUser, aPassword,
|
||||
mBackgroundRequest, mWithCredentials,
|
||||
mTimeout, mResponseType);
|
||||
|
||||
@ -1934,7 +1928,7 @@ void
|
||||
XMLHttpRequestWorker::SetRequestHeader(const nsACString& aHeader,
|
||||
const nsACString& aValue, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -1947,14 +1941,14 @@ XMLHttpRequestWorker::SetRequestHeader(const nsACString& aHeader,
|
||||
}
|
||||
|
||||
RefPtr<SetRequestHeaderRunnable> runnable =
|
||||
new SetRequestHeaderRunnable(mProxy, aHeader, aValue);
|
||||
new SetRequestHeaderRunnable(mWorkerPrivate, mProxy, aHeader, aValue);
|
||||
runnable->Dispatch(Terminating, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
XMLHttpRequestWorker::SetTimeout(uint32_t aTimeout, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -1970,14 +1964,14 @@ XMLHttpRequestWorker::SetTimeout(uint32_t aTimeout, ErrorResult& aRv)
|
||||
}
|
||||
|
||||
RefPtr<SetTimeoutRunnable> runnable =
|
||||
new SetTimeoutRunnable(mProxy, aTimeout);
|
||||
new SetTimeoutRunnable(mWorkerPrivate, mProxy, aTimeout);
|
||||
runnable->Dispatch(Terminating, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
XMLHttpRequestWorker::SetWithCredentials(bool aWithCredentials, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -1993,7 +1987,7 @@ XMLHttpRequestWorker::SetWithCredentials(bool aWithCredentials, ErrorResult& aRv
|
||||
}
|
||||
|
||||
RefPtr<SetWithCredentialsRunnable> runnable =
|
||||
new SetWithCredentialsRunnable(mProxy, aWithCredentials);
|
||||
new SetWithCredentialsRunnable(mWorkerPrivate, mProxy, aWithCredentials);
|
||||
runnable->Dispatch(Terminating, aRv);
|
||||
}
|
||||
|
||||
@ -2001,7 +1995,7 @@ void
|
||||
XMLHttpRequestWorker::SetMozBackgroundRequest(bool aBackgroundRequest,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -2017,14 +2011,15 @@ XMLHttpRequestWorker::SetMozBackgroundRequest(bool aBackgroundRequest,
|
||||
}
|
||||
|
||||
RefPtr<SetBackgroundRequestRunnable> runnable =
|
||||
new SetBackgroundRequestRunnable(mProxy, aBackgroundRequest);
|
||||
new SetBackgroundRequestRunnable(mWorkerPrivate, mProxy,
|
||||
aBackgroundRequest);
|
||||
runnable->Dispatch(Terminating, aRv);
|
||||
}
|
||||
|
||||
XMLHttpRequestUpload*
|
||||
XMLHttpRequestWorker::GetUpload(ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -2048,7 +2043,7 @@ XMLHttpRequestWorker::Send(JSContext* aCx,
|
||||
const Nullable<DocumentOrBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString>& aData,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -2063,7 +2058,7 @@ XMLHttpRequestWorker::Send(JSContext* aCx,
|
||||
RefPtr<SendRunnable> sendRunnable;
|
||||
|
||||
if (aData.IsNull()) {
|
||||
sendRunnable = new SendRunnable(mProxy, VoidString());
|
||||
sendRunnable = new SendRunnable(mWorkerPrivate, mProxy, VoidString());
|
||||
// Nothing to clone.
|
||||
}
|
||||
|
||||
@ -2089,7 +2084,7 @@ XMLHttpRequestWorker::Send(JSContext* aCx,
|
||||
return;
|
||||
}
|
||||
|
||||
sendRunnable = new SendRunnable(mProxy, EmptyString());
|
||||
sendRunnable = new SendRunnable(mWorkerPrivate, mProxy, EmptyString());
|
||||
|
||||
sendRunnable->Write(aCx, value, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
@ -2098,7 +2093,7 @@ XMLHttpRequestWorker::Send(JSContext* aCx,
|
||||
}
|
||||
|
||||
else if (aData.Value().IsArrayBuffer()) {
|
||||
sendRunnable = new SendRunnable(mProxy, EmptyString());
|
||||
sendRunnable = new SendRunnable(mWorkerPrivate, mProxy, EmptyString());
|
||||
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
value.setObject(*aData.Value().GetAsArrayBuffer().Obj());
|
||||
@ -2119,7 +2114,7 @@ XMLHttpRequestWorker::Send(JSContext* aCx,
|
||||
return;
|
||||
}
|
||||
|
||||
sendRunnable = new SendRunnable(mProxy, EmptyString());
|
||||
sendRunnable = new SendRunnable(mWorkerPrivate, mProxy, EmptyString());
|
||||
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
value.setObject(*body.Obj());
|
||||
@ -2138,7 +2133,7 @@ XMLHttpRequestWorker::Send(JSContext* aCx,
|
||||
return;
|
||||
}
|
||||
|
||||
sendRunnable = new SendRunnable(mProxy, EmptyString());
|
||||
sendRunnable = new SendRunnable(mWorkerPrivate, mProxy, EmptyString());
|
||||
|
||||
sendRunnable->Write(aCx, value, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
@ -2154,7 +2149,7 @@ XMLHttpRequestWorker::Send(JSContext* aCx,
|
||||
return;
|
||||
}
|
||||
|
||||
sendRunnable = new SendRunnable(mProxy, EmptyString());
|
||||
sendRunnable = new SendRunnable(mWorkerPrivate, mProxy, EmptyString());
|
||||
|
||||
sendRunnable->Write(aCx, value, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
@ -2163,7 +2158,8 @@ XMLHttpRequestWorker::Send(JSContext* aCx,
|
||||
}
|
||||
|
||||
else if (aData.Value().IsUSVString()) {
|
||||
sendRunnable = new SendRunnable(mProxy, aData.Value().GetAsUSVString());
|
||||
sendRunnable = new SendRunnable(mWorkerPrivate, mProxy,
|
||||
aData.Value().GetAsUSVString());
|
||||
// Nothing to clone.
|
||||
}
|
||||
|
||||
@ -2174,7 +2170,7 @@ XMLHttpRequestWorker::Send(JSContext* aCx,
|
||||
void
|
||||
XMLHttpRequestWorker::Abort(ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -2207,13 +2203,9 @@ XMLHttpRequestWorker::Abort(ErrorResult& aRv)
|
||||
mStateData.mReadyState = 0;
|
||||
}
|
||||
|
||||
if (!mProxy) {
|
||||
return;
|
||||
}
|
||||
|
||||
mProxy->mOuterEventStreamId++;
|
||||
|
||||
RefPtr<AbortRunnable> runnable = new AbortRunnable(mProxy);
|
||||
RefPtr<AbortRunnable> runnable = new AbortRunnable(mWorkerPrivate, mProxy);
|
||||
runnable->Dispatch(Terminating, aRv);
|
||||
}
|
||||
|
||||
@ -2221,7 +2213,7 @@ void
|
||||
XMLHttpRequestWorker::GetResponseHeader(const nsACString& aHeader,
|
||||
nsACString& aResponseHeader, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -2235,7 +2227,8 @@ XMLHttpRequestWorker::GetResponseHeader(const nsACString& aHeader,
|
||||
|
||||
nsCString responseHeader;
|
||||
RefPtr<GetResponseHeaderRunnable> runnable =
|
||||
new GetResponseHeaderRunnable(mProxy, aHeader, responseHeader);
|
||||
new GetResponseHeaderRunnable(mWorkerPrivate, mProxy, aHeader,
|
||||
responseHeader);
|
||||
runnable->Dispatch(Terminating, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
@ -2247,7 +2240,7 @@ void
|
||||
XMLHttpRequestWorker::GetAllResponseHeaders(nsACString& aResponseHeaders,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -2261,7 +2254,7 @@ XMLHttpRequestWorker::GetAllResponseHeaders(nsACString& aResponseHeaders,
|
||||
|
||||
nsCString responseHeaders;
|
||||
RefPtr<GetAllResponseHeadersRunnable> runnable =
|
||||
new GetAllResponseHeadersRunnable(mProxy, responseHeaders);
|
||||
new GetAllResponseHeadersRunnable(mWorkerPrivate, mProxy, responseHeaders);
|
||||
runnable->Dispatch(Terminating, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
@ -2273,7 +2266,7 @@ XMLHttpRequestWorker::GetAllResponseHeaders(nsACString& aResponseHeaders,
|
||||
void
|
||||
XMLHttpRequestWorker::OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -2293,7 +2286,7 @@ XMLHttpRequestWorker::OverrideMimeType(const nsAString& aMimeType, ErrorResult&
|
||||
}
|
||||
|
||||
RefPtr<OverrideMimeTypeRunnable> runnable =
|
||||
new OverrideMimeTypeRunnable(mProxy, aMimeType);
|
||||
new OverrideMimeTypeRunnable(mWorkerPrivate, mProxy, aMimeType);
|
||||
runnable->Dispatch(Terminating, aRv);
|
||||
}
|
||||
|
||||
@ -2301,7 +2294,7 @@ void
|
||||
XMLHttpRequestWorker::SetResponseType(XMLHttpRequestResponseType aResponseType,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (mCanceled) {
|
||||
aRv.ThrowUncatchableException();
|
||||
@ -2329,7 +2322,7 @@ XMLHttpRequestWorker::SetResponseType(XMLHttpRequestResponseType aResponseType,
|
||||
}
|
||||
|
||||
RefPtr<SetResponseTypeRunnable> runnable =
|
||||
new SetResponseTypeRunnable(mProxy, aResponseType);
|
||||
new SetResponseTypeRunnable(mWorkerPrivate, mProxy, aResponseType);
|
||||
runnable->Dispatch(Terminating, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
@ -2339,23 +2332,23 @@ XMLHttpRequestWorker::SetResponseType(XMLHttpRequestResponseType aResponseType,
|
||||
}
|
||||
|
||||
void
|
||||
XMLHttpRequestWorker::GetResponse(JSContext* aCx,
|
||||
XMLHttpRequestWorker::GetResponse(JSContext* /* unused */,
|
||||
JS::MutableHandle<JS::Value> aResponse,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
|
||||
if (NS_SUCCEEDED(mStateData.mResponseTextResult) &&
|
||||
mStateData.mResponse.isUndefined()) {
|
||||
MOZ_ASSERT(NS_SUCCEEDED(mStateData.mResponseResult));
|
||||
|
||||
if (mStateData.mResponseText.IsEmpty()) {
|
||||
mStateData.mResponse = JS_GetEmptyStringValue(aCx);
|
||||
mStateData.mResponse =
|
||||
JS_GetEmptyStringValue(mWorkerPrivate->GetJSContext());
|
||||
} else {
|
||||
XMLHttpRequestStringSnapshotReaderHelper helper(mStateData.mResponseText);
|
||||
|
||||
JSString* str =
|
||||
JS_NewUCStringCopyN(aCx, helper.Buffer(), helper.Length());
|
||||
JS_NewUCStringCopyN(mWorkerPrivate->GetJSContext(),
|
||||
helper.Buffer(), helper.Length());
|
||||
|
||||
if (!str) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
@ -2385,17 +2378,15 @@ XMLHttpRequestWorker::GetResponseText(DOMString& aResponseText, ErrorResult& aRv
|
||||
}
|
||||
|
||||
void
|
||||
XMLHttpRequestWorker::UpdateState(JSContext* aCx,
|
||||
const StateData& aStateData,
|
||||
XMLHttpRequestWorker::UpdateState(const StateData& aStateData,
|
||||
bool aUseCachedArrayBufferResponse)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(XMLHttpRequestWorker);
|
||||
|
||||
if (aUseCachedArrayBufferResponse) {
|
||||
MOZ_ASSERT(mStateData.mResponse.isObject() &&
|
||||
JS_IsArrayBufferObject(&mStateData.mResponse.toObject()));
|
||||
|
||||
JS::Rooted<JS::Value> response(aCx, mStateData.mResponse);
|
||||
JS::Rooted<JS::Value> response(mWorkerPrivate->GetJSContext(),
|
||||
mStateData.mResponse);
|
||||
mStateData = aStateData;
|
||||
mStateData.mResponse = response;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "XMLHttpRequest.h"
|
||||
#include "XMLHttpRequestString.h"
|
||||
#include "mozilla/dom/TypedArray.h"
|
||||
#include "mozilla/dom/WorkerHolder.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -17,9 +18,10 @@ namespace dom {
|
||||
class Proxy;
|
||||
class SendRunnable;
|
||||
class DOMString;
|
||||
class StrongWorkerRef;
|
||||
class WorkerPrivate;
|
||||
|
||||
class XMLHttpRequestWorker final : public XMLHttpRequest
|
||||
class XMLHttpRequestWorker final : public XMLHttpRequest,
|
||||
public WorkerHolder
|
||||
{
|
||||
public:
|
||||
struct StateData
|
||||
@ -46,13 +48,14 @@ public:
|
||||
|
||||
private:
|
||||
RefPtr<XMLHttpRequestUpload> mUpload;
|
||||
RefPtr<StrongWorkerRef> mWorkerRef;
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
RefPtr<Proxy> mProxy;
|
||||
XMLHttpRequestResponseType mResponseType;
|
||||
StateData mStateData;
|
||||
|
||||
uint32_t mTimeout;
|
||||
|
||||
bool mRooted;
|
||||
bool mBackgroundRequest;
|
||||
bool mWithCredentials;
|
||||
bool mCanceled;
|
||||
@ -74,6 +77,9 @@ public:
|
||||
void
|
||||
Unpin();
|
||||
|
||||
bool
|
||||
Notify(WorkerStatus aStatus) override;
|
||||
|
||||
virtual uint16_t
|
||||
ReadyState() const override
|
||||
{
|
||||
@ -245,8 +251,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
UpdateState(JSContext* aCx, const StateData& aStateData,
|
||||
bool aUseCachedArrayBufferResponse);
|
||||
UpdateState(const StateData& aStateData, bool aUseCachedArrayBufferResponse);
|
||||
|
||||
void
|
||||
NullResponseText()
|
||||
@ -273,11 +278,11 @@ public:
|
||||
bool
|
||||
SendInProgress() const
|
||||
{
|
||||
return !!mWorkerRef;
|
||||
return mRooted;
|
||||
}
|
||||
|
||||
private:
|
||||
XMLHttpRequestWorker();
|
||||
explicit XMLHttpRequestWorker(WorkerPrivate* aWorkerPrivate);
|
||||
~XMLHttpRequestWorker();
|
||||
|
||||
enum ReleaseType { Default, XHRIsGoingAway, WorkerIsGoingAway };
|
||||
@ -285,14 +290,14 @@ private:
|
||||
void
|
||||
ReleaseProxy(ReleaseType aType = Default);
|
||||
|
||||
bool
|
||||
MaybePin();
|
||||
void
|
||||
MaybePin(ErrorResult& aRv);
|
||||
|
||||
void
|
||||
MaybeDispatchPrematureAbortEvents(ErrorResult& aRv);
|
||||
|
||||
void
|
||||
DispatchPrematureAbortEvent(EventTarget* aTarget, Proxy* aProxy,
|
||||
DispatchPrematureAbortEvent(EventTarget* aTarget,
|
||||
const nsAString& aEventType, bool aUploadTarget,
|
||||
ErrorResult& aRv);
|
||||
|
||||
|
@ -366460,12 +366460,6 @@
|
||||
{}
|
||||
]
|
||||
],
|
||||
"xhr/xmlhttprequest-closing-worker.html": [
|
||||
[
|
||||
"/xhr/xmlhttprequest-closing-worker.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"xhr/xmlhttprequest-eventtarget.htm": [
|
||||
[
|
||||
"/xhr/xmlhttprequest-eventtarget.htm",
|
||||
@ -601515,10 +601509,6 @@
|
||||
"a67d1876d6245fb94d60a937b633c87c51a04d21",
|
||||
"testharness"
|
||||
],
|
||||
"xhr/xmlhttprequest-closing-worker.html": [
|
||||
"2e12b49aca2dc3908837b6b419c92cb890e60e3f",
|
||||
"testharness"
|
||||
],
|
||||
"xhr/xmlhttprequest-eventtarget.htm": [
|
||||
"40c886f79399108db3ded8a23848905dcf9e0862",
|
||||
"testharness"
|
||||
|
Loading…
Reference in New Issue
Block a user