Bug 1366361 - Part 1: .action/formAction should return the document's URL if @action/formaction is missing or empty. r=smaug

MozReview-Commit-ID: H4CK0SVpaCv
This commit is contained in:
Jessica Jong 2017-07-17 14:17:19 +08:00
parent 4c033a0b2c
commit b52a4e5094
6 changed files with 53 additions and 1 deletions

View File

@ -23,6 +23,7 @@ class HTMLButtonElement final : public nsGenericHTMLFormElementWithState,
{
public:
using nsIConstraintValidation::GetValidationMessage;
using nsGenericHTMLFormElementWithState::GetFormAction;
explicit HTMLButtonElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser = NOT_FROM_PARSER);

View File

@ -1585,6 +1585,27 @@ HTMLFormElement::FlushPendingSubmission()
}
}
void
HTMLFormElement::GetAction(nsString& aValue)
{
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::action, aValue) ||
aValue.IsEmpty()) {
nsIDocument* document = OwnerDoc();
nsIURI* docURI = document->GetDocumentURI();
if (docURI) {
nsAutoCString spec;
nsresult rv = docURI->GetSpec(spec);
if (NS_FAILED(rv)) {
return;
}
CopyUTF8toUTF16(spec, aValue);
}
} else {
GetURIAttr(nsGkAtoms::action, nullptr, aValue);
}
}
nsresult
HTMLFormElement::GetActionURL(nsIURI** aActionURL,
nsIContent* aOriginatingElement)

View File

@ -314,7 +314,8 @@ public:
SetHTMLAttr(nsGkAtoms::acceptcharset, aValue, aRv);
}
// XPCOM GetAction() is OK
void GetAction(nsString& aValue);
void SetAction(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::action, aValue, aRv);

View File

@ -137,6 +137,7 @@ class HTMLInputElement final : public nsGenericHTMLFormElementWithState,
public:
using nsIConstraintValidation::GetValidationMessage;
using nsGenericHTMLFormElementWithState::GetForm;
using nsGenericHTMLFormElementWithState::GetFormAction;
enum class FromClone { no, yes };

View File

@ -2428,6 +2428,32 @@ nsGenericHTMLFormElement::IsLabelable() const
type == NS_FORM_TEXTAREA;
}
void
nsGenericHTMLFormElement::GetFormAction(nsString& aValue)
{
uint32_t type = ControlType();
if (!(type & NS_FORM_INPUT_ELEMENT) && !(type & NS_FORM_BUTTON_ELEMENT)) {
return;
}
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::formaction, aValue) ||
aValue.IsEmpty()) {
nsIDocument* document = OwnerDoc();
nsIURI* docURI = document->GetDocumentURI();
if (docURI) {
nsAutoCString spec;
nsresult rv = docURI->GetSpec(spec);
if (NS_FAILED(rv)) {
return;
}
CopyUTF8toUTF16(spec, aValue);
}
} else {
GetURIAttr(nsGkAtoms::formaction, nullptr, aValue);
}
}
//----------------------------------------------------------------------
void

View File

@ -1120,6 +1120,8 @@ public:
virtual bool IsLabelable() const override;
void GetFormAction(nsString& aValue);
protected:
virtual ~nsGenericHTMLFormElement();