Bug 1496308 - Require URLExtraData::mPrincipal to be non-null r=emilio
authorCameron McCormack <cam@mcc.id.au>
Wed, 10 Oct 2018 03:10:07 +0000
changeset 496150 7bfe1c7c5d89664f6d004e94fc1ed42c43ec22f8
parent 496149 8d795e0fa2851bcb88d886ad5197aee8bffb22f6
child 496151 fc14ec1e17384de01a6d439b5cdcb1ce166f5118
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1496308
milestone64.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 1496308 - Require URLExtraData::mPrincipal to be non-null r=emilio Differential Revision: https://phabricator.services.mozilla.com/D7682
dom/base/Element.cpp
dom/base/nsDocument.cpp
layout/base/nsCSSFrameConstructor.cpp
layout/style/FontFaceSet.cpp
layout/style/ServoBindings.cpp
layout/style/URLExtraData.h
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -617,17 +617,17 @@ Element::WrapObject(JSContext *aCx, JS::
     bool ok = GetBindingURL(doc, getter_AddRefs(bindingURL));
     if (!ok) {
       dom::Throw(aCx, NS_ERROR_FAILURE);
       return nullptr;
     }
 
     if (bindingURL) {
       nsCOMPtr<nsIURI> uri = bindingURL->GetURI();
-      nsCOMPtr<nsIPrincipal> principal = bindingURL->mExtraData->GetPrincipal();
+      nsCOMPtr<nsIPrincipal> principal = bindingURL->mExtraData->Principal();
 
       // We have a binding that must be installed.
       bool dummy;
 
       nsXBLService* xblService = nsXBLService::GetInstance();
       if (!xblService) {
         dom::Throw(aCx, NS_ERROR_NOT_AVAILABLE);
         return nullptr;
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -3794,17 +3794,17 @@ nsIDocument::DefaultStyleAttrURLData()
   nsIURI* baseURI = GetDocBaseURI();
   nsIURI* docURI = GetDocumentURI();
   nsIPrincipal* principal = NodePrincipal();
   mozilla::net::ReferrerPolicy policy = GetReferrerPolicy();
   if (!mCachedURLData ||
       mCachedURLData->BaseURI() != baseURI ||
       mCachedURLData->GetReferrer() != docURI ||
       mCachedURLData->GetReferrerPolicy() != policy ||
-      mCachedURLData->GetPrincipal() != principal) {
+      mCachedURLData->Principal() != principal) {
     mCachedURLData = new URLExtraData(baseURI, docURI, principal, policy);
   }
   return mCachedURLData;
 }
 
 void
 nsIDocument::SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding)
 {
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -2421,17 +2421,17 @@ nsCSSFrameConstructor::ConstructDocEleme
 
     nsXBLService* xblService = nsXBLService::GetInstance();
     if (!xblService) {
       return nullptr;
     }
 
     RefPtr<nsXBLBinding> binding;
     rv = xblService->LoadBindings(aDocElement, display->mBinding->GetURI(),
-                                  display->mBinding->mExtraData->GetPrincipal(),
+                                  display->mBinding->mExtraData->Principal(),
                                   getter_AddRefs(binding), &resolveStyle);
     if (NS_FAILED(rv) && rv != NS_ERROR_XBL_BLOCKED) {
       // Binding will load asynchronously.
       return nullptr;
     }
 
     if (binding) {
       // For backwards compat, keep firing the root's constructor
@@ -5574,17 +5574,17 @@ nsCSSFrameConstructor::LoadXBLBindingIfN
     return { };
   }
 
   auto newPendingBinding = MakeUnique<PendingBinding>();
 
   bool resolveStyle;
   nsresult rv = xblService->LoadBindings(aContent.AsElement(),
                                          binding->GetURI(),
-                                         binding->mExtraData->GetPrincipal(),
+                                         binding->mExtraData->Principal(),
                                          getter_AddRefs(newPendingBinding->mBinding),
                                          &resolveStyle);
   if (NS_FAILED(rv)) {
     if (rv == NS_ERROR_XBL_BLOCKED) {
       return { aContent, aStyle };
     }
     return { };
   }
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -1100,18 +1100,17 @@ FontFaceSet::FindOrCreateUserFontEntryFr
         case StyleFontFaceSourceListComponent::Tag::Url: {
           face->mSourceType = gfxFontFaceSrc::eSourceType_URL;
           const URLValue* url = component.url._0;
           nsIURI* uri = url->GetURI();
           face->mURI = uri ? new gfxFontSrcURI(uri) : nullptr;
           face->mReferrer = url->mExtraData->GetReferrer();
           face->mReferrerPolicy = url->mExtraData->GetReferrerPolicy();
           face->mOriginPrincipal =
-            new gfxFontSrcPrincipal(url->mExtraData->GetPrincipal());
-          NS_ASSERTION(face->mOriginPrincipal, "null origin principal in @font-face rule");
+            new gfxFontSrcPrincipal(url->mExtraData->Principal());
 
           // agent and user stylesheets are treated slightly differently,
           // the same-site origin check and access control headers are
           // enforced against the sheet principal rather than the document
           // principal to allow user stylesheets to include @font-face rules
           face->mUseOriginPrincipal = (aSheetType == SheetType::User ||
                                        aSheetType == SheetType::Agent);
 
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -1383,18 +1383,16 @@ const AnonymousCounterStyle*
 Gecko_CounterStyle_GetAnonymous(const CounterStylePtr* aPtr)
 {
   return aPtr->AsAnonymous();
 }
 
 already_AddRefed<css::URLValue>
 ServoBundledURI::IntoCssUrl(CORSMode aCorsMode)
 {
-  MOZ_ASSERT(mExtraData->GetPrincipal());
-
   RefPtr<css::URLValue> urlValue =
     new css::URLValue(mURLString, do_AddRef(mExtraData), aCorsMode);
   return urlValue.forget();
 }
 
 void
 Gecko_SetNullImageValue(nsStyleImage* aImage)
 {
@@ -2576,17 +2574,17 @@ LoadImportSheet(css::Loader* aLoader,
     RefPtr<StyleSheet> emptySheet =
       aParent->CreateEmptyChildSheet(media.forget());
     // Make a dummy URI if we don't have one because some methods assume
     // non-null URIs.
     if (!uri) {
       NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:invalid"));
     }
     emptySheet->SetURIs(uri, uri, uri);
-    emptySheet->SetPrincipal(aURL->mExtraData->GetPrincipal());
+    emptySheet->SetPrincipal(aURL->mExtraData->Principal());
     emptySheet->SetComplete();
     aParent->PrependStyleSheet(emptySheet);
     return emptySheet.forget();
   }
 
   RefPtr<StyleSheet> sheet =
     static_cast<StyleSheet*>(aParent->GetFirstChild());
   return sheet.forget();
--- a/layout/style/URLExtraData.h
+++ b/layout/style/URLExtraData.h
@@ -30,31 +30,32 @@ struct URLExtraData
     , mReferrer(std::move(aReferrer))
     , mReferrerPolicy(aReferrerPolicy)
     , mPrincipal(std::move(aPrincipal))
       // When we hold the URI data of a style sheet, mReferrer is always
       // equal to the sheet URI.
     , mIsChrome(mReferrer ? dom::IsChromeURI(mReferrer) : false)
   {
     MOZ_ASSERT(mBaseURI);
+    MOZ_ASSERT(mPrincipal);
   }
 
   URLExtraData(nsIURI* aBaseURI, nsIURI* aReferrer, nsIPrincipal* aPrincipal,
                net::ReferrerPolicy aReferrerPolicy)
     : URLExtraData(do_AddRef(aBaseURI),
                    do_AddRef(aReferrer),
                    do_AddRef(aPrincipal),
                    aReferrerPolicy) {}
 
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(URLExtraData)
 
   nsIURI* BaseURI() const { return mBaseURI; }
   nsIURI* GetReferrer() const { return mReferrer; }
   net::ReferrerPolicy GetReferrerPolicy() const { return mReferrerPolicy;}
-  nsIPrincipal* GetPrincipal() const { return mPrincipal; }
+  nsIPrincipal* Principal() const { return mPrincipal; }
 
   static URLExtraData* Dummy() {
     MOZ_ASSERT(sDummy);
     return sDummy;
   }
   static void InitDummy();
   static void ReleaseDummy();
 
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -905,35 +905,34 @@ css::URLValue::Equals(const URLValue& aO
   return GetString() == aOther.GetString() &&
           (GetURI() == aOther.GetURI() || // handles null == null
            (mURI && aOther.mURI &&
             NS_SUCCEEDED(mURI->Equals(aOther.mURI, &eq)) &&
             eq)) &&
           (self->BaseURI() == other->BaseURI() ||
            (NS_SUCCEEDED(self->BaseURI()->Equals(other->BaseURI(), &eq)) &&
             eq)) &&
-          (self->GetPrincipal() == other->GetPrincipal() ||
-           self->GetPrincipal()->Equals(other->GetPrincipal())) &&
+          self->Principal()->Equals(other->Principal()) &&
           IsLocalRef() == aOther.IsLocalRef();
 }
 
 bool
 css::URLValue::DefinitelyEqualURIs(const URLValue& aOther) const
 {
   if (mExtraData->BaseURI() != aOther.mExtraData->BaseURI()) {
     return false;
   }
   return GetString() == aOther.GetString();
 }
 
 bool
 css::URLValue::DefinitelyEqualURIsAndPrincipal(
     const URLValue& aOther) const
 {
-  return mExtraData->GetPrincipal() == aOther.mExtraData->GetPrincipal() &&
+  return mExtraData->Principal() == aOther.mExtraData->Principal() &&
          DefinitelyEqualURIs(aOther);
 }
 
 nsDependentCSubstring
 css::URLValue::GetString() const
 {
   const uint8_t* chars;
   uint32_t len;
@@ -1074,17 +1073,17 @@ css::URLValue::LoadImage(nsIDocument* aD
   // and clone it to aDocument.
   nsIDocument* loadingDoc = aDocument->GetOriginalDocument();
   if (!loadingDoc) {
     loadingDoc = aDocument;
   }
 
   // Kick off the load in the loading document.
   ImageLoader::LoadImage(GetURI(),
-                         mExtraData->GetPrincipal(),
+                         mExtraData->Principal(),
                          mExtraData->GetReferrer(),
                          mExtraData->GetReferrerPolicy(),
                          loadingDoc,
                          this,
                          mCORSMode);
 
   // Register the image in the document that's using it.
   return aDocument->StyleImageLoader()->RegisterCSSImage(this);
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -91,30 +91,29 @@ class CSSStyleSheet;
   }
 
 namespace mozilla {
 namespace css {
 
 struct URLValue final
 {
 public:
-  // aString must not be null.
-  // principal of aExtraData must not be null.
+  // aString and aExtraData must not be null.
+  //
   // Construct with a base URI; this will create the actual URI lazily from
   // aString and aExtraData.
   URLValue(ServoRawOffsetArc<RustString> aString,
            already_AddRefed<URLExtraData> aExtraData,
            CORSMode aCORSMode)
     : mExtraData(std::move(aExtraData))
     , mURIResolved(false)
     , mString(aString)
     , mCORSMode(aCORSMode)
   {
     MOZ_ASSERT(mExtraData);
-    MOZ_ASSERT(mExtraData->GetPrincipal());
   }
 
   // Returns true iff all fields of the two URLValue objects are equal.
   //
   // Only safe to call on the main thread, since this will call Equals on the
   // nsIURI and nsIPrincipal objects stored on the URLValue objects.
   bool Equals(const URLValue& aOther) const;