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

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: Aura compilation 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.
114 password_form_map_.clear();
115 state_ = password_manager::ui::CREDENTIAL_REQUEST_STATE;
116 UpdateBubbleAndIconVisibility();
117 if (bubble_shown_)
118 credentials_callback_ = callback;
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 #endif 191 #endif
173 } 192 }
174 193
175 void ManagePasswordsUIController::SavePassword() { 194 void ManagePasswordsUIController::SavePassword() {
176 DCHECK(PasswordPendingUserDecision()); 195 DCHECK(PasswordPendingUserDecision());
177 SavePasswordInternal(); 196 SavePasswordInternal();
178 state_ = password_manager::ui::MANAGE_STATE; 197 state_ = password_manager::ui::MANAGE_STATE;
179 UpdateBubbleAndIconVisibility(); 198 UpdateBubbleAndIconVisibility();
180 } 199 }
181 200
201 void ManagePasswordsUIController::ChooseCredential(
202 bool was_chosen,
203 const autofill::PasswordForm& form) {
204 DCHECK_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, state_);
205 DCHECK(!credentials_callback_.is_null());
206 password_manager::CredentialInfo info = was_chosen ?
207 password_manager::CredentialInfo(form) :
208 password_manager::CredentialInfo();
209 credentials_callback_.Run(info);
210 state_ = password_manager::ui::INACTIVE_STATE;
211 UpdateBubbleAndIconVisibility();
212 }
213
182 void ManagePasswordsUIController::SavePasswordInternal() { 214 void ManagePasswordsUIController::SavePasswordInternal() {
183 DCHECK(form_manager_.get()); 215 DCHECK(form_manager_.get());
184 form_manager_->Save(); 216 form_manager_->Save();
185 } 217 }
186 218
187 void ManagePasswordsUIController::NeverSavePassword() { 219 void ManagePasswordsUIController::NeverSavePassword() {
188 DCHECK(PasswordPendingUserDecision()); 220 DCHECK(PasswordPendingUserDecision());
189 NeverSavePasswordInternal(); 221 NeverSavePasswordInternal();
190 state_ = password_manager::ui::BLACKLIST_STATE; 222 state_ = password_manager::ui::BLACKLIST_STATE;
191 UpdateBubbleAndIconVisibility(); 223 UpdateBubbleAndIconVisibility();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 timer_.reset(new base::ElapsedTimer()); 265 timer_.reset(new base::ElapsedTimer());
234 } 266 }
235 267
236 void ManagePasswordsUIController::WasHidden() { 268 void ManagePasswordsUIController::WasHidden() {
237 #if !defined(OS_ANDROID) 269 #if !defined(OS_ANDROID)
238 chrome::CloseManagePasswordsBubble(web_contents()); 270 chrome::CloseManagePasswordsBubble(web_contents());
239 #endif 271 #endif
240 } 272 }
241 273
242 const autofill::PasswordForm& ManagePasswordsUIController:: 274 const autofill::PasswordForm& ManagePasswordsUIController::
243 PendingCredentials() const { 275 PendingPassword() const {
244 DCHECK(form_manager_); 276 DCHECK(form_manager_);
245 return form_manager_->pending_credentials(); 277 return form_manager_->pending_credentials();
246 } 278 }
247 279
248 void ManagePasswordsUIController::UpdateIconAndBubbleState( 280 void ManagePasswordsUIController::UpdateIconAndBubbleState(
249 ManagePasswordsIcon* icon) { 281 ManagePasswordsIcon* icon) {
250 if (password_manager::ui::IsAutomaticDisplayState(state_)) { 282 if (password_manager::ui::IsAutomaticDisplayState(state_)) {
251 // We must display the icon before showing the bubble, as the bubble would 283 // 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 284 // 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 285 // 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 286 // the original state to determine if the bubble opened automagically or via
255 // user action. 287 // user action.
256 password_manager::ui::State end_state = 288 password_manager::ui::State end_state =
257 GetEndStateForAutomaticState(state_); 289 GetEndStateForAutomaticState(state_);
258 icon->SetState(end_state); 290 icon->SetState(end_state);
259 ShowBubbleWithoutUserInteraction(); 291 ShowBubbleWithoutUserInteraction();
260 state_ = end_state; 292 state_ = end_state;
261 } else { 293 } else {
262 icon->SetState(state_); 294 icon->SetState(state_);
263 } 295 }
264 } 296 }
265 297
298 void ManagePasswordsUIController::OnBubbleShown() {
299 bubble_shown_ = true;
300 }
301
266 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { 302 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() {
267 DCHECK(password_manager::ui::IsAutomaticDisplayState(state_)); 303 DCHECK(password_manager::ui::IsAutomaticDisplayState(state_));
268 #if !defined(OS_ANDROID) 304 #if !defined(OS_ANDROID)
269 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 305 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
270 if (!browser || browser->toolbar_model()->input_in_progress()) 306 if (!browser || browser->toolbar_model()->input_in_progress())
271 return; 307 return;
272 if (state_ == password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE && 308 if (state_ == password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE &&
273 !password_bubble_experiment::ShouldShowBubble( 309 !password_bubble_experiment::ShouldShowBubble(
274 browser->profile()->GetPrefs())) 310 browser->profile()->GetPrefs()))
275 return; 311 return;
276 CommandUpdater* updater = browser->command_controller()->command_updater(); 312 CommandUpdater* updater = browser->command_controller()->command_updater();
277 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); 313 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE);
278 #endif 314 #endif
279 } 315 }
280 316
281 bool ManagePasswordsUIController::PasswordPendingUserDecision() const { 317 bool ManagePasswordsUIController::PasswordPendingUserDecision() const {
282 return state_ == password_manager::ui::PENDING_PASSWORD_STATE || 318 return state_ == password_manager::ui::PENDING_PASSWORD_STATE ||
283 state_ == password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE; 319 state_ == password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE;
284 } 320 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698