Ejemplo n.º 1
0
/**
 * Tries to call |nsCSSValue::StartImageLoad()| on an image source.
 * Image sources are specified by |url()| or |-moz-image-rect()| function.
 */
static void
TryToStartImageLoadOnValue(const nsCSSValue& aValue, nsIDocument* aDocument,
                           nsCSSValueTokenStream* aTokenStream)
{
  MOZ_ASSERT(aDocument);

  if (aValue.GetUnit() == eCSSUnit_URL) {
    aValue.StartImageLoad(aDocument);
    if (aTokenStream) {
      aTokenStream->mImageValues.PutEntry(aValue.GetImageStructValue());
    }
  }
  else if (aValue.GetUnit() == eCSSUnit_Image) {
    // If we already have a request, see if this document needs to clone it.
    imgIRequest* request = aValue.GetImageValue(nullptr);

    if (request) {
      mozilla::css::ImageValue* imageValue = aValue.GetImageStructValue();
      aDocument->StyleImageLoader()->MaybeRegisterCSSImage(imageValue);
      if (aTokenStream) {
        aTokenStream->mImageValues.PutEntry(imageValue);
      }
    }
  }
  else if (aValue.EqualsFunction(eCSSKeyword__moz_image_rect)) {
    nsCSSValue::Array* arguments = aValue.GetArrayValue();
    MOZ_ASSERT(arguments->Count() == 6, "unexpected num of arguments");

    const nsCSSValue& image = arguments->Item(1);
    TryToStartImageLoadOnValue(image, aDocument, aTokenStream);
  }
}
Ejemplo n.º 2
0
/**
 * Tries to call |nsCSSValue::StartImageLoad()| on an image source.
 * Image sources are specified by |url()| or |-moz-image-rect()| function.
 */
static void
TryToStartImageLoadOnValue(const nsCSSValue& aValue, nsIDocument* aDocument,
                           nsStyleContext* aContext, nsCSSProperty aProperty,
                           bool aForTokenStream)
{
  MOZ_ASSERT(aDocument);

  if (aValue.GetUnit() == eCSSUnit_URL) {
    aValue.StartImageLoad(aDocument);
    if (aForTokenStream && aContext) {
      CSSVariableImageTable::Add(aContext, aProperty,
                                 aValue.GetImageStructValue());
    }
  }
  else if (aValue.GetUnit() == eCSSUnit_Image) {
    // If we already have a request, see if this document needs to clone it.
    imgIRequest* request = aValue.GetImageValue(nullptr);

    if (request) {
      ImageValue* imageValue = aValue.GetImageStructValue();
      aDocument->StyleImageLoader()->MaybeRegisterCSSImage(imageValue);
      if (aForTokenStream && aContext) {
        CSSVariableImageTable::Add(aContext, aProperty, imageValue);
      }
    }
  }
  else if (aValue.EqualsFunction(eCSSKeyword__moz_image_rect)) {
    nsCSSValue::Array* arguments = aValue.GetArrayValue();
    MOZ_ASSERT(arguments->Count() == 6, "unexpected num of arguments");

    const nsCSSValue& image = arguments->Item(1);
    TryToStartImageLoadOnValue(image, aDocument, aContext, aProperty,
                               aForTokenStream);
  }
}
Ejemplo n.º 3
0
/**
 * Tries to call |nsCSSValue::StartImageLoad()| on an image source.
 * Image sources are specified by |url()| or |-moz-image-rect()| function.
 */
static void
TryToStartImageLoadOnValue(const nsCSSValue& aValue, nsIDocument* aDocument)
{
  if (aValue.GetUnit() == eCSSUnit_URL) {
    aValue.StartImageLoad(aDocument);
  }
  else if (aValue.EqualsFunction(eCSSKeyword__moz_image_rect)) {
    nsCSSValue::Array* arguments = aValue.GetArrayValue();
    NS_ABORT_IF_FALSE(arguments->Count() == 6, "unexpected num of arguments");

    const nsCSSValue& image = arguments->Item(1);
    if (image.GetUnit() == eCSSUnit_URL)
      image.StartImageLoad(aDocument);
  }
}
Ejemplo n.º 4
0
/**
 * Tries to call |nsCSSValue::StartImageLoad()| on an image source.
 * Image sources are specified by |url()| or |-moz-image-rect()| function.
 */
static void
TryToStartImageLoadOnValue(const nsCSSValue& aValue, nsIDocument* aDocument,
                           nsStyleContext* aContext, nsCSSPropertyID aProperty,
                           bool aForTokenStream)
{
  MOZ_ASSERT(aDocument);

  if (aValue.GetUnit() == eCSSUnit_URL) {
#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) {
      // 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
    aValue.StartImageLoad(aDocument);
    if (aForTokenStream && aContext) {
      CSSVariableImageTable::Add(aContext, aProperty,
                                 aValue.GetImageStructValue());
    }
  }
  else if (aValue.GetUnit() == eCSSUnit_Image) {
    // If we already have a request, see if this document needs to clone it.
    imgIRequest* request = aValue.GetImageValue(nullptr);

    if (request) {
      ImageValue* imageValue = aValue.GetImageStructValue();
      aDocument->StyleImageLoader()->MaybeRegisterCSSImage(imageValue);
      if (aForTokenStream && aContext) {
        CSSVariableImageTable::Add(aContext, aProperty, imageValue);
      }
    }
  }
  else if (aValue.EqualsFunction(eCSSKeyword__moz_image_rect)) {
    nsCSSValue::Array* arguments = aValue.GetArrayValue();
    MOZ_ASSERT(arguments->Count() == 6, "unexpected num of arguments");

    const nsCSSValue& image = arguments->Item(1);
    TryToStartImageLoadOnValue(image, aDocument, aContext, aProperty,
                               aForTokenStream);
  }
}