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> |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "chrome/browser/autofill/autofill_type.h" | 30 #include "chrome/browser/autofill/autofill_type.h" |
31 #include "chrome/browser/autofill/credit_card.h" | 31 #include "chrome/browser/autofill/credit_card.h" |
32 #include "chrome/browser/autofill/form_structure.h" | 32 #include "chrome/browser/autofill/form_structure.h" |
33 #include "chrome/browser/autofill/password_generator.h" | 33 #include "chrome/browser/autofill/password_generator.h" |
34 #include "chrome/browser/autofill/personal_data_manager.h" | 34 #include "chrome/browser/autofill/personal_data_manager.h" |
35 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 35 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
36 #include "chrome/browser/autofill/phone_number.h" | 36 #include "chrome/browser/autofill/phone_number.h" |
37 #include "chrome/browser/autofill/phone_number_i18n.h" | 37 #include "chrome/browser/autofill/phone_number_i18n.h" |
38 #include "chrome/browser/autofill/select_control_handler.h" | 38 #include "chrome/browser/autofill/select_control_handler.h" |
39 #include "chrome/browser/password_manager/password_manager.h" | 39 #include "chrome/browser/password_manager/password_manager.h" |
40 #include "chrome/browser/prefs/pref_service.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" |
50 #include "chrome/common/chrome_notification_types.h" | 50 #include "chrome/common/chrome_notification_types.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 did_show_suggestions_(false), | 190 did_show_suggestions_(false), |
191 user_did_type_(false), | 191 user_did_type_(false), |
192 user_did_autofill_(false), | 192 user_did_autofill_(false), |
193 user_did_edit_autofilled_field_(false), | 193 user_did_edit_autofilled_field_(false), |
194 password_generation_enabled_(false), | 194 password_generation_enabled_(false), |
195 external_delegate_(NULL) { | 195 external_delegate_(NULL) { |
196 // |personal_data_| is NULL when using test-enabled WebContents. | 196 // |personal_data_| is NULL when using test-enabled WebContents. |
197 personal_data_ = PersonalDataManagerFactory::GetForProfile( | 197 personal_data_ = PersonalDataManagerFactory::GetForProfile( |
198 tab_contents->profile()->GetOriginalProfile()); | 198 tab_contents->profile()->GetOriginalProfile()); |
199 RegisterWithSyncService(); | 199 RegisterWithSyncService(); |
200 registrar_.Init(tab_contents->profile()->GetPrefs()); | 200 registrar_.Init(PrefServiceBase::ForProfile(tab_contents->profile())); |
201 registrar_.Add(prefs::kPasswordGenerationEnabled, this); | 201 registrar_.Add(prefs::kPasswordGenerationEnabled, this); |
202 notification_registrar_.Add(this, | 202 notification_registrar_.Add(this, |
203 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 203 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
204 content::Source<TabContents>(tab_contents)); | 204 content::Source<TabContents>(tab_contents)); |
205 } | 205 } |
206 | 206 |
207 AutofillManager::~AutofillManager() { | 207 AutofillManager::~AutofillManager() { |
208 } | 208 } |
209 | 209 |
210 // static | 210 // static |
211 void AutofillManager::RegisterUserPrefs(PrefService* prefs) { | 211 void AutofillManager::RegisterUserPrefs(PrefServiceBase* prefs) { |
212 prefs->RegisterBooleanPref(prefs::kAutofillEnabled, | 212 prefs->RegisterBooleanPref(prefs::kAutofillEnabled, |
213 true, | 213 true, |
214 PrefService::SYNCABLE_PREF); | 214 PrefServiceBase::SYNCABLE_PREF); |
215 prefs->RegisterBooleanPref(prefs::kPasswordGenerationEnabled, | 215 prefs->RegisterBooleanPref(prefs::kPasswordGenerationEnabled, |
216 true, | 216 true, |
217 PrefService::SYNCABLE_PREF); | 217 PrefServiceBase::SYNCABLE_PREF); |
218 #if defined(OS_MACOSX) | 218 #if defined(OS_MACOSX) |
219 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled, | 219 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled, |
220 true, | 220 true, |
221 PrefService::SYNCABLE_PREF); | 221 PrefServiceBase::SYNCABLE_PREF); |
222 #else | 222 #else |
223 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled, | 223 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled, |
224 false, | 224 false, |
225 PrefService::UNSYNCABLE_PREF); | 225 PrefServiceBase::UNSYNCABLE_PREF); |
226 #endif | 226 #endif |
227 prefs->RegisterDoublePref(prefs::kAutofillPositiveUploadRate, | 227 prefs->RegisterDoublePref(prefs::kAutofillPositiveUploadRate, |
228 kAutofillPositiveUploadRateDefaultValue, | 228 kAutofillPositiveUploadRateDefaultValue, |
229 PrefService::UNSYNCABLE_PREF); | 229 PrefServiceBase::UNSYNCABLE_PREF); |
230 prefs->RegisterDoublePref(prefs::kAutofillNegativeUploadRate, | 230 prefs->RegisterDoublePref(prefs::kAutofillNegativeUploadRate, |
231 kAutofillNegativeUploadRateDefaultValue, | 231 kAutofillNegativeUploadRateDefaultValue, |
232 PrefService::UNSYNCABLE_PREF); | 232 PrefServiceBase::UNSYNCABLE_PREF); |
233 } | 233 } |
234 | 234 |
235 void AutofillManager::RegisterWithSyncService() { | 235 void AutofillManager::RegisterWithSyncService() { |
236 ProfileSyncService* temp_sync_service = | 236 ProfileSyncService* temp_sync_service = |
237 ProfileSyncServiceFactory::GetForProfile(tab_contents_->profile()); | 237 ProfileSyncServiceFactory::GetForProfile(tab_contents_->profile()); |
238 if (temp_sync_service) | 238 if (temp_sync_service) |
239 temp_sync_service->AddObserver(this); | 239 temp_sync_service->AddObserver(this); |
240 } | 240 } |
241 | 241 |
242 void AutofillManager::SendPasswordGenerationStateToRenderer( | 242 void AutofillManager::SendPasswordGenerationStateToRenderer( |
(...skipping 17 matching lines...) Expand all Loading... |
260 syncer::ModelTypeSet sync_set = service->GetPreferredDataTypes(); | 260 syncer::ModelTypeSet sync_set = service->GetPreferredDataTypes(); |
261 password_sync_enabled = | 261 password_sync_enabled = |
262 service->HasSyncSetupCompleted() && sync_set.Has(syncer::PASSWORDS); | 262 service->HasSyncSetupCompleted() && sync_set.Has(syncer::PASSWORDS); |
263 } | 263 } |
264 | 264 |
265 bool password_manager_enabled = | 265 bool password_manager_enabled = |
266 tab_contents_->password_manager()->IsSavingEnabled(); | 266 tab_contents_->password_manager()->IsSavingEnabled(); |
267 | 267 |
268 Profile* profile = Profile::FromBrowserContext( | 268 Profile* profile = Profile::FromBrowserContext( |
269 web_contents()->GetBrowserContext()); | 269 web_contents()->GetBrowserContext()); |
270 bool preference_checked = | 270 bool preference_checked = PrefServiceBase::ForProfile(profile)->GetBoolean( |
271 profile->GetPrefs()->GetBoolean(prefs::kPasswordGenerationEnabled); | 271 prefs::kPasswordGenerationEnabled); |
272 | 272 |
273 bool new_password_generation_enabled = | 273 bool new_password_generation_enabled = |
274 password_sync_enabled && | 274 password_sync_enabled && |
275 password_manager_enabled && | 275 password_manager_enabled && |
276 preference_checked; | 276 preference_checked; |
277 | 277 |
278 if (new_password_generation_enabled != password_generation_enabled_ || | 278 if (new_password_generation_enabled != password_generation_enabled_ || |
279 new_renderer) { | 279 new_renderer) { |
280 password_generation_enabled_ = new_password_generation_enabled; | 280 password_generation_enabled_ = new_password_generation_enabled; |
281 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_); | 281 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_); |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 } | 808 } |
809 | 809 |
810 void AutofillManager::OnDidEndTextFieldEditing() { | 810 void AutofillManager::OnDidEndTextFieldEditing() { |
811 if (external_delegate_) | 811 if (external_delegate_) |
812 external_delegate_->DidEndTextFieldEditing(); | 812 external_delegate_->DidEndTextFieldEditing(); |
813 } | 813 } |
814 | 814 |
815 bool AutofillManager::IsAutofillEnabled() const { | 815 bool AutofillManager::IsAutofillEnabled() const { |
816 Profile* profile = Profile::FromBrowserContext( | 816 Profile* profile = Profile::FromBrowserContext( |
817 const_cast<AutofillManager*>(this)->web_contents()->GetBrowserContext()); | 817 const_cast<AutofillManager*>(this)->web_contents()->GetBrowserContext()); |
818 return profile->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 818 return PrefServiceBase::ForProfile(profile)->GetBoolean( |
| 819 prefs::kAutofillEnabled); |
819 } | 820 } |
820 | 821 |
821 void AutofillManager::SendAutofillTypePredictions( | 822 void AutofillManager::SendAutofillTypePredictions( |
822 const std::vector<FormStructure*>& forms) const { | 823 const std::vector<FormStructure*>& forms) const { |
823 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 824 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
824 switches::kShowAutofillTypePredictions)) | 825 switches::kShowAutofillTypePredictions)) |
825 return; | 826 return; |
826 | 827 |
827 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 828 RenderViewHost* host = web_contents()->GetRenderViewHost(); |
828 if (!host) | 829 if (!host) |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 *profile_guid = IDToGUID(profile_id); | 1413 *profile_guid = IDToGUID(profile_id); |
1413 } | 1414 } |
1414 | 1415 |
1415 void AutofillManager::UpdateInitialInteractionTimestamp( | 1416 void AutofillManager::UpdateInitialInteractionTimestamp( |
1416 const TimeTicks& interaction_timestamp) { | 1417 const TimeTicks& interaction_timestamp) { |
1417 if (initial_interaction_timestamp_.is_null() || | 1418 if (initial_interaction_timestamp_.is_null() || |
1418 interaction_timestamp < initial_interaction_timestamp_) { | 1419 interaction_timestamp < initial_interaction_timestamp_) { |
1419 initial_interaction_timestamp_ = interaction_timestamp; | 1420 initial_interaction_timestamp_ = interaction_timestamp; |
1420 } | 1421 } |
1421 } | 1422 } |
OLD | NEW |