Bug 1317367 part 4. Pass an explicit CallerType to HTMLInputElement::GetValueInternal. r=smaug

I'm not 100% sure that I'm being very consistent in my handling of
mFocusedValue, but since that's not used for file inputs, I don't think it
matters much...

A bigger problem is if people start using this caller type for things other than
file inputs.
This commit is contained in:
Boris Zbarsky 2016-11-15 12:46:32 -05:00
Родитель a59a621bb6
Коммит 62e08b6904
13 изменённых файлов: 147 добавлений и 140 удалений

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

@ -351,8 +351,11 @@ HTMLTextFieldAccessible::Value(nsString& aValue)
} }
HTMLInputElement* input = HTMLInputElement::FromContent(mContent); HTMLInputElement* input = HTMLInputElement::FromContent(mContent);
if (input) if (input) {
input->GetValue(aValue); // Pass NonSystem as the caller type, to be safe. We don't expect to have a
// file input here.
input->GetValue(aValue, CallerType::NonSystem);
}
} }
void void
@ -552,7 +555,10 @@ HTMLSpinnerAccessible::Value(nsString& aValue)
if (!aValue.IsEmpty()) if (!aValue.IsEmpty())
return; return;
HTMLInputElement::FromContent(mContent)->GetValue(aValue); // Pass NonSystem as the caller type, to be safe. We don't expect to have a
// file input here.
HTMLInputElement::FromContent(mContent)->GetValue(aValue,
CallerType::NonSystem);
} }
double double
@ -628,7 +634,10 @@ HTMLRangeAccessible::Value(nsString& aValue)
if (!aValue.IsEmpty()) if (!aValue.IsEmpty())
return; return;
HTMLInputElement::FromContent(mContent)->GetValue(aValue); // Pass NonSystem as the caller type, to be safe. We don't expect to have a
// file input here.
HTMLInputElement::FromContent(mContent)->GetValue(aValue,
CallerType::NonSystem);
} }
double double

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

@ -691,7 +691,7 @@ nsColorPickerShownCallback::UpdateInternal(const nsAString& aColor,
if (aTrustedUpdate) { if (aTrustedUpdate) {
valueChanged = true; valueChanged = true;
} else { } else {
mInput->GetValue(oldValue); mInput->GetValue(oldValue, CallerType::System);
} }
IgnoredErrorResult rv; IgnoredErrorResult rv;
@ -699,7 +699,7 @@ nsColorPickerShownCallback::UpdateInternal(const nsAString& aColor,
if (!aTrustedUpdate) { if (!aTrustedUpdate) {
nsAutoString newValue; nsAutoString newValue;
mInput->GetValue(newValue); mInput->GetValue(newValue, CallerType::System);
if (!oldValue.Equals(newValue)) { if (!oldValue.Equals(newValue)) {
valueChanged = true; valueChanged = true;
} }
@ -785,7 +785,7 @@ DatePickerShownCallback::Done(const nsAString& aDate)
nsAutoString oldValue; nsAutoString oldValue;
mInput->PickerClosed(); mInput->PickerClosed();
mInput->GetValue(oldValue); mInput->GetValue(oldValue, CallerType::System);
if(!oldValue.Equals(aDate)){ if(!oldValue.Equals(aDate)){
IgnoredErrorResult rv; IgnoredErrorResult rv;
@ -866,7 +866,7 @@ HTMLInputElement::InitDatePicker()
} }
nsAutoString initialValue; nsAutoString initialValue;
GetValueInternal(initialValue); GetNonFileValueInternal(initialValue);
rv = datePicker->Init(win, title, initialValue); rv = datePicker->Init(win, title, initialValue);
nsCOMPtr<nsIDatePickerShownCallback> callback = nsCOMPtr<nsIDatePickerShownCallback> callback =
@ -911,7 +911,7 @@ HTMLInputElement::InitColorPicker()
} }
nsAutoString initialValue; nsAutoString initialValue;
GetValueInternal(initialValue); GetNonFileValueInternal(initialValue);
nsresult rv = colorPicker->Init(win, title, initialValue); nsresult rv = colorPicker->Init(win, title, initialValue);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -1324,7 +1324,7 @@ HTMLInputElement::Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) co
// We don't have our default value anymore. Set our value on // We don't have our default value anymore. Set our value on
// the clone. // the clone.
nsAutoString value; nsAutoString value;
GetValueInternal(value); GetNonFileValueInternal(value);
// SetValueInternal handles setting the VALUE_CHANGED bit for us // SetValueInternal handles setting the VALUE_CHANGED bit for us
rv = it->SetValueInternal(value, nsTextEditorState::eSetValue_Notify); rv = it->SetValueInternal(value, nsTextEditorState::eSetValue_Notify);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -1519,7 +1519,7 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
// a step mismatch and a value that results in overflow. For example, // a step mismatch and a value that results in overflow. For example,
// if @max in the example above were to change from 1 to -1. // if @max in the example above were to change from 1 to -1.
nsAutoString value; nsAutoString value;
GetValue(value); GetNonFileValueInternal(value);
nsresult rv = nsresult rv =
SetValueInternal(value, nsTextEditorState::eSetValue_Internal); SetValueInternal(value, nsTextEditorState::eSetValue_Internal);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -1538,7 +1538,7 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
if (mType == NS_FORM_INPUT_RANGE) { if (mType == NS_FORM_INPUT_RANGE) {
// See @max comment // See @max comment
nsAutoString value; nsAutoString value;
GetValue(value); GetNonFileValueInternal(value);
nsresult rv = nsresult rv =
SetValueInternal(value, nsTextEditorState::eSetValue_Internal); SetValueInternal(value, nsTextEditorState::eSetValue_Internal);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -1554,7 +1554,7 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
if (mType == NS_FORM_INPUT_RANGE) { if (mType == NS_FORM_INPUT_RANGE) {
// See @max comment // See @max comment
nsAutoString value; nsAutoString value;
GetValue(value); GetNonFileValueInternal(value);
nsresult rv = nsresult rv =
SetValueInternal(value, nsTextEditorState::eSetValue_Internal); SetValueInternal(value, nsTextEditorState::eSetValue_Internal);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -1572,7 +1572,7 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
if (mType == NS_FORM_INPUT_NUMBER) { if (mType == NS_FORM_INPUT_NUMBER) {
// Update the value that is displayed to the user to the new locale: // Update the value that is displayed to the user to the new locale:
nsAutoString value; nsAutoString value;
GetValueInternal(value); GetNonFileValueInternal(value);
nsNumberControlFrame* numberControlFrame = nsNumberControlFrame* numberControlFrame =
do_QueryFrame(GetPrimaryFrame()); do_QueryFrame(GetPrimaryFrame());
if (numberControlFrame) { if (numberControlFrame) {
@ -1754,22 +1754,41 @@ HTMLInputElement::SetWidth(uint32_t aWidth)
return rv.StealNSResult(); return rv.StealNSResult();
} }
NS_IMETHODIMP void
HTMLInputElement::GetValue(nsAString& aValue) HTMLInputElement::GetValue(nsAString& aValue, CallerType aCallerType)
{ {
GetValueInternal(aValue); GetValueInternal(aValue, aCallerType);
// Don't return non-sanitized value for types that are experimental on mobile // Don't return non-sanitized value for types that are experimental on mobile
// or datetime types // or datetime types
if (IsExperimentalMobileType(mType) || IsDateTimeInputType(mType)) { if (IsExperimentalMobileType(mType) || IsDateTimeInputType(mType)) {
SanitizeValue(aValue); SanitizeValue(aValue);
} }
return NS_OK;
} }
void void
HTMLInputElement::GetValueInternal(nsAString& aValue) const HTMLInputElement::GetValueInternal(nsAString& aValue,
CallerType aCallerType) const
{
if (mType != NS_FORM_INPUT_FILE) {
GetNonFileValueInternal(aValue);
return;
}
if (aCallerType == CallerType::System) {
aValue.Assign(mFirstFilePath);
} else {
// Just return the leaf name
if (mFilesOrDirectories.IsEmpty()) {
aValue.Truncate();
} else {
GetDOMFileOrDirectoryName(mFilesOrDirectories[0], aValue);
}
}
}
void
HTMLInputElement::GetNonFileValueInternal(nsAString& aValue) const
{ {
switch (GetValueMode()) { switch (GetValueMode()) {
case VALUE_MODE_VALUE: case VALUE_MODE_VALUE:
@ -1781,17 +1800,9 @@ HTMLInputElement::GetValueInternal(nsAString& aValue) const
return; return;
case VALUE_MODE_FILENAME: case VALUE_MODE_FILENAME:
if (nsContentUtils::LegacyIsCallerChromeOrNativeCode()) { NS_NOTREACHED("Someone screwed up here");
aValue.Assign(mFirstFilePath); // We'll just return empty string if someone does screw up.
} else {
// Just return the leaf name
if (mFilesOrDirectories.IsEmpty()) {
aValue.Truncate(); aValue.Truncate();
} else {
GetDOMFileOrDirectoryName(mFilesOrDirectories[0], aValue);
}
}
return; return;
case VALUE_MODE_DEFAULT: case VALUE_MODE_DEFAULT:
@ -1812,7 +1823,7 @@ bool
HTMLInputElement::IsValueEmpty() const HTMLInputElement::IsValueEmpty() const
{ {
nsAutoString value; nsAutoString value;
GetValueInternal(value); GetNonFileValueInternal(value);
return value.IsEmpty(); return value.IsEmpty();
} }
@ -1933,7 +1944,7 @@ HTMLInputElement::GetValueAsDecimal() const
Decimal decimalValue; Decimal decimalValue;
nsAutoString stringValue; nsAutoString stringValue;
GetValueInternal(stringValue); GetNonFileValueInternal(stringValue);
return !ConvertStringToNumber(stringValue, decimalValue) ? Decimal::nan() return !ConvertStringToNumber(stringValue, decimalValue) ? Decimal::nan()
: decimalValue; : decimalValue;
@ -1976,7 +1987,7 @@ HTMLInputElement::SetValue(const nsAString& aValue, CallerType aCallerType,
// NOTE: this is currently quite expensive work (too much string // NOTE: this is currently quite expensive work (too much string
// manipulation). We should probably optimize that. // manipulation). We should probably optimize that.
nsAutoString currentValue; nsAutoString currentValue;
GetValue(currentValue); GetValue(currentValue, aCallerType);
nsresult rv = nsresult rv =
SetValueInternal(aValue, nsTextEditorState::eSetValue_ByContent | SetValueInternal(aValue, nsTextEditorState::eSetValue_ByContent |
@ -1987,7 +1998,7 @@ HTMLInputElement::SetValue(const nsAString& aValue, CallerType aCallerType,
} }
if (mFocusedValue.Equals(currentValue)) { if (mFocusedValue.Equals(currentValue)) {
GetValue(mFocusedValue); GetValue(mFocusedValue, aCallerType);
} }
} else { } else {
nsresult rv = nsresult rv =
@ -2001,13 +2012,6 @@ HTMLInputElement::SetValue(const nsAString& aValue, CallerType aCallerType,
} }
} }
NS_IMETHODIMP
HTMLInputElement::SetValue(const nsAString& aValue)
{
NS_NOTREACHED("No one should be calling this method");
return NS_ERROR_FAILURE;
}
nsGenericHTMLElement* nsGenericHTMLElement*
HTMLInputElement::GetList() const HTMLInputElement::GetList() const
{ {
@ -2207,7 +2211,7 @@ HTMLInputElement::GetValueAsDate(ErrorResult& aRv)
{ {
uint32_t year, month, day; uint32_t year, month, day;
nsAutoString value; nsAutoString value;
GetValueInternal(value); GetNonFileValueInternal(value);
if (!ParseDate(value, &year, &month, &day)) { if (!ParseDate(value, &year, &month, &day)) {
return Nullable<Date>(); return Nullable<Date>();
} }
@ -2219,7 +2223,7 @@ HTMLInputElement::GetValueAsDate(ErrorResult& aRv)
{ {
uint32_t millisecond; uint32_t millisecond;
nsAutoString value; nsAutoString value;
GetValueInternal(value); GetNonFileValueInternal(value);
if (!ParseTime(value, &millisecond)) { if (!ParseTime(value, &millisecond)) {
return Nullable<Date>(); return Nullable<Date>();
} }
@ -2234,7 +2238,7 @@ HTMLInputElement::GetValueAsDate(ErrorResult& aRv)
{ {
uint32_t year, month; uint32_t year, month;
nsAutoString value; nsAutoString value;
GetValueInternal(value); GetNonFileValueInternal(value);
if (!ParseMonth(value, &year, &month)) { if (!ParseMonth(value, &year, &month)) {
return Nullable<Date>(); return Nullable<Date>();
} }
@ -2246,7 +2250,7 @@ HTMLInputElement::GetValueAsDate(ErrorResult& aRv)
{ {
uint32_t year, week; uint32_t year, week;
nsAutoString value; nsAutoString value;
GetValueInternal(value); GetNonFileValueInternal(value);
if (!ParseWeek(value, &year, &week)) { if (!ParseWeek(value, &year, &week)) {
return Nullable<Date>(); return Nullable<Date>();
} }
@ -3091,8 +3095,10 @@ HTMLInputElement::AfterSetFilesOrDirectories(bool aSetValueChanged)
void void
HTMLInputElement::FireChangeEventIfNeeded() HTMLInputElement::FireChangeEventIfNeeded()
{ {
// We're not exposing the GetValue return value anywhere here, so it's safe to
// claim to be a system caller.
nsAutoString value; nsAutoString value;
GetValue(value); GetValue(value, CallerType::System);
if (!MayFireChangeOnBlur() || mFocusedValue.Equals(value)) { if (!MayFireChangeOnBlur() || mFocusedValue.Equals(value)) {
return; return;
@ -3859,7 +3865,7 @@ HTMLInputElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
// StartRangeThumbDrag already set mFocusedValue on 'mousedown' before // StartRangeThumbDrag already set mFocusedValue on 'mousedown' before
// we get the 'focus' event. // we get the 'focus' event.
!mIsDraggingRange) { !mIsDraggingRange) {
GetValue(mFocusedValue); GetValue(mFocusedValue, CallerType::System);
} }
// Fire onchange (if necessary), before we do the blur, bug 357684. // Fire onchange (if necessary), before we do the blur, bug 357684.
@ -3869,7 +3875,7 @@ HTMLInputElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
// option has been enabled on desktop. // option has been enabled on desktop.
if (IsExperimentalMobileType(mType)) { if (IsExperimentalMobileType(mType)) {
nsAutoString aValue; nsAutoString aValue;
GetValueInternal(aValue); GetNonFileValueInternal(aValue);
nsresult rv = nsresult rv =
SetValueInternal(aValue, nsTextEditorState::eSetValue_Internal); SetValueInternal(aValue, nsTextEditorState::eSetValue_Internal);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -4050,7 +4056,7 @@ HTMLInputElement::StartRangeThumbDrag(WidgetGUIEvent* aEvent)
// because the 'focus' event is handled after the 'mousedown' event that // because the 'focus' event is handled after the 'mousedown' event that
// we're being called for (i.e. too late to update mFocusedValue, since we'll // we're being called for (i.e. too late to update mFocusedValue, since we'll
// have changed it by then). // have changed it by then).
GetValue(mFocusedValue); GetValue(mFocusedValue, CallerType::System);
SetValueOfRangeForUserEvent(rangeFrame->GetValueAtEventPoint(aEvent)); SetValueOfRangeForUserEvent(rangeFrame->GetValueAtEventPoint(aEvent));
} }
@ -5031,7 +5037,9 @@ HTMLInputElement::HandleTypeChange(uint8_t aNewType)
nsAutoString aOldValue; nsAutoString aOldValue;
if (aOldValueMode == VALUE_MODE_VALUE) { if (aOldValueMode == VALUE_MODE_VALUE) {
GetValue(aOldValue); // Doesn't matter what caller type we pass here, since we know we're not a
// file input anyway.
GetValue(aOldValue, CallerType::NonSystem);
} }
nsTextEditorState::SelectionProperties sp; nsTextEditorState::SelectionProperties sp;
@ -5096,7 +5104,7 @@ HTMLInputElement::HandleTypeChange(uint8_t aNewType)
// Otherwise, if the new type doesn't fire a change event on blur, but the // Otherwise, if the new type doesn't fire a change event on blur, but the
// previous type does, we should clear out mFocusedValue. // previous type does, we should clear out mFocusedValue.
if (MayFireChangeOnBlur(mType) && !MayFireChangeOnBlur(oldType)) { if (MayFireChangeOnBlur(mType) && !MayFireChangeOnBlur(oldType)) {
GetValue(mFocusedValue); GetValue(mFocusedValue, CallerType::System);
} else if (!IsSingleLineTextControl(false, mType) && } else if (!IsSingleLineTextControl(false, mType) &&
IsSingleLineTextControl(false, oldType)) { IsSingleLineTextControl(false, oldType)) {
mFocusedValue.Truncate(); mFocusedValue.Truncate();
@ -6010,21 +6018,13 @@ HTMLInputElement::GetControllers(nsIControllers** aResult)
} }
int32_t int32_t
HTMLInputElement::GetTextLength(ErrorResult& aRv) HTMLInputElement::InputTextLength(CallerType aCallerType)
{ {
nsAutoString val; nsAutoString val;
GetValue(val); GetValue(val, aCallerType);
return val.Length(); return val.Length();
} }
NS_IMETHODIMP
HTMLInputElement::GetTextLength(int32_t* aTextLength)
{
ErrorResult rv;
*aTextLength = GetTextLength(rv);
return rv.StealNSResult();
}
void void
HTMLInputElement::SetSelectionRange(int32_t aSelectionStart, HTMLInputElement::SetSelectionRange(int32_t aSelectionStart,
int32_t aSelectionEnd, int32_t aSelectionEnd,
@ -6114,7 +6114,7 @@ HTMLInputElement::SetRangeText(const nsAString& aReplacement, uint32_t aStart,
} }
nsAutoString value; nsAutoString value;
GetValueInternal(value); GetNonFileValueInternal(value);
uint32_t inputValueLength = value.Length(); uint32_t inputValueLength = value.Length();
if (aStart > inputValueLength) { if (aStart > inputValueLength) {
@ -6535,7 +6535,7 @@ HTMLInputElement::SetDirectionIfAuto(bool aAuto, bool aNotify)
SetHasDirAuto(); SetHasDirAuto();
if (IsSingleLineTextControl(true)) { if (IsSingleLineTextControl(true)) {
nsAutoString value; nsAutoString value;
GetValue(value); GetValue(value, CallerType::System);
SetDirectionalityFromValue(this, value, aNotify); SetDirectionalityFromValue(this, value, aNotify);
} }
} else { } else {
@ -6618,31 +6618,11 @@ HTMLInputElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission)
return NS_OK; return NS_OK;
} }
//
// Submit name=value
//
// If name not there, don't submit // If name not there, don't submit
if (name.IsEmpty()) { if (name.IsEmpty()) {
return NS_OK; return NS_OK;
} }
// Get the value
nsAutoString value;
nsresult rv = GetValue(value);
if (NS_FAILED(rv)) {
return rv;
}
if (mType == NS_FORM_INPUT_SUBMIT && value.IsEmpty() &&
!HasAttr(kNameSpaceID_None, nsGkAtoms::value)) {
// Get our default value, which is the same as our default label
nsXPIDLString defaultValue;
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
"Submit", defaultValue);
value = defaultValue;
}
// //
// Submit file if its input type=file and this encoding method accepts files // Submit file if its input type=file and this encoding method accepts files
// //
@ -6675,6 +6655,24 @@ HTMLInputElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission)
return aFormSubmission->AddNameValuePair(name, return aFormSubmission->AddNameValuePair(name,
NS_ConvertASCIItoUTF16(charset)); NS_ConvertASCIItoUTF16(charset));
} }
//
// Submit name=value
//
// Get the value
nsAutoString value;
GetValue(value, CallerType::System);
if (mType == NS_FORM_INPUT_SUBMIT && value.IsEmpty() &&
!HasAttr(kNameSpaceID_None, nsGkAtoms::value)) {
// Get our default value, which is the same as our default label
nsXPIDLString defaultValue;
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
"Submit", defaultValue);
value = defaultValue;
}
if (IsSingleLineTextControl(true) && if (IsSingleLineTextControl(true) &&
name.EqualsLiteral("isindex") && name.EqualsLiteral("isindex") &&
aFormSubmission->SupportsIsindexSubmission()) { aFormSubmission->SupportsIsindexSubmission()) {
@ -6713,13 +6711,10 @@ HTMLInputElement::SaveState()
inputState = new HTMLInputElementState(); inputState = new HTMLInputElementState();
nsAutoString value; nsAutoString value;
nsresult rv = GetValue(value); GetValue(value, CallerType::System);
if (NS_FAILED(rv)) {
return rv;
}
if (!IsSingleLineTextControl(false)) { if (!IsSingleLineTextControl(false)) {
rv = nsLinebreakConverter::ConvertStringLineBreaks( nsresult rv = nsLinebreakConverter::ConvertStringLineBreaks(
value, value,
nsLinebreakConverter::eLinebreakPlatform, nsLinebreakConverter::eLinebreakPlatform,
nsLinebreakConverter::eLinebreakContent); nsLinebreakConverter::eLinebreakContent);
@ -6777,7 +6772,7 @@ HTMLInputElement::DoneCreatingElement()
// Sanitize the value. // Sanitize the value.
if (GetValueMode() == VALUE_MODE_VALUE) { if (GetValueMode() == VALUE_MODE_VALUE) {
nsAutoString aValue; nsAutoString aValue;
GetValue(aValue); GetValue(aValue, CallerType::System);
// TODO: What should we do if SetValueInternal fails? (The allocation // TODO: What should we do if SetValueInternal fails? (The allocation
// may potentially be big, but most likely we've failed to allocate // may potentially be big, but most likely we've failed to allocate
// before the type change.) // before the type change.)
@ -7455,10 +7450,7 @@ HTMLInputElement::IsTooLong()
return false; return false;
} }
int32_t textLength = -1; return InputTextLength(CallerType::System) > maxLength;
GetTextLength(&textLength);
return textLength > maxLength;
} }
bool bool
@ -7478,8 +7470,7 @@ HTMLInputElement::IsTooShort()
return false; return false;
} }
int32_t textLength = -1; int32_t textLength = InputTextLength(CallerType::System);
GetTextLength(&textLength);
return textLength && textLength < minLength; return textLength && textLength < minLength;
} }
@ -7525,7 +7516,7 @@ HTMLInputElement::HasTypeMismatch() const
} }
nsAutoString value; nsAutoString value;
GetValueInternal(value); GetNonFileValueInternal(value);
if (value.IsEmpty()) { if (value.IsEmpty()) {
return false; return false;
@ -7568,7 +7559,7 @@ HTMLInputElement::HasPatternMismatch() const
GetAttr(kNameSpaceID_None, nsGkAtoms::pattern, pattern); GetAttr(kNameSpaceID_None, nsGkAtoms::pattern, pattern);
nsAutoString value; nsAutoString value;
GetValueInternal(value); GetNonFileValueInternal(value);
if (value.IsEmpty()) { if (value.IsEmpty()) {
return false; return false;
@ -7703,7 +7694,7 @@ HTMLInputElement::HasBadInput() const
{ {
if (mType == NS_FORM_INPUT_NUMBER) { if (mType == NS_FORM_INPUT_NUMBER) {
nsAutoString value; nsAutoString value;
GetValueInternal(value); GetNonFileValueInternal(value);
if (!value.IsEmpty()) { if (!value.IsEmpty()) {
// The input can't be bad, otherwise it would have been sanitized to the // The input can't be bad, otherwise it would have been sanitized to the
// empty string. // empty string.
@ -7727,7 +7718,7 @@ HTMLInputElement::HasBadInput() const
nsAutoString value; nsAutoString value;
nsAutoCString unused; nsAutoCString unused;
uint32_t unused2; uint32_t unused2;
GetValueInternal(value); GetNonFileValueInternal(value);
HTMLSplitOnSpacesTokenizer tokenizer(value, ','); HTMLSplitOnSpacesTokenizer tokenizer(value, ',');
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
if (!PunycodeEncodeEmailAddress(tokenizer.nextToken(), unused, &unused2)) { if (!PunycodeEncodeEmailAddress(tokenizer.nextToken(), unused, &unused2)) {
@ -7894,12 +7885,10 @@ HTMLInputElement::GetValidationMessage(nsAString& aValidationMessage,
{ {
nsXPIDLString message; nsXPIDLString message;
int32_t maxLength = MaxLength(); int32_t maxLength = MaxLength();
int32_t textLength = -1; int32_t textLength = InputTextLength(CallerType::System);
nsAutoString strMaxLength; nsAutoString strMaxLength;
nsAutoString strTextLength; nsAutoString strTextLength;
GetTextLength(&textLength);
strMaxLength.AppendInt(maxLength); strMaxLength.AppendInt(maxLength);
strTextLength.AppendInt(textLength); strTextLength.AppendInt(textLength);
@ -7914,12 +7903,10 @@ HTMLInputElement::GetValidationMessage(nsAString& aValidationMessage,
{ {
nsXPIDLString message; nsXPIDLString message;
int32_t minLength = MinLength(); int32_t minLength = MinLength();
int32_t textLength = -1; int32_t textLength = InputTextLength(CallerType::System);
nsAutoString strMinLength; nsAutoString strMinLength;
nsAutoString strTextLength; nsAutoString strTextLength;
GetTextLength(&textLength);
strMinLength.AppendInt(minLength); strMinLength.AppendInt(minLength);
strTextLength.AppendInt(textLength); strTextLength.AppendInt(textLength);

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

@ -663,11 +663,7 @@ public:
void SetValue(const nsAString& aValue, CallerType aCallerType, void SetValue(const nsAString& aValue, CallerType aCallerType,
ErrorResult& aRv); ErrorResult& aRv);
void GetValue(nsAString& aValue, CallerType aCallerType) void GetValue(nsAString& aValue, CallerType aCallerType);
{
// For now just ignore the caller type.
GetValue(aValue);
}
Nullable<Date> GetValueAsDate(ErrorResult& aRv); Nullable<Date> GetValueAsDate(ErrorResult& aRv);
@ -776,7 +772,7 @@ public:
nsIControllers* GetControllers(ErrorResult& aRv); nsIControllers* GetControllers(ErrorResult& aRv);
int32_t GetTextLength(ErrorResult& aRv); int32_t InputTextLength(CallerType aCallerType);
void MozGetFileNameArray(nsTArray<nsString>& aFileNames, ErrorResult& aRv); void MozGetFileNameArray(nsTArray<nsString>& aFileNames, ErrorResult& aRv);
@ -931,10 +927,17 @@ protected:
*/ */
nsresult SetValueInternal(const nsAString& aValue, uint32_t aFlags); nsresult SetValueInternal(const nsAString& aValue, uint32_t aFlags);
void GetValueInternal(nsAString& aValue) const; // Generic getter for the value that doesn't do experimental control type
// sanitization.
void GetValueInternal(nsAString& aValue, CallerType aCallerType) const;
// A getter for callers that know we're not dealing with a file input, so they
// don't have to think about the caller type.
void GetNonFileValueInternal(nsAString& aValue) const;
/** /**
* Returns whether the current value is the empty string. * Returns whether the current value is the empty string. This only makes
* sense for some input types; does NOT make sense for file inputs.
* *
* @return whether the current value is the empty string. * @return whether the current value is the empty string.
*/ */

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

@ -32,12 +32,12 @@ GetAsRadio(nsIContent* node)
} }
void void
RadioNodeList::GetValue(nsString& retval) RadioNodeList::GetValue(nsString& retval, CallerType aCallerType)
{ {
for (uint32_t i = 0; i < Length(); i++) { for (uint32_t i = 0; i < Length(); i++) {
HTMLInputElement* maybeRadio = GetAsRadio(Item(i)); HTMLInputElement* maybeRadio = GetAsRadio(Item(i));
if (maybeRadio && maybeRadio->Checked()) { if (maybeRadio && maybeRadio->Checked()) {
maybeRadio->GetValue(retval); maybeRadio->GetValue(retval, aCallerType);
return; return;
} }
} }
@ -45,7 +45,7 @@ RadioNodeList::GetValue(nsString& retval)
} }
void void
RadioNodeList::SetValue(const nsAString& value) RadioNodeList::SetValue(const nsAString& value, CallerType aCallerType)
{ {
for (uint32_t i = 0; i < Length(); i++) { for (uint32_t i = 0; i < Length(); i++) {
@ -55,7 +55,7 @@ RadioNodeList::SetValue(const nsAString& value)
} }
nsString curval = nsString(); nsString curval = nsString();
maybeRadio->GetValue(curval); maybeRadio->GetValue(curval, aCallerType);
if (curval.Equals(value)) { if (curval.Equals(value)) {
maybeRadio->SetChecked(true); maybeRadio->SetChecked(true);
return; return;

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

@ -10,6 +10,7 @@
#include "nsContentList.h" #include "nsContentList.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "HTMLFormElement.h" #include "HTMLFormElement.h"
#include "mozilla/dom/BindingDeclarations.h"
#define MOZILLA_DOM_RADIONODELIST_IMPLEMENTATION_IID \ #define MOZILLA_DOM_RADIONODELIST_IMPLEMENTATION_IID \
{ 0xbba7f3e8, 0xf3b5, 0x42e5, \ { 0xbba7f3e8, 0xf3b5, 0x42e5, \
@ -24,8 +25,8 @@ public:
explicit RadioNodeList(HTMLFormElement* aForm) : nsSimpleContentList(aForm) { } explicit RadioNodeList(HTMLFormElement* aForm) : nsSimpleContentList(aForm) { }
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override; virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
void GetValue(nsString& retval); void GetValue(nsString& retval, CallerType aCallerType);
void SetValue(const nsAString& value); void SetValue(const nsAString& value, CallerType aCallerType);
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_RADIONODELIST_IMPLEMENTATION_IID) NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_RADIONODELIST_IMPLEMENTATION_IID)

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

@ -68,7 +68,6 @@ interface nsIDOMHTMLInputElement : nsISupports
attribute DOMString type; attribute DOMString type;
attribute DOMString defaultValue; attribute DOMString defaultValue;
attribute DOMString value;
// valustAsDate is only supported via WebIDL, because it's intimately // valustAsDate is only supported via WebIDL, because it's intimately
// tied to JS Date objects and xpidl support for that sort of thing is // tied to JS Date objects and xpidl support for that sort of thing is
// terrible. // terrible.
@ -93,7 +92,6 @@ interface nsIDOMHTMLInputElement : nsISupports
attribute DOMString useMap; attribute DOMString useMap;
readonly attribute nsIControllers controllers; readonly attribute nsIControllers controllers;
readonly attribute long textLength;
/** /**
* This non-standard method prevents to check types manually to know if the * This non-standard method prevents to check types manually to know if the

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

@ -146,7 +146,8 @@ partial interface HTMLInputElement {
[GetterThrows, ChromeOnly] [GetterThrows, ChromeOnly]
readonly attribute nsIControllers controllers; readonly attribute nsIControllers controllers;
[GetterThrows] // Binaryname because we have a FragmentOrElement function named "TextLength()".
[NeedsCallerType, BinaryName="inputTextLength"]
readonly attribute long textLength; readonly attribute long textLength;
[Throws, ChromeOnly] [Throws, ChromeOnly]

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

@ -12,5 +12,6 @@
*/ */
interface RadioNodeList : NodeList { interface RadioNodeList : NodeList {
[NeedsCallerType]
attribute DOMString value; attribute DOMString value;
}; };

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

@ -1201,7 +1201,8 @@ PersistNodeFixup::FixupNode(nsIDOMNode *aNodeIn,
return rv; return rv;
} }
nsCOMPtr<nsIDOMHTMLInputElement> nodeAsInput = do_QueryInterface(aNodeIn); RefPtr<dom::HTMLInputElement> nodeAsInput =
dom::HTMLInputElement::FromContentOrNull(content);
if (nodeAsInput) { if (nodeAsInput) {
rv = GetNodeToFixup(aNodeIn, aNodeOut); rv = GetNodeToFixup(aNodeIn, aNodeOut);
if (NS_SUCCEEDED(rv) && *aNodeOut) { if (NS_SUCCEEDED(rv) && *aNodeOut) {
@ -1232,7 +1233,7 @@ PersistNodeFixup::FixupNode(nsIDOMNode *aNodeIn,
case NS_FORM_INPUT_DATE: case NS_FORM_INPUT_DATE:
case NS_FORM_INPUT_TIME: case NS_FORM_INPUT_TIME:
case NS_FORM_INPUT_COLOR: case NS_FORM_INPUT_COLOR:
nodeAsInput->GetValue(valueStr); nodeAsInput->GetValue(valueStr, dom::CallerType::System);
// Avoid superfluous value="" serialization // Avoid superfluous value="" serialization
if (valueStr.IsEmpty()) if (valueStr.IsEmpty())
outElt->RemoveAttribute(valueAttr); outElt->RemoveAttribute(valueAttr);
@ -1241,9 +1242,10 @@ PersistNodeFixup::FixupNode(nsIDOMNode *aNodeIn,
break; break;
case NS_FORM_INPUT_CHECKBOX: case NS_FORM_INPUT_CHECKBOX:
case NS_FORM_INPUT_RADIO: case NS_FORM_INPUT_RADIO:
bool checked; {
nodeAsInput->GetChecked(&checked); bool checked = nodeAsInput->Checked();
outElt->SetDefaultChecked(checked); outElt->SetDefaultChecked(checked);
}
break; break;
default: default:
break; break;

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

@ -11,14 +11,16 @@
#include "nsCSSPseudoElements.h" #include "nsCSSPseudoElements.h"
#include "nsFormControlFrame.h" #include "nsFormControlFrame.h"
#include "nsGkAtoms.h" #include "nsGkAtoms.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMNode.h" #include "nsIDOMNode.h"
#include "nsIFormControl.h" #include "nsIFormControl.h"
#include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandle.h"
#include "mozilla/StyleSetHandleInlines.h" #include "mozilla/StyleSetHandleInlines.h"
#include "mozilla/dom/HTMLInputElement.h"
#include "nsIDocument.h" #include "nsIDocument.h"
using mozilla::dom::Element; using mozilla::dom::Element;
using mozilla::dom::HTMLInputElement;
using mozilla::dom::CallerType;
nsColorControlFrame::nsColorControlFrame(nsStyleContext* aContext) nsColorControlFrame::nsColorControlFrame(nsStyleContext* aContext)
: nsHTMLButtonControlFrame(aContext) : nsHTMLButtonControlFrame(aContext)
@ -100,8 +102,8 @@ nsColorControlFrame::UpdateColor()
// Get the color from the "value" property of our content; it will return the // Get the color from the "value" property of our content; it will return the
// default color (through the sanitization algorithm) if there is none. // default color (through the sanitization algorithm) if there is none.
nsAutoString color; nsAutoString color;
nsCOMPtr<nsIDOMHTMLInputElement> elt = do_QueryInterface(mContent); HTMLInputElement* elt = HTMLInputElement::FromContent(mContent);
elt->GetValue(color); elt->GetValue(color, CallerType::System);
MOZ_ASSERT(!color.IsEmpty(), MOZ_ASSERT(!color.IsEmpty(),
"Content node's GetValue() should return a valid color string " "Content node's GetValue() should return a valid color string "
"(the default color, in case no valid color is set)"); "(the default color, in case no valid color is set)");

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

@ -8,6 +8,7 @@
#include "nsGkAtoms.h" #include "nsGkAtoms.h"
#include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandle.h"
#include "mozilla/StyleSetHandleInlines.h" #include "mozilla/StyleSetHandleInlines.h"
#include "mozilla/dom/HTMLInputElement.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
// MouseEvent suppression in PP // MouseEvent suppression in PP
#include "nsContentList.h" #include "nsContentList.h"
@ -139,19 +140,18 @@ nsGfxButtonControlFrame::GetLabel(nsXPIDLString& aLabel)
{ {
// Get the text from the "value" property on our content if there is // Get the text from the "value" property on our content if there is
// one; otherwise set it to a default value (localized). // one; otherwise set it to a default value (localized).
nsresult rv; dom::HTMLInputElement* elt = dom::HTMLInputElement::FromContent(mContent);
nsCOMPtr<nsIDOMHTMLInputElement> elt = do_QueryInterface(mContent);
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::value) && elt) { if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::value) && elt) {
rv = elt->GetValue(aLabel); elt->GetValue(aLabel, dom::CallerType::System);
} else { } else {
// Generate localized label. // Generate localized label.
// We can't make any assumption as to what the default would be // We can't make any assumption as to what the default would be
// because the value is localized for non-english platforms, thus // because the value is localized for non-english platforms, thus
// it might not be the string "Reset", "Submit Query", or "Browse..." // it might not be the string "Reset", "Submit Query", or "Browse..."
nsresult rv;
rv = GetDefaultLabel(aLabel); rv = GetDefaultLabel(aLabel);
}
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
}
// Compress whitespace out of label if needed. // Compress whitespace out of label if needed.
if (!StyleText()->WhiteSpaceIsSignificant()) { if (!StyleText()->WhiteSpaceIsSignificant()) {

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

@ -404,7 +404,7 @@ nsNumberControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
// Initialize the text field value: // Initialize the text field value:
nsAutoString value; nsAutoString value;
content->GetValue(value); content->GetValue(value, CallerType::System);
SetValueOfAnonTextControl(value); SetValueOfAnonTextControl(value);
// If we're readonly, make sure our anonymous text control is too: // If we're readonly, make sure our anonymous text control is too:
@ -709,7 +709,7 @@ nsNumberControlFrame::GetValueOfAnonTextControl(nsAString& aValue)
return; return;
} }
HTMLInputElement::FromContent(mTextField)->GetValue(aValue); HTMLInputElement::FromContent(mTextField)->GetValue(aValue, CallerType::System);
#ifdef ENABLE_INTL_API #ifdef ENABLE_INTL_API
// Here we need to de-localize any number typed in by the user. That is, we // Here we need to de-localize any number typed in by the user. That is, we
@ -762,7 +762,7 @@ nsNumberControlFrame::AnonTextControlIsEmpty()
return true; return true;
} }
nsAutoString value; nsAutoString value;
HTMLInputElement::FromContent(mTextField)->GetValue(value); HTMLInputElement::FromContent(mTextField)->GetValue(value, CallerType::System);
return value.IsEmpty(); return value.IsEmpty();
} }

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

@ -8,6 +8,7 @@
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent() #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
#include "mozilla/dom/HTMLInputElement.h"
#include "nsIFormAutoComplete.h" #include "nsIFormAutoComplete.h"
#include "nsIInputListAutoComplete.h" #include "nsIInputListAutoComplete.h"
#include "nsIAutoCompleteSimpleResult.h" #include "nsIAutoCompleteSimpleResult.h"
@ -502,7 +503,9 @@ NS_IMETHODIMP
nsFormFillController::GetTextValue(nsAString & aTextValue) nsFormFillController::GetTextValue(nsAString & aTextValue)
{ {
if (mFocusedInput) { if (mFocusedInput) {
mFocusedInput->GetValue(aTextValue); nsCOMPtr<nsIContent> content = do_QueryInterface(mFocusedInput);
HTMLInputElement::FromContent(content)->GetValue(aTextValue,
CallerType::System);
} else { } else {
aTextValue.Truncate(); aTextValue.Truncate();
} }