diff options
-rw-r--r-- | base/mac_util.h | 23 | ||||
-rw-r--r-- | base/mac_util.mm | 42 | ||||
-rw-r--r-- | chrome/browser/importer/importer.cc | 23 | ||||
-rw-r--r-- | chrome/browser/password_manager/password_store_mac.cc | 28 | ||||
-rw-r--r-- | chrome/browser/password_manager/password_store_mac_internal.h | 7 | ||||
-rw-r--r-- | chrome/common/chrome_paths.cc | 5 |
6 files changed, 81 insertions, 47 deletions
diff --git a/base/mac_util.h b/base/mac_util.h index 43f0e5c..220d68e 100644 --- a/base/mac_util.h +++ b/base/mac_util.h @@ -5,7 +5,9 @@ #ifndef BASE_MAC_UTIL_H_ #define BASE_MAC_UTIL_H_ -struct FSRef; +#include <Carbon/Carbon.h> +#include <string> + class FilePath; #ifdef __OBJC__ @@ -14,8 +16,6 @@ class FilePath; class NSBundle; #endif -#include <string> - namespace mac_util { std::string PathFromFSRef(const FSRef& ref); @@ -29,14 +29,25 @@ bool AmIBundled(); // aren't a bundle. NSBundle* MainAppBundle(); -// Returns the ~/Library directory. -FilePath GetUserLibraryPath(); - // Set the bundle that MainAppBundle will return, overriding the default value // (Restore the default by calling SetOverrideAppBundle(nil)). void SetOverrideAppBundle(NSBundle* bundle); void SetOverrideAppBundlePath(const FilePath& file_path); +// Returns the creator code associated with the CFBundleRef at bundle. +OSType CreatorCodeForCFBundleRef(CFBundleRef bundle); + +// Returns the creator code associated with this application, by calling +// CreatorCodeForCFBundleRef for the application's main bundle. If this +// information cannot be determined, returns kUnknownType ('????'). This +// does not respect the override app bundle because it's based on CFBundle +// instead of NSBundle, and because callers probably don't want the override +// app bundle's creator code anyway. +OSType CreatorCodeForApplication(); + +// Returns the ~/Library directory. +FilePath GetUserLibraryPath(); + } // namespace mac_util #endif // BASE_MAC_UTIL_H_ diff --git a/base/mac_util.mm b/base/mac_util.mm index 5304b75..aebba8f 100644 --- a/base/mac_util.mm +++ b/base/mac_util.mm @@ -4,7 +4,6 @@ #include "base/mac_util.h" -#include <Carbon/Carbon.h> #import <Cocoa/Cocoa.h> #include "base/file_path.h" @@ -53,6 +52,35 @@ NSBundle* MainAppBundle() { return [NSBundle mainBundle]; } +void SetOverrideAppBundle(NSBundle* bundle) { + if (bundle != g_override_app_bundle) { + [g_override_app_bundle release]; + g_override_app_bundle = [bundle retain]; + } +} + +void SetOverrideAppBundlePath(const FilePath& file_path) { + NSString* path = base::SysUTF8ToNSString(file_path.value()); + NSBundle* bundle = [NSBundle bundleWithPath:path]; + DCHECK(bundle) << "failed to load the bundle: " << file_path.value(); + + SetOverrideAppBundle(bundle); +} + +OSType CreatorCodeForCFBundleRef(CFBundleRef bundle) { + OSType creator; + CFBundleGetPackageInfo(bundle, NULL, &creator); + return creator; +} + +OSType CreatorCodeForApplication() { + CFBundleRef bundle = CFBundleGetMainBundle(); + if (!bundle) + return kUnknownType; + + return CreatorCodeForCFBundleRef(bundle); +} + FilePath GetUserLibraryPath() { NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); @@ -67,17 +95,5 @@ FilePath GetUserLibraryPath() { return FilePath(library_dir_path); } -void SetOverrideAppBundle(NSBundle* bundle) { - [g_override_app_bundle release]; - g_override_app_bundle = [bundle retain]; -} - -void SetOverrideAppBundlePath(const FilePath& file_path) { - NSString* path = base::SysUTF8ToNSString(file_path.value()); - NSBundle* bundle = [NSBundle bundleWithPath:path]; - DCHECK(bundle) << "failed to load the bundle: " << file_path.value(); - - SetOverrideAppBundle(bundle); -} } // namespace mac_util diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index 904361a..994ee7e 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -9,12 +9,8 @@ #include "app/gfx/favicon_size.h" #include "app/l10n_util.h" -#if defined(OS_WIN) -#include "app/win_util.h" -#endif #include "base/file_util.h" #include "base/gfx/png_encoder.h" -#include "base/mac_util.h" #include "base/message_loop.h" #include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -26,16 +22,7 @@ #include "chrome/browser/importer/firefox3_importer.h" #include "chrome/browser/importer/firefox_importer_utils.h" #include "chrome/browser/importer/firefox_profile_lock.h" -#if defined(OS_WIN) -#include "chrome/browser/importer/ie_importer.h" -#endif -#if defined(OS_MACOSX) -#include "chrome/browser/importer/safari_importer.h" -#endif #include "chrome/browser/importer/toolbar_importer.h" -#if defined(OS_WIN) -#include "chrome/browser/password_manager/ie7_password.h" -#endif #include "chrome/browser/renderer_host/site_instance.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/shell_integration.h" @@ -56,6 +43,16 @@ #include "chrome/browser/gtk/import_lock_dialog_gtk.h" #endif +#if defined(OS_WIN) +#include "app/win_util.h" +#include "chrome/browser/importer/ie_importer.h" +#include "chrome/browser/password_manager/ie7_password.h" +#endif +#if defined(OS_MACOSX) +#include "base/mac_util.h" +#include "chrome/browser/importer/safari_importer.h" +#endif + using webkit_glue::PasswordForm; // ProfileWriter. diff --git a/chrome/browser/password_manager/password_store_mac.cc b/chrome/browser/password_manager/password_store_mac.cc index cc05047..594478a 100644 --- a/chrome/browser/password_manager/password_store_mac.cc +++ b/chrome/browser/password_manager/password_store_mac.cc @@ -10,6 +10,7 @@ #include <vector> #include "base/logging.h" +#include "base/mac_util.h" #include "base/stl_util-inl.h" #include "base/string_util.h" #include "chrome/browser/keychain_mac.h" @@ -17,8 +18,6 @@ using webkit_glue::PasswordForm; -static const OSType kChromeKeychainCreatorCode = 'rimZ'; - // Utility class to handle the details of constructing and running a keychain // search from a set of attributes. class KeychainSearch { @@ -438,7 +437,7 @@ void MergePasswordForms(std::vector<PasswordForm*>* keychain_forms, std::vector<PasswordForm*> GetPasswordsForForms( const MacKeychain& keychain, std::vector<PasswordForm*>* database_forms) { MacKeychainPasswordFormAdapter keychain_adapter(&keychain); - + std::vector<PasswordForm*> merged_forms; for (std::vector<PasswordForm*>::iterator i = database_forms->begin(); i != database_forms->end();) { @@ -507,13 +506,12 @@ std::vector<PasswordForm*> kSecAuthenticationTypeHTTPBasic, kSecAuthenticationTypeHTTPDigest, }; - OSType creator = finds_only_owned_ ? kChromeKeychainCreatorCode : 0; std::vector<SecKeychainItemRef> matches; for (unsigned int i = 0; i < arraysize(supported_auth_types); ++i) { KeychainSearch keychain_search(*keychain_); keychain_search.Init(NULL, 0, kSecProtocolTypeAny, supported_auth_types[i], - NULL, NULL, NULL, creator); + NULL, NULL, NULL, CreatorCodeForSearch()); keychain_search.FindMatchingItems(&matches); } @@ -547,7 +545,7 @@ bool MacKeychainPasswordFormAdapter::AddPassword(const PasswordForm& form) { password.size(), password.c_str(), &new_item); if (result == noErr) { - SetKeychainItemCreatorCode(new_item, kChromeKeychainCreatorCode); + SetKeychainItemCreatorCode(new_item, mac_util::CreatorCodeForApplication()); keychain_->Free(new_item); } else if (result == errSecDuplicateItem) { // If we collide with an existing item, find and update it instead. @@ -641,11 +639,9 @@ std::vector<SecKeychainItemRef> SecAuthenticationType auth_type = AuthTypeForScheme(scheme); const char* auth_domain = (scheme == PasswordForm::SCHEME_HTML) ? NULL : security_domain.c_str(); - OSType creator = finds_only_owned_ ? kChromeKeychainCreatorCode : 0; - KeychainSearch keychain_search(*keychain_); keychain_search.Init(server.c_str(), port, protocol, auth_type, - auth_domain, path, username, creator); + auth_domain, path, username, CreatorCodeForSearch()); keychain_search.FindMatchingItems(&matches); return matches; } @@ -705,6 +701,10 @@ bool MacKeychainPasswordFormAdapter::SetKeychainItemCreatorCode( return result == noErr; } +OSType MacKeychainPasswordFormAdapter::CreatorCodeForSearch() { + return finds_only_owned_ ? mac_util::CreatorCodeForApplication() : 0; +} + #pragma mark - PasswordStoreMac::PasswordStoreMac(MacKeychain* keychain, @@ -813,15 +813,15 @@ void PasswordStoreMac::GetBlacklistLoginsImpl(GetLoginsRequest* request) { void PasswordStoreMac::GetAutofillableLoginsImpl(GetLoginsRequest* request) { std::vector<PasswordForm*> database_forms; login_metadata_db_->GetAutofillableLogins(&database_forms); - + std::vector<PasswordForm*> merged_forms = internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms); - + // Clean up any orphaned database entries. RemoveDatabaseForms(database_forms); STLDeleteElements(&database_forms); - + NotifyConsumer(request, merged_forms); } @@ -853,12 +853,12 @@ bool PasswordStoreMac::DatabaseHasFormMatchingKeychainForm( std::vector<PasswordForm*> PasswordStoreMac::GetUnusedKeychainForms() { std::vector<PasswordForm*> database_forms; login_metadata_db_->GetAutofillableLogins(&database_forms); - + MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_.get()); owned_keychain_adapter.SetFindsOnlyOwnedItems(true); std::vector<PasswordForm*> owned_keychain_forms = owned_keychain_adapter.GetAllPasswordFormPasswords(); - + // Run a merge; anything left in owned_keychain_forms when we are done no // longer has a matching database entry. std::vector<PasswordForm*> merged_forms; diff --git a/chrome/browser/password_manager/password_store_mac_internal.h b/chrome/browser/password_manager/password_store_mac_internal.h index 59dd2f2..223c20e 100644 --- a/chrome/browser/password_manager/password_store_mac_internal.h +++ b/chrome/browser/password_manager/password_store_mac_internal.h @@ -101,6 +101,13 @@ class MacKeychainPasswordFormAdapter { bool SetKeychainItemCreatorCode(const SecKeychainItemRef& keychain_item, OSType creator_code); + // Returns the creator code to be used for a Keychain search, depending on + // whether this object was instructed to search only for items it created. + // If searches should be restricted in this way, the application-specific + // creator code will be returned. Otherwise, 0 will be returned, indicating + // a search of all items, regardless of creator. + OSType CreatorCodeForSearch(); + const MacKeychain* keychain_; // If true, Keychain searches are restricted to items created by Chrome. diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc index e8f26b6..2460f49 100644 --- a/chrome/common/chrome_paths.cc +++ b/chrome/common/chrome_paths.cc @@ -8,7 +8,6 @@ #include "base/file_path.h" #include "base/file_util.h" #include "base/logging.h" -#include "base/mac_util.h" #include "base/path_service.h" #include "base/string_util.h" #include "base/sys_info.h" @@ -16,6 +15,10 @@ #include "chrome/common/chrome_paths_internal.h" #include "chrome/common/chrome_switches.h" +#if defined(OS_MACOSX) +#include "base/mac_util.h" +#endif + namespace chrome { bool GetGearsPluginPathFromCommandLine(FilePath* path) { |