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

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

Issue 952023002: Credential Manager API: pop up the new "Manage accounts" bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months 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 "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/browsing_data/browsing_data_helper.h" 9 #include "chrome/browser/browsing_data/browsing_data_helper.h"
10 #include "chrome/browser/password_manager/chrome_password_manager_client.h" 10 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 ScopedVector<autofill::PasswordForm>* deleter) { 55 ScopedVector<autofill::PasswordForm>* deleter) {
56 ConstifyMap(map).swap(*ret); 56 ConstifyMap(map).swap(*ret);
57 deleter->clear(); 57 deleter->clear();
58 for (autofill::ConstPasswordFormMap::iterator i = ret->begin(); 58 for (autofill::ConstPasswordFormMap::iterator i = ret->begin();
59 i != ret->end(); ++i) { 59 i != ret->end(); ++i) {
60 deleter->push_back(new autofill::PasswordForm(*i->second)); 60 deleter->push_back(new autofill::PasswordForm(*i->second));
61 i->second = deleter->back(); 61 i->second = deleter->back();
62 } 62 }
63 } 63 }
64 64
65 void RemoveFormFromVector(const autofill::PasswordForm& form_to_delete,
66 ScopedVector<autofill::PasswordForm>* forms) {
67 ScopedVector<autofill::PasswordForm>::iterator it = std::find_if(
68 forms->begin(), forms->end(),
69 [&form_to_delete](autofill::PasswordForm* form) {
70 return IsEqualUniqueKey(*form, form_to_delete);
71 });
72 if (it != forms->end())
73 forms->erase(it);
74 }
75
65 } // namespace 76 } // namespace
66 77
67 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController); 78 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController);
68 79
69 ManagePasswordsUIController::ManagePasswordsUIController( 80 ManagePasswordsUIController::ManagePasswordsUIController(
70 content::WebContents* web_contents) 81 content::WebContents* web_contents)
71 : content::WebContentsObserver(web_contents), 82 : content::WebContentsObserver(web_contents),
72 state_(password_manager::ui::INACTIVE_STATE), 83 state_(password_manager::ui::INACTIVE_STATE),
73 should_pop_up_bubble_(false) { 84 should_pop_up_bubble_(false) {
74 password_manager::PasswordStore* password_store = 85 password_manager::PasswordStore* password_store =
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 const password_manager::PasswordStoreChangeList& changes) { 209 const password_manager::PasswordStoreChangeList& changes) {
199 password_manager::ui::State current_state = state_; 210 password_manager::ui::State current_state = state_;
200 for (password_manager::PasswordStoreChangeList::const_iterator it = 211 for (password_manager::PasswordStoreChangeList::const_iterator it =
201 changes.begin(); 212 changes.begin();
202 it != changes.end(); 213 it != changes.end();
203 it++) { 214 it++) {
204 const autofill::PasswordForm& changed_form = it->form(); 215 const autofill::PasswordForm& changed_form = it->form();
205 if (changed_form.origin != origin_) 216 if (changed_form.origin != origin_)
206 continue; 217 continue;
207 218
219 // TODO(vasilii): refactor this messy code after deciding how to transition
220 // within the new Credential Manager API states.
208 if (it->type() == password_manager::PasswordStoreChange::REMOVE) { 221 if (it->type() == password_manager::PasswordStoreChange::REMOVE) {
209 password_form_map_.erase(changed_form.username_value); 222 if (current_state == password_manager::ui::AUTO_SIGNIN_STATE ||
223 current_state == password_manager::ui::MANAGE_ACCOUNTS_STATE) {
224 RemoveFormFromVector(changed_form, &local_credentials_forms_);
225 } else {
226 password_form_map_.erase(changed_form.username_value);
227 }
210 if (changed_form.blacklisted_by_user) 228 if (changed_form.blacklisted_by_user)
211 SetState(password_manager::ui::MANAGE_STATE); 229 SetState(password_manager::ui::MANAGE_STATE);
212 } else { 230 } else {
213 new_password_forms_.push_back(new autofill::PasswordForm(changed_form)); 231 if (current_state == password_manager::ui::AUTO_SIGNIN_STATE ||
214 password_form_map_[changed_form.username_value] = 232 current_state == password_manager::ui::MANAGE_ACCOUNTS_STATE) {
215 new_password_forms_.back(); 233 if (it->type() == password_manager::PasswordStoreChange::UPDATE) {
234 RemoveFormFromVector(changed_form, &local_credentials_forms_);
235 }
236 local_credentials_forms_.push_back(
237 new autofill::PasswordForm(changed_form));
238 } else {
239 new_password_forms_.push_back(new autofill::PasswordForm(changed_form));
240 password_form_map_[changed_form.username_value] =
241 new_password_forms_.back();
242 }
216 if (changed_form.blacklisted_by_user) 243 if (changed_form.blacklisted_by_user)
217 SetState(password_manager::ui::BLACKLIST_STATE); 244 SetState(password_manager::ui::BLACKLIST_STATE);
218 } 245 }
219 } 246 }
220 // TODO(vasilii): handle CREDENTIAL_REQUEST_STATE.
221 if (current_state != state_) 247 if (current_state != state_)
222 UpdateBubbleAndIconVisibility(); 248 UpdateBubbleAndIconVisibility();
223 } 249 }
224 250
225 void ManagePasswordsUIController:: 251 void ManagePasswordsUIController::
226 NavigateToPasswordManagerSettingsPage() { 252 NavigateToPasswordManagerSettingsPage() {
227 #if defined(OS_ANDROID) 253 #if defined(OS_ANDROID)
228 chrome::android::ChromiumApplication::ShowPasswordSettings(); 254 chrome::android::ChromiumApplication::ShowPasswordSettings();
229 #else 255 #else
230 chrome::ShowSettingsSubPage( 256 chrome::ShowSettingsSubPage(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 DCHECK(password_form_map_.begin()->second); 334 DCHECK(password_form_map_.begin()->second);
309 DCHECK(state_ == password_manager::ui::BLACKLIST_STATE); 335 DCHECK(state_ == password_manager::ui::BLACKLIST_STATE);
310 password_manager::PasswordStore* password_store = 336 password_manager::PasswordStore* password_store =
311 GetPasswordStore(web_contents()); 337 GetPasswordStore(web_contents());
312 if (password_store) 338 if (password_store)
313 password_store->RemoveLogin(*password_form_map_.begin()->second); 339 password_store->RemoveLogin(*password_form_map_.begin()->second);
314 SetState(password_manager::ui::MANAGE_STATE); 340 SetState(password_manager::ui::MANAGE_STATE);
315 UpdateBubbleAndIconVisibility(); 341 UpdateBubbleAndIconVisibility();
316 } 342 }
317 343
344 void ManagePasswordsUIController::ManageAccounts() {
345 DCHECK_EQ(password_manager::ui::AUTO_SIGNIN_STATE, state_);
346 SetState(password_manager::ui::MANAGE_ACCOUNTS_STATE);
347 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true);
348 UpdateBubbleAndIconVisibility();
349 }
350
318 void ManagePasswordsUIController::DidNavigateMainFrame( 351 void ManagePasswordsUIController::DidNavigateMainFrame(
319 const content::LoadCommittedDetails& details, 352 const content::LoadCommittedDetails& details,
320 const content::FrameNavigateParams& params) { 353 const content::FrameNavigateParams& params) {
321 // Don't react to in-page (fragment) navigations. 354 // Don't react to in-page (fragment) navigations.
322 if (details.is_in_page) 355 if (details.is_in_page)
323 return; 356 return;
324 357
325 // Don't do anything if a navigation occurs before a user could reasonably 358 // Don't do anything if a navigation occurs before a user could reasonably
326 // interact with the password bubble. 359 // interact with the password bubble.
327 if (Elapsed() < base::TimeDelta::FromSeconds(1)) 360 if (Elapsed() < base::TimeDelta::FromSeconds(1))
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 should_pop_up_bubble_ = false; 419 should_pop_up_bubble_ = false;
387 } 420 }
388 421
389 void ManagePasswordsUIController::OnBubbleHidden() { 422 void ManagePasswordsUIController::OnBubbleHidden() {
390 password_manager::ui::State next_state = state_; 423 password_manager::ui::State next_state = state_;
391 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) 424 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE)
392 next_state = password_manager::ui::INACTIVE_STATE; 425 next_state = password_manager::ui::INACTIVE_STATE;
393 else if (state_ == password_manager::ui::CONFIRMATION_STATE) 426 else if (state_ == password_manager::ui::CONFIRMATION_STATE)
394 next_state = password_manager::ui::MANAGE_STATE; 427 next_state = password_manager::ui::MANAGE_STATE;
395 else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) 428 else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE)
396 next_state = password_manager::ui::INACTIVE_STATE; 429 next_state = password_manager::ui::MANAGE_ACCOUNTS_STATE;
397 430
398 if (next_state != state_) { 431 if (next_state != state_) {
399 SetState(next_state); 432 SetState(next_state);
400 UpdateBubbleAndIconVisibility(); 433 UpdateBubbleAndIconVisibility();
401 } 434 }
402 } 435 }
403 436
404 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { 437 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() {
405 DCHECK(should_pop_up_bubble_); 438 DCHECK(should_pop_up_bubble_);
406 #if !defined(OS_ANDROID) 439 #if !defined(OS_ANDROID)
(...skipping 24 matching lines...) Expand all
431 ScopedVector<autofill::PasswordForm> local_forms, 464 ScopedVector<autofill::PasswordForm> local_forms,
432 ScopedVector<autofill::PasswordForm> federated_forms) { 465 ScopedVector<autofill::PasswordForm> federated_forms) {
433 form_manager_.reset(); 466 form_manager_.reset();
434 origin_ = GURL(); 467 origin_ = GURL();
435 local_credentials_forms_.swap(local_forms); 468 local_credentials_forms_.swap(local_forms);
436 federated_credentials_forms_.swap(federated_forms); 469 federated_credentials_forms_.swap(federated_forms);
437 // The map is useless because usernames may overlap. 470 // The map is useless because usernames may overlap.
438 password_form_map_.clear(); 471 password_form_map_.clear();
439 new_password_forms_.clear(); 472 new_password_forms_.clear();
440 } 473 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698