Bug 1459498: Refactor nsStyleLinkElement so that all the stylesheet information comes from one place. r=heycam

I've kept the nsAutoStrings in the StyleSheetInfo class on the hopes that the
compiler does RVO, but if it doesn't I can remove I guess.

MozReview-Commit-ID: 2vN6BSEhYcw
This commit is contained in:
Emilio Cobos Álvarez
2018-05-06 13:20:03 +02:00
parent a60aad1d99
commit e7b8d2db8c
12 changed files with 243 additions and 246 deletions

View File

@@ -194,47 +194,43 @@ HTMLStyleElement::SetTextContentInternal(const nsAString& aTextContent,
Unused << UpdateStyleSheetInternal(nullptr, nullptr);
}
already_AddRefed<nsIURI>
HTMLStyleElement::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
Maybe<nsStyleLinkElement::StyleSheetInfo>
HTMLStyleElement::GetStyleSheetInfo()
{
*aIsInline = true;
*aTriggeringPrincipal = do_AddRef(mTriggeringPrincipal).take();
return nullptr;
}
void
HTMLStyleElement::GetStyleSheetInfo(nsAString& aTitle,
nsAString& aType,
nsAString& aMedia,
bool* aIsAlternate)
{
aTitle.Truncate();
aType.Truncate();
aMedia.Truncate();
*aIsAlternate = false;
nsAutoString title;
GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
title.CompressWhitespace();
aTitle.Assign(title);
GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
nsAutoString media;
GetAttr(kNameSpaceID_None, nsGkAtoms::media, media);
// The HTML5 spec is formulated in terms of the CSSOM spec, which specifies
// that media queries should be ASCII lowercased during serialization.
nsContentUtils::ASCIIToLower(aMedia);
GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
//
// FIXME(emilio): Doesn't matter I'd think, style should take care of that.
nsContentUtils::ASCIIToLower(media);
nsAutoString type;
nsAutoString mimeType;
nsAutoString notUsed;
nsContentUtils::SplitMimeType(aType, mimeType, notUsed);
GetAttr(kNameSpaceID_None, nsGkAtoms::type, type);
nsContentUtils::SplitMimeType(type, mimeType, notUsed);
if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
return;
return Nothing();
}
// If we get here we assume that we're loading a css file, so set the
// type to 'text/css'
aType.AssignLiteral("text/css");
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
return Some(StyleSheetInfo {
*OwnerDoc(),
this,
nullptr,
prin.forget(),
net::ReferrerPolicy::RP_Unset,
CORS_NONE,
title,
media,
IsAlternate::No,
IsInline::Yes,
});
}
JSObject*