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

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