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/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 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 287 |
288 ParseForms(forms); | 288 ParseForms(forms); |
289 } | 289 } |
290 | 290 |
291 bool AutofillManager::OnWillSubmitForm(const FormData& form, | 291 bool AutofillManager::OnWillSubmitForm(const FormData& form, |
292 const TimeTicks& timestamp) { | 292 const TimeTicks& timestamp) { |
293 if (!IsValidFormData(form)) | 293 if (!IsValidFormData(form)) |
294 return false; | 294 return false; |
295 | 295 |
296 // We will always give Autocomplete a chance to save the data. | 296 // We will always give Autocomplete a chance to save the data. |
297 scoped_ptr<FormStructure> submitted_form = ValidateSubmittedForm(form); | 297 std::unique_ptr<FormStructure> submitted_form = ValidateSubmittedForm(form); |
298 if (!submitted_form) { | 298 if (!submitted_form) { |
299 autocomplete_history_manager_->OnWillSubmitForm(form); | 299 autocomplete_history_manager_->OnWillSubmitForm(form); |
300 return false; | 300 return false; |
301 } | 301 } |
302 | 302 |
303 // However, if Autofill has recognized a field as CVC, that shouldn't be | 303 // However, if Autofill has recognized a field as CVC, that shouldn't be |
304 // saved. | 304 // saved. |
305 FormData form_for_autocomplete = submitted_form->ToFormData(); | 305 FormData form_for_autocomplete = submitted_form->ToFormData(); |
306 for (size_t i = 0; i < submitted_form->field_count(); ++i) { | 306 for (size_t i = 0; i < submitted_form->field_count(); ++i) { |
307 if (submitted_form->field(i)->Type().GetStorableType() == | 307 if (submitted_form->field(i)->Type().GetStorableType() == |
308 CREDIT_CARD_VERIFICATION_CODE) { | 308 CREDIT_CARD_VERIFICATION_CODE) { |
309 form_for_autocomplete.fields[i].should_autocomplete = false; | 309 form_for_autocomplete.fields[i].should_autocomplete = false; |
310 } | 310 } |
311 } | 311 } |
312 autocomplete_history_manager_->OnWillSubmitForm(form_for_autocomplete); | 312 autocomplete_history_manager_->OnWillSubmitForm(form_for_autocomplete); |
313 | 313 |
314 address_form_event_logger_->OnWillSubmitForm(); | 314 address_form_event_logger_->OnWillSubmitForm(); |
315 credit_card_form_event_logger_->OnWillSubmitForm(); | 315 credit_card_form_event_logger_->OnWillSubmitForm(); |
316 | 316 |
317 StartUploadProcess(std::move(submitted_form), timestamp, true); | 317 StartUploadProcess(std::move(submitted_form), timestamp, true); |
318 | 318 |
319 return true; | 319 return true; |
320 } | 320 } |
321 | 321 |
322 bool AutofillManager::OnFormSubmitted(const FormData& form) { | 322 bool AutofillManager::OnFormSubmitted(const FormData& form) { |
323 if (!IsValidFormData(form)) | 323 if (!IsValidFormData(form)) |
324 return false; | 324 return false; |
325 | 325 |
326 // We will always give Autocomplete a chance to save the data. | 326 // We will always give Autocomplete a chance to save the data. |
327 scoped_ptr<FormStructure> submitted_form = ValidateSubmittedForm(form); | 327 std::unique_ptr<FormStructure> submitted_form = ValidateSubmittedForm(form); |
328 if (!submitted_form) { | 328 if (!submitted_form) { |
329 return false; | 329 return false; |
330 } | 330 } |
331 | 331 |
332 address_form_event_logger_->OnFormSubmitted(); | 332 address_form_event_logger_->OnFormSubmitted(); |
333 credit_card_form_event_logger_->OnFormSubmitted(); | 333 credit_card_form_event_logger_->OnFormSubmitted(); |
334 | 334 |
335 // Update Personal Data with the form's submitted data. | 335 // Update Personal Data with the form's submitted data. |
336 if (submitted_form->IsAutofillable()) | 336 if (submitted_form->IsAutofillable()) |
337 ImportFormData(*submitted_form); | 337 ImportFormData(*submitted_form); |
338 | 338 |
339 return true; | 339 return true; |
340 } | 340 } |
341 | 341 |
342 void AutofillManager::StartUploadProcess( | 342 void AutofillManager::StartUploadProcess( |
343 scoped_ptr<FormStructure> form_structure, | 343 std::unique_ptr<FormStructure> form_structure, |
344 const TimeTicks& timestamp, | 344 const TimeTicks& timestamp, |
345 bool observed_submission) { | 345 bool observed_submission) { |
346 // It is possible for |personal_data_| to be null, such as when used in the | 346 // It is possible for |personal_data_| to be null, such as when used in the |
347 // Android webview. | 347 // Android webview. |
348 if (!personal_data_) | 348 if (!personal_data_) |
349 return; | 349 return; |
350 | 350 |
351 // Only upload server statistics and UMA metrics if at least some local data | 351 // Only upload server statistics and UMA metrics if at least some local data |
352 // is available to use as a baseline. | 352 // is available to use as a baseline. |
353 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | 353 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 // A new pending form is assigned. | 395 // A new pending form is assigned. |
396 pending_form_data_.reset(new FormData(form)); | 396 pending_form_data_.reset(new FormData(form)); |
397 } | 397 } |
398 | 398 |
399 void AutofillManager::ProcessPendingFormForUpload() { | 399 void AutofillManager::ProcessPendingFormForUpload() { |
400 if (!pending_form_data_) | 400 if (!pending_form_data_) |
401 return; | 401 return; |
402 | 402 |
403 // We get the FormStructure corresponding to |pending_form_data_|, used in the | 403 // We get the FormStructure corresponding to |pending_form_data_|, used in the |
404 // upload process. |pending_form_data_| is reset. | 404 // upload process. |pending_form_data_| is reset. |
405 scoped_ptr<FormStructure> upload_form = | 405 std::unique_ptr<FormStructure> upload_form = |
406 ValidateSubmittedForm(*pending_form_data_); | 406 ValidateSubmittedForm(*pending_form_data_); |
407 pending_form_data_.reset(); | 407 pending_form_data_.reset(); |
408 if (!upload_form) | 408 if (!upload_form) |
409 return; | 409 return; |
410 | 410 |
411 StartUploadProcess(std::move(upload_form), base::TimeTicks::Now(), false); | 411 StartUploadProcess(std::move(upload_form), base::TimeTicks::Now(), false); |
412 } | 412 } |
413 | 413 |
414 void AutofillManager::OnTextFieldDidChange(const FormData& form, | 414 void AutofillManager::OnTextFieldDidChange(const FormData& form, |
415 const FormFieldData& field, | 415 const FormFieldData& field, |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_, | 907 FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_, |
908 unmask_request_.card); | 908 unmask_request_.card); |
909 } | 909 } |
910 | 910 |
911 client_->OnUnmaskVerificationResult(result); | 911 client_->OnUnmaskVerificationResult(result); |
912 } | 912 } |
913 | 913 |
914 void AutofillManager::OnDidGetUploadDetails( | 914 void AutofillManager::OnDidGetUploadDetails( |
915 AutofillClient::PaymentsRpcResult result, | 915 AutofillClient::PaymentsRpcResult result, |
916 const base::string16& context_token, | 916 const base::string16& context_token, |
917 scoped_ptr<base::DictionaryValue> legal_message) { | 917 std::unique_ptr<base::DictionaryValue> legal_message) { |
918 // TODO(jdonnelly): Log duration. | 918 // TODO(jdonnelly): Log duration. |
919 if (result == AutofillClient::SUCCESS) { | 919 if (result == AutofillClient::SUCCESS) { |
920 // Do *not* call payments_client_->Prepare() here. We shouldn't send | 920 // Do *not* call payments_client_->Prepare() here. We shouldn't send |
921 // credentials until the user has explicitly accepted a prompt to upload. | 921 // credentials until the user has explicitly accepted a prompt to upload. |
922 upload_request_.context_token = context_token; | 922 upload_request_.context_token = context_token; |
923 user_did_accept_upload_prompt_ = false; | 923 user_did_accept_upload_prompt_ = false; |
924 client_->ConfirmSaveCreditCardToCloud( | 924 client_->ConfirmSaveCreditCardToCloud( |
925 upload_request_.card, std::move(legal_message), | 925 upload_request_.card, std::move(legal_message), |
926 base::Bind(&AutofillManager::OnUserDidAcceptUpload, | 926 base::Bind(&AutofillManager::OnUserDidAcceptUpload, |
927 weak_ptr_factory_.GetWeakPtr())); | 927 weak_ptr_factory_.GetWeakPtr())); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 bool AutofillManager::ShouldUploadForm(const FormStructure& form) { | 998 bool AutofillManager::ShouldUploadForm(const FormStructure& form) { |
999 return IsAutofillEnabled() && !driver_->IsOffTheRecord() && | 999 return IsAutofillEnabled() && !driver_->IsOffTheRecord() && |
1000 form.ShouldBeParsed() && | 1000 form.ShouldBeParsed() && |
1001 (form.active_field_count() >= kRequiredFieldsForUpload || | 1001 (form.active_field_count() >= kRequiredFieldsForUpload || |
1002 (form.all_fields_are_passwords() && | 1002 (form.all_fields_are_passwords() && |
1003 form.active_field_count() >= | 1003 form.active_field_count() >= |
1004 kRequiredFieldsForFormsWithOnlyPasswordFields)); | 1004 kRequiredFieldsForFormsWithOnlyPasswordFields)); |
1005 } | 1005 } |
1006 | 1006 |
1007 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { | 1007 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { |
1008 scoped_ptr<CreditCard> imported_credit_card; | 1008 std::unique_ptr<CreditCard> imported_credit_card; |
1009 if (!personal_data_->ImportFormData( | 1009 if (!personal_data_->ImportFormData( |
1010 submitted_form, IsCreditCardUploadEnabled(), &imported_credit_card)) { | 1010 submitted_form, IsCreditCardUploadEnabled(), &imported_credit_card)) { |
1011 return; | 1011 return; |
1012 } | 1012 } |
1013 | 1013 |
1014 #ifdef ENABLE_FORM_DEBUG_DUMP | 1014 #ifdef ENABLE_FORM_DEBUG_DUMP |
1015 // Debug code for research on what autofill Chrome extracts from the last few | 1015 // Debug code for research on what autofill Chrome extracts from the last few |
1016 // forms when submitting credit card data. See DumpAutofillData(). | 1016 // forms when submitting credit card data. See DumpAutofillData(). |
1017 bool dump_data = base::CommandLine::ForCurrentProcess()->HasSwitch( | 1017 bool dump_data = base::CommandLine::ForCurrentProcess()->HasSwitch( |
1018 "dump-autofill-data"); | 1018 "dump-autofill-data"); |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 autofilled_form_signatures_.pop_back(); | 1488 autofilled_form_signatures_.pop_back(); |
1489 | 1489 |
1490 // Note that this may invalidate |data_model|, particularly if it is a Mac | 1490 // Note that this may invalidate |data_model|, particularly if it is a Mac |
1491 // address book entry. | 1491 // address book entry. |
1492 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) | 1492 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) |
1493 personal_data_->RecordUseOf(data_model); | 1493 personal_data_->RecordUseOf(data_model); |
1494 | 1494 |
1495 driver_->SendFormDataToRenderer(query_id, action, result); | 1495 driver_->SendFormDataToRenderer(query_id, action, result); |
1496 } | 1496 } |
1497 | 1497 |
1498 scoped_ptr<FormStructure> AutofillManager::ValidateSubmittedForm( | 1498 std::unique_ptr<FormStructure> AutofillManager::ValidateSubmittedForm( |
1499 const FormData& form) { | 1499 const FormData& form) { |
1500 scoped_ptr<FormStructure> submitted_form(new FormStructure(form)); | 1500 std::unique_ptr<FormStructure> submitted_form(new FormStructure(form)); |
1501 if (!ShouldUploadForm(*submitted_form)) | 1501 if (!ShouldUploadForm(*submitted_form)) |
1502 return scoped_ptr<FormStructure>(); | 1502 return std::unique_ptr<FormStructure>(); |
1503 | 1503 |
1504 // Ignore forms not present in our cache. These are typically forms with | 1504 // Ignore forms not present in our cache. These are typically forms with |
1505 // wonky JavaScript that also makes them not auto-fillable. | 1505 // wonky JavaScript that also makes them not auto-fillable. |
1506 FormStructure* cached_submitted_form; | 1506 FormStructure* cached_submitted_form; |
1507 if (!FindCachedForm(form, &cached_submitted_form)) | 1507 if (!FindCachedForm(form, &cached_submitted_form)) |
1508 return scoped_ptr<FormStructure>(); | 1508 return std::unique_ptr<FormStructure>(); |
1509 | 1509 |
1510 submitted_form->UpdateFromCache(*cached_submitted_form); | 1510 submitted_form->UpdateFromCache(*cached_submitted_form); |
1511 return submitted_form; | 1511 return submitted_form; |
1512 } | 1512 } |
1513 | 1513 |
1514 bool AutofillManager::FindCachedForm(const FormData& form, | 1514 bool AutofillManager::FindCachedForm(const FormData& form, |
1515 FormStructure** form_structure) const { | 1515 FormStructure** form_structure) const { |
1516 // Find the FormStructure that corresponds to |form|. | 1516 // Find the FormStructure that corresponds to |form|. |
1517 // Scan backward through the cached |form_structures_|, as updated versions of | 1517 // Scan backward through the cached |form_structures_|, as updated versions of |
1518 // forms are added to the back of the list, whereas original versions of these | 1518 // forms are added to the back of the list, whereas original versions of these |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 | 1686 |
1687 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { | 1687 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { |
1688 if (forms.empty()) | 1688 if (forms.empty()) |
1689 return; | 1689 return; |
1690 | 1690 |
1691 std::vector<FormStructure*> non_queryable_forms; | 1691 std::vector<FormStructure*> non_queryable_forms; |
1692 std::vector<FormStructure*> queryable_forms; | 1692 std::vector<FormStructure*> queryable_forms; |
1693 for (const FormData& form : forms) { | 1693 for (const FormData& form : forms) { |
1694 const auto parse_form_start_time = base::TimeTicks::Now(); | 1694 const auto parse_form_start_time = base::TimeTicks::Now(); |
1695 | 1695 |
1696 scoped_ptr<FormStructure> form_structure(new FormStructure(form)); | 1696 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); |
1697 form_structure->ParseFieldTypesFromAutocompleteAttributes(); | 1697 form_structure->ParseFieldTypesFromAutocompleteAttributes(); |
1698 if (!form_structure->ShouldBeParsed()) | 1698 if (!form_structure->ShouldBeParsed()) |
1699 continue; | 1699 continue; |
1700 | 1700 |
1701 form_structure->DetermineHeuristicTypes(); | 1701 form_structure->DetermineHeuristicTypes(); |
1702 | 1702 |
1703 // Ownership is transferred to |form_structures_| which maintains it until | 1703 // Ownership is transferred to |form_structures_| which maintains it until |
1704 // the manager is Reset() or destroyed. It is safe to use references below | 1704 // the manager is Reset() or destroyed. It is safe to use references below |
1705 // as long as receivers don't take ownership. | 1705 // as long as receivers don't take ownership. |
1706 form_structures_.push_back(std::move(form_structure)); | 1706 form_structures_.push_back(std::move(form_structure)); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1998 if (i > 0) | 1998 if (i > 0) |
1999 fputs("Next oldest form:\n", file); | 1999 fputs("Next oldest form:\n", file); |
2000 } | 2000 } |
2001 fputs("\n", file); | 2001 fputs("\n", file); |
2002 | 2002 |
2003 fclose(file); | 2003 fclose(file); |
2004 } | 2004 } |
2005 #endif // ENABLE_FORM_DEBUG_DUMP | 2005 #endif // ENABLE_FORM_DEBUG_DUMP |
2006 | 2006 |
2007 } // namespace autofill | 2007 } // namespace autofill |
OLD | NEW |