Bug 1345168 - Get rid of OriginAttributes::Inherit, r=tjr
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 08 Mar 2017 07:41:51 +0100
changeset 396981 ffed210e1e21c462ac1e4db9f08030724a7d02c2
parent 396980 3de78a28ad060b02ca18021a077860352229f69a
child 396982 a308f1d04a7488ea9de101c6ea82963958b1d92e
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstjr
bugs1345168
milestone55.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 1345168 - Get rid of OriginAttributes::Inherit, r=tjr
caps/BasePrincipal.cpp
caps/BasePrincipal.h
caps/nsNullPrincipal.cpp
caps/nsScriptSecurityManager.cpp
docshell/base/LoadContext.cpp
docshell/base/nsDocShell.cpp
dom/base/nsFrameLoader.cpp
dom/base/nsScriptLoader.cpp
dom/security/nsMixedContentBlocker.cpp
image/imgLoader.cpp
netwerk/base/LoadInfo.cpp
netwerk/base/Predictor.cpp
netwerk/cookie/CookieServiceParent.cpp
netwerk/protocol/http/HttpBaseChannel.cpp
netwerk/protocol/http/nsHttpHandler.cpp
toolkit/components/windowwatcher/nsWindowWatcher.cpp
--- a/caps/BasePrincipal.cpp
+++ b/caps/BasePrincipal.cpp
@@ -46,29 +46,16 @@ OriginAttributes::InitPrefs()
     Preferences::AddBoolVarCache(&sFirstPartyIsolation,
                                  "privacy.firstparty.isolate");
     Preferences::AddBoolVarCache(&sRestrictedOpenerAccess,
                                  "privacy.firstparty.isolate.restrict_opener_access");
   }
 }
 
 void
-OriginAttributes::Inherit(const OriginAttributes& aAttrs)
-{
-  mAppId = aAttrs.mAppId;
-  mInIsolatedMozBrowser = aAttrs.mInIsolatedMozBrowser;
-
-
-  mUserContextId = aAttrs.mUserContextId;
-
-  mPrivateBrowsingId = aAttrs.mPrivateBrowsingId;
-  mFirstPartyDomain = aAttrs.mFirstPartyDomain;
-}
-
-void
 OriginAttributes::SetFirstPartyDomain(const bool aIsTopLevelDocument,
                                       nsIURI* aURI)
 {
   bool isFirstPartyEnabled = IsFirstPartyEnabled();
 
   // When the pref is on, we also compute the firstPartyDomain attribute
   // if this is for top-level document.
   if (isFirstPartyEnabled && aIsTopLevelDocument) {
--- a/caps/BasePrincipal.h
+++ b/caps/BasePrincipal.h
@@ -35,20 +35,16 @@ public:
     mAppId = aAppId;
     mInIsolatedMozBrowser = aInIsolatedMozBrowser;
   }
 
   explicit OriginAttributes(const OriginAttributesDictionary& aOther)
     : OriginAttributesDictionary(aOther)
   {}
 
-  // This method 'clones' the OriginAttributes ignoring the addonId value becaue
-  // this is computed from the principal URI and never propagated.
-  void Inherit(const OriginAttributes& aAttrs);
-
   void SetFirstPartyDomain(const bool aIsTopLevelDocument, nsIURI* aURI);
 
   enum {
     STRIP_FIRST_PARTY_DOMAIN = 0x01,
     STRIP_USER_CONTEXT_ID = 0x02,
   };
 
   inline void StripAttributes(uint32_t aFlags)
--- a/caps/nsNullPrincipal.cpp
+++ b/caps/nsNullPrincipal.cpp
@@ -43,21 +43,19 @@ nsNullPrincipal::CreateWithInheritedAttr
   nsresult rv = nullPrin->Init(Cast(aInheritFrom)->OriginAttributesRef());
   MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
   return nullPrin.forget();
 }
 
 /* static */ already_AddRefed<nsNullPrincipal>
 nsNullPrincipal::CreateWithInheritedAttributes(nsIDocShell* aDocShell)
 {
-  OriginAttributes attrs;
-  attrs.Inherit(nsDocShell::Cast(aDocShell)->GetOriginAttributes());
-
   RefPtr<nsNullPrincipal> nullPrin = new nsNullPrincipal();
-  nsresult rv = nullPrin->Init(attrs);
+  nsresult rv =
+    nullPrin->Init(nsDocShell::Cast(aDocShell)->GetOriginAttributes());
   MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
   return nullPrin.forget();
 }
 
 /* static */ already_AddRefed<nsNullPrincipal>
 nsNullPrincipal::Create(const OriginAttributes& aOriginAttributes, nsIURI* aURI)
 {
   RefPtr<nsNullPrincipal> nullPrin = new nsNullPrincipal();
--- a/caps/nsScriptSecurityManager.cpp
+++ b/caps/nsScriptSecurityManager.cpp
@@ -374,19 +374,21 @@ nsScriptSecurityManager::GetChannelURIPr
     // 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.Inherit(loadInfo->GetOriginAttributes());
+      attrs = loadInfo->GetOriginAttributes();
     }
-    nsCOMPtr<nsIPrincipal> prin = BasePrincipal::CreateCodebasePrincipal(uri, attrs);
+
+    nsCOMPtr<nsIPrincipal> prin =
+      BasePrincipal::CreateCodebasePrincipal(uri, attrs);
     prin.forget(aPrincipal);
     return *aPrincipal ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsScriptSecurityManager::IsSystemPrincipal(nsIPrincipal* aPrincipal,
                                            bool* aIsSystem)
 {
@@ -1138,36 +1140,32 @@ nsScriptSecurityManager::GetAppCodebaseP
 NS_IMETHODIMP
 nsScriptSecurityManager::
   GetLoadContextCodebasePrincipal(nsIURI* aURI,
                                   nsILoadContext* aLoadContext,
                                   nsIPrincipal** aPrincipal)
 {
   NS_ENSURE_STATE(aLoadContext);
   OriginAttributes docShellAttrs;
-  bool result = aLoadContext->GetOriginAttributes(docShellAttrs);;
+  bool result = aLoadContext->GetOriginAttributes(docShellAttrs);
   NS_ENSURE_TRUE(result, NS_ERROR_FAILURE);
 
-  OriginAttributes attrs;
-  attrs.Inherit(docShellAttrs);
-
-  nsCOMPtr<nsIPrincipal> prin = BasePrincipal::CreateCodebasePrincipal(aURI, attrs);
+  nsCOMPtr<nsIPrincipal> prin =
+    BasePrincipal::CreateCodebasePrincipal(aURI, docShellAttrs);
   prin.forget(aPrincipal);
   return *aPrincipal ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsScriptSecurityManager::GetDocShellCodebasePrincipal(nsIURI* aURI,
                                                       nsIDocShell* aDocShell,
                                                       nsIPrincipal** aPrincipal)
 {
-  OriginAttributes attrs;
-  attrs.Inherit(nsDocShell::Cast(aDocShell)->GetOriginAttributes());
-
-  nsCOMPtr<nsIPrincipal> prin = BasePrincipal::CreateCodebasePrincipal(aURI, attrs);
+  nsCOMPtr<nsIPrincipal> prin =
+    BasePrincipal::CreateCodebasePrincipal(aURI, nsDocShell::Cast(aDocShell)->GetOriginAttributes());
   prin.forget(aPrincipal);
   return *aPrincipal ? NS_OK : NS_ERROR_FAILURE;
 }
 
 // static
 nsIPrincipal*
 nsScriptSecurityManager::doGetObjectPrincipal(JSObject *aObj)
 {
--- a/docshell/base/LoadContext.cpp
+++ b/docshell/base/LoadContext.cpp
@@ -46,17 +46,17 @@ LoadContext::LoadContext(nsIPrincipal* a
   , mNestedFrameId(0)
   , mIsContent(true)
   , mUseRemoteTabs(false)
   , mUseTrackingProtection(false)
 #ifdef DEBUG
   , mIsNotNull(true)
 #endif
 {
-  mOriginAttributes.Inherit(aPrincipal->OriginAttributesRef());
+  mOriginAttributes = aPrincipal->OriginAttributesRef();
   if (!aOptionalBase) {
     return;
   }
 
   MOZ_ALWAYS_SUCCEEDS(aOptionalBase->GetIsContent(&mIsContent));
   MOZ_ALWAYS_SUCCEEDS(aOptionalBase->GetUseRemoteTabs(&mUseRemoteTabs));
   MOZ_ALWAYS_SUCCEEDS(aOptionalBase->GetUseTrackingProtection(&mUseTrackingProtection));
 }
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -4998,40 +4998,38 @@ nsDocShell::DisplayLoadError(nsresult aE
       if (errorClass == nsINSSErrorsService::ERROR_CLASS_BAD_CERT) {
         error.AssignLiteral("nssBadCert");
 
         // If this is an HTTP Strict Transport Security host or a pinned host
         // and the certificate is bad, don't allow overrides (RFC 6797 section
         // 12.1, HPKP draft spec section 2.6).
         uint32_t flags =
           UsePrivateBrowsing() ? nsISocketProvider::NO_PERMANENT_STORAGE : 0;
-        OriginAttributes originAttributes;
-        originAttributes.Inherit(mOriginAttributes);
         bool isStsHost = false;
         bool isPinnedHost = false;
         if (XRE_IsParentProcess()) {
           nsCOMPtr<nsISiteSecurityService> sss =
             do_GetService(NS_SSSERVICE_CONTRACTID, &rv);
           NS_ENSURE_SUCCESS(rv, rv);
           rv = sss->IsSecureURI(nsISiteSecurityService::HEADER_HSTS, aURI,
-                                flags, originAttributes, nullptr, &isStsHost);
+                                flags, mOriginAttributes, nullptr, &isStsHost);
           NS_ENSURE_SUCCESS(rv, rv);
           rv = sss->IsSecureURI(nsISiteSecurityService::HEADER_HPKP, aURI,
-                                flags, originAttributes, nullptr,
+                                flags, mOriginAttributes, nullptr,
                                 &isPinnedHost);
           NS_ENSURE_SUCCESS(rv, rv);
         } else {
           mozilla::dom::ContentChild* cc =
             mozilla::dom::ContentChild::GetSingleton();
           mozilla::ipc::URIParams uri;
           SerializeURI(aURI, uri);
           cc->SendIsSecureURI(nsISiteSecurityService::HEADER_HSTS, uri, flags,
-                              originAttributes, &isStsHost);
+                              mOriginAttributes, &isStsHost);
           cc->SendIsSecureURI(nsISiteSecurityService::HEADER_HPKP, uri, flags,
-                              originAttributes, &isPinnedHost);
+                              mOriginAttributes, &isPinnedHost);
         }
 
         if (Preferences::GetBool(
               "browser.xul.error_pages.expert_bad_cert", false)) {
           cssClass.AssignLiteral("expertBadCert");
         }
 
         // HSTS/pinning takes precedence over the expert bad cert pref. We
@@ -9731,20 +9729,18 @@ nsDocShell::JustStartedNetworkLoad()
 {
   return mDocumentRequest && mDocumentRequest != GetCurrentDocChannel();
 }
 
 nsresult
 nsDocShell::CreatePrincipalFromReferrer(nsIURI* aReferrer,
                                         nsIPrincipal** aResult)
 {
-  OriginAttributes attrs;
-  attrs.Inherit(mOriginAttributes);
   nsCOMPtr<nsIPrincipal> prin =
-    BasePrincipal::CreateCodebasePrincipal(aReferrer, attrs);
+    BasePrincipal::CreateCodebasePrincipal(aReferrer, mOriginAttributes);
   prin.forget(aResult);
 
   return *aResult ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsDocShell::InternalLoad(nsIURI* aURI,
                          nsIURI* aOriginalURI,
@@ -10724,21 +10720,21 @@ nsDocShell::InternalLoad(nsIURI* aURI,
 
   nsAutoString srcdoc;
   if (aFlags & INTERNAL_LOAD_FLAGS_IS_SRCDOC) {
     srcdoc = aSrcdoc;
   } else {
     srcdoc = NullString();
   }
 
-  OriginAttributes attrs;
   bool isTopLevelDoc = mItemType == typeContent &&
                        (isTargetTopLevelDocShell ||
                         GetIsMozBrowser());
-  attrs.Inherit(GetOriginAttributes());
+
+  OriginAttributes attrs = GetOriginAttributes();
   attrs.SetFirstPartyDomain(isTopLevelDoc, aURI);
 
   net::PredictorLearn(aURI, nullptr,
                       nsINetworkPredictor::LEARN_LOAD_TOPLEVEL, attrs);
   net::PredictorPredict(aURI, nullptr,
                         nsINetworkPredictor::PREDICT_LOAD, attrs, nullptr);
 
   // Increase pressure on the throttling service so background channels will be
@@ -10980,19 +10976,19 @@ nsDocShell::DoURILoad(nsIURI* aURI,
 
   // 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 &&
                        (aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT ||
                         GetIsMozBrowser());
 
-  OriginAttributes attrs;
-  attrs.Inherit(GetOriginAttributes());
+  OriginAttributes attrs = GetOriginAttributes();
   attrs.SetFirstPartyDomain(isTopLevelDoc, aURI);
+
   rv = loadInfo->SetOriginAttributes(attrs);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (!isSrcdoc) {
     rv = NS_NewChannelInternal(getter_AddRefs(channel),
                                aURI,
@@ -14226,22 +14222,20 @@ nsDocShell::OnOverLink(nsIContent* aCont
   nsAutoCString spec;
   rv = aURI->GetSpec(spec);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoString uStr;
   rv = textToSubURI->UnEscapeURIForUI(charset, spec, uStr);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  OriginAttributes attrs;
-  attrs.Inherit(aContent->NodePrincipal()->OriginAttributesRef());
-
   mozilla::net::PredictorPredict(aURI, mCurrentURI,
                                  nsINetworkPredictor::PREDICT_LINK,
-                                 attrs, nullptr);
+                                 aContent->NodePrincipal()->OriginAttributesRef(),
+                                 nullptr);
 
   if (browserChrome2) {
     nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aContent);
     rv = browserChrome2->SetStatusWithContext(nsIWebBrowserChrome::STATUS_LINK,
                                               uStr, element);
   } else {
     rv = browserChrome->SetStatus(nsIWebBrowserChrome::STATUS_LINK, uStr.get());
   }
@@ -14743,20 +14737,18 @@ nsDocShell::ShouldPrepareForIntercept(ns
 
       if (isThirdPartyURI) {
         return NS_OK;
       }
     }
   }
 
   if (aIsNonSubresourceRequest) {
-    OriginAttributes attrs;
-    attrs.Inherit(mOriginAttributes);
     nsCOMPtr<nsIPrincipal> principal =
-      BasePrincipal::CreateCodebasePrincipal(aURI, attrs);
+      BasePrincipal::CreateCodebasePrincipal(aURI, mOriginAttributes);
     *aShouldIntercept = swm->IsAvailable(principal, aURI);
     return NS_OK;
   }
 
   nsCOMPtr<nsIDocument> doc = GetDocument();
   if (!doc) {
     return NS_ERROR_NOT_AVAILABLE;
   }
@@ -14795,22 +14787,19 @@ nsDocShell::ChannelIntercepted(nsIInterc
     // For top-level navigations, save a document ID which will be passed to
     // the FetchEvent as the clientId later on.
     rv = nsIDocument::GenerateDocumentId(mInterceptedDocumentId);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   bool isReload = mLoadType & LOAD_CMD_RELOAD;
 
-  OriginAttributes attrs;
-  attrs.Inherit(mOriginAttributes);
-
   ErrorResult error;
-  swm->DispatchFetchEvent(attrs, doc, mInterceptedDocumentId, aChannel,
-                          isReload, isSubresourceLoad, error);
+  swm->DispatchFetchEvent(mOriginAttributes, doc, mInterceptedDocumentId,
+                          aChannel, isReload, isSubresourceLoad, error);
   if (NS_WARN_IF(error.Failed())) {
     return error.StealNSResult();
   }
 
   return NS_OK;
 }
 
 bool
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -2447,17 +2447,17 @@ nsFrameLoader::MaybeCreateDocShell()
               "docshell and document should have the same appId attribute.");
     MOZ_ASSERT(attrs.mUserContextId == oa.mUserContextId,
               "docshell and document should have the same userContextId attribute.");
     MOZ_ASSERT(attrs.mInIsolatedMozBrowser == oa.mInIsolatedMozBrowser,
               "docshell and document should have the same inIsolatedMozBrowser attribute.");
     MOZ_ASSERT(attrs.mPrivateBrowsingId == oa.mPrivateBrowsingId,
               "docshell and document should have the same privateBrowsingId attribute.");
 
-    attrs.Inherit(oa);
+    attrs = oa;
   }
 
   if (OwnerIsMozBrowserFrame()) {
     attrs.mAppId = nsIScriptSecurityManager::NO_APP_ID;
     attrs.mInIsolatedMozBrowser = OwnerIsIsolatedMozBrowserFrame();
     mDocShell->SetFrameType(nsIDocShell::FRAME_TYPE_BROWSER);
   }
 
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -1308,21 +1308,19 @@ nsScriptLoader::StartLoad(nsScriptLoadRe
 
     nsCOMPtr<nsIHttpChannelInternal> internalChannel(do_QueryInterface(httpChannel));
     if (internalChannel) {
       rv = internalChannel->SetIntegrityMetadata(aRequest->mIntegrity.GetIntegrityString());
       MOZ_ASSERT(NS_SUCCEEDED(rv));
     }
   }
 
-  OriginAttributes attrs;
-  attrs.Inherit(mDocument->NodePrincipal()->OriginAttributesRef());
-
   mozilla::net::PredictorLearn(aRequest->mURI, mDocument->GetDocumentURI(),
-      nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE, attrs);
+                               nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE,
+                               mDocument->NodePrincipal()->OriginAttributesRef());
 
   // Set the initiator type
   nsCOMPtr<nsITimedChannel> timedChannel(do_QueryInterface(httpChannel));
   if (timedChannel) {
     timedChannel->SetInitiatorType(NS_LITERAL_STRING("script"));
   }
 
   nsAutoPtr<mozilla::dom::SRICheckDataVerifier> sriDataVerifier;
--- a/dom/security/nsMixedContentBlocker.cpp
+++ b/dom/security/nsMixedContentBlocker.cpp
@@ -861,19 +861,19 @@ nsMixedContentBlocker::ShouldLoad(bool a
   if (!securityUI) {
     *aDecision = nsIContentPolicy::ACCEPT;
     return NS_OK;
   }
   nsresult stateRV = securityUI->GetState(&state);
 
   OriginAttributes originAttributes;
   if (principal) {
-    originAttributes.Inherit(principal->OriginAttributesRef());
+    originAttributes = principal->OriginAttributesRef();
   } else if (aRequestPrincipal) {
-    originAttributes.Inherit(aRequestPrincipal->OriginAttributesRef());
+    originAttributes = aRequestPrincipal->OriginAttributesRef();
   }
 
   bool doHSTSPriming = false;
   if (IsEligibleForHSTSPriming(aContentLocation)) {
     bool hsts = false;
     bool cached = false;
     nsCOMPtr<nsISiteSecurityService> sss =
       do_GetService(NS_SSSERVICE_CONTRACTID, &rv);
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -767,22 +767,21 @@ NewImageChannel(nsIChannel** aResult,
     if (NS_FAILED(rv)) {
       return rv;
     }
 
     if (aPolicyType == nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON) {
       // If this is a favicon loading, we will use the originAttributes from the
       // loadingPrincipal as the channel's originAttributes. This allows the favicon
       // loading from XUL will use the correct originAttributes.
-      OriginAttributes attrs;
-      attrs.Inherit(aLoadingPrincipal->OriginAttributesRef());
 
       nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->GetLoadInfo();
       if (loadInfo) {
-        rv = loadInfo->SetOriginAttributes(attrs);
+        rv =
+          loadInfo->SetOriginAttributes(aLoadingPrincipal->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 loadingPrincipal and
     // triggeringPrincipal should always be the systemPrincipal.
     // However, there are exceptions: one is Notifications which create a
@@ -800,17 +799,17 @@ NewImageChannel(nsIChannel** aResult,
       return rv;
     }
 
     // Use the OriginAttributes from the loading principal, if one is available,
     // and adjust the private browsing ID based on what kind of load the caller
     // has asked us to perform.
     OriginAttributes attrs;
     if (aLoadingPrincipal) {
-      attrs.Inherit(aLoadingPrincipal->OriginAttributesRef());
+      attrs = aLoadingPrincipal->OriginAttributesRef();
     }
     attrs.mPrivateBrowsingId = aRespectPrivacy ? 1 : 0;
 
     nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->GetLoadInfo();
     if (loadInfo) {
       rv = loadInfo->SetOriginAttributes(attrs);
     }
   }
@@ -2344,17 +2343,17 @@ imgLoader::LoadImageWithChannel(nsIChann
   channel->GetURI(getter_AddRefs(uri));
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(aCX);
 
   NS_ENSURE_TRUE(channel, NS_ERROR_FAILURE);
   nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
 
   OriginAttributes attrs;
   if (loadInfo) {
-    attrs.Inherit(loadInfo->GetOriginAttributes());
+    attrs = loadInfo->GetOriginAttributes();
   }
 
   nsresult rv;
   ImageCacheKey key(uri, attrs, doc, rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsLoadFlags requestFlags = nsIRequest::LOAD_NORMAL;
   channel->GetLoadFlags(&requestFlags);
--- a/netwerk/base/LoadInfo.cpp
+++ b/netwerk/base/LoadInfo.cpp
@@ -23,23 +23,16 @@
 #include "nsGlobalWindow.h"
 #include "nsNullPrincipal.h"
 
 using namespace mozilla::dom;
 
 namespace mozilla {
 namespace net {
 
-static void
-InheritOriginAttributes(nsIPrincipal* aLoadingPrincipal,
-                        OriginAttributes& aAttrs)
-{
-  aAttrs.Inherit(aLoadingPrincipal->OriginAttributesRef());
-}
-
 LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
                    nsIPrincipal* aTriggeringPrincipal,
                    nsINode* aLoadingContext,
                    nsSecurityFlags aSecurityFlags,
                    nsContentPolicyType aContentPolicyType)
   : mLoadingPrincipal(aLoadingContext ?
                         aLoadingContext->NodePrincipal() : aLoadingPrincipal)
   , mTriggeringPrincipal(aTriggeringPrincipal ?
@@ -172,17 +165,17 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadin
         aLoadingPrincipal->GetPreloadCsp(getter_AddRefs(preloadCSP));
         if (preloadCSP) {
           preloadCSP->RequireSRIForType(externalType, &mEnforceSRI);
         }
       }
     }
   }
 
-  InheritOriginAttributes(mLoadingPrincipal, mOriginAttributes);
+  mOriginAttributes = mLoadingPrincipal->OriginAttributesRef();
 
   // We need to do this after inheriting the document's origin attributes
   // above, in case the loading principal ends up being the system principal.
   if (aLoadingContext) {
     nsCOMPtr<nsILoadContext> loadContext =
       aLoadingContext->OwnerDoc()->GetLoadContext();
     nsCOMPtr<nsIDocShell> docShell = aLoadingContext->OwnerDoc()->GetDocShell();
     if (loadContext && docShell &&
@@ -256,25 +249,24 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* a
   // TODO We can have a parent without a frame element in some cases dealing
   // with the hidden window.
   nsCOMPtr<nsPIDOMWindowOuter> parent = aOuterWindow->GetScriptableParent();
   mParentOuterWindowID = parent ? parent->WindowID() : 0;
 
   // get the docshell from the outerwindow, and then get the originattributes
   nsCOMPtr<nsIDocShell> docShell = aOuterWindow->GetDocShell();
   MOZ_ASSERT(docShell);
-  const OriginAttributes attrs =
-    nsDocShell::Cast(docShell)->GetOriginAttributes();
+  mOriginAttributes = nsDocShell::Cast(docShell)->GetOriginAttributes();
 
+#ifdef DEBUG
   if (docShell->ItemType() == nsIDocShellTreeItem::typeChrome) {
-    MOZ_ASSERT(attrs.mPrivateBrowsingId == 0,
+    MOZ_ASSERT(mOriginAttributes.mPrivateBrowsingId == 0,
                "chrome docshell shouldn't have mPrivateBrowsingId set.");
   }
-
-  mOriginAttributes.Inherit(attrs);
+#endif
 }
 
 LoadInfo::LoadInfo(const LoadInfo& rhs)
   : mLoadingPrincipal(rhs.mLoadingPrincipal)
   , mTriggeringPrincipal(rhs.mTriggeringPrincipal)
   , mPrincipalToInherit(rhs.mPrincipalToInherit)
   , mSandboxedLoadingPrincipal(rhs.mSandboxedLoadingPrincipal)
   , mLoadingContext(rhs.mLoadingContext)
@@ -719,19 +711,18 @@ LoadInfo::GetScriptableOriginAttributes(
   return NS_OK;
 }
 
 NS_IMETHODIMP
 LoadInfo::ResetPrincipalsToNullPrincipal()
 {
   // take the originAttributes from the LoadInfo and create
   // a new NullPrincipal using those origin attributes.
-  OriginAttributes attrs;
-  attrs.Inherit(mOriginAttributes);
-  nsCOMPtr<nsIPrincipal> newNullPrincipal = nsNullPrincipal::Create(attrs);
+  nsCOMPtr<nsIPrincipal> newNullPrincipal =
+    nsNullPrincipal::Create(mOriginAttributes);
 
   MOZ_ASSERT(mInternalContentPolicyType != nsIContentPolicy::TYPE_DOCUMENT ||
              !mLoadingPrincipal,
              "LoadingPrincipal should be null for toplevel loads");
 
   // the loadingPrincipal for toplevel loads is always a nullptr;
   if (mInternalContentPolicyType != nsIContentPolicy::TYPE_DOCUMENT) {
     mLoadingPrincipal = newNullPrincipal;
--- a/netwerk/base/Predictor.cpp
+++ b/netwerk/base/Predictor.cpp
@@ -2276,20 +2276,17 @@ PredictorLearn(nsIURI *targetURI, nsIURI
 
   if (loadGroup) {
     nsCOMPtr<nsIInterfaceRequestor> callbacks;
     loadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
     if (callbacks) {
       loadContext = do_GetInterface(callbacks);
 
       if (loadContext) {
-        OriginAttributes dAttrs;
-        loadContext->GetOriginAttributes(dAttrs);
-
-        originAttributes.Inherit(dAttrs);
+        loadContext->GetOriginAttributes(originAttributes);
       }
     }
   }
 
   return predictor->LearnNative(targetURI, sourceURI, reason, originAttributes);
 }
 
 nsresult
@@ -2308,19 +2305,18 @@ PredictorLearn(nsIURI *targetURI, nsIURI
   NS_ENSURE_SUCCESS(rv, rv);
 
   OriginAttributes originAttributes;
 
   if (document) {
     nsCOMPtr<nsIPrincipal> docPrincipal = document->NodePrincipal();
 
     if (docPrincipal) {
-      originAttributes.Inherit(docPrincipal->OriginAttributesRef());
+      originAttributes = docPrincipal->OriginAttributesRef();
     }
-
   }
 
   return predictor->LearnNative(targetURI, sourceURI, reason, originAttributes);
 }
 
 nsresult
 PredictorLearnRedirect(nsIURI *targetURI, nsIChannel *channel,
                        const OriginAttributes& originAttributes)
--- a/netwerk/cookie/CookieServiceParent.cpp
+++ b/netwerk/cookie/CookieServiceParent.cpp
@@ -25,21 +25,18 @@ using mozilla::net::NeckoParent;
 namespace {
 
 // Ignore failures from this function, as they only affect whether we do or
 // don't show a dialog box in private browsing mode if the user sets a pref.
 void
 CreateDummyChannel(nsIURI* aHostURI, OriginAttributes& aAttrs, bool aIsPrivate,
                    nsIChannel** aChannel)
 {
-  OriginAttributes attrs;
-  attrs.Inherit(aAttrs);
-
   nsCOMPtr<nsIPrincipal> principal =
-    BasePrincipal::CreateCodebasePrincipal(aHostURI, attrs);
+    BasePrincipal::CreateCodebasePrincipal(aHostURI, aAttrs);
   if (!principal) {
     return;
   }
 
   nsCOMPtr<nsIURI> dummyURI;
   nsresult rv = NS_NewURI(getter_AddRefs(dummyURI), "about:blank");
   if (NS_FAILED(rv)) {
       return;
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -3137,17 +3137,17 @@ HttpBaseChannel::SetupReplacementChannel
 
       MOZ_ASSERT(docShellAttrs.mUserContextId == attrs.mUserContextId,
                 "docshell and necko should have the same userContextId attribute.");
       MOZ_ASSERT(docShellAttrs.mInIsolatedMozBrowser == attrs.mInIsolatedMozBrowser,
                 "docshell and necko should have the same inIsolatedMozBrowser attribute.");
       MOZ_ASSERT(docShellAttrs.mPrivateBrowsingId == attrs.mPrivateBrowsingId,
                  "docshell and necko should have the same privateBrowsingId attribute.");
 
-      attrs.Inherit(docShellAttrs);
+      attrs = docShellAttrs;
       attrs.SetFirstPartyDomain(true, newURI);
       newLoadInfo->SetOriginAttributes(attrs);
     }
 
     bool isInternalRedirect =
       (redirectFlags & (nsIChannelEventSink::REDIRECT_INTERNAL |
                         nsIChannelEventSink::REDIRECT_STS_UPGRADE));
     newLoadInfo->AppendRedirectedPrincipal(GetURIPrincipal(), isInternalRedirect);
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -2177,17 +2177,17 @@ nsHttpHandler::SpeculativeConnectInterna
     if (loadContext && loadContext->UsePrivateBrowsing())
         flags |= nsISocketProvider::NO_PERMANENT_STORAGE;
 
     OriginAttributes originAttributes;
     // If the principal is given, we use the originAttributes from this
     // principal. Otherwise, we use the originAttributes from the
     // loadContext.
     if (aPrincipal) {
-        originAttributes.Inherit(aPrincipal->OriginAttributesRef());
+        originAttributes = aPrincipal->OriginAttributesRef();
     } else if (loadContext) {
         loadContext->GetOriginAttributes(originAttributes);
     }
 
     nsCOMPtr<nsIURI> clone;
     if (NS_SUCCEEDED(sss->IsSecureURI(nsISiteSecurityService::HEADER_HSTS,
                                       aURI, flags, originAttributes,
                                       nullptr, &isStsHost)) &&
--- a/toolkit/components/windowwatcher/nsWindowWatcher.cpp
+++ b/toolkit/components/windowwatcher/nsWindowWatcher.cpp
@@ -1093,20 +1093,19 @@ nsWindowWatcher::OpenWindowInternal(mozI
   if (windowIsNew) {
     auto* docShell = static_cast<nsDocShell*>(newDocShell.get());
 
     // If this is not a chrome docShell, we apply originAttributes from the
     // subjectPrincipal unless if it's an expanded or system principal.
     if (subjectPrincipal &&
         !nsContentUtils::IsSystemOrExpandedPrincipal(subjectPrincipal) &&
         docShell->ItemType() != nsIDocShellTreeItem::typeChrome) {
-      OriginAttributes attrs;
-      attrs.Inherit(subjectPrincipal->OriginAttributesRef());
-      isPrivateBrowsingWindow = !!attrs.mPrivateBrowsingId;
-      docShell->SetOriginAttributes(attrs);
+      isPrivateBrowsingWindow =
+        !!subjectPrincipal->OriginAttributesRef().mPrivateBrowsingId;
+      docShell->SetOriginAttributes(subjectPrincipal->OriginAttributesRef());
     } else {
       nsCOMPtr<nsIDocShellTreeItem> parentItem;
       GetWindowTreeItem(aParent, getter_AddRefs(parentItem));
       nsCOMPtr<nsILoadContext> parentContext = do_QueryInterface(parentItem);
       if (parentContext) {
         isPrivateBrowsingWindow = parentContext->UsePrivateBrowsing();
       }
     }