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 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 true, | 205 true, |
206 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 206 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
207 #else // defined(OS_MACOSX) || defined(OS_ANDROID) | 207 #else // defined(OS_MACOSX) || defined(OS_ANDROID) |
208 registry->RegisterBooleanPref( | 208 registry->RegisterBooleanPref( |
209 prefs::kAutofillAuxiliaryProfilesEnabled, | 209 prefs::kAutofillAuxiliaryProfilesEnabled, |
210 false, | 210 false, |
211 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 211 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
212 #endif // defined(OS_MACOSX) || defined(OS_ANDROID) | 212 #endif // defined(OS_MACOSX) || defined(OS_ANDROID) |
213 #if defined(OS_MACOSX) | 213 #if defined(OS_MACOSX) |
214 registry->RegisterBooleanPref( | 214 registry->RegisterBooleanPref( |
215 prefs::kAutofillAuxiliaryProfilesQueried, | 215 prefs::kAutofillMacAddressBookQueried, |
216 false, | 216 false, |
217 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 217 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
218 #endif // defined(OS_MACOSX) | 218 #endif // defined(OS_MACOSX) |
219 registry->RegisterDoublePref( | 219 registry->RegisterDoublePref( |
220 prefs::kAutofillPositiveUploadRate, | 220 prefs::kAutofillPositiveUploadRate, |
221 kAutofillPositiveUploadRateDefaultValue, | 221 kAutofillPositiveUploadRateDefaultValue, |
222 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 222 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
223 registry->RegisterDoublePref( | 223 registry->RegisterDoublePref( |
224 prefs::kAutofillNegativeUploadRate, | 224 prefs::kAutofillNegativeUploadRate, |
225 kAutofillNegativeUploadRateDefaultValue, | 225 kAutofillNegativeUploadRateDefaultValue, |
226 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 226 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 227 |
| 228 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 229 registry->RegisterBooleanPref( |
| 230 prefs::kAutofillUseMacAddressBook, |
| 231 false, |
| 232 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 233 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
227 } | 234 } |
228 | 235 |
| 236 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 237 void AutofillManager::MigrateUserPrefs(PrefService* prefs) { |
| 238 const PrefService::Preference* pref = |
| 239 prefs->FindPreference(prefs::kAutofillUseMacAddressBook); |
| 240 |
| 241 // If the pref is not its default value, then the migration has already been |
| 242 // performed. |
| 243 if (!pref->IsDefaultValue()) |
| 244 return; |
| 245 |
| 246 // Whether Chrome has already tried to access the user's Address Book. |
| 247 const PrefService::Preference* pref_accessed = |
| 248 prefs->FindPreference(prefs::kAutofillMacAddressBookQueried); |
| 249 // Whether the user wants to use the Address Book to populate Autofill. |
| 250 const PrefService::Preference* pref_enabled = |
| 251 prefs->FindPreference(prefs::kAutofillAuxiliaryProfilesEnabled); |
| 252 |
| 253 if (pref_accessed->IsDefaultValue() && pref_enabled->IsDefaultValue()) { |
| 254 // This is likely a new user. Reset the default value to prevent the |
| 255 // migration from happening again. |
| 256 prefs->SetBoolean(prefs::kAutofillUseMacAddressBook, |
| 257 prefs->GetBoolean(prefs::kAutofillUseMacAddressBook)); |
| 258 return; |
| 259 } |
| 260 |
| 261 bool accessed; |
| 262 bool enabled; |
| 263 bool success = pref_accessed->GetValue()->GetAsBoolean(&accessed); |
| 264 DCHECK(success); |
| 265 success = pref_enabled->GetValue()->GetAsBoolean(&enabled); |
| 266 DCHECK(success); |
| 267 |
| 268 prefs->SetBoolean(prefs::kAutofillUseMacAddressBook, accessed && enabled); |
| 269 } |
| 270 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 271 |
229 void AutofillManager::SetExternalDelegate(AutofillExternalDelegate* delegate) { | 272 void AutofillManager::SetExternalDelegate(AutofillExternalDelegate* delegate) { |
230 // TODO(jrg): consider passing delegate into the ctor. That won't | 273 // TODO(jrg): consider passing delegate into the ctor. That won't |
231 // work if the delegate has a pointer to the AutofillManager, but | 274 // work if the delegate has a pointer to the AutofillManager, but |
232 // future directions may not need such a pointer. | 275 // future directions may not need such a pointer. |
233 external_delegate_ = delegate; | 276 external_delegate_ = delegate; |
234 autocomplete_history_manager_->SetExternalDelegate(delegate); | 277 autocomplete_history_manager_->SetExternalDelegate(delegate); |
235 } | 278 } |
236 | 279 |
237 void AutofillManager::ShowAutofillSettings() { | 280 void AutofillManager::ShowAutofillSettings() { |
238 client_->ShowAutofillSettings(); | 281 client_->ShowAutofillSettings(); |
239 } | 282 } |
240 | 283 |
| 284 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 285 bool AutofillManager::ShouldShowAccessAddressBookSuggestion( |
| 286 const FormData& form, |
| 287 const FormFieldData& field) { |
| 288 if (!personal_data_) |
| 289 return false; |
| 290 FormStructure* form_structure = NULL; |
| 291 AutofillField* autofill_field = NULL; |
| 292 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) |
| 293 return false; |
| 294 |
| 295 return personal_data_->ShouldShowAccessAddressBookSuggestion( |
| 296 autofill_field->Type()); |
| 297 } |
| 298 |
| 299 bool AutofillManager::AccessAddressBook() { |
| 300 if (!personal_data_) |
| 301 return false; |
| 302 return personal_data_->AccessAddressBook(); |
| 303 } |
| 304 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 305 |
241 bool AutofillManager::OnFormSubmitted(const FormData& form, | 306 bool AutofillManager::OnFormSubmitted(const FormData& form, |
242 const TimeTicks& timestamp) { | 307 const TimeTicks& timestamp) { |
243 if (!IsValidFormData(form)) | 308 if (!IsValidFormData(form)) |
244 return false; | 309 return false; |
245 | 310 |
246 // Let Autocomplete know as well. | 311 // Let Autocomplete know as well. |
247 autocomplete_history_manager_->OnFormSubmitted(form); | 312 autocomplete_history_manager_->OnFormSubmitted(form); |
248 | 313 |
249 // Grab a copy of the form data. | 314 // Grab a copy of the form data. |
250 scoped_ptr<FormStructure> submitted_form(new FormStructure(form)); | 315 scoped_ptr<FormStructure> submitted_form(new FormStructure(form)); |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 return false; | 1206 return false; |
1142 | 1207 |
1143 // Disregard forms that we wouldn't ever autofill in the first place. | 1208 // Disregard forms that we wouldn't ever autofill in the first place. |
1144 if (!form.ShouldBeParsed(true)) | 1209 if (!form.ShouldBeParsed(true)) |
1145 return false; | 1210 return false; |
1146 | 1211 |
1147 return true; | 1212 return true; |
1148 } | 1213 } |
1149 | 1214 |
1150 } // namespace autofill | 1215 } // namespace autofill |
OLD | NEW |