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