Issue #2158 - Part 2: Handle and expose preload link destination to DOM

This also defines known preload destinations and ensures it is reflected in JS.
This commit is contained in:
FranklinDM 2023-03-11 16:42:18 +08:00 • committed by roytam1
commit 24189770aa
11 changed files with 98 additions and 5 deletions

View file

@ -26,6 +26,47 @@
namespace mozilla {
namespace dom {
enum Destination : uint8_t
{
DESTINATION_INVALID,
DESTINATION_AUDIO,
DESTINATION_AUDIOWORKLET,
DESTINATION_DOCUMENT,
DESTINATION_EMBED,
DESTINATION_FONT,
DESTINATION_FRAME,
DESTINATION_IFRAME,
DESTINATION_IMAGE,
DESTINATION_JSON,
DESTINATION_MANIFEST,
DESTINATION_OBJECT,
DESTINATION_REPORT,
DESTINATION_SCRIPT,
DESTINATION_SERVICEWORKER,
DESTINATION_SHAREDWORKER,
DESTINATION_STYLE,
DESTINATION_TRACK,
DESTINATION_VIDEO,
DESTINATION_WEBIDENTITY,
DESTINATION_WORKER,
DESTINATION_XSLT,
DESTINATION_FETCH
};
static const nsAttrValue::EnumTable kDestinationAttributeTable[] = {
{ "", DESTINATION_INVALID },
{ "audio", DESTINATION_AUDIO },
{ "font", DESTINATION_FONT },
{ "image", DESTINATION_IMAGE },
{ "script", DESTINATION_SCRIPT },
{ "style", DESTINATION_STYLE },
{ "track", DESTINATION_TRACK },
{ "video", DESTINATION_VIDEO },
{ "fetch", DESTINATION_FETCH },
{ "json", DESTINATION_JSON },
{ nullptr, 0 }
};
Link::Link(Element *aElement)
: mElement(aElement)
, mHistory(services::GetHistoryService())
@ -635,6 +676,17 @@ Link::SetHrefAttribute(nsIURI *aURI)
NS_ConvertUTF8toUTF16(href), true);
}
/* static */ void
Link::ParseDestinationValue(const nsAString& aValue,
nsAttrValue& aResult)
{
// Invalid values are treated as an empty string.
aResult.ParseEnumValue(aValue,
kDestinationAttributeTable,
false,
&kDestinationAttributeTable[0]);
}
size_t
Link::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{