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

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

Issue 1009953002: Integrate ManagePasswordsState into ManagePasswordsUIController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: last comments 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 23 matching lines...) Expand all
34 34
35 namespace { 35 namespace {
36 36
37 password_manager::PasswordStore* GetPasswordStore( 37 password_manager::PasswordStore* GetPasswordStore(
38 content::WebContents* web_contents) { 38 content::WebContents* web_contents) {
39 return PasswordStoreFactory::GetForProfile( 39 return PasswordStoreFactory::GetForProfile(
40 Profile::FromBrowserContext(web_contents->GetBrowserContext()), 40 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
41 ServiceAccessType::EXPLICIT_ACCESS).get(); 41 ServiceAccessType::EXPLICIT_ACCESS).get();
42 } 42 }
43 43
44 autofill::ConstPasswordFormMap ConstifyMap(
45 const autofill::PasswordFormMap& map) {
46 autofill::ConstPasswordFormMap ret;
47 ret.insert(map.begin(), map.end());
48 return ret;
49 }
50
51 // Performs a deep copy of the PasswordForm pointers in |map|. The resulting map
52 // is returned via |ret|. |deleter| is populated with these new objects.
53 void DeepCopyMap(const autofill::PasswordFormMap& map,
54 autofill::ConstPasswordFormMap* ret,
55 ScopedVector<autofill::PasswordForm>* deleter) {
56 ConstifyMap(map).swap(*ret);
57 deleter->clear();
58 for (autofill::ConstPasswordFormMap::iterator i = ret->begin();
59 i != ret->end(); ++i) {
60 deleter->push_back(new autofill::PasswordForm(*i->second));
61 i->second = deleter->back();
62 }
63 }
64
65 } // namespace 44 } // namespace
66 45
67 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController); 46 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController);
68 47
69 ManagePasswordsUIController::ManagePasswordsUIController( 48 ManagePasswordsUIController::ManagePasswordsUIController(
70 content::WebContents* web_contents) 49 content::WebContents* web_contents)
71 : content::WebContentsObserver(web_contents), 50 : content::WebContentsObserver(web_contents),
72 state_(password_manager::ui::INACTIVE_STATE),
73 should_pop_up_bubble_(false) { 51 should_pop_up_bubble_(false) {
52 passwords_data_.set_client(
53 ChromePasswordManagerClient::FromWebContents(web_contents));
74 password_manager::PasswordStore* password_store = 54 password_manager::PasswordStore* password_store =
75 GetPasswordStore(web_contents); 55 GetPasswordStore(web_contents);
76 if (password_store) 56 if (password_store)
77 password_store->AddObserver(this); 57 password_store->AddObserver(this);
78 } 58 }
79 59
80 ManagePasswordsUIController::~ManagePasswordsUIController() {} 60 ManagePasswordsUIController::~ManagePasswordsUIController() {}
81 61
82 void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() { 62 void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() {
83 // If we're not on a "webby" URL (e.g. "chrome://sign-in"), we shouldn't 63 // If we're not on a "webby" URL (e.g. "chrome://sign-in"), we shouldn't
84 // display either the bubble or the icon. 64 // display either the bubble or the icon.
85 if (!BrowsingDataHelper::IsWebScheme( 65 if (!BrowsingDataHelper::IsWebScheme(
86 web_contents()->GetLastCommittedURL().scheme())) { 66 web_contents()->GetLastCommittedURL().scheme())) {
87 SetState(password_manager::ui::INACTIVE_STATE); 67 passwords_data_.OnInactive();
88 } 68 }
89 69
90 #if !defined(OS_ANDROID) 70 #if !defined(OS_ANDROID)
91 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 71 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
92 if (!browser) 72 if (!browser)
93 return; 73 return;
94 LocationBar* location_bar = browser->window()->GetLocationBar(); 74 LocationBar* location_bar = browser->window()->GetLocationBar();
95 DCHECK(location_bar); 75 DCHECK(location_bar);
96 location_bar->UpdateManagePasswordsIconAndBubble(); 76 location_bar->UpdateManagePasswordsIconAndBubble();
97 #endif 77 #endif
98 } 78 }
99 79
100 void ManagePasswordsUIController:: 80 void ManagePasswordsUIController::
101 UpdateAndroidAccountChooserInfoBarVisibility() { 81 UpdateAndroidAccountChooserInfoBarVisibility() {
102 #if defined(OS_ANDROID) 82 #if defined(OS_ANDROID)
103 AccountChooserInfoBarDelegateAndroid::Create( 83 AccountChooserInfoBarDelegateAndroid::Create(
104 InfoBarService::FromWebContents(web_contents()), this); 84 InfoBarService::FromWebContents(web_contents()), this);
105 should_pop_up_bubble_ = false; 85 should_pop_up_bubble_ = false;
106 #endif 86 #endif
107 } 87 }
108 88
109 base::TimeDelta ManagePasswordsUIController::Elapsed() const { 89 base::TimeDelta ManagePasswordsUIController::Elapsed() const {
110 return timer_ ? timer_->Elapsed() : base::TimeDelta::Max(); 90 return timer_ ? timer_->Elapsed() : base::TimeDelta::Max();
111 } 91 }
112 92
113 void ManagePasswordsUIController::OnPasswordSubmitted( 93 void ManagePasswordsUIController::OnPasswordSubmitted(
114 scoped_ptr<PasswordFormManager> form_manager) { 94 scoped_ptr<PasswordFormManager> form_manager) {
115 form_manager_ = form_manager.Pass(); 95 passwords_data_.OnPendingPassword(form_manager.Pass());
116 password_form_map_ = ConstifyMap(form_manager_->best_matches());
117 origin_ = PendingPassword().origin;
118 SetState(password_manager::ui::PENDING_PASSWORD_STATE);
119 timer_.reset(new base::ElapsedTimer); 96 timer_.reset(new base::ElapsedTimer);
120 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true); 97 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true);
121 UpdateBubbleAndIconVisibility(); 98 UpdateBubbleAndIconVisibility();
122 } 99 }
123 100
124 bool ManagePasswordsUIController::OnChooseCredentials( 101 bool ManagePasswordsUIController::OnChooseCredentials(
125 ScopedVector<autofill::PasswordForm> local_credentials, 102 ScopedVector<autofill::PasswordForm> local_credentials,
126 ScopedVector<autofill::PasswordForm> federated_credentials, 103 ScopedVector<autofill::PasswordForm> federated_credentials,
127 const GURL& origin, 104 const GURL& origin,
128 base::Callback<void(const password_manager::CredentialInfo&)> callback) { 105 base::Callback<void(const password_manager::CredentialInfo&)> callback) {
129 DCHECK(!local_credentials.empty() || !federated_credentials.empty()); 106 DCHECK_IMPLIES(local_credentials.empty(), !federated_credentials.empty());
130 SaveForms(local_credentials.Pass(), federated_credentials.Pass()); 107 passwords_data_.OnRequestCredentials(local_credentials.Pass(),
131 origin_ = origin; 108 federated_credentials.Pass(),
132 SetState(password_manager::ui::CREDENTIAL_REQUEST_STATE); 109 origin);
133 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true); 110 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true);
134 #if defined(OS_ANDROID) 111 #if defined(OS_ANDROID)
135 UpdateAndroidAccountChooserInfoBarVisibility(); 112 UpdateAndroidAccountChooserInfoBarVisibility();
136 #else 113 #else
137 UpdateBubbleAndIconVisibility(); 114 UpdateBubbleAndIconVisibility();
138 #endif 115 #endif
139 if (!should_pop_up_bubble_) { 116 if (!should_pop_up_bubble_) {
140 credentials_callback_ = callback; 117 passwords_data_.set_credentials_callback(callback);
141 return true; 118 return true;
142 } 119 }
120 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE);
143 return false; 121 return false;
144 } 122 }
145 123
146 void ManagePasswordsUIController::OnAutoSignin( 124 void ManagePasswordsUIController::OnAutoSignin(
147 ScopedVector<autofill::PasswordForm> local_forms) { 125 ScopedVector<autofill::PasswordForm> local_forms) {
148 DCHECK(!local_forms.empty()); 126 DCHECK(!local_forms.empty());
149 SaveForms(local_forms.Pass(), ScopedVector<autofill::PasswordForm>()); 127 passwords_data_.OnAutoSignin(local_forms.Pass());
150 origin_ = local_credentials_forms_[0]->origin;
151 SetState(password_manager::ui::AUTO_SIGNIN_STATE);
152 timer_.reset(new base::ElapsedTimer); 128 timer_.reset(new base::ElapsedTimer);
153 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true); 129 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true);
154 UpdateBubbleAndIconVisibility(); 130 UpdateBubbleAndIconVisibility();
155 } 131 }
156 132
157 void ManagePasswordsUIController::OnAutomaticPasswordSave( 133 void ManagePasswordsUIController::OnAutomaticPasswordSave(
158 scoped_ptr<PasswordFormManager> form_manager) { 134 scoped_ptr<PasswordFormManager> form_manager) {
159 form_manager_ = form_manager.Pass(); 135 passwords_data_.OnAutomaticPasswordSave(form_manager.Pass());
160 password_form_map_ = ConstifyMap(form_manager_->best_matches());
161 password_form_map_[form_manager_->associated_username()] =
162 &form_manager_->pending_credentials();
163 origin_ = form_manager_->pending_credentials().origin;
164 SetState(password_manager::ui::CONFIRMATION_STATE);
165 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true); 136 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true);
166 UpdateBubbleAndIconVisibility(); 137 UpdateBubbleAndIconVisibility();
167 } 138 }
168 139
169 void ManagePasswordsUIController::OnPasswordAutofilled( 140 void ManagePasswordsUIController::OnPasswordAutofilled(
170 const PasswordFormMap& password_form_map) { 141 const PasswordFormMap& password_form_map) {
171 DeepCopyMap(password_form_map, &password_form_map_, &new_password_forms_); 142 passwords_data_.OnPasswordAutofilled(password_form_map);
172 origin_ = password_form_map_.begin()->second->origin;
173 // Don't show the UI for PSL matched passwords. They are not stored for this
174 // page and cannot be deleted.
175 SetState(password_form_map_.begin()->second->IsPublicSuffixMatch()
176 ? password_manager::ui::INACTIVE_STATE
177 : password_manager::ui::MANAGE_STATE);
178 UpdateBubbleAndIconVisibility(); 143 UpdateBubbleAndIconVisibility();
179 } 144 }
180 145
181 void ManagePasswordsUIController::OnBlacklistBlockedAutofill( 146 void ManagePasswordsUIController::OnBlacklistBlockedAutofill(
182 const PasswordFormMap& password_form_map) { 147 const PasswordFormMap& password_form_map) {
183 DeepCopyMap(password_form_map, &password_form_map_, &new_password_forms_); 148 passwords_data_.OnBlacklistBlockedAutofill(password_form_map);
184 origin_ = password_form_map_.begin()->second->origin;
185 SetState(password_manager::ui::BLACKLIST_STATE);
186 UpdateBubbleAndIconVisibility(); 149 UpdateBubbleAndIconVisibility();
187 } 150 }
188 151
189 void ManagePasswordsUIController::OnLoginsChanged( 152 void ManagePasswordsUIController::OnLoginsChanged(
190 const password_manager::PasswordStoreChangeList& changes) { 153 const password_manager::PasswordStoreChangeList& changes) {
191 password_manager::ui::State current_state = state_; 154 password_manager::ui::State current_state = state();
192 for (password_manager::PasswordStoreChangeList::const_iterator it = 155 passwords_data_.ProcessLoginsChanged(changes);
193 changes.begin(); 156 if (current_state != state())
194 it != changes.end();
195 it++) {
196 const autofill::PasswordForm& changed_form = it->form();
197 if (changed_form.origin != origin_)
198 continue;
199
200 if (it->type() == password_manager::PasswordStoreChange::REMOVE) {
201 password_form_map_.erase(changed_form.username_value);
202 if (changed_form.blacklisted_by_user)
203 SetState(password_manager::ui::MANAGE_STATE);
204 } else {
205 new_password_forms_.push_back(new autofill::PasswordForm(changed_form));
206 password_form_map_[changed_form.username_value] =
207 new_password_forms_.back();
208 if (changed_form.blacklisted_by_user)
209 SetState(password_manager::ui::BLACKLIST_STATE);
210 }
211 }
212 // TODO(vasilii): handle CREDENTIAL_REQUEST_STATE.
213 if (current_state != state_)
214 UpdateBubbleAndIconVisibility(); 157 UpdateBubbleAndIconVisibility();
215 } 158 }
216 159
217 void ManagePasswordsUIController:: 160 void ManagePasswordsUIController::
218 NavigateToPasswordManagerSettingsPage() { 161 NavigateToPasswordManagerSettingsPage() {
219 #if defined(OS_ANDROID) 162 #if defined(OS_ANDROID)
220 chrome::android::ChromiumApplication::ShowPasswordSettings(); 163 chrome::android::ChromiumApplication::ShowPasswordSettings();
221 #else 164 #else
222 chrome::ShowSettingsSubPage( 165 chrome::ShowSettingsSubPage(
223 chrome::FindBrowserWithWebContents(web_contents()), 166 chrome::FindBrowserWithWebContents(web_contents()),
224 chrome::kPasswordManagerSubPage); 167 chrome::kPasswordManagerSubPage);
225 #endif 168 #endif
226 } 169 }
227 170
228 void ManagePasswordsUIController::SavePassword() { 171 void ManagePasswordsUIController::SavePassword() {
229 DCHECK(PasswordPendingUserDecision()); 172 DCHECK(PasswordPendingUserDecision());
230 SavePasswordInternal(); 173 SavePasswordInternal();
231 SetState(password_manager::ui::MANAGE_STATE); 174 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE);
232 UpdateBubbleAndIconVisibility(); 175 UpdateBubbleAndIconVisibility();
233 } 176 }
234 177
235 void ManagePasswordsUIController::ChooseCredential( 178 void ManagePasswordsUIController::ChooseCredential(
236 const autofill::PasswordForm& form, 179 const autofill::PasswordForm& form,
237 password_manager::CredentialType credential_type) { 180 password_manager::CredentialType credential_type) {
238 DCHECK_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, state_); 181 DCHECK_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, state());
239 DCHECK(!credentials_callback_.is_null()); 182 DCHECK(!passwords_data_.credentials_callback().is_null());
240 183
241 // Here, |credential_type| refers to whether the credential was originally 184 // Here, |credential_type| refers to whether the credential was originally
242 // passed into ::OnChooseCredentials as part of the |local_credentials| or 185 // passed into ::OnChooseCredentials as part of the |local_credentials| or
243 // |federated_credentials| lists (e.g. whether it is an existing credential 186 // |federated_credentials| lists (e.g. whether it is an existing credential
244 // saved for this origin, or whether we should synthesize a new 187 // saved for this origin, or whether we should synthesize a new
245 // FederatedCredential). 188 // FederatedCredential).
246 // 189 //
247 // If |credential_type| is federated, the credential MUST be returned as 190 // If |credential_type| is federated, the credential MUST be returned as
248 // a FederatedCredential in order to prevent password information leaking 191 // a FederatedCredential in order to prevent password information leaking
249 // cross-origin. 192 // cross-origin.
(...skipping 10 matching lines...) Expand all
260 type_to_return = password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL; 203 type_to_return = password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL;
261 } else if (credential_type == 204 } else if (credential_type ==
262 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY) { 205 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY) {
263 type_to_return = password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY; 206 type_to_return = password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY;
264 } else { 207 } else {
265 type_to_return = 208 type_to_return =
266 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED; 209 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED;
267 } 210 }
268 password_manager::CredentialInfo info = 211 password_manager::CredentialInfo info =
269 password_manager::CredentialInfo(form, type_to_return); 212 password_manager::CredentialInfo(form, type_to_return);
270 credentials_callback_.Run(info); 213 passwords_data_.credentials_callback().Run(info);
271 credentials_callback_.Reset(); 214 passwords_data_.set_credentials_callback(
215 ManagePasswordsState::CredentialsCallback());
272 } 216 }
273 217
274 void ManagePasswordsUIController::SavePasswordInternal() { 218 void ManagePasswordsUIController::SavePasswordInternal() {
275 DCHECK(form_manager_.get()); 219 password_manager::PasswordFormManager* form_manager =
276 form_manager_->Save(); 220 passwords_data_.form_manager();
221 DCHECK(form_manager);
222 form_manager->Save();
277 } 223 }
278 224
279 void ManagePasswordsUIController::NeverSavePassword() { 225 void ManagePasswordsUIController::NeverSavePassword() {
280 DCHECK(PasswordPendingUserDecision()); 226 DCHECK(PasswordPendingUserDecision());
281 NeverSavePasswordInternal(); 227 NeverSavePasswordInternal();
282 SetState(password_manager::ui::BLACKLIST_STATE); 228 passwords_data_.TransitionToState(password_manager::ui::BLACKLIST_STATE);
283 UpdateBubbleAndIconVisibility(); 229 UpdateBubbleAndIconVisibility();
284 } 230 }
285 231
286 void ManagePasswordsUIController::NeverSavePasswordInternal() { 232 void ManagePasswordsUIController::NeverSavePasswordInternal() {
287 DCHECK(form_manager_.get()); 233 password_manager::PasswordFormManager* form_manager =
288 form_manager_->PermanentlyBlacklist(); 234 passwords_data_.form_manager();
235 DCHECK(form_manager);
236 form_manager->PermanentlyBlacklist();
289 } 237 }
290 238
291 void ManagePasswordsUIController::UnblacklistSite() { 239 void ManagePasswordsUIController::UnblacklistSite() {
292 // We're in one of two states: either the user _just_ blacklisted the site 240 // We're in one of two states: either the user _just_ blacklisted the site
293 // by clicking "Never save" in the pending bubble, or the user is visiting 241 // by clicking "Never save" in the pending bubble, or the user is visiting
294 // a blacklisted site. 242 // a blacklisted site.
295 // 243 //
296 // Either way, |password_form_map_| has been populated with the relevant 244 // Either way, |passwords_data_| has been populated with the relevant form. We
297 // form. We can safely pull it out, send it over to the password store 245 // can safely pull it out, send it over to the password store for removal, and
298 // for removal, and update our internal state. 246 // update our internal state.
299 DCHECK(!password_form_map_.empty()); 247 DCHECK(!passwords_data_.GetCurrentForms().empty());
300 DCHECK(password_form_map_.begin()->second); 248 DCHECK_EQ(password_manager::ui::BLACKLIST_STATE, state());
301 DCHECK(state_ == password_manager::ui::BLACKLIST_STATE);
302 password_manager::PasswordStore* password_store = 249 password_manager::PasswordStore* password_store =
303 GetPasswordStore(web_contents()); 250 GetPasswordStore(web_contents());
251 DCHECK(GetCurrentForms().front()->blacklisted_by_user);
304 if (password_store) 252 if (password_store)
305 password_store->RemoveLogin(*password_form_map_.begin()->second); 253 password_store->RemoveLogin(*GetCurrentForms().front());
306 SetState(password_manager::ui::MANAGE_STATE); 254 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE);
307 UpdateBubbleAndIconVisibility(); 255 UpdateBubbleAndIconVisibility();
308 } 256 }
309 257
310 void ManagePasswordsUIController::DidNavigateMainFrame( 258 void ManagePasswordsUIController::DidNavigateMainFrame(
311 const content::LoadCommittedDetails& details, 259 const content::LoadCommittedDetails& details,
312 const content::FrameNavigateParams& params) { 260 const content::FrameNavigateParams& params) {
313 // Don't react to in-page (fragment) navigations. 261 // Don't react to in-page (fragment) navigations.
314 if (details.is_in_page) 262 if (details.is_in_page)
315 return; 263 return;
316 264
317 // Don't do anything if a navigation occurs before a user could reasonably 265 // Don't do anything if a navigation occurs before a user could reasonably
318 // interact with the password bubble. 266 // interact with the password bubble.
319 if (Elapsed() < base::TimeDelta::FromSeconds(1)) 267 if (Elapsed() < base::TimeDelta::FromSeconds(1))
320 return; 268 return;
321 269
322 // Otherwise, reset the password manager and the timer. 270 // Otherwise, reset the password manager and the timer.
323 SetState(password_manager::ui::INACTIVE_STATE); 271 passwords_data_.OnInactive();
324 UpdateBubbleAndIconVisibility(); 272 UpdateBubbleAndIconVisibility();
325 // This allows the bubble to survive several redirects in case the whole 273 // This allows the bubble to survive several redirects in case the whole
326 // process of navigating to the landing page is longer than 1 second. 274 // process of navigating to the landing page is longer than 1 second.
327 timer_.reset(new base::ElapsedTimer()); 275 timer_.reset(new base::ElapsedTimer());
328 } 276 }
329 277
330 void ManagePasswordsUIController::WasHidden() { 278 void ManagePasswordsUIController::WasHidden() {
331 #if !defined(OS_ANDROID) 279 #if !defined(OS_ANDROID)
332 TabDialogs::FromWebContents(web_contents())->HideManagePasswordsBubble(); 280 TabDialogs::FromWebContents(web_contents())->HideManagePasswordsBubble();
333 #endif 281 #endif
334 } 282 }
335 283
336 void ManagePasswordsUIController::SetState(password_manager::ui::State state) {
337 password_manager::PasswordManagerClient* client =
338 ChromePasswordManagerClient::FromWebContents(web_contents());
339 // |client| might be NULL in tests.
340 if (client && client->IsLoggingActive()) {
341 password_manager::BrowserSavePasswordProgressLogger logger(client);
342 logger.LogNumber(
343 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE,
344 state);
345 }
346 state_ = state;
347 }
348
349 const autofill::PasswordForm& ManagePasswordsUIController:: 284 const autofill::PasswordForm& ManagePasswordsUIController::
350 PendingPassword() const { 285 PendingPassword() const {
351 DCHECK(form_manager_); 286 DCHECK(state() == password_manager::ui::PENDING_PASSWORD_STATE ||
352 return form_manager_->pending_credentials(); 287 state() == password_manager::ui::CONFIRMATION_STATE) << state();
288 password_manager::PasswordFormManager* form_manager =
289 passwords_data_.form_manager();
290 DCHECK(form_manager);
291 return form_manager->pending_credentials();
353 } 292 }
354 293
355 void ManagePasswordsUIController::UpdateIconAndBubbleState( 294 void ManagePasswordsUIController::UpdateIconAndBubbleState(
356 ManagePasswordsIcon* icon) { 295 ManagePasswordsIcon* icon) {
357 if (should_pop_up_bubble_) { 296 if (should_pop_up_bubble_) {
358 // We must display the icon before showing the bubble, as the bubble would 297 // We must display the icon before showing the bubble, as the bubble would
359 // be otherwise unanchored. 298 // be otherwise unanchored.
360 icon->SetState(state_); 299 icon->SetState(state());
361 ShowBubbleWithoutUserInteraction(); 300 ShowBubbleWithoutUserInteraction();
362 } else { 301 } else {
363 icon->SetState(state_); 302 icon->SetState(state());
364 } 303 }
365 } 304 }
366 305
367 void ManagePasswordsUIController::OnBubbleShown() { 306 void ManagePasswordsUIController::OnBubbleShown() {
368 should_pop_up_bubble_ = false; 307 should_pop_up_bubble_ = false;
369 } 308 }
370 309
371 void ManagePasswordsUIController::OnBubbleHidden() { 310 void ManagePasswordsUIController::OnBubbleHidden() {
372 password_manager::ui::State next_state = state_; 311 password_manager::ui::State next_state = state();
373 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) 312 if (state() == password_manager::ui::CREDENTIAL_REQUEST_STATE)
374 next_state = password_manager::ui::INACTIVE_STATE;
375 else if (state_ == password_manager::ui::CONFIRMATION_STATE)
376 next_state = password_manager::ui::MANAGE_STATE; 313 next_state = password_manager::ui::MANAGE_STATE;
377 else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) 314 else if (state() == password_manager::ui::CONFIRMATION_STATE)
315 next_state = password_manager::ui::MANAGE_STATE;
316 else if (state() == password_manager::ui::AUTO_SIGNIN_STATE)
378 next_state = password_manager::ui::INACTIVE_STATE; 317 next_state = password_manager::ui::INACTIVE_STATE;
379 318
380 if (next_state != state_) { 319 if (next_state != state()) {
381 SetState(next_state); 320 if (next_state == password_manager::ui::INACTIVE_STATE)
321 passwords_data_.OnInactive();
322 else
323 passwords_data_.TransitionToState(next_state);
382 UpdateBubbleAndIconVisibility(); 324 UpdateBubbleAndIconVisibility();
383 } 325 }
384 } 326 }
385 327
386 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { 328 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() {
387 DCHECK(should_pop_up_bubble_); 329 DCHECK(should_pop_up_bubble_);
388 #if !defined(OS_ANDROID) 330 #if !defined(OS_ANDROID)
389 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 331 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
390 if (!browser || browser->toolbar_model()->input_in_progress()) 332 if (!browser || browser->toolbar_model()->input_in_progress())
391 return; 333 return;
392 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE && 334 if (state() == password_manager::ui::PENDING_PASSWORD_STATE &&
393 !password_bubble_experiment::ShouldShowBubble( 335 !password_bubble_experiment::ShouldShowBubble(
394 browser->profile()->GetPrefs())) 336 browser->profile()->GetPrefs()))
395 return; 337 return;
396 CommandUpdater* updater = browser->command_controller()->command_updater(); 338 CommandUpdater* updater = browser->command_controller()->command_updater();
397 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); 339 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE);
398 #endif 340 #endif
399 } 341 }
400 342
401 bool ManagePasswordsUIController::PasswordPendingUserDecision() const {
402 return state_ == password_manager::ui::PENDING_PASSWORD_STATE;
403 }
404
405 void ManagePasswordsUIController::WebContentsDestroyed() { 343 void ManagePasswordsUIController::WebContentsDestroyed() {
406 password_manager::PasswordStore* password_store = 344 password_manager::PasswordStore* password_store =
407 GetPasswordStore(web_contents()); 345 GetPasswordStore(web_contents());
408 if (password_store) 346 if (password_store)
409 password_store->RemoveObserver(this); 347 password_store->RemoveObserver(this);
410 } 348 }
411
412 void ManagePasswordsUIController::SaveForms(
413 ScopedVector<autofill::PasswordForm> local_forms,
414 ScopedVector<autofill::PasswordForm> federated_forms) {
415 form_manager_.reset();
416 origin_ = GURL();
417 local_credentials_forms_.swap(local_forms);
418 federated_credentials_forms_.swap(federated_forms);
419 // The map is useless because usernames may overlap.
420 password_form_map_.clear();
421 new_password_forms_.clear();
422 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698