OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_ui_controller.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 password_manager::PasswordStore* GetPasswordStore( | 40 password_manager::PasswordStore* GetPasswordStore( |
41 content::WebContents* web_contents) { | 41 content::WebContents* web_contents) { |
42 return PasswordStoreFactory::GetForProfile( | 42 return PasswordStoreFactory::GetForProfile( |
43 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 43 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
44 ServiceAccessType::EXPLICIT_ACCESS).get(); | 44 ServiceAccessType::EXPLICIT_ACCESS).get(); |
45 } | 45 } |
46 | 46 |
47 std::vector<scoped_ptr<autofill::PasswordForm>> CopyFormVector( | 47 std::vector<std::unique_ptr<autofill::PasswordForm>> CopyFormVector( |
48 const ScopedVector<autofill::PasswordForm>& forms) { | 48 const ScopedVector<autofill::PasswordForm>& forms) { |
49 std::vector<scoped_ptr<autofill::PasswordForm>> result(forms.size()); | 49 std::vector<std::unique_ptr<autofill::PasswordForm>> result(forms.size()); |
50 for (size_t i = 0; i < forms.size(); ++i) | 50 for (size_t i = 0; i < forms.size(); ++i) |
51 result[i].reset(new autofill::PasswordForm(*forms[i])); | 51 result[i].reset(new autofill::PasswordForm(*forms[i])); |
52 return result; | 52 return result; |
53 } | 53 } |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController); | 57 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController); |
58 | 58 |
59 ManagePasswordsUIController::ManagePasswordsUIController( | 59 ManagePasswordsUIController::ManagePasswordsUIController( |
60 content::WebContents* web_contents) | 60 content::WebContents* web_contents) |
61 : content::WebContentsObserver(web_contents), | 61 : content::WebContentsObserver(web_contents), |
62 bubble_status_(NOT_SHOWN) { | 62 bubble_status_(NOT_SHOWN) { |
63 passwords_data_.set_client( | 63 passwords_data_.set_client( |
64 ChromePasswordManagerClient::FromWebContents(web_contents)); | 64 ChromePasswordManagerClient::FromWebContents(web_contents)); |
65 password_manager::PasswordStore* password_store = | 65 password_manager::PasswordStore* password_store = |
66 GetPasswordStore(web_contents); | 66 GetPasswordStore(web_contents); |
67 if (password_store) | 67 if (password_store) |
68 password_store->AddObserver(this); | 68 password_store->AddObserver(this); |
69 } | 69 } |
70 | 70 |
71 ManagePasswordsUIController::~ManagePasswordsUIController() {} | 71 ManagePasswordsUIController::~ManagePasswordsUIController() {} |
72 | 72 |
73 void ManagePasswordsUIController::OnPasswordSubmitted( | 73 void ManagePasswordsUIController::OnPasswordSubmitted( |
74 scoped_ptr<PasswordFormManager> form_manager) { | 74 std::unique_ptr<PasswordFormManager> form_manager) { |
75 bool show_bubble = !form_manager->IsBlacklisted(); | 75 bool show_bubble = !form_manager->IsBlacklisted(); |
76 DestroyAccountChooser(); | 76 DestroyAccountChooser(); |
77 passwords_data_.OnPendingPassword(std::move(form_manager)); | 77 passwords_data_.OnPendingPassword(std::move(form_manager)); |
78 if (show_bubble) { | 78 if (show_bubble) { |
79 password_manager::InteractionsStats* stats = GetCurrentInteractionStats(); | 79 password_manager::InteractionsStats* stats = GetCurrentInteractionStats(); |
80 const int show_threshold = | 80 const int show_threshold = |
81 password_bubble_experiment::GetSmartBubbleDismissalThreshold(); | 81 password_bubble_experiment::GetSmartBubbleDismissalThreshold(); |
82 if (stats && show_threshold > 0 && stats->dismissal_count >= show_threshold) | 82 if (stats && show_threshold > 0 && stats->dismissal_count >= show_threshold) |
83 show_bubble = false; | 83 show_bubble = false; |
84 } | 84 } |
85 if (show_bubble) | 85 if (show_bubble) |
86 bubble_status_ = SHOULD_POP_UP; | 86 bubble_status_ = SHOULD_POP_UP; |
87 UpdateBubbleAndIconVisibility(); | 87 UpdateBubbleAndIconVisibility(); |
88 } | 88 } |
89 | 89 |
90 void ManagePasswordsUIController::OnUpdatePasswordSubmitted( | 90 void ManagePasswordsUIController::OnUpdatePasswordSubmitted( |
91 scoped_ptr<PasswordFormManager> form_manager) { | 91 std::unique_ptr<PasswordFormManager> form_manager) { |
92 DestroyAccountChooser(); | 92 DestroyAccountChooser(); |
93 passwords_data_.OnUpdatePassword(std::move(form_manager)); | 93 passwords_data_.OnUpdatePassword(std::move(form_manager)); |
94 bubble_status_ = SHOULD_POP_UP; | 94 bubble_status_ = SHOULD_POP_UP; |
95 UpdateBubbleAndIconVisibility(); | 95 UpdateBubbleAndIconVisibility(); |
96 } | 96 } |
97 | 97 |
98 bool ManagePasswordsUIController::OnChooseCredentials( | 98 bool ManagePasswordsUIController::OnChooseCredentials( |
99 ScopedVector<autofill::PasswordForm> local_credentials, | 99 ScopedVector<autofill::PasswordForm> local_credentials, |
100 ScopedVector<autofill::PasswordForm> federated_credentials, | 100 ScopedVector<autofill::PasswordForm> federated_credentials, |
101 const GURL& origin, | 101 const GURL& origin, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 if (dialog_controller_) | 133 if (dialog_controller_) |
134 return; | 134 return; |
135 dialog_controller_.reset(new PasswordDialogControllerImpl( | 135 dialog_controller_.reset(new PasswordDialogControllerImpl( |
136 Profile::FromBrowserContext(web_contents()->GetBrowserContext()), | 136 Profile::FromBrowserContext(web_contents()->GetBrowserContext()), |
137 this)); | 137 this)); |
138 dialog_controller_->ShowAutosigninPrompt( | 138 dialog_controller_->ShowAutosigninPrompt( |
139 CreateAutoSigninPrompt(dialog_controller_.get())); | 139 CreateAutoSigninPrompt(dialog_controller_.get())); |
140 } | 140 } |
141 | 141 |
142 void ManagePasswordsUIController::OnAutomaticPasswordSave( | 142 void ManagePasswordsUIController::OnAutomaticPasswordSave( |
143 scoped_ptr<PasswordFormManager> form_manager) { | 143 std::unique_ptr<PasswordFormManager> form_manager) { |
144 DestroyAccountChooser(); | 144 DestroyAccountChooser(); |
145 passwords_data_.OnAutomaticPasswordSave(std::move(form_manager)); | 145 passwords_data_.OnAutomaticPasswordSave(std::move(form_manager)); |
146 bubble_status_ = SHOULD_POP_UP; | 146 bubble_status_ = SHOULD_POP_UP; |
147 UpdateBubbleAndIconVisibility(); | 147 UpdateBubbleAndIconVisibility(); |
148 } | 148 } |
149 | 149 |
150 void ManagePasswordsUIController::OnPasswordAutofilled( | 150 void ManagePasswordsUIController::OnPasswordAutofilled( |
151 const autofill::PasswordFormMap& password_form_map, | 151 const autofill::PasswordFormMap& password_form_map, |
152 const GURL& origin, | 152 const GURL& origin, |
153 const std::vector<scoped_ptr<autofill::PasswordForm>>* federated_matches) { | 153 const std::vector<std::unique_ptr<autofill::PasswordForm>>* |
| 154 federated_matches) { |
154 // To change to managed state only when the managed state is more important | 155 // To change to managed state only when the managed state is more important |
155 // for the user that the current state. | 156 // for the user that the current state. |
156 if (passwords_data_.state() == password_manager::ui::INACTIVE_STATE || | 157 if (passwords_data_.state() == password_manager::ui::INACTIVE_STATE || |
157 passwords_data_.state() == password_manager::ui::MANAGE_STATE) { | 158 passwords_data_.state() == password_manager::ui::MANAGE_STATE) { |
158 passwords_data_.OnPasswordAutofilled(password_form_map, origin, | 159 passwords_data_.OnPasswordAutofilled(password_form_map, origin, |
159 federated_matches); | 160 federated_matches); |
160 UpdateBubbleAndIconVisibility(); | 161 UpdateBubbleAndIconVisibility(); |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); | 426 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); |
426 } | 427 } |
427 } | 428 } |
428 | 429 |
429 void ManagePasswordsUIController::WebContentsDestroyed() { | 430 void ManagePasswordsUIController::WebContentsDestroyed() { |
430 password_manager::PasswordStore* password_store = | 431 password_manager::PasswordStore* password_store = |
431 GetPasswordStore(web_contents()); | 432 GetPasswordStore(web_contents()); |
432 if (password_store) | 433 if (password_store) |
433 password_store->RemoveObserver(this); | 434 password_store->RemoveObserver(this); |
434 } | 435 } |
OLD | NEW |