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

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

Issue 228593002: Password bubble: Keep the bubble in sync with the password store. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: vabr's feedback. Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
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_ui_controller.h" 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/password_manager/password_store_factory.h"
8 #include "chrome/browser/ui/browser_finder.h" 9 #include "chrome/browser/ui/browser_finder.h"
9 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/omnibox/location_bar.h" 11 #include "chrome/browser/ui/omnibox/location_bar.h"
11 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
12 13
13 using autofill::PasswordFormMap; 14 using autofill::PasswordFormMap;
14 15
16 namespace {
17
18 PasswordStore* GetPasswordStore(content::WebContents* web_contents) {
19 return PasswordStoreFactory::GetForProfile(
20 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
21 Profile::EXPLICIT_ACCESS).get();
22 }
23
24 } // namespace
25
15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsBubbleUIController); 26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsBubbleUIController);
16 27
17 ManagePasswordsBubbleUIController::ManagePasswordsBubbleUIController( 28 ManagePasswordsBubbleUIController::ManagePasswordsBubbleUIController(
18 content::WebContents* web_contents) 29 content::WebContents* web_contents)
19 : content::WebContentsObserver(web_contents), 30 : content::WebContentsObserver(web_contents),
20 manage_passwords_icon_to_be_shown_(false), 31 manage_passwords_icon_to_be_shown_(false),
21 password_to_be_saved_(false), 32 password_to_be_saved_(false),
22 manage_passwords_bubble_needs_showing_(false), 33 manage_passwords_bubble_needs_showing_(false),
23 password_submitted_(false), 34 autofill_blocked_(false) {
24 autofill_blocked_(false) {} 35 PasswordStore* password_store = GetPasswordStore(web_contents);
36 if (password_store)
37 password_store->AddObserver(this);
38 }
25 39
26 ManagePasswordsBubbleUIController::~ManagePasswordsBubbleUIController() {} 40 ManagePasswordsBubbleUIController::~ManagePasswordsBubbleUIController() {}
27 41
28 void ManagePasswordsBubbleUIController::UpdateBubbleAndIconVisibility() { 42 void ManagePasswordsBubbleUIController::UpdateBubbleAndIconVisibility() {
29 #if !defined(OS_ANDROID) 43 #if !defined(OS_ANDROID)
30 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 44 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
31 if (!browser) 45 if (!browser)
32 return; 46 return;
33 LocationBar* location_bar = browser->window()->GetLocationBar(); 47 LocationBar* location_bar = browser->window()->GetLocationBar();
34 DCHECK(location_bar); 48 DCHECK(location_bar);
35 location_bar->UpdateManagePasswordsIconAndBubble(); 49 location_bar->UpdateManagePasswordsIconAndBubble();
36 #endif 50 #endif
37 } 51 }
38 52
39 void ManagePasswordsBubbleUIController::OnPasswordSubmitted( 53 void ManagePasswordsBubbleUIController::OnPasswordSubmitted(
40 PasswordFormManager* form_manager) { 54 PasswordFormManager* form_manager) {
41 form_manager_.reset(form_manager); 55 form_manager_.reset(form_manager);
42 password_form_map_ = form_manager_->best_matches(); 56 password_form_map_ = form_manager_->best_matches();
57 origin_ = pending_credentials().origin;
43 manage_passwords_icon_to_be_shown_ = true; 58 manage_passwords_icon_to_be_shown_ = true;
44 password_to_be_saved_ = true; 59 password_to_be_saved_ = true;
45 manage_passwords_bubble_needs_showing_ = true; 60 manage_passwords_bubble_needs_showing_ = true;
46 password_submitted_ = true;
47 autofill_blocked_ = false; 61 autofill_blocked_ = false;
48 UpdateBubbleAndIconVisibility(); 62 UpdateBubbleAndIconVisibility();
49 } 63 }
50 64
51 void ManagePasswordsBubbleUIController::OnPasswordAutofilled( 65 void ManagePasswordsBubbleUIController::OnPasswordAutofilled(
52 const PasswordFormMap& password_form_map) { 66 const PasswordFormMap& password_form_map) {
53 password_form_map_ = password_form_map; 67 password_form_map_ = password_form_map;
68 origin_ = password_form_map_.begin()->second->origin;
54 manage_passwords_icon_to_be_shown_ = true; 69 manage_passwords_icon_to_be_shown_ = true;
55 password_to_be_saved_ = false; 70 password_to_be_saved_ = false;
56 manage_passwords_bubble_needs_showing_ = false; 71 manage_passwords_bubble_needs_showing_ = false;
57 password_submitted_ = false;
58 autofill_blocked_ = false; 72 autofill_blocked_ = false;
59 UpdateBubbleAndIconVisibility(); 73 UpdateBubbleAndIconVisibility();
60 } 74 }
61 75
62 void ManagePasswordsBubbleUIController::OnBlacklistBlockedAutofill() { 76 void ManagePasswordsBubbleUIController::OnBlacklistBlockedAutofill() {
63 manage_passwords_icon_to_be_shown_ = true; 77 manage_passwords_icon_to_be_shown_ = true;
64 password_to_be_saved_ = false; 78 password_to_be_saved_ = false;
65 manage_passwords_bubble_needs_showing_ = false; 79 manage_passwords_bubble_needs_showing_ = false;
66 password_submitted_ = false;
67 autofill_blocked_ = true; 80 autofill_blocked_ = true;
68 UpdateBubbleAndIconVisibility(); 81 UpdateBubbleAndIconVisibility();
69 } 82 }
70 83
71 void ManagePasswordsBubbleUIController::RemoveFromBestMatches( 84 void ManagePasswordsBubbleUIController::WebContentsDestroyed(
72 autofill::PasswordForm password_form) { 85 content::WebContents* web_contents) {
73 password_form_map_.erase(password_form.username_value); 86 PasswordStore* password_store = GetPasswordStore(web_contents);
87 if (password_store)
88 password_store->RemoveObserver(this);
89 }
90
91 void ManagePasswordsBubbleUIController::OnLoginsChanged(
92 const PasswordStoreChangeList& changes) {
93 for (PasswordStoreChangeList::const_iterator it = changes.begin();
94 it != changes.end();
95 it++) {
96 const autofill::PasswordForm& changed_form = it->form();
97 if (changed_form.origin != origin_)
98 continue;
99
100 if (it->type() == PasswordStoreChange::REMOVE) {
101 password_form_map_.erase(changed_form.username_value);
102 } else {
103 autofill::PasswordForm* new_form =
104 new autofill::PasswordForm(changed_form);
105 password_form_map_[changed_form.username_value] = new_form;
106 }
107 }
74 } 108 }
75 109
76 void ManagePasswordsBubbleUIController::OnBubbleShown() { 110 void ManagePasswordsBubbleUIController::OnBubbleShown() {
77 unset_manage_passwords_bubble_needs_showing(); 111 unset_manage_passwords_bubble_needs_showing();
78 } 112 }
79 113
80 void ManagePasswordsBubbleUIController::SavePassword() { 114 void ManagePasswordsBubbleUIController::SavePassword() {
81 DCHECK(form_manager_.get()); 115 DCHECK(form_manager_.get());
82 form_manager_->Save(); 116 form_manager_->Save();
83 } 117 }
84 118
85 void ManagePasswordsBubbleUIController::NeverSavePassword() { 119 void ManagePasswordsBubbleUIController::NeverSavePassword() {
86 DCHECK(form_manager_.get()); 120 DCHECK(form_manager_.get());
87 form_manager_->PermanentlyBlacklist(); 121 form_manager_->PermanentlyBlacklist();
88 } 122 }
89 123
90 void ManagePasswordsBubbleUIController::DidNavigateMainFrame( 124 void ManagePasswordsBubbleUIController::DidNavigateMainFrame(
91 const content::LoadCommittedDetails& details, 125 const content::LoadCommittedDetails& details,
92 const content::FrameNavigateParams& params) { 126 const content::FrameNavigateParams& params) {
93 if (details.is_in_page) 127 if (details.is_in_page)
94 return; 128 return;
95 // Reset password states for next page. 129 // Reset password states for next page.
96 manage_passwords_icon_to_be_shown_ = false; 130 manage_passwords_icon_to_be_shown_ = false;
97 password_to_be_saved_ = false; 131 password_to_be_saved_ = false;
98 manage_passwords_bubble_needs_showing_ = false; 132 manage_passwords_bubble_needs_showing_ = false;
99 password_submitted_ = false;
100 UpdateBubbleAndIconVisibility(); 133 UpdateBubbleAndIconVisibility();
101 } 134 }
135
markusheintz_ 2014/04/10 13:22:12 nit: remove
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698