| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/autofill_manager.h" | 5 #include "components/autofill/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> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/guid.h" | 16 #include "base/guid.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 19 #include "base/string16.h" | 19 #include "base/string16.h" |
| 20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 21 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 23 #include "components/autofill/browser/autocheckout/whitelist_manager.h" | 23 #include "components/autofill/browser/autocheckout/whitelist_manager.h" |
| 24 #include "components/autofill/browser/autocheckout_manager.h" | 24 #include "components/autofill/browser/autocheckout_manager.h" |
| 25 #include "components/autofill/browser/autocomplete_history_manager.h" | 25 #include "components/autofill/browser/autocomplete_history_manager.h" |
| 26 #include "components/autofill/browser/autofill_country.h" | |
| 27 #include "components/autofill/browser/autofill_external_delegate.h" | 26 #include "components/autofill/browser/autofill_external_delegate.h" |
| 28 #include "components/autofill/browser/autofill_field.h" | 27 #include "components/autofill/browser/autofill_field.h" |
| 29 #include "components/autofill/browser/autofill_manager_delegate.h" | 28 #include "components/autofill/browser/autofill_manager_delegate.h" |
| 30 #include "components/autofill/browser/autofill_manager_test_delegate.h" | 29 #include "components/autofill/browser/autofill_manager_test_delegate.h" |
| 31 #include "components/autofill/browser/autofill_metrics.h" | 30 #include "components/autofill/browser/autofill_metrics.h" |
| 32 #include "components/autofill/browser/autofill_profile.h" | 31 #include "components/autofill/browser/autofill_profile.h" |
| 33 #include "components/autofill/browser/autofill_type.h" | 32 #include "components/autofill/browser/autofill_type.h" |
| 34 #include "components/autofill/browser/credit_card.h" | 33 #include "components/autofill/browser/credit_card.h" |
| 35 #include "components/autofill/browser/form_structure.h" | 34 #include "components/autofill/browser/form_structure.h" |
| 36 #include "components/autofill/browser/password_generator.h" | 35 #include "components/autofill/browser/password_generator.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 164 |
| 166 field->set_possible_types(matching_types); | 165 field->set_possible_types(matching_types); |
| 167 } | 166 } |
| 168 } | 167 } |
| 169 | 168 |
| 170 } // namespace | 169 } // namespace |
| 171 | 170 |
| 172 // static | 171 // static |
| 173 void AutofillManager::CreateForWebContentsAndDelegate( | 172 void AutofillManager::CreateForWebContentsAndDelegate( |
| 174 content::WebContents* contents, | 173 content::WebContents* contents, |
| 175 autofill::AutofillManagerDelegate* delegate) { | 174 autofill::AutofillManagerDelegate* delegate, |
| 175 const std::string& app_locale) { |
| 176 if (FromWebContents(contents)) | 176 if (FromWebContents(contents)) |
| 177 return; | 177 return; |
| 178 | 178 |
| 179 contents->SetUserData(kAutofillManagerWebContentsUserDataKey, | 179 contents->SetUserData(kAutofillManagerWebContentsUserDataKey, |
| 180 new AutofillManager(contents, delegate)); | 180 new AutofillManager(contents, delegate, app_locale)); |
| 181 | 181 |
| 182 // Trigger the lazy creation of AutocheckoutWhitelistManagerService, and | 182 // Trigger the lazy creation of AutocheckoutWhitelistManagerService, and |
| 183 // schedule a fetch of the Autocheckout whitelist file if it's not already | 183 // schedule a fetch of the Autocheckout whitelist file if it's not already |
| 184 // loaded. This helps ensure that the whitelist will be available by the time | 184 // loaded. This helps ensure that the whitelist will be available by the time |
| 185 // the user navigates to a form on which Autocheckout should be enabled. | 185 // the user navigates to a form on which Autocheckout should be enabled. |
| 186 delegate->GetAutocheckoutWhitelistManager(); | 186 delegate->GetAutocheckoutWhitelistManager(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // static | 189 // static |
| 190 AutofillManager* AutofillManager::FromWebContents( | 190 AutofillManager* AutofillManager::FromWebContents( |
| 191 content::WebContents* contents) { | 191 content::WebContents* contents) { |
| 192 return static_cast<AutofillManager*>( | 192 return static_cast<AutofillManager*>( |
| 193 contents->GetUserData(kAutofillManagerWebContentsUserDataKey)); | 193 contents->GetUserData(kAutofillManagerWebContentsUserDataKey)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 AutofillManager::AutofillManager(content::WebContents* web_contents, | 196 AutofillManager::AutofillManager(content::WebContents* web_contents, |
| 197 autofill::AutofillManagerDelegate* delegate) | 197 autofill::AutofillManagerDelegate* delegate, |
| 198 const std::string& app_locale) |
| 198 : content::WebContentsObserver(web_contents), | 199 : content::WebContentsObserver(web_contents), |
| 199 manager_delegate_(delegate), | 200 manager_delegate_(delegate), |
| 201 app_locale_(app_locale), |
| 200 personal_data_(delegate->GetPersonalDataManager()), | 202 personal_data_(delegate->GetPersonalDataManager()), |
| 201 download_manager_(web_contents->GetBrowserContext(), this), | 203 download_manager_(web_contents->GetBrowserContext(), this), |
| 202 disable_download_manager_requests_(false), | 204 disable_download_manager_requests_(false), |
| 203 autocomplete_history_manager_(web_contents), | 205 autocomplete_history_manager_(web_contents), |
| 204 autocheckout_manager_(this), | 206 autocheckout_manager_(this), |
| 205 metric_logger_(new AutofillMetrics), | 207 metric_logger_(new AutofillMetrics), |
| 206 has_logged_autofill_enabled_(false), | 208 has_logged_autofill_enabled_(false), |
| 207 has_logged_address_suggestions_count_(false), | 209 has_logged_address_suggestions_count_(false), |
| 208 did_show_suggestions_(false), | 210 did_show_suggestions_(false), |
| 209 user_did_type_(false), | 211 user_did_type_(false), |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 } | 428 } |
| 427 | 429 |
| 428 // Note that ownership of |submitted_form| is passed to the second task, | 430 // Note that ownership of |submitted_form| is passed to the second task, |
| 429 // using |base::Owned|. | 431 // using |base::Owned|. |
| 430 FormStructure* raw_submitted_form = submitted_form.get(); | 432 FormStructure* raw_submitted_form = submitted_form.get(); |
| 431 BrowserThread::GetBlockingPool()->PostTaskAndReply( | 433 BrowserThread::GetBlockingPool()->PostTaskAndReply( |
| 432 FROM_HERE, | 434 FROM_HERE, |
| 433 base::Bind(&DeterminePossibleFieldTypesForUpload, | 435 base::Bind(&DeterminePossibleFieldTypesForUpload, |
| 434 copied_profiles, | 436 copied_profiles, |
| 435 copied_credit_cards, | 437 copied_credit_cards, |
| 436 AutofillCountry::ApplicationLocale(), | 438 app_locale_, |
| 437 raw_submitted_form), | 439 raw_submitted_form), |
| 438 base::Bind(&AutofillManager::UploadFormDataAsyncCallback, | 440 base::Bind(&AutofillManager::UploadFormDataAsyncCallback, |
| 439 weak_ptr_factory_.GetWeakPtr(), | 441 weak_ptr_factory_.GetWeakPtr(), |
| 440 base::Owned(submitted_form.release()), | 442 base::Owned(submitted_form.release()), |
| 441 forms_loaded_timestamp_, | 443 forms_loaded_timestamp_, |
| 442 initial_interaction_timestamp_, | 444 initial_interaction_timestamp_, |
| 443 timestamp)); | 445 timestamp)); |
| 444 } | 446 } |
| 445 | 447 |
| 446 return true; | 448 return true; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 DCHECK(autofill_field); | 624 DCHECK(autofill_field); |
| 623 | 625 |
| 624 FormData result = form; | 626 FormData result = form; |
| 625 | 627 |
| 626 // If the relevant section is auto-filled, we should fill |field| but not the | 628 // If the relevant section is auto-filled, we should fill |field| but not the |
| 627 // rest of the form. | 629 // rest of the form. |
| 628 if (SectionIsAutofilled(*form_structure, form, autofill_field->section())) { | 630 if (SectionIsAutofilled(*form_structure, form, autofill_field->section())) { |
| 629 for (std::vector<FormFieldData>::iterator iter = result.fields.begin(); | 631 for (std::vector<FormFieldData>::iterator iter = result.fields.begin(); |
| 630 iter != result.fields.end(); ++iter) { | 632 iter != result.fields.end(); ++iter) { |
| 631 if ((*iter) == field) { | 633 if ((*iter) == field) { |
| 632 form_group->FillFormField(*autofill_field, variant, &(*iter)); | 634 form_group->FillFormField( |
| 635 *autofill_field, variant, app_locale_, &(*iter)); |
| 633 // Mark the cached field as autofilled, so that we can detect when a | 636 // Mark the cached field as autofilled, so that we can detect when a |
| 634 // user edits an autofilled field (for metrics). | 637 // user edits an autofilled field (for metrics). |
| 635 autofill_field->is_autofilled = true; | 638 autofill_field->is_autofilled = true; |
| 636 break; | 639 break; |
| 637 } | 640 } |
| 638 } | 641 } |
| 639 | 642 |
| 640 host->Send(new AutofillMsg_FormDataFilled(host->GetRoutingID(), query_id, | 643 host->Send(new AutofillMsg_FormDataFilled(host->GetRoutingID(), query_id, |
| 641 result)); | 644 result)); |
| 642 return; | 645 return; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 661 // (b) part of the same logical unit, e.g. name or phone number, | 664 // (b) part of the same logical unit, e.g. name or phone number, |
| 662 // then take the multi-profile "variant" into account. | 665 // then take the multi-profile "variant" into account. |
| 663 // Otherwise fill with the default (zeroth) variant. | 666 // Otherwise fill with the default (zeroth) variant. |
| 664 size_t use_variant = 0; | 667 size_t use_variant = 0; |
| 665 if (result.fields[i] == field || | 668 if (result.fields[i] == field || |
| 666 field_group_type == initiating_group_type) { | 669 field_group_type == initiating_group_type) { |
| 667 use_variant = variant; | 670 use_variant = variant; |
| 668 } | 671 } |
| 669 form_group->FillFormField(*cached_field, | 672 form_group->FillFormField(*cached_field, |
| 670 use_variant, | 673 use_variant, |
| 674 app_locale_, |
| 671 &result.fields[i]); | 675 &result.fields[i]); |
| 672 // Mark the cached field as autofilled, so that we can detect when a user | 676 // Mark the cached field as autofilled, so that we can detect when a user |
| 673 // edits an autofilled field (for metrics). | 677 // edits an autofilled field (for metrics). |
| 674 form_structure->field(i)->is_autofilled = true; | 678 form_structure->field(i)->is_autofilled = true; |
| 675 } | 679 } |
| 676 } | 680 } |
| 677 | 681 |
| 678 autofilled_form_signatures_.push_front(form_structure->FormSignature()); | 682 autofilled_form_signatures_.push_front(form_structure->FormSignature()); |
| 679 // Only remember the last few forms that we've seen, both to avoid false | 683 // Only remember the last few forms that we've seen, both to avoid false |
| 680 // positives and to avoid wasting memory. | 684 // positives and to avoid wasting memory. |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 | 1003 |
| 1000 if (external_delegate_) | 1004 if (external_delegate_) |
| 1001 external_delegate_->Reset(); | 1005 external_delegate_->Reset(); |
| 1002 } | 1006 } |
| 1003 | 1007 |
| 1004 AutofillManager::AutofillManager(content::WebContents* web_contents, | 1008 AutofillManager::AutofillManager(content::WebContents* web_contents, |
| 1005 autofill::AutofillManagerDelegate* delegate, | 1009 autofill::AutofillManagerDelegate* delegate, |
| 1006 PersonalDataManager* personal_data) | 1010 PersonalDataManager* personal_data) |
| 1007 : content::WebContentsObserver(web_contents), | 1011 : content::WebContentsObserver(web_contents), |
| 1008 manager_delegate_(delegate), | 1012 manager_delegate_(delegate), |
| 1013 app_locale_("en-US"), |
| 1009 personal_data_(personal_data), | 1014 personal_data_(personal_data), |
| 1010 download_manager_(web_contents->GetBrowserContext(), this), | 1015 download_manager_(web_contents->GetBrowserContext(), this), |
| 1011 disable_download_manager_requests_(true), | 1016 disable_download_manager_requests_(true), |
| 1012 autocomplete_history_manager_(web_contents), | 1017 autocomplete_history_manager_(web_contents), |
| 1013 autocheckout_manager_(this), | 1018 autocheckout_manager_(this), |
| 1014 metric_logger_(new AutofillMetrics), | 1019 metric_logger_(new AutofillMetrics), |
| 1015 has_logged_autofill_enabled_(false), | 1020 has_logged_autofill_enabled_(false), |
| 1016 has_logged_address_suggestions_count_(false), | 1021 has_logged_address_suggestions_count_(false), |
| 1017 did_show_suggestions_(false), | 1022 did_show_suggestions_(false), |
| 1018 user_did_type_(false), | 1023 user_did_type_(false), |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 *profile_guid = IDToGUID(profile_id); | 1337 *profile_guid = IDToGUID(profile_id); |
| 1333 } | 1338 } |
| 1334 | 1339 |
| 1335 void AutofillManager::UpdateInitialInteractionTimestamp( | 1340 void AutofillManager::UpdateInitialInteractionTimestamp( |
| 1336 const TimeTicks& interaction_timestamp) { | 1341 const TimeTicks& interaction_timestamp) { |
| 1337 if (initial_interaction_timestamp_.is_null() || | 1342 if (initial_interaction_timestamp_.is_null() || |
| 1338 interaction_timestamp < initial_interaction_timestamp_) { | 1343 interaction_timestamp < initial_interaction_timestamp_) { |
| 1339 initial_interaction_timestamp_ = interaction_timestamp; | 1344 initial_interaction_timestamp_ = interaction_timestamp; |
| 1340 } | 1345 } |
| 1341 } | 1346 } |
| OLD | NEW |