Commit 1dd7837b authored by valenting's avatar valenting
Browse files

Bug 1848694 - Remove/avoid global references to nsIIOService...

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

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
parent 260ccd41
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@
using namespace mozilla;
using namespace mozilla::dom;

nsIIOService* nsScriptSecurityManager::sIOService = nullptr;
StaticRefPtr<nsIIOService> nsScriptSecurityManager::sIOService;
std::atomic<bool> nsScriptSecurityManager::sStrictFileOriginPolicy = true;

namespace {
@@ -1548,9 +1548,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
@@ -1596,7 +1599,7 @@ nsScriptSecurityManager::~nsScriptSecurityManager(void) {
}

void nsScriptSecurityManager::Shutdown() {
  NS_IF_RELEASE(sIOService);
  sIOService = nullptr;
  BundleHelper::Shutdown();
  SystemPrincipal::Shutdown();
}
+1 −1
Original line number Diff line number Diff line
@@ -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;
};

+2 −2
Original line number Diff line number Diff line
@@ -12479,8 +12479,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;
  }
+6 −4
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include "mozilla/AnimationTarget.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/CORSMode.h"
#include "mozilla/Components.h"
#include "mozilla/ComputedStyle.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/DebugOnly.h"
@@ -3259,13 +3260,14 @@ 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());
            if (nsCOMPtr<nsISpeculativeConnect> sc =
                    mozilla::components::IO::Service()) {
              nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(shell);
              sc->SpeculativeConnect(absURI, NodePrincipal(), ir, false);
            }
          }
        }
      }
    } break;

    case eMouseClick: {
+9 −11
Original line number Diff line number Diff line
@@ -420,7 +420,6 @@ nsIXPConnect* nsContentUtils::sXPConnect;
nsIScriptSecurityManager* nsContentUtils::sSecurityManager;
nsIPrincipal* nsContentUtils::sSystemPrincipal;
nsIPrincipal* nsContentUtils::sNullSubjectPrincipal;
nsIIOService* nsContentUtils::sIOService;
nsIConsoleService* nsContentUtils::sConsoleService;
nsTHashMap<nsRefPtrHashKey<nsAtom>, EventNameMapping>*
    nsContentUtils::sAtomEventTable = nullptr;
@@ -802,13 +801,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) {
@@ -1894,7 +1886,6 @@ void nsContentUtils::Shutdown() {
  NS_IF_RELEASE(sSecurityManager);
  NS_IF_RELEASE(sSystemPrincipal);
  NS_IF_RELEASE(sNullSubjectPrincipal);
  NS_IF_RELEASE(sIOService);

  sBidiKeyboard = nullptr;

@@ -2101,8 +2092,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;
  }

@@ -6365,7 +6363,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 &&
Loading