Bug 1341667 - Part 1. Keep url in nsStyleImage for local-fragment url. r=heycam draft
authorcku <cku@mozilla.com>
Tue, 11 Apr 2017 22:56:41 +0800
changeset 561048 1dffe2649fa2a4b5872fd2b3194a8ab2c29be98e
parent 560921 f40e24f40b4c4556944c762d4764eace261297f5
child 561049 760988606398f580f0c7e081640ea450ab93b1d4
push id53607
push userbmo:cku@mozilla.com
push dateWed, 12 Apr 2017 05:28:42 +0000
reviewersheycam
bugs1341667
milestone55.0a1
Bug 1341667 - Part 1. Keep url in nsStyleImage for local-fragment url. r=heycam MozReview-Commit-ID: KEbO4vZXBJo
layout/style/nsStyleStruct.cpp
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -2028,23 +2028,36 @@ nsStyleImageRequest::~nsStyleImageReques
 bool
 nsStyleImageRequest::Resolve(nsPresContext* aPresContext)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!IsResolved(), "already resolved");
   MOZ_ASSERT(aPresContext);
 
   mResolved = true;
-  mDocGroup = aPresContext->Document()->GetDocGroup();
+
+  nsIDocument* doc = aPresContext->Document();
+  nsIURI* docURI = doc->GetDocumentURI();
+  if (GetImageValue()->HasRef()) {
+    bool isEqualExceptRef = false;
+    RefPtr<nsIURI> imageURI = GetImageURI();
+    imageURI->EqualsExceptRef(docURI, &isEqualExceptRef);
+    if (isEqualExceptRef) {
+      // Prevent loading an internal resource.
+      return true;
+    }
+  }
+
+  mDocGroup = doc->GetDocGroup();
 
   // For now, just have unique nsCSSValue/ImageValue objects.  We should
   // really store the ImageValue on the Servo specified value, so that we can
   // share imgRequestProxys that come from the same rule in the same
   // document.
-  mImageValue->Initialize(aPresContext->Document());
+  mImageValue->Initialize(doc);
 
   nsCSSValue value;
   value.SetImageValue(mImageValue);
   mRequestProxy = value.GetPossiblyStaticImageValue(aPresContext->Document(),
                                                     aPresContext);
 
   if (!mRequestProxy) {
     // The URL resolution or image load failed.
@@ -2388,17 +2401,17 @@ nsStyleImage::IsOpaque() const
   if (!IsComplete()) {
     return false;
   }
 
   if (mType == eStyleImageType_Gradient) {
     return mGradient->IsOpaque();
   }
 
-  if (mType == eStyleImageType_Element) {
+  if (mType == eStyleImageType_Element || mType == eStyleImageType_URL) {
     return false;
   }
 
   MOZ_ASSERT(mType == eStyleImageType_Image, "unexpected image type");
   MOZ_ASSERT(GetImageData(), "should've returned earlier above");
 
   nsCOMPtr<imgIContainer> imageContainer;
   GetImageData()->GetImage(getter_AddRefs(imageContainer));