From 953004415b5f70168b245594c845195624846489 Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Thu, 6 Aug 2020 22:35:14 +0000 Subject: [PATCH] Bug 1657231, part 4 - Don't allow using the URL preloader in the child. r=kmag It never gets initialized there anyways, so assert and clean up a bit of dead code. Differential Revision: https://phabricator.services.mozilla.com/D86032 --- js/xpconnect/loader/URLPreloader.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/js/xpconnect/loader/URLPreloader.cpp b/js/xpconnect/loader/URLPreloader.cpp index 83a5ecac662e..a5bec9826834 100644 --- a/js/xpconnect/loader/URLPreloader.cpp +++ b/js/xpconnect/loader/URLPreloader.cpp @@ -78,6 +78,11 @@ nsresult URLPreloader::CollectReports(nsIHandleReportCallback* aHandleReport, // static already_AddRefed URLPreloader::Create() { + // The static APIs like URLPreloader::Read work in the child process because + // they fall back to a synchronous read. The actual preloader must be + // explicitly initialized, and this should only be done in the parent. + MOZ_RELEASE_ASSERT(XRE_IsParentProcess()); + RefPtr preloader = new URLPreloader(); if (preloader->InitInternal().isOk()) { RegisterWeakMemoryReporter(preloader); @@ -131,16 +136,11 @@ Result URLPreloader::InitInternal() { return Err(NS_ERROR_UNEXPECTED); } - if (XRE_IsParentProcess()) { - nsCOMPtr obs = services::GetObserverService(); + nsCOMPtr obs = services::GetObserverService(); - MOZ_TRY(obs->AddObserver(this, DELAYED_STARTUP_TOPIC, false)); + MOZ_TRY(obs->AddObserver(this, DELAYED_STARTUP_TOPIC, false)); - MOZ_TRY(NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(mProfD))); - } else { - mStartupFinished = true; - mReaderInitialized = true; - } + MOZ_TRY(NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(mProfD))); return Ok(); }