Bug 1351957 - Create URLExtraData for holding base uri, referrer, and principal. r=heycam

MozReview-Commit-ID: 1wqTb3kvvWh

--HG--
extra : rebase_source : cae3dba21c916ab0f52056bd9db215249b650cd3
This commit is contained in:
Xidorn Quan 2017-03-30 18:54:48 +11:00
Родитель 5ed46cc5d0
Коммит e3e4554871
19 изменённых файлов: 158 добавлений и 193 удалений

Просмотреть файл

@ -1022,13 +1022,14 @@ MakePropertyValuePair(nsCSSPropertyID aProperty, const nsAString& aStringValue,
nsCString baseString;
// FIXME this is using the wrong base uri (bug 1343919)
GeckoParserExtraData data(aDocument->GetDocumentURI(),
aDocument->GetDocumentURI(),
aDocument->NodePrincipal());
RefPtr<css::URLExtraData> data =
new css::URLExtraData(aDocument->GetDocumentURI(),
aDocument->GetDocumentURI(),
aDocument->NodePrincipal());
aDocument->GetDocumentURI()->GetSpec(baseString);
RefPtr<RawServoDeclarationBlock> servoDeclarationBlock =
Servo_ParseProperty(&name, &value, &baseString, &data).Consume();
Servo_ParseProperty(&name, &value, &baseString, data).Consume();
if (servoDeclarationBlock) {
result.mServoDeclarationBlock = servoDeclarationBlock.forget();

Просмотреть файл

@ -118,11 +118,12 @@ TimingParams::ParseEasing(const nsAString& aEasing,
nsTimingFunction timingFunction;
nsCString baseString;
// FIXME this is using the wrong base uri (bug 1343919)
GeckoParserExtraData data(aDocument->GetDocumentURI(),
aDocument->GetDocumentURI(),
aDocument->NodePrincipal());
RefPtr<css::URLExtraData> data =
new css::URLExtraData(aDocument->GetDocumentURI(),
aDocument->GetDocumentURI(),
aDocument->NodePrincipal());
aDocument->GetDocumentURI()->GetSpec(baseString);
if (!Servo_ParseEasing(&aEasing, &baseString, &data, &timingFunction)) {
if (!Servo_ParseEasing(&aEasing, &baseString, data, &timingFunction)) {
aRv.ThrowTypeError<dom::MSG_INVALID_EASING_ERROR>(aEasing);
return Nothing();
}

Просмотреть файл

@ -550,7 +550,7 @@ Element::WrapObject(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
if (bindingURL) {
nsCOMPtr<nsIURI> uri = bindingURL->GetURI();
nsCOMPtr<nsIPrincipal> principal = bindingURL->mOriginPrincipal.get();
nsCOMPtr<nsIPrincipal> principal = bindingURL->mExtraData->GetPrincipal();
// We have a binding that must be installed.
bool dummy;

Просмотреть файл

@ -1687,8 +1687,8 @@ nsAttrValue::LoadImage(nsIDocument* aDocument)
MiscContainer* cont = GetMiscContainer();
mozilla::css::URLValue* url = cont->mValue.mURL;
mozilla::css::ImageValue* image =
new css::ImageValue(url->GetURI(), url->mString, url->mBaseURI,
url->mReferrer, url->mOriginPrincipal, aDocument);
new css::ImageValue(url->GetURI(), url->mString,
do_AddRef(url->mExtraData), aDocument);
NS_ADDREF(image);
cont->mValue.mImage = image;
@ -1725,7 +1725,8 @@ nsAttrValue::ParseStyleAttribute(const nsAString& aString,
RefPtr<DeclarationBlock> decl;
if (ownerDoc->GetStyleBackendType() == StyleBackendType::Servo) {
GeckoParserExtraData data(baseURI, docURI, aElement->NodePrincipal());
RefPtr<css::URLExtraData> data =
new css::URLExtraData(baseURI, docURI, aElement->NodePrincipal());
decl = ServoDeclarationBlock::FromCssText(aString, data);
} else {
css::Loader* cssLoader = ownerDoc->CSSLoader();

Просмотреть файл

@ -1235,11 +1235,12 @@ MappedAttrParser::ParseMappedAttrValue(nsIAtom* aMappedAttrName,
NS_ConvertUTF16toUTF8 value(aMappedAttrValue);
// FIXME (bug 1343964): Figure out a better solution for sending the base uri to servo
nsCString baseString;
GeckoParserExtraData data(mBaseURI, mDocURI, mElement->NodePrincipal());
RefPtr<css::URLExtraData> data =
new css::URLExtraData(mBaseURI, mDocURI, mElement->NodePrincipal());
mBaseURI->GetSpec(baseString);
// FIXME (bug 1342559): Set SVG parsing mode for lengths
changed = Servo_DeclarationBlock_SetPropertyById(mDecl->AsServo()->Raw(), propertyID,
&value, false, &baseString, &data);
&value, false, &baseString, data);
}
if (changed) {

Просмотреть файл

@ -2475,7 +2475,7 @@ nsCSSFrameConstructor::ConstructDocElementFrame(Element* aDocEle
RefPtr<nsXBLBinding> binding;
rv = xblService->LoadBindings(aDocElement, display->mBinding->GetURI(),
display->mBinding->mOriginPrincipal,
display->mBinding->mExtraData->GetPrincipal(),
getter_AddRefs(binding), &resolveStyle);
if (NS_FAILED(rv) && rv != NS_ERROR_XBL_BLOCKED)
return nullptr; // Binding will load asynchronously.
@ -5779,10 +5779,10 @@ nsCSSFrameConstructor::AddFrameConstructionItemsInternal(nsFrameConstructorState
nsAutoPtr<PendingBinding> newPendingBinding(new PendingBinding());
nsresult rv = xblService->LoadBindings(aContent, display->mBinding->GetURI(),
display->mBinding->mOriginPrincipal,
getter_AddRefs(newPendingBinding->mBinding),
&resolveStyle);
nsresult rv = xblService->LoadBindings(
aContent, display->mBinding->GetURI(),
display->mBinding->mExtraData->GetPrincipal(),
getter_AddRefs(newPendingBinding->mBinding), &resolveStyle);
if (NS_FAILED(rv) && rv != NS_ERROR_XBL_BLOCKED)
return;

Просмотреть файл

@ -1098,12 +1098,13 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsAString& aFamilyName,
face->mURI = nullptr;
face->mFormatFlags = 0;
break;
case eCSSUnit_URL:
case eCSSUnit_URL: {
face->mSourceType = gfxFontFaceSrc::eSourceType_URL;
face->mURI = val.GetURLValue();
face->mReferrer = val.GetURLStructValue()->mReferrer;
URLValue* url = val.GetURLStructValue();
face->mReferrer = url->mExtraData->GetReferrer();
face->mReferrerPolicy = mDocument->GetReferrerPolicy();
face->mOriginPrincipal = val.GetURLStructValue()->mOriginPrincipal;
face->mOriginPrincipal = url->mExtraData->GetPrincipal();
NS_ASSERTION(face->mOriginPrincipal, "null origin principal in @font-face rule");
// agent and user stylesheets are treated slightly differently,
@ -1147,6 +1148,7 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsAString& aFamilyName,
continue;
}
break;
}
default:
NS_ASSERTION(unit == eCSSUnit_Local_Font || unit == eCSSUnit_URL,
"strange unit type in font-face src array");

Просмотреть файл

@ -30,9 +30,7 @@ SERVO_BINDING_FUNC(Servo_StyleSheet_FromUTF8Bytes, RawServoStyleSheetStrong,
const nsACString* data,
mozilla::css::SheetParsingMode parsing_mode,
const nsACString* base_url,
ThreadSafeURIHolder* base,
ThreadSafeURIHolder* referrer,
ThreadSafePrincipalHolder* principal)
RawGeckoURLExtraData* extra_data)
SERVO_BINDING_FUNC(Servo_ImportRule_GetSheet,
RawServoStyleSheetStrong,
const RawServoImportRuleBorrowed import_rule)
@ -42,9 +40,7 @@ SERVO_BINDING_FUNC(Servo_StyleSheet_ClearAndUpdate,
mozilla::css::Loader* loader,
mozilla::ServoStyleSheet* gecko_stylesheet,
const nsACString* data,
ThreadSafeURIHolder* base,
ThreadSafeURIHolder* referrer,
ThreadSafePrincipalHolder* principal)
RawGeckoURLExtraData* extra_data)
SERVO_BINDING_FUNC(Servo_StyleSheet_HasRules, bool,
RawServoStyleSheetBorrowed sheet)
SERVO_BINDING_FUNC(Servo_StyleSheet_GetRules, ServoCssRulesStrong,
@ -122,11 +118,11 @@ SERVO_BINDING_FUNC(Servo_ParseProperty,
RawServoDeclarationBlockStrong,
const nsACString* property, const nsACString* value,
const nsACString* base,
const GeckoParserExtraData* data)
RawGeckoURLExtraData* data)
SERVO_BINDING_FUNC(Servo_ParseEasing, bool,
const nsAString* easing,
const nsACString* base,
const GeckoParserExtraData* data,
RawGeckoURLExtraData* data,
nsTimingFunctionBorrowedMut output)
SERVO_BINDING_FUNC(Servo_GetComputedKeyframeValues, void,
RawGeckoKeyframeListBorrowed keyframes,
@ -162,7 +158,7 @@ SERVO_BINDING_FUNC(Servo_AnimationValue_DeepEqual, bool,
SERVO_BINDING_FUNC(Servo_ParseStyleAttribute, RawServoDeclarationBlockStrong,
const nsACString* data,
const nsACString* base,
const GeckoParserExtraData* extraData)
RawGeckoURLExtraData* extra_data)
SERVO_BINDING_FUNC(Servo_DeclarationBlock_CreateEmpty,
RawServoDeclarationBlockStrong)
SERVO_BINDING_FUNC(Servo_DeclarationBlock_Clone, RawServoDeclarationBlockStrong,
@ -195,13 +191,13 @@ SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetProperty, bool,
const nsACString* property,
const nsACString* value, bool is_important,
const nsACString* base,
const GeckoParserExtraData* data)
RawGeckoURLExtraData* data)
SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetPropertyById, bool,
RawServoDeclarationBlockBorrowed declarations,
nsCSSPropertyID property,
const nsACString* value, bool is_important,
const nsACString* base,
const GeckoParserExtraData* data)
RawGeckoURLExtraData* data)
SERVO_BINDING_FUNC(Servo_DeclarationBlock_RemoveProperty, void,
RawServoDeclarationBlockBorrowed declarations,
const nsACString* property)

Просмотреть файл

@ -22,6 +22,9 @@ struct RawServoStyleSet;
namespace mozilla {
class ServoElementSnapshot;
struct StyleAnimation;
namespace css {
struct URLExtraData;
} // namespace css
namespace dom {
class Element;
class StyleChildrenIterator;
@ -45,6 +48,7 @@ typedef nsINode RawGeckoNode;
typedef mozilla::dom::Element RawGeckoElement;
typedef nsIDocument RawGeckoDocument;
typedef nsPresContext RawGeckoPresContext;
typedef mozilla::css::URLExtraData RawGeckoURLExtraData;
typedef nsTArray<mozilla::Keyframe> RawGeckoKeyframeList;
typedef nsTArray<mozilla::ComputedKeyframeValues> RawGeckoComputedKeyframeValuesList;
typedef nsTArray<mozilla::PropertyStyleAnimationValuePair> RawGeckoAnimationValueList;

Просмотреть файл

@ -872,9 +872,6 @@ Gecko_CopyListStyleTypeFrom(nsStyleList* dst, const nsStyleList* src)
dst->SetCounterStyle(src->GetCounterStyle());
}
NS_IMPL_HOLDER_FFI_REFCOUNTING(nsIPrincipal, Principal)
NS_IMPL_HOLDER_FFI_REFCOUNTING(nsIURI, URI)
already_AddRefed<css::URLValue>
ServoBundledURI::IntoCssUrl()
{
@ -882,9 +879,8 @@ ServoBundledURI::IntoCssUrl()
return nullptr;
}
MOZ_ASSERT(mBaseURI);
MOZ_ASSERT(mReferrer);
MOZ_ASSERT(mPrincipal);
MOZ_ASSERT(mExtraData->GetReferrer());
MOZ_ASSERT(mExtraData->GetPrincipal());
nsString url;
nsDependentCSubstring urlString(reinterpret_cast<const char*>(mURLString),
@ -892,22 +888,11 @@ ServoBundledURI::IntoCssUrl()
AppendUTF8toUTF16(urlString, url);
RefPtr<nsStringBuffer> urlBuffer = nsCSSValue::BufferFromString(url);
RefPtr<css::URLValue> urlValue = new css::URLValue(urlBuffer,
do_AddRef(mBaseURI),
do_AddRef(mReferrer),
do_AddRef(mPrincipal));
RefPtr<css::URLValue> urlValue =
new css::URLValue(urlBuffer, do_AddRef(mExtraData));
return urlValue.forget();
}
GeckoParserExtraData::GeckoParserExtraData(nsIURI* aBaseURI,
nsIURI* aReferrer,
nsIPrincipal* aPrincipal)
: mBaseURI(new ThreadSafeURIHolder(aBaseURI)),
mReferrer(new ThreadSafeURIHolder(aReferrer)),
mPrincipal(new ThreadSafePrincipalHolder(aPrincipal))
{
}
void
Gecko_SetNullImageValue(nsStyleImage* aImage)
{
@ -927,9 +912,8 @@ CreateStyleImageRequest(nsStyleImageRequest::Mode aModeFlags,
ServoBundledURI aURI)
{
MOZ_ASSERT(aURI.mURLString);
MOZ_ASSERT(aURI.mBaseURI);
MOZ_ASSERT(aURI.mReferrer);
MOZ_ASSERT(aURI.mPrincipal);
MOZ_ASSERT(aURI.mExtraData->GetReferrer());
MOZ_ASSERT(aURI.mExtraData->GetPrincipal());
nsString url;
nsDependentCSubstring urlString(reinterpret_cast<const char*>(aURI.mURLString),
@ -938,8 +922,7 @@ CreateStyleImageRequest(nsStyleImageRequest::Mode aModeFlags,
RefPtr<nsStringBuffer> urlBuffer = nsCSSValue::BufferFromString(url);
RefPtr<nsStyleImageRequest> req =
new nsStyleImageRequest(aModeFlags, urlBuffer, do_AddRef(aURI.mBaseURI),
do_AddRef(aURI.mReferrer), do_AddRef(aURI.mPrincipal));
new nsStyleImageRequest(aModeFlags, urlBuffer, do_AddRef(aURI.mExtraData));
return req.forget();
}
@ -1320,6 +1303,8 @@ Gecko_NewURLValue(ServoBundledURI aURI)
NS_IMPL_THREADSAFE_FFI_REFCOUNTING(css::URLValue, CSSURLValue);
NS_IMPL_THREADSAFE_FFI_REFCOUNTING(css::URLExtraData, URLExtraData);
NS_IMPL_THREADSAFE_FFI_REFCOUNTING(nsStyleCoord::Calc, Calc);
nsCSSShadowArray*
@ -1552,7 +1537,7 @@ void
Gecko_LoadStyleSheet(css::Loader* aLoader,
ServoStyleSheet* aParent,
RawServoImportRuleBorrowed aImportRule,
nsIURI* aBaseURI,
RawGeckoURLExtraData* aBaseURLData,
const uint8_t* aURLString,
uint32_t aURLStringLength,
const uint8_t* aMediaString,
@ -1562,7 +1547,7 @@ Gecko_LoadStyleSheet(css::Loader* aLoader,
MOZ_ASSERT(aLoader, "Should've catched this before");
MOZ_ASSERT(aParent, "Only used for @import, so parent should exist!");
MOZ_ASSERT(aURLString, "Invalid URLs shouldn't be loaded!");
MOZ_ASSERT(aBaseURI, "Need a base URI");
MOZ_ASSERT(aBaseURLData, "Need base URL data");
RefPtr<nsMediaList> media = new nsMediaList();
if (aMediaStringLength) {
MOZ_ASSERT(aMediaString);
@ -1578,7 +1563,8 @@ Gecko_LoadStyleSheet(css::Loader* aLoader,
nsDependentCSubstring urlSpec(reinterpret_cast<const char*>(aURLString),
aURLStringLength);
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), urlSpec, nullptr, aBaseURI);
nsresult rv = NS_NewURI(getter_AddRefs(uri), urlSpec, nullptr,
aBaseURLData->BaseURI());
if (NS_FAILED(rv)) {
// Servo and Gecko have different ideas of what a valid URL is, so we might

Просмотреть файл

@ -64,16 +64,6 @@ struct nsStyleDisplay;
void Gecko_Release##name_##ArbitraryThread(class_* aPtr) \
{ NS_RELEASE(aPtr); }
#define NS_DECL_HOLDER_FFI_REFCOUNTING(class_, name_) \
typedef nsMainThreadPtrHolder<class_> ThreadSafe##name_##Holder; \
void Gecko_AddRef##name_##ArbitraryThread(ThreadSafe##name_##Holder* aPtr); \
void Gecko_Release##name_##ArbitraryThread(ThreadSafe##name_##Holder* aPtr);
#define NS_IMPL_HOLDER_FFI_REFCOUNTING(class_, name_) \
void Gecko_AddRef##name_##ArbitraryThread(ThreadSafe##name_##Holder* aPtr) \
{ NS_ADDREF(aPtr); } \
void Gecko_Release##name_##ArbitraryThread(ThreadSafe##name_##Holder* aPtr) \
{ NS_RELEASE(aPtr); } \
#define NS_DECL_FFI_REFCOUNTING(class_, name_) \
void Gecko_##name_##_AddRef(class_* aPtr); \
void Gecko_##name_##_Release(class_* aPtr);
@ -81,7 +71,6 @@ struct nsStyleDisplay;
void Gecko_##name_##_AddRef(class_* aPtr) { NS_ADDREF(aPtr); } \
void Gecko_##name_##_Release(class_* aPtr) { NS_RELEASE(aPtr); }
#define DEFINE_ARRAY_TYPE_FOR(type_) \
struct nsTArrayBorrowed_##type_ { \
nsTArray<type_>* mArray; \
@ -93,30 +82,13 @@ DEFINE_ARRAY_TYPE_FOR(uintptr_t);
extern "C" {
// Object refcounting.
NS_DECL_HOLDER_FFI_REFCOUNTING(nsIPrincipal, Principal)
NS_DECL_HOLDER_FFI_REFCOUNTING(nsIURI, URI)
class ServoBundledURI
{
public:
already_AddRefed<mozilla::css::URLValue> IntoCssUrl();
const uint8_t* mURLString;
uint32_t mURLStringLength;
ThreadSafeURIHolder* mBaseURI;
ThreadSafeURIHolder* mReferrer;
ThreadSafePrincipalHolder* mPrincipal;
};
class GeckoParserExtraData
{
public:
GeckoParserExtraData(nsIURI* aBaseURI,
nsIURI* aReferrer,
nsIPrincipal* aPrincipal);
RefPtr<ThreadSafeURIHolder> mBaseURI;
RefPtr<ThreadSafeURIHolder> mReferrer;
RefPtr<ThreadSafePrincipalHolder> mPrincipal;
mozilla::css::URLExtraData* mExtraData;
};
// DOM Traversal.
@ -140,7 +112,7 @@ RawGeckoElementBorrowedOrNull Gecko_GetDocumentElement(RawGeckoDocumentBorrowed
void Gecko_LoadStyleSheet(mozilla::css::Loader* loader,
mozilla::ServoStyleSheet* parent,
RawServoImportRuleBorrowed import_rule,
nsIURI* base_uri,
RawGeckoURLExtraData* base_url_data,
const uint8_t* url_bytes,
uint32_t url_length,
const uint8_t* media_bytes,
@ -346,6 +318,7 @@ void Gecko_nsStyleSVG_CopyDashArray(nsStyleSVG* dst, const nsStyleSVG* src);
mozilla::css::URLValue* Gecko_NewURLValue(ServoBundledURI uri);
NS_DECL_THREADSAFE_FFI_REFCOUNTING(mozilla::css::URLValue, CSSURLValue);
NS_DECL_THREADSAFE_FFI_REFCOUNTING(RawGeckoURLExtraData, URLExtraData);
void Gecko_FillAllBackgroundLists(nsStyleImageLayers* layers, uint32_t max_len);
void Gecko_FillAllMaskLists(nsStyleImageLayers* layers, uint32_t max_len);

Просмотреть файл

@ -13,14 +13,14 @@ namespace mozilla {
/* static */ already_AddRefed<ServoDeclarationBlock>
ServoDeclarationBlock::FromCssText(const nsAString& aCssText,
const GeckoParserExtraData& aExtraData)
css::URLExtraData* aExtraData)
{
NS_ConvertUTF16toUTF8 value(aCssText);
nsCString baseString;
// FIXME (bug 1343964): Figure out a better solution for sending the base uri to servo
aExtraData.mBaseURI->get()->GetSpec(baseString);
aExtraData->BaseURI()->GetSpec(baseString);
RefPtr<RawServoDeclarationBlock>
raw = Servo_ParseStyleAttribute(&value, &baseString, &aExtraData).Consume();
raw = Servo_ParseStyleAttribute(&value, &baseString, aExtraData).Consume();
RefPtr<ServoDeclarationBlock> decl = new ServoDeclarationBlock(raw.forget());
return decl.forget();
}

Просмотреть файл

@ -28,8 +28,7 @@ public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServoDeclarationBlock)
static already_AddRefed<ServoDeclarationBlock>
FromCssText(const nsAString& aCssText,
const GeckoParserExtraData& aExtraData);
FromCssText(const nsAString& aCssText, css::URLExtraData* aExtraData);
RawServoDeclarationBlock* Raw() const { return mRaw; }
RawServoDeclarationBlock* const* RefRaw() const {

Просмотреть файл

@ -87,10 +87,8 @@ ServoStyleSheet::ParseSheet(css::Loader* aLoader,
nsIPrincipal* aSheetPrincipal,
uint32_t aLineNumber)
{
RefPtr<ThreadSafeURIHolder> base = new ThreadSafeURIHolder(aBaseURI);
RefPtr<ThreadSafeURIHolder> referrer = new ThreadSafeURIHolder(aSheetURI);
RefPtr<ThreadSafePrincipalHolder> principal =
new ThreadSafePrincipalHolder(aSheetPrincipal);
RefPtr<css::URLExtraData> extraData =
new css::URLExtraData(aBaseURI, aSheetURI, aSheetPrincipal);
nsCString baseString;
nsresult rv = aBaseURI->GetSpec(baseString);
@ -100,11 +98,10 @@ ServoStyleSheet::ParseSheet(css::Loader* aLoader,
if (!Inner()->mSheet) {
Inner()->mSheet =
Servo_StyleSheet_FromUTF8Bytes(aLoader, this, &input, mParsingMode,
&baseString, base, referrer,
principal).Consume();
&baseString, extraData).Consume();
} else {
Servo_StyleSheet_ClearAndUpdate(Inner()->mSheet, aLoader, this, &input, base,
referrer, principal);
Servo_StyleSheet_ClearAndUpdate(Inner()->mSheet, aLoader,
this, &input, extraData);
}
return NS_OK;

Просмотреть файл

@ -901,9 +901,7 @@ void nsCSSValue::StartImageLoad(nsIDocument* aDocument) const
mozilla::css::ImageValue* image =
new mozilla::css::ImageValue(mValue.mURL->GetURI(),
mValue.mURL->mString,
mValue.mURL->mBaseURI,
mValue.mURL->mReferrer,
mValue.mURL->mOriginPrincipal,
do_AddRef(mValue.mURL->mExtraData),
aDocument);
nsCSSValue* writable = const_cast<nsCSSValue*>(this);
@ -2785,40 +2783,39 @@ nsCSSValue::Array::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) cons
return n;
}
css::URLExtraData::~URLExtraData()
{
if (!NS_IsMainThread()) {
NS_ReleaseOnMainThread(mBaseURI.forget());
NS_ReleaseOnMainThread(mReferrer.forget());
NS_ReleaseOnMainThread(mPrincipal.forget());
}
}
css::URLValueData::URLValueData(already_AddRefed<PtrHolder<nsIURI>> aURI,
nsStringBuffer* aString,
already_AddRefed<PtrHolder<nsIURI>> aBaseURI,
already_AddRefed<PtrHolder<nsIURI>> aReferrer,
already_AddRefed<PtrHolder<nsIPrincipal>>
aOriginPrincipal)
already_AddRefed<URLExtraData> aExtraData)
: mURI(Move(aURI))
, mBaseURI(Move(aBaseURI))
, mString(aString)
, mReferrer(Move(aReferrer))
, mOriginPrincipal(Move(aOriginPrincipal))
, mExtraData(Move(aExtraData))
, mURIResolved(true)
, mIsLocalRef(IsLocalRefURL(aString))
{
MOZ_ASSERT(mString);
MOZ_ASSERT(mBaseURI);
MOZ_ASSERT(mOriginPrincipal);
MOZ_ASSERT(mExtraData);
MOZ_ASSERT(mExtraData->GetPrincipal());
}
css::URLValueData::URLValueData(nsStringBuffer* aString,
already_AddRefed<PtrHolder<nsIURI>> aBaseURI,
already_AddRefed<PtrHolder<nsIURI>> aReferrer,
already_AddRefed<PtrHolder<nsIPrincipal>>
aOriginPrincipal)
: mBaseURI(Move(aBaseURI))
, mString(aString)
, mReferrer(Move(aReferrer))
, mOriginPrincipal(Move(aOriginPrincipal))
already_AddRefed<URLExtraData> aExtraData)
: mString(aString)
, mExtraData(Move(aExtraData))
, mURIResolved(false)
, mIsLocalRef(IsLocalRefURL(aString))
{
MOZ_ASSERT(aString);
MOZ_ASSERT(mBaseURI);
MOZ_ASSERT(mOriginPrincipal);
MOZ_ASSERT(mExtraData);
MOZ_ASSERT(mExtraData->GetPrincipal());
}
bool
@ -2828,26 +2825,26 @@ css::URLValueData::Equals(const URLValueData& aOther) const
bool eq;
// Cast away const so we can call nsIPrincipal::Equals.
auto& self = *const_cast<URLValueData*>(this);
auto& other = const_cast<URLValueData&>(aOther);
const URLExtraData* self = mExtraData;
const URLExtraData* other = aOther.mExtraData;
return NS_strcmp(nsCSSValue::GetBufferValue(mString),
nsCSSValue::GetBufferValue(aOther.mString)) == 0 &&
(GetURI() == aOther.GetURI() || // handles null == null
(mURI && aOther.mURI &&
NS_SUCCEEDED(mURI->Equals(aOther.mURI, &eq)) &&
eq)) &&
(mBaseURI == aOther.mBaseURI ||
(NS_SUCCEEDED(self.mBaseURI.get()->Equals(other.mBaseURI.get(), &eq)) &&
(self->BaseURI() == other->BaseURI() ||
(NS_SUCCEEDED(self->BaseURI()->Equals(other->BaseURI(), &eq)) &&
eq)) &&
(mOriginPrincipal == aOther.mOriginPrincipal ||
self.mOriginPrincipal.get()->Equals(other.mOriginPrincipal.get())) &&
(self->GetPrincipal() == other->GetPrincipal() ||
self->GetPrincipal()->Equals(other->GetPrincipal())) &&
mIsLocalRef == aOther.mIsLocalRef;
}
bool
css::URLValueData::DefinitelyEqualURIs(const URLValueData& aOther) const
{
return mBaseURI == aOther.mBaseURI &&
return mExtraData->BaseURI() == aOther.mExtraData->BaseURI() &&
(mString == aOther.mString ||
NS_strcmp(nsCSSValue::GetBufferValue(mString),
nsCSSValue::GetBufferValue(aOther.mString)) == 0);
@ -2857,7 +2854,7 @@ bool
css::URLValueData::DefinitelyEqualURIsAndPrincipal(
const URLValueData& aOther) const
{
return mOriginPrincipal == aOther.mOriginPrincipal &&
return mExtraData->GetPrincipal() == aOther.mExtraData->GetPrincipal() &&
DefinitelyEqualURIs(aOther);
}
@ -2871,7 +2868,7 @@ css::URLValueData::GetURI() const
nsCOMPtr<nsIURI> newURI;
NS_NewURI(getter_AddRefs(newURI),
NS_ConvertUTF16toUTF8(nsCSSValue::GetBufferValue(mString)),
nullptr, const_cast<nsIURI*>(mBaseURI.get()));
nullptr, mExtraData->BaseURI());
mURI = new PtrHolder<nsIURI>(newURI.forget());
mURIResolved = true;
}
@ -2972,17 +2969,14 @@ css::URLValueData::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) cons
// Measurement of the following members may be added later if DMD finds it
// is worthwhile:
// - mURI
// - mReferrer
// - mOriginPrincipal
// - mExtraData
return n;
}
URLValue::URLValue(nsStringBuffer* aString, nsIURI* aBaseURI, nsIURI* aReferrer,
nsIPrincipal* aOriginPrincipal)
: URLValueData(aString,
do_AddRef(new PtrHolder<nsIURI>(aBaseURI)),
do_AddRef(new PtrHolder<nsIURI>(aReferrer)),
do_AddRef(new PtrHolder<nsIPrincipal>(aOriginPrincipal)))
: URLValueData(aString, do_AddRef(new URLExtraData(aBaseURI, aReferrer,
aOriginPrincipal)))
{
MOZ_ASSERT(NS_IsMainThread());
}
@ -2991,9 +2985,8 @@ URLValue::URLValue(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aBaseURI,
nsIURI* aReferrer, nsIPrincipal* aOriginPrincipal)
: URLValueData(do_AddRef(new PtrHolder<nsIURI>(aURI)),
aString,
do_AddRef(new PtrHolder<nsIURI>(aBaseURI)),
do_AddRef(new PtrHolder<nsIURI>(aReferrer)),
do_AddRef(new PtrHolder<nsIPrincipal>(aOriginPrincipal)))
do_AddRef(new URLExtraData(aBaseURI, aReferrer,
aOriginPrincipal)))
{
MOZ_ASSERT(NS_IsMainThread());
}
@ -3011,25 +3004,17 @@ css::URLValue::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
}
css::ImageValue::ImageValue(nsIURI* aURI, nsStringBuffer* aString,
nsIURI* aBaseURI, nsIURI* aReferrer,
nsIPrincipal* aOriginPrincipal,
already_AddRefed<URLExtraData> aExtraData,
nsIDocument* aDocument)
: URLValueData(do_AddRef(new PtrHolder<nsIURI>(aURI)),
aString,
do_AddRef(new PtrHolder<nsIURI>(aBaseURI, false)),
do_AddRef(new PtrHolder<nsIURI>(aReferrer)),
do_AddRef(new PtrHolder<nsIPrincipal>(aOriginPrincipal)))
aString, Move(aExtraData))
{
Initialize(aDocument);
}
css::ImageValue::ImageValue(
nsStringBuffer* aString,
already_AddRefed<PtrHolder<nsIURI>> aBaseURI,
already_AddRefed<PtrHolder<nsIURI>> aReferrer,
already_AddRefed<PtrHolder<nsIPrincipal>> aOriginPrincipal)
: URLValueData(aString, Move(aBaseURI), Move(aReferrer),
Move(aOriginPrincipal))
css::ImageValue::ImageValue(nsStringBuffer* aString,
already_AddRefed<URLExtraData> aExtraData)
: URLValueData(aString, Move(aExtraData))
{
}
@ -3047,8 +3032,9 @@ css::ImageValue::Initialize(nsIDocument* aDocument)
loadingDoc = aDocument;
}
loadingDoc->StyleImageLoader()->LoadImage(GetURI(), mOriginPrincipal,
mReferrer, this);
loadingDoc->StyleImageLoader()->LoadImage(GetURI(),
mExtraData->GetPrincipal(),
mExtraData->GetReferrer(), this);
if (loadingDoc != aDocument) {
aDocument->StyleImageLoader()->MaybeRegisterCSSImage(this);

Просмотреть файл

@ -93,6 +93,37 @@ class CSSStyleSheet;
namespace mozilla {
namespace css {
struct URLExtraData
{
URLExtraData(already_AddRefed<nsIURI> aBaseURI,
already_AddRefed<nsIURI> aReferrer,
already_AddRefed<nsIPrincipal> aPrincipal)
: mBaseURI(Move(aBaseURI))
, mReferrer(Move(aReferrer))
, mPrincipal(Move(aPrincipal))
{
MOZ_ASSERT(mBaseURI);
}
URLExtraData(nsIURI* aBaseURI, nsIURI* aReferrer, nsIPrincipal* aPrincipal)
: URLExtraData(do_AddRef(aBaseURI),
do_AddRef(aReferrer),
do_AddRef(aPrincipal)) {}
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(URLExtraData)
nsIURI* BaseURI() const { return mBaseURI; }
nsIURI* GetReferrer() const { return mReferrer; }
nsIPrincipal* GetPrincipal() const { return mPrincipal; }
private:
~URLExtraData();
RefPtr<nsIURI> mBaseURI;
RefPtr<nsIURI> mReferrer;
RefPtr<nsIPrincipal> mPrincipal;
};
struct URLValueData
{
protected:
@ -101,19 +132,15 @@ protected:
// over.
// For both constructors aString must not be null.
// For both constructors aOriginPrincipal must not be null.
// For both constructors principal of aExtraData must not be null.
// Construct with a base URI; this will create the actual URI lazily from
// aString and aBaseURI.
// aString and aExtraData.
URLValueData(nsStringBuffer* aString,
already_AddRefed<PtrHolder<nsIURI>> aBaseURI,
already_AddRefed<PtrHolder<nsIURI>> aReferrer,
already_AddRefed<PtrHolder<nsIPrincipal>> aOriginPricinpal);
already_AddRefed<URLExtraData> aExtraData);
// Construct with the actual URI.
URLValueData(already_AddRefed<PtrHolder<nsIURI>> aURI,
nsStringBuffer* aString,
already_AddRefed<PtrHolder<nsIURI>> aBaseURI,
already_AddRefed<PtrHolder<nsIURI>> aReferrer,
already_AddRefed<PtrHolder<nsIPrincipal>> aOriginPrincipal);
already_AddRefed<URLExtraData> aExtraData);
public:
// Returns true iff all fields of the two URLValueData objects are equal.
@ -159,10 +186,8 @@ private:
// invalid, even once resolved.
mutable PtrHandle<nsIURI> mURI;
public:
PtrHandle<nsIURI> mBaseURI;
RefPtr<nsStringBuffer> mString;
PtrHandle<nsIURI> mReferrer;
PtrHandle<nsIPrincipal> mOriginPrincipal;
RefPtr<URLExtraData> mExtraData;
private:
mutable bool mURIResolved;
// mIsLocalRef is set when url starts with a U+0023 number sign(#) character.
@ -188,11 +213,8 @@ struct URLValue final : public URLValueData
// This constructor is safe to call from any thread.
URLValue(nsStringBuffer* aString,
already_AddRefed<PtrHolder<nsIURI>> aBaseURI,
already_AddRefed<PtrHolder<nsIURI>> aReferrer,
already_AddRefed<PtrHolder<nsIPrincipal>> aOriginPrincipal)
: URLValueData(aString, Move(aBaseURI), Move(aReferrer),
Move(aOriginPrincipal)) {}
already_AddRefed<URLExtraData> aExtraData)
: URLValueData(aString, Move(aExtraData)) {}
URLValue(const URLValue&) = delete;
URLValue& operator=(const URLValue&) = delete;
@ -208,16 +230,14 @@ struct ImageValue final : public URLValueData
// aString must not be null.
//
// This constructor is only safe to call from the main thread.
ImageValue(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aBaseURI,
nsIURI* aReferrer, nsIPrincipal* aOriginPrincipal,
ImageValue(nsIURI* aURI, nsStringBuffer* aString,
already_AddRefed<URLExtraData> aExtraData,
nsIDocument* aDocument);
// This constructor is safe to call from any thread, but Initialize
// must be called later for the object to be useful.
ImageValue(nsStringBuffer* aString,
already_AddRefed<PtrHolder<nsIURI>> aBaseURI,
already_AddRefed<PtrHolder<nsIURI>> aReferrer,
already_AddRefed<PtrHolder<nsIPrincipal>> aOriginPrincipal);
already_AddRefed<URLExtraData> aExtraData);
ImageValue(const ImageValue&) = delete;
ImageValue& operator=(const ImageValue&) = delete;

Просмотреть файл

@ -131,7 +131,8 @@ nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText)
RefPtr<DeclarationBlock> newdecl;
if (olddecl->IsServo()) {
GeckoParserExtraData data(env.mBaseURI, env.mSheetURI, env.mPrincipal);
RefPtr<css::URLExtraData> data =
new css::URLExtraData(env.mBaseURI, env.mSheetURI, env.mPrincipal);
newdecl = ServoDeclarationBlock::FromCssText(aCssText, data);
} else {
RefPtr<css::Declaration> decl(new css::Declaration());
@ -307,12 +308,13 @@ nsDOMCSSDeclaration::ParsePropertyValue(const nsCSSPropertyID aPropID,
decl->AsGecko(), &changed, aIsImportant);
} else {
NS_ConvertUTF16toUTF8 value(aPropValue);
GeckoParserExtraData data(env.mBaseURI, env.mSheetURI, env.mPrincipal);
RefPtr<css::URLExtraData> data =
new css::URLExtraData(env.mBaseURI, env.mSheetURI, env.mPrincipal);
nsCString baseString;
// FIXME (bug 1343964): Figure out a better solution for sending the base uri to servo
env.mBaseURI->GetSpec(baseString);
changed = Servo_DeclarationBlock_SetPropertyById(
decl->AsServo()->Raw(), aPropID, &value, aIsImportant, &baseString, &data);
decl->AsServo()->Raw(), aPropID, &value, aIsImportant, &baseString, data);
}
if (!changed) {
// Parsing failed -- but we don't throw an exception for that.
@ -358,11 +360,12 @@ nsDOMCSSDeclaration::ParseCustomPropertyValue(const nsAString& aPropertyName,
} else {
NS_ConvertUTF16toUTF8 property(aPropertyName);
NS_ConvertUTF16toUTF8 value(aPropValue);
GeckoParserExtraData data(env.mBaseURI, env.mSheetURI, env.mPrincipal);
RefPtr<css::URLExtraData> data =
new css::URLExtraData(env.mBaseURI, env.mSheetURI, env.mPrincipal);
nsCString baseString;
env.mBaseURI->GetSpec(baseString);
changed = Servo_DeclarationBlock_SetProperty(
decl->AsServo()->Raw(), &property, &value, aIsImportant, &baseString, &data);
decl->AsServo()->Raw(), &property, &value, aIsImportant, &baseString, data);
}
if (!changed) {
// Parsing failed -- but we don't throw an exception for that.

Просмотреть файл

@ -1999,14 +1999,11 @@ nsStyleImageRequest::nsStyleImageRequest(Mode aModeFlags,
nsStyleImageRequest::nsStyleImageRequest(
Mode aModeFlags,
nsStringBuffer* aURLBuffer,
already_AddRefed<PtrHolder<nsIURI>> aBaseURI,
already_AddRefed<PtrHolder<nsIURI>> aReferrer,
already_AddRefed<PtrHolder<nsIPrincipal>> aPrincipal)
: mModeFlags(aModeFlags)
already_AddRefed<css::URLExtraData> aExtraData)
: mImageValue(new css::ImageValue(aURLBuffer, Move(aExtraData)))
, mModeFlags(aModeFlags)
, mResolved(false)
{
mImageValue = new css::ImageValue(aURLBuffer, Move(aBaseURI),
Move(aReferrer), Move(aPrincipal));
}
nsStyleImageRequest::~nsStyleImageRequest()

Просмотреть файл

@ -339,9 +339,7 @@ public:
nsStyleImageRequest(
Mode aModeFlags,
nsStringBuffer* aURLBuffer,
already_AddRefed<mozilla::PtrHolder<nsIURI>> aBaseURI,
already_AddRefed<mozilla::PtrHolder<nsIURI>> aReferrer,
already_AddRefed<mozilla::PtrHolder<nsIPrincipal>> aPrincipal);
already_AddRefed<mozilla::css::URLExtraData> aExtraData);
bool Resolve(nsPresContext* aPresContext);
bool IsResolved() const { return mResolved; }