Bug 1623379 - nsMixedContentBlocker.cpp r=ckerschb
authorSebastian Streich <sstreich@mozilla.com>
Tue, 24 Mar 2020 12:03:17 +0000
changeset 520211 6f13cd068474c9cdb5cc2ee81b854cd2feb5998a
parent 520210 8794663e89e0cff217fed41ea79b60c3de94bfb1
child 520212 7be47bd25f460a29042f9e19a6d5be23b8c77453
push id37245
push useropoprus@mozilla.com
push dateTue, 24 Mar 2020 21:46:41 +0000
treeherdermozilla-central@dbabf2e388fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1623379
milestone76.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 1623379 - nsMixedContentBlocker.cpp r=ckerschb Differential Revision: https://phabricator.services.mozilla.com/D67349
dom/security/nsMixedContentBlocker.cpp
--- a/dom/security/nsMixedContentBlocker.cpp
+++ b/dom/security/nsMixedContentBlocker.cpp
@@ -351,18 +351,22 @@ nsMixedContentBlocker::ShouldLoad(nsIURI
                                   nsILoadInfo* aLoadInfo,
                                   const nsACString& aMimeGuess,
                                   int16_t* aDecision) {
   uint32_t contentType = aLoadInfo->InternalContentPolicyType();
   nsCOMPtr<nsISupports> requestingContext = aLoadInfo->GetLoadingContext();
   nsCOMPtr<nsIPrincipal> requestPrincipal = aLoadInfo->TriggeringPrincipal();
   nsCOMPtr<nsIURI> requestingLocation;
   nsCOMPtr<nsIPrincipal> loadingPrincipal = aLoadInfo->LoadingPrincipal();
-  if (loadingPrincipal) {
-    loadingPrincipal->GetURI(getter_AddRefs(requestingLocation));
+
+  // We need to get a Requesting Location if possible
+  // so we're casting to BasePrincipal to acess GetURI
+  auto* basePrin = BasePrincipal::Cast(loadingPrincipal);
+  if (basePrin) {
+    basePrin->GetURI(getter_AddRefs(requestingLocation));
   }
 
   // We pass in false as the first parameter to ShouldLoad(), because the
   // callers of this method don't know whether the load went through cached
   // image redirects.  This is handled by direct callers of the static
   // ShouldLoad.
   nsresult rv =
       ShouldLoad(false,  // aHadInsecureImageRedirect
@@ -730,18 +734,21 @@ nsresult nsMixedContentBlocker::ShouldLo
     nsCOMPtr<nsIScriptObjectPrincipal> scriptObjPrin =
         do_QueryInterface(aRequestingContext);
     if (scriptObjPrin) {
       principal = scriptObjPrin->GetPrincipal();
     }
   }
 
   nsCOMPtr<nsIURI> requestingLocation;
-  if (principal) {
-    principal->GetURI(getter_AddRefs(requestingLocation));
+  // We need to get a Requesting Location if possible
+  // so we're casting to BasePrincipal to acess GetURI
+  auto* basePrin = BasePrincipal::Cast(principal);
+  if (basePrin) {
+    basePrin->GetURI(getter_AddRefs(requestingLocation));
   }
 
   // 2) if aRequestingContext yields a principal but no location, we check if
   // its a system principal.
   if (principal && !requestingLocation) {
     if (principal->IsSystemPrincipal()) {
       *aDecision = ACCEPT;
       return NS_OK;