Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: components/autofill/core/browser/autofill_manager.cc

Issue 23857010: Revert "Revert 223907 "[password generation] Upload possible account cre..."" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // future directions may not need such a pointer. 246 // future directions may not need such a pointer.
247 external_delegate_ = delegate; 247 external_delegate_ = delegate;
248 autocomplete_history_manager_->SetExternalDelegate(delegate); 248 autocomplete_history_manager_->SetExternalDelegate(delegate);
249 } 249 }
250 250
251 bool AutofillManager::OnFormSubmitted(const FormData& form, 251 bool AutofillManager::OnFormSubmitted(const FormData& form,
252 const TimeTicks& timestamp) { 252 const TimeTicks& timestamp) {
253 // Let Autocomplete know as well. 253 // Let Autocomplete know as well.
254 autocomplete_history_manager_->OnFormSubmitted(form); 254 autocomplete_history_manager_->OnFormSubmitted(form);
255 255
256 if (!IsAutofillEnabled()) 256 // Grab a copy of the form data.
257 return false; 257 scoped_ptr<FormStructure> submitted_form(new FormStructure(form));
258 258
259 if (driver_->GetWebContents()->GetBrowserContext()->IsOffTheRecord()) 259 if (!ShouldUploadForm(*submitted_form))
260 return false; 260 return false;
261 261
262 // Don't save data that was submitted through JavaScript. 262 // Don't save data that was submitted through JavaScript.
263 if (!form.user_submitted) 263 if (!form.user_submitted)
264 return false; 264 return false;
265 265
266 // Grab a copy of the form data.
267 scoped_ptr<FormStructure> submitted_form(new FormStructure(form));
268
269 // Disregard forms that we wouldn't ever autofill in the first place.
270 if (!submitted_form->ShouldBeParsed(true))
271 return false;
272
273 // Ignore forms not present in our cache. These are typically forms with 266 // Ignore forms not present in our cache. These are typically forms with
274 // wonky JavaScript that also makes them not auto-fillable. 267 // wonky JavaScript that also makes them not auto-fillable.
275 FormStructure* cached_submitted_form; 268 FormStructure* cached_submitted_form;
276 if (!FindCachedForm(form, &cached_submitted_form)) 269 if (!FindCachedForm(form, &cached_submitted_form))
277 return false; 270 return false;
278 271
279 submitted_form->UpdateFromCache(*cached_submitted_form); 272 submitted_form->UpdateFromCache(*cached_submitted_form);
280 if (submitted_form->IsAutofillable(true)) 273 if (submitted_form->IsAutofillable(true))
281 ImportFormData(*submitted_form); 274 ImportFormData(*submitted_form);
282 275
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 // Always add PASSWORD to |non_empty_types| so that if |submitted_form| 765 // Always add PASSWORD to |non_empty_types| so that if |submitted_form|
773 // contains a password field it will be uploaded to the server. If 766 // contains a password field it will be uploaded to the server. If
774 // |submitted_form| doesn't contain a password field, there is no side 767 // |submitted_form| doesn't contain a password field, there is no side
775 // effect from adding PASSWORD to |non_empty_types|. 768 // effect from adding PASSWORD to |non_empty_types|.
776 non_empty_types.insert(autofill::PASSWORD); 769 non_empty_types.insert(autofill::PASSWORD);
777 770
778 download_manager_->StartUploadRequest(submitted_form, was_autofilled, 771 download_manager_->StartUploadRequest(submitted_form, was_autofilled,
779 non_empty_types); 772 non_empty_types);
780 } 773 }
781 774
775 bool AutofillManager::UploadPasswordGenerationForm(const FormData& form) {
776 FormStructure form_structure(form);
777
778 if (!ShouldUploadForm(form_structure))
779 return false;
780
781 if (!form_structure.ShouldBeCrowdsourced())
782 return false;
783
784 // TODO(gcasto): Check that PasswordGeneration is enabled?
785
786 // Find the first password field to label. We don't try to label anything
787 // else.
788 bool found_password_field = false;
789 for (size_t i = 0; i < form_structure.field_count(); ++i) {
790 AutofillField* field = form_structure.field(i);
791
792 ServerFieldTypeSet types;
793 if (!found_password_field && field->form_control_type == "password") {
794 types.insert(ACCOUNT_CREATION_PASSWORD);
795 found_password_field = true;
796 } else {
797 types.insert(UNKNOWN_TYPE);
798 }
799 field->set_possible_types(types);
800 }
801 DCHECK(found_password_field);
802
803 // Only one field type should be present.
804 ServerFieldTypeSet available_field_types;
805 available_field_types.insert(ACCOUNT_CREATION_PASSWORD);
806
807 // Force uploading as these events are relatively rare and we want to make
808 // sure to receive them. It also makes testing easier if these requests
809 // always pass.
810 form_structure.set_upload_required(UPLOAD_REQUIRED);
811
812 if (!download_manager_)
813 return false;
814
815 return download_manager_->StartUploadRequest(form_structure,
816 false /* was_autofilled */,
817 available_field_types);
818 }
819
782 void AutofillManager::Reset() { 820 void AutofillManager::Reset() {
783 form_structures_.clear(); 821 form_structures_.clear();
784 has_logged_autofill_enabled_ = false; 822 has_logged_autofill_enabled_ = false;
785 has_logged_address_suggestions_count_ = false; 823 has_logged_address_suggestions_count_ = false;
786 did_show_suggestions_ = false; 824 did_show_suggestions_ = false;
787 user_did_type_ = false; 825 user_did_type_ = false;
788 user_did_autofill_ = false; 826 user_did_autofill_ = false;
789 user_did_edit_autofilled_field_ = false; 827 user_did_edit_autofilled_field_ = false;
790 forms_loaded_timestamp_ = TimeTicks(); 828 forms_loaded_timestamp_ = TimeTicks();
791 initial_interaction_timestamp_ = TimeTicks(); 829 initial_interaction_timestamp_ = TimeTicks();
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 } 1163 }
1126 1164
1127 void AutofillManager::UpdateInitialInteractionTimestamp( 1165 void AutofillManager::UpdateInitialInteractionTimestamp(
1128 const TimeTicks& interaction_timestamp) { 1166 const TimeTicks& interaction_timestamp) {
1129 if (initial_interaction_timestamp_.is_null() || 1167 if (initial_interaction_timestamp_.is_null() ||
1130 interaction_timestamp < initial_interaction_timestamp_) { 1168 interaction_timestamp < initial_interaction_timestamp_) {
1131 initial_interaction_timestamp_ = interaction_timestamp; 1169 initial_interaction_timestamp_ = interaction_timestamp;
1132 } 1170 }
1133 } 1171 }
1134 1172
1173 bool AutofillManager::ShouldUploadForm(const FormStructure& form) {
1174 if (!IsAutofillEnabled())
1175 return false;
1176
1177 if (driver_->GetWebContents()->GetBrowserContext()->IsOffTheRecord())
1178 return false;
1179
1180 // Disregard forms that we wouldn't ever autofill in the first place.
1181 if (!form.ShouldBeParsed(true))
1182 return false;
1183
1184 return true;
1185 }
1186
1135 } // namespace autofill 1187 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.h ('k') | components/autofill/core/browser/form_structure.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698