Changeset 63879 in webkit


Ignore:
Timestamp:
Jul 22, 2010 1:20:47 AM (14 years ago)
Author:
tkent@chromium.org
Message:

2010-07-22 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

Small refactoring for input value sanitization
https://bugs.webkit.org/show_bug.cgi?id=42807

Rename some functions to clarify their roles.

  • dom/InputElement.cpp: (WebCore::replaceEOLAndLimitLength): Renamed from sanitizeUserInputValue(). (WebCore::InputElement::sanitizeValueForTextField): Renamed from sanitizeValue(), and call replaceEOLAndLimitLength() instead of sanitizeUserInputValue(). (WebCore::InputElement::sanitizeUserInputValue): Just call replaceEOLAndLimitLength(). (WebCore::InputElement::updateValueIfNeeded): Use non-static sanitizeValue() for consistency.
  • dom/InputElement.h:
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::setInputType): Revert the change of r63876. It is not needed because of the updateValueIfNeeded() change. (WebCore::HTMLInputElement::sanitizeValue): Apply the sanitizeValue() renaming.
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63878 r63879  
     12010-07-22  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Small refactoring for input value sanitization
     6        https://bugs.webkit.org/show_bug.cgi?id=42807
     7
     8        Rename some functions to clarify their roles.
     9
     10        * dom/InputElement.cpp:
     11        (WebCore::replaceEOLAndLimitLength):
     12          Renamed from sanitizeUserInputValue().
     13        (WebCore::InputElement::sanitizeValueForTextField):
     14          Renamed from sanitizeValue(), and call replaceEOLAndLimitLength()
     15          instead of sanitizeUserInputValue().
     16        (WebCore::InputElement::sanitizeUserInputValue):
     17          Just call replaceEOLAndLimitLength().
     18        (WebCore::InputElement::updateValueIfNeeded):
     19          Use non-static sanitizeValue() for consistency.
     20        * dom/InputElement.h:
     21        * html/HTMLInputElement.cpp:
     22        (WebCore::HTMLInputElement::setInputType):
     23          Revert the change of r63876. It is not needed because of the
     24          updateValueIfNeeded() change.
     25        (WebCore::HTMLInputElement::sanitizeValue):
     26          Apply the sanitizeValue() renaming.
     27
    1282010-07-22  Tony Gentilcore  <tonyg@chromium.org>
    229
  • trunk/WebCore/dom/InputElement.cpp

    r59773 r63879  
    146146}
    147147
    148 String InputElement::sanitizeValue(const InputElement* inputElement, const String& proposedValue)
    149 {
    150 #if ENABLE(WCSS)
    151     InputElementData data = const_cast<InputElement*>(inputElement)->data();
    152     if (!isConformToInputMask(data, proposedValue)) {
    153         if (isConformToInputMask(data, data.value()))
    154             return data.value();
    155         return String();
    156     }
    157 #endif
    158     return InputElement::sanitizeUserInputValue(inputElement, proposedValue, s_maximumLength);
    159 }
    160 
    161 String InputElement::sanitizeUserInputValue(const InputElement* inputElement, const String& proposedValue, int maxLength)
     148static String replaceEOLAndLimitLength(const InputElement* inputElement, const String& proposedValue, int maxLength)
    162149{
    163150    if (!inputElement->isTextField())
     
    178165    }
    179166    return string.left(newLength);
     167}
     168
     169String InputElement::sanitizeValueForTextField(const InputElement* inputElement, const String& proposedValue)
     170{
     171#if ENABLE(WCSS)
     172    InputElementData data = const_cast<InputElement*>(inputElement)->data();
     173    if (!isConformToInputMask(data, proposedValue)) {
     174        if (isConformToInputMask(data, data.value()))
     175            return data.value();
     176        return String();
     177    }
     178#endif
     179    return replaceEOLAndLimitLength(inputElement, proposedValue, s_maximumLength);
     180}
     181
     182String InputElement::sanitizeUserInputValue(const InputElement* inputElement, const String& proposedValue, int maxLength)
     183{
     184    return replaceEOLAndLimitLength(inputElement, proposedValue, maxLength);
    180185}
    181186
     
    246251{
    247252    String oldValue = data.value();
    248     String newValue = sanitizeValue(inputElement, oldValue);
     253    String newValue = inputElement->sanitizeValue(oldValue);
    249254    if (newValue != oldValue)
    250255        inputElement->setValue(newValue);
  • trunk/WebCore/dom/InputElement.h

    r61752 r63879  
    7979    // Replaces CRs and LFs, shrinks the value for s_maximumLength.
    8080    // This should be applied to values from the HTML value attribute and the DOM value property.
    81     static String sanitizeValue(const InputElement*, const String&);
     81    // This function should be called only by sanitizeValue() implementations.
     82    static String sanitizeValueForTextField(const InputElement*, const String&);
    8283    // Replaces CRs and LFs, shrinks the value for the specified maximum length.
    8384    // This should be applied to values specified by users.
     85    // The input string may be a fragment of the whole value.
    8486    static String sanitizeUserInputValue(const InputElement*, const String&, int);
    8587    static void handleBeforeTextInsertedEvent(InputElementData&, InputElement*, Element*, Event*);
  • trunk/WebCore/html/HTMLInputElement.cpp

    r63876 r63879  
    864864            if (!didStoreValue && willStoreValue)
    865865                m_data.setValue(sanitizeValue(getAttribute(valueAttr)));
    866             else {
    867                 String oldValue = m_data.value();
    868                 String newValue = sanitizeValue(oldValue);
    869                 if (newValue != oldValue)
    870                     setValue(newValue);
    871             }
     866            else
     867                InputElement::updateValueIfNeeded(m_data, this);
    872868
    873869            if (wasPasswordField && !isPasswordField)
     
    25672563{
    25682564    if (isTextField())
    2569         return InputElement::sanitizeValue(this, proposedValue);
     2565        return InputElement::sanitizeValueForTextField(this, proposedValue);
    25702566
    25712567    // If the proposedValue is null than this is a reset scenario and we
Note: See TracChangeset for help on using the changeset viewer.