| 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 "components/autofill/content/browser/request_autocomplete_manager.h" | 5 #include "components/autofill/content/browser/request_autocomplete_manager.h" |
| 6 | 6 |
| 7 #include "components/autofill/content/browser/content_autofill_driver.h" | 7 #include "components/autofill/content/browser/content_autofill_driver.h" |
| 8 #include "components/autofill/content/common/autofill_messages.h" | 8 #include "components/autofill/content/common/autofill_messages.h" |
| 9 #include "components/autofill/core/browser/form_structure.h" | 9 #include "components/autofill/core/browser/form_structure.h" |
| 10 #include "components/autofill/core/common/autofill_data_validation.h" | 10 #include "components/autofill/core/common/autofill_data_validation.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 case AutofillClient::AutocompleteResultErrorCancel: | 28 case AutofillClient::AutocompleteResultErrorCancel: |
| 29 return blink::WebFormElement::AutocompleteResultErrorCancel; | 29 return blink::WebFormElement::AutocompleteResultErrorCancel; |
| 30 case AutofillClient::AutocompleteResultErrorInvalid: | 30 case AutofillClient::AutocompleteResultErrorInvalid: |
| 31 return blink::WebFormElement::AutocompleteResultErrorInvalid; | 31 return blink::WebFormElement::AutocompleteResultErrorInvalid; |
| 32 } | 32 } |
| 33 | 33 |
| 34 NOTREACHED(); | 34 NOTREACHED(); |
| 35 return blink::WebFormElement::AutocompleteResultErrorDisabled; | 35 return blink::WebFormElement::AutocompleteResultErrorDisabled; |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool HasValue(const FormFieldData& field) { |
| 39 return !field.value.empty(); |
| 40 } |
| 41 |
| 42 // Helper function to set or reset the |is_autofilled| property of fields |
| 43 // present in |form_data|. |
| 44 void SetAutofillPropertyOfFields(FormData* form_data, bool is_autofilled) { |
| 45 if (HasValue(form_data->username_field)) |
| 46 form_data->username_field.is_autofilled = is_autofilled; |
| 47 |
| 48 if (HasValue(form_data->password_field)) |
| 49 form_data->password_field.is_autofilled = is_autofilled; |
| 50 |
| 51 // TODO (pritam.nikam): Make sure we remove |fields|, and add form fields |
| 52 // for all possible autofillable input fields (http://crbug.com/417295). |
| 53 for (size_t i = 0; i < form_data->fields.size(); ++i) { |
| 54 if (HasValue(form_data->fields[i])) |
| 55 form_data->fields[i].is_autofilled = is_autofilled; |
| 56 } |
| 57 } |
| 58 |
| 38 } // namespace | 59 } // namespace |
| 39 | 60 |
| 40 RequestAutocompleteManager::RequestAutocompleteManager( | 61 RequestAutocompleteManager::RequestAutocompleteManager( |
| 41 ContentAutofillDriver* autofill_driver) | 62 ContentAutofillDriver* autofill_driver) |
| 42 : autofill_driver_(autofill_driver), weak_ptr_factory_(this) { | 63 : autofill_driver_(autofill_driver), weak_ptr_factory_(this) { |
| 43 DCHECK(autofill_driver_); | 64 DCHECK(autofill_driver_); |
| 44 } | 65 } |
| 45 | 66 |
| 46 RequestAutocompleteManager::~RequestAutocompleteManager() {} | 67 RequestAutocompleteManager::~RequestAutocompleteManager() {} |
| 47 | 68 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 72 return; | 93 return; |
| 73 | 94 |
| 74 content::RenderViewHost* host = | 95 content::RenderViewHost* host = |
| 75 autofill_driver_->web_contents()->GetRenderViewHost(); | 96 autofill_driver_->web_contents()->GetRenderViewHost(); |
| 76 if (!host) | 97 if (!host) |
| 77 return; | 98 return; |
| 78 | 99 |
| 79 FormData form_data; | 100 FormData form_data; |
| 80 if (form_structure) { | 101 if (form_structure) { |
| 81 form_data = form_structure->ToFormData(); | 102 form_data = form_structure->ToFormData(); |
| 82 for (size_t i = 0; i < form_data.fields.size(); ++i) { | 103 SetAutofillPropertyOfFields(&form_data, true); |
| 83 if(!form_data.fields[i].value.empty()) | |
| 84 form_data.fields[i].is_autofilled = true; | |
| 85 } | |
| 86 } | 104 } |
| 87 | 105 |
| 88 host->Send(new AutofillMsg_RequestAutocompleteResult( | 106 host->Send(new AutofillMsg_RequestAutocompleteResult( |
| 89 host->GetRoutingID(), | 107 host->GetRoutingID(), |
| 90 ToWebkitAutocompleteResult(result), | 108 ToWebkitAutocompleteResult(result), |
| 91 debug_message, | 109 debug_message, |
| 92 form_data)); | 110 form_data)); |
| 93 } | 111 } |
| 94 | 112 |
| 95 void RequestAutocompleteManager::ShowRequestAutocompleteDialog( | 113 void RequestAutocompleteManager::ShowRequestAutocompleteDialog( |
| 96 const FormData& form, | 114 const FormData& form, |
| 97 const GURL& source_url, | 115 const GURL& source_url, |
| 98 const AutofillClient::ResultCallback& callback) { | 116 const AutofillClient::ResultCallback& callback) { |
| 99 AutofillClient* client = autofill_driver_->autofill_manager()->client(); | 117 AutofillClient* client = autofill_driver_->autofill_manager()->client(); |
| 100 client->ShowRequestAutocompleteDialog(form, source_url, callback); | 118 client->ShowRequestAutocompleteDialog(form, source_url, callback); |
| 101 } | 119 } |
| 102 | 120 |
| 103 } // namespace autofill | 121 } // namespace autofill |
| OLD | NEW |