diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index 313464c00cbd..b437d9f65d5d 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -319,6 +319,14 @@ XMLHttpRequestMainThread::InitParameters(bool aAnon, bool aSystem) SetParameters(aAnon, aSystem); } +void +XMLHttpRequestMainThread::SetClientInfoAndController(const ClientInfo& aClientInfo, + const Maybe& aController) +{ + mClientInfo.emplace(aClientInfo); + mController = aController; +} + void XMLHttpRequestMainThread::ResetResponse() { @@ -2503,6 +2511,17 @@ XMLHttpRequestMainThread::CreateChannel() loadGroup, nullptr, // aCallbacks loadFlags); + } else if (mClientInfo.isSome()) { + rv = NS_NewChannel(getter_AddRefs(mChannel), + mRequestURL, + mPrincipal, + mClientInfo.ref(), + mController, + secFlags, + nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST, + loadGroup, + nullptr, // aCallbacks + loadFlags); } else { // Otherwise use the principal. rv = NS_NewChannel(getter_AddRefs(mChannel), diff --git a/dom/xhr/XMLHttpRequestMainThread.h b/dom/xhr/XMLHttpRequestMainThread.h index 12ec5626e316..ade4291c2241 100644 --- a/dom/xhr/XMLHttpRequestMainThread.h +++ b/dom/xhr/XMLHttpRequestMainThread.h @@ -32,13 +32,16 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/DOMEventTargetHelper.h" +#include "mozilla/Maybe.h" #include "mozilla/MemoryReporting.h" #include "mozilla/NotNull.h" #include "mozilla/dom/MutableBlobStorage.h" #include "mozilla/dom/BodyExtractor.h" +#include "mozilla/dom/ClientInfo.h" #include "mozilla/dom/TypedArray.h" #include "mozilla/dom/File.h" #include "mozilla/dom/FormData.h" +#include "mozilla/dom/ServiceWorkerDescriptor.h" #include "mozilla/dom/URLSearchParams.h" #include "mozilla/dom/XMLHttpRequest.h" #include "mozilla/dom/XMLHttpRequestBinding.h" @@ -221,6 +224,9 @@ public: mIsSystem = aSystem; } + void SetClientInfoAndController(const ClientInfo& aClientInfo, + const Maybe& aController); + NS_DECL_ISUPPORTS_INHERITED // nsIXMLHttpRequest @@ -690,6 +696,9 @@ protected: nsCOMPtr mBaseURI; nsCOMPtr mLoadGroup; + Maybe mClientInfo; + Maybe mController; + State mState; StyleBackendType mStyleBackend; diff --git a/dom/xhr/XMLHttpRequestWorker.cpp b/dom/xhr/XMLHttpRequestWorker.cpp index 13e494e65db0..6ce37c4cac9b 100644 --- a/dom/xhr/XMLHttpRequestWorker.cpp +++ b/dom/xhr/XMLHttpRequestWorker.cpp @@ -97,6 +97,8 @@ public: // Read on multiple threads. WorkerPrivate* mWorkerPrivate; XMLHttpRequestWorker* mXMLHttpRequestPrivate; + const ClientInfo mClientInfo; + const Maybe mController; // XHR Params: bool mMozAnon; @@ -132,8 +134,11 @@ public: bool mArrayBufferResponseWasTransferred; public: - Proxy(XMLHttpRequestWorker* aXHRPrivate, bool aMozAnon, bool aMozSystem) + Proxy(XMLHttpRequestWorker* aXHRPrivate, const ClientInfo& aClientInfo, + const Maybe& aController, bool aMozAnon, + bool aMozSystem) : mWorkerPrivate(nullptr), mXMLHttpRequestPrivate(aXHRPrivate), + mClientInfo(aClientInfo), mController(aController), mMozAnon(aMozAnon), mMozSystem(aMozSystem), mInnerEventStreamId(0), mInnerChannelId(0), mOutstandingSendCount(0), mOuterEventStreamId(0), mOuterChannelId(0), mOpenCount(0), mLastLoaded(0), @@ -871,6 +876,7 @@ Proxy::Init() mWorkerPrivate->GetLoadGroup()); mXHR->SetParameters(mMozAnon, mMozSystem); + mXHR->SetClientInfoAndController(mClientInfo, mController); ErrorResult rv; mXHRUpload = mXHR->GetUpload(rv); @@ -1882,7 +1888,8 @@ XMLHttpRequestWorker::Open(const nsACString& aMethod, } } else { - mProxy = new Proxy(this, mMozAnon, mMozSystem); + mProxy = new Proxy(this, mWorkerPrivate->GetClientInfo(), + mWorkerPrivate->GetController(), mMozAnon, mMozSystem); } mProxy->mOuterEventStreamId++;