Bug 42662: Values of disabled form elements should not be submitted; r=kmcclusk

This commit is contained in:
pollmann%netscape.com 2000-08-03 23:32:02 +00:00
Родитель 938616c2a3
Коммит 5ede1ee556
17 изменённых файлов: 95 добавлений и 17 удалений

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

@ -337,7 +337,9 @@ PRBool
nsComboboxControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
return !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
}
// If nothing is selected, and we have options, select item 0

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

@ -181,7 +181,9 @@ PRBool
nsFileControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
return !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
}
void

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

@ -762,10 +762,14 @@ PRBool
nsFormControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
nsAutoString name;
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
// Since JS Submit() calls are not linked to an element, aSubmitter is null.
// Return success to allow the call to go through.
if (aSubmitter == nsnull) return PR_TRUE;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
return !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
}
NS_METHOD

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

@ -1399,3 +1399,21 @@ nsFormControlHelper::GetLocalizedString(char* aKey, nsString& oVal)
return rv;
}
// Return value of disabled attribute or PR_FALSE if none set
nsresult
nsFormControlHelper::GetDisabled(nsIContent* aContent, PRBool* oIsDisabled)
{
nsCOMPtr<nsIHTMLContent> formControl = do_QueryInterface(aContent);
nsHTMLValue value;
nsresult result = formControl->GetHTMLAttribute(nsHTMLAtoms::disabled, value);
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
if (eHTMLUnit_Empty == value.GetUnit()) {
*oIsDisabled = PR_TRUE;
} else {
*oIsDisabled = PR_FALSE;
}
} else {
*oIsDisabled = PR_FALSE;
}
return NS_OK;
}

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

@ -179,6 +179,8 @@ public:
// Localization Helper
static nsresult GetLocalizedString(char* aKey, nsString& oVal);
static nsresult GetDisabled(nsIContent* aContent, PRBool* oIsDisabled);
//
//-------------------------------------------------------------------------------------
// Utility methods for managing checkboxes and radiobuttons

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

@ -41,14 +41,18 @@ nsGfxButtonControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
PRInt32 type;
GetType(&type);
PRBool successful = PR_TRUE;
if ((NS_FORM_INPUT_HIDDEN == type) || (this == aSubmitter)) {
// Can not use the nsHTMLButtonControlFrame::IsSuccessful because
// it will fail it's test of (this==aSubmitter)
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
successful = !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
} else {
return PR_FALSE;
successful = PR_FALSE;
}
return successful;
}
PRInt32

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

@ -280,12 +280,16 @@ nsHTMLButtonControlFrame::GetValue(nsString* aResult)
PRBool
nsHTMLButtonControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
PRBool successful = PR_TRUE;
if (this == (aSubmitter)) {
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
successful = !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
} else {
return PR_FALSE;
successful = PR_FALSE;
}
return successful;
}
PRBool

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

@ -1738,7 +1738,9 @@ PRBool
nsListControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
return !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
}

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

@ -337,7 +337,9 @@ PRBool
nsComboboxControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
return !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
}
// If nothing is selected, and we have options, select item 0

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

@ -181,7 +181,9 @@ PRBool
nsFileControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
return !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
}
void

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

@ -762,10 +762,14 @@ PRBool
nsFormControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
nsAutoString name;
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
// Since JS Submit() calls are not linked to an element, aSubmitter is null.
// Return success to allow the call to go through.
if (aSubmitter == nsnull) return PR_TRUE;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
return !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
}
NS_METHOD

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

@ -1399,3 +1399,21 @@ nsFormControlHelper::GetLocalizedString(char* aKey, nsString& oVal)
return rv;
}
// Return value of disabled attribute or PR_FALSE if none set
nsresult
nsFormControlHelper::GetDisabled(nsIContent* aContent, PRBool* oIsDisabled)
{
nsCOMPtr<nsIHTMLContent> formControl = do_QueryInterface(aContent);
nsHTMLValue value;
nsresult result = formControl->GetHTMLAttribute(nsHTMLAtoms::disabled, value);
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
if (eHTMLUnit_Empty == value.GetUnit()) {
*oIsDisabled = PR_TRUE;
} else {
*oIsDisabled = PR_FALSE;
}
} else {
*oIsDisabled = PR_FALSE;
}
return NS_OK;
}

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

@ -179,6 +179,8 @@ public:
// Localization Helper
static nsresult GetLocalizedString(char* aKey, nsString& oVal);
static nsresult GetDisabled(nsIContent* aContent, PRBool* oIsDisabled);
//
//-------------------------------------------------------------------------------------
// Utility methods for managing checkboxes and radiobuttons

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

@ -41,14 +41,18 @@ nsGfxButtonControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
PRInt32 type;
GetType(&type);
PRBool successful = PR_TRUE;
if ((NS_FORM_INPUT_HIDDEN == type) || (this == aSubmitter)) {
// Can not use the nsHTMLButtonControlFrame::IsSuccessful because
// it will fail it's test of (this==aSubmitter)
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
successful = !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
} else {
return PR_FALSE;
successful = PR_FALSE;
}
return successful;
}
PRInt32

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

@ -2085,7 +2085,9 @@ PRBool
nsGfxTextControlFrame2::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
return !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
}
NS_IMETHODIMP

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

@ -280,12 +280,16 @@ nsHTMLButtonControlFrame::GetValue(nsString* aResult)
PRBool
nsHTMLButtonControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
PRBool successful = PR_TRUE;
if (this == (aSubmitter)) {
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
successful = !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
} else {
return PR_FALSE;
successful = PR_FALSE;
}
return successful;
}
PRBool

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

@ -1738,7 +1738,9 @@ PRBool
nsListControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
nsAutoString name;
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
PRBool disabled = PR_FALSE;
nsFormControlHelper::GetDisabled(mContent, &disabled);
return !disabled && (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
}