OLD | NEW |
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" |
11 #include "chrome/browser/password_manager/password_store_factory.h" | 11 #include "chrome/browser/password_manager/password_store_factory.h" |
12 #include "chrome/browser/ui/browser_command_controller.h" | 12 #include "chrome/browser/ui/browser_command_controller.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/browser_navigator_params.h" | 14 #include "chrome/browser/ui/browser_navigator_params.h" |
15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/browser/ui/chrome_pages.h" | 16 #include "chrome/browser/ui/chrome_pages.h" |
17 #include "chrome/browser/ui/location_bar/location_bar.h" | 17 #include "chrome/browser/ui/location_bar/location_bar.h" |
18 #include "chrome/browser/ui/tab_dialogs.h" | 18 #include "chrome/browser/ui/tab_dialogs.h" |
19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
20 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
21 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" | 21 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" |
22 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 22 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
23 #include "components/password_manager/core/browser/password_form_manager.h" | 23 #include "components/password_manager/core/browser/password_form_manager.h" |
24 #include "components/password_manager/core/common/credential_manager_types.h" | 24 #include "components/password_manager/core/common/credential_manager_types.h" |
25 #include "content/public/browser/navigation_details.h" | 25 #include "content/public/browser/navigation_details.h" |
26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
27 | 27 |
28 #if defined(OS_ANDROID) | 28 #if defined(ANDROID_JAVA_UI) |
29 #include "chrome/browser/android/chrome_application.h" | 29 #include "chrome/browser/android/chrome_application.h" |
30 #include "chrome/browser/infobars/infobar_service.h" | 30 #include "chrome/browser/infobars/infobar_service.h" |
31 #include "chrome/browser/password_manager/account_chooser_dialog_android.h" | 31 #include "chrome/browser/password_manager/account_chooser_dialog_android.h" |
32 #else | 32 #else |
33 #include "chrome/browser/ui/passwords/manage_passwords_icon_view.h" | 33 #include "chrome/browser/ui/passwords/manage_passwords_icon_view.h" |
34 #endif | 34 #endif |
35 | 35 |
36 using autofill::PasswordFormMap; | 36 using autofill::PasswordFormMap; |
37 using password_manager::PasswordFormManager; | 37 using password_manager::PasswordFormManager; |
38 | 38 |
(...skipping 28 matching lines...) Expand all Loading... |
67 ManagePasswordsUIController::~ManagePasswordsUIController() {} | 67 ManagePasswordsUIController::~ManagePasswordsUIController() {} |
68 | 68 |
69 void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() { | 69 void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() { |
70 // If we're not on a "webby" URL (e.g. "chrome://sign-in"), we shouldn't | 70 // If we're not on a "webby" URL (e.g. "chrome://sign-in"), we shouldn't |
71 // display either the bubble or the icon. | 71 // display either the bubble or the icon. |
72 if (!BrowsingDataHelper::IsWebScheme( | 72 if (!BrowsingDataHelper::IsWebScheme( |
73 web_contents()->GetLastCommittedURL().scheme())) { | 73 web_contents()->GetLastCommittedURL().scheme())) { |
74 passwords_data_.OnInactive(); | 74 passwords_data_.OnInactive(); |
75 } | 75 } |
76 | 76 |
77 #if !defined(OS_ANDROID) | 77 #if !defined(ANDROID_JAVA_UI) |
78 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 78 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
79 if (!browser) | 79 if (!browser) |
80 return; | 80 return; |
81 LocationBar* location_bar = browser->window()->GetLocationBar(); | 81 LocationBar* location_bar = browser->window()->GetLocationBar(); |
82 DCHECK(location_bar); | 82 DCHECK(location_bar); |
83 location_bar->UpdateManagePasswordsIconAndBubble(); | 83 location_bar->UpdateManagePasswordsIconAndBubble(); |
84 #endif | 84 #endif |
85 } | 85 } |
86 | 86 |
87 void ManagePasswordsUIController:: | 87 void ManagePasswordsUIController:: |
88 UpdateAndroidAccountChooserInfoBarVisibility() { | 88 UpdateAndroidAccountChooserInfoBarVisibility() { |
89 #if defined(OS_ANDROID) | 89 #if defined(ANDROID_JAVA_UI) |
90 // Deletes itself on the event from Java counterpart, when user interacts with | 90 // Deletes itself on the event from Java counterpart, when user interacts with |
91 // dialog. | 91 // dialog. |
92 AccountChooserDialogAndroid* acccount_chooser_dialog = | 92 AccountChooserDialogAndroid* acccount_chooser_dialog = |
93 new AccountChooserDialogAndroid(web_contents(), this); | 93 new AccountChooserDialogAndroid(web_contents(), this); |
94 acccount_chooser_dialog->ShowDialog(); | 94 acccount_chooser_dialog->ShowDialog(); |
95 should_pop_up_bubble_ = false; | 95 should_pop_up_bubble_ = false; |
96 #endif | 96 #endif |
97 } | 97 } |
98 | 98 |
99 base::TimeDelta ManagePasswordsUIController::Elapsed() const { | 99 base::TimeDelta ManagePasswordsUIController::Elapsed() const { |
(...skipping 20 matching lines...) Expand all Loading... |
120 bool ManagePasswordsUIController::OnChooseCredentials( | 120 bool ManagePasswordsUIController::OnChooseCredentials( |
121 ScopedVector<autofill::PasswordForm> local_credentials, | 121 ScopedVector<autofill::PasswordForm> local_credentials, |
122 ScopedVector<autofill::PasswordForm> federated_credentials, | 122 ScopedVector<autofill::PasswordForm> federated_credentials, |
123 const GURL& origin, | 123 const GURL& origin, |
124 base::Callback<void(const password_manager::CredentialInfo&)> callback) { | 124 base::Callback<void(const password_manager::CredentialInfo&)> callback) { |
125 DCHECK(!local_credentials.empty() || !federated_credentials.empty()); | 125 DCHECK(!local_credentials.empty() || !federated_credentials.empty()); |
126 passwords_data_.OnRequestCredentials(local_credentials.Pass(), | 126 passwords_data_.OnRequestCredentials(local_credentials.Pass(), |
127 federated_credentials.Pass(), | 127 federated_credentials.Pass(), |
128 origin); | 128 origin); |
129 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true); | 129 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true); |
130 #if defined(OS_ANDROID) | 130 #if defined(ANDROID_JAVA_UI) |
131 UpdateAndroidAccountChooserInfoBarVisibility(); | 131 UpdateAndroidAccountChooserInfoBarVisibility(); |
132 #else | 132 #else |
133 UpdateBubbleAndIconVisibility(); | 133 UpdateBubbleAndIconVisibility(); |
134 #endif | 134 #endif |
135 if (!should_pop_up_bubble_) { | 135 if (!should_pop_up_bubble_) { |
136 passwords_data_.set_credentials_callback(callback); | 136 passwords_data_.set_credentials_callback(callback); |
137 return true; | 137 return true; |
138 } | 138 } |
139 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); | 139 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); |
140 return false; | 140 return false; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 void ManagePasswordsUIController::OnLoginsChanged( | 175 void ManagePasswordsUIController::OnLoginsChanged( |
176 const password_manager::PasswordStoreChangeList& changes) { | 176 const password_manager::PasswordStoreChangeList& changes) { |
177 password_manager::ui::State current_state = state(); | 177 password_manager::ui::State current_state = state(); |
178 passwords_data_.ProcessLoginsChanged(changes); | 178 passwords_data_.ProcessLoginsChanged(changes); |
179 if (current_state != state()) | 179 if (current_state != state()) |
180 UpdateBubbleAndIconVisibility(); | 180 UpdateBubbleAndIconVisibility(); |
181 } | 181 } |
182 | 182 |
183 void ManagePasswordsUIController::NavigateToPasswordManagerSettingsPage() { | 183 void ManagePasswordsUIController::NavigateToPasswordManagerSettingsPage() { |
184 #if defined(OS_ANDROID) | 184 #if defined(ANDROID_JAVA_UI) |
185 chrome::android::ChromeApplication::ShowPasswordSettings(); | 185 chrome::android::ChromeApplication::ShowPasswordSettings(); |
186 #else | 186 #else |
187 chrome::ShowSettingsSubPage( | 187 chrome::ShowSettingsSubPage( |
188 chrome::FindBrowserWithWebContents(web_contents()), | 188 chrome::FindBrowserWithWebContents(web_contents()), |
189 chrome::kPasswordManagerSubPage); | 189 chrome::kPasswordManagerSubPage); |
190 #endif | 190 #endif |
191 } | 191 } |
192 | 192 |
193 void ManagePasswordsUIController::NavigateToExternalPasswordManager() { | 193 void ManagePasswordsUIController::NavigateToExternalPasswordManager() { |
194 #if defined(OS_ANDROID) | 194 #if defined(ANDROID_JAVA_UI) |
195 NOTREACHED(); | 195 NOTREACHED(); |
196 #else | 196 #else |
197 chrome::NavigateParams params( | 197 chrome::NavigateParams params( |
198 chrome::FindBrowserWithWebContents(web_contents()), | 198 chrome::FindBrowserWithWebContents(web_contents()), |
199 GURL(chrome::kPasswordManagerAccountDashboardURL), | 199 GURL(chrome::kPasswordManagerAccountDashboardURL), |
200 ui::PAGE_TRANSITION_LINK); | 200 ui::PAGE_TRANSITION_LINK); |
201 params.disposition = NEW_FOREGROUND_TAB; | 201 params.disposition = NEW_FOREGROUND_TAB; |
202 chrome::Navigate(¶ms); | 202 chrome::Navigate(¶ms); |
203 #endif | 203 #endif |
204 } | 204 } |
205 | 205 |
206 void ManagePasswordsUIController::NavigateToSmartLockPage() { | 206 void ManagePasswordsUIController::NavigateToSmartLockPage() { |
207 #if defined(OS_ANDROID) | 207 #if defined(ANDROID_JAVA_UI) |
208 NOTREACHED(); | 208 NOTREACHED(); |
209 #else | 209 #else |
210 chrome::NavigateParams params( | 210 chrome::NavigateParams params( |
211 chrome::FindBrowserWithWebContents(web_contents()), | 211 chrome::FindBrowserWithWebContents(web_contents()), |
212 GURL(l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK_PAGE)), | 212 GURL(l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK_PAGE)), |
213 ui::PAGE_TRANSITION_LINK); | 213 ui::PAGE_TRANSITION_LINK); |
214 params.disposition = NEW_FOREGROUND_TAB; | 214 params.disposition = NEW_FOREGROUND_TAB; |
215 chrome::Navigate(¶ms); | 215 chrome::Navigate(¶ms); |
216 #endif | 216 #endif |
217 } | 217 } |
218 | 218 |
219 void ManagePasswordsUIController::NavigateToSmartLockHelpPage() { | 219 void ManagePasswordsUIController::NavigateToSmartLockHelpPage() { |
220 #if defined(OS_ANDROID) | 220 #if defined(ANDROID_JAVA_UI) |
221 NOTREACHED(); | 221 NOTREACHED(); |
222 #else | 222 #else |
223 chrome::NavigateParams params( | 223 chrome::NavigateParams params( |
224 chrome::FindBrowserWithWebContents(web_contents()), | 224 chrome::FindBrowserWithWebContents(web_contents()), |
225 GURL(chrome::kSmartLockHelpPage), ui::PAGE_TRANSITION_LINK); | 225 GURL(chrome::kSmartLockHelpPage), ui::PAGE_TRANSITION_LINK); |
226 params.disposition = NEW_FOREGROUND_TAB; | 226 params.disposition = NEW_FOREGROUND_TAB; |
227 chrome::Navigate(¶ms); | 227 chrome::Navigate(¶ms); |
228 #endif | 228 #endif |
229 } | 229 } |
230 | 230 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 296 |
297 // Otherwise, reset the password manager and the timer. | 297 // Otherwise, reset the password manager and the timer. |
298 passwords_data_.OnInactive(); | 298 passwords_data_.OnInactive(); |
299 UpdateBubbleAndIconVisibility(); | 299 UpdateBubbleAndIconVisibility(); |
300 // This allows the bubble to survive several redirects in case the whole | 300 // This allows the bubble to survive several redirects in case the whole |
301 // process of navigating to the landing page is longer than 1 second. | 301 // process of navigating to the landing page is longer than 1 second. |
302 timer_.reset(new base::ElapsedTimer()); | 302 timer_.reset(new base::ElapsedTimer()); |
303 } | 303 } |
304 | 304 |
305 void ManagePasswordsUIController::WasHidden() { | 305 void ManagePasswordsUIController::WasHidden() { |
306 #if !defined(OS_ANDROID) | 306 #if !defined(ANDROID_JAVA_UI) |
307 TabDialogs::FromWebContents(web_contents())->HideManagePasswordsBubble(); | 307 TabDialogs::FromWebContents(web_contents())->HideManagePasswordsBubble(); |
308 #endif | 308 #endif |
309 } | 309 } |
310 | 310 |
311 const autofill::PasswordForm& ManagePasswordsUIController:: | 311 const autofill::PasswordForm& ManagePasswordsUIController:: |
312 PendingPassword() const { | 312 PendingPassword() const { |
313 if (state() == password_manager::ui::AUTO_SIGNIN_STATE) | 313 if (state() == password_manager::ui::AUTO_SIGNIN_STATE) |
314 return *GetCurrentForms()[0]; | 314 return *GetCurrentForms()[0]; |
315 | 315 |
316 DCHECK(state() == password_manager::ui::PENDING_PASSWORD_STATE || | 316 DCHECK(state() == password_manager::ui::PENDING_PASSWORD_STATE || |
317 state() == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE || | 317 state() == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE || |
318 state() == password_manager::ui::CONFIRMATION_STATE) | 318 state() == password_manager::ui::CONFIRMATION_STATE) |
319 << state(); | 319 << state(); |
320 password_manager::PasswordFormManager* form_manager = | 320 password_manager::PasswordFormManager* form_manager = |
321 passwords_data_.form_manager(); | 321 passwords_data_.form_manager(); |
322 return form_manager->pending_credentials(); | 322 return form_manager->pending_credentials(); |
323 } | 323 } |
324 | 324 |
325 bool ManagePasswordsUIController::PasswordOverridden() const { | 325 bool ManagePasswordsUIController::PasswordOverridden() const { |
326 const password_manager::PasswordFormManager* form_manager = | 326 const password_manager::PasswordFormManager* form_manager = |
327 passwords_data_.form_manager(); | 327 passwords_data_.form_manager(); |
328 return form_manager ? form_manager->password_overridden() : false; | 328 return form_manager ? form_manager->password_overridden() : false; |
329 } | 329 } |
330 | 330 |
331 #if !defined(OS_ANDROID) | 331 #if !defined(ANDROID_JAVA_UI) |
332 void ManagePasswordsUIController::UpdateIconAndBubbleState( | 332 void ManagePasswordsUIController::UpdateIconAndBubbleState( |
333 ManagePasswordsIconView* icon) { | 333 ManagePasswordsIconView* icon) { |
334 if (should_pop_up_bubble_) { | 334 if (should_pop_up_bubble_) { |
335 // We must display the icon before showing the bubble, as the bubble would | 335 // We must display the icon before showing the bubble, as the bubble would |
336 // be otherwise unanchored. | 336 // be otherwise unanchored. |
337 icon->SetState(state()); | 337 icon->SetState(state()); |
338 ShowBubbleWithoutUserInteraction(); | 338 ShowBubbleWithoutUserInteraction(); |
339 } else { | 339 } else { |
340 icon->SetState(state()); | 340 icon->SetState(state()); |
341 } | 341 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 UpdateBubbleAndIconVisibility(); | 374 UpdateBubbleAndIconVisibility(); |
375 } | 375 } |
376 } | 376 } |
377 | 377 |
378 password_manager::ui::State ManagePasswordsUIController::state() const { | 378 password_manager::ui::State ManagePasswordsUIController::state() const { |
379 return passwords_data_.state(); | 379 return passwords_data_.state(); |
380 } | 380 } |
381 | 381 |
382 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { | 382 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { |
383 DCHECK(should_pop_up_bubble_); | 383 DCHECK(should_pop_up_bubble_); |
384 #if !defined(OS_ANDROID) | 384 #if !defined(ANDROID_JAVA_UI) |
385 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 385 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
386 if (!browser || browser->toolbar_model()->input_in_progress()) | 386 if (!browser || browser->toolbar_model()->input_in_progress()) |
387 return; | 387 return; |
388 | 388 |
389 CommandUpdater* updater = browser->command_controller()->command_updater(); | 389 CommandUpdater* updater = browser->command_controller()->command_updater(); |
390 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); | 390 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); |
391 #endif | 391 #endif |
392 } | 392 } |
393 | 393 |
394 void ManagePasswordsUIController::WebContentsDestroyed() { | 394 void ManagePasswordsUIController::WebContentsDestroyed() { |
395 password_manager::PasswordStore* password_store = | 395 password_manager::PasswordStore* password_store = |
396 GetPasswordStore(web_contents()); | 396 GetPasswordStore(web_contents()); |
397 if (password_store) | 397 if (password_store) |
398 password_store->RemoveObserver(this); | 398 password_store->RemoveObserver(this); |
399 } | 399 } |
OLD | NEW |