Bug 1848694 - Remove/avoid global references to nsIIOService r=mccr8,necko-reviewers,kershaw

This patch removes the static pointer to nsIIOService in nsContentUtils,
replacing it to calls to mozilla::components::IO::Service.

It also makes nsScriptSecurityManager::sIOService a StaticRefPtr.

Differential Revision: https://phabricator.services.mozilla.com/D188714
This commit is contained in:
Valentin Gosu 2023-09-21 12:39:20 +00:00
Родитель e7bc47985e
Коммит 32014974c0
7 изменённых файлов: 29 добавлений и 29 удалений

Просмотреть файл

@ -79,7 +79,7 @@
using namespace mozilla;
using namespace mozilla::dom;
nsIIOService* nsScriptSecurityManager::sIOService = nullptr;
StaticRefPtr<nsIIOService> nsScriptSecurityManager::sIOService;
std::atomic<bool> nsScriptSecurityManager::sStrictFileOriginPolicy = true;
namespace {
@ -1549,9 +1549,12 @@ nsScriptSecurityManager::nsScriptSecurityManager(void)
}
nsresult nsScriptSecurityManager::Init() {
nsresult rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);
NS_ENSURE_SUCCESS(rv, rv);
nsresult rv;
RefPtr<nsIIOService> io = mozilla::components::IO::Service(&rv);
if (NS_FAILED(rv)) {
return rv;
}
sIOService = std::move(io);
InitPrefs();
// Create our system principal singleton
@ -1597,7 +1600,7 @@ nsScriptSecurityManager::~nsScriptSecurityManager(void) {
}
void nsScriptSecurityManager::Shutdown() {
NS_IF_RELEASE(sIOService);
sIOService = nullptr;
BundleHelper::Shutdown();
SystemPrincipal::Shutdown();
}

Просмотреть файл

@ -135,7 +135,7 @@ class nsScriptSecurityManager final : public nsIScriptSecurityManager {
static std::atomic<bool> sStrictFileOriginPolicy;
static nsIIOService* sIOService;
static mozilla::StaticRefPtr<nsIIOService> sIOService;
static nsIStringBundle* sStrBundle;
};

Просмотреть файл

@ -12496,8 +12496,8 @@ void Document::MaybePreconnect(nsIURI* aOrigURI, mozilla::CORSMode aCORSMode) {
return;
}
nsCOMPtr<nsISpeculativeConnect> speculator(
do_QueryInterface(nsContentUtils::GetIOService()));
nsCOMPtr<nsISpeculativeConnect> speculator =
mozilla::components::IO::Service();
if (!speculator) {
return;
}

Просмотреть файл

@ -3263,10 +3263,11 @@ nsresult Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor) {
// connection to be sure we have one ready when we open the channel.
if (nsIDocShell* shell = OwnerDoc()->GetDocShell()) {
if (nsCOMPtr<nsIURI> absURI = GetHrefURI()) {
nsCOMPtr<nsISpeculativeConnect> sc =
do_QueryInterface(nsContentUtils::GetIOService());
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(shell);
sc->SpeculativeConnect(absURI, NodePrincipal(), ir, false);
if (nsCOMPtr<nsISpeculativeConnect> sc =
mozilla::components::IO::Service()) {
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(shell);
sc->SpeculativeConnect(absURI, NodePrincipal(), ir, false);
}
}
}
}

Просмотреть файл

@ -424,7 +424,6 @@ nsIXPConnect* nsContentUtils::sXPConnect;
nsIScriptSecurityManager* nsContentUtils::sSecurityManager;
nsIPrincipal* nsContentUtils::sSystemPrincipal;
nsIPrincipal* nsContentUtils::sNullSubjectPrincipal;
nsIIOService* nsContentUtils::sIOService;
nsIConsoleService* nsContentUtils::sConsoleService;
static nsTHashMap<RefPtr<nsAtom>, EventNameMapping>* sAtomEventTable;
@ -804,13 +803,6 @@ nsresult nsContentUtils::Init() {
nullPrincipal.forget(&sNullSubjectPrincipal);
nsresult rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);
if (NS_FAILED(rv)) {
// This makes life easier, but we can live without it.
sIOService = nullptr;
}
if (!InitializeEventTable()) return NS_ERROR_FAILURE;
if (!sEventListenerManagersHash) {
@ -1880,7 +1872,6 @@ void nsContentUtils::Shutdown() {
NS_IF_RELEASE(sSecurityManager);
NS_IF_RELEASE(sSystemPrincipal);
NS_IF_RELEASE(sNullSubjectPrincipal);
NS_IF_RELEASE(sIOService);
sBidiKeyboard = nullptr;
@ -2084,8 +2075,15 @@ bool nsContentUtils::IsAbsoluteURL(const nsACString& aURL) {
return true;
}
nsresult rv = NS_OK;
nsCOMPtr<nsIIOService> io = mozilla::components::IO::Service(&rv);
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
if (NS_FAILED(rv)) {
return false;
}
uint32_t flags;
if (NS_SUCCEEDED(sIOService->GetProtocolFlags(scheme.get(), &flags))) {
if (NS_SUCCEEDED(io->GetProtocolFlags(scheme.get(), &flags))) {
return flags & nsIProtocolHandler::URI_NORELATIVE;
}
@ -6255,7 +6253,7 @@ bool nsContentUtils::CheckForSubFrameDrop(nsIDragSession* aDragSession,
/* static */
bool nsContentUtils::URIIsLocalFile(nsIURI* aURI) {
bool isFile;
nsCOMPtr<nsINetUtil> util = do_QueryInterface(sIOService);
nsCOMPtr<nsINetUtil> util = mozilla::components::IO::Service();
// Important: we do NOT test the entire URI chain here!
return util &&

Просмотреть файл

@ -826,8 +826,6 @@ class nsContentUtils {
// element.
static bool InProlog(nsINode* aNode);
static nsIIOService* GetIOService() { return sIOService; }
static nsIBidiKeyboard* GetBidiKeyboard();
/**
@ -3523,8 +3521,6 @@ class nsContentUtils {
static nsIPrincipal* sSystemPrincipal;
static nsIPrincipal* sNullSubjectPrincipal;
static nsIIOService* sIOService;
static nsIConsoleService* sConsoleService;
static nsIStringBundleService* sStringBundleService;

Просмотреть файл

@ -176,8 +176,10 @@ static bool CanHandleURI(nsIURI* aURI) {
return false;
}
nsIIOService* ios = nsContentUtils::GetIOService();
if (!ios) return false;
nsCOMPtr<nsIIOService> ios = mozilla::components::IO::Service();
if (!ios) {
return false;
}
nsCOMPtr<nsIProtocolHandler> handler;
ios->GetProtocolHandler(scheme.get(), getter_AddRefs(handler));