From 3b86d2992fa84639524c773df04d1782abbd9b4d Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Thu, 20 Oct 2016 08:36:26 +0800 Subject: [PATCH] Bug 1288302 - Part 6: Add FFI function to set nsStyleImageRequest values. r=xidorn MozReview-Commit-ID: 448vAeDiKX7 --- layout/style/ServoBindings.cpp | 29 +++++++++++++++++++++++++++++ layout/style/ServoBindings.h | 16 +++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/layout/style/ServoBindings.cpp b/layout/style/ServoBindings.cpp index 34c86375d506..ca421b19331a 100644 --- a/layout/style/ServoBindings.cpp +++ b/layout/style/ServoBindings.cpp @@ -734,6 +734,35 @@ Gecko_SetGradientImageValue(nsStyleImage* aImage, nsStyleGradient* aGradient) aImage->SetGradientData(aGradient); } +void +Gecko_SetUrlImageValue(nsStyleImage* aImage, + const uint8_t* aURLString, uint32_t aURLStringLength, + ThreadSafeURIHolder* aBaseURI, + ThreadSafeURIHolder* aReferrer, + ThreadSafePrincipalHolder* aPrincipal) +{ + MOZ_ASSERT(aImage); + MOZ_ASSERT(aURLString); + MOZ_ASSERT(aBaseURI); + MOZ_ASSERT(aReferrer); + MOZ_ASSERT(aPrincipal); + + nsString url; + nsDependentCSubstring urlString(reinterpret_cast(aURLString), + aURLStringLength); + AppendUTF8toUTF16(urlString, url); + RefPtr urlBuffer = nsCSSValue::BufferFromString(url); + + RefPtr req = + new nsStyleImageRequest(nsStyleImageRequest::Mode::Track | + nsStyleImageRequest::Mode::Lock, + urlBuffer, + do_AddRef(aBaseURI), + do_AddRef(aReferrer), + do_AddRef(aPrincipal)); + aImage->SetImageRequest(req.forget()); +} + void Gecko_CopyImageValueFrom(nsStyleImage* aImage, const nsStyleImage* aOther) { diff --git a/layout/style/ServoBindings.h b/layout/style/ServoBindings.h index 71079b72a15e..b76518b6260b 100644 --- a/layout/style/ServoBindings.h +++ b/layout/style/ServoBindings.h @@ -156,6 +156,10 @@ DECL_BORROWED_MUT_REF_TYPE_FOR(StyleChildrenIterator) extern "C" { +// Object refcounting. +NS_DECL_HOLDER_FFI_REFCOUNTING(nsIPrincipal, Principal) +NS_DECL_HOLDER_FFI_REFCOUNTING(nsIURI, URI) + // DOM Traversal. uint32_t Gecko_ChildrenCount(RawGeckoNodeBorrowed node); bool Gecko_NodeIsElement(RawGeckoNodeBorrowed node); @@ -246,9 +250,15 @@ void Gecko_SetListStyleType(nsStyleList* style_struct, uint32_t type); void Gecko_CopyListStyleTypeFrom(nsStyleList* dst, const nsStyleList* src); // background-image style. -// TODO: support url() values (and maybe element() too?). +// TODO: support element() and -moz-image() void Gecko_SetNullImageValue(nsStyleImage* image); void Gecko_SetGradientImageValue(nsStyleImage* image, nsStyleGradient* gradient); +void Gecko_SetUrlImageValue(nsStyleImage* image, + const uint8_t* url_bytes, + uint32_t url_length, + ThreadSafeURIHolder* base_uri, + ThreadSafeURIHolder* referrer, + ThreadSafePrincipalHolder* principal); void Gecko_CopyImageValueFrom(nsStyleImage* image, const nsStyleImage* other); nsStyleGradient* Gecko_CreateGradient(uint8_t shape, @@ -257,10 +267,6 @@ nsStyleGradient* Gecko_CreateGradient(uint8_t shape, bool legacy_syntax, uint32_t stops); -// Object refcounting. -NS_DECL_HOLDER_FFI_REFCOUNTING(nsIPrincipal, Principal) -NS_DECL_HOLDER_FFI_REFCOUNTING(nsIURI, URI) - // Display style. void Gecko_SetMozBinding(nsStyleDisplay* style_struct, const uint8_t* string_bytes, uint32_t string_length,