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 "chrome/browser/autofill/autofill_manager.h" | 5 #include "chrome/browser/autofill/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/string16.h" | 18 #include "base/string16.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "chrome/browser/api/infobars/infobar_tab_service.h" | 22 #include "chrome/browser/api/infobars/infobar_tab_service.h" |
| 23 #include "chrome/browser/autofill/api/autofill_manager_delegate.h" |
23 #include "chrome/browser/autofill/autocomplete_history_manager.h" | 24 #include "chrome/browser/autofill/autocomplete_history_manager.h" |
24 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 25 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
25 #include "chrome/browser/autofill/autofill_external_delegate.h" | 26 #include "chrome/browser/autofill/autofill_external_delegate.h" |
26 #include "chrome/browser/autofill/autofill_feedback_infobar_delegate.h" | 27 #include "chrome/browser/autofill/autofill_feedback_infobar_delegate.h" |
27 #include "chrome/browser/autofill/autofill_field.h" | 28 #include "chrome/browser/autofill/autofill_field.h" |
28 #include "chrome/browser/autofill/autofill_metrics.h" | 29 #include "chrome/browser/autofill/autofill_metrics.h" |
29 #include "chrome/browser/autofill/autofill_profile.h" | 30 #include "chrome/browser/autofill/autofill_profile.h" |
30 #include "chrome/browser/autofill/autofill_type.h" | 31 #include "chrome/browser/autofill/autofill_type.h" |
31 #include "chrome/browser/autofill/credit_card.h" | 32 #include "chrome/browser/autofill/credit_card.h" |
32 #include "chrome/browser/autofill/form_structure.h" | 33 #include "chrome/browser/autofill/form_structure.h" |
33 #include "chrome/browser/autofill/password_generator.h" | 34 #include "chrome/browser/autofill/password_generator.h" |
34 #include "chrome/browser/autofill/personal_data_manager.h" | 35 #include "chrome/browser/autofill/personal_data_manager.h" |
35 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 36 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
36 #include "chrome/browser/autofill/phone_number.h" | 37 #include "chrome/browser/autofill/phone_number.h" |
37 #include "chrome/browser/autofill/phone_number_i18n.h" | 38 #include "chrome/browser/autofill/phone_number_i18n.h" |
38 #include "chrome/browser/autofill/select_control_handler.h" | 39 #include "chrome/browser/autofill/select_control_handler.h" |
39 #include "chrome/browser/password_manager/password_manager.h" | |
40 #include "chrome/browser/api/prefs/pref_service_base.h" | 40 #include "chrome/browser/api/prefs/pref_service_base.h" |
41 #include "chrome/browser/profiles/profile.h" | 41 #include "chrome/browser/profiles/profile.h" |
42 #include "chrome/browser/sync/profile_sync_service.h" | 42 #include "chrome/browser/sync/profile_sync_service.h" |
43 #include "chrome/browser/sync/profile_sync_service_factory.h" | 43 #include "chrome/browser/sync/profile_sync_service_factory.h" |
44 #include "chrome/browser/ui/browser.h" | 44 #include "chrome/browser/ui/browser.h" |
45 #include "chrome/browser/ui/browser_finder.h" | 45 #include "chrome/browser/ui/browser_finder.h" |
46 #include "chrome/browser/ui/browser_window.h" | 46 #include "chrome/browser/ui/browser_window.h" |
47 #include "chrome/browser/ui/chrome_pages.h" | 47 #include "chrome/browser/ui/chrome_pages.h" |
48 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 48 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
49 #include "chrome/common/autofill_messages.h" | 49 #include "chrome/common/autofill_messages.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 171 |
172 if (matching_types.empty()) | 172 if (matching_types.empty()) |
173 matching_types.insert(UNKNOWN_TYPE); | 173 matching_types.insert(UNKNOWN_TYPE); |
174 | 174 |
175 field->set_possible_types(matching_types); | 175 field->set_possible_types(matching_types); |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 } // namespace | 179 } // namespace |
180 | 180 |
181 AutofillManager::AutofillManager(TabContents* tab_contents) | 181 AutofillManager::AutofillManager(autofill::AutofillManagerDelegate* delegate, |
| 182 TabContents* tab_contents) |
182 : content::WebContentsObserver(tab_contents->web_contents()), | 183 : content::WebContentsObserver(tab_contents->web_contents()), |
| 184 manager_delegate_(delegate), |
183 tab_contents_(tab_contents), | 185 tab_contents_(tab_contents), |
184 personal_data_(NULL), | 186 personal_data_(NULL), |
185 download_manager_(tab_contents->profile(), this), | 187 download_manager_(tab_contents->profile(), this), |
186 disable_download_manager_requests_(false), | 188 disable_download_manager_requests_(false), |
187 metric_logger_(new AutofillMetrics), | 189 metric_logger_(new AutofillMetrics), |
188 has_logged_autofill_enabled_(false), | 190 has_logged_autofill_enabled_(false), |
189 has_logged_address_suggestions_count_(false), | 191 has_logged_address_suggestions_count_(false), |
190 did_show_suggestions_(false), | 192 did_show_suggestions_(false), |
191 user_did_type_(false), | 193 user_did_type_(false), |
192 user_did_autofill_(false), | 194 user_did_autofill_(false), |
193 user_did_edit_autofilled_field_(false), | 195 user_did_edit_autofilled_field_(false), |
194 password_generation_enabled_(false), | 196 password_generation_enabled_(false), |
195 external_delegate_(NULL) { | 197 external_delegate_(NULL) { |
196 // |personal_data_| is NULL when using test-enabled WebContents. | 198 // |personal_data_| is NULL when using test-enabled WebContents. |
197 personal_data_ = PersonalDataManagerFactory::GetForProfile( | 199 personal_data_ = PersonalDataManagerFactory::GetForProfile( |
198 tab_contents->profile()->GetOriginalProfile()); | 200 tab_contents->profile()->GetOriginalProfile()); |
199 RegisterWithSyncService(); | 201 RegisterWithSyncService(); |
200 registrar_.Init(PrefServiceBase::ForProfile(tab_contents->profile())); | 202 registrar_.Init(manager_delegate_->GetPrefs()); |
201 registrar_.Add(prefs::kPasswordGenerationEnabled, this); | 203 registrar_.Add(prefs::kPasswordGenerationEnabled, this); |
202 notification_registrar_.Add(this, | 204 notification_registrar_.Add(this, |
203 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 205 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
204 content::Source<TabContents>(tab_contents)); | 206 content::Source<TabContents>(tab_contents)); |
205 } | 207 } |
206 | 208 |
207 AutofillManager::~AutofillManager() { | 209 AutofillManager::~AutofillManager() { |
208 } | 210 } |
209 | 211 |
210 // static | 212 // static |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 ProfileSyncService* service = ProfileSyncServiceFactory::GetForProfile( | 257 ProfileSyncService* service = ProfileSyncServiceFactory::GetForProfile( |
256 tab_contents_->profile()); | 258 tab_contents_->profile()); |
257 | 259 |
258 bool password_sync_enabled = false; | 260 bool password_sync_enabled = false; |
259 if (service) { | 261 if (service) { |
260 syncer::ModelTypeSet sync_set = service->GetPreferredDataTypes(); | 262 syncer::ModelTypeSet sync_set = service->GetPreferredDataTypes(); |
261 password_sync_enabled = | 263 password_sync_enabled = |
262 service->HasSyncSetupCompleted() && sync_set.Has(syncer::PASSWORDS); | 264 service->HasSyncSetupCompleted() && sync_set.Has(syncer::PASSWORDS); |
263 } | 265 } |
264 | 266 |
265 bool password_manager_enabled = | 267 bool saving_passwords_enabled = manager_delegate_->IsSavingPasswordsEnabled(); |
266 tab_contents_->password_manager()->IsSavingEnabled(); | 268 bool preference_checked = manager_delegate_->GetPrefs()->GetBoolean( |
267 | |
268 Profile* profile = Profile::FromBrowserContext( | |
269 web_contents()->GetBrowserContext()); | |
270 bool preference_checked = PrefServiceBase::ForProfile(profile)->GetBoolean( | |
271 prefs::kPasswordGenerationEnabled); | 269 prefs::kPasswordGenerationEnabled); |
272 | 270 |
273 bool new_password_generation_enabled = | 271 bool new_password_generation_enabled = |
274 password_sync_enabled && | 272 password_sync_enabled && |
275 password_manager_enabled && | 273 saving_passwords_enabled && |
276 preference_checked; | 274 preference_checked; |
277 | 275 |
278 if (new_password_generation_enabled != password_generation_enabled_ || | 276 if (new_password_generation_enabled != password_generation_enabled_ || |
279 new_renderer) { | 277 new_renderer) { |
280 password_generation_enabled_ = new_password_generation_enabled; | 278 password_generation_enabled_ = new_password_generation_enabled; |
281 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_); | 279 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_); |
282 } | 280 } |
283 } | 281 } |
284 | 282 |
285 void AutofillManager::RenderViewCreated(content::RenderViewHost* host) { | 283 void AutofillManager::RenderViewCreated(content::RenderViewHost* host) { |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 // If the corresponding flag is set, annotate forms with the predicted types. | 804 // If the corresponding flag is set, annotate forms with the predicted types. |
807 SendAutofillTypePredictions(form_structures_.get()); | 805 SendAutofillTypePredictions(form_structures_.get()); |
808 } | 806 } |
809 | 807 |
810 void AutofillManager::OnDidEndTextFieldEditing() { | 808 void AutofillManager::OnDidEndTextFieldEditing() { |
811 if (external_delegate_) | 809 if (external_delegate_) |
812 external_delegate_->DidEndTextFieldEditing(); | 810 external_delegate_->DidEndTextFieldEditing(); |
813 } | 811 } |
814 | 812 |
815 bool AutofillManager::IsAutofillEnabled() const { | 813 bool AutofillManager::IsAutofillEnabled() const { |
816 Profile* profile = Profile::FromBrowserContext( | 814 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
817 const_cast<AutofillManager*>(this)->web_contents()->GetBrowserContext()); | |
818 return PrefServiceBase::ForProfile(profile)->GetBoolean( | |
819 prefs::kAutofillEnabled); | |
820 } | 815 } |
821 | 816 |
822 void AutofillManager::SendAutofillTypePredictions( | 817 void AutofillManager::SendAutofillTypePredictions( |
823 const std::vector<FormStructure*>& forms) const { | 818 const std::vector<FormStructure*>& forms) const { |
824 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 819 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
825 switches::kShowAutofillTypePredictions)) | 820 switches::kShowAutofillTypePredictions)) |
826 return; | 821 return; |
827 | 822 |
828 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 823 RenderViewHost* host = web_contents()->GetRenderViewHost(); |
829 if (!host) | 824 if (!host) |
830 return; | 825 return; |
831 | 826 |
832 std::vector<FormDataPredictions> type_predictions; | 827 std::vector<FormDataPredictions> type_predictions; |
833 FormStructure::GetFieldTypePredictions(forms, &type_predictions); | 828 FormStructure::GetFieldTypePredictions(forms, &type_predictions); |
834 host->Send( | 829 host->Send( |
835 new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(), | 830 new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(), |
836 type_predictions)); | 831 type_predictions)); |
837 } | 832 } |
838 | 833 |
839 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { | 834 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { |
840 const CreditCard* imported_credit_card; | 835 const CreditCard* imported_credit_card; |
841 if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card)) | 836 if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card)) |
842 return; | 837 return; |
843 | 838 |
844 // If credit card information was submitted, show an infobar to offer to save | 839 // If credit card information was submitted, show an infobar to offer to save |
845 // it. | 840 // it. |
846 scoped_ptr<const CreditCard> scoped_credit_card(imported_credit_card); | 841 scoped_ptr<const CreditCard> scoped_credit_card(imported_credit_card); |
847 if (imported_credit_card && web_contents()) { | 842 if (imported_credit_card && web_contents()) { |
848 InfoBarTabService* infobar_service = | 843 InfoBarTabService* infobar_service = manager_delegate_->GetInfoBarService(); |
849 InfoBarTabService::ForTab(tab_contents_); | |
850 infobar_service->AddInfoBar( | 844 infobar_service->AddInfoBar( |
851 new AutofillCCInfoBarDelegate(infobar_service, | 845 new AutofillCCInfoBarDelegate(infobar_service, |
852 scoped_credit_card.release(), | 846 scoped_credit_card.release(), |
853 personal_data_, | 847 personal_data_, |
854 metric_logger_.get())); | 848 metric_logger_.get())); |
855 } | 849 } |
856 } | 850 } |
857 | 851 |
858 // Note that |submitted_form| is passed as a pointer rather than as a reference | 852 // Note that |submitted_form| is passed as a pointer rather than as a reference |
859 // so that we can get memory management right across threads. Note also that we | 853 // so that we can get memory management right across threads. Note also that we |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 user_did_type_ = false; | 897 user_did_type_ = false; |
904 user_did_autofill_ = false; | 898 user_did_autofill_ = false; |
905 user_did_edit_autofilled_field_ = false; | 899 user_did_edit_autofilled_field_ = false; |
906 forms_loaded_timestamp_ = TimeTicks(); | 900 forms_loaded_timestamp_ = TimeTicks(); |
907 initial_interaction_timestamp_ = TimeTicks(); | 901 initial_interaction_timestamp_ = TimeTicks(); |
908 | 902 |
909 if (external_delegate_) | 903 if (external_delegate_) |
910 external_delegate_->Reset(); | 904 external_delegate_->Reset(); |
911 } | 905 } |
912 | 906 |
913 AutofillManager::AutofillManager(TabContents* tab_contents, | 907 AutofillManager::AutofillManager(autofill::AutofillManagerDelegate* delegate, |
| 908 TabContents* tab_contents, |
914 PersonalDataManager* personal_data) | 909 PersonalDataManager* personal_data) |
915 : content::WebContentsObserver(tab_contents->web_contents()), | 910 : content::WebContentsObserver(tab_contents->web_contents()), |
| 911 manager_delegate_(delegate), |
916 tab_contents_(tab_contents), | 912 tab_contents_(tab_contents), |
917 personal_data_(personal_data), | 913 personal_data_(personal_data), |
918 download_manager_(tab_contents->profile(), this), | 914 download_manager_(tab_contents->profile(), this), |
919 disable_download_manager_requests_(true), | 915 disable_download_manager_requests_(true), |
920 metric_logger_(new AutofillMetrics), | 916 metric_logger_(new AutofillMetrics), |
921 has_logged_autofill_enabled_(false), | 917 has_logged_autofill_enabled_(false), |
922 has_logged_address_suggestions_count_(false), | 918 has_logged_address_suggestions_count_(false), |
923 did_show_suggestions_(false), | 919 did_show_suggestions_(false), |
924 user_did_type_(false), | 920 user_did_type_(false), |
925 user_did_autofill_(false), | 921 user_did_autofill_(false), |
926 user_did_edit_autofilled_field_(false), | 922 user_did_edit_autofilled_field_(false), |
927 password_generation_enabled_(false), | 923 password_generation_enabled_(false), |
928 external_delegate_(NULL) { | 924 external_delegate_(NULL) { |
929 DCHECK(tab_contents); | 925 DCHECK(tab_contents_); |
| 926 DCHECK(manager_delegate_); |
930 RegisterWithSyncService(); | 927 RegisterWithSyncService(); |
931 // Test code doesn't need registrar_. | 928 // Test code doesn't need registrar_. |
932 } | 929 } |
933 | 930 |
934 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { | 931 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { |
935 metric_logger_.reset(metric_logger); | 932 metric_logger_.reset(metric_logger); |
936 } | 933 } |
937 | 934 |
938 bool AutofillManager::GetHost(const std::vector<AutofillProfile*>& profiles, | 935 bool AutofillManager::GetHost(const std::vector<AutofillProfile*>& profiles, |
939 const std::vector<CreditCard*>& credit_cards, | 936 const std::vector<CreditCard*>& credit_cards, |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 *profile_guid = IDToGUID(profile_id); | 1410 *profile_guid = IDToGUID(profile_id); |
1414 } | 1411 } |
1415 | 1412 |
1416 void AutofillManager::UpdateInitialInteractionTimestamp( | 1413 void AutofillManager::UpdateInitialInteractionTimestamp( |
1417 const TimeTicks& interaction_timestamp) { | 1414 const TimeTicks& interaction_timestamp) { |
1418 if (initial_interaction_timestamp_.is_null() || | 1415 if (initial_interaction_timestamp_.is_null() || |
1419 interaction_timestamp < initial_interaction_timestamp_) { | 1416 interaction_timestamp < initial_interaction_timestamp_) { |
1420 initial_interaction_timestamp_ = interaction_timestamp; | 1417 initial_interaction_timestamp_ = interaction_timestamp; |
1421 } | 1418 } |
1422 } | 1419 } |
OLD | NEW |