Bug 42662: Values of disabled form elements should not be submitted; r=kmcclusk
git-svn-id: svn://10.0.0.236/trunk@75557 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user