| 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/browser/password_manager_constants.h" | 24 #include "components/password_manager/core/browser/password_manager_constants.h" |
| 25 #include "components/password_manager/core/browser/statistics_table.h" | 25 #include "components/password_manager/core/browser/statistics_table.h" |
| 26 #include "components/password_manager/core/common/credential_manager_types.h" | 26 #include "components/password_manager/core/common/credential_manager_types.h" |
| 27 #include "content/public/browser/navigation_details.h" | 27 #include "content/public/browser/navigation_details.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 | 29 |
| 30 #if defined(OS_ANDROID) | 30 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 31 #include "chrome/browser/android/chrome_application.h" | 31 #include "chrome/browser/android/chrome_application.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 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 142 } |
| 143 | 143 |
| 144 void ManagePasswordsUIController::OnLoginsChanged( | 144 void ManagePasswordsUIController::OnLoginsChanged( |
| 145 const password_manager::PasswordStoreChangeList& changes) { | 145 const password_manager::PasswordStoreChangeList& changes) { |
| 146 password_manager::ui::State current_state = GetState(); | 146 password_manager::ui::State current_state = GetState(); |
| 147 passwords_data_.ProcessLoginsChanged(changes); | 147 passwords_data_.ProcessLoginsChanged(changes); |
| 148 if (current_state != GetState()) | 148 if (current_state != GetState()) |
| 149 UpdateBubbleAndIconVisibility(); | 149 UpdateBubbleAndIconVisibility(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 #if !defined(OS_ANDROID) | 152 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 153 void ManagePasswordsUIController::UpdateIconAndBubbleState( | 153 void ManagePasswordsUIController::UpdateIconAndBubbleState( |
| 154 ManagePasswordsIconView* icon) { | 154 ManagePasswordsIconView* icon) { |
| 155 if (should_pop_up_bubble_) { | 155 if (should_pop_up_bubble_) { |
| 156 // We must display the icon before showing the bubble, as the bubble would | 156 // We must display the icon before showing the bubble, as the bubble would |
| 157 // be otherwise unanchored. | 157 // be otherwise unanchored. |
| 158 icon->SetState(GetState()); | 158 icon->SetState(GetState()); |
| 159 ShowBubbleWithoutUserInteraction(); | 159 ShowBubbleWithoutUserInteraction(); |
| 160 } else { | 160 } else { |
| 161 icon->SetState(GetState()); | 161 icon->SetState(GetState()); |
| 162 } | 162 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 UpdateBubbleAndIconVisibility(); | 264 UpdateBubbleAndIconVisibility(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void ManagePasswordsUIController::ChooseCredential( | 267 void ManagePasswordsUIController::ChooseCredential( |
| 268 const autofill::PasswordForm& form, | 268 const autofill::PasswordForm& form, |
| 269 password_manager::CredentialType credential_type) { | 269 password_manager::CredentialType credential_type) { |
| 270 passwords_data_.ChooseCredential(form, credential_type); | 270 passwords_data_.ChooseCredential(form, credential_type); |
| 271 } | 271 } |
| 272 | 272 |
| 273 void ManagePasswordsUIController::NavigateToExternalPasswordManager() { | 273 void ManagePasswordsUIController::NavigateToExternalPasswordManager() { |
| 274 #if defined(OS_ANDROID) | 274 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 275 NOTREACHED(); | 275 NOTREACHED(); |
| 276 #else | 276 #else |
| 277 chrome::NavigateParams params( | 277 chrome::NavigateParams params( |
| 278 chrome::FindBrowserWithWebContents(web_contents()), | 278 chrome::FindBrowserWithWebContents(web_contents()), |
| 279 GURL(password_manager::kPasswordManagerAccountDashboardURL), | 279 GURL(password_manager::kPasswordManagerAccountDashboardURL), |
| 280 ui::PAGE_TRANSITION_LINK); | 280 ui::PAGE_TRANSITION_LINK); |
| 281 params.disposition = NEW_FOREGROUND_TAB; | 281 params.disposition = NEW_FOREGROUND_TAB; |
| 282 chrome::Navigate(¶ms); | 282 chrome::Navigate(¶ms); |
| 283 #endif | 283 #endif |
| 284 } | 284 } |
| 285 | 285 |
| 286 void ManagePasswordsUIController::NavigateToSmartLockHelpPage() { | 286 void ManagePasswordsUIController::NavigateToSmartLockHelpPage() { |
| 287 #if defined(OS_ANDROID) | 287 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 288 NOTREACHED(); | 288 NOTREACHED(); |
| 289 #else | 289 #else |
| 290 chrome::NavigateParams params( | 290 chrome::NavigateParams params( |
| 291 chrome::FindBrowserWithWebContents(web_contents()), | 291 chrome::FindBrowserWithWebContents(web_contents()), |
| 292 GURL(chrome::kSmartLockHelpPage), ui::PAGE_TRANSITION_LINK); | 292 GURL(chrome::kSmartLockHelpPage), ui::PAGE_TRANSITION_LINK); |
| 293 params.disposition = NEW_FOREGROUND_TAB; | 293 params.disposition = NEW_FOREGROUND_TAB; |
| 294 chrome::Navigate(¶ms); | 294 chrome::Navigate(¶ms); |
| 295 #endif | 295 #endif |
| 296 } | 296 } |
| 297 | 297 |
| 298 void ManagePasswordsUIController::NavigateToPasswordManagerSettingsPage() { | 298 void ManagePasswordsUIController::NavigateToPasswordManagerSettingsPage() { |
| 299 #if defined(OS_ANDROID) | 299 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 300 chrome::android::ChromeApplication::ShowPasswordSettings(); | 300 chrome::android::ChromeApplication::ShowPasswordSettings(); |
| 301 #else | 301 #else |
| 302 chrome::ShowSettingsSubPage( | 302 chrome::ShowSettingsSubPage( |
| 303 chrome::FindBrowserWithWebContents(web_contents()), | 303 chrome::FindBrowserWithWebContents(web_contents()), |
| 304 chrome::kPasswordManagerSubPage); | 304 chrome::kPasswordManagerSubPage); |
| 305 #endif | 305 #endif |
| 306 } | 306 } |
| 307 | 307 |
| 308 void ManagePasswordsUIController::SavePasswordInternal() { | 308 void ManagePasswordsUIController::SavePasswordInternal() { |
| 309 password_manager::PasswordStore* password_store = | 309 password_manager::PasswordStore* password_store = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 333 } | 333 } |
| 334 | 334 |
| 335 void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() { | 335 void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() { |
| 336 // If we're not on a "webby" URL (e.g. "chrome://sign-in"), we shouldn't | 336 // If we're not on a "webby" URL (e.g. "chrome://sign-in"), we shouldn't |
| 337 // display either the bubble or the icon. | 337 // display either the bubble or the icon. |
| 338 if (!BrowsingDataHelper::IsWebScheme( | 338 if (!BrowsingDataHelper::IsWebScheme( |
| 339 web_contents()->GetLastCommittedURL().scheme())) { | 339 web_contents()->GetLastCommittedURL().scheme())) { |
| 340 passwords_data_.OnInactive(); | 340 passwords_data_.OnInactive(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 #if !defined(OS_ANDROID) | 343 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 344 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 344 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 345 if (!browser) | 345 if (!browser) |
| 346 return; | 346 return; |
| 347 LocationBar* location_bar = browser->window()->GetLocationBar(); | 347 LocationBar* location_bar = browser->window()->GetLocationBar(); |
| 348 DCHECK(location_bar); | 348 DCHECK(location_bar); |
| 349 location_bar->UpdateManagePasswordsIconAndBubble(); | 349 location_bar->UpdateManagePasswordsIconAndBubble(); |
| 350 #endif | 350 #endif |
| 351 } | 351 } |
| 352 | 352 |
| 353 base::TimeDelta ManagePasswordsUIController::Elapsed() const { | 353 base::TimeDelta ManagePasswordsUIController::Elapsed() const { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 368 | 368 |
| 369 // Otherwise, reset the password manager and the timer. | 369 // Otherwise, reset the password manager and the timer. |
| 370 passwords_data_.OnInactive(); | 370 passwords_data_.OnInactive(); |
| 371 UpdateBubbleAndIconVisibility(); | 371 UpdateBubbleAndIconVisibility(); |
| 372 // This allows the bubble to survive several redirects in case the whole | 372 // This allows the bubble to survive several redirects in case the whole |
| 373 // process of navigating to the landing page is longer than 1 second. | 373 // process of navigating to the landing page is longer than 1 second. |
| 374 timer_.reset(new base::ElapsedTimer()); | 374 timer_.reset(new base::ElapsedTimer()); |
| 375 } | 375 } |
| 376 | 376 |
| 377 void ManagePasswordsUIController::WasHidden() { | 377 void ManagePasswordsUIController::WasHidden() { |
| 378 #if !defined(OS_ANDROID) | 378 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 379 TabDialogs::FromWebContents(web_contents())->HideManagePasswordsBubble(); | 379 TabDialogs::FromWebContents(web_contents())->HideManagePasswordsBubble(); |
| 380 #endif | 380 #endif |
| 381 } | 381 } |
| 382 | 382 |
| 383 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { | 383 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { |
| 384 DCHECK(should_pop_up_bubble_); | 384 DCHECK(should_pop_up_bubble_); |
| 385 #if !defined(OS_ANDROID) | 385 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 386 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 386 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 387 if (!browser || browser->toolbar_model()->input_in_progress()) | 387 if (!browser || browser->toolbar_model()->input_in_progress()) |
| 388 return; | 388 return; |
| 389 | 389 |
| 390 CommandUpdater* updater = browser->command_controller()->command_updater(); | 390 CommandUpdater* updater = browser->command_controller()->command_updater(); |
| 391 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); | 391 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); |
| 392 #endif | 392 #endif |
| 393 } | 393 } |
| 394 | 394 |
| 395 void ManagePasswordsUIController::WebContentsDestroyed() { | 395 void ManagePasswordsUIController::WebContentsDestroyed() { |
| 396 password_manager::PasswordStore* password_store = | 396 password_manager::PasswordStore* password_store = |
| 397 GetPasswordStore(web_contents()); | 397 GetPasswordStore(web_contents()); |
| 398 if (password_store) | 398 if (password_store) |
| 399 password_store->RemoveObserver(this); | 399 password_store->RemoveObserver(this); |
| 400 } | 400 } |
| OLD | NEW |