| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
| 6 | 6 |
| 7 #include "chrome/browser/password_manager/password_store.h" | 7 #include "chrome/browser/password_manager/password_store.h" |
| 8 #include "chrome/browser/password_manager/password_store_factory.h" | 8 #include "chrome/browser/password_manager/password_store_factory.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
| 11 #include "chrome/browser/ui/chrome_pages.h" | 11 #include "chrome/browser/ui/chrome_pages.h" |
| 12 #include "chrome/browser/ui/passwords/manage_passwords_controller.h" |
| 12 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 | 16 |
| 16 using content::WebContents; | 17 using content::WebContents; |
| 17 using autofill::PasswordFormMap; | 18 using autofill::PasswordFormMap; |
| 18 | 19 |
| 19 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( | 20 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( |
| 20 WebContents* web_contents) | 21 content::WebContents* web_contents) |
| 21 : content::WebContentsObserver(web_contents), | 22 : content::WebContentsObserver(web_contents), |
| 22 web_contents_(web_contents) { | 23 web_contents_(web_contents) { |
| 23 TabSpecificContentSettings* content_settings = | 24 ManagePasswordsController* manage_passwords_controller = |
| 24 TabSpecificContentSettings::FromWebContents(web_contents); | 25 ManagePasswordsController::FromWebContents(web_contents_); |
| 25 | 26 |
| 26 password_submitted_ = content_settings->password_submitted(); | 27 password_submitted_ = manage_passwords_controller->password_submitted(); |
| 27 if (password_submitted_) { | 28 if (password_submitted_) { |
| 28 if (content_settings->password_to_be_saved()) | 29 if (manage_passwords_controller->password_to_be_saved()) |
| 29 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; | 30 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; |
| 30 else | 31 else |
| 31 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING; | 32 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING; |
| 32 } else { | 33 } else { |
| 33 manage_passwords_bubble_state_ = MANAGE_PASSWORDS; | 34 manage_passwords_bubble_state_ = MANAGE_PASSWORDS; |
| 34 } | 35 } |
| 35 | 36 |
| 36 title_ = l10n_util::GetStringUTF16( | 37 title_ = l10n_util::GetStringUTF16( |
| 37 (manage_passwords_bubble_state_ == PASSWORD_TO_BE_SAVED) ? | 38 (manage_passwords_bubble_state_ == PASSWORD_TO_BE_SAVED) ? |
| 38 IDS_SAVE_PASSWORD : IDS_MANAGE_PASSWORDS); | 39 IDS_SAVE_PASSWORD : IDS_MANAGE_PASSWORDS); |
| 39 if (password_submitted_) | 40 if (password_submitted_) { |
| 40 pending_credentials_ = content_settings->pending_credentials(); | 41 pending_credentials_ = manage_passwords_controller->pending_credentials(); |
| 41 best_matches_ = content_settings->best_matches(); | 42 } |
| 43 best_matches_ = manage_passwords_controller->best_matches(); |
| 42 manage_link_ = | 44 manage_link_ = |
| 43 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK); | 45 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK); |
| 44 } | 46 } |
| 45 | 47 |
| 46 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {} | 48 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {} |
| 47 | 49 |
| 48 void ManagePasswordsBubbleModel::OnCancelClicked() { | 50 void ManagePasswordsBubbleModel::OnCancelClicked() { |
| 49 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; | 51 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; |
| 50 } | 52 } |
| 51 | 53 |
| 52 void ManagePasswordsBubbleModel::OnSaveClicked() { | 54 void ManagePasswordsBubbleModel::OnSaveClicked() { |
| 53 TabSpecificContentSettings* content_settings = | 55 ManagePasswordsController* manage_passwords_controller = |
| 54 TabSpecificContentSettings::FromWebContents(web_contents_); | 56 ManagePasswordsController::FromWebContents(web_contents_); |
| 55 content_settings->SavePassword(); | 57 manage_passwords_controller->SavePassword(); |
| 56 content_settings->unset_password_to_be_saved(); | 58 manage_passwords_controller->unset_password_to_be_saved(); |
| 57 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING; | 59 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING; |
| 58 } | 60 } |
| 59 | 61 |
| 60 void ManagePasswordsBubbleModel::OnManageLinkClicked() { | 62 void ManagePasswordsBubbleModel::OnManageLinkClicked() { |
| 61 chrome::ShowSettingsSubPage(chrome::FindBrowserWithWebContents(web_contents_), | 63 chrome::ShowSettingsSubPage(chrome::FindBrowserWithWebContents(web_contents_), |
| 62 chrome::kPasswordManagerSubPage); | 64 chrome::kPasswordManagerSubPage); |
| 63 } | 65 } |
| 64 | 66 |
| 65 void ManagePasswordsBubbleModel::PasswordAction( | 67 void ManagePasswordsBubbleModel::AddOrRemovePassword( |
| 66 autofill::PasswordForm password_form, bool remove) { | 68 autofill::PasswordForm password_form, |
| 69 bool remove) { |
| 67 if (!web_contents_) | 70 if (!web_contents_) |
| 68 return; | 71 return; |
| 69 Profile* profile = | 72 Profile* profile = |
| 70 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 73 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 71 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 74 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
| 72 profile, Profile::EXPLICIT_ACCESS).get(); | 75 profile, Profile::EXPLICIT_ACCESS).get(); |
| 73 DCHECK(password_store); | 76 DCHECK(password_store); |
| 74 if (remove) | 77 if (remove) |
| 75 password_store->RemoveLogin(password_form); | 78 password_store->RemoveLogin(password_form); |
| 76 else | 79 else |
| 77 password_store->AddLogin(password_form); | 80 password_store->AddLogin(password_form); |
| 78 // This is necessary in case the bubble is instantiated again, we thus do not | 81 // This is necessary in case the bubble is instantiated again, we thus do not |
| 79 // display the pending credentials if they were deleted. | 82 // display the pending credentials if they were deleted. |
| 80 if (password_form.username_value == pending_credentials_.username_value) { | 83 if (password_form.username_value == pending_credentials_.username_value) { |
| 81 TabSpecificContentSettings* content_settings = | 84 ManagePasswordsController::FromWebContents(web_contents_)-> |
| 82 TabSpecificContentSettings::FromWebContents(web_contents_); | 85 set_password_submitted(!remove); |
| 83 content_settings->password_submitted(!remove); | |
| 84 } | 86 } |
| 85 } | 87 } |
| 86 | 88 |
| 87 void ManagePasswordsBubbleModel::DeleteFromBestMatches( | 89 void ManagePasswordsBubbleModel::DeleteFromBestMatches( |
| 88 autofill::PasswordForm password_form) { | 90 autofill::PasswordForm password_form) { |
| 89 TabSpecificContentSettings* content_settings = | 91 ManagePasswordsController::FromWebContents(web_contents_)-> |
| 90 TabSpecificContentSettings::FromWebContents(web_contents_); | 92 RemoveFromBestMatches(password_form); |
| 91 content_settings->remove_from_best_matches(password_form); | |
| 92 } | 93 } |
| 93 | 94 |
| 94 void ManagePasswordsBubbleModel::WebContentsDestroyed( | 95 void ManagePasswordsBubbleModel::WebContentsDestroyed( |
| 95 content::WebContents* web_contents) { | 96 content::WebContents* web_contents) { |
| 96 // The WebContents have been destroyed. | 97 // The WebContents have been destroyed. |
| 97 web_contents_ = NULL; | 98 web_contents_ = NULL; |
| 98 } | 99 } |
| OLD | NEW |