Bug 490665 - Implement HTML5-compliant isindex form submission. r=jonas.

--HG--
extra : rebase_source : 2075bc59ce711e29718eac8bb0e1b8867e291a53
This commit is contained in:
Henri Sivonen 2010-03-11 14:29:51 +02:00
Родитель 98fa4b36ac
Коммит 3bd2cdfb7c
3 изменённых файлов: 52 добавлений и 3 удалений

Просмотреть файл

@ -83,6 +83,27 @@ public:
virtual nsresult AddNameFilePair(const nsAString& aName,
nsIFile* aFile) = 0;
/**
* Reports whether the instance supports AddIsindex().
*
* @return true if supported.
*/
virtual PRBool SupportsIsindexSubmission()
{
return PR_FALSE;
}
/**
* Adds an isindex value to the submission.
*
* @param aValue the field value
*/
virtual nsresult AddIsindex(const nsAString& aValue)
{
NS_NOTREACHED("AddIsindex called when not supported");
return NS_ERROR_UNEXPECTED;
}
/**
* Given a URI and the current submission, create the final URI and data
* stream that will be submitted. Subclasses *must* implement this.

Просмотреть файл

@ -114,6 +114,13 @@ public:
virtual nsresult GetEncodedSubmission(nsIURI* aURI,
nsIInputStream** aPostDataStream);
virtual PRBool SupportsIsindexSubmission()
{
return PR_TRUE;
}
virtual nsresult AddIsindex(const nsAString& aValue);
protected:
/**
@ -169,6 +176,24 @@ nsFSURLEncoded::AddNameValuePair(const nsAString& aName,
return NS_OK;
}
nsresult
nsFSURLEncoded::AddIsindex(const nsAString& aValue)
{
// Encode value
nsCString convValue;
nsresult rv = URLEncode(aValue, convValue);
NS_ENSURE_SUCCESS(rv, rv);
// Append data to string
if (mQueryString.IsEmpty()) {
mQueryString.Assign(convValue);
} else {
mQueryString += NS_LITERAL_CSTRING("&isindex=") + convValue;
}
return NS_OK;
}
nsresult
nsFSURLEncoded::AddNameFilePair(const nsAString& aName,
nsIFile* aFile)

Просмотреть файл

@ -2659,15 +2659,18 @@ nsHTMLInputElement::SubmitNamesValues(nsFormSubmission* aFormSubmission,
return NS_OK;
}
// Submit
// (for type=image, only submit if value is non-null)
if (mType == NS_FORM_INPUT_HIDDEN && name.EqualsLiteral("_charset_")) {
nsCString charset;
aFormSubmission->GetCharset(charset);
rv = aFormSubmission->AddNameValuePair(name,
NS_ConvertASCIItoUTF16(charset));
}
else if (mType != NS_FORM_INPUT_IMAGE || !value.IsEmpty()) {
else if (mType == NS_FORM_INPUT_TEXT &&
name.EqualsLiteral("isindex") &&
aFormSubmission->SupportsIsindexSubmission()) {
rv = aFormSubmission->AddIsindex(value);
}
else {
rv = aFormSubmission->AddNameValuePair(name, value);
}