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_bubble_ui_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 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = |
24 TabSpecificContentSettings::FromWebContents(web_contents); | 25 ManagePasswordsBubbleUIController::FromWebContents(web_contents_); |
25 | 26 |
26 password_submitted_ = content_settings->password_submitted(); | 27 password_submitted_ = |
| 28 manage_passwords_bubble_ui_controller->password_submitted(); |
27 if (password_submitted_) { | 29 if (password_submitted_) { |
28 if (content_settings->password_to_be_saved()) | 30 if (manage_passwords_bubble_ui_controller->password_to_be_saved()) |
29 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; | 31 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; |
30 else | 32 else |
31 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING; | 33 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING; |
32 } else { | 34 } else { |
33 manage_passwords_bubble_state_ = MANAGE_PASSWORDS; | 35 manage_passwords_bubble_state_ = MANAGE_PASSWORDS; |
34 } | 36 } |
35 | 37 |
36 title_ = l10n_util::GetStringUTF16( | 38 title_ = l10n_util::GetStringUTF16( |
37 (manage_passwords_bubble_state_ == PASSWORD_TO_BE_SAVED) ? | 39 (manage_passwords_bubble_state_ == PASSWORD_TO_BE_SAVED) ? |
38 IDS_SAVE_PASSWORD : IDS_MANAGE_PASSWORDS); | 40 IDS_SAVE_PASSWORD : IDS_MANAGE_PASSWORDS); |
39 if (password_submitted_) | 41 if (password_submitted_) { |
40 pending_credentials_ = content_settings->pending_credentials(); | 42 pending_credentials_ = |
41 best_matches_ = content_settings->best_matches(); | 43 manage_passwords_bubble_ui_controller->pending_credentials(); |
| 44 } |
| 45 best_matches_ = manage_passwords_bubble_ui_controller->best_matches(); |
42 manage_link_ = | 46 manage_link_ = |
43 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK); | 47 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK); |
44 } | 48 } |
45 | 49 |
46 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {} | 50 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {} |
47 | 51 |
48 void ManagePasswordsBubbleModel::OnCancelClicked() { | 52 void ManagePasswordsBubbleModel::OnCancelClicked() { |
49 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; | 53 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; |
50 } | 54 } |
51 | 55 |
52 void ManagePasswordsBubbleModel::OnSaveClicked() { | 56 void ManagePasswordsBubbleModel::OnSaveClicked() { |
53 TabSpecificContentSettings* content_settings = | 57 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = |
54 TabSpecificContentSettings::FromWebContents(web_contents_); | 58 ManagePasswordsBubbleUIController::FromWebContents(web_contents_); |
55 content_settings->SavePassword(); | 59 manage_passwords_bubble_ui_controller->SavePassword(); |
56 content_settings->unset_password_to_be_saved(); | 60 manage_passwords_bubble_ui_controller->unset_password_to_be_saved(); |
57 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING; | 61 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING; |
58 } | 62 } |
59 | 63 |
60 void ManagePasswordsBubbleModel::OnManageLinkClicked() { | 64 void ManagePasswordsBubbleModel::OnManageLinkClicked() { |
61 chrome::ShowSettingsSubPage(chrome::FindBrowserWithWebContents(web_contents_), | 65 chrome::ShowSettingsSubPage(chrome::FindBrowserWithWebContents(web_contents_), |
62 chrome::kPasswordManagerSubPage); | 66 chrome::kPasswordManagerSubPage); |
63 } | 67 } |
64 | 68 |
65 void ManagePasswordsBubbleModel::PasswordAction( | 69 void ManagePasswordsBubbleModel::OnPasswordAction( |
66 autofill::PasswordForm password_form, bool remove) { | 70 autofill::PasswordForm password_form, |
| 71 bool remove) { |
67 if (!web_contents_) | 72 if (!web_contents_) |
68 return; | 73 return; |
69 Profile* profile = | 74 Profile* profile = |
70 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 75 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
71 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 76 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
72 profile, Profile::EXPLICIT_ACCESS).get(); | 77 profile, Profile::EXPLICIT_ACCESS).get(); |
73 DCHECK(password_store); | 78 DCHECK(password_store); |
74 if (remove) | 79 if (remove) |
75 password_store->RemoveLogin(password_form); | 80 password_store->RemoveLogin(password_form); |
76 else | 81 else |
77 password_store->AddLogin(password_form); | 82 password_store->AddLogin(password_form); |
78 // This is necessary in case the bubble is instantiated again, we thus do not | 83 // This is necessary in case the bubble is instantiated again, we thus do not |
79 // display the pending credentials if they were deleted. | 84 // display the pending credentials if they were deleted. |
80 if (password_form.username_value == pending_credentials_.username_value) { | 85 if (password_form.username_value == pending_credentials_.username_value) { |
81 TabSpecificContentSettings* content_settings = | 86 ManagePasswordsBubbleUIController::FromWebContents(web_contents_)-> |
82 TabSpecificContentSettings::FromWebContents(web_contents_); | 87 set_password_submitted(!remove); |
83 content_settings->password_submitted(!remove); | |
84 } | 88 } |
85 } | 89 } |
86 | 90 |
87 void ManagePasswordsBubbleModel::DeleteFromBestMatches( | 91 void ManagePasswordsBubbleModel::DeleteFromBestMatches( |
88 autofill::PasswordForm password_form) { | 92 autofill::PasswordForm password_form) { |
89 TabSpecificContentSettings* content_settings = | 93 ManagePasswordsBubbleUIController::FromWebContents(web_contents_)-> |
90 TabSpecificContentSettings::FromWebContents(web_contents_); | 94 RemoveFromBestMatches(password_form); |
91 content_settings->remove_from_best_matches(password_form); | |
92 } | 95 } |
93 | 96 |
94 void ManagePasswordsBubbleModel::WebContentsDestroyed( | 97 void ManagePasswordsBubbleModel::WebContentsDestroyed( |
95 content::WebContents* web_contents) { | 98 content::WebContents* web_contents) { |
96 // The WebContents have been destroyed. | 99 // The WebContents have been destroyed. |
97 web_contents_ = NULL; | 100 web_contents_ = NULL; |
98 } | 101 } |
OLD | NEW |