diff options
Diffstat (limited to 'chrome')
20 files changed, 156 insertions, 1336 deletions
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index 7ebef21..52afa04 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -1524,31 +1524,15 @@ > </File> <File - RelativePath=".\password_manager\password_manager.cc" - > - </File> - <File - RelativePath=".\password_manager\password_manager.h" - > - </File> - <File - RelativePath=".\password_manager\password_store.cc" + RelativePath=".\password_manager\password_form_manager_win.cc" > </File> <File - RelativePath=".\password_manager\password_store.h" - > - </File> - <File - RelativePath=".\password_manager\password_store_default.cc" - > - </File> - <File - RelativePath=".\password_manager\password_store_default.h" + RelativePath=".\password_manager\password_manager.cc" > </File> <File - RelativePath=".\password_manager\password_store_win.cc" + RelativePath=".\password_manager\password_manager.h" > </File> <File diff --git a/chrome/browser/password_manager/password_form_manager.cc b/chrome/browser/password_manager/password_form_manager.cc index 26ebd4c..cf40a1b 100644 --- a/chrome/browser/password_manager/password_form_manager.cc +++ b/chrome/browser/password_manager/password_form_manager.cc @@ -21,7 +21,7 @@ PasswordFormManager::PasswordFormManager(Profile* profile, observed_form_(observed_form), is_new_login_(true), password_manager_(password_manager), - pending_login_query_(0), + pending_login_query_(NULL), preferred_match_(NULL), state_(PRE_MATCHING_PHASE), profile_(profile) { @@ -168,21 +168,25 @@ void PasswordFormManager::FetchMatchingLoginsFromWebDatabase() { DCHECK_EQ(state_, PRE_MATCHING_PHASE); DCHECK(!pending_login_query_); state_ = MATCHING_PHASE; - PasswordStore* password_store = - profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); - if (!password_store) { + WebDataService* web_data_service = + profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); + if (!web_data_service) { NOTREACHED(); return; } - pending_login_query_ = password_store->GetLogins(observed_form_, this); + pending_login_query_ = web_data_service->GetLogins(observed_form_, this); } bool PasswordFormManager::HasCompletedMatching() { return state_ == POST_MATCHING_PHASE; } -void PasswordFormManager::OnRequestDone(int handle, - const std::vector<PasswordForm*>& logins_result) { +void PasswordFormManager::OnRequestDone(WebDataService::Handle h, + const WDTypedResult* result) { + // Get the result from the database into a usable form. + const WDResult<std::vector<PasswordForm*> >* r = + static_cast<const WDResult<std::vector<PasswordForm*> >*>(result); + std::vector<PasswordForm*> logins_result = r->GetValue(); // Note that the result gets deleted after this call completes, but we own // the PasswordForm objects pointed to by the result vector, thus we keep // copies to a minimum here. @@ -235,6 +239,14 @@ void PasswordFormManager::OnRequestDone(int handle, // We're done matching now. state_ = POST_MATCHING_PHASE; + if (best_score <= 0) { +#if defined(OS_WIN) + state_ = PRE_MATCHING_PHASE; + FetchMatchingIE7LoginFromWebDatabase(); +#endif + return; + } + for (std::vector<PasswordForm>::const_iterator it = empties.begin(); it != empties.end(); ++it) { // If we don't already have a result with the same username, add the @@ -260,17 +272,30 @@ void PasswordFormManager::OnRequestDone(int handle, } } -void PasswordFormManager::OnPasswordStoreRequestDone( - int handle, const std::vector<PasswordForm*>& result) { +void PasswordFormManager::OnWebDataServiceRequestDone(WebDataService::Handle h, + const WDTypedResult* result) { DCHECK_EQ(state_, MATCHING_PHASE); - DCHECK_EQ(pending_login_query_, handle); + DCHECK_EQ(pending_login_query_, h); + DCHECK(result); + pending_login_query_ = NULL; - if (result.empty()) { - state_ = POST_MATCHING_PHASE; + if (!result) return; - } - OnRequestDone(handle, result); + switch (result->GetType()) { + case PASSWORD_RESULT: { + OnRequestDone(h, result); + break; + } +#if defined(OS_WIN) + case PASSWORD_IE7_RESULT: { + OnIE7RequestDone(h, result); + break; + } +#endif + default: + NOTREACHED(); + } } bool PasswordFormManager::IgnoreResult(const PasswordForm& form) const { @@ -297,15 +322,14 @@ void PasswordFormManager::SaveAsNewLogin() { DCHECK(!profile_->IsOffTheRecord()); - PasswordStore* password_store = - profile_->GetPasswordStore(Profile::IMPLICIT_ACCESS); - if (!password_store) { + WebDataService* web_data_service = + profile_->GetWebDataService(Profile::IMPLICIT_ACCESS); + if (!web_data_service) { NOTREACHED(); return; } - pending_credentials_.date_created = Time::Now(); - password_store->AddLogin(pending_credentials_); + web_data_service->AddLogin(pending_credentials_); } void PasswordFormManager::UpdateLogin() { @@ -317,9 +341,9 @@ void PasswordFormManager::UpdateLogin() { DCHECK(!IsNewLogin() && pending_credentials_.preferred); DCHECK(!profile_->IsOffTheRecord()); - PasswordStore* password_store = - profile_->GetPasswordStore(Profile::IMPLICIT_ACCESS); - if (!password_store) { + WebDataService* web_data_service = + profile_->GetWebDataService(Profile::IMPLICIT_ACCESS); + if (!web_data_service) { NOTREACHED(); return; } @@ -331,7 +355,7 @@ void PasswordFormManager::UpdateLogin() { iter->second->preferred) { // This wasn't the selected login but it used to be preferred. iter->second->preferred = false; - password_store->UpdateLogin(*iter->second); + web_data_service->UpdateLogin(*iter->second); } } // Update the new preferred login. @@ -356,20 +380,23 @@ void PasswordFormManager::UpdateLogin() { PasswordForm copy(pending_credentials_); copy.origin = observed_form_.origin; copy.action = observed_form_.action; - password_store->AddLogin(copy); + web_data_service->AddLogin(copy); } else { - password_store->UpdateLogin(pending_credentials_); + web_data_service->UpdateLogin(pending_credentials_); } } void PasswordFormManager::CancelLoginsQuery() { - PasswordStore* password_store = - profile_->GetPasswordStore(Profile::IMPLICIT_ACCESS); - if (!password_store) { - // Can be NULL in unit tests. + if (!pending_login_query_) + return; + WebDataService* web_data_service = + profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); + if (!web_data_service) { + NOTREACHED(); return; } - password_store->CancelLoginsQuery(pending_login_query_); + web_data_service->CancelRequest(pending_login_query_); + pending_login_query_ = NULL; } int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { diff --git a/chrome/browser/password_manager/password_form_manager.h b/chrome/browser/password_manager/password_form_manager.h index 90ffc86..332eea3 100644 --- a/chrome/browser/password_manager/password_form_manager.h +++ b/chrome/browser/password_manager/password_form_manager.h @@ -8,7 +8,6 @@ #include "build/build_config.h" #include "base/stl_util-inl.h" -#include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/webdata/web_data_service.h" #include "webkit/glue/password_form.h" @@ -17,7 +16,7 @@ class Profile; // Per-password-form-{on-page, dialog} class responsible for interactions // between a given form, the per-tab PasswordManager, and the web database. -class PasswordFormManager : public PasswordStoreConsumer { +class PasswordFormManager : public WebDataServiceConsumer { public: // web_data_service allows access to current profile's Web Data // password_manager owns this object @@ -35,6 +34,9 @@ class PasswordFormManager : public PasswordStoreConsumer { // Retrieves potential matching logins from the database. void FetchMatchingLoginsFromWebDatabase(); +#if defined(OS_WIN) + void FetchMatchingIE7LoginFromWebDatabase(); +#endif // Simple state-check to verify whether this object as received a callback // from the web database and completed its matching phase. Note that the @@ -58,12 +60,19 @@ class PasswordFormManager : public PasswordStoreConsumer { // managed by this. bool IsNewLogin(); + // WebDataServiceConsumer implementation. If matches were found + // (in *result), this is where we determine we need to autofill. + virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, + const WDTypedResult* result); + // Determines if we need to autofill given the results of the query. - void OnRequestDone(int handle, const std::vector<PasswordForm*>& result); + void OnRequestDone(WebDataService::Handle h, const WDTypedResult* result); - // PasswordStoreConsumer implementation. - virtual void OnPasswordStoreRequestDone( - int handle, const std::vector<PasswordForm*>& result); +#if defined(OS_WIN) + // Determines if we need to autofill given the results of the query in the + // ie7_password table. + void OnIE7RequestDone(WebDataService::Handle h, const WDTypedResult* result); +#endif // A user opted to 'never remember' passwords for this form. // Blacklist it so that from now on when it is seen we ignore it. @@ -132,7 +141,7 @@ class PasswordFormManager : public PasswordStoreConsumer { const PasswordManager* const password_manager_; // Handle to any pending WebDataService::GetLogins query. - int pending_login_query_; + WebDataService::Handle pending_login_query_; // Convenience pointer to entry in best_matches_ that is marked // as preferred. This is only allowed to be null if there are no best matches diff --git a/chrome/browser/password_manager/password_form_manager_win.cc b/chrome/browser/password_manager/password_form_manager_win.cc index e69de29..a075617 100644 --- a/chrome/browser/password_manager/password_form_manager_win.cc +++ b/chrome/browser/password_manager/password_form_manager_win.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/password_manager/password_form_manager.h" + +#include "base/string_util.h" +#include "chrome/browser/password_manager/ie7_password.h" +#include "chrome/browser/password_manager/password_manager.h" +#include "chrome/browser/profile.h" + +void PasswordFormManager::FetchMatchingIE7LoginFromWebDatabase() { + DCHECK_EQ(state_, PRE_MATCHING_PHASE); + DCHECK(!pending_login_query_); + state_ = MATCHING_PHASE; + WebDataService* web_data_service = + profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); + if (!web_data_service) { + NOTREACHED(); + return; + } + + IE7PasswordInfo info; + std::wstring url = ASCIIToWide(observed_form_.origin.spec()); + info.url_hash = ie7_password::GetUrlHash(url); + pending_login_query_ = web_data_service->GetIE7Login(info, this); +} + +void PasswordFormManager::OnIE7RequestDone(WebDataService::Handle h, + const WDTypedResult* result) { + // Get the result from the database into a usable form. + const WDResult<IE7PasswordInfo>* r = + static_cast<const WDResult<IE7PasswordInfo>*>(result); + IE7PasswordInfo result_value = r->GetValue(); + + state_ = POST_MATCHING_PHASE; + + if (!result_value.encrypted_data.empty()) { + // We got a result. + // Delete the entry. If it's good we will add it to the real saved password + // table. + WebDataService* web_data_service = + profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); + if (!web_data_service) { + NOTREACHED(); + return; + } + web_data_service->RemoveIE7Login(result_value); + + std::wstring username; + std::wstring password; + std::wstring url = ASCIIToWide(observed_form_.origin.spec()); + if (!ie7_password::DecryptPassword(url, result_value.encrypted_data, + &username, &password)) { + return; + } + + PasswordForm* auto_fill = new PasswordForm(observed_form_); + auto_fill->username_value = username; + auto_fill->password_value = password; + auto_fill->preferred = true; + auto_fill->ssl_valid = observed_form_.origin.SchemeIsSecure(); + auto_fill->date_created = result_value.date_created; + // Add this PasswordForm to the saved password table. + web_data_service->AddLogin(*auto_fill); + + if (IgnoreResult(*auto_fill)) { + delete auto_fill; + return; + } + + best_matches_[auto_fill->username_value] = auto_fill; + preferred_match_ = auto_fill; + password_manager_->Autofill(observed_form_, best_matches_, + preferred_match_); + } +} diff --git a/chrome/browser/password_manager/password_manager.cc b/chrome/browser/password_manager/password_manager.cc index e09aa08..b558bf94 100644 --- a/chrome/browser/password_manager/password_manager.cc +++ b/chrome/browser/password_manager/password_manager.cc @@ -8,7 +8,6 @@ #include "app/resource_bundle.h" #include "base/stl_util-inl.h" #include "base/string_util.h" -#include "chrome/browser/password_manager/password_form_manager.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/notification_registrar.h" @@ -235,9 +234,8 @@ void PasswordManager::Autofill( return; } default: - if (observer_) { + if (observer_) observer_->OnAutofillDataAvailable(preferred_match->username_value, preferred_match->password_value); - } } } diff --git a/chrome/browser/password_manager/password_manager.h b/chrome/browser/password_manager/password_manager.h index 175e4cd..9c80714 100644 --- a/chrome/browser/password_manager/password_manager.h +++ b/chrome/browser/password_manager/password_manager.h @@ -7,13 +7,13 @@ #include "base/scoped_ptr.h" #include "base/stl_util-inl.h" +#include "chrome/browser/password_manager/password_form_manager.h" #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/views/login_view.h" #include "chrome/common/pref_member.h" #include "webkit/glue/password_form.h" #include "webkit/glue/password_form_dom_manager.h" -class PasswordFormManager; class PrefService; class TabContents; diff --git a/chrome/browser/password_manager/password_store.cc b/chrome/browser/password_manager/password_store.cc deleted file mode 100644 index 77c6081..0000000 --- a/chrome/browser/password_manager/password_store.cc +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/password_manager/password_store.h" - -#include "base/scoped_ptr.h" -#include "base/task.h" - -using std::vector; - -PasswordStore::PasswordStore() : handle_(0) { -} - -bool PasswordStore::Init() { - thread_.reset(new base::Thread("Chrome_PasswordStore_Thread")); - - if (!thread_->Start()) { - thread_.reset(NULL); - return false; - } - - return true; -} - -void PasswordStore::ScheduleTask(Task* task) { - if (thread_.get()) { - thread_->message_loop()->PostTask(FROM_HERE, task); - } -} - -void PasswordStore::AddLogin(const PasswordForm& form) { - ScheduleTask(NewRunnableMethod( - this, &PasswordStore::AddLoginImpl, form)); -} - -void PasswordStore::UpdateLogin(const PasswordForm& form) { - ScheduleTask(NewRunnableMethod( - this, &PasswordStore::UpdateLoginImpl, form)); -} - -void PasswordStore::RemoveLogin(const PasswordForm& form) { - ScheduleTask(NewRunnableMethod( - this, &PasswordStore::RemoveLoginImpl, form)); -} - -int PasswordStore::GetLogins(const PasswordForm& form, - PasswordStoreConsumer* consumer) { - int handle = handle_++; - GetLoginsRequest* request = new GetLoginsRequest(form, consumer, handle); - - AutoLock l(pending_requests_lock_); - pending_requests_.insert(handle); - - ScheduleTask(NewRunnableMethod(this, &PasswordStore::GetLoginsImpl, request)); - return handle; -} - -void PasswordStore::NotifyConsumer(GetLoginsRequest* request, - const vector<PasswordForm*> forms) { - scoped_ptr<GetLoginsRequest> request_ptr(request); - - request->message_loop->PostTask(FROM_HERE, - NewRunnableMethod(this, - &PasswordStore::NotifyConsumerImpl, - request->consumer, request->handle, forms)); -} - -void PasswordStore::NotifyConsumerImpl(PasswordStoreConsumer* consumer, - int handle, - const vector<PasswordForm*> forms) { - { // Scope for the AutoLock. - AutoLock l(pending_requests_lock_); - - // Don't notify the consumer if the request was canceled. - if (pending_requests_.find(handle) == pending_requests_.end()) - return; - pending_requests_.erase(handle); - } - - consumer->OnPasswordStoreRequestDone(handle, forms); -} - -void PasswordStore::CancelLoginsQuery(int handle) { - AutoLock l(pending_requests_lock_); - pending_requests_.erase(handle); -} - -PasswordStore::GetLoginsRequest::GetLoginsRequest( - const PasswordForm& form, - PasswordStoreConsumer* consumer, - int handle) - : form(form), - consumer(consumer), - handle(handle), - message_loop(MessageLoop::current()) { -} diff --git a/chrome/browser/password_manager/password_store.h b/chrome/browser/password_manager/password_store.h deleted file mode 100644 index 88616ba..0000000 --- a/chrome/browser/password_manager/password_store.h +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE -#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE - -#include <set> -#include <vector> - -#include "base/ref_counted.h" -#include "base/scoped_ptr.h" -#include "base/thread.h" -#include "webkit/glue/password_form.h" - -class Profile; -class Task; - -class PasswordStoreConsumer { - public: - virtual ~PasswordStoreConsumer() {} - // Call this when the request is finished. If there are no results, call it - // anyway with an empty vector. - virtual void OnPasswordStoreRequestDone( - int handle, const std::vector<PasswordForm*>& result) = 0; -}; - -// Interface for storing form passwords in a platform-specific secure way. -class PasswordStore : public base::RefCountedThreadSafe<PasswordStore> { - public: - PasswordStore(); - virtual ~PasswordStore() {} - - // Reimplement this to add custom initialization. Always call this too. - virtual bool Init(); - - // Adds the given PasswordForm to the secure password store asynchronously. - void AddLogin(const PasswordForm& form); - // Updates the matching PasswordForm in the secure password store (async). - void UpdateLogin(const PasswordForm& form); - // Removes the matching PasswordForm from the secure password store (async). - void RemoveLogin(const PasswordForm& form); - // Searches for a matching PasswordForm and returns a handle so the async - // request can be tracked. Implement the PasswordStoreConsumer interface to - // be notified on completion. - int GetLogins(const PasswordForm& form, - PasswordStoreConsumer* consumer); - - // Cancels a previous GetLogins query (async) - virtual void CancelLoginsQuery(int handle); - - protected: - // Simple container class that represents a GetLogins request. - // Created in GetLogins and passed to GetLoginsImpl. - struct GetLoginsRequest { - GetLoginsRequest(const PasswordForm& f, - PasswordStoreConsumer* c, - int handle); - - // The query form that was originally passed to GetLogins - PasswordForm form; - // The consumer to notify when this GetLogins request is complete - PasswordStoreConsumer* consumer; - // A unique handle for the request - int handle; - // The message loop that the GetLogins request was made from. We send the - // result back to the consumer in this same message loop. - MessageLoop* message_loop; - - DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest); - }; - - // Schedule the given task to be run in the PasswordStore's own thread. - void ScheduleTask(Task* task); - - // These will be run in PasswordStore's own thread. - // Synchronous implementation to add the given login. - virtual void AddLoginImpl(const PasswordForm& form) = 0; - // Synchronous implementation to update the given login. - virtual void UpdateLoginImpl(const PasswordForm& form) = 0; - // Synchronous implementation to remove the given login. - virtual void RemoveLoginImpl(const PasswordForm& form) = 0; - // Should find all PasswordForms with the same signon_realm. The results - // will then be scored by the PasswordFormManager. Once they are found - // (or not), the consumer should be notified. - virtual void GetLoginsImpl(GetLoginsRequest* request) = 0; - - // Notifies the consumer that GetLoginsImpl() is complete. - void NotifyConsumer(GetLoginsRequest* request, - const std::vector<PasswordForm*> forms); - - // Next handle to return from GetLogins() to allow callers to track - // their request. - int handle_; - - // Thread that the synchronous methods are run in. - scoped_ptr<base::Thread> thread_; - - private: - // Called by NotifyConsumer, but runs in the consumer's thread. Will not - // call the consumer if the request was canceled. This extra layer is here so - // that PasswordStoreConsumer doesn't have to be reference counted (we assume - // consumers will cancel their requests before they are destroyed). - void NotifyConsumerImpl(PasswordStoreConsumer* consumer, int handle, - const std::vector<PasswordForm*> forms); - - // List of pending request handles. Handles are removed from the set when - // they finish or are canceled. - Lock pending_requests_lock_; - std::set<int> pending_requests_; - - DISALLOW_COPY_AND_ASSIGN(PasswordStore); -}; - -#endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE diff --git a/chrome/browser/password_manager/password_store_default.cc b/chrome/browser/password_manager/password_store_default.cc deleted file mode 100644 index 35de563..0000000 --- a/chrome/browser/password_manager/password_store_default.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/password_manager/password_store_default.h" -#include "chrome/browser/webdata/web_data_service.h" -#include "chrome/common/chrome_constants.h" - -#include "base/logging.h" -#include "base/task.h" - -PasswordStoreDefault::PasswordStoreDefault(WebDataService* web_data_service) - : web_data_service_(web_data_service) { -} - -PasswordStoreDefault::~PasswordStoreDefault() { - for (PendingRequestMap::const_iterator it = pending_requests_.begin(); - it != pending_requests_.end(); ++it) { - scoped_ptr<GetLoginsRequest> request(it->second); - web_data_service_->CancelRequest(it->first); - } -} - -void PasswordStoreDefault::AddLoginImpl(const PasswordForm& form) { - web_data_service_->AddLogin(form); -} - -void PasswordStoreDefault::RemoveLoginImpl(const PasswordForm& form) { - web_data_service_->RemoveLogin(form); -} - -void PasswordStoreDefault::UpdateLoginImpl(const PasswordForm& form) { - web_data_service_->UpdateLogin(form); -} - -void PasswordStoreDefault::GetLoginsImpl(GetLoginsRequest* request) { - int web_data_handle = web_data_service_->GetLogins(request->form, this); - pending_requests_.insert(PendingRequestMap::value_type( - web_data_handle, request)); -} - -void PasswordStoreDefault::OnWebDataServiceRequestDone( - WebDataService::Handle h, - const WDTypedResult *result) { - // Look up this handle in our request map to get the original - // GetLoginsRequest. - PendingRequestMap::iterator it(pending_requests_.find(h)); - DCHECK(it != pending_requests_.end()); - - GetLoginsRequest* request = it->second; - pending_requests_.erase(it); - - DCHECK(result); - if (!result) - return; - - const WDResult<std::vector<PasswordForm*> >* r = - static_cast<const WDResult<std::vector<PasswordForm*> >*>(result); - - NotifyConsumer(request, r->GetValue()); -} diff --git a/chrome/browser/password_manager/password_store_default.h b/chrome/browser/password_manager/password_store_default.h deleted file mode 100644 index 542d54a..0000000 --- a/chrome/browser/password_manager/password_store_default.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT -#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT - -#include <map> - -#include "base/file_path.h" -#include "base/ref_counted.h" -#include "base/scoped_ptr.h" -#include "chrome/browser/password_manager/password_store.h" -#include "chrome/browser/webdata/web_data_service.h" - -class Task; - -// Simple password store implementation that delegates everything to -// the WebDatabase. -class PasswordStoreDefault : public PasswordStore, - public WebDataServiceConsumer { - public: - explicit PasswordStoreDefault(WebDataService* web_data_service); - virtual ~PasswordStoreDefault(); - - protected: - // Implements PasswordStore interface. - void AddLoginImpl(const PasswordForm& form); - void UpdateLoginImpl(const PasswordForm& form); - void RemoveLoginImpl(const PasswordForm& form); - void GetLoginsImpl(GetLoginsRequest* request); - - // Called when a WebDataService method finishes. - virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, - const WDTypedResult* result); - - scoped_refptr<WebDataService> web_data_service_; - - // Methods in this class call async WebDataService methods. This mapping - // remembers which WebDataService request corresponds to which PasswordStore - // request. - typedef std::map<WebDataService::Handle, GetLoginsRequest*> PendingRequestMap; - PendingRequestMap pending_requests_; - - private: - DISALLOW_COPY_AND_ASSIGN(PasswordStoreDefault); -}; - -#endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT diff --git a/chrome/browser/password_manager/password_store_gnome.cc b/chrome/browser/password_manager/password_store_gnome.cc deleted file mode 100644 index 93f3b6f..0000000 --- a/chrome/browser/password_manager/password_store_gnome.cc +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/password_manager/password_store_gnome.h" - -#include <string> - -#include "base/logging.h" -#include "base/string_util.h" -#include "base/task.h" -#include "base/time.h" - -using std::map; -using std::string; -using std::vector; - -// Schema is analagous to the fields in PasswordForm. -const GnomeKeyringPasswordSchema PasswordStoreGnome::kGnomeSchema = { - GNOME_KEYRING_ITEM_GENERIC_SECRET, { - { "origin_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, - { "action_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, - { "username_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, - { "username_value", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, - { "password_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, - { "submit_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, - { "signon_realm", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, - { "ssl_valid", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, - { "preferred", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, - { "date_created", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, - { "blacklisted_by_user", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, - { "scheme", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, - { NULL } - } -}; - -PasswordStoreGnome::PasswordStoreGnome() { -} - -PasswordStoreGnome::~PasswordStoreGnome() { -} - -bool PasswordStoreGnome::Init() { - return PasswordStore::Init() && gnome_keyring_is_available(); -} - -void PasswordStoreGnome::AddLoginImpl(const PasswordForm& form) { - AutoLock l(gnome_keyring_lock_); - GnomeKeyringResult result = gnome_keyring_store_password_sync( - &kGnomeSchema, - NULL, // Default keyring. - // TODO(johnmaguire@google.com): Localise this. - "Form password stored by Chrome", - WideToASCII(form.password_value).c_str(), - "origin_url", form.origin.spec().c_str(), - "action_url", form.action.spec().c_str(), - "username_element", form.username_element.c_str(), - "username_value", form.username_value.c_str(), - "password_element", form.password_element.c_str(), - "submit_element", form.submit_element.c_str(), - "signon_realm", form.signon_realm.c_str(), - "ssl_valid", form.ssl_valid, - "preferred", form.preferred, - "date_created", Int64ToString(base::Time::Now().ToTimeT()).c_str(), - "blacklisted_by_user", form.blacklisted_by_user, - "scheme", form.scheme, - NULL); - - if (result != GNOME_KEYRING_RESULT_OK) { - LOG(ERROR) << "Keyring save failed: " - << gnome_keyring_result_to_message(result); - } -} - -void PasswordStoreGnome::UpdateLoginImpl(const PasswordForm& form) { - AddLoginImpl(form); // Add & Update are the same in gnome keyring. -} - -void PasswordStoreGnome::RemoveLoginImpl(const PasswordForm& form) { - AutoLock l(gnome_keyring_lock_); - GnomeKeyringResult result = gnome_keyring_delete_password_sync( - &kGnomeSchema, - "origin_url", form.origin.spec().c_str(), - "action_url", form.action.spec().c_str(), - "username_element", form.username_element.c_str(), - "username_value", form.username_value.c_str(), - "password_element", form.password_element.c_str(), - "submit_element", form.submit_element.c_str(), - "signon_realm", form.signon_realm.c_str(), - "ssl_valid", form.ssl_valid, - "preferred", form.preferred, - "date_created", Int64ToString(form.date_created.ToTimeT()).c_str(), - "blacklisted_by_user", form.blacklisted_by_user, - "scheme", form.scheme, - NULL); - if (result != GNOME_KEYRING_RESULT_OK) { - LOG(ERROR) << "Keyring delete failed: " - << gnome_keyring_result_to_message(result); - } -} - -void PasswordStoreGnome::GetLoginsImpl(GetLoginsRequest* request) { - AutoLock l(gnome_keyring_lock_); - GList* found = NULL; - // Search gnome keyring for matching passwords. - GnomeKeyringResult result = gnome_keyring_find_itemsv_sync( - GNOME_KEYRING_ITEM_GENERIC_SECRET, - &found, - "signon_realm", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING, - request->form.signon_realm.c_str(), - NULL); - vector<PasswordForm*> forms; - if (result == GNOME_KEYRING_RESULT_NO_MATCH) { - NotifyConsumer(request, forms); - return; - } else if (result != GNOME_KEYRING_RESULT_OK) { - LOG(ERROR) << "Keyring find failed: " - << gnome_keyring_result_to_message(result); - NotifyConsumer(request, forms); - return; - } - - // Parse all the results from the returned GList into a - // vector<PasswordForm*>. PasswordForms are allocated on the heap. These - // will be deleted by the consumer. - GList* element = g_list_first(found); - while (element != NULL) { - GnomeKeyringFound* data = static_cast<GnomeKeyringFound*>(element->data); - char* password = data->secret; - - GnomeKeyringAttributeList* attributes = data->attributes; - // Read the string & int attributes into the appropriate map. - map<string, string> string_attribute_map; - map<string, uint32> uint_attribute_map; - for (unsigned int i = 0; i < attributes->len; ++i) { - GnomeKeyringAttribute attribute = - gnome_keyring_attribute_list_index(attributes, i); - if (attribute.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) { - string_attribute_map[string(attribute.name)] = - string(attribute.value.string); - } else if (attribute.type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32) { - uint_attribute_map[string(attribute.name)] = attribute.value.integer; - } - } - - PasswordForm* form = new PasswordForm(); - form->origin = GURL(string_attribute_map["origin_url"]); - form->action = GURL(string_attribute_map["action_url"]); - form->username_element = - ASCIIToWide(string(string_attribute_map["username_element"])); - form->username_value = - ASCIIToWide(string(string_attribute_map["username_value"])); - form->password_element = - ASCIIToWide(string(string_attribute_map["password_element"])); - form->password_value = ASCIIToWide(string(password)); - form->submit_element = - ASCIIToWide(string(string_attribute_map["submit_element"])); - form->signon_realm = uint_attribute_map["signon_realm"]; - form->ssl_valid = uint_attribute_map["ssl_valid"]; - form->preferred = uint_attribute_map["preferred"]; - string date = string_attribute_map["date_created"]; - int64 date_created = 0; - DCHECK(StringToInt64(date, &date_created) && date_created != 0); - form->date_created = base::Time::FromTimeT(date_created); - form->blacklisted_by_user = uint_attribute_map["blacklisted_by_user"]; - form->scheme = - static_cast<PasswordForm::Scheme>(uint_attribute_map["scheme"]); - - forms.push_back(form); - - element = g_list_next(element); - } - gnome_keyring_found_list_free(found); - found = NULL; - - NotifyConsumer(request, forms); -} diff --git a/chrome/browser/password_manager/password_store_gnome.h b/chrome/browser/password_manager/password_store_gnome.h deleted file mode 100644 index abbd054..0000000 --- a/chrome/browser/password_manager/password_store_gnome.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_GNOME -#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_GNOME - -extern "C" { -#include <gnome-keyring.h> -} - -#include "base/lock.h" -#include "chrome/browser/password_manager/password_store.h" - -class Profile; -class Task; - -// PasswordStore implementation using Gnome Keyring. -class PasswordStoreGnome : public PasswordStore { - public: - PasswordStoreGnome(); - virtual ~PasswordStoreGnome(); - - virtual bool Init(); - - private: - void AddLoginImpl(const PasswordForm& form); - void UpdateLoginImpl(const PasswordForm& form); - void RemoveLoginImpl(const PasswordForm& form); - void GetLoginsImpl(GetLoginsRequest* request); - - static const GnomeKeyringPasswordSchema kGnomeSchema; - - // Mutex for all interactions with Gnome Keyring. - Lock gnome_keyring_lock_; - - DISALLOW_COPY_AND_ASSIGN(PasswordStoreGnome); -}; - -#endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_GNOME diff --git a/chrome/browser/password_manager/password_store_kwallet.cc b/chrome/browser/password_manager/password_store_kwallet.cc deleted file mode 100644 index 1c50e3e..0000000 --- a/chrome/browser/password_manager/password_store_kwallet.cc +++ /dev/null @@ -1,387 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/password_manager/password_store_kwallet.h" - -#include <sstream> - -#include "base/logging.h" -#include "base/md5.h" -#include "base/pickle.h" -#include "base/string_util.h" -#include "base/task.h" - -using std::string; -using std::vector; - -const char* PasswordStoreKWallet::kAppId = "Chrome"; -const char* PasswordStoreKWallet::kKWalletFolder = "Chrome Form Data"; - -const char* PasswordStoreKWallet::kKWalletServiceName = "org.kde.kwalletd"; -const char* PasswordStoreKWallet::kKWalletPath = "/modules/kwalletd"; -const char* PasswordStoreKWallet::kKWalletInterface = "org.kde.KWallet"; -const char* PasswordStoreKWallet::kKLauncherServiceName = "org.kde.klauncher"; -const char* PasswordStoreKWallet::kKLauncherPath = "/KLauncher"; -const char* PasswordStoreKWallet::kKLauncherInterface = "org.kde.KLauncher"; - -PasswordStoreKWallet::PasswordStoreKWallet() - : error_(NULL), - connection_(NULL), - proxy_(NULL) { -} - -PasswordStoreKWallet::~PasswordStoreKWallet() { - if (proxy_) { - g_object_unref(proxy_); - } -} - -bool PasswordStoreKWallet::Init() { - thread_.reset(new base::Thread("Chrome_KeyringThread")); - - if (!thread_->Start()) { - thread_.reset(NULL); - return false; - } - - // Initialize threading in dbus-glib - it should be fine for - // dbus_g_thread_init to be called multiple times. - if (!g_thread_supported()) - g_thread_init(NULL); - dbus_g_thread_init(); - - // Get a connection to the session bus. - connection_ = dbus_g_bus_get(DBUS_BUS_SESSION, &error_); - if (CheckError()) - return false; - - if (!StartKWalletd()) return false; - if (!InitWallet()) return false; - - return true; -} - -bool PasswordStoreKWallet::StartKWalletd() { - // Sadly kwalletd doesn't use DBUS activation, so we have to make a call to - // klauncher to start it. - DBusGProxy* klauncher_proxy = - dbus_g_proxy_new_for_name(connection_, kKLauncherServiceName, - kKLauncherPath, kKLauncherInterface); - - char* empty_string_list = NULL; - int ret = 1; - char* error = NULL; - dbus_g_proxy_call(klauncher_proxy, "start_service_by_desktop_name", &error_, - G_TYPE_STRING, "kwalletd", // serviceName - G_TYPE_STRV, &empty_string_list, // urls - G_TYPE_STRV, &empty_string_list, // envs - G_TYPE_STRING, "", // startup_id - G_TYPE_BOOLEAN, (gboolean) false, // blind - G_TYPE_INVALID, - G_TYPE_INT, &ret, // result - G_TYPE_STRING, NULL, // dubsName - G_TYPE_STRING, &error, // error - G_TYPE_INT, NULL, // pid - G_TYPE_INVALID); - - if (error && *error) { - LOG(ERROR) << "Error launching kwalletd: " << error; - ret = 1; // Make sure we return false after freeing. - } - - g_free(error); - g_object_unref(klauncher_proxy); - - if (CheckError() || ret != 0) - return false; - return true; -} - -bool PasswordStoreKWallet::InitWallet() { - // Make a proxy to KWallet. - proxy_ = dbus_g_proxy_new_for_name(connection_, kKWalletServiceName, - kKWalletPath, kKWalletInterface); - - // Check KWallet is enabled. - gboolean is_enabled = false; - dbus_g_proxy_call(proxy_, "isEnabled", &error_, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &is_enabled, - G_TYPE_INVALID); - if (CheckError() || !is_enabled) - return false; - - // Get the wallet name. - char* wallet_name = NULL; - dbus_g_proxy_call(proxy_, "networkWallet", &error_, - G_TYPE_INVALID, - G_TYPE_STRING, &wallet_name, - G_TYPE_INVALID); - if (CheckError() || !wallet_name) - return false; - - wallet_name_.assign(wallet_name); - g_free(wallet_name); - - return true; -} - -void PasswordStoreKWallet::AddLoginImpl(const PasswordForm& form) { - AutoLock l(kwallet_lock_); - int wallet_handle = WalletHandle(); - if (wallet_handle == kInvalidKWalletHandle) - return; - - PasswordFormList forms; - GetLoginsList(&forms, form, wallet_handle); - - forms.push_back(const_cast<PasswordForm*>(&form)); - - SetLoginsList(forms, form, wallet_handle); -} - -void PasswordStoreKWallet::UpdateLoginImpl(const PasswordForm& form) { - AutoLock l(kwallet_lock_); - int wallet_handle = WalletHandle(); - if (wallet_handle == kInvalidKWalletHandle) - return; - - PasswordFormList forms; - GetLoginsList(&forms, form, wallet_handle); - - for (uint i = 0; i < forms.size(); ++i) { - if (CompareForms(form, *forms[i])) { - forms.erase(forms.begin() + i); - forms.insert(forms.begin() + i, const_cast<PasswordForm*>(&form)); - } - } - - SetLoginsList(forms, form, wallet_handle); -} - -void PasswordStoreKWallet::RemoveLoginImpl(const PasswordForm& form) { - AutoLock l(kwallet_lock_); - int wallet_handle = WalletHandle(); - if (wallet_handle == kInvalidKWalletHandle) - return; - - PasswordFormList forms; - GetLoginsList(&forms, form, wallet_handle); - - for (uint i = 0; i < forms.size(); ++i) { - if (CompareForms(form, *forms[i])) { - forms.erase(forms.begin() + i); - --i; - } - } - - if (forms.empty()) { - // No items left? Remove the entry from the wallet. - int ret = 0; - dbus_g_proxy_call(proxy_, "removeEntry", &error_, - G_TYPE_INT, wallet_handle, // handle - G_TYPE_STRING, kKWalletFolder, // folder - G_TYPE_STRING, form.signon_realm.c_str(), // key - G_TYPE_STRING, kAppId, // appid - G_TYPE_INVALID, - G_TYPE_INT, &ret, - G_TYPE_INVALID); - CheckError(); - if (ret) - LOG(ERROR) << "Bad return code " << ret << " from kwallet removeEntry"; - } else { - // Otherwise update the entry in the wallet. - SetLoginsList(forms, form, wallet_handle); - } -} - -void PasswordStoreKWallet::GetLoginsImpl(GetLoginsRequest* request) { - PasswordFormList forms; - - AutoLock l(kwallet_lock_); - int wallet_handle = WalletHandle(); - if (wallet_handle != kInvalidKWalletHandle) - GetLoginsList(&forms, request->form, wallet_handle); - - NotifyConsumer(request, forms); -} - -void PasswordStoreKWallet::GetLoginsList(PasswordFormList* forms, - const PasswordForm& key, - int wallet_handle) { - // Is there an entry in the wallet? - gboolean has_entry = false; - dbus_g_proxy_call(proxy_, "hasEntry", &error_, - G_TYPE_INT, wallet_handle, // handle - G_TYPE_STRING, kKWalletFolder, // folder - G_TYPE_STRING, key.signon_realm.c_str(), // key - G_TYPE_STRING, kAppId, // appid - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &has_entry, - G_TYPE_INVALID); - - if (CheckError() || !has_entry) - return; - - GArray* byte_array = NULL; - dbus_g_proxy_call(proxy_, "readEntry", &error_, - G_TYPE_INT, wallet_handle, // handle - G_TYPE_STRING, kKWalletFolder, // folder - G_TYPE_STRING, key.signon_realm.c_str(), // key - G_TYPE_STRING, kAppId, // appid - G_TYPE_INVALID, - DBUS_TYPE_G_UCHAR_ARRAY, &byte_array, - G_TYPE_INVALID); - - if (CheckError() || !byte_array || !byte_array->len) - return; - - Pickle pickle(byte_array->data, byte_array->len); - DeserializeValue(key, pickle, forms); -} - -void PasswordStoreKWallet::SetLoginsList(const PasswordFormList& forms, - const PasswordForm& key, - int wallet_handle) { - Pickle value; - SerializeValue(forms, &value); - - // Convert the pickled bytes to a GByteArray. - GArray* byte_array = g_array_sized_new(false, false, sizeof(char), - value.size()); - g_array_append_vals(byte_array, value.data(), value.size()); - - // Make the call. - int ret = 0; - dbus_g_proxy_call(proxy_, "writeEntry", &error_, - G_TYPE_INT, wallet_handle, // handle - G_TYPE_STRING, kKWalletFolder, // folder - G_TYPE_STRING, key.signon_realm.c_str(), // key - DBUS_TYPE_G_UCHAR_ARRAY, byte_array, // value - G_TYPE_STRING, kAppId, // appid - G_TYPE_INVALID, - G_TYPE_INT, &ret, - G_TYPE_INVALID); - g_array_free(byte_array, true); - - CheckError(); - if (ret) - LOG(ERROR) << "Bad return code " << ret << " from kwallet writeEntry"; -} - -bool PasswordStoreKWallet::CompareForms(const PasswordForm& a, - const PasswordForm& b) { - return a.origin == b.origin && - a.password_element == b.password_element && - a.signon_realm == b.signon_realm && - a.submit_element == b.submit_element && - a.username_element == b.username_element && - a.username_value == b.username_value; -} - -void PasswordStoreKWallet::SerializeValue(const PasswordFormList& forms, - Pickle* pickle) { - pickle->WriteInt(forms.size()); - for (PasswordFormList::const_iterator it = forms.begin() ; - it != forms.end() ; ++it) { - const PasswordForm* form = *it; - pickle->WriteInt(form->scheme); - pickle->WriteString(form->origin.spec()); - pickle->WriteString(form->action.spec()); - pickle->WriteWString(form->username_element); - pickle->WriteWString(form->username_value); - pickle->WriteWString(form->password_element); - pickle->WriteWString(form->password_value); - pickle->WriteWString(form->submit_element); - pickle->WriteBool(form->ssl_valid); - pickle->WriteBool(form->preferred); - pickle->WriteBool(form->blacklisted_by_user); - } -} - -void PasswordStoreKWallet::DeserializeValue(const PasswordForm& key, - const Pickle& pickle, - PasswordFormList* forms) { - void* iter = NULL; - - int count = 0; - pickle.ReadInt(&iter, &count); - - for (int i = 0; i < count; ++i) { - PasswordForm* form = new PasswordForm(); - form->signon_realm.assign(key.signon_realm); - - pickle.ReadInt(&iter, reinterpret_cast<int*>(&form->scheme)); - ReadGURL(pickle, &iter, &form->origin); - ReadGURL(pickle, &iter, &form->action); - pickle.ReadWString(&iter, &form->username_element); - pickle.ReadWString(&iter, &form->username_value); - pickle.ReadWString(&iter, &form->password_element); - pickle.ReadWString(&iter, &form->password_value); - pickle.ReadWString(&iter, &form->submit_element); - pickle.ReadBool(&iter, &form->ssl_valid); - pickle.ReadBool(&iter, &form->preferred); - pickle.ReadBool(&iter, &form->blacklisted_by_user); - forms->push_back(form); - } -} - -void PasswordStoreKWallet::ReadGURL(const Pickle& pickle, void** iter, - GURL* url) { - string url_string; - pickle.ReadString(iter, &url_string); - *url = GURL(url_string); -} - -bool PasswordStoreKWallet::CheckError() { - if (error_) { - LOG(ERROR) << "Failed to complete KWallet call: " << error_->message; - g_error_free(error_); - error_ = NULL; - return true; - } - return false; -} - -int PasswordStoreKWallet::WalletHandle() { - // Open the wallet. - int handle = kInvalidKWalletHandle; - dbus_g_proxy_call(proxy_, "open", &error_, - G_TYPE_STRING, wallet_name_.c_str(), // wallet - G_TYPE_INT64, 0LL, // wid - G_TYPE_STRING, kAppId, // appid - G_TYPE_INVALID, - G_TYPE_INT, &handle, - G_TYPE_INVALID); - if (CheckError() || handle == kInvalidKWalletHandle) - return kInvalidKWalletHandle; - - // Check if our folder exists. - gboolean has_folder = false; - dbus_g_proxy_call(proxy_, "hasFolder", &error_, - G_TYPE_INT, handle, // handle - G_TYPE_STRING, kKWalletFolder, // folder - G_TYPE_STRING, kAppId, // appid - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &has_folder, - G_TYPE_INVALID); - if (CheckError()) - return kInvalidKWalletHandle; - - // Create it if it didn't. - if (!has_folder) { - gboolean success = false; - dbus_g_proxy_call(proxy_, "createFolder", &error_, - G_TYPE_INT, handle, // handle - G_TYPE_STRING, kKWalletFolder, // folder - G_TYPE_STRING, kAppId, // appid - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &success, - G_TYPE_INVALID); - if (CheckError() || !success) - return kInvalidKWalletHandle; - } - - return handle; -} diff --git a/chrome/browser/password_manager/password_store_kwallet.h b/chrome/browser/password_manager/password_store_kwallet.h deleted file mode 100644 index f0ca283..0000000 --- a/chrome/browser/password_manager/password_store_kwallet.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_KWALLET -#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_KWALLET - -#include <dbus/dbus-glib.h> -#include <glib.h> - -#include <string> -#include <vector> - -#include "base/lock.h" -#include "base/thread.h" -#include "chrome/browser/password_manager/password_store.h" -#include "webkit/glue/password_form.h" - -class Pickle; -class Profile; -class Task; - -class PasswordStoreKWallet : public PasswordStore { - public: - PasswordStoreKWallet(); - virtual ~PasswordStoreKWallet(); - - bool Init(); - - private: - typedef std::vector<PasswordForm*> PasswordFormList; - - // Implements PasswordStore interface. - void AddLoginImpl(const PasswordForm& form); - void UpdateLoginImpl(const PasswordForm& form); - void RemoveLoginImpl(const PasswordForm& form); - void GetLoginsImpl(GetLoginsRequest* request); - - // Initialisation. - bool StartKWalletd(); - bool InitWallet(); - - // Reads a list of PasswordForms from the wallet that match the signon_realm - // of key. - void GetLoginsList(PasswordFormList* forms, const PasswordForm& key, - int wallet_handle); - - // Writes a list of PasswordForms to the wallet with the signon_realm from - // key. Overwrites any existing list for this key. - void SetLoginsList(const PasswordFormList& forms, const PasswordForm& key, - int wallet_handle); - - // Checks if the last dbus call returned an error. If it did, logs the error - // message, frees it and returns true. - // This must be called after every dbus call. - bool CheckError(); - - // Opens the wallet and ensures that the "Chrome Form Data" folder exists. - // Returns kInvalidWalletHandle on error. - int WalletHandle(); - - // Compares two PasswordForms and returns true if they are the same. - // Checks only the fields that we persist in KWallet, and ignores - // password_value. - static bool CompareForms(const PasswordForm& a, const PasswordForm& b); - - // Serializes a list of PasswordForms to be stored in the wallet. - static void SerializeValue(const PasswordFormList& forms, Pickle* pickle); - - // Deserializes a list of PasswordForms from the wallet. - static void DeserializeValue(const PasswordForm& key, const Pickle& pickle, - PasswordFormList* forms); - - // Convenience function to read a GURL from a Pickle. Assumes the URL has - // been written as a std::string. - static void ReadGURL(const Pickle& pickle, void** iter, GURL* url); - - // Name of the application - will appear in kwallet's dialogs. - static const char* kAppId; - // Name of the folder to store passwords in. - static const char* kKWalletFolder; - - // DBUS stuff. - static const char* kKWalletServiceName; - static const char* kKWalletPath; - static const char* kKWalletInterface; - static const char* kKLauncherServiceName; - static const char* kKLauncherPath; - static const char* kKLauncherInterface; - - // Invalid handle returned by WalletHandle(). - static const int kInvalidKWalletHandle = -1; - - // Controls all access to kwallet dbus calls. - Lock kwallet_lock_; - - // Error from the last dbus call. NULL when there's no error. Freed and - // cleared by CheckError(). - GError* error_; - // Connection to the dbus session bus. - DBusGConnection* connection_; - // Proxy to the kwallet dbus service. - DBusGProxy* proxy_; - - // The name of the wallet we've opened. Set during Init(). - std::string wallet_name_; - - DISALLOW_COPY_AND_ASSIGN(PasswordStoreKWallet); -}; - -#endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_KWALLET diff --git a/chrome/browser/password_manager/password_store_win.cc b/chrome/browser/password_manager/password_store_win.cc deleted file mode 100644 index a3c45b6..0000000 --- a/chrome/browser/password_manager/password_store_win.cc +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/password_manager/password_store_win.h" - -#include "base/logging.h" -#include "base/string_util.h" -#include "chrome/browser/password_manager/ie7_password.h" -#include "chrome/browser/password_manager/password_manager.h" -#include "chrome/browser/profile.h" - -using std::map; -using std::vector; - -PasswordStoreWin::PasswordStoreWin(WebDataService* web_data_service) - : PasswordStoreDefault(web_data_service) { -} - -void PasswordStoreWin::OnWebDataServiceRequestDone( - WebDataService::Handle h, const WDTypedResult *result) { - // Look up this handle in our request map to get the original - // GetLoginsRequest. - PendingRequestMap::const_iterator it(pending_requests_.find(h)); - DCHECK(it != pending_requests_.end()); - - GetLoginsRequest* request = (*it).second; - pending_requests_.erase(h); - - DCHECK(result); - if (!result) - return; - - switch (result->GetType()) { - case PASSWORD_RESULT: { - // This is a response from WebDataService::GetLogins. - const WDResult<std::vector<PasswordForm*> >* r = - static_cast<const WDResult<std::vector<PasswordForm*> >*>(result); - std::vector<PasswordForm*> result_value = r->GetValue(); - - if (result_value.size()) { - // If we found some results then return them now. - NotifyConsumer(request, result_value); - return; - } else { - // Otherwise try finding IE7 logins. - IE7PasswordInfo info; - std::wstring url = ASCIIToWide(request->form.origin.spec()); - info.url_hash = ie7_password::GetUrlHash(url); - - WebDataService::Handle web_data_handle = - web_data_service_->GetIE7Login(info, this); - pending_requests_.insert(PendingRequestMap::value_type( - web_data_handle, request)); - } - break; - } - - case PASSWORD_IE7_RESULT: { - // This is a response from WebDataService::GetIE7Login. - PasswordForm* ie7_form = GetIE7Result(result, request->form); - - std::vector<PasswordForm*> forms; - if (ie7_form) - forms.push_back(ie7_form); - - NotifyConsumer(request, forms); - break; - } - } -} - -PasswordForm* PasswordStoreWin::GetIE7Result(const WDTypedResult *result, - const PasswordForm& form) { - const WDResult<IE7PasswordInfo>* r = - static_cast<const WDResult<IE7PasswordInfo>*>(result); - IE7PasswordInfo info = r->GetValue(); - - if (!info.encrypted_data.empty()) { - // We got a result. - // Delete the entry. If it's good we will add it to the real saved password - // table. - web_data_service_->RemoveIE7Login(info); - std::wstring username; - std::wstring password; - std::wstring url = ASCIIToWide(form.origin.spec()); - if (!ie7_password::DecryptPassword(url, info.encrypted_data, - &username, &password)) { - return NULL; - } - - PasswordForm* auto_fill = new PasswordForm(form); - auto_fill->username_value = username; - auto_fill->password_value = password; - auto_fill->preferred = true; - auto_fill->ssl_valid = form.origin.SchemeIsSecure(); - auto_fill->date_created = info.date_created; - // Add this PasswordForm to the saved password table. - AddLogin(*auto_fill); - return auto_fill; - } - return NULL; -} diff --git a/chrome/browser/password_manager/password_store_win.h b/chrome/browser/password_manager/password_store_win.h deleted file mode 100644 index a56b416..0000000 --- a/chrome/browser/password_manager/password_store_win.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_WIN -#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_WIN - -#include <map> -#include <vector> - -#include "base/file_path.h" -#include "base/scoped_ptr.h" -#include "chrome/browser/password_manager/password_store.h" -#include "chrome/browser/password_manager/password_store_default.h" -#include "chrome/browser/webdata/web_data_service.h" -#include "chrome/browser/webdata/web_database.h" - -// Windows PasswordStore implementation that uses the default implementation, -// but also uses IE7 passwords if no others found. -class PasswordStoreWin : public PasswordStoreDefault { - public: - // FilePath specifies path to WebDatabase. - explicit PasswordStoreWin(WebDataService* web_data_service); - virtual ~PasswordStoreWin() {} - - private: - // See PasswordStoreDefault. - void OnWebDataServiceRequestDone(WebDataService::Handle h, - const WDTypedResult* result); - - // Gets logins from IE7 if no others are found. Also copies them into - // Chrome's WebDatabase so we don't need to look next time. - PasswordForm* GetIE7Result(const WDTypedResult* result, - const PasswordForm& form); - - DISALLOW_COPY_AND_ASSIGN(PasswordStoreWin); -}; - -#endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_WIN diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 5fba79e..1435288 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -19,7 +19,6 @@ #include "chrome/browser/extensions/user_script_master.h" #include "chrome/browser/history/history.h" #include "chrome/browser/net/chrome_url_request_context.h" -#include "chrome/browser/password_manager/password_store_default.h" #include "chrome/browser/profile_manager.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/search_engines/template_url_fetcher.h" @@ -89,14 +88,6 @@ URLRequestContext* Profile::GetDefaultRequestContext() { return default_request_context_; } -#if defined(OS_LINUX) -// Temporarily disabled while we figure some stuff out. -// http://code.google.com/p/chromium/issues/detail?id=12351 -// #include "chrome/browser/password_manager/password_store_gnome.h" -// #include "chrome/browser/password_manager/password_store_kwallet.h" -#elif defined(OS_WIN) -#include "chrome/browser/password_manager/password_store_win.h" -#endif //////////////////////////////////////////////////////////////////////////////// // @@ -200,15 +191,6 @@ class OffTheRecordProfileImpl : public Profile, } } - virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) { - if (sat == EXPLICIT_ACCESS) { - return profile_->GetPasswordStore(sat); - } else { - NOTREACHED() << "This profile is OffTheRecord"; - return NULL; - } - } - virtual PrefService* GetPrefs() { return profile_->GetPrefs(); } @@ -430,7 +412,6 @@ ProfileImpl::ProfileImpl(const FilePath& path) extensions_request_context_(NULL), history_service_created_(false), created_web_data_service_(false), - created_password_store_(false), created_download_manager_(false), created_theme_provider_(false), start_time_(Time::Now()), @@ -804,41 +785,6 @@ void ProfileImpl::CreateWebDataService() { web_data_service_.swap(wds); } -PasswordStore* ProfileImpl::GetPasswordStore(ServiceAccessType sat) { - if (!created_password_store_) - CreatePasswordStore(); - return password_store_.get(); -} - -void ProfileImpl::CreatePasswordStore() { - DCHECK(!created_password_store_ && password_store_.get() == NULL); - created_password_store_ = true; - scoped_refptr<PasswordStore> ps; -#if defined(OS_LINUX) -// Temporarily disabled while we figure some stuff out. -// http://code.google.com/p/chromium/issues/detail?id=12351 -// if (getenv("KDE_FULL_SESSION")) { -// ps = new PasswordStoreKWallet(); -// } else { -// ps = new PasswordStoreGnome(); -// } - NOTIMPLEMENTED(); -#elif defined(OS_WIN) - ps = new PasswordStoreWin(GetWebDataService(Profile::IMPLICIT_ACCESS)); -#else - NOTIMPLEMENTED(); -#endif - if (!ps || !ps->Init()) { - // Try falling back to the default password manager - LOG(WARNING) << "Could not initialise native password manager - " - "falling back to default"; - ps = new PasswordStoreDefault(GetWebDataService(Profile::IMPLICIT_ACCESS)); - if (!ps->Init()) - return; - } - password_store_.swap(ps); -} - DownloadManager* ProfileImpl::GetDownloadManager() { if (!created_download_manager_) { scoped_refptr<DownloadManager> dlm(new DownloadManager); diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index d5e800f..1ee1a19 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -31,7 +31,6 @@ class ExtensionProcessManager; class ExtensionsService; class HistoryService; class NavigationController; -class PasswordStore; class PrefService; class SessionService; class SpellChecker; @@ -158,9 +157,6 @@ class Profile { // the ServiceAccessType definition above. virtual WebDataService* GetWebDataService(ServiceAccessType access) = 0; - // Returns the PasswordStore for this profile. This is owned by the Profile. - virtual PasswordStore* GetPasswordStore(ServiceAccessType access) = 0; - // Retrieves a pointer to the PrefService that manages the preferences // for this user profile. The PrefService is lazily created the first // time that this method is called. @@ -318,7 +314,6 @@ class ProfileImpl : public Profile, virtual ExtensionProcessManager* GetExtensionProcessManager(); virtual HistoryService* GetHistoryService(ServiceAccessType sat); virtual WebDataService* GetWebDataService(ServiceAccessType sat); - virtual PasswordStore* GetPasswordStore(ServiceAccessType sat); virtual PrefService* GetPrefs(); virtual TemplateURLModel* GetTemplateURLModel(); virtual TemplateURLFetcher* GetTemplateURLFetcher(); @@ -364,8 +359,6 @@ class ProfileImpl : public Profile, void CreateWebDataService(); FilePath GetPrefFilePath(); - void CreatePasswordStore(); - void StopCreateSessionServiceTimer(); void EnsureSessionServiceCreated() { @@ -408,12 +401,10 @@ class ProfileImpl : public Profile, scoped_refptr<DownloadManager> download_manager_; scoped_refptr<HistoryService> history_service_; scoped_refptr<WebDataService> web_data_service_; - scoped_refptr<PasswordStore> password_store_; scoped_refptr<SessionService> session_service_; scoped_refptr<BrowserThemeProvider> theme_provider_; bool history_service_created_; bool created_web_data_service_; - bool created_password_store_; bool created_download_manager_; bool created_theme_provider_; // Whether or not the last session exited cleanly. This is set only once. diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 907be46..0a01353 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1093,23 +1093,9 @@ 'browser/password_manager/ie7_password.h', 'browser/password_manager/password_form_manager.cc', 'browser/password_manager/password_form_manager.h', + 'browser/password_manager/password_form_manager_win.cc', 'browser/password_manager/password_manager.cc', 'browser/password_manager/password_manager.h', - 'browser/password_manager/password_store.cc', - 'browser/password_manager/password_store.h', - 'browser/password_manager/password_store_default.cc', - 'browser/password_manager/password_store_default.h', - # Temporarily disabled while we figure some stuff out. - # http://code.google.com/p/chromium/issues/detail?id=12351 - # 'browser/password_manager/password_store_gnome.h', - # 'browser/password_manager/password_store_gnome.cc', - # 'browser/password_manager/password_store_kwallet.h', - # 'browser/password_manager/password_store_kwallet.cc', - 'browser/password_manager/password_store_mac_internal.h', - 'browser/password_manager/password_store_mac.h', - 'browser/password_manager/password_store_mac.cc', - 'browser/password_manager/password_store_win.h', - 'browser/password_manager/password_store_win.cc', 'browser/plugin_installer.cc', 'browser/plugin_installer.h', 'browser/plugin_process_host.cc', @@ -1563,10 +1549,6 @@ }], ['OS=="linux"', { 'dependencies': [ - # Temporarily disabled while we figure some stuff out. - # http://code.google.com/p/chromium/issues/detail?id=12351 - # '../build/linux/system.gyp:dbus-glib', - # '../build/linux/system.gyp:gnome-keyring', '../build/linux/system.gyp:gtk', ], 'sources!': [ @@ -1576,8 +1558,6 @@ 'browser/debugger/debugger_shell_stubs.cc', # Windows-specific files. 'browser/download/download_exe.cc', - 'browser/password_manager/password_store_win.cc', - 'browser/password_manager/password_store_win.h', ], 'conditions': [ ['linux_breakpad==1', { @@ -1610,12 +1590,6 @@ 'browser/bookmarks/bookmark_context_menu.cc', 'browser/bookmarks/bookmark_drop_info.cc', 'browser/debugger/debugger_shell_stubs.cc', - 'browser/password_manager/password_store_gnome.h', - 'browser/password_manager/password_store_gnome.cc', - 'browser/password_manager/password_store_kwallet.h', - 'browser/password_manager/password_store_kwallet.cc', - 'browser/password_manager/password_store_win.cc', - 'browser/password_manager/password_store_win.h', ], 'sources': [ # Build the necessary GTM sources @@ -1663,10 +1637,6 @@ 'sources!': [ 'browser/debugger/debugger_shell_stubs.cc', 'browser/history/history_publisher_none.cc', - 'browser/password_manager/password_store_gnome.h', - 'browser/password_manager/password_store_gnome.cc', - 'browser/password_manager/password_store_kwallet.h', - 'browser/password_manager/password_store_kwallet.cc', ], 'configurations': { 'Debug': { diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 7abdd8f..974d31d 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -102,9 +102,6 @@ class TestingProfile : public Profile { virtual WebDataService* GetWebDataService(ServiceAccessType access) { return NULL; } - virtual PasswordStore* GetPasswordStore(ServiceAccessType access) { - return NULL; - } virtual PrefService* GetPrefs() { FilePath prefs_filename; PathService::Get(base::DIR_TEMP, &prefs_filename); |