Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_ui_controller.cc

Issue 733463003: Show user credentials chooser bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/browsing_data/browsing_data_helper.h" 8 #include "chrome/browser/browsing_data/browsing_data_helper.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/password_manager/password_store_factory.h" 10 #include "chrome/browser/password_manager/password_store_factory.h"
11 #include "chrome/browser/ui/browser_command_controller.h" 11 #include "chrome/browser/ui/browser_command_controller.h"
12 #include "chrome/browser/ui/browser_dialogs.h" 12 #include "chrome/browser/ui/browser_dialogs.h"
13 #include "chrome/browser/ui/browser_finder.h" 13 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/chrome_pages.h" 15 #include "chrome/browser/ui/chrome_pages.h"
16 #include "chrome/browser/ui/location_bar/location_bar.h" 16 #include "chrome/browser/ui/location_bar/location_bar.h"
17 #include "chrome/browser/ui/passwords/manage_passwords_icon.h" 17 #include "chrome/browser/ui/passwords/manage_passwords_icon.h"
18 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" 18 #include "chrome/browser/ui/passwords/password_bubble_experiment.h"
19 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
20 #include "components/password_manager/content/common/credential_manager_types.h"
20 #include "components/password_manager/core/browser/password_store.h" 21 #include "components/password_manager/core/browser/password_store.h"
21 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
22 23
23 #if defined(OS_ANDROID) 24 #if defined(OS_ANDROID)
24 #include "chrome/browser/android/chromium_application.h" 25 #include "chrome/browser/android/chromium_application.h"
25 #endif 26 #endif
26 27
27 using autofill::PasswordFormMap; 28 using autofill::PasswordFormMap;
28 using password_manager::PasswordFormManager; 29 using password_manager::PasswordFormManager;
29 30
(...skipping 27 matching lines...) Expand all
57 } 58 }
58 } 59 }
59 60
60 } // namespace 61 } // namespace
61 62
62 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController); 63 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController);
63 64
64 ManagePasswordsUIController::ManagePasswordsUIController( 65 ManagePasswordsUIController::ManagePasswordsUIController(
65 content::WebContents* web_contents) 66 content::WebContents* web_contents)
66 : content::WebContentsObserver(web_contents), 67 : content::WebContentsObserver(web_contents),
67 state_(password_manager::ui::INACTIVE_STATE) { 68 state_(password_manager::ui::INACTIVE_STATE),
69 bubble_shown_(false) {
68 password_manager::PasswordStore* password_store = 70 password_manager::PasswordStore* password_store =
69 GetPasswordStore(web_contents); 71 GetPasswordStore(web_contents);
70 if (password_store) 72 if (password_store)
71 password_store->AddObserver(this); 73 password_store->AddObserver(this);
72 } 74 }
73 75
74 ManagePasswordsUIController::~ManagePasswordsUIController() {} 76 ManagePasswordsUIController::~ManagePasswordsUIController() {}
75 77
76 void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() { 78 void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() {
79 bubble_shown_ = false;
77 // If we're not on a "webby" URL (e.g. "chrome://sign-in"), we shouldn't 80 // If we're not on a "webby" URL (e.g. "chrome://sign-in"), we shouldn't
78 // display either the bubble or the icon. 81 // display either the bubble or the icon.
79 if (!BrowsingDataHelper::IsWebScheme( 82 if (!BrowsingDataHelper::IsWebScheme(
80 web_contents()->GetLastCommittedURL().scheme())) { 83 web_contents()->GetLastCommittedURL().scheme())) {
81 state_ = password_manager::ui::INACTIVE_STATE; 84 state_ = password_manager::ui::INACTIVE_STATE;
82 } 85 }
83 86
84 #if !defined(OS_ANDROID) 87 #if !defined(OS_ANDROID)
85 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 88 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
86 if (!browser) 89 if (!browser)
87 return; 90 return;
88 LocationBar* location_bar = browser->window()->GetLocationBar(); 91 LocationBar* location_bar = browser->window()->GetLocationBar();
89 DCHECK(location_bar); 92 DCHECK(location_bar);
90 location_bar->UpdateManagePasswordsIconAndBubble(); 93 location_bar->UpdateManagePasswordsIconAndBubble();
91 #endif 94 #endif
92 } 95 }
93 96
94 void ManagePasswordsUIController::OnPasswordSubmitted( 97 void ManagePasswordsUIController::OnPasswordSubmitted(
95 scoped_ptr<PasswordFormManager> form_manager) { 98 scoped_ptr<PasswordFormManager> form_manager) {
96 form_manager_ = form_manager.Pass(); 99 form_manager_ = form_manager.Pass();
97 password_form_map_ = ConstifyMap(form_manager_->best_matches()); 100 password_form_map_ = ConstifyMap(form_manager_->best_matches());
98 origin_ = PendingCredentials().origin; 101 origin_ = PendingPassword().origin;
99 state_ = password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE; 102 state_ = password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE;
100 UpdateBubbleAndIconVisibility(); 103 UpdateBubbleAndIconVisibility();
101 } 104 }
102 105
106 bool ManagePasswordsUIController::OnChooseCredentials(
107 ScopedVector<autofill::PasswordForm> credentials,
108 base::Callback<void(const password_manager::CredentialInfo&)> callback){
109 DCHECK(!credentials.empty());
110 form_manager_.reset();
111 origin_ = credentials[0]->origin;
112 new_password_forms_.swap(credentials);
113 // The map is useless because usernames may overlap.
Mike West 2014/11/20 08:19:32 TODO(vasilii)? :)
vasilii 2014/11/20 15:08:05 TODO what? It's useful for other states.
Mike West 2014/11/21 11:21:12 Yeah, I misunderstood this comment. Sorry for the
114 password_form_map_.clear();
115 state_ = password_manager::ui::PENDING_CREDENTIALS_AND_BUBBLE_STATE;
116 UpdateBubbleAndIconVisibility();
117 if (bubble_shown_)
Mike West 2014/11/20 08:19:32 When wouldn't the bubble be shown?
vasilii 2014/11/20 15:08:05 There is a condition in ShowBubbleWithoutUserInter
Mike West 2014/11/21 11:21:12 Hrm. Ok. I hope that case will be impossible to re
118 credentials_callback_ = callback;
Mike West 2014/11/20 08:19:31 We need to callback to Blink even if the user does
vasilii 2014/11/20 15:08:05 if we return false then this case is handled immed
Mike West 2014/11/21 11:21:12 Acknowledged.
119 return bubble_shown_;
120 }
121
103 void ManagePasswordsUIController::OnAutomaticPasswordSave( 122 void ManagePasswordsUIController::OnAutomaticPasswordSave(
104 scoped_ptr<PasswordFormManager> form_manager) { 123 scoped_ptr<PasswordFormManager> form_manager) {
105 form_manager_ = form_manager.Pass(); 124 form_manager_ = form_manager.Pass();
106 password_form_map_ = ConstifyMap(form_manager_->best_matches()); 125 password_form_map_ = ConstifyMap(form_manager_->best_matches());
107 password_form_map_[form_manager_->associated_username()] = 126 password_form_map_[form_manager_->associated_username()] =
108 &form_manager_->pending_credentials(); 127 &form_manager_->pending_credentials();
109 origin_ = form_manager_->pending_credentials().origin; 128 origin_ = form_manager_->pending_credentials().origin;
110 state_ = password_manager::ui::CONFIRMATION_STATE; 129 state_ = password_manager::ui::CONFIRMATION_STATE;
111 UpdateBubbleAndIconVisibility(); 130 UpdateBubbleAndIconVisibility();
112 } 131 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (changed_form.blacklisted_by_user) 169 if (changed_form.blacklisted_by_user)
151 state_ = password_manager::ui::MANAGE_STATE; 170 state_ = password_manager::ui::MANAGE_STATE;
152 } else { 171 } else {
153 new_password_forms_.push_back(new autofill::PasswordForm(changed_form)); 172 new_password_forms_.push_back(new autofill::PasswordForm(changed_form));
154 password_form_map_[changed_form.username_value] = 173 password_form_map_[changed_form.username_value] =
155 new_password_forms_.back(); 174 new_password_forms_.back();
156 if (changed_form.blacklisted_by_user) 175 if (changed_form.blacklisted_by_user)
157 state_ = password_manager::ui::BLACKLIST_STATE; 176 state_ = password_manager::ui::BLACKLIST_STATE;
158 } 177 }
159 } 178 }
179 // If we're in PENDING_CREDENTIALS_AND_BUBBLE_STATE just close the bubble.
180 if (current_state ==
181 password_manager::ui::PENDING_CREDENTIALS_AND_BUBBLE_STATE)
182 state_ = password_manager::ui::INACTIVE_STATE;
Mike West 2014/11/20 08:19:31 This seems wrong; if I have another window open, a
vasilii 2014/11/20 15:08:05 You are right. I removed this code. What should we
Mike West 2014/11/21 11:21:12 I'd just add a TODO for now; I don't think we have
vasilii 2014/11/21 16:45:37 Done.
160 if (current_state != state_) 183 if (current_state != state_)
161 UpdateBubbleAndIconVisibility(); 184 UpdateBubbleAndIconVisibility();
162 } 185 }
163 186
164 void ManagePasswordsUIController:: 187 void ManagePasswordsUIController::
165 NavigateToPasswordManagerSettingsPage() { 188 NavigateToPasswordManagerSettingsPage() {
166 #if defined(OS_ANDROID) 189 #if defined(OS_ANDROID)
167 chrome::android::ChromiumApplication::ShowPasswordSettings(); 190 chrome::android::ChromiumApplication::ShowPasswordSettings();
168 #else 191 #else
169 chrome::ShowSettingsSubPage( 192 chrome::ShowSettingsSubPage(
170 chrome::FindBrowserWithWebContents(web_contents()), 193 chrome::FindBrowserWithWebContents(web_contents()),
171 chrome::kPasswordManagerSubPage); 194 chrome::kPasswordManagerSubPage);
172 #endif 195 #endif
173 } 196 }
174 197
175 void ManagePasswordsUIController::SavePassword() { 198 void ManagePasswordsUIController::SavePassword() {
176 DCHECK(PasswordPendingUserDecision()); 199 DCHECK(PasswordPendingUserDecision());
177 SavePasswordInternal(); 200 SavePasswordInternal();
178 state_ = password_manager::ui::MANAGE_STATE; 201 state_ = password_manager::ui::MANAGE_STATE;
179 UpdateBubbleAndIconVisibility(); 202 UpdateBubbleAndIconVisibility();
180 } 203 }
181 204
205 void ManagePasswordsUIController::ChooseCredential(
206 bool was_chosen,
207 const autofill::PasswordForm& form) {
208 DCHECK_EQ(password_manager::ui::PENDING_CREDENTIALS_AND_BUBBLE_STATE, state_);
209 DCHECK(!credentials_callback_.is_null());
210 password_manager::CredentialInfo info = was_chosen ?
211 password_manager::CredentialInfo(form) :
212 password_manager::CredentialInfo();
213 credentials_callback_.Run(info);
214 state_ = password_manager::ui::INACTIVE_STATE;
215 UpdateBubbleAndIconVisibility();
216 }
217
182 void ManagePasswordsUIController::SavePasswordInternal() { 218 void ManagePasswordsUIController::SavePasswordInternal() {
183 DCHECK(form_manager_.get()); 219 DCHECK(form_manager_.get());
184 form_manager_->Save(); 220 form_manager_->Save();
185 } 221 }
186 222
187 void ManagePasswordsUIController::NeverSavePassword() { 223 void ManagePasswordsUIController::NeverSavePassword() {
188 DCHECK(PasswordPendingUserDecision()); 224 DCHECK(PasswordPendingUserDecision());
189 NeverSavePasswordInternal(); 225 NeverSavePasswordInternal();
190 state_ = password_manager::ui::BLACKLIST_STATE; 226 state_ = password_manager::ui::BLACKLIST_STATE;
191 UpdateBubbleAndIconVisibility(); 227 UpdateBubbleAndIconVisibility();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 timer_.reset(new base::ElapsedTimer()); 269 timer_.reset(new base::ElapsedTimer());
234 } 270 }
235 271
236 void ManagePasswordsUIController::WasHidden() { 272 void ManagePasswordsUIController::WasHidden() {
237 #if !defined(OS_ANDROID) 273 #if !defined(OS_ANDROID)
238 chrome::CloseManagePasswordsBubble(web_contents()); 274 chrome::CloseManagePasswordsBubble(web_contents());
239 #endif 275 #endif
240 } 276 }
241 277
242 const autofill::PasswordForm& ManagePasswordsUIController:: 278 const autofill::PasswordForm& ManagePasswordsUIController::
243 PendingCredentials() const { 279 PendingPassword() const {
244 DCHECK(form_manager_); 280 DCHECK(form_manager_);
245 return form_manager_->pending_credentials(); 281 return form_manager_->pending_credentials();
246 } 282 }
247 283
248 void ManagePasswordsUIController::UpdateIconAndBubbleState( 284 void ManagePasswordsUIController::UpdateIconAndBubbleState(
249 ManagePasswordsIcon* icon) { 285 ManagePasswordsIcon* icon) {
250 if (password_manager::ui::IsAutomaticDisplayState(state_)) { 286 if (password_manager::ui::IsAutomaticDisplayState(state_)) {
251 // We must display the icon before showing the bubble, as the bubble would 287 // We must display the icon before showing the bubble, as the bubble would
252 // be otherwise unanchored. However, we can't change the controller's state 288 // be otherwise unanchored. However, we can't change the controller's state
253 // until _after_ the bubble is shown, as our metrics depend on the seeing 289 // until _after_ the bubble is shown, as our metrics depend on the seeing
254 // the original state to determine if the bubble opened automagically or via 290 // the original state to determine if the bubble opened automagically or via
255 // user action. 291 // user action.
256 password_manager::ui::State end_state = 292 password_manager::ui::State end_state =
257 GetEndStateForAutomaticState(state_); 293 GetEndStateForAutomaticState(state_);
258 icon->SetState(end_state); 294 icon->SetState(end_state);
259 ShowBubbleWithoutUserInteraction(); 295 ShowBubbleWithoutUserInteraction();
260 state_ = end_state; 296 state_ = end_state;
261 } else { 297 } else {
262 icon->SetState(state_); 298 icon->SetState(state_);
263 } 299 }
264 } 300 }
265 301
302 void ManagePasswordsUIController::OnBubbleShown() {
303 bubble_shown_ = true;
304 }
305
266 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { 306 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() {
267 DCHECK(password_manager::ui::IsAutomaticDisplayState(state_)); 307 DCHECK(password_manager::ui::IsAutomaticDisplayState(state_));
268 #if !defined(OS_ANDROID) 308 #if !defined(OS_ANDROID)
269 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 309 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
270 if (!browser || browser->toolbar_model()->input_in_progress()) 310 if (!browser || browser->toolbar_model()->input_in_progress())
271 return; 311 return;
272 if (state_ == password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE && 312 if (state_ == password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE &&
273 !password_bubble_experiment::ShouldShowBubble( 313 !password_bubble_experiment::ShouldShowBubble(
274 browser->profile()->GetPrefs())) 314 browser->profile()->GetPrefs()))
275 return; 315 return;
276 CommandUpdater* updater = browser->command_controller()->command_updater(); 316 CommandUpdater* updater = browser->command_controller()->command_updater();
277 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); 317 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE);
278 #endif 318 #endif
279 } 319 }
280 320
281 bool ManagePasswordsUIController::PasswordPendingUserDecision() const { 321 bool ManagePasswordsUIController::PasswordPendingUserDecision() const {
282 return state_ == password_manager::ui::PENDING_PASSWORD_STATE || 322 return state_ == password_manager::ui::PENDING_PASSWORD_STATE ||
283 state_ == password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE; 323 state_ == password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE;
284 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698