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

Side by Side Diff: chrome/browser/password_manager/password_store_mac_internal.h

Issue 10875029: Rename MacKeychain to AppleKeychain (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address Avi's code review: add NStoCFCast and other nits. Created 8 years, 3 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 (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 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_
7 7
8 #include <Security/Security.h> 8 #include <Security/Security.h>
9 9
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "crypto/keychain_mac.h" 14 #include "crypto/apple_keychain.h"
15 15
16 using crypto::MacKeychain; 16 using crypto::AppleKeychain;
17 17
18 // Adapter that wraps a MacKeychain and provides interaction in terms of 18 // Adapter that wraps a AppleKeychain and provides interaction in terms of
19 // PasswordForms instead of Keychain items. 19 // PasswordForms instead of Keychain items.
20 class MacKeychainPasswordFormAdapter { 20 class MacKeychainPasswordFormAdapter {
21 public: 21 public:
22 // Creates an adapter for |keychain|. This class does not take ownership of 22 // Creates an adapter for |keychain|. This class does not take ownership of
23 // |keychain|, so the caller must make sure that the keychain outlives the 23 // |keychain|, so the caller must make sure that the keychain outlives the
24 // created object. 24 // created object.
25 explicit MacKeychainPasswordFormAdapter(const MacKeychain* keychain); 25 explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain);
26 26
27 // Returns PasswordForms for each keychain entry that could be used to fill 27 // Returns PasswordForms for each keychain entry that could be used to fill
28 // |form|. Caller is responsible for deleting the returned forms. 28 // |form|. Caller is responsible for deleting the returned forms.
29 std::vector<webkit::forms::PasswordForm*> PasswordsFillingForm( 29 std::vector<webkit::forms::PasswordForm*> PasswordsFillingForm(
30 const webkit::forms::PasswordForm& query_form); 30 const webkit::forms::PasswordForm& query_form);
31 31
32 // Returns PasswordForms for each keychain entry that could be merged with 32 // Returns PasswordForms for each keychain entry that could be merged with
33 // |form|. Differs from PasswordsFillingForm in that the username must match. 33 // |form|. Differs from PasswordsFillingForm in that the username must match.
34 // Caller is responsible for deleting the returned forms. 34 // Caller is responsible for deleting the returned forms.
35 std::vector<webkit::forms::PasswordForm*> PasswordsMergeableWithForm( 35 std::vector<webkit::forms::PasswordForm*> PasswordsMergeableWithForm(
(...skipping 24 matching lines...) Expand all
60 // Removes the keychain password matching |form| if any. Returns true if a 60 // Removes the keychain password matching |form| if any. Returns true if a
61 // keychain item was found and successfully removed. 61 // keychain item was found and successfully removed.
62 bool RemovePassword(const webkit::forms::PasswordForm& form); 62 bool RemovePassword(const webkit::forms::PasswordForm& form);
63 63
64 // Controls whether or not Chrome will restrict Keychain searches to items 64 // Controls whether or not Chrome will restrict Keychain searches to items
65 // that it created. Defaults to false. 65 // that it created. Defaults to false.
66 void SetFindsOnlyOwnedItems(bool finds_only_owned); 66 void SetFindsOnlyOwnedItems(bool finds_only_owned);
67 67
68 private: 68 private:
69 // Returns PasswordForms constructed from the given Keychain items, calling 69 // Returns PasswordForms constructed from the given Keychain items, calling
70 // MacKeychain::Free on all of the keychain items and clearing the vector. 70 // AppleKeychain::Free on all of the keychain items and clearing the vector.
71 // Caller is responsible for deleting the returned forms. 71 // Caller is responsible for deleting the returned forms.
72 std::vector<webkit::forms::PasswordForm*> ConvertKeychainItemsToForms( 72 std::vector<webkit::forms::PasswordForm*> ConvertKeychainItemsToForms(
73 std::vector<SecKeychainItemRef>* items); 73 std::vector<SecKeychainItemRef>* items);
74 74
75 // Searches |keychain| for the specific keychain entry that corresponds to the 75 // Searches |keychain| for the specific keychain entry that corresponds to the
76 // given form, and returns it (or NULL if no match is found). The caller is 76 // given form, and returns it (or NULL if no match is found). The caller is
77 // responsible for calling MacKeychain::Free on on the returned item. 77 // responsible for calling AppleKeychain::Free on on the returned item.
78 SecKeychainItemRef KeychainItemForForm( 78 SecKeychainItemRef KeychainItemForForm(
79 const webkit::forms::PasswordForm& form); 79 const webkit::forms::PasswordForm& form);
80 80
81 // Returns the Keychain items matching the given signon_realm, scheme, and 81 // Returns the Keychain items matching the given signon_realm, scheme, and
82 // optionally path and username (either of both can be NULL). 82 // optionally path and username (either of both can be NULL).
83 // The caller is responsible for calling MacKeychain::Free on the 83 // The caller is responsible for calling AppleKeychain::Free on the
84 // returned items. 84 // returned items.
85 std::vector<SecKeychainItemRef> MatchingKeychainItems( 85 std::vector<SecKeychainItemRef> MatchingKeychainItems(
86 const std::string& signon_realm, 86 const std::string& signon_realm,
87 webkit::forms::PasswordForm::Scheme scheme, 87 webkit::forms::PasswordForm::Scheme scheme,
88 const char* path, 88 const char* path,
89 const char* username); 89 const char* username);
90 90
91 // Takes a PasswordForm's signon_realm and parses it into its component parts, 91 // Takes a PasswordForm's signon_realm and parses it into its component parts,
92 // which are returned though the appropriate out parameters. 92 // which are returned though the appropriate out parameters.
93 // Returns true if it can be successfully parsed, in which case all out params 93 // Returns true if it can be successfully parsed, in which case all out params
(...skipping 18 matching lines...) Expand all
112 bool SetKeychainItemCreatorCode(const SecKeychainItemRef& keychain_item, 112 bool SetKeychainItemCreatorCode(const SecKeychainItemRef& keychain_item,
113 OSType creator_code); 113 OSType creator_code);
114 114
115 // Returns the creator code to be used for a Keychain search, depending on 115 // Returns the creator code to be used for a Keychain search, depending on
116 // whether this object was instructed to search only for items it created. 116 // whether this object was instructed to search only for items it created.
117 // If searches should be restricted in this way, the application-specific 117 // If searches should be restricted in this way, the application-specific
118 // creator code will be returned. Otherwise, 0 will be returned, indicating 118 // creator code will be returned. Otherwise, 0 will be returned, indicating
119 // a search of all items, regardless of creator. 119 // a search of all items, regardless of creator.
120 OSType CreatorCodeForSearch(); 120 OSType CreatorCodeForSearch();
121 121
122 const MacKeychain* keychain_; 122 const AppleKeychain* keychain_;
123 123
124 // If true, Keychain searches are restricted to items created by Chrome. 124 // If true, Keychain searches are restricted to items created by Chrome.
125 bool finds_only_owned_; 125 bool finds_only_owned_;
126 126
127 DISALLOW_COPY_AND_ASSIGN(MacKeychainPasswordFormAdapter); 127 DISALLOW_COPY_AND_ASSIGN(MacKeychainPasswordFormAdapter);
128 }; 128 };
129 129
130 namespace internal_keychain_helpers { 130 namespace internal_keychain_helpers {
131 131
132 // Sets the fields of |form| based on the keychain data from |keychain_item|. 132 // Sets the fields of |form| based on the keychain data from |keychain_item|.
133 // Fields that can't be determined from |keychain_item| will be unchanged. 133 // Fields that can't be determined from |keychain_item| will be unchanged.
134 // 134 //
135 // IMPORTANT: This function can cause the OS to trigger UI (to allow access to 135 // IMPORTANT: This function can cause the OS to trigger UI (to allow access to
136 // the keychain item if we aren't trusted for the item), and block until the UI 136 // the keychain item if we aren't trusted for the item), and block until the UI
137 // is dismissed. 137 // is dismissed.
138 // 138 //
139 // If excessive prompting for access to other applications' keychain items 139 // If excessive prompting for access to other applications' keychain items
140 // becomes an issue, the password storage API will need to be refactored to 140 // becomes an issue, the password storage API will need to be refactored to
141 // allow the password to be retrieved later (accessing other fields doesn't 141 // allow the password to be retrieved later (accessing other fields doesn't
142 // require authorization). 142 // require authorization).
143 bool FillPasswordFormFromKeychainItem(const MacKeychain& keychain, 143 bool FillPasswordFormFromKeychainItem(const AppleKeychain& keychain,
144 const SecKeychainItemRef& keychain_item, 144 const SecKeychainItemRef& keychain_item,
145 webkit::forms::PasswordForm* form); 145 webkit::forms::PasswordForm* form);
146 146
147 // Returns true if the two given forms match based on signon_reaml, scheme, and 147 // Returns true if the two given forms match based on signon_reaml, scheme, and
148 // username_value, and are thus suitable for merging (see MergePasswordForms). 148 // username_value, and are thus suitable for merging (see MergePasswordForms).
149 bool FormsMatchForMerge(const webkit::forms::PasswordForm& form_a, 149 bool FormsMatchForMerge(const webkit::forms::PasswordForm& form_a,
150 const webkit::forms::PasswordForm& form_b); 150 const webkit::forms::PasswordForm& form_b);
151 151
152 // Populates merged_forms by combining the password data from keychain_forms and 152 // Populates merged_forms by combining the password data from keychain_forms and
153 // the metadata from database_forms, removing used entries from the two source 153 // the metadata from database_forms, removing used entries from the two source
154 // lists. 154 // lists.
155 // 155 //
156 // On return, database_forms and keychain_forms will have only unused 156 // On return, database_forms and keychain_forms will have only unused
157 // entries; for database_forms that means entries for which no corresponding 157 // entries; for database_forms that means entries for which no corresponding
158 // password can be found (and which aren't blacklist entries), and for 158 // password can be found (and which aren't blacklist entries), and for
159 // keychain_forms it's entries that weren't merged into at least one database 159 // keychain_forms its entries that weren't merged into at least one database
160 // form. 160 // form.
161 void MergePasswordForms( 161 void MergePasswordForms(
162 std::vector<webkit::forms::PasswordForm*>* keychain_forms, 162 std::vector<webkit::forms::PasswordForm*>* keychain_forms,
163 std::vector<webkit::forms::PasswordForm*>* database_forms, 163 std::vector<webkit::forms::PasswordForm*>* database_forms,
164 std::vector<webkit::forms::PasswordForm*>* merged_forms); 164 std::vector<webkit::forms::PasswordForm*>* merged_forms);
165 165
166 // Fills in the passwords for as many of the forms in |database_forms| as 166 // Fills in the passwords for as many of the forms in |database_forms| as
167 // possible using entries from |keychain| and returns them. On return, 167 // possible using entries from |keychain| and returns them. On return,
168 // |database_forms| will contain only the forms for which no password was found. 168 // |database_forms| will contain only the forms for which no password was found.
169 std::vector<webkit::forms::PasswordForm*> GetPasswordsForForms( 169 std::vector<webkit::forms::PasswordForm*> GetPasswordsForForms(
170 const MacKeychain& keychain, 170 const AppleKeychain& keychain,
171 std::vector<webkit::forms::PasswordForm*>* database_forms); 171 std::vector<webkit::forms::PasswordForm*>* database_forms);
172 172
173 } // internal_keychain_helpers 173 } // internal_keychain_helpers
174 174
175 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ 175 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_mac.cc ('k') | chrome/browser/password_manager/password_store_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698