Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / components / autofill / content / renderer / form_autofill_util.cc
index 29b6009..10d6cca 100644 (file)
@@ -54,17 +54,6 @@ using blink::WebVector;
 namespace autofill {
 namespace {
 
-// A bit field mask for FillForm functions to not fill some fields.
-enum FieldFilterMask {
-  FILTER_NONE                       = 0,
-  FILTER_DISABLED_ELEMENTS          = 1 << 0,
-  FILTER_READONLY_ELEMENTS          = 1 << 1,
-  FILTER_NON_FOCUSABLE_ELEMENTS     = 1 << 2,
-  FILTER_ALL_NON_EDITIABLE_ELEMENTS = FILTER_DISABLED_ELEMENTS |
-                                      FILTER_READONLY_ELEMENTS |
-                                      FILTER_NON_FOCUSABLE_ELEMENTS,
-};
-
 bool IsOptionElement(const WebElement& element) {
   CR_DEFINE_STATIC_LOCAL(WebString, kOption, ("option"));
   return element.hasHTMLTagName(kOption);
@@ -476,7 +465,7 @@ typedef void (*Callback)(const FormFieldData&,
 void ForEachMatchingFormField(const WebFormElement& form_element,
                               const WebElement& initiating_element,
                               const FormData& data,
-                              FieldFilterMask filters,
+                              bool only_focusable_elements,
                               bool force_override,
                               Callback callback) {
   std::vector<WebFormControlElement> control_elements;
@@ -519,9 +508,8 @@ void ForEachMatchingFormField(const WebFormElement& form_element,
          !element->value().isEmpty()))
       continue;
 
-    if (((filters & FILTER_DISABLED_ELEMENTS) && !element->isEnabled()) ||
-        ((filters & FILTER_READONLY_ELEMENTS) && element->isReadOnly()) ||
-        ((filters & FILTER_NON_FOCUSABLE_ELEMENTS) && !element->isFocusable()))
+    if (!element->isEnabled() || element->isReadOnly() ||
+        (only_focusable_elements && !element->isFocusable()))
       continue;
 
     callback(data.fields[i], is_initiating_element, element);
@@ -540,8 +528,6 @@ void FillFormField(const FormFieldData& data,
   if (!data.is_autofilled)
     return;
 
-  field->setAutofilled(true);
-
   WebInputElement* input_element = toWebInputElement(field);
   if (IsCheckableElement(input_element)) {
     input_element->setChecked(data.is_checked, true);
@@ -555,6 +541,8 @@ void FillFormField(const FormFieldData& data,
     field->setValue(value, true);
   }
 
+  field->setAutofilled(true);
+
   if (is_initiating_node &&
       ((IsTextInput(input_element) || IsMonthInput(input_element)) ||
        IsTextAreaElement(*field))) {
@@ -642,28 +630,28 @@ const size_t kMaxParseableFields = 200;
 
 bool IsMonthInput(const WebInputElement* element) {
   CR_DEFINE_STATIC_LOCAL(WebString, kMonth, ("month"));
-  return element && element->formControlType() == kMonth;
+  return element && !element->isNull() && element->formControlType() == kMonth;
 }
 
 // All text fields, including password fields, should be extracted.
 bool IsTextInput(const WebInputElement* element) {
-  return element && element->isTextField();
+  return element && !element->isNull() && element->isTextField();
 }
 
 bool IsSelectElement(const WebFormControlElement& element) {
   // Static for improved performance.
   CR_DEFINE_STATIC_LOCAL(WebString, kSelectOne, ("select-one"));
-  return element.formControlType() == kSelectOne;
+  return !element.isNull() && element.formControlType() == kSelectOne;
 }
 
 bool IsTextAreaElement(const WebFormControlElement& element) {
   // Static for improved performance.
   CR_DEFINE_STATIC_LOCAL(WebString, kTextArea, ("textarea"));
-  return element.formControlType() == kTextArea;
+  return !element.isNull() && element.formControlType() == kTextArea;
 }
 
 bool IsCheckableElement(const WebInputElement* element) {
-  if (!element)
+  if (!element || element->isNull())
     return false;
 
   return element->isCheckbox() || element->isRadioButton();
@@ -1001,8 +989,8 @@ void FillForm(const FormData& form, const WebFormControlElement& element) {
   ForEachMatchingFormField(form_element,
                            element,
                            form,
-                           FILTER_ALL_NON_EDITIABLE_ELEMENTS,
-                           false, /* dont force override */
+                           true, /* only_focusable_elements */
+                           false, /* don't force override */
                            &FillFormField);
 }
 
@@ -1011,25 +999,10 @@ void FillFormIncludingNonFocusableElements(const FormData& form_data,
   if (form_element.isNull())
     return;
 
-  FieldFilterMask filter_mask = static_cast<FieldFilterMask>(
-      FILTER_DISABLED_ELEMENTS | FILTER_READONLY_ELEMENTS);
-  ForEachMatchingFormField(form_element,
-                           WebInputElement(),
-                           form_data,
-                           filter_mask,
-                           true, /* force override */
-                           &FillFormField);
-}
-
-void FillFormForAllElements(const FormData& form_data,
-                            const WebFormElement& form_element) {
-  if (form_element.isNull())
-    return;
-
   ForEachMatchingFormField(form_element,
                            WebInputElement(),
                            form_data,
-                           FILTER_NONE,
+                           false, /* only_focusable_elements */
                            true, /* force override */
                            &FillFormField);
 }
@@ -1042,7 +1015,7 @@ void PreviewForm(const FormData& form, const WebFormControlElement& element) {
   ForEachMatchingFormField(form_element,
                            element,
                            form,
-                           FILTER_ALL_NON_EDITIABLE_ELEMENTS,
+                           true, /* only_focusable_elements */
                            false, /* dont force override */
                            &PreviewFormField);
 }