зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
a59a621bb6
Коммит
62e08b6904
|
@ -351,8 +351,11 @@ HTMLTextFieldAccessible::Value(nsString& aValue)
|
|||
}
|
||||
|
||||
HTMLInputElement* input = HTMLInputElement::FromContent(mContent);
|
||||
if (input)
|
||||
input->GetValue(aValue);
|
||||
if (input) {
|
||||
// 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
|
||||
|
@ -552,7 +555,10 @@ HTMLSpinnerAccessible::Value(nsString& aValue)
|
|||
if (!aValue.IsEmpty())
|
||||
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
|
||||
|
@ -628,7 +634,10 @@ HTMLRangeAccessible::Value(nsString& aValue)
|
|||
if (!aValue.IsEmpty())
|
||||
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
|
||||
|
|
|
@ -691,7 +691,7 @@ nsColorPickerShownCallback::UpdateInternal(const nsAString& aColor,
|
|||
if (aTrustedUpdate) {
|
||||
valueChanged = true;
|
||||
} else {
|
||||
mInput->GetValue(oldValue);
|
||||
mInput->GetValue(oldValue, CallerType::System);
|
||||
}
|
||||
|
||||
IgnoredErrorResult rv;
|
||||
|
@ -699,7 +699,7 @@ nsColorPickerShownCallback::UpdateInternal(const nsAString& aColor,
|
|||
|
||||
if (!aTrustedUpdate) {
|
||||
nsAutoString newValue;
|
||||
mInput->GetValue(newValue);
|
||||
mInput->GetValue(newValue, CallerType::System);
|
||||
if (!oldValue.Equals(newValue)) {
|
||||
valueChanged = true;
|
||||
}
|
||||
|
@ -785,7 +785,7 @@ DatePickerShownCallback::Done(const nsAString& aDate)
|
|||
nsAutoString oldValue;
|
||||
|
||||
mInput->PickerClosed();
|
||||
mInput->GetValue(oldValue);
|
||||
mInput->GetValue(oldValue, CallerType::System);
|
||||
|
||||
if(!oldValue.Equals(aDate)){
|
||||
IgnoredErrorResult rv;
|
||||
|
@ -866,7 +866,7 @@ HTMLInputElement::InitDatePicker()
|
|||
}
|
||||
|
||||
nsAutoString initialValue;
|
||||
GetValueInternal(initialValue);
|
||||
GetNonFileValueInternal(initialValue);
|
||||
rv = datePicker->Init(win, title, initialValue);
|
||||
|
||||
nsCOMPtr<nsIDatePickerShownCallback> callback =
|
||||
|
@ -911,7 +911,7 @@ HTMLInputElement::InitColorPicker()
|
|||
}
|
||||
|
||||
nsAutoString initialValue;
|
||||
GetValueInternal(initialValue);
|
||||
GetNonFileValueInternal(initialValue);
|
||||
nsresult rv = colorPicker->Init(win, title, initialValue);
|
||||
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
|
||||
// the clone.
|
||||
nsAutoString value;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
// SetValueInternal handles setting the VALUE_CHANGED bit for us
|
||||
rv = it->SetValueInternal(value, nsTextEditorState::eSetValue_Notify);
|
||||
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,
|
||||
// if @max in the example above were to change from 1 to -1.
|
||||
nsAutoString value;
|
||||
GetValue(value);
|
||||
GetNonFileValueInternal(value);
|
||||
nsresult rv =
|
||||
SetValueInternal(value, nsTextEditorState::eSetValue_Internal);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -1538,7 +1538,7 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|||
if (mType == NS_FORM_INPUT_RANGE) {
|
||||
// See @max comment
|
||||
nsAutoString value;
|
||||
GetValue(value);
|
||||
GetNonFileValueInternal(value);
|
||||
nsresult rv =
|
||||
SetValueInternal(value, nsTextEditorState::eSetValue_Internal);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -1554,7 +1554,7 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|||
if (mType == NS_FORM_INPUT_RANGE) {
|
||||
// See @max comment
|
||||
nsAutoString value;
|
||||
GetValue(value);
|
||||
GetNonFileValueInternal(value);
|
||||
nsresult rv =
|
||||
SetValueInternal(value, nsTextEditorState::eSetValue_Internal);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -1572,7 +1572,7 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|||
if (mType == NS_FORM_INPUT_NUMBER) {
|
||||
// Update the value that is displayed to the user to the new locale:
|
||||
nsAutoString value;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
nsNumberControlFrame* numberControlFrame =
|
||||
do_QueryFrame(GetPrimaryFrame());
|
||||
if (numberControlFrame) {
|
||||
|
@ -1754,22 +1754,41 @@ HTMLInputElement::SetWidth(uint32_t aWidth)
|
|||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLInputElement::GetValue(nsAString& aValue)
|
||||
void
|
||||
HTMLInputElement::GetValue(nsAString& aValue, CallerType aCallerType)
|
||||
{
|
||||
GetValueInternal(aValue);
|
||||
GetValueInternal(aValue, aCallerType);
|
||||
|
||||
// Don't return non-sanitized value for types that are experimental on mobile
|
||||
// or datetime types
|
||||
if (IsExperimentalMobileType(mType) || IsDateTimeInputType(mType)) {
|
||||
SanitizeValue(aValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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()) {
|
||||
case VALUE_MODE_VALUE:
|
||||
|
@ -1781,17 +1800,9 @@ HTMLInputElement::GetValueInternal(nsAString& aValue) const
|
|||
return;
|
||||
|
||||
case VALUE_MODE_FILENAME:
|
||||
if (nsContentUtils::LegacyIsCallerChromeOrNativeCode()) {
|
||||
aValue.Assign(mFirstFilePath);
|
||||
} else {
|
||||
// Just return the leaf name
|
||||
if (mFilesOrDirectories.IsEmpty()) {
|
||||
aValue.Truncate();
|
||||
} else {
|
||||
GetDOMFileOrDirectoryName(mFilesOrDirectories[0], aValue);
|
||||
}
|
||||
}
|
||||
|
||||
NS_NOTREACHED("Someone screwed up here");
|
||||
// We'll just return empty string if someone does screw up.
|
||||
aValue.Truncate();
|
||||
return;
|
||||
|
||||
case VALUE_MODE_DEFAULT:
|
||||
|
@ -1812,7 +1823,7 @@ bool
|
|||
HTMLInputElement::IsValueEmpty() const
|
||||
{
|
||||
nsAutoString value;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
|
||||
return value.IsEmpty();
|
||||
}
|
||||
|
@ -1933,7 +1944,7 @@ HTMLInputElement::GetValueAsDecimal() const
|
|||
Decimal decimalValue;
|
||||
nsAutoString stringValue;
|
||||
|
||||
GetValueInternal(stringValue);
|
||||
GetNonFileValueInternal(stringValue);
|
||||
|
||||
return !ConvertStringToNumber(stringValue, decimalValue) ? Decimal::nan()
|
||||
: decimalValue;
|
||||
|
@ -1976,7 +1987,7 @@ HTMLInputElement::SetValue(const nsAString& aValue, CallerType aCallerType,
|
|||
// NOTE: this is currently quite expensive work (too much string
|
||||
// manipulation). We should probably optimize that.
|
||||
nsAutoString currentValue;
|
||||
GetValue(currentValue);
|
||||
GetValue(currentValue, aCallerType);
|
||||
|
||||
nsresult rv =
|
||||
SetValueInternal(aValue, nsTextEditorState::eSetValue_ByContent |
|
||||
|
@ -1987,7 +1998,7 @@ HTMLInputElement::SetValue(const nsAString& aValue, CallerType aCallerType,
|
|||
}
|
||||
|
||||
if (mFocusedValue.Equals(currentValue)) {
|
||||
GetValue(mFocusedValue);
|
||||
GetValue(mFocusedValue, aCallerType);
|
||||
}
|
||||
} else {
|
||||
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*
|
||||
HTMLInputElement::GetList() const
|
||||
{
|
||||
|
@ -2207,7 +2211,7 @@ HTMLInputElement::GetValueAsDate(ErrorResult& aRv)
|
|||
{
|
||||
uint32_t year, month, day;
|
||||
nsAutoString value;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
if (!ParseDate(value, &year, &month, &day)) {
|
||||
return Nullable<Date>();
|
||||
}
|
||||
|
@ -2219,7 +2223,7 @@ HTMLInputElement::GetValueAsDate(ErrorResult& aRv)
|
|||
{
|
||||
uint32_t millisecond;
|
||||
nsAutoString value;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
if (!ParseTime(value, &millisecond)) {
|
||||
return Nullable<Date>();
|
||||
}
|
||||
|
@ -2234,7 +2238,7 @@ HTMLInputElement::GetValueAsDate(ErrorResult& aRv)
|
|||
{
|
||||
uint32_t year, month;
|
||||
nsAutoString value;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
if (!ParseMonth(value, &year, &month)) {
|
||||
return Nullable<Date>();
|
||||
}
|
||||
|
@ -2246,7 +2250,7 @@ HTMLInputElement::GetValueAsDate(ErrorResult& aRv)
|
|||
{
|
||||
uint32_t year, week;
|
||||
nsAutoString value;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
if (!ParseWeek(value, &year, &week)) {
|
||||
return Nullable<Date>();
|
||||
}
|
||||
|
@ -3091,8 +3095,10 @@ HTMLInputElement::AfterSetFilesOrDirectories(bool aSetValueChanged)
|
|||
void
|
||||
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;
|
||||
GetValue(value);
|
||||
GetValue(value, CallerType::System);
|
||||
|
||||
if (!MayFireChangeOnBlur() || mFocusedValue.Equals(value)) {
|
||||
return;
|
||||
|
@ -3859,7 +3865,7 @@ HTMLInputElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
|||
// StartRangeThumbDrag already set mFocusedValue on 'mousedown' before
|
||||
// we get the 'focus' event.
|
||||
!mIsDraggingRange) {
|
||||
GetValue(mFocusedValue);
|
||||
GetValue(mFocusedValue, CallerType::System);
|
||||
}
|
||||
|
||||
// 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.
|
||||
if (IsExperimentalMobileType(mType)) {
|
||||
nsAutoString aValue;
|
||||
GetValueInternal(aValue);
|
||||
GetNonFileValueInternal(aValue);
|
||||
nsresult rv =
|
||||
SetValueInternal(aValue, nsTextEditorState::eSetValue_Internal);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -4050,7 +4056,7 @@ HTMLInputElement::StartRangeThumbDrag(WidgetGUIEvent* aEvent)
|
|||
// 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
|
||||
// have changed it by then).
|
||||
GetValue(mFocusedValue);
|
||||
GetValue(mFocusedValue, CallerType::System);
|
||||
|
||||
SetValueOfRangeForUserEvent(rangeFrame->GetValueAtEventPoint(aEvent));
|
||||
}
|
||||
|
@ -5031,7 +5037,9 @@ HTMLInputElement::HandleTypeChange(uint8_t aNewType)
|
|||
nsAutoString aOldValue;
|
||||
|
||||
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;
|
||||
|
@ -5096,7 +5104,7 @@ HTMLInputElement::HandleTypeChange(uint8_t aNewType)
|
|||
// Otherwise, if the new type doesn't fire a change event on blur, but the
|
||||
// previous type does, we should clear out mFocusedValue.
|
||||
if (MayFireChangeOnBlur(mType) && !MayFireChangeOnBlur(oldType)) {
|
||||
GetValue(mFocusedValue);
|
||||
GetValue(mFocusedValue, CallerType::System);
|
||||
} else if (!IsSingleLineTextControl(false, mType) &&
|
||||
IsSingleLineTextControl(false, oldType)) {
|
||||
mFocusedValue.Truncate();
|
||||
|
@ -6010,21 +6018,13 @@ HTMLInputElement::GetControllers(nsIControllers** aResult)
|
|||
}
|
||||
|
||||
int32_t
|
||||
HTMLInputElement::GetTextLength(ErrorResult& aRv)
|
||||
HTMLInputElement::InputTextLength(CallerType aCallerType)
|
||||
{
|
||||
nsAutoString val;
|
||||
GetValue(val);
|
||||
GetValue(val, aCallerType);
|
||||
return val.Length();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLInputElement::GetTextLength(int32_t* aTextLength)
|
||||
{
|
||||
ErrorResult rv;
|
||||
*aTextLength = GetTextLength(rv);
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
void
|
||||
HTMLInputElement::SetSelectionRange(int32_t aSelectionStart,
|
||||
int32_t aSelectionEnd,
|
||||
|
@ -6114,7 +6114,7 @@ HTMLInputElement::SetRangeText(const nsAString& aReplacement, uint32_t aStart,
|
|||
}
|
||||
|
||||
nsAutoString value;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
uint32_t inputValueLength = value.Length();
|
||||
|
||||
if (aStart > inputValueLength) {
|
||||
|
@ -6535,7 +6535,7 @@ HTMLInputElement::SetDirectionIfAuto(bool aAuto, bool aNotify)
|
|||
SetHasDirAuto();
|
||||
if (IsSingleLineTextControl(true)) {
|
||||
nsAutoString value;
|
||||
GetValue(value);
|
||||
GetValue(value, CallerType::System);
|
||||
SetDirectionalityFromValue(this, value, aNotify);
|
||||
}
|
||||
} else {
|
||||
|
@ -6618,31 +6618,11 @@ HTMLInputElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// Submit name=value
|
||||
//
|
||||
|
||||
// If name not there, don't submit
|
||||
if (name.IsEmpty()) {
|
||||
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
|
||||
//
|
||||
|
@ -6675,6 +6655,24 @@ HTMLInputElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission)
|
|||
return aFormSubmission->AddNameValuePair(name,
|
||||
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) &&
|
||||
name.EqualsLiteral("isindex") &&
|
||||
aFormSubmission->SupportsIsindexSubmission()) {
|
||||
|
@ -6713,13 +6711,10 @@ HTMLInputElement::SaveState()
|
|||
|
||||
inputState = new HTMLInputElementState();
|
||||
nsAutoString value;
|
||||
nsresult rv = GetValue(value);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
GetValue(value, CallerType::System);
|
||||
|
||||
if (!IsSingleLineTextControl(false)) {
|
||||
rv = nsLinebreakConverter::ConvertStringLineBreaks(
|
||||
nsresult rv = nsLinebreakConverter::ConvertStringLineBreaks(
|
||||
value,
|
||||
nsLinebreakConverter::eLinebreakPlatform,
|
||||
nsLinebreakConverter::eLinebreakContent);
|
||||
|
@ -6777,7 +6772,7 @@ HTMLInputElement::DoneCreatingElement()
|
|||
// Sanitize the value.
|
||||
if (GetValueMode() == VALUE_MODE_VALUE) {
|
||||
nsAutoString aValue;
|
||||
GetValue(aValue);
|
||||
GetValue(aValue, CallerType::System);
|
||||
// TODO: What should we do if SetValueInternal fails? (The allocation
|
||||
// may potentially be big, but most likely we've failed to allocate
|
||||
// before the type change.)
|
||||
|
@ -7455,10 +7450,7 @@ HTMLInputElement::IsTooLong()
|
|||
return false;
|
||||
}
|
||||
|
||||
int32_t textLength = -1;
|
||||
GetTextLength(&textLength);
|
||||
|
||||
return textLength > maxLength;
|
||||
return InputTextLength(CallerType::System) > maxLength;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -7478,8 +7470,7 @@ HTMLInputElement::IsTooShort()
|
|||
return false;
|
||||
}
|
||||
|
||||
int32_t textLength = -1;
|
||||
GetTextLength(&textLength);
|
||||
int32_t textLength = InputTextLength(CallerType::System);
|
||||
|
||||
return textLength && textLength < minLength;
|
||||
}
|
||||
|
@ -7525,7 +7516,7 @@ HTMLInputElement::HasTypeMismatch() const
|
|||
}
|
||||
|
||||
nsAutoString value;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
|
||||
if (value.IsEmpty()) {
|
||||
return false;
|
||||
|
@ -7568,7 +7559,7 @@ HTMLInputElement::HasPatternMismatch() const
|
|||
GetAttr(kNameSpaceID_None, nsGkAtoms::pattern, pattern);
|
||||
|
||||
nsAutoString value;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
|
||||
if (value.IsEmpty()) {
|
||||
return false;
|
||||
|
@ -7703,7 +7694,7 @@ HTMLInputElement::HasBadInput() const
|
|||
{
|
||||
if (mType == NS_FORM_INPUT_NUMBER) {
|
||||
nsAutoString value;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
if (!value.IsEmpty()) {
|
||||
// The input can't be bad, otherwise it would have been sanitized to the
|
||||
// empty string.
|
||||
|
@ -7727,7 +7718,7 @@ HTMLInputElement::HasBadInput() const
|
|||
nsAutoString value;
|
||||
nsAutoCString unused;
|
||||
uint32_t unused2;
|
||||
GetValueInternal(value);
|
||||
GetNonFileValueInternal(value);
|
||||
HTMLSplitOnSpacesTokenizer tokenizer(value, ',');
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
if (!PunycodeEncodeEmailAddress(tokenizer.nextToken(), unused, &unused2)) {
|
||||
|
@ -7894,12 +7885,10 @@ HTMLInputElement::GetValidationMessage(nsAString& aValidationMessage,
|
|||
{
|
||||
nsXPIDLString message;
|
||||
int32_t maxLength = MaxLength();
|
||||
int32_t textLength = -1;
|
||||
int32_t textLength = InputTextLength(CallerType::System);
|
||||
nsAutoString strMaxLength;
|
||||
nsAutoString strTextLength;
|
||||
|
||||
GetTextLength(&textLength);
|
||||
|
||||
strMaxLength.AppendInt(maxLength);
|
||||
strTextLength.AppendInt(textLength);
|
||||
|
||||
|
@ -7914,12 +7903,10 @@ HTMLInputElement::GetValidationMessage(nsAString& aValidationMessage,
|
|||
{
|
||||
nsXPIDLString message;
|
||||
int32_t minLength = MinLength();
|
||||
int32_t textLength = -1;
|
||||
int32_t textLength = InputTextLength(CallerType::System);
|
||||
nsAutoString strMinLength;
|
||||
nsAutoString strTextLength;
|
||||
|
||||
GetTextLength(&textLength);
|
||||
|
||||
strMinLength.AppendInt(minLength);
|
||||
strTextLength.AppendInt(textLength);
|
||||
|
||||
|
|
|
@ -663,11 +663,7 @@ public:
|
|||
|
||||
void SetValue(const nsAString& aValue, CallerType aCallerType,
|
||||
ErrorResult& aRv);
|
||||
void GetValue(nsAString& aValue, CallerType aCallerType)
|
||||
{
|
||||
// For now just ignore the caller type.
|
||||
GetValue(aValue);
|
||||
}
|
||||
void GetValue(nsAString& aValue, CallerType aCallerType);
|
||||
|
||||
Nullable<Date> GetValueAsDate(ErrorResult& aRv);
|
||||
|
||||
|
@ -776,7 +772,7 @@ public:
|
|||
|
||||
nsIControllers* GetControllers(ErrorResult& aRv);
|
||||
|
||||
int32_t GetTextLength(ErrorResult& aRv);
|
||||
int32_t InputTextLength(CallerType aCallerType);
|
||||
|
||||
void MozGetFileNameArray(nsTArray<nsString>& aFileNames, ErrorResult& aRv);
|
||||
|
||||
|
@ -931,10 +927,17 @@ protected:
|
|||
*/
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -32,12 +32,12 @@ GetAsRadio(nsIContent* node)
|
|||
}
|
||||
|
||||
void
|
||||
RadioNodeList::GetValue(nsString& retval)
|
||||
RadioNodeList::GetValue(nsString& retval, CallerType aCallerType)
|
||||
{
|
||||
for (uint32_t i = 0; i < Length(); i++) {
|
||||
HTMLInputElement* maybeRadio = GetAsRadio(Item(i));
|
||||
if (maybeRadio && maybeRadio->Checked()) {
|
||||
maybeRadio->GetValue(retval);
|
||||
maybeRadio->GetValue(retval, aCallerType);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ RadioNodeList::GetValue(nsString& retval)
|
|||
}
|
||||
|
||||
void
|
||||
RadioNodeList::SetValue(const nsAString& value)
|
||||
RadioNodeList::SetValue(const nsAString& value, CallerType aCallerType)
|
||||
{
|
||||
for (uint32_t i = 0; i < Length(); i++) {
|
||||
|
||||
|
@ -55,7 +55,7 @@ RadioNodeList::SetValue(const nsAString& value)
|
|||
}
|
||||
|
||||
nsString curval = nsString();
|
||||
maybeRadio->GetValue(curval);
|
||||
maybeRadio->GetValue(curval, aCallerType);
|
||||
if (curval.Equals(value)) {
|
||||
maybeRadio->SetChecked(true);
|
||||
return;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "nsContentList.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "HTMLFormElement.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
|
||||
#define MOZILLA_DOM_RADIONODELIST_IMPLEMENTATION_IID \
|
||||
{ 0xbba7f3e8, 0xf3b5, 0x42e5, \
|
||||
|
@ -24,8 +25,8 @@ public:
|
|||
explicit RadioNodeList(HTMLFormElement* aForm) : nsSimpleContentList(aForm) { }
|
||||
|
||||
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
void GetValue(nsString& retval);
|
||||
void SetValue(const nsAString& value);
|
||||
void GetValue(nsString& retval, CallerType aCallerType);
|
||||
void SetValue(const nsAString& value, CallerType aCallerType);
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_RADIONODELIST_IMPLEMENTATION_IID)
|
||||
|
|
|
@ -68,7 +68,6 @@ interface nsIDOMHTMLInputElement : nsISupports
|
|||
|
||||
attribute DOMString type;
|
||||
attribute DOMString defaultValue;
|
||||
attribute DOMString value;
|
||||
// valustAsDate is only supported via WebIDL, because it's intimately
|
||||
// tied to JS Date objects and xpidl support for that sort of thing is
|
||||
// terrible.
|
||||
|
@ -93,7 +92,6 @@ interface nsIDOMHTMLInputElement : nsISupports
|
|||
|
||||
attribute DOMString useMap;
|
||||
readonly attribute nsIControllers controllers;
|
||||
readonly attribute long textLength;
|
||||
|
||||
/**
|
||||
* This non-standard method prevents to check types manually to know if the
|
||||
|
|
|
@ -146,7 +146,8 @@ partial interface HTMLInputElement {
|
|||
|
||||
[GetterThrows, ChromeOnly]
|
||||
readonly attribute nsIControllers controllers;
|
||||
[GetterThrows]
|
||||
// Binaryname because we have a FragmentOrElement function named "TextLength()".
|
||||
[NeedsCallerType, BinaryName="inputTextLength"]
|
||||
readonly attribute long textLength;
|
||||
|
||||
[Throws, ChromeOnly]
|
||||
|
|
|
@ -12,5 +12,6 @@
|
|||
*/
|
||||
|
||||
interface RadioNodeList : NodeList {
|
||||
[NeedsCallerType]
|
||||
attribute DOMString value;
|
||||
};
|
||||
|
|
|
@ -1201,7 +1201,8 @@ PersistNodeFixup::FixupNode(nsIDOMNode *aNodeIn,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> nodeAsInput = do_QueryInterface(aNodeIn);
|
||||
RefPtr<dom::HTMLInputElement> nodeAsInput =
|
||||
dom::HTMLInputElement::FromContentOrNull(content);
|
||||
if (nodeAsInput) {
|
||||
rv = GetNodeToFixup(aNodeIn, aNodeOut);
|
||||
if (NS_SUCCEEDED(rv) && *aNodeOut) {
|
||||
|
@ -1232,7 +1233,7 @@ PersistNodeFixup::FixupNode(nsIDOMNode *aNodeIn,
|
|||
case NS_FORM_INPUT_DATE:
|
||||
case NS_FORM_INPUT_TIME:
|
||||
case NS_FORM_INPUT_COLOR:
|
||||
nodeAsInput->GetValue(valueStr);
|
||||
nodeAsInput->GetValue(valueStr, dom::CallerType::System);
|
||||
// Avoid superfluous value="" serialization
|
||||
if (valueStr.IsEmpty())
|
||||
outElt->RemoveAttribute(valueAttr);
|
||||
|
@ -1241,9 +1242,10 @@ PersistNodeFixup::FixupNode(nsIDOMNode *aNodeIn,
|
|||
break;
|
||||
case NS_FORM_INPUT_CHECKBOX:
|
||||
case NS_FORM_INPUT_RADIO:
|
||||
bool checked;
|
||||
nodeAsInput->GetChecked(&checked);
|
||||
outElt->SetDefaultChecked(checked);
|
||||
{
|
||||
bool checked = nodeAsInput->Checked();
|
||||
outElt->SetDefaultChecked(checked);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -11,14 +11,16 @@
|
|||
#include "nsCSSPseudoElements.h"
|
||||
#include "nsFormControlFrame.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsIDOMHTMLInputElement.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIFormControl.h"
|
||||
#include "mozilla/StyleSetHandle.h"
|
||||
#include "mozilla/StyleSetHandleInlines.h"
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
#include "nsIDocument.h"
|
||||
|
||||
using mozilla::dom::Element;
|
||||
using mozilla::dom::HTMLInputElement;
|
||||
using mozilla::dom::CallerType;
|
||||
|
||||
nsColorControlFrame::nsColorControlFrame(nsStyleContext* aContext)
|
||||
: nsHTMLButtonControlFrame(aContext)
|
||||
|
@ -100,8 +102,8 @@ nsColorControlFrame::UpdateColor()
|
|||
// Get the color from the "value" property of our content; it will return the
|
||||
// default color (through the sanitization algorithm) if there is none.
|
||||
nsAutoString color;
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> elt = do_QueryInterface(mContent);
|
||||
elt->GetValue(color);
|
||||
HTMLInputElement* elt = HTMLInputElement::FromContent(mContent);
|
||||
elt->GetValue(color, CallerType::System);
|
||||
MOZ_ASSERT(!color.IsEmpty(),
|
||||
"Content node's GetValue() should return a valid color string "
|
||||
"(the default color, in case no valid color is set)");
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "nsGkAtoms.h"
|
||||
#include "mozilla/StyleSetHandle.h"
|
||||
#include "mozilla/StyleSetHandleInlines.h"
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
#include "nsContentUtils.h"
|
||||
// MouseEvent suppression in PP
|
||||
#include "nsContentList.h"
|
||||
|
@ -139,20 +140,19 @@ nsGfxButtonControlFrame::GetLabel(nsXPIDLString& aLabel)
|
|||
{
|
||||
// Get the text from the "value" property on our content if there is
|
||||
// one; otherwise set it to a default value (localized).
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> elt = do_QueryInterface(mContent);
|
||||
dom::HTMLInputElement* elt = dom::HTMLInputElement::FromContent(mContent);
|
||||
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::value) && elt) {
|
||||
rv = elt->GetValue(aLabel);
|
||||
elt->GetValue(aLabel, dom::CallerType::System);
|
||||
} else {
|
||||
// Generate localized label.
|
||||
// We can't make any assumption as to what the default would be
|
||||
// because the value is localized for non-english platforms, thus
|
||||
// it might not be the string "Reset", "Submit Query", or "Browse..."
|
||||
nsresult rv;
|
||||
rv = GetDefaultLabel(aLabel);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Compress whitespace out of label if needed.
|
||||
if (!StyleText()->WhiteSpaceIsSignificant()) {
|
||||
aLabel.CompressWhitespace();
|
||||
|
|
|
@ -404,7 +404,7 @@ nsNumberControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
|||
|
||||
// Initialize the text field value:
|
||||
nsAutoString value;
|
||||
content->GetValue(value);
|
||||
content->GetValue(value, CallerType::System);
|
||||
SetValueOfAnonTextControl(value);
|
||||
|
||||
// If we're readonly, make sure our anonymous text control is too:
|
||||
|
@ -709,7 +709,7 @@ nsNumberControlFrame::GetValueOfAnonTextControl(nsAString& aValue)
|
|||
return;
|
||||
}
|
||||
|
||||
HTMLInputElement::FromContent(mTextField)->GetValue(aValue);
|
||||
HTMLInputElement::FromContent(mTextField)->GetValue(aValue, CallerType::System);
|
||||
|
||||
#ifdef ENABLE_INTL_API
|
||||
// Here we need to de-localize any number typed in by the user. That is, we
|
||||
|
@ -762,7 +762,7 @@ nsNumberControlFrame::AnonTextControlIsEmpty()
|
|||
return true;
|
||||
}
|
||||
nsAutoString value;
|
||||
HTMLInputElement::FromContent(mTextField)->GetValue(value);
|
||||
HTMLInputElement::FromContent(mTextField)->GetValue(value, CallerType::System);
|
||||
return value.IsEmpty();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
#include "nsIFormAutoComplete.h"
|
||||
#include "nsIInputListAutoComplete.h"
|
||||
#include "nsIAutoCompleteSimpleResult.h"
|
||||
|
@ -502,7 +503,9 @@ NS_IMETHODIMP
|
|||
nsFormFillController::GetTextValue(nsAString & aTextValue)
|
||||
{
|
||||
if (mFocusedInput) {
|
||||
mFocusedInput->GetValue(aTextValue);
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(mFocusedInput);
|
||||
HTMLInputElement::FromContent(content)->GetValue(aTextValue,
|
||||
CallerType::System);
|
||||
} else {
|
||||
aTextValue.Truncate();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче