Bug 1528677: Remove nullchecks for loadinfo since we have loadinfo on all channels. r=baku
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Wed, 20 Feb 2019 13:27:25 +0100
changeset 460100 ae4650359867653d2c9d01ab822158b1c5649fb5
parent 460099 f3e70b536542c941d4525e04526a35dc2342f93b
child 460101 b9c19a2b48548963aa0b469912f82bf156a829bc
push id35583
push usercsabou@mozilla.com
push dateThu, 21 Feb 2019 03:42:51 +0000
treeherdermozilla-central@7b26b8338599 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1528677
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1528677: Remove nullchecks for loadinfo since we have loadinfo on all channels. r=baku
caps/nsScriptSecurityManager.cpp
docshell/base/nsDocShell.cpp
docshell/base/nsDocShellLoadState.cpp
dom/base/Document.cpp
dom/base/ThirdPartyUtil.cpp
dom/base/nsContentUtils.cpp
dom/base/nsGlobalWindowInner.cpp
dom/base/nsGlobalWindowOuter.cpp
dom/base/nsNodeInfoManager.cpp
dom/base/nsObjectLoadingContent.cpp
dom/base/nsSyncLoadService.cpp
dom/clients/manager/ClientChannelHelper.cpp
dom/fetch/FetchDriver.cpp
dom/html/HTMLMediaElement.cpp
dom/html/ImageDocument.cpp
dom/html/nsHTMLDocument.cpp
dom/jsurl/nsJSProtocolHandler.cpp
dom/media/ChannelMediaResource.cpp
dom/performance/PerformanceTiming.cpp
dom/plugins/base/nsPluginStreamListenerPeer.cpp
dom/script/ScriptLoader.cpp
dom/security/FramingChecker.cpp
dom/security/SRICheck.cpp
dom/security/nsCSPService.cpp
dom/security/nsContentSecurityManager.cpp
dom/security/nsMixedContentBlocker.cpp
dom/serviceworkers/ServiceWorkerEvents.cpp
dom/serviceworkers/ServiceWorkerInterceptController.cpp
dom/serviceworkers/ServiceWorkerManager.cpp
dom/workers/ScriptLoader.cpp
dom/xhr/XMLHttpRequestMainThread.cpp
image/imgLoader.cpp
image/imgRequest.cpp
layout/style/Loader.cpp
netwerk/base/LoadInfo.cpp
netwerk/base/Predictor.cpp
netwerk/base/nsAsyncRedirectVerifyHelper.cpp
netwerk/base/nsBaseChannel.cpp
netwerk/base/nsIChannel.idl
netwerk/base/nsINetworkInterceptController.idl
netwerk/base/nsIOService.cpp
netwerk/base/nsNetUtil.cpp
netwerk/cookie/CookieServiceChild.cpp
netwerk/cookie/CookieServiceParent.cpp
netwerk/cookie/nsCookieService.cpp
netwerk/ipc/ChannelEventQueue.cpp
netwerk/protocol/about/nsAboutProtocolHandler.cpp
netwerk/protocol/http/HttpBaseChannel.cpp
netwerk/protocol/http/HttpChannelParent.cpp
netwerk/protocol/http/TrackingDummyChannelChild.cpp
netwerk/protocol/http/nsCORSListenerProxy.cpp
netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
netwerk/protocol/viewsource/nsViewSourceChannel.cpp
netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
netwerk/url-classifier/UrlClassifierCommon.cpp
netwerk/url-classifier/UrlClassifierFeatureFlash.cpp
security/manager/ssl/nsNSSCallbacks.cpp
toolkit/components/antitracking/AntiTrackingCommon.cpp
toolkit/components/extensions/ExtensionPolicyService.cpp
toolkit/components/extensions/WebExtensionPolicy.cpp
toolkit/components/extensions/webrequest/ChannelWrapper.h
toolkit/components/places/nsAnnoProtocolHandler.cpp
toolkit/components/reputationservice/ApplicationReputation.cpp
toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
uriloader/exthandler/nsExternalHelperAppService.cpp
uriloader/prefetch/nsPrefetchService.cpp
--- a/caps/nsScriptSecurityManager.cpp
+++ b/caps/nsScriptSecurityManager.cpp
@@ -248,19 +248,19 @@ static void InheritAndSetCSPOnPrincipalI
                                                 nsIPrincipal* aPrincipal) {
   // loading a data: URI into an iframe, or loading frame[srcdoc] need
   // to inherit the CSP (see Bug 1073952, 1381761).
   MOZ_ASSERT(aChannel && aPrincipal, "need a valid channel and principal");
   if (!aChannel) {
     return;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo || loadInfo->GetExternalContentPolicyType() !=
-                       nsIContentPolicy::TYPE_SUBDOCUMENT) {
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+  if (loadInfo->GetExternalContentPolicyType() !=
+      nsIContentPolicy::TYPE_SUBDOCUMENT) {
     return;
   }
 
   nsCOMPtr<nsIURI> uri;
   nsresult rv = aChannel->GetURI(getter_AddRefs(uri));
   NS_ENSURE_SUCCESS_VOID(rv);
   nsAutoCString URISpec;
   rv = uri->GetSpec(URISpec);
@@ -297,80 +297,78 @@ static void InheritAndSetCSPOnPrincipalI
   aPrincipal->SetCsp(originalCSP);
 }
 
 nsresult nsScriptSecurityManager::GetChannelResultPrincipal(
     nsIChannel* aChannel, nsIPrincipal** aPrincipal, bool aIgnoreSandboxing) {
   MOZ_ASSERT(aChannel, "Must have channel!");
 
   // Check whether we have an nsILoadInfo that says what we should do.
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (loadInfo && loadInfo->GetForceInheritPrincipalOverruleOwner()) {
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+  if (loadInfo->GetForceInheritPrincipalOverruleOwner()) {
     nsCOMPtr<nsIPrincipal> principalToInherit =
         loadInfo->FindPrincipalToInherit(aChannel);
     principalToInherit.forget(aPrincipal);
     return NS_OK;
   }
 
   nsCOMPtr<nsISupports> owner;
   aChannel->GetOwner(getter_AddRefs(owner));
   if (owner) {
     CallQueryInterface(owner, aPrincipal);
     if (*aPrincipal) {
       return NS_OK;
     }
   }
 
-  if (loadInfo) {
-    if (!aIgnoreSandboxing && loadInfo->GetLoadingSandboxed()) {
-      nsCOMPtr<nsIPrincipal> sandboxedLoadingPrincipal =
-          loadInfo->GetSandboxedLoadingPrincipal();
-      MOZ_ASSERT(sandboxedLoadingPrincipal);
-      InheritAndSetCSPOnPrincipalIfNeeded(aChannel, sandboxedLoadingPrincipal);
-      sandboxedLoadingPrincipal.forget(aPrincipal);
-      return NS_OK;
-    }
+  if (!aIgnoreSandboxing && loadInfo->GetLoadingSandboxed()) {
+    nsCOMPtr<nsIPrincipal> sandboxedLoadingPrincipal =
+        loadInfo->GetSandboxedLoadingPrincipal();
+    MOZ_ASSERT(sandboxedLoadingPrincipal);
+    InheritAndSetCSPOnPrincipalIfNeeded(aChannel, sandboxedLoadingPrincipal);
+    sandboxedLoadingPrincipal.forget(aPrincipal);
+    return NS_OK;
+  }
 
-    bool forceInherit = loadInfo->GetForceInheritPrincipal();
-    if (aIgnoreSandboxing && !forceInherit) {
-      // Check if SEC_FORCE_INHERIT_PRINCIPAL was dropped because of
-      // sandboxing:
-      if (loadInfo->GetLoadingSandboxed() &&
-          loadInfo->GetForceInheritPrincipalDropped()) {
-        forceInherit = true;
-      }
+  bool forceInherit = loadInfo->GetForceInheritPrincipal();
+  if (aIgnoreSandboxing && !forceInherit) {
+    // Check if SEC_FORCE_INHERIT_PRINCIPAL was dropped because of
+    // sandboxing:
+    if (loadInfo->GetLoadingSandboxed() &&
+        loadInfo->GetForceInheritPrincipalDropped()) {
+      forceInherit = true;
     }
-    if (forceInherit) {
-      nsCOMPtr<nsIPrincipal> principalToInherit =
-          loadInfo->FindPrincipalToInherit(aChannel);
+  }
+  if (forceInherit) {
+    nsCOMPtr<nsIPrincipal> principalToInherit =
+        loadInfo->FindPrincipalToInherit(aChannel);
+    principalToInherit.forget(aPrincipal);
+    return NS_OK;
+  }
+
+  auto securityMode = loadInfo->GetSecurityMode();
+  // The data: inheritance flags should only apply to the initial load,
+  // not to loads that it might have redirected to.
+  if (loadInfo->RedirectChain().IsEmpty() &&
+      (securityMode == nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS ||
+       securityMode == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS ||
+       securityMode == nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS)) {
+    nsCOMPtr<nsIURI> uri;
+    nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIPrincipal> principalToInherit =
+        loadInfo->FindPrincipalToInherit(aChannel);
+    bool inheritForAboutBlank = loadInfo->GetAboutBlankInherits();
+
+    if (nsContentUtils::ChannelShouldInheritPrincipal(
+            principalToInherit, uri, inheritForAboutBlank, false)) {
       principalToInherit.forget(aPrincipal);
       return NS_OK;
     }
-
-    auto securityMode = loadInfo->GetSecurityMode();
-    // The data: inheritance flags should only apply to the initial load,
-    // not to loads that it might have redirected to.
-    if (loadInfo->RedirectChain().IsEmpty() &&
-        (securityMode == nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS ||
-         securityMode == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS ||
-         securityMode == nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS)) {
-      nsCOMPtr<nsIURI> uri;
-      nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri));
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      nsCOMPtr<nsIPrincipal> principalToInherit =
-          loadInfo->FindPrincipalToInherit(aChannel);
-      bool inheritForAboutBlank = loadInfo->GetAboutBlankInherits();
-
-      if (nsContentUtils::ChannelShouldInheritPrincipal(
-              principalToInherit, uri, inheritForAboutBlank, false)) {
-        principalToInherit.forget(aPrincipal);
-        return NS_OK;
-      }
-    }
   }
   nsresult rv = GetChannelURIPrincipal(aChannel, aPrincipal);
   NS_ENSURE_SUCCESS(rv, rv);
   InheritAndSetCSPOnPrincipalIfNeeded(aChannel, *aPrincipal);
   return NS_OK;
 }
 
 /* The principal of the URI that this channel is loading. This is never
@@ -390,30 +388,24 @@ nsScriptSecurityManager::GetChannelURIPr
   MOZ_ASSERT(aChannel, "Must have channel!");
 
   // Get the principal from the URI.  Make sure this does the same thing
   // as Document::Reset and XULDocument::StartDocumentLoad.
   nsCOMPtr<nsIURI> uri;
   nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsILoadInfo> loadInfo;
-  aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
 
   // Inherit the origin attributes from loadInfo.
   // If this is a top-level document load, the origin attributes of the
   // loadInfo will be set from nsDocShell::DoURILoad.
   // For subresource loading, the origin attributes of the loadInfo is from
   // its loadingPrincipal.
-  OriginAttributes attrs;
-
-  // For addons loadInfo might be null.
-  if (loadInfo) {
-    attrs = loadInfo->GetOriginAttributes();
-  }
+  OriginAttributes attrs = loadInfo->GetOriginAttributes();
 
   nsCOMPtr<nsIPrincipal> prin =
       BasePrincipal::CreateCodebasePrincipal(uri, attrs);
   prin.forget(aPrincipal);
   return *aPrincipal ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -4571,20 +4571,18 @@ nsDocShell::Reload(uint32_t aReloadFlags
       uint32_t loadFlags;
       chan->GetLoadFlags(&loadFlags);
       loadReplace = loadFlags & nsIChannel::LOAD_REPLACE;
       nsCOMPtr<nsIHttpChannel> httpChan(do_QueryInterface(chan));
       if (httpChan) {
         httpChan->GetOriginalURI(getter_AddRefs(originalURI));
       }
 
-      nsCOMPtr<nsILoadInfo> loadInfo = chan->GetLoadInfo();
-      if (loadInfo) {
-        loadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
-      }
+      nsCOMPtr<nsILoadInfo> loadInfo = chan->LoadInfo();
+      loadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
     }
 
     MOZ_ASSERT(triggeringPrincipal, "Need a valid triggeringPrincipal");
     if (mUseStrictSecurityChecks && !triggeringPrincipal) {
       return NS_ERROR_FAILURE;
     }
 
     // Stack variables to ensure changes to the member variables don't affect to
@@ -6845,17 +6843,17 @@ nsresult nsDocShell::EndPageLoad(nsIWebP
           nsAutoCString newSpec;
           newURI->GetSpec(newSpec);
           NS_ConvertUTF8toUTF16 newSpecW(newSpec);
 
           // This notification is meant for Firefox Health Report so it
           // can increment counts from the search engine
           MaybeNotifyKeywordSearchLoading(keywordProviderName, keywordAsSent);
 
-          nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
+          nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
           MOZ_ASSERT(loadInfo, "loadInfo is required on all channels");
           nsCOMPtr<nsIPrincipal> triggeringPrincipal =
               loadInfo->TriggeringPrincipal();
 
           LoadURIOptions loadURIOptions;
           loadURIOptions.mTriggeringPrincipal = triggeringPrincipal;
           loadURIOptions.mPostData = newPostData;
           return LoadURI(newSpecW, loadURIOptions);
@@ -6897,20 +6895,18 @@ nsresult nsDocShell::EndPageLoad(nsIWebP
       // out which error to return. Or we can fix up the error here.
       if (!(mLoadType & LOAD_CMD_HISTORY)) {
         aStatus = NS_ERROR_OFFLINE;
       }
       DisplayLoadError(aStatus, url, nullptr, aChannel);
     }
   } else if (url && NS_SUCCEEDED(aStatus)) {
     // If we have a host
-    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-    if (loadInfo) {
-      PredictorLearnRedirect(url, aChannel, loadInfo->GetOriginAttributes());
-    }
+    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+    PredictorLearnRedirect(url, aChannel, loadInfo->GetOriginAttributes());
   }
 
   return NS_OK;
 }
 
 //*****************************************************************************
 // nsDocShell: Content Viewer Management
 //*****************************************************************************
@@ -9824,18 +9820,17 @@ nsresult nsDocShell::DoURILoad(nsDocShel
   // We have to do this in case our OriginAttributes are different from the
   // OriginAttributes of the parent document. Or in case there isn't a
   // parent document.
   bool isTopLevelDoc = mItemType == typeContent &&
                        (contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT ||
                         GetIsMozBrowser());
 
   if (isTopLevelDoc && GetDocument() && GetDocument()->GetChannel()) {
-    nsCOMPtr<nsILoadInfo> oldLoadInfo =
-        GetDocument()->GetChannel()->GetLoadInfo();
+    nsCOMPtr<nsILoadInfo> oldLoadInfo = GetDocument()->GetChannel()->LoadInfo();
     loadInfo->SetOpenerPolicy(oldLoadInfo->GetOpenerPolicy());
   }
 
   OriginAttributes attrs;
 
   // Inherit origin attributes from PrincipalToInherit if inheritAttrs is
   // true. Otherwise we just use the origin attributes from docshell.
   if (inheritAttrs) {
@@ -11288,39 +11283,37 @@ nsresult nsDocShell::AddToSessionHistory
       rv = httpChannel->GetReferrer(getter_AddRefs(referrerURI));
       MOZ_ASSERT(NS_SUCCEEDED(rv));
       rv = httpChannel->GetReferrerPolicy(&referrerPolicy);
       MOZ_ASSERT(NS_SUCCEEDED(rv));
 
       discardLayoutState = ShouldDiscardLayoutState(httpChannel);
     }
 
-    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-    if (loadInfo) {
-      if (!triggeringPrincipal) {
-        triggeringPrincipal = loadInfo->TriggeringPrincipal();
-      }
-
-      loadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
-
-      // For now keep storing just the principal in the SHEntry.
-      if (!principalToInherit) {
-        if (loadInfo->GetLoadingSandboxed()) {
-          if (loadInfo->LoadingPrincipal()) {
-            principalToInherit = NullPrincipal::CreateWithInheritedAttributes(
-                loadInfo->LoadingPrincipal());
-          } else {
-            // get the OriginAttributes
-            OriginAttributes attrs;
-            loadInfo->GetOriginAttributes(&attrs);
-            principalToInherit = NullPrincipal::Create(attrs);
-          }
+    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+    if (!triggeringPrincipal) {
+      triggeringPrincipal = loadInfo->TriggeringPrincipal();
+    }
+
+    loadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
+
+    // For now keep storing just the principal in the SHEntry.
+    if (!principalToInherit) {
+      if (loadInfo->GetLoadingSandboxed()) {
+        if (loadInfo->LoadingPrincipal()) {
+          principalToInherit = NullPrincipal::CreateWithInheritedAttributes(
+              loadInfo->LoadingPrincipal());
         } else {
-          principalToInherit = loadInfo->PrincipalToInherit();
+          // get the OriginAttributes
+          OriginAttributes attrs;
+          loadInfo->GetOriginAttributes(&attrs);
+          principalToInherit = NullPrincipal::Create(attrs);
         }
+      } else {
+        principalToInherit = loadInfo->PrincipalToInherit();
       }
     }
   }
 
   // Title is set in nsDocShell::SetTitle()
   entry->Create(aURI,                 // uri
                 EmptyString(),        // Title
                 inputStream,          // Post data stream
--- a/docshell/base/nsDocShellLoadState.cpp
+++ b/docshell/base/nsDocShellLoadState.cpp
@@ -88,20 +88,17 @@ nsresult nsDocShellLoadState::CreateFrom
   // nsDocShellLoadState.
   nsCOMPtr<nsIURI> originalUri;
   rv = channel->GetOriginalURI(getter_AddRefs(originalUri));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   loadState->SetOriginalURI(originalUri);
 
-  nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-  if (NS_WARN_IF(!loadInfo)) {
-    return NS_ERROR_FAILURE;
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
   loadState->SetTriggeringPrincipal(loadInfo->TriggeringPrincipal());
 
   // Return the newly created loadState.
   loadState.forget(aResult);
   return NS_OK;
 }
 
 nsIReferrerInfo* nsDocShellLoadState::GetReferrerInfo() const {
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -2414,17 +2414,17 @@ static void WarnIfSandboxIneffective(nsI
     nsContentUtils::ReportToConsole(
         nsIScriptError::warningFlag, NS_LITERAL_CSTRING("Iframe Sandbox"),
         parentDocument, nsContentUtils::eSECURITY_PROPERTIES,
         "BothAllowScriptsAndSameOriginPresent", nullptr, 0, iframeUri);
   }
 }
 
 bool Document::IsSynthesized() {
-  nsCOMPtr<nsILoadInfo> loadInfo = mChannel ? mChannel->GetLoadInfo() : nullptr;
+  nsCOMPtr<nsILoadInfo> loadInfo = mChannel ? mChannel->LoadInfo() : nullptr;
   return loadInfo && loadInfo->GetServiceWorkerTaintingSynthesized();
 }
 
 // static
 bool Document::IsCallerChromeOrAddon(JSContext* aCx, JSObject* aObject) {
   nsIPrincipal* principal = nsContentUtils::SubjectPrincipal(aCx);
   return principal && (nsContentUtils::IsSystemPrincipal(principal) ||
                        principal->GetIsAddonOrExpandedAddonPrincipal());
@@ -2514,18 +2514,18 @@ nsresult Document::StartDocumentLoad(con
   }
 
   // If this document is being loaded by a docshell, copy its sandbox flags
   // to the document, and store the fullscreen enabled flag. These are
   // immutable after being set here.
   nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(aContainer);
 
   // If this is an error page, don't inherit sandbox flags from docshell
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (docShell && !(loadInfo && loadInfo->GetLoadErrorPage())) {
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+  if (docShell && !loadInfo->GetLoadErrorPage()) {
     nsresult rv = docShell->GetSandboxFlags(&mSandboxFlags);
     NS_ENSURE_SUCCESS(rv, rv);
     WarnIfSandboxIneffective(docShell, mSandboxFlags, GetChannel());
   }
 
   // The CSP directive upgrade-insecure-requests not only applies to the
   // toplevel document, but also to nested documents. Let's propagate that
   // flag from the parent to the nested document.
@@ -2662,18 +2662,18 @@ nsresult Document::InitCSP(nsIChannel* a
   NS_ConvertASCIItoUTF16 cspROHeaderValue(tCspROHeaderValue);
 
   // Check if this is a document from a WebExtension.
   nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
   auto addonPolicy = BasePrincipal::Cast(principal)->AddonPolicy();
 
   // Check if this is a signed content to apply default CSP.
   bool applySignedContentCSP = false;
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (loadInfo && loadInfo->GetVerifySignedContent()) {
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+  if (loadInfo->GetVerifySignedContent()) {
     applySignedContentCSP = true;
   }
 
   // If there's no CSP to apply, go ahead and return early
   if (!addonPolicy && !applySignedContentCSP && cspHeaderValue.IsEmpty() &&
       cspROHeaderValue.IsEmpty()) {
     if (MOZ_LOG_TEST(gCspPRLog, LogLevel::Debug)) {
       nsCOMPtr<nsIURI> chanURI;
@@ -7418,23 +7418,20 @@ bool Document::CanSavePresentation(nsIRe
       nsCOMPtr<nsISupports> elem;
       requests->GetNext(getter_AddRefs(elem));
 
       nsCOMPtr<nsIRequest> request = do_QueryInterface(elem);
       if (request && request != aNewRequest && request != baseChannel) {
         // Favicon loads don't need to block caching.
         nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
         if (channel) {
-          nsCOMPtr<nsILoadInfo> li;
-          channel->GetLoadInfo(getter_AddRefs(li));
-          if (li) {
-            if (li->InternalContentPolicyType() ==
-                nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON) {
-              continue;
-            }
+          nsCOMPtr<nsILoadInfo> li = channel->LoadInfo();
+          if (li->InternalContentPolicyType() ==
+              nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON) {
+            continue;
           }
         }
 #ifdef DEBUG_PAGE_CACHE
         nsAutoCString requestName, docSpec;
         request->GetName(requestName);
         if (mDocumentURI) mDocumentURI->GetSpec(docSpec);
 
         printf("document %s has request %s\n", docSpec.get(),
@@ -11716,18 +11713,18 @@ void Document::SetUserHasInteracted() {
   MaybeStoreUserInteractionAsPermission();
 
   if (mUserHasInteracted) {
     return;
   }
 
   mUserHasInteracted = true;
 
-  nsCOMPtr<nsILoadInfo> loadInfo = mChannel ? mChannel->GetLoadInfo() : nullptr;
-  if (loadInfo) {
+  if (mChannel) {
+    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
     loadInfo->SetDocumentHasUserInteracted(true);
   }
 
   MaybeAllowStorageForOpenerAfterUserInteraction();
 }
 
 BrowsingContext* Document::GetBrowsingContext() const {
   nsPIDOMWindowOuter* outer = GetWindow();
--- a/dom/base/ThirdPartyUtil.cpp
+++ b/dom/base/ThirdPartyUtil.cpp
@@ -235,17 +235,17 @@ ThirdPartyUtil::IsThirdPartyChannel(nsIC
   rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI));
   if (NS_FAILED(rv)) return rv;
 
   nsAutoCString channelDomain;
   rv = GetBaseDomain(channelURI, channelDomain);
   if (NS_FAILED(rv)) return rv;
 
   if (!doForce) {
-    if (nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo()) {
+    if (nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo()) {
       parentIsThird = loadInfo->GetIsInThirdPartyContext();
       if (!parentIsThird && loadInfo->GetExternalContentPolicyType() !=
                                 nsIContentPolicy::TYPE_DOCUMENT) {
         // Check if the channel itself is third-party to its own requestor.
         // Unforunately, we have to go through the loading principal.
         nsCOMPtr<nsIURI> parentURI;
         rv = loadInfo->LoadingPrincipal()->GetURI(getter_AddRefs(parentURI));
         if (NS_SUCCEEDED(rv) && parentURI) {
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -8117,20 +8117,17 @@ net::ReferrerPolicy nsContentUtils::GetR
 // static
 bool nsContentUtils::IsNonSubresourceRequest(nsIChannel* aChannel) {
   nsLoadFlags loadFlags = 0;
   aChannel->GetLoadFlags(&loadFlags);
   if (loadFlags & nsIChannel::LOAD_DOCUMENT_URI) {
     return true;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo) {
-    return false;
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   nsContentPolicyType type = loadInfo->InternalContentPolicyType();
   return IsNonSubresourceInternalPolicyType(type);
 }
 
 // static
 bool nsContentUtils::IsNonSubresourceInternalPolicyType(
     nsContentPolicyType aType) {
   return aType == nsIContentPolicy::TYPE_DOCUMENT ||
@@ -9805,20 +9802,17 @@ nsContentUtils::LookupCustomElementDefin
   rv = aChannel->GetURI(getter_AddRefs(uri));
   NS_ENSURE_SUCCESS(rv, false);
   NS_ENSURE_TRUE(uri, false);
 
   nsCOMPtr<nsIURI> referrer;
   rv = aChannel->GetReferrer(getter_AddRefs(referrer));
   NS_ENSURE_SUCCESS(rv, false);
 
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo) {
-    return false;
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   nsCOMPtr<nsIPrincipal> triggeringPrincipal = loadInfo->TriggeringPrincipal();
 
   // Get the channel's load flags, and use them to generate nsIWebNavigation
   // load flags. We want to make sure to propagate the refresh and cache busting
   // flags.
   nsLoadFlags channelLoadFlags;
   aChannel->GetLoadFlags(&channelLoadFlags);
 
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -1713,17 +1713,17 @@ nsresult nsGlobalWindowInner::EnsureClie
       bool isData = false;
       bool isBlob = false;
       ignoreLoadInfo =
           (NS_SUCCEEDED(uri->SchemeIs("data", &isData)) && isData) ||
           (NS_SUCCEEDED(uri->SchemeIs("blob", &isBlob)) && isBlob);
     }
 
     if (!ignoreLoadInfo) {
-      loadInfo = channel->GetLoadInfo();
+      loadInfo = channel->LoadInfo();
     }
   }
 
   // Take the initial client source from the docshell immediately.  Even if we
   // don't end up using it here we should consume it.
   UniquePtr<ClientSource> initialClientSource;
   nsIDocShell* docshell = GetDocShell();
   if (docshell) {
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -5511,21 +5511,20 @@ void nsGlobalWindowOuter::NotifyContentB
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 }
 
 // static
 bool nsGlobalWindowOuter::SameLoadingURI(Document* aDoc, nsIChannel* aChannel) {
   nsCOMPtr<nsIURI> docURI = aDoc->GetDocumentURI();
-  nsCOMPtr<nsILoadInfo> channelLoadInfo = aChannel->GetLoadInfo();
-  if (!channelLoadInfo || !docURI) {
+  if (!docURI) {
     return false;
   }
-
+  nsCOMPtr<nsILoadInfo> channelLoadInfo = aChannel->LoadInfo();
   nsCOMPtr<nsIPrincipal> channelLoadingPrincipal =
       channelLoadInfo->LoadingPrincipal();
   if (!channelLoadingPrincipal) {
     // TYPE_DOCUMENT loads will not have a channelLoadingPrincipal. But top
     // level loads should not be blocked by Tracking Protection, so we will
     // return false
     return false;
   }
--- a/dom/base/nsNodeInfoManager.cpp
+++ b/dom/base/nsNodeInfoManager.cpp
@@ -326,17 +326,17 @@ bool nsNodeInfoManager::InternalSVGEnabl
   bool SVGEnabled = false;
 
   if (nsmgr && !nsmgr->mSVGDisabled) {
     SVGEnabled = true;
   } else {
     nsCOMPtr<nsIChannel> channel = mDocument->GetChannel();
     // We don't have a channel for SVGs constructed inside a SVG script
     if (channel) {
-      loadInfo = channel->GetLoadInfo();
+      loadInfo = channel->LoadInfo();
     }
   }
   bool conclusion =
       (SVGEnabled || nsContentUtils::IsSystemPrincipal(mPrincipal) ||
        (loadInfo &&
         (loadInfo->GetExternalContentPolicyType() ==
              nsIContentPolicy::TYPE_IMAGE ||
          loadInfo->GetExternalContentPolicyType() ==
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -2407,18 +2407,17 @@ nsresult nsObjectLoadingContent::OpenCha
       nullptr,  // aPerformanceStorage
       group,    // aLoadGroup
       shim,     // aCallbacks
       nsIChannel::LOAD_CALL_CONTENT_SNIFFERS | nsIChannel::LOAD_CLASSIFY_URI |
           nsIChannel::LOAD_BYPASS_SERVICE_WORKER |
           nsIRequest::LOAD_HTML_OBJECT_DATA);
   NS_ENSURE_SUCCESS(rv, rv);
   if (inherit) {
-    nsCOMPtr<nsILoadInfo> loadinfo = chan->GetLoadInfo();
-    NS_ENSURE_STATE(loadinfo);
+    nsCOMPtr<nsILoadInfo> loadinfo = chan->LoadInfo();
     loadinfo->SetPrincipalToInherit(thisContent->NodePrincipal());
   }
 
   // Referrer
   nsCOMPtr<nsIHttpChannel> httpChan(do_QueryInterface(chan));
   if (httpChan) {
     rv = httpChan->SetReferrerWithPolicy(doc->GetDocumentURI(),
                                          doc->GetReferrerPolicy());
--- a/dom/base/nsSyncLoadService.cpp
+++ b/dom/base/nsSyncLoadService.cpp
@@ -130,24 +130,22 @@ nsresult nsSyncLoader::LoadDocument(nsIC
   nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(mChannel);
   if (http) {
     rv = http->SetRequestHeader(
         NS_LITERAL_CSTRING("Accept"),
         NS_LITERAL_CSTRING(
             "text/xml,application/xml,application/xhtml+xml,*/*;q=0.1"),
         false);
     MOZ_ASSERT(NS_SUCCEEDED(rv));
-    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-    if (loadInfo) {
-      nsCOMPtr<nsIURI> loaderUri;
-      loadInfo->TriggeringPrincipal()->GetURI(getter_AddRefs(loaderUri));
-      if (loaderUri) {
-        rv = http->SetReferrerWithPolicy(loaderUri, aReferrerPolicy);
-        MOZ_ASSERT(NS_SUCCEEDED(rv));
-      }
+    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+    nsCOMPtr<nsIURI> loaderUri;
+    loadInfo->TriggeringPrincipal()->GetURI(getter_AddRefs(loaderUri));
+    if (loaderUri) {
+      rv = http->SetReferrerWithPolicy(loaderUri, aReferrerPolicy);
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
     }
   }
 
   // Hook us up to listen to redirects and the like.
   // Do this before setting up the cross-site proxy since
   // that installs its own proxies.
   mChannel->SetNotificationCallbacks(this);
 
--- a/dom/clients/manager/ClientChannelHelper.cpp
+++ b/dom/clients/manager/ClientChannelHelper.cpp
@@ -50,29 +50,24 @@ class ClientChannelHelper final : public
   }
 
   NS_IMETHOD
   AsyncOnChannelRedirect(nsIChannel* aOldChannel, nsIChannel* aNewChannel,
                          uint32_t aFlags,
                          nsIAsyncVerifyRedirectCallback* aCallback) override {
     MOZ_ASSERT(NS_IsMainThread());
 
-    nsCOMPtr<nsILoadInfo> oldLoadInfo;
-    nsresult rv = aOldChannel->GetLoadInfo(getter_AddRefs(oldLoadInfo));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsILoadInfo> newLoadInfo;
-    rv = aNewChannel->GetLoadInfo(getter_AddRefs(newLoadInfo));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    rv = nsContentUtils::CheckSameOrigin(aOldChannel, aNewChannel);
+    nsresult rv = nsContentUtils::CheckSameOrigin(aOldChannel, aNewChannel);
     if (NS_WARN_IF(NS_FAILED(rv) && rv != NS_ERROR_DOM_BAD_URI)) {
       return rv;
     }
 
+    nsCOMPtr<nsILoadInfo> oldLoadInfo = aOldChannel->LoadInfo();
+    nsCOMPtr<nsILoadInfo> newLoadInfo = aNewChannel->LoadInfo();
+
     UniquePtr<ClientSource> reservedClient =
         oldLoadInfo->TakeReservedClientSource();
 
     // If its a same-origin redirect we just move our reserved client to the
     // new channel.
     if (NS_SUCCEEDED(rv)) {
       if (reservedClient) {
         newLoadInfo->GiveReservedClientSource(std::move(reservedClient));
@@ -176,18 +171,17 @@ nsresult AddClientChannelHelper(nsIChann
                                 nsISerialEventTarget* aEventTarget) {
   MOZ_ASSERT(NS_IsMainThread());
 
   Maybe<ClientInfo> initialClientInfo(std::move(aInitialClientInfo));
   Maybe<ClientInfo> reservedClientInfo(std::move(aReservedClientInfo));
   MOZ_DIAGNOSTIC_ASSERT(reservedClientInfo.isNothing() ||
                         initialClientInfo.isNothing());
 
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
 
   nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
   NS_ENSURE_TRUE(ssm, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIPrincipal> channelPrincipal;
   nsresult rv = ssm->GetChannelResultPrincipal(
       aChannel, getter_AddRefs(channelPrincipal));
   NS_ENSURE_SUCCESS(rv, rv);
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -526,21 +526,17 @@ nsresult FetchDriver::HttpFetch(
     rv = NS_NewChannel(getter_AddRefs(chan), uri, mPrincipal, secFlags,
                        mRequest->ContentPolicyType(), mPerformanceStorage,
                        mLoadGroup, nullptr, /* aCallbacks */
                        loadFlags, ios);
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mCSPEventListener) {
-    nsCOMPtr<nsILoadInfo> loadInfo = chan->GetLoadInfo();
-    if (NS_WARN_IF(!loadInfo)) {
-      return NS_ERROR_UNEXPECTED;
-    }
-
+    nsCOMPtr<nsILoadInfo> loadInfo = chan->LoadInfo();
     rv = loadInfo->SetCspEventListener(mCSPEventListener);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Insert ourselves into the notification callbacks chain so we can set
   // headers on redirects.
 #ifdef DEBUG
   {
@@ -583,17 +579,17 @@ nsresult FetchDriver::HttpFetch(
         mRequest->GetEnvironmentReferrerPolicy();
     if (mRequest->ReferrerPolicy_() == ReferrerPolicy::_empty) {
       mRequest->SetReferrerPolicy(net_referrerPolicy);
     }
     // Step 6 of https://fetch.spec.whatwg.org/#main-fetch
     // If request’s referrer policy is the empty string,
     // then set request’s referrer policy to the user-set default policy.
     if (mRequest->ReferrerPolicy_() == ReferrerPolicy::_empty) {
-      nsCOMPtr<nsILoadInfo> loadInfo = httpChan->GetLoadInfo();
+      nsCOMPtr<nsILoadInfo> loadInfo = httpChan->LoadInfo();
       bool isPrivate = loadInfo->GetOriginAttributes().mPrivateBrowsingId > 0;
       net::ReferrerPolicy referrerPolicy = static_cast<net::ReferrerPolicy>(
           NS_GetDefaultReferrerPolicy(isPrivate));
       mRequest->SetReferrerPolicy(referrerPolicy);
     }
 
     rv = FetchUtil::SetRequestReferrer(mPrincipal, mDocument, httpChan,
                                        mRequest);
@@ -668,20 +664,18 @@ nsresult FetchDriver::HttpFetch(
   // If preflight is required, start a "CORS preflight fetch"
   // https://fetch.spec.whatwg.org/#cors-preflight-fetch-0. All the
   // implementation is handled by the http channel calling into
   // nsCORSListenerProxy. We just inform it which unsafe headers are included
   // in the request.
   if (mRequest->Mode() == RequestMode::Cors) {
     AutoTArray<nsCString, 5> unsafeHeaders;
     mRequest->Headers()->GetUnsafeHeaders(unsafeHeaders);
-    nsCOMPtr<nsILoadInfo> loadInfo = chan->GetLoadInfo();
-    if (loadInfo) {
-      loadInfo->SetCorsPreflightInfo(unsafeHeaders, false);
-    }
+    nsCOMPtr<nsILoadInfo> loadInfo = chan->LoadInfo();
+    loadInfo->SetCorsPreflightInfo(unsafeHeaders, false);
   }
 
   if (mIsTrackingFetch && nsContentUtils::IsTailingEnabled() && cos) {
     cos->AddClassFlags(nsIClassOfService::Throttleable |
                        nsIClassOfService::Tail);
   }
 
   if (mIsTrackingFetch &&
@@ -976,23 +970,17 @@ FetchDriver::OnStartRequest(nsIRequest* 
   nsCOMPtr<nsIURI> channelURI;
   rv = channel->GetURI(getter_AddRefs(channelURI));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     FailWithNetworkError(rv);
     // Cancel request.
     return rv;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo;
-  rv = channel->GetLoadInfo(getter_AddRefs(loadInfo));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    FailWithNetworkError(rv);
-    return rv;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
   // Propagate any tainting from the channel back to our response here.  This
   // step is not reflected in the spec because the spec is written such that
   // FetchEvent.respondWith() just passes the already-tainted Response back to
   // the outer fetch().  In gecko, however, we serialize the Response through
   // the channel and must regenerate the tainting from the channel in the
   // interception case.
   mRequest->MaybeIncreaseResponseTainting(loadInfo->GetTainting());
 
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1288,22 +1288,20 @@ class HTMLMediaElement::ChannelLoader fi
 
     if (NS_FAILED(rv)) {
       // Notify load error so the element will try next resource candidate.
       aElement->NotifyLoadError(NS_LITERAL_CSTRING("Fail to create channel"));
       return;
     }
 
     if (setAttrs) {
-      nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-      if (loadInfo) {
-        // The function simply returns NS_OK, so we ignore the return value.
-        Unused << loadInfo->SetOriginAttributes(
-            triggeringPrincipal->OriginAttributesRef());
-      }
+      nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+      // The function simply returns NS_OK, so we ignore the return value.
+      Unused << loadInfo->SetOriginAttributes(
+          triggeringPrincipal->OriginAttributesRef());
     }
 
     nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(channel));
     if (cos) {
       if (aElement->mUseUrgentStartForChannel) {
         cos->AddClassFlags(nsIClassOfService::UrgentStart);
 
         // Reset the flag to avoid loading again without initiated by user
--- a/dom/html/ImageDocument.cpp
+++ b/dom/html/ImageDocument.cpp
@@ -82,31 +82,31 @@ ImageListener::OnStartRequest(nsIRequest
 
   // Do a ShouldProcess check to see whether to keep loading the image.
   nsCOMPtr<nsIURI> channelURI;
   channel->GetURI(getter_AddRefs(channelURI));
 
   nsAutoCString mimeType;
   channel->GetContentType(mimeType);
 
-  nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
+  nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
   // query the corresponding arguments for the channel loadinfo and pass
   // it on to the temporary loadinfo used for content policy checks.
   nsCOMPtr<nsINode> requestingNode = domWindow->GetFrameElementInternal();
   nsCOMPtr<nsIPrincipal> loadingPrincipal;
   if (requestingNode) {
     loadingPrincipal = requestingNode->NodePrincipal();
   } else {
     nsContentUtils::GetSecurityManager()->GetChannelResultPrincipal(
         channel, getter_AddRefs(loadingPrincipal));
   }
 
   nsCOMPtr<nsILoadInfo> secCheckLoadInfo = new net::LoadInfo(
-      loadingPrincipal, loadInfo ? loadInfo->TriggeringPrincipal() : nullptr,
-      requestingNode, nsILoadInfo::SEC_ONLY_FOR_EXPLICIT_CONTENTSEC_CHECK,
+      loadingPrincipal, loadInfo->TriggeringPrincipal(), requestingNode,
+      nsILoadInfo::SEC_ONLY_FOR_EXPLICIT_CONTENTSEC_CHECK,
       nsIContentPolicy::TYPE_INTERNAL_IMAGE);
 
   int16_t decision = nsIContentPolicy::ACCEPT;
   nsresult rv = NS_CheckContentProcessPolicy(
       channelURI, secCheckLoadInfo, mimeType, &decision,
       nsContentUtils::GetContentPolicy());
 
   if (NS_FAILED(rv) || NS_CP_REJECTED(decision)) {
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -1918,18 +1918,17 @@ nsresult nsHTMLDocument::CreateAndAddWyc
   // Create the nsIWyciwygChannel to store out-of-band
   // document.write() script to cache
   nsCOMPtr<nsIChannel> channel;
   // Create a wyciwyg Channel
   rv = NS_NewChannel(getter_AddRefs(channel), wcwgURI, NodePrincipal(),
                      nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL,
                      nsIContentPolicy::TYPE_OTHER);
   NS_ENSURE_SUCCESS(rv, rv);
-  nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-  NS_ENSURE_STATE(loadInfo);
+  nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
   loadInfo->SetPrincipalToInherit(NodePrincipal());
 
   mWyciwygChannel = do_QueryInterface(channel);
 
   mWyciwygChannel->SetSecurityInfo(mSecurityInfo);
 
   // Note: we want to treat this like a "previous document" hint so that,
   // e.g. a <meta> tag in the document.write content can override it.
--- a/dom/jsurl/nsJSProtocolHandler.cpp
+++ b/dom/jsurl/nsJSProtocolHandler.cpp
@@ -139,19 +139,18 @@ nsresult nsJSThunk::EvaluateScript(
 
   NS_ENSURE_ARG_POINTER(aChannel);
 
   // Get principal of code for execution
   nsCOMPtr<nsISupports> owner;
   aChannel->GetOwner(getter_AddRefs(owner));
   nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(owner);
   if (!principal) {
-    nsCOMPtr<nsILoadInfo> loadInfo;
-    aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
-    if (loadInfo && loadInfo->GetForceInheritPrincipal()) {
+    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+    if (loadInfo->GetForceInheritPrincipal()) {
       principal = loadInfo->FindPrincipalToInherit(aChannel);
     } else {
       // No execution without a principal!
       NS_ASSERTION(!owner, "Non-principal owner?");
       NS_WARNING("No principal to execute JS with");
       return NS_ERROR_DOM_RETVAL_UNDEFINED;
     }
   }
@@ -504,17 +503,17 @@ nsJSChannel::AsyncOpen(nsIStreamListener
 
   nsCOMPtr<nsIStreamListener> listener = aListener;
   nsresult rv =
       nsContentSecurityManager::doContentSecurityCheck(this, listener);
   NS_ENSURE_SUCCESS(rv, rv);
 
 #ifdef DEBUG
   {
-    nsCOMPtr<nsILoadInfo> loadInfo = nsIChannel::GetLoadInfo();
+    nsCOMPtr<nsILoadInfo> loadInfo = nsIChannel::LoadInfo();
     MOZ_ASSERT(!loadInfo || loadInfo->GetSecurityMode() == 0 ||
                    loadInfo->GetInitialSecurityCheckDone(),
                "security flags in loadInfo but asyncOpen() not called");
   }
 #endif
 
   // First make sure that we have a usable inner window; we'll want to make
   // sure that we execute against that inner and no other.
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -760,22 +760,20 @@ nsresult ChannelMediaResource::RecreateC
       securityFlags, contentPolicyType,
       nullptr,  // aPerformanceStorage
       loadGroup,
       nullptr,  // aCallbacks
       loadFlags);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (setAttrs) {
-    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-    if (loadInfo) {
-      // The function simply returns NS_OK, so we ignore the return value.
-      Unused << loadInfo->SetOriginAttributes(
-          triggeringPrincipal->OriginAttributesRef());
-    }
+    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
+    // The function simply returns NS_OK, so we ignore the return value.
+    Unused << loadInfo->SetOriginAttributes(
+        triggeringPrincipal->OriginAttributesRef());
   }
 
   nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(mChannel));
   if (cos) {
     // Unconditionally disable throttling since we want the media to fluently
     // play even when we switch the tab to background.
     cos->AddClassFlags(nsIClassOfService::DontThrottle);
   }
--- a/dom/performance/PerformanceTiming.cpp
+++ b/dom/performance/PerformanceTiming.cpp
@@ -262,21 +262,17 @@ DOMTimeMilliSec PerformanceTiming::Fetch
 
 bool PerformanceTimingData::CheckAllowedOrigin(nsIHttpChannel* aResourceChannel,
                                                nsITimedChannel* aChannel) {
   if (!IsInitialized()) {
     return false;
   }
 
   // Check that the current document passes the ckeck.
-  nsCOMPtr<nsILoadInfo> loadInfo;
-  aResourceChannel->GetLoadInfo(getter_AddRefs(loadInfo));
-  if (!loadInfo) {
-    return false;
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = aResourceChannel->LoadInfo();
 
   // TYPE_DOCUMENT loads have no loadingPrincipal.
   if (loadInfo->GetExternalContentPolicyType() ==
       nsIContentPolicy::TYPE_DOCUMENT) {
     return true;
   }
 
   nsCOMPtr<nsIPrincipal> principal = loadInfo->LoadingPrincipal();
--- a/dom/plugins/base/nsPluginStreamListenerPeer.cpp
+++ b/dom/plugins/base/nsPluginStreamListenerPeer.cpp
@@ -162,17 +162,17 @@ nsPluginStreamListenerPeer::OnStartReque
     }
   }
 
   nsAutoCString contentType;
   rv = channel->GetContentType(contentType);
   if (NS_FAILED(rv)) return rv;
 
   // Check ShouldProcess with content policy
-  nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
+  nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
 
   int16_t shouldLoad = nsIContentPolicy::ACCEPT;
   rv = NS_CheckContentProcessPolicy(mURL, loadInfo, contentType, &shouldLoad);
   if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
     mRequestFailed = true;
     return NS_ERROR_CONTENT_BLOCKED;
   }
 
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -1270,17 +1270,17 @@ nsresult ScriptLoader::StartLoad(ScriptL
 
   // snapshot the nonce at load start time for performing CSP checks
   if (contentPolicyType == nsIContentPolicy::TYPE_INTERNAL_SCRIPT ||
       contentPolicyType == nsIContentPolicy::TYPE_INTERNAL_MODULE) {
     nsCOMPtr<Element> element = do_QueryInterface(context);
     if (element && element->IsHTMLElement()) {
       nsAutoString cspNonce;
       element->GetAttribute(NS_LITERAL_STRING("nonce"), cspNonce);
-      nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
+      nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
       loadInfo->SetCspNonce(cspNonce);
     }
   }
 
   // To avoid decoding issues, the build-id is part of the JSBytecodeMimeType
   // constant.
   aRequest->mCacheInfo = nullptr;
   nsCOMPtr<nsICacheInfoChannel> cic(do_QueryInterface(channel));
@@ -3203,19 +3203,19 @@ nsresult ScriptLoader::VerifySRI(ScriptL
           nsContentUtils::GetInnerWindowID(channelRequest));
     } else {
       mReporter->FlushConsoleReports(mDocument);
     }
     if (NS_FAILED(rv)) {
       rv = NS_ERROR_SRI_CORRUPT;
     }
   } else {
-    nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-
-    if (loadInfo && loadInfo->GetEnforceSRI()) {
+    nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+
+    if (loadInfo->GetEnforceSRI()) {
       MOZ_LOG(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug,
               ("ScriptLoader::OnStreamComplete, required SRI not found"));
       nsCOMPtr<nsIContentSecurityPolicy> csp;
       loadInfo->LoadingPrincipal()->GetCsp(getter_AddRefs(csp));
       nsAutoCString violationURISpec;
       mDocument->GetDocumentURI()->GetAsciiSpec(violationURISpec);
       uint32_t lineNo =
           aRequest->Element() ? aRequest->Element()->GetScriptLineNumber() : 0;
--- a/dom/security/FramingChecker.cpp
+++ b/dom/security/FramingChecker.cpp
@@ -179,20 +179,19 @@ static bool ShouldIgnoreFrameOptions(nsI
   csp->GetEnforcesFrameAncestors(&enforcesFrameAncestors);
   if (!enforcesFrameAncestors) {
     // if CSP does not contain frame-ancestors, then there
     // is nothing to do here.
     return false;
   }
 
   // log warning to console that xfo is ignored because of CSP
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  uint64_t innerWindowID = loadInfo ? loadInfo->GetInnerWindowID() : 0;
-  bool privateWindow =
-      loadInfo ? !!loadInfo->GetOriginAttributes().mPrivateBrowsingId : false;
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+  uint64_t innerWindowID = loadInfo->GetInnerWindowID();
+  bool privateWindow = !!loadInfo->GetOriginAttributes().mPrivateBrowsingId;
   const char16_t* params[] = {u"x-frame-options", u"frame-ancestors"};
   CSP_LogLocalizedStr("IgnoringSrcBecauseOfDirective", params,
                       ArrayLength(params),
                       EmptyString(),  // no sourcefile
                       EmptyString(),  // no scriptsample
                       0,              // no linenumber
                       0,              // no columnnumber
                       nsIScriptError::warningFlag,
@@ -247,19 +246,17 @@ static bool ShouldIgnoreFrameOptions(nsI
   while (tokenizer.hasMoreTokens()) {
     const nsAString& tok = tokenizer.nextToken();
     if (!CheckOneFrameOptionsPolicy(httpChannel, tok, aDocShell)) {
       // cancel the load and display about:blank
       httpChannel->Cancel(NS_BINDING_ABORTED);
       if (aDocShell) {
         nsCOMPtr<nsIWebNavigation> webNav(do_QueryObject(aDocShell));
         if (webNav) {
-          nsCOMPtr<nsILoadInfo> loadInfo = httpChannel->GetLoadInfo();
-          MOZ_ASSERT(loadInfo);
-
+          nsCOMPtr<nsILoadInfo> loadInfo = httpChannel->LoadInfo();
           RefPtr<NullPrincipal> principal =
               NullPrincipal::CreateWithInheritedAttributes(
                   loadInfo->TriggeringPrincipal());
 
           LoadURIOptions loadURIOptions;
           loadURIOptions.mTriggeringPrincipal = principal;
           webNav->LoadURI(NS_LITERAL_STRING("about:blank"), loadURIOptions);
         }
--- a/dom/security/SRICheck.cpp
+++ b/dom/security/SRICheck.cpp
@@ -322,18 +322,17 @@ nsresult SRICheckDataVerifier::Verify(co
     request->GetName(requestURL);
     SRILOG(("SRICheckDataVerifier::Verify, url=%s (length=%zu)",
             requestURL.get(), mBytesHashed));
   }
 
   nsresult rv = Finish();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   LoadTainting tainting = loadInfo->GetTainting();
 
   if (NS_FAILED(IsEligible(aChannel, tainting, aSourceFileURI, aReporter))) {
     return NS_ERROR_SRI_NOT_ELIGIBLE;
   }
 
   if (mInvalidMetadata) {
     return NS_OK;  // ignore invalid metadata for forward-compatibility
--- a/dom/security/nsCSPService.cpp
+++ b/dom/security/nsCSPService.cpp
@@ -255,23 +255,17 @@ CSPService::AsyncOnChannelRedirect(nsICh
                                    nsIChannel *newChannel, uint32_t flags,
                                    nsIAsyncVerifyRedirectCallback *callback) {
   net::nsAsyncRedirectAutoCallback autoCallback(callback);
 
   nsCOMPtr<nsIURI> newUri;
   nsresult rv = newChannel->GetURI(getter_AddRefs(newUri));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsILoadInfo> loadInfo = oldChannel->GetLoadInfo();
-
-  // if no loadInfo on the channel, nothing for us to do
-  if (!loadInfo) {
-    return NS_OK;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = oldChannel->LoadInfo();
   nsCOMPtr<nsICSPEventListener> cspEventListener;
   rv = loadInfo->GetCspEventListener(getter_AddRefs(cspEventListener));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // No need to continue processing if CSP is disabled or if the protocol
   // is *not* subject to CSP.
   // Please note, the correct way to opt-out of CSP using a custom
   // protocolHandler is to set one of the nsIProtocolHandler flags
--- a/dom/security/nsContentSecurityManager.cpp
+++ b/dom/security/nsContentSecurityManager.cpp
@@ -40,20 +40,17 @@ static mozilla::LazyLogModule sCSMLog("C
   // a NullPrincipal. In other cases, e.g. typing a data: URL into
   // the URL-Bar, the triggeringPrincipal is a SystemPrincipal;
   // we don't want to block those loads. Only exception, loads coming
   // from an external applicaton (e.g. Thunderbird) don't load
   // using a codeBasePrincipal, but we want to block those loads.
   if (!mozilla::net::nsIOService::BlockToplevelDataUriNavigations()) {
     return true;
   }
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo) {
-    return true;
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   if (loadInfo->GetExternalContentPolicyType() !=
       nsIContentPolicy::TYPE_DOCUMENT) {
     return true;
   }
   if (loadInfo->GetForceAllowDataURI()) {
     // if the loadinfo explicitly allows the data URI navigation, let's allow it
     // now
     return true;
@@ -110,20 +107,17 @@ static mozilla::LazyLogModule sCSMLog("C
       nsIScriptError::warningFlag, NS_LITERAL_CSTRING("DATA_URI_BLOCKED"), doc,
       nsContentUtils::eSECURITY_PROPERTIES, "BlockTopLevelDataURINavigation",
       params, ArrayLength(params));
   return false;
 }
 
 /* static */ bool nsContentSecurityManager::AllowInsecureRedirectToDataURI(
     nsIChannel* aNewChannel) {
-  nsCOMPtr<nsILoadInfo> loadInfo = aNewChannel->GetLoadInfo();
-  if (!loadInfo) {
-    return true;
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = aNewChannel->LoadInfo();
   if (loadInfo->GetExternalContentPolicyType() !=
       nsIContentPolicy::TYPE_SCRIPT) {
     return true;
   }
   nsCOMPtr<nsIURI> newURI;
   nsresult rv = NS_GetFinalChannelURI(aNewChannel, getter_AddRefs(newURI));
   if (NS_FAILED(rv) || !newURI) {
     return true;
@@ -165,21 +159,17 @@ static mozilla::LazyLogModule sCSMLog("C
     nsIChannel* aChannel) {
   // We dissallow using FTP resources as a subresource almost everywhere.
   // The only valid way to use FTP resources is loading it as
   // a top level document.
   if (!mozilla::net::nsIOService::BlockFTPSubresources()) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo) {
-    return NS_OK;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   nsContentPolicyType type = loadInfo->GetExternalContentPolicyType();
 
   // Allow top-level FTP documents and save-as download of FTP files on
   // HTTP pages.
   if (type == nsIContentPolicy::TYPE_DOCUMENT ||
       type == nsIContentPolicy::TYPE_SAVEAS_DOWNLOAD) {
     return NS_OK;
   }
@@ -788,24 +778,17 @@ static void DebugDoContentSecurityCheck(
  * @param aInAndOutListener
  *    The streamListener that is passed to channel->AsyncOpen() that is now
  * potentially wrappend within nsCORSListenerProxy() and becomes the
  * corsListener that now needs to be set as new streamListener on the channel.
  */
 nsresult nsContentSecurityManager::doContentSecurityCheck(
     nsIChannel* aChannel, nsCOMPtr<nsIStreamListener>& aInAndOutListener) {
   NS_ENSURE_ARG(aChannel);
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-
-  if (!loadInfo) {
-    MOZ_ASSERT(false,
-               "channel needs to have loadInfo to perform security checks");
-    return NS_ERROR_UNEXPECTED;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   if (MOZ_UNLIKELY(MOZ_LOG_TEST(sCSMLog, LogLevel::Debug))) {
     DebugDoContentSecurityCheck(aChannel, loadInfo);
   }
 
   // if dealing with a redirected channel then we have already installed
   // streamlistener and redirect proxies and so we are done.
   if (loadInfo->GetInitialSecurityCheckDone()) {
     return NS_OK;
@@ -839,26 +822,24 @@ nsresult nsContentSecurityManager::doCon
   // all security checks passed - lets allow the load
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsContentSecurityManager::AsyncOnChannelRedirect(
     nsIChannel* aOldChannel, nsIChannel* aNewChannel, uint32_t aRedirFlags,
     nsIAsyncVerifyRedirectCallback* aCb) {
-  nsCOMPtr<nsILoadInfo> loadInfo = aOldChannel->GetLoadInfo();
-  if (loadInfo) {
-    nsresult rv = CheckChannel(aNewChannel);
-    if (NS_SUCCEEDED(rv)) {
-      rv = CheckFTPSubresourceLoad(aNewChannel);
-    }
-    if (NS_FAILED(rv)) {
-      aOldChannel->Cancel(rv);
-      return rv;
-    }
+  nsCOMPtr<nsILoadInfo> loadInfo = aOldChannel->LoadInfo();
+  nsresult rv = CheckChannel(aNewChannel);
+  if (NS_SUCCEEDED(rv)) {
+    rv = CheckFTPSubresourceLoad(aNewChannel);
+  }
+  if (NS_FAILED(rv)) {
+    aOldChannel->Cancel(rv);
+    return rv;
   }
 
   // Also verify that the redirecting server is allowed to redirect to the
   // given URI
   nsCOMPtr<nsIPrincipal> oldPrincipal;
   nsContentUtils::GetSecurityManager()->GetChannelResultPrincipal(
       aOldChannel, getter_AddRefs(oldPrincipal));
 
@@ -871,17 +852,17 @@ nsContentSecurityManager::AsyncOnChannel
     // cancel the old channel and return an error
     aOldChannel->Cancel(NS_ERROR_CONTENT_BLOCKED);
     return NS_ERROR_CONTENT_BLOCKED;
   }
 
   const uint32_t flags =
       nsIScriptSecurityManager::LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT |
       nsIScriptSecurityManager::DISALLOW_SCRIPT;
-  nsresult rv = nsContentUtils::GetSecurityManager()->CheckLoadURIWithPrincipal(
+  rv = nsContentUtils::GetSecurityManager()->CheckLoadURIWithPrincipal(
       oldPrincipal, newURI, flags);
   NS_ENSURE_SUCCESS(rv, rv);
 
   aCb->OnRedirectVerifyCallback(NS_OK);
   return NS_OK;
 }
 
 static void AddLoadFlags(nsIRequest* aRequest, nsLoadFlags aNewFlags) {
@@ -891,19 +872,17 @@ static void AddLoadFlags(nsIRequest* aRe
   aRequest->SetLoadFlags(flags);
 }
 
 /*
  * Check that this channel passes all security checks. Returns an error code
  * if this requesst should not be permitted.
  */
 nsresult nsContentSecurityManager::CheckChannel(nsIChannel* aChannel) {
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  MOZ_ASSERT(loadInfo);
-
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   nsCOMPtr<nsIURI> uri;
   nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsContentPolicyType contentPolicyType =
       loadInfo->GetExternalContentPolicyType();
 
   if (contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT ||
--- a/dom/security/nsMixedContentBlocker.cpp
+++ b/dom/security/nsMixedContentBlocker.cpp
@@ -296,17 +296,17 @@ nsMixedContentBlocker::AsyncOnChannelRed
   rv = aOldChannel->GetURI(getter_AddRefs(oldUri));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIURI> newUri;
   rv = aNewChannel->GetURI(getter_AddRefs(newUri));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Get the loading Info from the old channel
-  nsCOMPtr<nsILoadInfo> loadInfo = aOldChannel->GetLoadInfo();
+  nsCOMPtr<nsILoadInfo> loadInfo = aOldChannel->LoadInfo();
   nsCOMPtr<nsIPrincipal> requestingPrincipal = loadInfo->LoadingPrincipal();
 
   // Since we are calling shouldLoad() directly on redirects, we don't go
   // through the code in nsContentPolicyUtils::NS_CheckContentLoadPolicy().
   // Hence, we have to duplicate parts of it here.
   if (requestingPrincipal) {
     // We check to see if the loadingPrincipal is systemPrincipal and return
     // early if it is
--- a/dom/serviceworkers/ServiceWorkerEvents.cpp
+++ b/dom/serviceworkers/ServiceWorkerEvents.cpp
@@ -267,19 +267,19 @@ class StartResponse final : public Runna
   NS_IMETHOD
   Run() override {
     MOZ_ASSERT(NS_IsMainThread());
 
     nsCOMPtr<nsIChannel> underlyingChannel;
     nsresult rv = mChannel->GetChannel(getter_AddRefs(underlyingChannel));
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(underlyingChannel, NS_ERROR_UNEXPECTED);
-    nsCOMPtr<nsILoadInfo> loadInfo = underlyingChannel->GetLoadInfo();
+    nsCOMPtr<nsILoadInfo> loadInfo = underlyingChannel->LoadInfo();
 
-    if (!loadInfo || !CSPPermitsResponse(loadInfo)) {
+    if (!CSPPermitsResponse(loadInfo)) {
       mChannel->CancelInterception(NS_ERROR_CONTENT_BLOCKED);
       return NS_OK;
     }
 
     ChannelInfo channelInfo;
     if (mInternalResponse->GetChannelInfo().IsInitialized()) {
       channelInfo = mInternalResponse->GetChannelInfo();
     } else {
--- a/dom/serviceworkers/ServiceWorkerInterceptController.cpp
+++ b/dom/serviceworkers/ServiceWorkerInterceptController.cpp
@@ -17,20 +17,17 @@ namespace dom {
 NS_IMPL_ISUPPORTS(ServiceWorkerInterceptController,
                   nsINetworkInterceptController)
 
 NS_IMETHODIMP
 ServiceWorkerInterceptController::ShouldPrepareForIntercept(
     nsIURI* aURI, nsIChannel* aChannel, bool* aShouldIntercept) {
   *aShouldIntercept = false;
 
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo) {
-    return NS_OK;
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
 
   // For subresource requests we base our decision solely on the client's
   // controller value.  Any settings that would have blocked service worker
   // access should have been set before the initial navigation created the
   // window.
   if (!nsContentUtils::IsNonSubresourceRequest(aChannel)) {
     const Maybe<ServiceWorkerDescriptor>& controller =
         loadInfo->GetController();
--- a/dom/serviceworkers/ServiceWorkerManager.cpp
+++ b/dom/serviceworkers/ServiceWorkerManager.cpp
@@ -1868,48 +1868,46 @@ class ContinueDispatchFetchEventRunnable
     rv = channel->GetStatus(&status);
     if (NS_WARN_IF(NS_FAILED(rv) || NS_FAILED(status))) {
       HandleError();
       return NS_OK;
     }
 
     nsString clientId;
     nsString resultingClientId;
-    nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-    if (loadInfo) {
-      char buf[NSID_LENGTH];
-      Maybe<ClientInfo> clientInfo = loadInfo->GetClientInfo();
-      if (clientInfo.isSome()) {
-        clientInfo.ref().Id().ToProvidedString(buf);
-        NS_ConvertASCIItoUTF16 uuid(buf);
-
-        // Remove {} and the null terminator
-        clientId.Assign(Substring(uuid, 1, NSID_LENGTH - 3));
-      }
-
-      // Having an initial or reserved client are mutually exclusive events:
-      // either an initial client is used upon navigating an about:blank
-      // iframe, or a new, reserved environment/client is created (e.g.
-      // upon a top-level navigation). See step 4 of
-      // https://html.spec.whatwg.org/#process-a-navigate-fetch as well as
-      // https://github.com/w3c/ServiceWorker/issues/1228#issuecomment-345132444
-      Maybe<ClientInfo> resulting = loadInfo->GetInitialClientInfo();
-
-      if (resulting.isNothing()) {
-        resulting = loadInfo->GetReservedClientInfo();
-      } else {
-        MOZ_ASSERT(loadInfo->GetReservedClientInfo().isNothing());
-      }
-
-      if (resulting.isSome()) {
-        resulting.ref().Id().ToProvidedString(buf);
-        NS_ConvertASCIItoUTF16 uuid(buf);
-
-        resultingClientId.Assign(Substring(uuid, 1, NSID_LENGTH - 3));
-      }
+    nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+    char buf[NSID_LENGTH];
+    Maybe<ClientInfo> clientInfo = loadInfo->GetClientInfo();
+    if (clientInfo.isSome()) {
+      clientInfo.ref().Id().ToProvidedString(buf);
+      NS_ConvertASCIItoUTF16 uuid(buf);
+
+      // Remove {} and the null terminator
+      clientId.Assign(Substring(uuid, 1, NSID_LENGTH - 3));
+    }
+
+    // Having an initial or reserved client are mutually exclusive events:
+    // either an initial client is used upon navigating an about:blank
+    // iframe, or a new, reserved environment/client is created (e.g.
+    // upon a top-level navigation). See step 4 of
+    // https://html.spec.whatwg.org/#process-a-navigate-fetch as well as
+    // https://github.com/w3c/ServiceWorker/issues/1228#issuecomment-345132444
+    Maybe<ClientInfo> resulting = loadInfo->GetInitialClientInfo();
+
+    if (resulting.isNothing()) {
+      resulting = loadInfo->GetReservedClientInfo();
+    } else {
+      MOZ_ASSERT(loadInfo->GetReservedClientInfo().isNothing());
+    }
+
+    if (resulting.isSome()) {
+      resulting.ref().Id().ToProvidedString(buf);
+      NS_ConvertASCIItoUTF16 uuid(buf);
+
+      resultingClientId.Assign(Substring(uuid, 1, NSID_LENGTH - 3));
     }
 
     rv = mServiceWorkerPrivate->SendFetchEvent(mChannel, mLoadGroup, clientId,
                                                resultingClientId, mIsReload);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       HandleError();
     }
 
@@ -1931,22 +1929,17 @@ void ServiceWorkerManager::DispatchFetch
   }
 
   nsCOMPtr<nsILoadGroup> loadGroup;
   aRv = internalChannel->GetLoadGroup(getter_AddRefs(loadGroup));
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo = internalChannel->GetLoadInfo();
-  if (NS_WARN_IF(!loadInfo)) {
-    aRv.Throw(NS_ERROR_UNEXPECTED);
-    return;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = internalChannel->LoadInfo();
   RefPtr<ServiceWorkerInfo> serviceWorker;
 
   if (!nsContentUtils::IsNonSubresourceRequest(internalChannel)) {
     const Maybe<ServiceWorkerDescriptor>& controller =
         loadInfo->GetController();
     if (NS_WARN_IF(controller.isNothing())) {
       aRv.Throw(NS_ERROR_FAILURE);
       return;
--- a/dom/workers/ScriptLoader.cpp
+++ b/dom/workers/ScriptLoader.cpp
@@ -242,21 +242,17 @@ nsresult ChannelFromScriptURL(nsIPrincip
                          contentPolicyType, performanceStorage, loadGroup,
                          nullptr,  // aCallbacks
                          aLoadFlags, ios);
     }
 
     NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_SECURITY_ERR);
 
     if (cspEventListener) {
-      nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-      if (NS_WARN_IF(!loadInfo)) {
-        return NS_ERROR_UNEXPECTED;
-      }
-
+      nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
       rv = loadInfo->SetCspEventListener(cspEventListener);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   if (nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(channel)) {
     mozilla::net::ReferrerPolicy referrerPolicy =
         parentDoc ? parentDoc->GetReferrerPolicy() : mozilla::net::RP_Unset;
@@ -1151,18 +1147,18 @@ class ScriptLoaderRunnable final : publi
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!filename.IsEmpty()) {
       // This will help callers figure out what their script url resolved to in
       // case of errors.
       aLoadInfo.mURL.Assign(NS_ConvertUTF8toUTF16(filename));
     }
 
-    nsCOMPtr<nsILoadInfo> chanLoadInfo = channel->GetLoadInfo();
-    if (chanLoadInfo && chanLoadInfo->GetEnforceSRI()) {
+    nsCOMPtr<nsILoadInfo> chanLoadInfo = channel->LoadInfo();
+    if (chanLoadInfo->GetEnforceSRI()) {
       // importScripts() and the Worker constructor do not support integrity
       // metadata
       //  (or any fetch options). Until then, we can just block.
       //  If we ever have those data in the future, we'll have to the check to
       //  by using the SRICheck module
       MOZ_LOG(
           SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug,
           ("Scriptloader::Load, SRI required but not supported in workers"));
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -742,23 +742,17 @@ void XMLHttpRequestMainThread::GetRespon
   aResponse.setNull();
 }
 
 bool XMLHttpRequestMainThread::IsCrossSiteCORSRequest() const {
   if (!mChannel) {
     return false;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-  MOZ_ASSERT(loadInfo);
-
-  if (!loadInfo) {
-    return false;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
   return loadInfo->GetTainting() == LoadTainting::CORS;
 }
 
 bool XMLHttpRequestMainThread::IsDeniedCrossSiteCORSRequest() {
   if (IsCrossSiteCORSRequest()) {
     nsresult rv;
     mChannel->GetStatus(&rv);
     if (NS_FAILED(rv)) {
@@ -1473,21 +1467,18 @@ nsresult XMLHttpRequestMainThread::Open(
 }
 
 void XMLHttpRequestMainThread::SetOriginAttributes(
     const OriginAttributesDictionary& aAttrs) {
   MOZ_ASSERT((mState == XMLHttpRequest_Binding::OPENED) && !mFlagSend);
 
   OriginAttributes attrs(aAttrs);
 
-  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-  MOZ_ASSERT(loadInfo);
-  if (loadInfo) {
-    loadInfo->SetOriginAttributes(attrs);
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
+  loadInfo->SetOriginAttributes(attrs);
 }
 
 /*
  * "Copy" from a stream.
  */
 nsresult XMLHttpRequestMainThread::StreamReaderFunc(
     nsIInputStream* in, void* closure, const char* fromRawSegment,
     uint32_t toOffset, uint32_t count, uint32_t* writeCount) {
@@ -1984,22 +1975,19 @@ XMLHttpRequestMainThread::OnStartRequest
                           responseStatus == 304)) {
       mResponseXML->SetSuppressParserErrorConsoleMessages(true);
     }
 
     if (nsContentUtils::IsSystemPrincipal(mPrincipal)) {
       mResponseXML->ForceEnableXULXBL();
     }
 
-    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-    MOZ_ASSERT(loadInfo);
+    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
     bool isCrossSite = false;
-    if (loadInfo) {
-      isCrossSite = loadInfo->GetTainting() != LoadTainting::Basic;
-    }
+    isCrossSite = loadInfo->GetTainting() != LoadTainting::Basic;
 
     if (isCrossSite) {
       nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mResponseXML);
       if (htmlDoc) {
         htmlDoc->DisableCookieAccess();
       }
     }
 
@@ -2360,21 +2348,17 @@ nsresult XMLHttpRequestMainThread::Creat
                        mPerformanceStorage,  // aPerformanceStorage
                        loadGroup,
                        nullptr,  // aCallbacks
                        loadFlags);
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mCSPEventListener) {
-    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-    if (NS_WARN_IF(!loadInfo)) {
-      return NS_ERROR_UNEXPECTED;
-    }
-
+    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
     rv = loadInfo->SetCspEventListener(mCSPEventListener);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));
   if (httpChannel) {
     rv = httpChannel->SetRequestMethod(mRequestMethod);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -2520,20 +2504,18 @@ nsresult XMLHttpRequestMainThread::Initi
     }
   }
 
   // Due to the chrome-only XHR.channel API, we need a hacky way to set the
   // SEC_COOKIES_INCLUDE *after* the channel has been has been created, since
   // .withCredentials can be called after open() is called.
   // Not doing this for privileged system XHRs since those don't use CORS.
   if (!IsSystemXHR() && !mIsAnon && mFlagACwithCredentials) {
-    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-    if (loadInfo) {
-      static_cast<net::LoadInfo*>(loadInfo.get())->SetIncludeCookiesSecFlag();
-    }
+    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
+    static_cast<net::LoadInfo*>(loadInfo.get())->SetIncludeCookiesSecFlag();
   }
 
   // We never let XHR be blocked by head CSS/JS loads to avoid potential
   // deadlock where server generation of CSS/JS requires an XHR signal.
   nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(mChannel));
   if (cos) {
     cos->AddClassFlags(nsIClassOfService::Unblocked);
 
@@ -2586,21 +2568,19 @@ nsresult XMLHttpRequestMainThread::Initi
       contentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE)) {
     mChannel->SetContentType(NS_LITERAL_CSTRING("text/xml"));
   }
 
   // Set up the preflight if needed
   if (!IsSystemXHR()) {
     nsTArray<nsCString> CORSUnsafeHeaders;
     mAuthorRequestHeaders.GetCORSUnsafeHeaders(CORSUnsafeHeaders);
-    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-    if (loadInfo) {
-      loadInfo->SetCorsPreflightInfo(CORSUnsafeHeaders,
-                                     mFlagHadUploadListenersOnSend);
-    }
+    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
+    loadInfo->SetCorsPreflightInfo(CORSUnsafeHeaders,
+                                   mFlagHadUploadListenersOnSend);
   }
 
   // Hook us up to listen to redirects and the like. Only do this very late
   // since this creates a cycle between the channel and us. This cycle has
   // to be manually broken if anything below fails.
   mChannel->GetNotificationCallbacks(getter_AddRefs(mNotificationCallbacks));
   mChannel->SetNotificationCallbacks(this);
 
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -820,21 +820,19 @@ static nsresult NewImageChannel(
       return rv;
     }
 
     if (aPolicyType == nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON) {
       // If this is a favicon loading, we will use the originAttributes from the
       // triggeringPrincipal as the channel's originAttributes. This allows the
       // favicon loading from XUL will use the correct originAttributes.
 
-      nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->GetLoadInfo();
-      if (loadInfo) {
-        rv = loadInfo->SetOriginAttributes(
-            aTriggeringPrincipal->OriginAttributesRef());
-      }
+      nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->LoadInfo();
+      rv = loadInfo->SetOriginAttributes(
+          aTriggeringPrincipal->OriginAttributesRef());
     }
   } else {
     // either we are loading something inside a document, in which case
     // we should always have a requestingNode, or we are loading something
     // outside a document, in which case the triggeringPrincipal and
     // triggeringPrincipal should always be the systemPrincipal.
     // However, there are exceptions: one is Notifications which create a
     // channel in the parent prcoess in which case we can't get a
@@ -853,20 +851,18 @@ static nsresult NewImageChannel(
     // and adjust the private browsing ID based on what kind of load the caller
     // has asked us to perform.
     OriginAttributes attrs;
     if (aTriggeringPrincipal) {
       attrs = aTriggeringPrincipal->OriginAttributesRef();
     }
     attrs.mPrivateBrowsingId = aRespectPrivacy ? 1 : 0;
 
-    nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->GetLoadInfo();
-    if (loadInfo) {
-      rv = loadInfo->SetOriginAttributes(attrs);
-    }
+    nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->LoadInfo();
+    rv = loadInfo->SetOriginAttributes(attrs);
   }
 
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   // only inherit if we have a principal
   *aForcePrincipalCheckForCacheEntry =
@@ -2369,22 +2365,19 @@ nsresult imgLoader::LoadImageWithChannel
   LOG_SCOPE(gImgLog, "imgLoader::LoadImageWithChannel");
   RefPtr<imgRequest> request;
 
   nsCOMPtr<nsIURI> uri;
   channel->GetURI(getter_AddRefs(uri));
   nsCOMPtr<Document> doc = do_QueryInterface(aCX);
 
   NS_ENSURE_TRUE(channel, NS_ERROR_FAILURE);
-  nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-
-  OriginAttributes attrs;
-  if (loadInfo) {
-    attrs = loadInfo->GetOriginAttributes();
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+
+  OriginAttributes attrs = loadInfo->GetOriginAttributes();
 
   nsresult rv;
   ImageCacheKey key(uri, attrs, doc, rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsLoadFlags requestFlags = nsIRequest::LOAD_NORMAL;
   channel->GetLoadFlags(&requestFlags);
 
@@ -2415,22 +2408,20 @@ nsresult imgLoader::LoadImageWithChannel
       // we're getting if the channel is loading from the cache anyways.
       //
       // XXX -- should this be changed? it's pretty much verbatim from the old
       // code, but seems nonsensical.
       //
       // Since aCanMakeNewChannel == false, we don't need to pass content policy
       // type/principal/etc
 
-      nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
+      nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
       // if there is a loadInfo, use the right contentType, otherwise
       // default to the internal image type
-      nsContentPolicyType policyType =
-          loadInfo ? loadInfo->InternalContentPolicyType()
-                   : nsIContentPolicy::TYPE_INTERNAL_IMAGE;
+      nsContentPolicyType policyType = loadInfo->InternalContentPolicyType();
 
       if (ValidateEntry(entry, uri, nullptr, nullptr, RP_Unset, nullptr,
                         aObserver, aCX, doc, requestFlags, policyType, false,
                         nullptr, nullptr, nullptr, imgIRequest::CORS_NONE)) {
         request = entry->GetRequest();
       } else {
         nsCOMPtr<nsICacheInfoChannel> cacheChan(do_QueryInterface(channel));
         bool bUseCacheCopy;
--- a/image/imgRequest.cpp
+++ b/image/imgRequest.cpp
@@ -1195,17 +1195,17 @@ imgRequest::OnRedirectVerifyCallback(nsr
                                     &schemeLocal)) ||
       (!isHttps && !isChrome && !schemeLocal)) {
     MutexAutoLock lock(mMutex);
 
     // The csp directive upgrade-insecure-requests performs an internal redirect
     // to upgrade all requests from http to https before any data is fetched
     // from the network. Do not pollute mHadInsecureRedirect in case of such an
     // internal redirect.
-    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
+    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
     bool upgradeInsecureRequests =
         loadInfo ? loadInfo->GetUpgradeInsecureRequests() ||
                        loadInfo->GetBrowserUpgradeInsecureRequests()
                  : false;
     if (!upgradeInsecureRequests) {
       mHadInsecureRedirect = true;
     }
   }
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -738,18 +738,18 @@ nsresult SheetLoadData::VerifySheetReady
       mLoader->SheetComplete(this, NS_ERROR_NOT_AVAILABLE);
       return NS_OK;
     }
   }
 
   SRIMetadata sriMetadata;
   mSheet->GetIntegrity(sriMetadata);
   if (sriMetadata.IsEmpty()) {
-    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-    if (loadInfo && loadInfo->GetEnforceSRI()) {
+    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+    if (loadInfo->GetEnforceSRI()) {
       LOG(("  Load was blocked by SRI"));
       MOZ_LOG(gSriPRLog, mozilla::LogLevel::Debug,
               ("css::Loader::OnStreamComplete, required SRI not found"));
       mLoader->SheetComplete(this, NS_ERROR_SRI_CORRUPT);
       // log the failed load to web console
       nsCOMPtr<nsIContentSecurityPolicy> csp;
       loadInfo->LoadingPrincipal()->GetCsp(getter_AddRefs(csp));
       nsAutoCString spec;
@@ -1321,17 +1321,17 @@ nsresult Loader::LoadSheet(SheetLoadData
     }
 
     // snapshot the nonce at load start time for performing CSP checks
     if (contentPolicyType == nsIContentPolicy::TYPE_INTERNAL_STYLESHEET) {
       nsCOMPtr<Element> element = do_QueryInterface(aLoadData->mRequestingNode);
       if (element && element->IsHTMLElement()) {
         nsAutoString cspNonce;
         element->GetAttribute(NS_LITERAL_STRING("nonce"), cspNonce);
-        nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
+        nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
         loadInfo->SetCspNonce(cspNonce);
       }
     }
 
     nsCOMPtr<nsIInputStream> stream;
     rv = channel->Open(getter_AddRefs(stream));
 
     if (NS_FAILED(rv)) {
@@ -1460,17 +1460,17 @@ nsresult Loader::LoadSheet(SheetLoadData
   }
 
   // snapshot the nonce at load start time for performing CSP checks
   if (contentPolicyType == nsIContentPolicy::TYPE_INTERNAL_STYLESHEET) {
     nsCOMPtr<Element> element = do_QueryInterface(aLoadData->mRequestingNode);
     if (element && element->IsHTMLElement()) {
       nsAutoString cspNonce;
       element->GetAttribute(NS_LITERAL_STRING("nonce"), cspNonce);
-      nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
+      nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
       loadInfo->SetCspNonce(cspNonce);
     }
   }
 
   if (!aLoadData->ShouldDefer()) {
     nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(channel));
     if (cos) {
       cos->AddClassFlags(nsIClassOfService::Leader);
--- a/netwerk/base/LoadInfo.cpp
+++ b/netwerk/base/LoadInfo.cpp
@@ -264,20 +264,18 @@ LoadInfo::LoadInfo(
             mBrowserWouldUpgradeInsecureRequests = true;
           }
         }
       }
     }
     // if owner doc has content signature, we enforce SRI
     nsCOMPtr<nsIChannel> channel = aLoadingContext->OwnerDoc()->GetChannel();
     if (channel) {
-      nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-      if (loadInfo) {
-        mEnforceSRI = loadInfo->GetVerifySignedContent();
-      }
+      nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+      mEnforceSRI = loadInfo->GetVerifySignedContent();
     }
   }
 
   // If CSP requires SRI (require-sri-for), then store that information
   // in the loadInfo so we can enforce SRI before loading the subresource.
   if (!mEnforceSRI) {
     // do not look into the CSP if already true:
     // a CSP saying that SRI isn't needed should not
--- a/netwerk/base/Predictor.cpp
+++ b/netwerk/base/Predictor.cpp
@@ -1250,20 +1250,18 @@ nsresult Predictor::Prefetch(nsIURI *uri
       nsIRequest::LOAD_BACKGROUND);
 
   if (NS_FAILED(rv)) {
     PREDICTOR_LOG(
         ("    NS_NewChannel failed rv=0x%" PRIX32, static_cast<uint32_t>(rv)));
     return rv;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-  if (loadInfo) {
-    rv = loadInfo->SetOriginAttributes(originAttributes);
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+  rv = loadInfo->SetOriginAttributes(originAttributes);
 
   if (NS_FAILED(rv)) {
     PREDICTOR_LOG(
         ("    Set originAttributes into loadInfo failed rv=0x%" PRIX32,
          static_cast<uint32_t>(rv)));
     return rv;
   }
 
--- a/netwerk/base/nsAsyncRedirectVerifyHelper.cpp
+++ b/netwerk/base/nsAsyncRedirectVerifyHelper.cpp
@@ -69,18 +69,18 @@ nsresult nsAsyncRedirectVerifyHelper::In
   mNewChan = newChan;
   mFlags = flags;
   mCallbackEventTarget = NS_IsMainThread() && mainThreadEventTarget
                              ? mainThreadEventTarget
                              : GetCurrentThreadEventTarget();
 
   if (!(flags & (nsIChannelEventSink::REDIRECT_INTERNAL |
                  nsIChannelEventSink::REDIRECT_STS_UPGRADE))) {
-    nsCOMPtr<nsILoadInfo> loadInfo = oldChan->GetLoadInfo();
-    if (loadInfo && loadInfo->GetDontFollowRedirects()) {
+    nsCOMPtr<nsILoadInfo> loadInfo = oldChan->LoadInfo();
+    if (loadInfo->GetDontFollowRedirects()) {
       ExplicitCallback(NS_BINDING_ABORTED);
       return NS_OK;
     }
   }
 
   if (synchronize) mWaitingForRedirectCallback = true;
 
   nsCOMPtr<nsIRunnable> runnable = this;
--- a/netwerk/base/nsBaseChannel.cpp
+++ b/netwerk/base/nsBaseChannel.cpp
@@ -78,65 +78,58 @@ nsresult nsBaseChannel::Redirect(nsIChan
   // Transfer properties
 
   newChannel->SetLoadGroup(mLoadGroup);
   newChannel->SetNotificationCallbacks(mCallbacks);
   newChannel->SetLoadFlags(mLoadFlags | LOAD_REPLACE);
 
   // make a copy of the loadinfo, append to the redirectchain
   // and set it on the new channel
-  if (mLoadInfo) {
-    nsSecurityFlags secFlags = mLoadInfo->GetSecurityFlags() &
-                               ~nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
-    nsCOMPtr<nsILoadInfo> newLoadInfo =
-        static_cast<mozilla::net::LoadInfo *>(mLoadInfo.get())
-            ->CloneWithNewSecFlags(secFlags);
+  nsSecurityFlags secFlags =
+      mLoadInfo->GetSecurityFlags() & ~nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
+  nsCOMPtr<nsILoadInfo> newLoadInfo =
+      static_cast<mozilla::net::LoadInfo *>(mLoadInfo.get())
+          ->CloneWithNewSecFlags(secFlags);
 
-    nsCOMPtr<nsIPrincipal> uriPrincipal;
-    nsIScriptSecurityManager *sm = nsContentUtils::GetSecurityManager();
-    sm->GetChannelURIPrincipal(this, getter_AddRefs(uriPrincipal));
-    bool isInternalRedirect =
-        (redirectFlags & (nsIChannelEventSink::REDIRECT_INTERNAL |
-                          nsIChannelEventSink::REDIRECT_STS_UPGRADE));
+  nsCOMPtr<nsIPrincipal> uriPrincipal;
+  nsIScriptSecurityManager *sm = nsContentUtils::GetSecurityManager();
+  sm->GetChannelURIPrincipal(this, getter_AddRefs(uriPrincipal));
+  bool isInternalRedirect =
+      (redirectFlags & (nsIChannelEventSink::REDIRECT_INTERNAL |
+                        nsIChannelEventSink::REDIRECT_STS_UPGRADE));
 
-    // nsBaseChannel hst no thing to do with HttpBaseChannel, we would not care
-    // about referrer and remote address in this case
-    nsCOMPtr<nsIRedirectHistoryEntry> entry =
-        new nsRedirectHistoryEntry(uriPrincipal, nullptr, EmptyCString());
+  // nsBaseChannel hst no thing to do with HttpBaseChannel, we would not care
+  // about referrer and remote address in this case
+  nsCOMPtr<nsIRedirectHistoryEntry> entry =
+      new nsRedirectHistoryEntry(uriPrincipal, nullptr, EmptyCString());
 
-    newLoadInfo->AppendRedirectHistoryEntry(entry, isInternalRedirect);
+  newLoadInfo->AppendRedirectHistoryEntry(entry, isInternalRedirect);
 
-    // Ensure the channel's loadInfo's result principal URI so that it's
-    // either non-null or updated to the redirect target URI.
-    // We must do this because in case the loadInfo's result principal URI
-    // is null, it would be taken from OriginalURI of the channel.  But we
-    // overwrite it with the whole redirect chain first URI before opening
-    // the target channel, hence the information would be lost.
-    // If the protocol handler that created the channel wants to use
-    // the originalURI of the channel as the principal URI, it has left
-    // the result principal URI on the load info null.
-    nsCOMPtr<nsIURI> resultPrincipalURI;
+  // Ensure the channel's loadInfo's result principal URI so that it's
+  // either non-null or updated to the redirect target URI.
+  // We must do this because in case the loadInfo's result principal URI
+  // is null, it would be taken from OriginalURI of the channel.  But we
+  // overwrite it with the whole redirect chain first URI before opening
+  // the target channel, hence the information would be lost.
+  // If the protocol handler that created the channel wants to use
+  // the originalURI of the channel as the principal URI, it has left
+  // the result principal URI on the load info null.
+  nsCOMPtr<nsIURI> resultPrincipalURI;
 
-    nsCOMPtr<nsILoadInfo> existingLoadInfo = newChannel->GetLoadInfo();
-    if (existingLoadInfo) {
-      existingLoadInfo->GetResultPrincipalURI(
-          getter_AddRefs(resultPrincipalURI));
-    }
-    if (!resultPrincipalURI) {
-      newChannel->GetOriginalURI(getter_AddRefs(resultPrincipalURI));
-    }
+  nsCOMPtr<nsILoadInfo> existingLoadInfo = newChannel->LoadInfo();
+  if (existingLoadInfo) {
+    existingLoadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
+  }
+  if (!resultPrincipalURI) {
+    newChannel->GetOriginalURI(getter_AddRefs(resultPrincipalURI));
+  }
 
-    newLoadInfo->SetResultPrincipalURI(resultPrincipalURI);
+  newLoadInfo->SetResultPrincipalURI(resultPrincipalURI);
 
-    newChannel->SetLoadInfo(newLoadInfo);
-  } else {
-    // the newChannel was created with a dummy loadInfo, we should clear
-    // it in case the original channel does not have a loadInfo
-    newChannel->SetLoadInfo(nullptr);
-  }
+  newChannel->SetLoadInfo(newLoadInfo);
 
   // Preserve the privacy bit if it has been overridden
   if (mPrivateBrowsingOverriden) {
     nsCOMPtr<nsIPrivateBrowsingChannel> newPBChannel =
         do_QueryInterface(newChannel);
     if (newPBChannel) {
       newPBChannel->SetPrivate(mPrivateBrowsing);
     }
--- a/netwerk/base/nsIChannel.idl
+++ b/netwerk/base/nsIChannel.idl
@@ -351,18 +351,18 @@ interface nsIChannel : nsIRequest
   {
     bool isDocument = false;
     if (NS_SUCCEEDED(GetIsDocument(&isDocument)) && isDocument) {
       return true;
     }
     return false;
   }
 
-  inline already_AddRefed<nsILoadInfo> GetLoadInfo()
+  inline already_AddRefed<nsILoadInfo> LoadInfo()
   {
     nsCOMPtr<nsILoadInfo> result;
     mozilla::DebugOnly<nsresult> rv = GetLoadInfo(getter_AddRefs(result));
-    MOZ_ASSERT(NS_SUCCEEDED(rv) || !result);
+    MOZ_ASSERT(NS_SUCCEEDED(rv) && result);
     return result.forget();
   }
 %}
 
 };
--- a/netwerk/base/nsINetworkInterceptController.idl
+++ b/netwerk/base/nsINetworkInterceptController.idl
@@ -187,45 +187,43 @@ interface nsIInterceptedChannel : nsISup
       GetConsoleReportCollector(getter_AddRefs(reporter));
       return reporter.forget();
     }
 
     void
     GetSubresourceTimeStampKey(nsIChannel* aChannel, nsACString& aKey)
     {
       if (!nsContentUtils::IsNonSubresourceRequest(aChannel)) {
-        nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-        if (loadInfo) {
-          switch(loadInfo->InternalContentPolicyType()) {
-            case nsIContentPolicy::TYPE_SCRIPT:
-            case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
-            case nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD:
-            case nsIContentPolicy::TYPE_INTERNAL_MODULE:
-            case nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD:
-            case nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS: {
-              aKey = NS_LITERAL_CSTRING("subresource-script");
-              break;
-            }
-            case nsIContentPolicy::TYPE_IMAGE:
-            case nsIContentPolicy::TYPE_INTERNAL_IMAGE:
-            case nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD:
-            case nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON: {
-              aKey = NS_LITERAL_CSTRING("subresource-image");
-              break;
-            }
-            case nsIContentPolicy::TYPE_STYLESHEET:
-            case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET:
-            case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD: {
-              aKey = NS_LITERAL_CSTRING("subresource-stylesheet");
-              break;
-            }
-            default: {
-              aKey = NS_LITERAL_CSTRING("subresource-other");
-              break;
-            }
+        nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+        switch(loadInfo->InternalContentPolicyType()) {
+          case nsIContentPolicy::TYPE_SCRIPT:
+          case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
+          case nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD:
+          case nsIContentPolicy::TYPE_INTERNAL_MODULE:
+          case nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD:
+          case nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS: {
+            aKey = NS_LITERAL_CSTRING("subresource-script");
+            break;
+          }
+          case nsIContentPolicy::TYPE_IMAGE:
+          case nsIContentPolicy::TYPE_INTERNAL_IMAGE:
+          case nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD:
+          case nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON: {
+            aKey = NS_LITERAL_CSTRING("subresource-image");
+            break;
+          }
+          case nsIContentPolicy::TYPE_STYLESHEET:
+          case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET:
+          case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD: {
+            aKey = NS_LITERAL_CSTRING("subresource-stylesheet");
+            break;
+          }
+          default: {
+            aKey = NS_LITERAL_CSTRING("subresource-other");
+            break;
           }
         }
       }
     }
 %}
 
     /**
      * Allow the ServiceWorkerManager to set an RAII-style object on the
--- a/netwerk/base/nsIOService.cpp
+++ b/netwerk/base/nsIOService.cpp
@@ -893,17 +893,17 @@ nsresult nsIOService::NewChannelFromURIW
   // TYPE_DOCUMENT loads don't require a loadingNode or principal, but other
   // types do.
   if (aLoadingNode || aLoadingPrincipal ||
       aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) {
     loadInfo = new LoadInfo(aLoadingPrincipal, aTriggeringPrincipal,
                             aLoadingNode, aSecurityFlags, aContentPolicyType,
                             aLoadingClientInfo, aController);
   }
-  NS_ASSERTION(loadInfo, "Please pass security info when creating a channel");
+  MOZ_ASSERT(loadInfo, "Please pass security info when creating a channel");
   return NewChannelFromURIWithProxyFlagsInternal(aURI, aProxyURI, aProxyFlags,
                                                  loadInfo, result);
 }
 
 nsresult nsIOService::NewChannelFromURIWithProxyFlagsInternal(
     nsIURI *aURI, nsIURI *aProxyURI, uint32_t aProxyFlags,
     nsILoadInfo *aLoadInfo, nsIChannel **result) {
   nsresult rv;
@@ -930,17 +930,17 @@ nsresult nsIOService::NewChannelFromURIW
     rv = handler->NewChannel(aURI, aLoadInfo, getter_AddRefs(channel));
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Make sure that all the individual protocolhandlers attach a loadInfo.
   if (aLoadInfo) {
     // make sure we have the same instance of loadInfo on the newly created
     // channel
-    nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
+    nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
     if (aLoadInfo != loadInfo) {
       MOZ_ASSERT(false, "newly created channel must have a loadinfo attached");
       return NS_ERROR_UNEXPECTED;
     }
 
     // If we're sandboxed, make sure to clear any owner the channel
     // might already have.
     if (loadInfo->GetLoadingSandboxed()) {
@@ -1704,21 +1704,18 @@ IOServiceProxyCallback::OnProxyAvailable
   nsCOMPtr<nsIProtocolHandler> handler;
   rv = mIOService->GetProtocolHandler(scheme.get(), getter_AddRefs(handler));
   if (NS_FAILED(rv)) return NS_OK;
 
   nsCOMPtr<nsISpeculativeConnect> speculativeHandler =
       do_QueryInterface(handler);
   if (!speculativeHandler) return NS_OK;
 
-  nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-  nsCOMPtr<nsIPrincipal> principal;
-  if (loadInfo) {
-    principal = loadInfo->LoadingPrincipal();
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+  nsCOMPtr<nsIPrincipal> principal = loadInfo->LoadingPrincipal();
 
   nsLoadFlags loadFlags = 0;
   channel->GetLoadFlags(&loadFlags);
   if (loadFlags & nsIRequest::LOAD_ANONYMOUS) {
     speculativeHandler->SpeculativeAnonymousConnect2(uri, principal,
                                                      mCallbacks);
   } else {
     speculativeHandler->SpeculativeConnect2(uri, principal, mCallbacks);
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -227,20 +227,17 @@ nsresult NS_NewChannelInternal(
 #endif
 
   if (aLoadFlags != nsIRequest::LOAD_NORMAL) {
     rv = channel->SetLoadFlags(aLoadFlags);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (aPerformanceStorage) {
-    nsCOMPtr<nsILoadInfo> loadInfo;
-    rv = channel->GetLoadInfo(getter_AddRefs(loadInfo));
-    NS_ENSURE_SUCCESS(rv, rv);
-
+    nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
     loadInfo->SetPerformanceStorage(aPerformanceStorage);
   }
 
   channel.forget(outChannel);
   return NS_OK;
 }
 
 namespace {
@@ -382,20 +379,17 @@ nsresult NS_NewChannelInternal(
 #endif
 
   if (aLoadFlags != nsIRequest::LOAD_NORMAL) {
     rv = channel->SetLoadFlags(aLoadFlags);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (aPerformanceStorage) {
-    nsCOMPtr<nsILoadInfo> loadInfo;
-    rv = channel->GetLoadInfo(getter_AddRefs(loadInfo));
-    NS_ENSURE_SUCCESS(rv, rv);
-
+    nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
     loadInfo->SetPerformanceStorage(aPerformanceStorage);
   }
 
   channel.forget(outChannel);
   return NS_OK;
 }
 
 nsresult /*NS_NewChannelWithNodeAndTriggeringPrincipal */
@@ -641,16 +635,17 @@ nsresult NS_NewInputStreamChannelInterna
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (!aContentCharset.IsEmpty()) {
     rv = channel->SetContentCharset(aContentCharset);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
+  MOZ_ASSERT(aLoadInfo, "need a loadinfo to create a inputstreamchannel");
   channel->SetLoadInfo(aLoadInfo);
 
   // If we're sandboxed, make sure to clear any owner the channel
   // might already have.
   if (aLoadInfo && aLoadInfo->GetLoadingSandboxed()) {
     channel->SetOwner(nullptr);
   }
 
@@ -1698,22 +1693,18 @@ bool NS_UsePrivateBrowsing(nsIChannel *c
   OriginAttributes attrs;
   bool result = NS_GetOriginAttributes(channel, attrs);
   NS_ENSURE_TRUE(result, result);
   return attrs.mPrivateBrowsingId > 0;
 }
 
 bool NS_GetOriginAttributes(nsIChannel *aChannel,
                             mozilla::OriginAttributes &aAttributes) {
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  // For some channels, they might not have loadInfo, like
-  // ExternalHelperAppParent..
-  if (loadInfo) {
-    loadInfo->GetOriginAttributes(&aAttributes);
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+  loadInfo->GetOriginAttributes(&aAttributes);
 
   bool isPrivate = false;
   nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(aChannel);
   if (pbChannel) {
     nsresult rv = pbChannel->GetIsChannelPrivate(&isPrivate);
     NS_ENSURE_SUCCESS(rv, false);
   } else {
     // Some channels may not implement nsIPrivateBrowsingChannel
@@ -1721,25 +1712,17 @@ bool NS_GetOriginAttributes(nsIChannel *
     NS_QueryNotificationCallbacks(aChannel, loadContext);
     isPrivate = loadContext && loadContext->UsePrivateBrowsing();
   }
   aAttributes.SyncAttributesWithPrivateBrowsing(isPrivate);
   return true;
 }
 
 bool NS_HasBeenCrossOrigin(nsIChannel *aChannel, bool aReport) {
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  MOZ_RELEASE_ASSERT(
-      loadInfo,
-      "Origin tracking only works for channels created with a loadinfo");
-
-  if (!loadInfo) {
-    return false;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   // TYPE_DOCUMENT loads have a null LoadingPrincipal and can not be cross
   // origin.
   if (!loadInfo->LoadingPrincipal()) {
     return false;
   }
 
   // Always treat tainted channels as cross-origin.
   if (loadInfo->GetTainting() != LoadTainting::Basic) {
@@ -1790,20 +1773,17 @@ bool NS_HasBeenCrossOrigin(nsIChannel *a
 
   return NS_FAILED(loadingPrincipal->CheckMayLoad(uri, aReport, dataInherits));
 }
 
 bool NS_IsSafeTopLevelNav(nsIChannel *aChannel) {
   if (!aChannel) {
     return false;
   }
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo) {
-    return false;
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   if (loadInfo->GetExternalContentPolicyType() !=
       nsIContentPolicy::TYPE_DOCUMENT) {
     return false;
   }
   RefPtr<HttpBaseChannel> baseChan = do_QueryObject(aChannel);
   if (!baseChan) {
     return false;
   }
@@ -1813,21 +1793,17 @@ bool NS_IsSafeTopLevelNav(nsIChannel *aC
   }
   return requestHead->IsSafeMethod();
 }
 
 bool NS_IsSameSiteForeign(nsIChannel *aChannel, nsIURI *aHostURI) {
   if (!aChannel) {
     return false;
   }
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo) {
-    return false;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   // Do not treat loads triggered by web extensions as foreign
   nsCOMPtr<nsIURI> channelURI;
   NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI));
   if (BasePrincipal::Cast(loadInfo->TriggeringPrincipal())
           ->AddonAllowsLoad(channelURI)) {
     return false;
   }
 
@@ -2019,26 +1995,23 @@ already_AddRefed<nsIURI> NS_GetInnermost
   }
 
   return uri.forget();
 }
 
 nsresult NS_GetFinalChannelURI(nsIChannel *channel, nsIURI **uri) {
   *uri = nullptr;
 
-  nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-  if (loadInfo) {
-    nsCOMPtr<nsIURI> resultPrincipalURI;
-    loadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
-    if (resultPrincipalURI) {
-      resultPrincipalURI.forget(uri);
-      return NS_OK;
-    }
+  nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+  nsCOMPtr<nsIURI> resultPrincipalURI;
+  loadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
+  if (resultPrincipalURI) {
+    resultPrincipalURI.forget(uri);
+    return NS_OK;
   }
-
   return channel->GetOriginalURI(uri);
 }
 
 nsresult NS_URIChainHasFlags(nsIURI *uri, uint32_t flags, bool *result) {
   nsresult rv;
   nsCOMPtr<nsINetUtil> util = do_GetNetUtil(&rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -2354,23 +2327,23 @@ nsresult NS_LinkRedirectChannels(uint32_
       RedirectChannelRegistrar::GetOrCreate();
   MOZ_ASSERT(registrar);
 
   return registrar->LinkChannels(channelId, parentChannel, _result);
 }
 
 nsresult NS_MaybeOpenChannelUsingOpen(nsIChannel *aChannel,
                                       nsIInputStream **aStream) {
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   return aChannel->Open(aStream);
 }
 
 nsresult NS_MaybeOpenChannelUsingAsyncOpen(nsIChannel *aChannel,
                                            nsIStreamListener *aListener) {
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   return aChannel->AsyncOpen(aListener);
 }
 
 /** Given the first (disposition) token from a Content-Disposition header,
  * tell whether it indicates the content is inline or attachment
  * @param aDispToken the disposition token from the content-disposition header
  */
 uint32_t NS_GetContentDispositionFromToken(const nsAString &aDispToken) {
@@ -2683,22 +2656,21 @@ nsresult NS_GetSecureUpgradedURI(nsIURI 
       mutator.SetPort(oldPort);
     }
   }
 
   return mutator.Finalize(aUpgradedURI);
 }
 
 nsresult NS_CompareLoadInfoAndLoadContext(nsIChannel *aChannel) {
-  nsCOMPtr<nsILoadInfo> loadInfo;
-  aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
 
   nsCOMPtr<nsILoadContext> loadContext;
   NS_QueryNotificationCallbacks(aChannel, loadContext);
-  if (!loadInfo || !loadContext) {
+  if (!loadContext) {
     return NS_OK;
   }
 
   // We try to skip about:newtab.
   // about:newtab will use SystemPrincipal to download thumbnails through
   // https:// and blob URLs.
   bool isAboutPage = false;
   nsINode *node = loadInfo->LoadingNode();
--- a/netwerk/cookie/CookieServiceChild.cpp
+++ b/netwerk/cookie/CookieServiceChild.cpp
@@ -171,21 +171,18 @@ void CookieServiceChild::TrackCookieLoad
     // since the parent process can't do it for us as it won't have a channel
     // object handy.
     if (!firstPartyStorageAccessGranted) {
       AntiTrackingCommon::NotifyBlockingDecision(
           aChannel, AntiTrackingCommon::BlockingDecision::eBlock,
           rejectedReason);
     }
   }
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  mozilla::OriginAttributes attrs;
-  if (loadInfo) {
-    attrs = loadInfo->GetOriginAttributes();
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+  mozilla::OriginAttributes attrs = loadInfo->GetOriginAttributes();
   URIParams uriParams;
   SerializeURI(uri, uriParams);
   bool isSafeTopLevelNav = NS_IsSafeTopLevelNav(aChannel);
   bool isSameSiteForeign = NS_IsSameSiteForeign(aChannel, uri);
   SendPrepareCookieList(uriParams, isForeign, isTrackingResource,
                         firstPartyStorageAccessGranted, isSafeTopLevelNav,
                         isSameSiteForeign, attrs);
 }
@@ -479,20 +476,18 @@ nsresult CookieServiceChild::GetCookieSt
   // documents.
   nsAutoCString scheme;
   aHostURI->GetScheme(scheme);
   if (scheme.EqualsLiteral("moz-nullprincipal")) return NS_OK;
 
   nsCOMPtr<nsILoadInfo> loadInfo;
   mozilla::OriginAttributes attrs;
   if (aChannel) {
-    loadInfo = aChannel->GetLoadInfo();
-    if (loadInfo) {
-      attrs = loadInfo->GetOriginAttributes();
-    }
+    loadInfo = aChannel->LoadInfo();
+    attrs = loadInfo->GetOriginAttributes();
   }
 
   // Asynchronously call the parent.
   bool isForeign = true;
   if (RequireThirdPartyCheck())
     mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI, &isForeign);
 
   bool isTrackingResource = false;
@@ -564,20 +559,18 @@ nsresult CookieServiceChild::SetCookieSt
 
   OptionalURIParams channelURIParams;
   mozilla::OriginAttributes attrs;
   if (aChannel) {
     nsCOMPtr<nsIURI> channelURI;
     aChannel->GetURI(getter_AddRefs(channelURI));
     SerializeURI(channelURI, channelURIParams);
 
-    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-    if (loadInfo) {
-      attrs = loadInfo->GetOriginAttributes();
-    }
+    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+    attrs = loadInfo->GetOriginAttributes();
   } else {
     SerializeURI(nullptr, channelURIParams);
   }
 
   // Asynchronously call the parent.
   if (mIPCOpen) {
     SendSetCookieString(hostURIParams, channelURIParams, isForeign,
                         isTrackingResource, firstPartyStorageAccessGranted,
--- a/netwerk/cookie/CookieServiceParent.cpp
+++ b/netwerk/cookie/CookieServiceParent.cpp
@@ -127,21 +127,18 @@ void CookieServiceParent::AddCookie(nsIC
   }
   Unused << SendAddCookie(cookieStruct, attrs);
 }
 
 void CookieServiceParent::TrackCookieLoad(nsIChannel *aChannel) {
   nsCOMPtr<nsIURI> uri;
   aChannel->GetURI(getter_AddRefs(uri));
 
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  mozilla::OriginAttributes attrs;
-  if (loadInfo) {
-    attrs = loadInfo->GetOriginAttributes();
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+  mozilla::OriginAttributes attrs = loadInfo->GetOriginAttributes();
   bool isSafeTopLevelNav = NS_IsSafeTopLevelNav(aChannel);
   bool aIsSameSiteForeign = NS_IsSameSiteForeign(aChannel, uri);
 
   // Send matching cookies to Child.
   nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil;
   thirdPartyUtil = do_GetService(THIRDPARTYUTIL_CONTRACTID);
   bool isForeign = true;
   thirdPartyUtil->IsThirdPartyChannel(aChannel, uri, &isForeign);
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -3385,20 +3385,19 @@ bool nsCookieService::CanSetCookie(nsIUR
   // browser must ignore the cookie.
   if ((aCookieAttributes.sameSite != nsICookie2::SAMESITE_UNSET) &&
       aThirdPartyUtil && IsSameSiteEnabled()) {
     // Do not treat loads triggered by web extensions as foreign
     bool addonAllowsLoad = false;
     if (aChannel) {
       nsCOMPtr<nsIURI> channelURI;
       NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI));
-      nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-      addonAllowsLoad =
-          loadInfo && BasePrincipal::Cast(loadInfo->TriggeringPrincipal())
-                          ->AddonAllowsLoad(channelURI);
+      nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+      addonAllowsLoad = BasePrincipal::Cast(loadInfo->TriggeringPrincipal())
+                            ->AddonAllowsLoad(channelURI);
     }
 
     if (!addonAllowsLoad) {
       bool isThirdParty = false;
       nsresult rv = aThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI,
                                                          &isThirdParty);
       if (NS_FAILED(rv) || isThirdParty) {
         COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, savedCookieHeader,
--- a/netwerk/ipc/ChannelEventQueue.cpp
+++ b/netwerk/ipc/ChannelEventQueue.cpp
@@ -181,21 +181,17 @@ bool ChannelEventQueue::MaybeSuspendIfEv
     return false;
   }
 
   nsCOMPtr<nsIChannel> channel(do_QueryInterface(mOwner));
   if (!channel) {
     return false;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-  if (!loadInfo) {
-    return false;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
   // Figure out if this is for an XHR, if we haven't done so already.
   if (!mHasCheckedForXMLHttpRequest) {
     nsContentPolicyType contentType = loadInfo->InternalContentPolicyType();
     mForXMLHttpRequest =
         (contentType == nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST);
     mHasCheckedForXMLHttpRequest = true;
 
     if (!mForXMLHttpRequest) {
--- a/netwerk/protocol/about/nsAboutProtocolHandler.cpp
+++ b/netwerk/protocol/about/nsAboutProtocolHandler.cpp
@@ -199,32 +199,30 @@ nsAboutProtocolHandler::NewChannel(nsIUR
   if (NS_SUCCEEDED(rv)) {
     // The standard return case:
     rv = aboutMod->NewChannel(uri, aLoadInfo, result);
     if (NS_SUCCEEDED(rv)) {
       // Not all implementations of nsIAboutModule::NewChannel()
       // set the LoadInfo on the newly created channel yet, as
       // an interim solution we set the LoadInfo here if not
       // available on the channel. Bug 1087720
-      nsCOMPtr<nsILoadInfo> loadInfo = (*result)->GetLoadInfo();
+      nsCOMPtr<nsILoadInfo> loadInfo = (*result)->LoadInfo();
       if (aLoadInfo != loadInfo) {
-        if (loadInfo) {
-          NS_ASSERTION(false,
-                       "nsIAboutModule->newChannel(aURI, aLoadInfo) needs to "
-                       "set LoadInfo");
-          const char16_t *params[] = {
-              u"nsIAboutModule->newChannel(aURI)",
-              u"nsIAboutModule->newChannel(aURI, aLoadInfo)"};
-          nsContentUtils::ReportToConsole(
-              nsIScriptError::warningFlag,
-              NS_LITERAL_CSTRING("Security by Default"),
-              nullptr,  // aDocument
-              nsContentUtils::eNECKO_PROPERTIES, "APIDeprecationWarning",
-              params, mozilla::ArrayLength(params));
-        }
+        NS_ASSERTION(false,
+                     "nsIAboutModule->newChannel(aURI, aLoadInfo) needs to "
+                     "set LoadInfo");
+        const char16_t *params[] = {
+            u"nsIAboutModule->newChannel(aURI)",
+            u"nsIAboutModule->newChannel(aURI, aLoadInfo)"};
+        nsContentUtils::ReportToConsole(
+            nsIScriptError::warningFlag,
+            NS_LITERAL_CSTRING("Security by Default"),
+            nullptr,  // aDocument
+            nsContentUtils::eNECKO_PROPERTIES, "APIDeprecationWarning", params,
+            mozilla::ArrayLength(params));
         (*result)->SetLoadInfo(aLoadInfo);
       }
 
       // If this URI is safe for untrusted content, enforce that its
       // principal be based on the channel's originalURI by setting the
       // owner to null.
       // Note: this relies on aboutMod's newChannel implementation
       // having set the proper originalURI, which probably isn't ideal.
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -2576,19 +2576,16 @@ nsresult HttpBaseChannel::AddSecurityMes
   nsCOMPtr<nsIConsoleService> console(
       do_GetService(NS_CONSOLESERVICE_CONTRACTID));
   if (!console) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsILoadInfo> loadInfo;
   GetLoadInfo(getter_AddRefs(loadInfo));
-  if (!loadInfo) {
-    return NS_ERROR_FAILURE;
-  }
 
   auto innerWindowID = loadInfo->GetInnerWindowID();
 
   nsAutoString errorText;
   rv = nsContentUtils::GetLocalizedString(
       nsContentUtils::eSECURITY_PROPERTIES,
       NS_ConvertUTF16toUTF8(aMessageTag).get(), errorText);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -3435,26 +3432,23 @@ nsresult HttpBaseChannel::SetupReplaceme
   // either non-null or updated to the redirect target URI.
   // We must do this because in case the loadInfo's result principal URI
   // is null, it would be taken from OriginalURI of the channel.  But we
   // overwrite it with the whole redirect chain first URI before opening
   // the target channel, hence the information would be lost.
   // If the protocol handler that created the channel wants to use
   // the originalURI of the channel as the principal URI, this fulfills
   // that request - newURI is the original URI of the channel.
-  nsCOMPtr<nsILoadInfo> newLoadInfo = newChannel->GetLoadInfo();
-  if (newLoadInfo) {
-    nsCOMPtr<nsIURI> resultPrincipalURI;
-    rv = newLoadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
+  nsCOMPtr<nsILoadInfo> newLoadInfo = newChannel->LoadInfo();
+  nsCOMPtr<nsIURI> resultPrincipalURI;
+  rv = newLoadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
+  NS_ENSURE_SUCCESS(rv, rv);
+  if (!resultPrincipalURI) {
+    rv = newLoadInfo->SetResultPrincipalURI(newURI);
     NS_ENSURE_SUCCESS(rv, rv);
-
-    if (!resultPrincipalURI) {
-      rv = newLoadInfo->SetResultPrincipalURI(newURI);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
   }
 
   uint32_t newLoadFlags = mLoadFlags | LOAD_REPLACE;
   // if the original channel was using SSL and this channel is not using
   // SSL, then no need to inhibit persistent caching.  however, if the
   // original channel was not using SSL and has INHIBIT_PERSISTENT_CACHING
   // set, then allow the flag to apply to the redirected channel as well.
   // since we force set INHIBIT_PERSISTENT_CACHING on all HTTPS channels,
--- a/netwerk/protocol/http/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -439,20 +439,16 @@ bool HttpChannelParent::DoAsyncOpen(
 
   nsCOMPtr<nsILoadInfo> loadInfo;
   rv = mozilla::ipc::LoadInfoArgsToLoadInfo(aLoadInfoArgs,
                                             getter_AddRefs(loadInfo));
   if (NS_FAILED(rv)) {
     return SendFailedAsyncOpen(rv);
   }
 
-  if (!loadInfo) {
-    return SendFailedAsyncOpen(NS_ERROR_UNEXPECTED);
-  }
-
   nsCOMPtr<nsIChannel> channel;
   rv = NS_NewChannelInternal(getter_AddRefs(channel), uri, loadInfo, nullptr,
                              nullptr, nullptr, aLoadFlags, ios);
   if (NS_FAILED(rv)) {
     return SendFailedAsyncOpen(rv);
   }
 
   RefPtr<HttpBaseChannel> httpChannel = do_QueryObject(channel, &rv);
--- a/netwerk/protocol/http/TrackingDummyChannelChild.cpp
+++ b/netwerk/protocol/http/TrackingDummyChannelChild.cpp
@@ -27,21 +27,17 @@ namespace net {
     // Any non-http channel is allowed.
     return true;
   }
 
   nsCOMPtr<nsIURI> topWindowURI;
   nsresult topWindowURIResult =
       httpChannelInternal->GetTopWindowURI(getter_AddRefs(topWindowURI));
 
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo) {
-    return false;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   OptionalLoadInfoArgs loadInfoArgs;
   mozilla::ipc::LoadInfoToLoadInfoArgs(loadInfo, &loadInfoArgs);
 
   PTrackingDummyChannelChild* actor =
       gNeckoChild->SendPTrackingDummyChannelConstructor(
           aURI, topWindowURI, topWindowURIResult, loadInfoArgs);
   if (!actor) {
     return false;
--- a/netwerk/protocol/http/nsCORSListenerProxy.cpp
+++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp
@@ -527,18 +527,18 @@ nsresult nsCORSListenerProxy::CheckReque
 
   // Test that things worked on a HTTP level
   nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(aRequest);
   if (!http) {
     LogBlockedRequest(aRequest, "CORSRequestNotHttp", nullptr, topChannel);
     return NS_ERROR_DOM_BAD_URI;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo = http->GetLoadInfo();
-  if (loadInfo && loadInfo->GetServiceWorkerTaintingSynthesized()) {
+  nsCOMPtr<nsILoadInfo> loadInfo = http->LoadInfo();
+  if (loadInfo->GetServiceWorkerTaintingSynthesized()) {
     // For synthesized responses, we don't need to perform any checks.
     // Note: This would be unsafe if we ever changed our behavior to allow
     // service workers to intercept CORS preflights.
     return NS_OK;
   }
 
   // Check the Access-Control-Allow-Origin header
   RefPtr<CheckOriginHeader> visitor = new CheckOriginHeader();
@@ -837,50 +837,43 @@ bool CheckUpgradeInsecureRequestsPrevent
     return false;
   }
 
   // also check that uri matches the one of the originalURI
   if (!channelHost.EqualsIgnoreCase(origChannelHost.get())) {
     return false;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo;
-  rv = aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
-  NS_ENSURE_SUCCESS(rv, false);
-
-  if (!loadInfo) {
-    return false;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   // lets see if the loadInfo indicates that the request will
   // be upgraded before fetching any data from the netwerk.
   return loadInfo->GetUpgradeInsecureRequests() ||
          loadInfo->GetBrowserUpgradeInsecureRequests();
 }
 
 nsresult nsCORSListenerProxy::UpdateChannel(nsIChannel* aChannel,
                                             DataURIHandling aAllowDataURI,
                                             UpdateType aUpdateType) {
   nsCOMPtr<nsIURI> uri, originalURI;
   nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri));
   NS_ENSURE_SUCCESS(rv, rv);
   rv = aChannel->GetOriginalURI(getter_AddRefs(originalURI));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
 
   // exempt data URIs from the same origin check.
   if (aAllowDataURI == DataURIHandling::Allow && originalURI == uri) {
     bool dataScheme = false;
     rv = uri->SchemeIs("data", &dataScheme);
     NS_ENSURE_SUCCESS(rv, rv);
     if (dataScheme) {
       return NS_OK;
     }
-    if (loadInfo && loadInfo->GetAboutBlankInherits() && NS_IsAboutBlank(uri)) {
+    if (loadInfo->GetAboutBlankInherits() && NS_IsAboutBlank(uri)) {
       return NS_OK;
     }
   }
 
   // Set CORS attributes on channel so that intercepted requests get correct
   // values. We have to do this here because the CheckMayLoad checks may lead
   // to early return. We can't be sure this is an http channel though, so we
   // can't return early on failure.
@@ -996,19 +989,18 @@ nsresult nsCORSListenerProxy::UpdateChan
 
   return NS_OK;
 }
 
 nsresult nsCORSListenerProxy::CheckPreflightNeeded(nsIChannel* aChannel,
                                                    UpdateType aUpdateType) {
   // If this caller isn't using AsyncOpen, or if this *is* a preflight channel,
   // then we shouldn't initiate preflight for this channel.
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo ||
-      loadInfo->GetSecurityMode() !=
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+  if (loadInfo->GetSecurityMode() !=
           nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS ||
       loadInfo->GetIsPreflight()) {
     return NS_OK;
   }
 
   bool doPreflight = loadInfo->GetForcePreflight();
 
   nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(aChannel);
@@ -1218,17 +1210,17 @@ void nsCORSPreflightListener::AddResultT
 }
 
 NS_IMETHODIMP
 nsCORSPreflightListener::OnStartRequest(nsIRequest* aRequest,
                                         nsISupports* aContext) {
 #ifdef DEBUG
   {
     nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
-    nsCOMPtr<nsILoadInfo> loadInfo = channel ? channel->GetLoadInfo() : nullptr;
+    nsCOMPtr<nsILoadInfo> loadInfo = channel ? channel->LoadInfo() : nullptr;
     MOZ_ASSERT(!loadInfo || !loadInfo->GetServiceWorkerTaintingSynthesized());
   }
 #endif
 
   nsresult rv = CheckPreflightRequestApproved(aRequest);
 
   if (NS_SUCCEEDED(rv)) {
     // Everything worked, try to cache and then fire off the actual request.
@@ -1393,23 +1385,17 @@ nsresult nsCORSListenerProxy::StartCORSP
   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequestChannel));
   NS_ENSURE_TRUE(httpChannel, NS_ERROR_UNEXPECTED);
   Unused << httpChannel->GetRequestMethod(method);
 
   nsCOMPtr<nsIURI> uri;
   nsresult rv = NS_GetFinalChannelURI(aRequestChannel, getter_AddRefs(uri));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsILoadInfo> originalLoadInfo = aRequestChannel->GetLoadInfo();
-  MOZ_ASSERT(originalLoadInfo,
-             "can not perform CORS preflight without a loadInfo");
-  if (!originalLoadInfo) {
-    return NS_ERROR_FAILURE;
-  }
-
+  nsCOMPtr<nsILoadInfo> originalLoadInfo = aRequestChannel->LoadInfo();
   MOZ_ASSERT(originalLoadInfo->GetSecurityMode() ==
                  nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS,
              "how did we end up here?");
 
   nsCOMPtr<nsIPrincipal> principal = originalLoadInfo->LoadingPrincipal();
   MOZ_ASSERT(principal && originalLoadInfo->GetExternalContentPolicyType() !=
                               nsIContentPolicy::TYPE_DOCUMENT,
              "Should not do CORS loads for top-level loads, so a "
--- a/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
+++ b/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
@@ -894,57 +894,54 @@ bool nsHttpChannelAuthProvider::BlockPro
   }
 
   if (proxyAuth) {
     // Do not block auth-dialog if this is a proxy authentication.
     return false;
   }
 
   nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel);
-  nsCOMPtr<nsILoadInfo> loadInfo;
-  chan->GetLoadInfo(getter_AddRefs(loadInfo));
+  nsCOMPtr<nsILoadInfo> loadInfo = chan->LoadInfo();
 
   // We will treat loads w/o loadInfo as a top level document.
   bool topDoc = true;
   bool xhr = false;
   bool nonWebContent = false;
 
-  if (loadInfo) {
-    if (loadInfo->GetExternalContentPolicyType() !=
-        nsIContentPolicy::TYPE_DOCUMENT) {
-      topDoc = false;
+  if (loadInfo->GetExternalContentPolicyType() !=
+      nsIContentPolicy::TYPE_DOCUMENT) {
+    topDoc = false;
+  }
+
+  if (!topDoc) {
+    nsCOMPtr<nsIPrincipal> triggeringPrinc = loadInfo->TriggeringPrincipal();
+    if (nsContentUtils::IsSystemPrincipal(triggeringPrinc)) {
+      nonWebContent = true;
     }
+  }
 
-    if (!topDoc) {
-      nsCOMPtr<nsIPrincipal> triggeringPrinc = loadInfo->TriggeringPrincipal();
-      if (nsContentUtils::IsSystemPrincipal(triggeringPrinc)) {
-        nonWebContent = true;
+  if (loadInfo->GetExternalContentPolicyType() ==
+      nsIContentPolicy::TYPE_XMLHTTPREQUEST) {
+    xhr = true;
+  }
+
+  if (!topDoc && !xhr) {
+    nsCOMPtr<nsIURI> topURI;
+    Unused << chanInternal->GetTopWindowURI(getter_AddRefs(topURI));
+
+    if (!topURI) {
+      // If we do not have topURI try the loadingPrincipal.
+      nsCOMPtr<nsIPrincipal> loadingPrinc = loadInfo->LoadingPrincipal();
+      if (loadingPrinc) {
+        loadingPrinc->GetURI(getter_AddRefs(topURI));
       }
     }
 
-    if (loadInfo->GetExternalContentPolicyType() ==
-        nsIContentPolicy::TYPE_XMLHTTPREQUEST) {
-      xhr = true;
-    }
-
-    if (!topDoc && !xhr) {
-      nsCOMPtr<nsIURI> topURI;
-      Unused << chanInternal->GetTopWindowURI(getter_AddRefs(topURI));
-
-      if (!topURI) {
-        // If we do not have topURI try the loadingPrincipal.
-        nsCOMPtr<nsIPrincipal> loadingPrinc = loadInfo->LoadingPrincipal();
-        if (loadingPrinc) {
-          loadingPrinc->GetURI(getter_AddRefs(topURI));
-        }
-      }
-
-      if (!NS_SecurityCompareURIs(topURI, mURI, true)) {
-        mCrossOrigin = true;
-      }
+    if (!NS_SecurityCompareURIs(topURI, mURI, true)) {
+      mCrossOrigin = true;
     }
   }
 
   if (Telemetry::CanRecordPrereleaseData()) {
     if (topDoc) {
       Telemetry::Accumulate(Telemetry::HTTP_AUTH_DIALOG_STATS_3,
                             HTTP_AUTH_DIALOG_TOP_LEVEL_DOC);
     } else if (nonWebContent) {
--- a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp
+++ b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp
@@ -131,21 +131,17 @@ nsresult nsViewSourceChannel::InitSrcdoc
   return NS_OK;
 }
 
 nsresult nsViewSourceChannel::UpdateLoadInfoResultPrincipalURI() {
   nsresult rv;
 
   MOZ_ASSERT(mChannel);
 
-  nsCOMPtr<nsILoadInfo> channelLoadInfo = mChannel->GetLoadInfo();
-  if (!channelLoadInfo) {
-    return NS_OK;
-  }
-
+  nsCOMPtr<nsILoadInfo> channelLoadInfo = mChannel->LoadInfo();
   nsCOMPtr<nsIURI> channelResultPrincipalURI;
   rv = channelLoadInfo->GetResultPrincipalURI(
       getter_AddRefs(channelResultPrincipalURI));
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   if (!channelResultPrincipalURI) {
@@ -285,31 +281,21 @@ nsViewSourceChannel::GetURI(nsIURI **aUR
   }
 
   return BuildViewSourceURI(uri, aURI);
 }
 
 NS_IMETHODIMP
 nsViewSourceChannel::Open(nsIInputStream **aStream) {
   NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
-  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-  if (!loadInfo) {
-    MOZ_ASSERT(loadInfo, "can not enforce security without loadInfo");
-    return NS_ERROR_UNEXPECTED;
-  }
   return Open(aStream);
 }
 
 NS_IMETHODIMP
 nsViewSourceChannel::AsyncOpen(nsIStreamListener *aListener) {
-  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-  if (!loadInfo) {
-    MOZ_ASSERT(loadInfo, "can not enforce security without loadInfo");
-    return NS_ERROR_UNEXPECTED;
-  }
   // We can't ensure GetInitialSecurityCheckDone here
 
   NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
 
   mListener = aListener;
 
   /*
    * We want to add ourselves to the loadgroup before opening
--- a/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
@@ -106,20 +106,18 @@ mozilla::ipc::IPCResult WyciwygChannelPa
 
   if (NS_FAILED(rv)) {
     if (!SendCancelEarly(rv)) {
       return IPC_FAIL_NO_REASON(this);
     }
     return IPC_OK();
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo = chan->GetLoadInfo();
-  if (loadInfo) {
-    rv = loadInfo->SetPrincipalToInherit(principalToInherit);
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = chan->LoadInfo();
+  rv = loadInfo->SetPrincipalToInherit(principalToInherit);
   if (NS_FAILED(rv)) {
     if (!SendCancelEarly(rv)) {
       return IPC_FAIL_NO_REASON(this);
     }
     return IPC_OK();
   }
 
   mChannel = do_QueryInterface(chan, &rv);
@@ -207,17 +205,17 @@ mozilla::ipc::IPCResult WyciwygChannelPa
   rv = mChannel->SetNotificationCallbacks(this);
   if (NS_FAILED(rv)) {
     if (!SendCancelEarly(rv)) {
       return IPC_FAIL_NO_REASON(this);
     }
     return IPC_OK();
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
+  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
   rv = mChannel->AsyncOpen(this);
 
   if (NS_FAILED(rv)) {
     if (!SendCancelEarly(rv)) {
       return IPC_FAIL_NO_REASON(this);
     }
     return IPC_OK();
   }
--- a/netwerk/url-classifier/UrlClassifierCommon.cpp
+++ b/netwerk/url-classifier/UrlClassifierCommon.cpp
@@ -28,21 +28,17 @@ namespace net {
 
 const nsCString::size_type UrlClassifierCommon::sMaxSpecLength = 128;
 
 // MOZ_LOG=nsChannelClassifier:5
 LazyLogModule UrlClassifierCommon::sLog("nsChannelClassifier");
 
 /* static */ bool UrlClassifierCommon::AddonMayLoad(nsIChannel* aChannel,
                                                     nsIURI* aURI) {
-  nsCOMPtr<nsILoadInfo> channelLoadInfo = aChannel->GetLoadInfo();
-  if (!channelLoadInfo) {
-    return false;
-  }
-
+  nsCOMPtr<nsILoadInfo> channelLoadInfo = aChannel->LoadInfo();
   // loadingPrincipal is used here to ensure we are loading into an
   // addon principal.  This allows an addon, with explicit permission, to
   // call out to API endpoints that may otherwise get blocked.
   nsIPrincipal* loadingPrincipal = channelLoadInfo->LoadingPrincipal();
   if (!loadingPrincipal) {
     return false;
   }
 
--- a/netwerk/url-classifier/UrlClassifierFeatureFlash.cpp
+++ b/netwerk/url-classifier/UrlClassifierFeatureFlash.cpp
@@ -93,20 +93,19 @@ UrlClassifierFeatureFlash::UrlClassifier
     nsIChannel* aChannel,
     nsTArray<nsCOMPtr<nsIUrlClassifierFeature>>& aFeatures) {
   // All disabled.
   if (!StaticPrefs::plugins_flashBlock_enabled()) {
     return;
   }
 
   // We use Flash feature just for document loading.
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   nsContentPolicyType contentPolicyType =
-      loadInfo ? loadInfo->GetExternalContentPolicyType()
-               : nsIContentPolicy::TYPE_INVALID;
+      loadInfo->GetExternalContentPolicyType();
 
   if (contentPolicyType != nsIContentPolicy::TYPE_DOCUMENT &&
       contentPolicyType != nsIContentPolicy::TYPE_SUBDOCUMENT) {
     return;
   }
 
   // Only allow plugins for documents from an HTTP/HTTPS origin.
   if (StaticPrefs::plugins_http_https_only()) {
--- a/security/manager/ssl/nsNSSCallbacks.cpp
+++ b/security/manager/ssl/nsNSSCallbacks.cpp
@@ -266,20 +266,17 @@ OCSPRequest::Run() {
   // b) OCSP requests are shared across different containers as long as first
   // party isolation is not enabled and none of the containers are in private
   // browsing mode.
   if (mOriginAttributes != OriginAttributes()) {
     OriginAttributes attrs;
     attrs.mFirstPartyDomain = mOriginAttributes.mFirstPartyDomain;
     attrs.mPrivateBrowsingId = mOriginAttributes.mPrivateBrowsingId;
 
-    nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-    if (!loadInfo) {
-      return NotifyDone(NS_ERROR_FAILURE, lock);
-    }
+    nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
     rv = loadInfo->SetOriginAttributes(attrs);
     if (NS_FAILED(rv)) {
       return NotifyDone(rv, lock);
     }
   }
 
   nsCOMPtr<nsIInputStream> uploadStream;
   rv = NS_NewByteInputStream(getter_AddRefs(uploadStream),
--- a/toolkit/components/antitracking/AntiTrackingCommon.cpp
+++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp
@@ -1267,22 +1267,17 @@ bool AntiTrackingCommon::IsFirstPartySto
   if (NS_FAILED(rv)) {
     LOG(("Failed to get the channel final URI, bail out early"));
     return true;
   }
   LOG_SPEC(
       ("Computing whether channel %p has access to URI %s", aChannel, _spec),
       channelURI);
 
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo) {
-    LOG(("No loadInfo, bail out early"));
-    return true;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   // We need to find the correct principal to check the cookie permission. For
   // third-party contexts, we want to check if the top-level window has a custom
   // cookie permission.
   nsCOMPtr<nsIPrincipal> toplevelPrincipal = loadInfo->GetTopLevelPrincipal();
 
   // If this is already the top-level window, we should use the loading
   // principal.
   if (!toplevelPrincipal) {
--- a/toolkit/components/extensions/ExtensionPolicyService.cpp
+++ b/toolkit/components/extensions/ExtensionPolicyService.cpp
@@ -391,21 +391,17 @@ nsresult ExtensionPolicyService::InjectC
     MOZ_TRY(result);
   }
   return NS_OK;
 }
 
 // Checks a request for matching content scripts, and begins pre-loading them
 // if necessary.
 void ExtensionPolicyService::CheckRequest(nsIChannel* aChannel) {
-  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-  if (!loadInfo) {
-    return;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
   auto loadType = loadInfo->GetExternalContentPolicyType();
   if (loadType != nsIContentPolicy::TYPE_DOCUMENT &&
       loadType != nsIContentPolicy::TYPE_SUBDOCUMENT) {
     return;
   }
 
   nsCOMPtr<nsIURI> uri;
   if (NS_FAILED(aChannel->GetURI(getter_AddRefs(uri)))) {
--- a/toolkit/components/extensions/WebExtensionPolicy.cpp
+++ b/toolkit/components/extensions/WebExtensionPolicy.cpp
@@ -740,22 +740,17 @@ bool WindowShouldMatchActiveTab(nsPIDOMW
     return false;
   }
 
   nsIChannel* channel = doc->GetChannel();
   if (!channel) {
     return false;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-
-  if (!loadInfo) {
-    return false;
-  }
-
+  nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
   if (!loadInfo->GetOriginalFrameSrcLoad()) {
     return false;
   }
 
   nsCOMPtr<nsPIDOMWindowOuter> parent = aWin->GetParent();
   MOZ_ASSERT(parent != nullptr);
   return WindowShouldMatchActiveTab(parent);
 }
--- a/toolkit/components/extensions/webrequest/ChannelWrapper.h
+++ b/toolkit/components/extensions/webrequest/ChannelWrapper.h
@@ -175,17 +175,17 @@ class ChannelWrapper final : public DOME
 
   bool Matches(const dom::MozRequestFilter& aFilter,
                const WebExtensionPolicy* aExtension,
                const dom::MozRequestMatchOptions& aOptions) const;
 
   already_AddRefed<nsILoadInfo> GetLoadInfo() const {
     nsCOMPtr<nsIChannel> chan = MaybeChannel();
     if (chan) {
-      return chan->GetLoadInfo();
+      return chan->LoadInfo();
     }
     return nullptr;
   }
 
   int64_t WindowId() const;
 
   int64_t ParentWindowId() const;
 
--- a/toolkit/components/places/nsAnnoProtocolHandler.cpp
+++ b/toolkit/components/places/nsAnnoProtocolHandler.cpp
@@ -46,17 +46,17 @@ using namespace mozilla::places;
  * Creates a channel to obtain the default favicon.
  */
 static nsresult GetDefaultIcon(nsIChannel *aOriginalChannel,
                                nsIChannel **aChannel) {
   nsCOMPtr<nsIURI> defaultIconURI;
   nsresult rv = NS_NewURI(getter_AddRefs(defaultIconURI),
                           NS_LITERAL_CSTRING(FAVICON_DEFAULT_URL));
   NS_ENSURE_SUCCESS(rv, rv);
-  nsCOMPtr<nsILoadInfo> loadInfo = aOriginalChannel->GetLoadInfo();
+  nsCOMPtr<nsILoadInfo> loadInfo = aOriginalChannel->LoadInfo();
   rv = NS_NewChannelInternal(aChannel, defaultIconURI, loadInfo);
   NS_ENSURE_SUCCESS(rv, rv);
   Unused << (*aChannel)->SetContentType(
       NS_LITERAL_CSTRING(FAVICON_DEFAULT_MIMETYPE));
   Unused << aOriginalChannel->SetContentType(
       NS_LITERAL_CSTRING(FAVICON_DEFAULT_MIMETYPE));
   return NS_OK;
 }
@@ -127,17 +127,17 @@ class faviconAsyncLoader : public AsyncS
   NS_IMETHOD HandleCompletion(uint16_t aReason) override {
     MOZ_DIAGNOSTIC_ASSERT(mListener);
     NS_ENSURE_TRUE(mListener, NS_ERROR_UNEXPECTED);
 
     nsresult rv;
     // Ensure we'll break possible cycles with the listener.
     auto cleanup = MakeScopeExit([&]() { mListener = nullptr; });
 
-    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
+    nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
     nsCOMPtr<nsIEventTarget> target =
         nsContentUtils::GetEventTargetByLoadInfo(loadInfo, TaskCategory::Other);
     if (!mData.IsEmpty()) {
       nsCOMPtr<nsIInputStream> stream;
       rv = NS_NewCStringInputStream(getter_AddRefs(stream), mData);
       MOZ_ASSERT(NS_SUCCEEDED(rv));
       if (NS_SUCCEEDED(rv)) {
         RefPtr<nsInputStreamPump> pump;
--- a/toolkit/components/reputationservice/ApplicationReputation.cpp
+++ b/toolkit/components/reputationservice/ApplicationReputation.cpp
@@ -1587,23 +1587,20 @@ nsresult PendingLookup::SendRemoteQueryI
   rv = ios->NewChannel2(serviceUrl, nullptr, nullptr,
                         nullptr,  // aLoadingNode
                         nsContentUtils::GetSystemPrincipal(),
                         nullptr,  // aTriggeringPrincipal
                         nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                         nsIContentPolicy::TYPE_OTHER, getter_AddRefs(mChannel));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-  if (loadInfo) {
-    mozilla::OriginAttributes attrs;
-    attrs.mFirstPartyDomain.AssignLiteral(
-        NECKO_SAFEBROWSING_FIRST_PARTY_DOMAIN);
-    loadInfo->SetOriginAttributes(attrs);
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
+  mozilla::OriginAttributes attrs;
+  attrs.mFirstPartyDomain.AssignLiteral(NECKO_SAFEBROWSING_FIRST_PARTY_DOMAIN);
+  loadInfo->SetOriginAttributes(attrs);
 
   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
   mozilla::Unused << httpChannel;
 
   // Upload the protobuf to the application reputation service.
   nsCOMPtr<nsIUploadChannel2> uploadChannel = do_QueryInterface(mChannel, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -1995,22 +1995,20 @@ nsUrlClassifierDBService::SendThreatHitR
                      nsContentUtils::GetSystemPrincipal(),
                      nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                      nsIContentPolicy::TYPE_OTHER,
                      nullptr,  // aPerformanceStorage
                      nullptr,  // aLoadGroup
                      nullptr, loadFlags);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsILoadInfo> loadInfo = reportChannel->GetLoadInfo();
+  nsCOMPtr<nsILoadInfo> loadInfo = reportChannel->LoadInfo();
   mozilla::OriginAttributes attrs;
   attrs.mFirstPartyDomain.AssignLiteral(NECKO_SAFEBROWSING_FIRST_PARTY_DOMAIN);
-  if (loadInfo) {
-    loadInfo->SetOriginAttributes(attrs);
-  }
+  loadInfo->SetOriginAttributes(attrs);
 
   nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(reportChannel));
   NS_ENSURE_TRUE(uploadChannel, NS_ERROR_FAILURE);
   rv = uploadChannel->SetUploadStream(
       sis, NS_LITERAL_CSTRING("application/x-protobuf"), -1);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(reportChannel));
--- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
@@ -135,22 +135,20 @@ nsresult nsUrlClassifierStreamUpdater::F
                      nsIContentPolicy::TYPE_OTHER,
                      nullptr,  // aPerformanceStorage
                      nullptr,  // aLoadGroup
                      this,     // aInterfaceRequestor
                      loadFlags);
 
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
+  nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
   mozilla::OriginAttributes attrs;
   attrs.mFirstPartyDomain.AssignLiteral(NECKO_SAFEBROWSING_FIRST_PARTY_DOMAIN);
-  if (loadInfo) {
-    loadInfo->SetOriginAttributes(attrs);
-  }
+  loadInfo->SetOriginAttributes(attrs);
 
   mBeganStream = false;
 
   if (!aIsPostRequest) {
     // We use POST method to send our request in v2. In v4, the request
     // needs to be embedded to the URL and use GET method to send.
     // However, from the Chromium source code, a extended HTTP header has
     // to be sent along with the request to make the request succeed.
--- a/toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
@@ -656,34 +656,30 @@ static nsresult AddTabThreatSources(Thre
 
   nsCOMPtr<nsIURI> topUri;
   rv = topChannel->GetURI(getter_AddRefs(topUri));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool isTopUri = false;
   rv = topUri->Equals(uri, &isTopUri);
   if (NS_SUCCEEDED(rv) && !isTopUri) {
-    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
-    if (loadInfo && loadInfo->RedirectChain().Length()) {
+    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+    if (loadInfo->RedirectChain().Length()) {
       AddThreatSourceFromRedirectEntry(aHit, loadInfo->RedirectChain()[0],
                                        ThreatHit_ThreatSourceType_TAB_RESOURCE);
     }
   }
 
   // Set top level tab_url threat source
   rv = AddThreatSourceFromChannel(aHit, topChannel,
                                   ThreatHit_ThreatSourceType_TAB_URL);
   Unused << NS_WARN_IF(NS_FAILED(rv));
 
   // Set tab_redirect threat sources if there's any
-  nsCOMPtr<nsILoadInfo> topLoadInfo = topChannel->GetLoadInfo();
-  if (!topLoadInfo) {
-    return NS_OK;
-  }
-
+  nsCOMPtr<nsILoadInfo> topLoadInfo = topChannel->LoadInfo();
   nsIRedirectHistoryEntry* redirectEntry;
   size_t length = topLoadInfo->RedirectChain().Length();
   for (size_t i = 0; i < length; i++) {
     redirectEntry = topLoadInfo->RedirectChain()[i];
     AddThreatSourceFromRedirectEntry(aHit, redirectEntry,
                                      ThreatHit_ThreatSourceType_TAB_REDIRECT);
   }
 
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -620,17 +620,17 @@ nsresult nsExternalHelperAppService::DoC
 
   nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
   if (channel) {
     channel->GetURI(getter_AddRefs(uri));
     channel->GetContentLength(&contentLength);
     channel->GetContentDisposition(&contentDisposition);
     channel->GetContentDispositionFilename(fileName);
     channel->GetContentDispositionHeader(disp);
-    loadInfo = channel->GetLoadInfo();
+    loadInfo = channel->LoadInfo();
 
     nsCOMPtr<nsIFileChannel> fileChan(do_QueryInterface(aRequest));
     wasFileChannel = fileChan != nullptr;
   }
 
   nsCOMPtr<nsIURI> referrer;
   NS_GetReferrerFromChannel(channel, getter_AddRefs(referrer));
 
@@ -1973,29 +1973,27 @@ nsExternalAppHandler::OnSaveComplete(nsI
 
     // Free the reference that the saver keeps on us, even if we couldn't get
     // the hash.
     mSaver = nullptr;
 
     // Save the redirect information.
     nsCOMPtr<nsIChannel> channel = do_QueryInterface(mRequest);
     if (channel) {
-      nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-      if (loadInfo) {
-        nsresult rv = NS_OK;
-        nsCOMPtr<nsIMutableArray> redirectChain =
-            do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
-        NS_ENSURE_SUCCESS(rv, rv);
-        LOG(("nsExternalAppHandler: Got %zu redirects\n",
-             loadInfo->RedirectChain().Length()));
-        for (nsIRedirectHistoryEntry* entry : loadInfo->RedirectChain()) {
-          redirectChain->AppendElement(entry);
-        }
-        mRedirects = redirectChain;
+      nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+      nsresult rv = NS_OK;
+      nsCOMPtr<nsIMutableArray> redirectChain =
+          do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
+      NS_ENSURE_SUCCESS(rv, rv);
+      LOG(("nsExternalAppHandler: Got %zu redirects\n",
+           loadInfo->RedirectChain().Length()));
+      for (nsIRedirectHistoryEntry* entry : loadInfo->RedirectChain()) {
+        redirectChain->AppendElement(entry);
       }
+      mRedirects = redirectChain;
     }
 
     if (NS_FAILED(aStatus)) {
       nsAutoString path;
       mTempFile->GetPath(path);
 
       // It may happen when e10s is enabled that there will be no transfer
       // object available to communicate status as expected by the system.
--- a/uriloader/prefetch/nsPrefetchService.cpp
+++ b/uriloader/prefetch/nsPrefetchService.cpp
@@ -183,23 +183,21 @@ NS_IMETHODIMP
 nsPrefetchNode::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext) {
   nsresult rv;
 
   nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aRequest, &rv);
   if (NS_FAILED(rv)) return rv;
 
   // if the load is cross origin without CORS, or the CORS access is rejected,
   // always fire load event to avoid leaking site information.
-  nsCOMPtr<nsILoadInfo> loadInfo = httpChannel->GetLoadInfo();
-  if (loadInfo) {
-    mShouldFireLoadEvent =
-        loadInfo->GetTainting() == LoadTainting::Opaque ||
-        (loadInfo->GetTainting() == LoadTainting::CORS &&
-         (NS_FAILED(httpChannel->GetStatus(&rv)) || NS_FAILED(rv)));
-  }
+  nsCOMPtr<nsILoadInfo> loadInfo = httpChannel->LoadInfo();
+  mShouldFireLoadEvent =
+      loadInfo->GetTainting() == LoadTainting::Opaque ||
+      (loadInfo->GetTainting() == LoadTainting::CORS &&
+       (NS_FAILED(httpChannel->GetStatus(&rv)) || NS_FAILED(rv)));
 
   // no need to prefetch http error page
   bool requestSucceeded;
   if (NS_FAILED(httpChannel->GetRequestSucceeded(&requestSucceeded)) ||
       !requestSucceeded) {
     return NS_BINDING_ABORTED;
   }