Issue #2158 - Part 4: Dispatch load/error events upon parsing preload links

This commit is contained in:
FranklinDM 2024-01-27 16:38:43 +08:00 committed by roytam1
commit 95490b25eb
7 changed files with 408 additions and 25 deletions

View file

@ -216,6 +216,7 @@
#include "TabChild.h"
#include "mozilla/dom/DocGroup.h"
#include "mozilla/dom/TabGroup.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "nsIBidiKeyboard.h"
@ -4120,6 +4121,24 @@ nsresult GetEventAndTarget(nsIDocument* aDoc, nsISupports* aTarget,
return NS_OK;
}
void
nsContentUtils::DispatchEventForPreloadURI(nsIDOMNode* aNode,
nsContentPolicyType& aPolicyType)
{
nsCOMPtr<nsINode> domNode = do_QueryInterface(aNode);
if (domNode && domNode->IsInComposedDoc()) {
bool success = aPolicyType != nsIContentPolicy::TYPE_INVALID;
RefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(domNode,
success ?
NS_LITERAL_STRING("load") :
NS_LITERAL_STRING("error"),
/* aCanBubble = */ false,
/* aCancelable = */ false);
asyncDispatcher->RunDOMEventWhenSafe();
}
}
// static
nsresult
nsContentUtils::DispatchTrustedEvent(nsIDocument* aDoc, nsISupports* aTarget,
@ -7441,6 +7460,48 @@ nsContentUtils::IsJavascriptMIMEType(const nsAString& aMIMEType)
return false;
}
bool
nsContentUtils::IsJSONMIMEType(const nsAString& aMIMEType)
{
static const char* jsonTypes[] = {
"text/json",
"application/json",
"application/geo+json",
nullptr
};
for (uint32_t i = 0; jsonTypes[i]; ++i) {
if (aMIMEType.LowerCaseEqualsASCII(jsonTypes[i])) {
return true;
}
}
return false;
}
bool
nsContentUtils::IsFontMIMEType(const nsAString& aMIMEType)
{
// The following list was taken from IANA and excludes deprecated mime-types:
// https://www.iana.org/assignments/media-types/media-types.xhtml#font
static const char* fontTypes[] = {
"font/otf",
"font/sfnt",
"font/ttf",
"font/woff",
"font/woff2",
nullptr
};
for (uint32_t i = 0; fontTypes[i]; ++i) {
if (aMIMEType.LowerCaseEqualsASCII(fontTypes[i])) {
return true;
}
}
return false;
}
nsresult
nsContentUtils::GenerateUUIDInPlace(nsID& aUUID)
{