nsresult HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, bool aNotify) { if (aNameSpaceID == kNameSpaceID_None && mForm && (aName == nsGkAtoms::name || aName == nsGkAtoms::id) && aValue && !aValue->IsEmptyString()) { // add the image to the hashtable as needed NS_ABORT_IF_FALSE(aValue->Type() == nsAttrValue::eAtom, "Expected atom value for name/id"); mForm->AddImageElementToTable(this, nsDependentAtomString(aValue->GetAtomValue())); } // Handle src/srcset/crossorigin updates. If aNotify is false, we are coming // from the parser or some such place; we'll get bound after all the // attributes have been set, so we'll do the image load from BindToTree. if (aName == nsGkAtoms::src && aNameSpaceID == kNameSpaceID_None) { // SetAttr handles setting src in the non-responsive case, so only handle it // for responsive mode or unsetting if (!aValue) { CancelImageRequests(aNotify); } else if (mResponsiveSelector) { mResponsiveSelector->SetDefaultSource(aValue ? aValue->GetStringValue() : EmptyString()); LoadSelectedImage(false, aNotify); } } else if (aName == nsGkAtoms::srcset && aNameSpaceID == kNameSpaceID_None && aNotify && AsContent()->IsInDoc() && IsSrcsetEnabled()) { // We currently don't handle responsive mode until BindToTree UpdateSourceSet(aValue->GetStringValue()); LoadSelectedImage(false, aNotify); } else if (aName == nsGkAtoms::crossorigin && aNameSpaceID == kNameSpaceID_None && aNotify) { // We want aForce == true in this LoadImage call, because we want to force // a new load of the image with the new cross origin policy. nsCOMPtr<nsIURI> currentURI; if (NS_SUCCEEDED(GetCurrentURI(getter_AddRefs(currentURI))) && currentURI) { LoadImage(currentURI, true, aNotify); } } return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue, aNotify); }
void HTMLImageElement::MaybeLoadImage() { // Our base URI may have changed, or we may have had responsive parameters // change while not bound to the tree. Re-parse src/srcset and call LoadImage, // which is a no-op if it resolves to the same effective URI without aForce. // Note, check LoadingEnabled() after LoadImage call. LoadSelectedImage(false, true, false); if (!LoadingEnabled()) { CancelImageRequests(true); } }