Bug 1637159 provide XMLHttpRequest owner via DOMEventTargetHelper constructor r=smaug

Depends on D75039

Differential Revision: https://phabricator.services.mozilla.com/D75041
This commit is contained in:
Karl Tomlinson
2020-05-14 05:28:36 +00:00
parent ec35f134c4
commit 5b4fa745c2
7 changed files with 24 additions and 15 deletions

View File

@@ -42,8 +42,8 @@ already_AddRefed<XMLHttpRequest> XMLHttpRequest::Constructor(
cookieJarSettings = net::CookieJarSettings::Create(); cookieJarSettings = net::CookieJarSettings::Create();
} }
RefPtr<XMLHttpRequestMainThread> req = new XMLHttpRequestMainThread(); RefPtr<XMLHttpRequestMainThread> req = new XMLHttpRequestMainThread(global);
req->Construct(principal->GetPrincipal(), global, cookieJarSettings, false); req->Construct(principal->GetPrincipal(), cookieJarSettings, false);
req->InitParameters(aParams.mMozAnon, aParams.mMozSystem); req->InitParameters(aParams.mMozAnon, aParams.mMozSystem);
return req.forget(); return req.forget();
} }

View File

@@ -127,6 +127,10 @@ class XMLHttpRequest : public XMLHttpRequestEventTarget {
JS::Handle<JSObject*> aGivenProto) override { JS::Handle<JSObject*> aGivenProto) override {
return mozilla::dom::XMLHttpRequest_Binding::Wrap(aCx, this, aGivenProto); return mozilla::dom::XMLHttpRequest_Binding::Wrap(aCx, this, aGivenProto);
} }
protected:
explicit XMLHttpRequest(nsIGlobalObject* aGlobalObject)
: XMLHttpRequestEventTarget(aGlobalObject) {}
}; };
} // namespace dom } // namespace dom

View File

@@ -17,7 +17,8 @@ class XMLHttpRequestEventTarget : public DOMEventTargetHelper {
explicit XMLHttpRequestEventTarget(DOMEventTargetHelper* aOwner) explicit XMLHttpRequestEventTarget(DOMEventTargetHelper* aOwner)
: DOMEventTargetHelper(aOwner) {} : DOMEventTargetHelper(aOwner) {}
XMLHttpRequestEventTarget() = default; explicit XMLHttpRequestEventTarget(nsIGlobalObject* aGlobalObject)
: DOMEventTargetHelper(aGlobalObject) {}
virtual ~XMLHttpRequestEventTarget() = default; virtual ~XMLHttpRequestEventTarget() = default;

View File

@@ -186,8 +186,10 @@ static void AddLoadFlags(nsIRequest* request, nsLoadFlags newFlags) {
bool XMLHttpRequestMainThread::sDontWarnAboutSyncXHR = false; bool XMLHttpRequestMainThread::sDontWarnAboutSyncXHR = false;
XMLHttpRequestMainThread::XMLHttpRequestMainThread() XMLHttpRequestMainThread::XMLHttpRequestMainThread(
: mResponseBodyDecodedPos(0), nsIGlobalObject* aGlobalObject)
: XMLHttpRequest(aGlobalObject),
mResponseBodyDecodedPos(0),
mResponseType(XMLHttpRequestResponseType::_empty), mResponseType(XMLHttpRequestResponseType::_empty),
mRequestObserver(nullptr), mRequestObserver(nullptr),
mState(XMLHttpRequest_Binding::UNSENT), mState(XMLHttpRequest_Binding::UNSENT),

View File

@@ -210,16 +210,15 @@ class XMLHttpRequestMainThread final : public XMLHttpRequest,
ENUM_MAX ENUM_MAX
}; };
XMLHttpRequestMainThread(); explicit XMLHttpRequestMainThread(nsIGlobalObject* aGlobalObject);
void Construct(nsIPrincipal* aPrincipal, nsIGlobalObject* aGlobalObject, void Construct(nsIPrincipal* aPrincipal,
nsICookieJarSettings* aCookieJarSettings, bool aForWorker, nsICookieJarSettings* aCookieJarSettings, bool aForWorker,
nsIURI* aBaseURI = nullptr, nsILoadGroup* aLoadGroup = nullptr, nsIURI* aBaseURI = nullptr, nsILoadGroup* aLoadGroup = nullptr,
PerformanceStorage* aPerformanceStorage = nullptr, PerformanceStorage* aPerformanceStorage = nullptr,
nsICSPEventListener* aCSPEventListener = nullptr) { nsICSPEventListener* aCSPEventListener = nullptr) {
MOZ_ASSERT(aPrincipal); MOZ_ASSERT(aPrincipal);
mPrincipal = aPrincipal; mPrincipal = aPrincipal;
BindToOwner(aGlobalObject);
mBaseURI = aBaseURI; mBaseURI = aBaseURI;
mLoadGroup = aLoadGroup; mLoadGroup = aLoadGroup;
mCookieJarSettings = aCookieJarSettings; mCookieJarSettings = aCookieJarSettings;

View File

@@ -765,9 +765,9 @@ bool Proxy::Init() {
return false; return false;
} }
mXHR = new XMLHttpRequestMainThread(); mXHR = new XMLHttpRequestMainThread(ownerWindow ? ownerWindow->AsGlobal()
: nullptr);
mXHR->Construct(mWorkerPrivate->GetPrincipal(), mXHR->Construct(mWorkerPrivate->GetPrincipal(),
ownerWindow ? ownerWindow->AsGlobal() : nullptr,
mWorkerPrivate->CookieJarSettings(), true, mWorkerPrivate->CookieJarSettings(), true,
mWorkerPrivate->GetBaseURI(), mWorkerPrivate->GetLoadGroup(), mWorkerPrivate->GetBaseURI(), mWorkerPrivate->GetLoadGroup(),
mWorkerPrivate->GetPerformanceStorage(), mWorkerPrivate->GetPerformanceStorage(),
@@ -1355,8 +1355,10 @@ void SendRunnable::RunOnMainThread(ErrorResult& aRv) {
} }
} }
XMLHttpRequestWorker::XMLHttpRequestWorker(WorkerPrivate* aWorkerPrivate) XMLHttpRequestWorker::XMLHttpRequestWorker(WorkerPrivate* aWorkerPrivate,
: mWorkerPrivate(aWorkerPrivate), nsIGlobalObject* aGlobalObject)
: XMLHttpRequest(aGlobalObject),
mWorkerPrivate(aWorkerPrivate),
mResponseType(XMLHttpRequestResponseType::_empty), mResponseType(XMLHttpRequestResponseType::_empty),
mStateData(new StateData()), mStateData(new StateData()),
mResponseData(new ResponseData()), mResponseData(new ResponseData()),
@@ -1428,8 +1430,8 @@ already_AddRefed<XMLHttpRequest> XMLHttpRequestWorker::Construct(
return nullptr; return nullptr;
} }
RefPtr<XMLHttpRequestWorker> xhr = new XMLHttpRequestWorker(workerPrivate); RefPtr<XMLHttpRequestWorker> xhr =
xhr->BindToOwner(global); new XMLHttpRequestWorker(workerPrivate, global);
if (workerPrivate->XHRParamsAllowed()) { if (workerPrivate->XHRParamsAllowed()) {
if (aParams.mMozSystem) if (aParams.mMozSystem)

View File

@@ -223,7 +223,8 @@ class XMLHttpRequestWorker final : public XMLHttpRequest {
bool SendInProgress() const { return !!mWorkerRef; } bool SendInProgress() const { return !!mWorkerRef; }
private: private:
explicit XMLHttpRequestWorker(WorkerPrivate* aWorkerPrivate); XMLHttpRequestWorker(WorkerPrivate* aWorkerPrivate,
nsIGlobalObject* aGlobalObject);
~XMLHttpRequestWorker(); ~XMLHttpRequestWorker();
enum ReleaseType { Default, XHRIsGoingAway, WorkerIsGoingAway }; enum ReleaseType { Default, XHRIsGoingAway, WorkerIsGoingAway };