diff --git a/caps/nsScriptSecurityManager.cpp b/caps/nsScriptSecurityManager.cpp index 3158a01d6f85..0bfed0b86784 100644 --- a/caps/nsScriptSecurityManager.cpp +++ b/caps/nsScriptSecurityManager.cpp @@ -79,7 +79,7 @@ using namespace mozilla; using namespace mozilla::dom; -nsIIOService* nsScriptSecurityManager::sIOService = nullptr; +StaticRefPtr nsScriptSecurityManager::sIOService; std::atomic 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 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(); } diff --git a/caps/nsScriptSecurityManager.h b/caps/nsScriptSecurityManager.h index 2d5a24104d46..bc55a70ad612 100644 --- a/caps/nsScriptSecurityManager.h +++ b/caps/nsScriptSecurityManager.h @@ -135,7 +135,7 @@ class nsScriptSecurityManager final : public nsIScriptSecurityManager { static std::atomic sStrictFileOriginPolicy; - static nsIIOService* sIOService; + static mozilla::StaticRefPtr sIOService; static nsIStringBundle* sStrBundle; }; diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index f734a7fe03d6..6f1809202f90 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -12496,8 +12496,8 @@ void Document::MaybePreconnect(nsIURI* aOrigURI, mozilla::CORSMode aCORSMode) { return; } - nsCOMPtr speculator( - do_QueryInterface(nsContentUtils::GetIOService())); + nsCOMPtr speculator = + mozilla::components::IO::Service(); if (!speculator) { return; } diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index dedae906d8ac..f658dd5ed3db 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -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 absURI = GetHrefURI()) { - nsCOMPtr sc = - do_QueryInterface(nsContentUtils::GetIOService()); - nsCOMPtr ir = do_QueryInterface(shell); - sc->SpeculativeConnect(absURI, NodePrincipal(), ir, false); + if (nsCOMPtr sc = + mozilla::components::IO::Service()) { + nsCOMPtr ir = do_QueryInterface(shell); + sc->SpeculativeConnect(absURI, NodePrincipal(), ir, false); + } } } } diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 0c5d1f650be1..1f9863a8bc53 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -424,7 +424,6 @@ nsIXPConnect* nsContentUtils::sXPConnect; nsIScriptSecurityManager* nsContentUtils::sSecurityManager; nsIPrincipal* nsContentUtils::sSystemPrincipal; nsIPrincipal* nsContentUtils::sNullSubjectPrincipal; -nsIIOService* nsContentUtils::sIOService; nsIConsoleService* nsContentUtils::sConsoleService; static nsTHashMap, 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 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 util = do_QueryInterface(sIOService); + nsCOMPtr util = mozilla::components::IO::Service(); // Important: we do NOT test the entire URI chain here! return util && diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 9f2850584bbb..180c7fe15d6a 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -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; diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index 3f164f2b2e6f..e1879d701c43 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -176,8 +176,10 @@ static bool CanHandleURI(nsIURI* aURI) { return false; } - nsIIOService* ios = nsContentUtils::GetIOService(); - if (!ios) return false; + nsCOMPtr ios = mozilla::components::IO::Service(); + if (!ios) { + return false; + } nsCOMPtr handler; ios->GetProtocolHandler(scheme.get(), getter_AddRefs(handler));