| OLD | NEW | 
|     1 // Copyright 2013 The Chromium Authors. All rights reserved. |     1 // Copyright 2013 The Chromium Authors. All rights reserved. | 
|     2 // Use of this source code is governed by a BSD-style license that can be |     2 // Use of this source code is governed by a BSD-style license that can be | 
|     3 // found in the LICENSE file. |     3 // found in the LICENSE file. | 
|     4  |     4  | 
|     5 #include <stddef.h> |     5 #include <stddef.h> | 
|     6  |     6  | 
|     7 #include "base/macros.h" |     7 #include "base/macros.h" | 
|     8 #include "base/strings/string16.h" |     8 #include "base/strings/string16.h" | 
|     9 #include "base/strings/string_util.h" |     9 #include "base/strings/string_util.h" | 
|    10 #include "base/strings/stringprintf.h" |    10 #include "base/strings/stringprintf.h" | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   172   // values in the form elements came from the user input. |   172   // values in the form elements came from the user input. | 
|   173   std::unique_ptr<PasswordForm> LoadHTMLAndConvertForm( |   173   std::unique_ptr<PasswordForm> LoadHTMLAndConvertForm( | 
|   174       const std::string& html, |   174       const std::string& html, | 
|   175       FormsPredictionsMap* predictions, |   175       FormsPredictionsMap* predictions, | 
|   176       bool with_user_input) { |   176       bool with_user_input) { | 
|   177     WebFormElement form; |   177     WebFormElement form; | 
|   178     LoadWebFormFromHTML(html, &form); |   178     LoadWebFormFromHTML(html, &form); | 
|   179  |   179  | 
|   180     WebVector<WebFormControlElement> control_elements; |   180     WebVector<WebFormControlElement> control_elements; | 
|   181     form.getFormControlElements(control_elements); |   181     form.getFormControlElements(control_elements); | 
|   182     ModifiedValues user_input; |   182     FieldValueAndPropertiesMaskMap user_input; | 
|   183     for (size_t i = 0; i < control_elements.size(); ++i) { |   183     for (size_t i = 0; i < control_elements.size(); ++i) { | 
|   184       WebInputElement* input_element = toWebInputElement(&control_elements[i]); |   184       WebInputElement* input_element = toWebInputElement(&control_elements[i]); | 
|   185       if (input_element->hasAttribute("set-activated-submit")) |   185       if (input_element->hasAttribute("set-activated-submit")) | 
|   186         input_element->setActivatedSubmit(true); |   186         input_element->setActivatedSubmit(true); | 
|   187       if (with_user_input) |   187       if (with_user_input) | 
|   188         user_input[*input_element] = input_element->value(); |   188         user_input[*input_element] = | 
 |   189             std::pair<base::string16, FieldPropertiesMask>( | 
 |   190                 input_element->value(), 0U); | 
|   189     } |   191     } | 
|   190  |   192  | 
|   191     return CreatePasswordFormFromWebForm( |   193     return CreatePasswordFormFromWebForm( | 
|   192         form, with_user_input ? &user_input : nullptr, predictions); |   194         form, with_user_input ? &user_input : nullptr, predictions); | 
|   193   } |   195   } | 
|   194  |   196  | 
|   195   // Iterates on the form generated by the |html| and adds the fields and type |   197   // Iterates on the form generated by the |html| and adds the fields and type | 
|   196   // predictions corresponding to |predictions_positions| to |predictions|. |   198   // predictions corresponding to |predictions_positions| to |predictions|. | 
|   197   void SetPredictions(const std::string& html, |   199   void SetPredictions(const std::string& html, | 
|   198                       FormsPredictionsMap* predictions, |   200                       FormsPredictionsMap* predictions, | 
|   199                       const std::map<int, PasswordFormFieldPredictionType>& |   201                       const std::map<int, PasswordFormFieldPredictionType>& | 
|   200                           predictions_positions) { |   202                           predictions_positions) { | 
|   201     WebFormElement form; |   203     WebFormElement form; | 
|   202     LoadWebFormFromHTML(html, &form); |   204     LoadWebFormFromHTML(html, &form); | 
|   203  |   205  | 
|   204     FormData form_data; |   206     FormData form_data; | 
|   205     ASSERT_TRUE(form_util::WebFormElementToFormData( |   207     ASSERT_TRUE(form_util::WebFormElementToFormData( | 
|   206         form, WebFormControlElement(), form_util::EXTRACT_NONE, &form_data, |   208         form, WebFormControlElement(), nullptr, form_util::EXTRACT_NONE, | 
|   207         nullptr)); |   209         &form_data, nullptr)); | 
|   208  |   210  | 
|   209     FormStructure form_structure(form_data); |   211     FormStructure form_structure(form_data); | 
|   210  |   212  | 
|   211     int field_index = 0; |   213     int field_index = 0; | 
|   212     for (std::vector<AutofillField *>::const_iterator |   214     for (std::vector<AutofillField *>::const_iterator | 
|   213              field = form_structure.begin(); |   215              field = form_structure.begin(); | 
|   214          field != form_structure.end(); ++field, ++field_index) { |   216          field != form_structure.end(); ++field, ++field_index) { | 
|   215       if (predictions_positions.find(field_index) != |   217       if (predictions_positions.find(field_index) != | 
|   216           predictions_positions.end()) { |   218           predictions_positions.end()) { | 
|   217         (*predictions)[form_data][*(*field)] = |   219         (*predictions)[form_data][*(*field)] = | 
| (...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1450   builder.AddPasswordField("password", "secret", nullptr); |  1452   builder.AddPasswordField("password", "secret", nullptr); | 
|  1451   std::string html = builder.ProduceHTML(); |  1453   std::string html = builder.ProduceHTML(); | 
|  1452  |  1454  | 
|  1453   std::unique_ptr<PasswordForm> password_form = |  1455   std::unique_ptr<PasswordForm> password_form = | 
|  1454       LoadHTMLAndConvertForm(html, nullptr, true); |  1456       LoadHTMLAndConvertForm(html, nullptr, true); | 
|  1455   ASSERT_TRUE(password_form); |  1457   ASSERT_TRUE(password_form); | 
|  1456   EXPECT_FALSE(password_form->does_look_like_signup_form); |  1458   EXPECT_FALSE(password_form->does_look_like_signup_form); | 
|  1457 } |  1459 } | 
|  1458  |  1460  | 
|  1459 }  // namespace autofill |  1461 }  // namespace autofill | 
| OLD | NEW |