Bug 1291283 - Use URLValueData::GetLocalURLFlag() to identify local-ref URI. draft
authorcku <cku@mozilla.com>
Thu, 04 Aug 2016 23:50:22 +0800
changeset 397060 eebd321e8477be0720f77ae136c8d3620f662c71
parent 396804 0ba72e8027cfcbcbf3426770ac264a7ade2af090
child 527365 7edacced30bea79cb04eb3fd2a2edb6e04a6d22f
push id25192
push userbmo:cku@mozilla.com
push dateFri, 05 Aug 2016 04:55:26 +0000
bugs1291283
milestone51.0a1
Bug 1291283 - Use URLValueData::GetLocalURLFlag() to identify local-ref URI. MozReview-Commit-ID: 2tXEGMhPCkn
layout/style/nsCSSDataBlock.cpp
--- a/layout/style/nsCSSDataBlock.cpp
+++ b/layout/style/nsCSSDataBlock.cpp
@@ -64,19 +64,34 @@ TryToStartImageLoadOnValue(const nsCSSVa
 #ifdef MOZ_ENABLE_MASK_AS_SHORTHAND
     // The 'mask-image' property accepts local reference URIs.
     // For example,
     //   mask-image: url(#mask_id); // refer to a SVG mask element, whose id is
     //                              // "mask_id", in the current document.
     // For such 'mask-image' values (pointing to an in-document element),
     // there is no need to trigger image download.
     if (aProperty == eCSSProperty_mask_image) {
-      nsIURI* docURI = aDocument->GetDocumentURI();
+      // Filter out all fragment URLs.
+      // Since nsCSSValue::GetURLStructValue runs much faster than
+      // nsIURI::EqualsExceptRef bellow, we get performance gain by this
+      // early return.
+      URLValue* urlValue = aValue.GetURLStructValue();
+      if (urlValue->GetLocalURLFlag()) {
+        return;
+      }
+
+      // Even though urlValue is not a fragment URL, it might still refer to
+      // an internal resource.
+      // For example, aDocument base URL is "http://foo/index.html" and
+      // intentionally references a mask-image at
+      // url(http://foo/index.html#mask) which still refers to a resource in
+      // aDocument.
       nsIURI* imageURI = aValue.GetURLValue();
       if (imageURI) {
+        nsIURI* docURI = aDocument->GetDocumentURI();
         bool isEqualExceptRef = false;
         nsresult  rv = imageURI->EqualsExceptRef(docURI, &isEqualExceptRef);
         if (NS_SUCCEEDED(rv) && isEqualExceptRef) {
           return;
         }
       }
     }
 #endif