Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: components/autofill/core/browser/personal_data_manager_mac.mm

Issue 301343002: mac: Clean up autofill integration with Address Book. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@autofill_cleanup2_base
Patch Set: Address comments from isherman. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/personal_data_manager.h" 5 #include "components/autofill/core/browser/personal_data_manager.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #import <AddressBook/AddressBook.h> 9 #import <AddressBook/AddressBook.h>
10 10
(...skipping 19 matching lines...) Expand all
30 30
31 namespace autofill { 31 namespace autofill {
32 namespace { 32 namespace {
33 33
34 const char kAddressBookOrigin[] = "OS X Address Book"; 34 const char kAddressBookOrigin[] = "OS X Address Book";
35 35
36 // Whether Chrome has prompted the user for permission to access the user's 36 // Whether Chrome has prompted the user for permission to access the user's
37 // address book. 37 // address book.
38 bool HasPromptedForAccessToAddressBook(PrefService* pref_service) { 38 bool HasPromptedForAccessToAddressBook(PrefService* pref_service) {
39 return pref_service->GetBoolean(prefs::kAutofillAuxiliaryProfilesQueried); 39 return pref_service->GetBoolean(prefs::kAutofillAuxiliaryProfilesQueried);
40 } 40 }
Ilya Sherman 2014/06/02 22:54:27 nit: Please leave a blank line after this one.
erikchen 2014/06/03 01:34:19 Done.
41 // Whether the user wants Chrome to use the AddressBook to populate autofill
42 // entries.
43 bool ShouldUseAddressBook(PrefService* pref_service) {
44 return pref_service->GetBoolean(prefs::kAutofillUseMacAddressBook);
45 }
41 46
42 ABAddressBook* GetAddressBook(PrefService* pref_service) { 47 ABAddressBook* GetAddressBook(PrefService* pref_service) {
43 bool first_access = !HasPromptedForAccessToAddressBook(pref_service); 48 bool first_access = !HasPromptedForAccessToAddressBook(pref_service);
44 49
45 // +[ABAddressBook sharedAddressBook] throws an exception internally in 50 // +[ABAddressBook sharedAddressBook] throws an exception internally in
46 // circumstances that aren't clear. The exceptions are only observed in crash 51 // circumstances that aren't clear. The exceptions are only observed in crash
47 // reports, so it is unknown whether they would be caught by AppKit and nil 52 // reports, so it is unknown whether they would be caught by AppKit and nil
48 // returned, or if they would take down the app. In either case, avoid 53 // returned, or if they would take down the app. In either case, avoid
49 // crashing. http://crbug.com/129022 54 // crashing. http://crbug.com/129022
50 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions( 55 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 }; 108 };
104 109
105 // This method uses the |ABAddressBook| system service to fetch the "me" card 110 // This method uses the |ABAddressBook| system service to fetch the "me" card
106 // from the active user's address book. It looks for the user address 111 // from the active user's address book. It looks for the user address
107 // information and translates it to the internal list of |AutofillProfile| data 112 // information and translates it to the internal list of |AutofillProfile| data
108 // structures. 113 // structures.
109 void AuxiliaryProfilesImpl::GetAddressBookMeCard(const std::string& app_locale, 114 void AuxiliaryProfilesImpl::GetAddressBookMeCard(const std::string& app_locale,
110 PrefService* pref_service) { 115 PrefService* pref_service) {
111 profiles_.clear(); 116 profiles_.clear();
112 117
113 // Chrome has not yet requested address book permissions. Attempting to do so 118 // The user does not want Chrome to use the AddressBook to populate autofill
114 // presents a blocking modal dialog, which is undesirable. Instead, just show 119 // entries.
115 // no results. 120 if (!ShouldUseAddressBook(pref_service))
116 if (!HasPromptedForAccessToAddressBook(pref_service))
117 return; 121 return;
118 122
119 ABAddressBook* addressBook = GetAddressBook(pref_service); 123 ABAddressBook* addressBook = GetAddressBook(pref_service);
120 124
121 ABPerson* me = [addressBook me]; 125 ABPerson* me = [addressBook me];
122 if (!me) 126 if (!me)
123 return; 127 return;
124 128
125 ABMultiValue* addresses = [me valueForProperty:kABAddressProperty]; 129 ABMultiValue* addresses = [me valueForProperty:kABAddressProperty];
126 130
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 301
298 } // namespace 302 } // namespace
299 303
300 // Populate |auxiliary_profiles_| with the Address Book data. 304 // Populate |auxiliary_profiles_| with the Address Book data.
301 void PersonalDataManager::LoadAuxiliaryProfiles() const { 305 void PersonalDataManager::LoadAuxiliaryProfiles() const {
302 AuxiliaryProfilesImpl impl(&auxiliary_profiles_); 306 AuxiliaryProfilesImpl impl(&auxiliary_profiles_);
303 impl.GetAddressBookMeCard(app_locale_, pref_service_); 307 impl.GetAddressBookMeCard(app_locale_, pref_service_);
304 } 308 }
305 309
306 bool PersonalDataManager::AccessAddressBook() { 310 bool PersonalDataManager::AccessAddressBook() {
307 if (!pref_service_->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)) 311 // The user is attempting to give Chrome access to the user's Address Book.
308 return false; 312 // This implicitly acknowledges that the user wants to use auxiliary
309 313 // profiles.
310 if (HasPromptedForAccessToAddressBook(pref_service_)) 314 pref_service_->SetBoolean(prefs::kAutofillUseMacAddressBook, true);
erikchen 2014/06/02 21:21:17 I've intentionally removed the check against the p
311 return false;
312 315
313 // Request permissions. 316 // Request permissions.
314 GetAddressBook(pref_service_); 317 GetAddressBook(pref_service_);
315 return true; 318 return true;
316 } 319 }
317 320
318 bool PersonalDataManager::ShouldShowAccessAddressBookSuggestion( 321 bool PersonalDataManager::ShouldShowAccessAddressBookSuggestion(
319 AutofillType type) { 322 AutofillType type) {
320 if (!pref_service_->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled))
321 return false;
322
323 if (HasPromptedForAccessToAddressBook(pref_service_)) 323 if (HasPromptedForAccessToAddressBook(pref_service_))
324 return false; 324 return false;
325 325
326 switch (type.group()) { 326 switch (type.group()) {
327 case ADDRESS_BILLING: 327 case ADDRESS_BILLING:
328 case ADDRESS_HOME: 328 case ADDRESS_HOME:
329 case EMAIL: 329 case EMAIL:
330 case NAME: 330 case NAME:
331 case NAME_BILLING: 331 case NAME_BILLING:
332 case PHONE_BILLING: 332 case PHONE_BILLING:
333 case PHONE_HOME: 333 case PHONE_HOME:
334 return true; 334 return true;
335 case NO_GROUP: 335 case NO_GROUP:
336 case COMPANY: 336 case COMPANY:
337 case CREDIT_CARD: 337 case CREDIT_CARD:
338 case PASSWORD_FIELD: 338 case PASSWORD_FIELD:
339 return false; 339 return false;
340 } 340 }
341 341
342 return false; 342 return false;
343 } 343 }
344 344
345 } // namespace autofill 345 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698