mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1529177 - Make InsertTagCommand::DoCommandParams() use nsGkAtoms to set attribute r=m_kato
`InsertTagCommand::DoCommandParams()` uses `Element::SetAttribute()` which takes `nsAString` as attribute name. For avoiding unnecessary copy of attribute name, we should make it use `Element::SetAttr()` which takes `nsAtom` instead. Differential Revision: https://phabricator.services.mozilla.com/D20614 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
74e2bc67b3
commit
d926c78b43
@ -1404,26 +1404,29 @@ InsertTagCommand::DoCommandParams(const char* aCommandName,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Don't use nsAutoCString here because nsCommandParams stores c-string member
|
||||
// with nsCString*. Therefore, nsAutoCString always needs to copy the storage
|
||||
// but nsCString may avoid it.
|
||||
// TODO: This does not aware of URL which includes non-ASCII characters.
|
||||
// A follow up bug will fix this.
|
||||
nsCString asciiValue;
|
||||
// do we have an href to use for creating link?
|
||||
nsAutoCString asciiAttribute;
|
||||
nsresult rv =
|
||||
aParams->AsCommandParams()->GetCString(STATE_ATTRIBUTE, asciiAttribute);
|
||||
aParams->AsCommandParams()->GetCString(STATE_ATTRIBUTE, asciiValue);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
nsAutoString attribute;
|
||||
CopyASCIItoUTF16(asciiAttribute, attribute);
|
||||
|
||||
if (attribute.IsEmpty()) {
|
||||
NS_ConvertASCIItoUTF16 value(asciiValue);
|
||||
if (NS_WARN_IF(value.IsEmpty())) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// filter out tags we don't know how to insert
|
||||
nsAutoString attributeType;
|
||||
nsAtom* attribute = nullptr;
|
||||
if (mTagName == nsGkAtoms::a) {
|
||||
attributeType.AssignLiteral("href");
|
||||
attribute = nsGkAtoms::href;
|
||||
} else if (mTagName == nsGkAtoms::img) {
|
||||
attributeType.AssignLiteral("src");
|
||||
attribute = nsGkAtoms::src;
|
||||
} else {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
@ -1434,7 +1437,7 @@ InsertTagCommand::DoCommandParams(const char* aCommandName,
|
||||
}
|
||||
|
||||
ErrorResult err;
|
||||
newElement->SetAttribute(attributeType, attribute, err);
|
||||
newElement->SetAttr(attribute, value, err);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user