summaryrefslogtreecommitdiffstats
path: root/dom/html/HTMLMediaElement.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-04-17 05:33:06 -0400
committerMatt A. Tobin <email@mattatobin.com>2020-04-17 05:33:06 -0400
commit17f7e1c8c6fca351174bdbd73981aa8e44d0f9da (patch)
treee8ea42c3121ecd79638172d226a94ad241a21ea9 /dom/html/HTMLMediaElement.cpp
parent940d191ef8b61309f4ea83d0fea77828f361251b (diff)
downloadUXP-17f7e1c8c6fca351174bdbd73981aa8e44d0f9da.tar
UXP-17f7e1c8c6fca351174bdbd73981aa8e44d0f9da.tar.gz
UXP-17f7e1c8c6fca351174bdbd73981aa8e44d0f9da.tar.lz
UXP-17f7e1c8c6fca351174bdbd73981aa8e44d0f9da.tar.xz
UXP-17f7e1c8c6fca351174bdbd73981aa8e44d0f9da.zip
Bug 1365092 - Move side effects of SetAttr and ParseAttribute to BeforeSetAttr and AfterSetAttr
* Moves side effects of nsGenericHTMLElement and Element's SetAttr, UnsetAttr, and ParseAttribute functions to the corresponding BeforeSetAttr and AfterSetAttr functions * Moves side effects of HTMLAnchorElement's SetAttr, UnsetAttr, and ParseAttribute functions to the corresponding BeforeSetAttr and AfterSetAttr functions * Moves side effects of HTMLImageElement's SetAttr function to the corresponding BeforeSetAttr and AfterSetAttr functions * Moves side effects of SetAttr, UnsetAttr, and ParseAttribute functions to BeforeSetAttr and AfterSetAttr Tag #1375
Diffstat (limited to 'dom/html/HTMLMediaElement.cpp')
-rw-r--r--dom/html/HTMLMediaElement.cpp112
1 files changed, 54 insertions, 58 deletions
diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp
index 4bcc188d3..05eaf3e8b 100644
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3726,78 +3726,74 @@ int32_t HTMLMediaElement::TabIndexDefault()
return 0;
}
-nsresult HTMLMediaElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
- nsIAtom* aPrefix, const nsAString& aValue,
- bool aNotify)
-{
- nsresult rv =
- nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, aValue,
- aNotify);
- if (NS_FAILED(rv))
- return rv;
- if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
- DoLoad();
- }
- if (aNotify && aNameSpaceID == kNameSpaceID_None) {
- if (aName == nsGkAtoms::autoplay) {
- StopSuspendingAfterFirstFrame();
- CheckAutoplayDataReady();
- // This attribute can affect AddRemoveSelfReference
- AddRemoveSelfReference();
- UpdatePreloadAction();
+nsresult
+HTMLMediaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
+ const nsAttrValue* aValue,
+ const nsAttrValue* aOldValue, bool aNotify)
+{
+ if (aNameSpaceID == kNameSpaceID_None) {
+ if (aName == nsGkAtoms::src) {
+ mSrcMediaSource = nullptr;
+ if (aValue) {
+ nsString srcStr = aValue->GetStringValue();
+ nsCOMPtr<nsIURI> uri;
+ NewURIFromString(srcStr, getter_AddRefs(uri));
+ if (uri && IsMediaSourceURI(uri)) {
+ nsresult rv =
+ NS_GetSourceForMediaSourceURI(uri, getter_AddRefs(mSrcMediaSource));
+ if (NS_FAILED(rv)) {
+ nsAutoString spec;
+ GetCurrentSrc(spec);
+ const char16_t* params[] = { spec.get() };
+ ReportLoadError("MediaLoadInvalidURI", params, ArrayLength(params));
+ }
+ }
+ }
+ } else if (aName == nsGkAtoms::autoplay) {
+ if (aNotify) {
+ if (aValue) {
+ StopSuspendingAfterFirstFrame();
+ CheckAutoplayDataReady();
+ }
+ // This attribute can affect AddRemoveSelfReference
+ AddRemoveSelfReference();
+ UpdatePreloadAction();
+ }
} else if (aName == nsGkAtoms::preload) {
UpdatePreloadAction();
}
}
- return rv;
+ // Since AfterMaybeChangeAttr may call DoLoad, make sure that it is called
+ // *after* any possible changes to mSrcMediaSource.
+ if (aValue) {
+ AfterMaybeChangeAttr(aNameSpaceID, aName, aNotify);
+ }
+
+ return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
+ aValue, aOldValue, aNotify);
}
-nsresult HTMLMediaElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttr,
- bool aNotify)
+nsresult
+HTMLMediaElement::OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
+ const nsAttrValueOrString& aValue,
+ bool aNotify)
{
- nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttr, aNotify);
- if (NS_FAILED(rv))
- return rv;
- if (aNotify && aNameSpaceID == kNameSpaceID_None) {
- if (aAttr == nsGkAtoms::autoplay) {
- // This attribute can affect AddRemoveSelfReference
- AddRemoveSelfReference();
- UpdatePreloadAction();
- } else if (aAttr == nsGkAtoms::preload) {
- UpdatePreloadAction();
- }
- }
+ AfterMaybeChangeAttr(aNamespaceID, aName, aNotify);
- return rv;
+ return nsGenericHTMLElement::OnAttrSetButNotChanged(aNamespaceID, aName,
+ aValue, aNotify);
}
-nsresult
-HTMLMediaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
- const nsAttrValue* aValue,
- const nsAttrValue* aOldValue, bool aNotify)
+void
+HTMLMediaElement::AfterMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
+ bool aNotify)
{
- if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
- mSrcMediaSource = nullptr;
- if (aValue) {
- nsString srcStr = aValue->GetStringValue();
- nsCOMPtr<nsIURI> uri;
- NewURIFromString(srcStr, getter_AddRefs(uri));
- if (uri && IsMediaSourceURI(uri)) {
- nsresult rv =
- NS_GetSourceForMediaSourceURI(uri, getter_AddRefs(mSrcMediaSource));
- if (NS_FAILED(rv)) {
- nsAutoString spec;
- GetCurrentSrc(spec);
- const char16_t* params[] = { spec.get() };
- ReportLoadError("MediaLoadInvalidURI", params, ArrayLength(params));
- }
- }
+ if (aNamespaceID == kNameSpaceID_None) {
+ if (aName == nsGkAtoms::src) {
+ DoLoad();
}
}
-
- return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
- aValue, aOldValue, aNotify);
}
nsresult HTMLMediaElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,