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_factory.h" | 7 #include "chrome/browser/password_manager/password_store_factory.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/chrome_pages.h" | 10 #include "chrome/browser/ui/chrome_pages.h" |
11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" | 11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" |
12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
13 #include "components/password_manager/core/browser/password_store.h" | 13 #include "components/password_manager/core/browser/password_store.h" |
14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
16 | 16 |
17 using content::WebContents; | 17 using content::WebContents; |
18 using autofill::PasswordFormMap; | 18 using autofill::PasswordFormMap; |
19 | 19 |
20 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( | 20 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( |
21 content::WebContents* web_contents) | 21 content::WebContents* web_contents) |
22 : content::WebContentsObserver(web_contents), | 22 : content::WebContentsObserver(web_contents), |
23 web_contents_(web_contents) { | 23 web_contents_(web_contents) { |
24 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = | 24 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = |
25 ManagePasswordsBubbleUIController::FromWebContents(web_contents_); | 25 ManagePasswordsBubbleUIController::FromWebContents(web_contents_); |
26 | 26 |
27 password_submitted_ = | 27 if (manage_passwords_bubble_ui_controller->password_to_be_saved()) |
28 manage_passwords_bubble_ui_controller->password_submitted(); | 28 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; |
29 if (password_submitted_) { | 29 else |
30 if (manage_passwords_bubble_ui_controller->password_to_be_saved()) | |
31 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; | |
32 else | |
33 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING; | |
34 } else { | |
35 manage_passwords_bubble_state_ = MANAGE_PASSWORDS; | 30 manage_passwords_bubble_state_ = MANAGE_PASSWORDS; |
36 } | |
37 | 31 |
38 title_ = l10n_util::GetStringUTF16( | 32 title_ = l10n_util::GetStringUTF16( |
39 (manage_passwords_bubble_state_ == PASSWORD_TO_BE_SAVED) ? | 33 (manage_passwords_bubble_state_ == PASSWORD_TO_BE_SAVED) ? |
40 IDS_SAVE_PASSWORD : IDS_MANAGE_PASSWORDS); | 34 IDS_SAVE_PASSWORD : IDS_MANAGE_PASSWORDS); |
41 if (password_submitted_) { | 35 pending_credentials_ = |
42 pending_credentials_ = | 36 manage_passwords_bubble_ui_controller->pending_credentials(); |
43 manage_passwords_bubble_ui_controller->pending_credentials(); | |
44 } | |
45 best_matches_ = manage_passwords_bubble_ui_controller->best_matches(); | 37 best_matches_ = manage_passwords_bubble_ui_controller->best_matches(); |
46 manage_link_ = | 38 manage_link_ = |
47 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK); | 39 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK); |
48 } | 40 } |
49 | 41 |
50 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {} | 42 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {} |
51 | 43 |
52 void ManagePasswordsBubbleModel::OnNopeClicked() { | 44 void ManagePasswordsBubbleModel::OnNopeClicked() { |
53 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; | 45 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; |
54 } | 46 } |
55 | 47 |
56 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { | 48 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { |
57 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = | 49 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = |
58 ManagePasswordsBubbleUIController::FromWebContents(web_contents_); | 50 ManagePasswordsBubbleUIController::FromWebContents(web_contents_); |
59 manage_passwords_bubble_ui_controller->NeverSavePassword(); | 51 manage_passwords_bubble_ui_controller->NeverSavePassword(); |
60 manage_passwords_bubble_ui_controller->unset_password_to_be_saved(); | 52 manage_passwords_bubble_ui_controller->unset_password_to_be_saved(); |
61 manage_passwords_bubble_state_ = NEVER_SAVE_PASSWORDS; | 53 manage_passwords_bubble_state_ = NEVER_SAVE_PASSWORDS; |
62 } | 54 } |
63 | 55 |
64 void ManagePasswordsBubbleModel::OnSaveClicked() { | 56 void ManagePasswordsBubbleModel::OnSaveClicked() { |
65 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = | 57 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = |
66 ManagePasswordsBubbleUIController::FromWebContents(web_contents_); | 58 ManagePasswordsBubbleUIController::FromWebContents(web_contents_); |
67 manage_passwords_bubble_ui_controller->SavePassword(); | 59 manage_passwords_bubble_ui_controller->SavePassword(); |
68 manage_passwords_bubble_ui_controller->unset_password_to_be_saved(); | 60 manage_passwords_bubble_ui_controller->unset_password_to_be_saved(); |
69 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING; | 61 manage_passwords_bubble_state_ = MANAGE_PASSWORDS; |
70 } | 62 } |
71 | 63 |
72 void ManagePasswordsBubbleModel::OnManageLinkClicked() { | 64 void ManagePasswordsBubbleModel::OnManageLinkClicked() { |
73 chrome::ShowSettingsSubPage(chrome::FindBrowserWithWebContents(web_contents_), | 65 chrome::ShowSettingsSubPage(chrome::FindBrowserWithWebContents(web_contents_), |
74 chrome::kPasswordManagerSubPage); | 66 chrome::kPasswordManagerSubPage); |
75 } | 67 } |
76 | 68 |
77 void ManagePasswordsBubbleModel::OnPasswordAction( | 69 void ManagePasswordsBubbleModel::OnPasswordAction( |
78 const autofill::PasswordForm& password_form, | 70 const autofill::PasswordForm& password_form, |
79 PasswordAction action) { | 71 PasswordAction action) { |
80 if (!web_contents_) | 72 if (!web_contents_) |
81 return; | 73 return; |
82 Profile* profile = | 74 Profile* profile = |
83 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 75 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
84 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 76 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
85 profile, Profile::EXPLICIT_ACCESS).get(); | 77 profile, Profile::EXPLICIT_ACCESS).get(); |
86 DCHECK(password_store); | 78 DCHECK(password_store); |
87 if (action == REMOVE_PASSWORD) | 79 if (action == REMOVE_PASSWORD) |
88 password_store->RemoveLogin(password_form); | 80 password_store->RemoveLogin(password_form); |
89 else | 81 else |
90 password_store->AddLogin(password_form); | 82 password_store->AddLogin(password_form); |
91 // This is necessary in case the bubble is instantiated again, we thus do not | |
92 // display the pending credentials if they were deleted. | |
93 if (password_form.username_value == pending_credentials_.username_value) { | |
94 ManagePasswordsBubbleUIController::FromWebContents(web_contents_) | |
95 ->set_password_submitted(action == ADD_PASSWORD); | |
96 } | |
97 } | |
98 | |
99 void ManagePasswordsBubbleModel::DeleteFromBestMatches( | |
100 autofill::PasswordForm password_form) { | |
101 ManagePasswordsBubbleUIController::FromWebContents(web_contents_)-> | |
102 RemoveFromBestMatches(password_form); | |
103 } | 83 } |
104 | 84 |
105 void ManagePasswordsBubbleModel::WebContentsDestroyed( | 85 void ManagePasswordsBubbleModel::WebContentsDestroyed( |
106 content::WebContents* web_contents) { | 86 content::WebContents* web_contents) { |
107 // The WebContents have been destroyed. | 87 // The WebContents have been destroyed. |
108 web_contents_ = NULL; | 88 web_contents_ = NULL; |
109 } | 89 } |
OLD | NEW |