| 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" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 passwords_data_.set_client( | 64 passwords_data_.set_client( |
| 65 ChromePasswordManagerClient::FromWebContents(web_contents)); | 65 ChromePasswordManagerClient::FromWebContents(web_contents)); |
| 66 password_manager::PasswordStore* password_store = | 66 password_manager::PasswordStore* password_store = |
| 67 GetPasswordStore(web_contents); | 67 GetPasswordStore(web_contents); |
| 68 if (password_store) | 68 if (password_store) |
| 69 password_store->AddObserver(this); | 69 password_store->AddObserver(this); |
| 70 } | 70 } |
| 71 | 71 |
| 72 ManagePasswordsUIController::~ManagePasswordsUIController() {} | 72 ManagePasswordsUIController::~ManagePasswordsUIController() {} |
| 73 | 73 |
| 74 void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() { | |
| 75 // If we're not on a "webby" URL (e.g. "chrome://sign-in"), we shouldn't | |
| 76 // display either the bubble or the icon. | |
| 77 if (!BrowsingDataHelper::IsWebScheme( | |
| 78 web_contents()->GetLastCommittedURL().scheme())) { | |
| 79 passwords_data_.OnInactive(); | |
| 80 } | |
| 81 | |
| 82 #if !defined(OS_ANDROID) | |
| 83 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | |
| 84 if (!browser) | |
| 85 return; | |
| 86 LocationBar* location_bar = browser->window()->GetLocationBar(); | |
| 87 DCHECK(location_bar); | |
| 88 location_bar->UpdateManagePasswordsIconAndBubble(); | |
| 89 #endif | |
| 90 } | |
| 91 | |
| 92 void ManagePasswordsUIController:: | |
| 93 UpdateAndroidAccountChooserInfoBarVisibility() { | |
| 94 #if defined(OS_ANDROID) | |
| 95 // Deletes itself on the event from Java counterpart, when user interacts with | |
| 96 // dialog. | |
| 97 AccountChooserDialogAndroid* acccount_chooser_dialog = | |
| 98 new AccountChooserDialogAndroid(web_contents(), this); | |
| 99 acccount_chooser_dialog->ShowDialog(); | |
| 100 should_pop_up_bubble_ = false; | |
| 101 #endif | |
| 102 } | |
| 103 | |
| 104 base::TimeDelta ManagePasswordsUIController::Elapsed() const { | |
| 105 return timer_ ? timer_->Elapsed() : base::TimeDelta::Max(); | |
| 106 } | |
| 107 | |
| 108 void ManagePasswordsUIController::OnPasswordSubmitted( | 74 void ManagePasswordsUIController::OnPasswordSubmitted( |
| 109 scoped_ptr<PasswordFormManager> form_manager) { | 75 scoped_ptr<PasswordFormManager> form_manager) { |
| 110 bool show_bubble = !form_manager->IsBlacklisted(); | 76 bool show_bubble = !form_manager->IsBlacklisted(); |
| 111 passwords_data_.OnPendingPassword(form_manager.Pass()); | 77 passwords_data_.OnPendingPassword(form_manager.Pass()); |
| 112 if (show_bubble) { | 78 if (show_bubble) { |
| 113 password_manager::InteractionsStats* stats = GetCurrentInteractionStats(); | 79 password_manager::InteractionsStats* stats = GetCurrentInteractionStats(); |
| 114 if (stats && stats->dismissal_count > kMaxShowSaveBubble) | 80 if (stats && stats->dismissal_count > kMaxShowSaveBubble) |
| 115 show_bubble = false; | 81 show_bubble = false; |
| 116 } | 82 } |
| 117 timer_.reset(new base::ElapsedTimer); | 83 timer_.reset(new base::ElapsedTimer); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 149 } |
| 184 | 150 |
| 185 void ManagePasswordsUIController::OnLoginsChanged( | 151 void ManagePasswordsUIController::OnLoginsChanged( |
| 186 const password_manager::PasswordStoreChangeList& changes) { | 152 const password_manager::PasswordStoreChangeList& changes) { |
| 187 password_manager::ui::State current_state = GetState(); | 153 password_manager::ui::State current_state = GetState(); |
| 188 passwords_data_.ProcessLoginsChanged(changes); | 154 passwords_data_.ProcessLoginsChanged(changes); |
| 189 if (current_state != GetState()) | 155 if (current_state != GetState()) |
| 190 UpdateBubbleAndIconVisibility(); | 156 UpdateBubbleAndIconVisibility(); |
| 191 } | 157 } |
| 192 | 158 |
| 159 #if !defined(OS_ANDROID) |
| 160 void ManagePasswordsUIController::UpdateIconAndBubbleState( |
| 161 ManagePasswordsIconView* icon) { |
| 162 if (should_pop_up_bubble_) { |
| 163 // We must display the icon before showing the bubble, as the bubble would |
| 164 // be otherwise unanchored. |
| 165 icon->SetState(GetState()); |
| 166 ShowBubbleWithoutUserInteraction(); |
| 167 } else { |
| 168 icon->SetState(GetState()); |
| 169 } |
| 170 } |
| 171 #endif |
| 172 |
| 193 const GURL& ManagePasswordsUIController::GetOrigin() const { | 173 const GURL& ManagePasswordsUIController::GetOrigin() const { |
| 194 return passwords_data_.origin(); | 174 return passwords_data_.origin(); |
| 195 } | 175 } |
| 196 | 176 |
| 197 password_manager::ui::State ManagePasswordsUIController::GetState() const { | 177 password_manager::ui::State ManagePasswordsUIController::GetState() const { |
| 198 return passwords_data_.state(); | 178 return passwords_data_.state(); |
| 199 } | 179 } |
| 200 | 180 |
| 201 const autofill::PasswordForm& ManagePasswordsUIController:: | 181 const autofill::PasswordForm& ManagePasswordsUIController:: |
| 202 GetPendingPassword() const { | 182 GetPendingPassword() const { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 form_manager->Update(password_form); | 345 form_manager->Update(password_form); |
| 366 } | 346 } |
| 367 | 347 |
| 368 void ManagePasswordsUIController::NeverSavePasswordInternal() { | 348 void ManagePasswordsUIController::NeverSavePasswordInternal() { |
| 369 password_manager::PasswordFormManager* form_manager = | 349 password_manager::PasswordFormManager* form_manager = |
| 370 passwords_data_.form_manager(); | 350 passwords_data_.form_manager(); |
| 371 DCHECK(form_manager); | 351 DCHECK(form_manager); |
| 372 form_manager->PermanentlyBlacklist(); | 352 form_manager->PermanentlyBlacklist(); |
| 373 } | 353 } |
| 374 | 354 |
| 355 void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() { |
| 356 // If we're not on a "webby" URL (e.g. "chrome://sign-in"), we shouldn't |
| 357 // display either the bubble or the icon. |
| 358 if (!BrowsingDataHelper::IsWebScheme( |
| 359 web_contents()->GetLastCommittedURL().scheme())) { |
| 360 passwords_data_.OnInactive(); |
| 361 } |
| 362 |
| 363 #if !defined(OS_ANDROID) |
| 364 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 365 if (!browser) |
| 366 return; |
| 367 LocationBar* location_bar = browser->window()->GetLocationBar(); |
| 368 DCHECK(location_bar); |
| 369 location_bar->UpdateManagePasswordsIconAndBubble(); |
| 370 #endif |
| 371 } |
| 372 |
| 373 base::TimeDelta ManagePasswordsUIController::Elapsed() const { |
| 374 return timer_ ? timer_->Elapsed() : base::TimeDelta::Max(); |
| 375 } |
| 376 |
| 375 void ManagePasswordsUIController::DidNavigateMainFrame( | 377 void ManagePasswordsUIController::DidNavigateMainFrame( |
| 376 const content::LoadCommittedDetails& details, | 378 const content::LoadCommittedDetails& details, |
| 377 const content::FrameNavigateParams& params) { | 379 const content::FrameNavigateParams& params) { |
| 378 // Don't react to in-page (fragment) navigations. | 380 // Don't react to in-page (fragment) navigations. |
| 379 if (details.is_in_page) | 381 if (details.is_in_page) |
| 380 return; | 382 return; |
| 381 | 383 |
| 382 // Don't do anything if a navigation occurs before a user could reasonably | 384 // Don't do anything if a navigation occurs before a user could reasonably |
| 383 // interact with the password bubble. | 385 // interact with the password bubble. |
| 384 if (Elapsed() < base::TimeDelta::FromSeconds(kBubbleMinTime)) | 386 if (Elapsed() < base::TimeDelta::FromSeconds(kBubbleMinTime)) |
| 385 return; | 387 return; |
| 386 | 388 |
| 387 // Otherwise, reset the password manager and the timer. | 389 // Otherwise, reset the password manager and the timer. |
| 388 passwords_data_.OnInactive(); | 390 passwords_data_.OnInactive(); |
| 389 UpdateBubbleAndIconVisibility(); | 391 UpdateBubbleAndIconVisibility(); |
| 390 // This allows the bubble to survive several redirects in case the whole | 392 // This allows the bubble to survive several redirects in case the whole |
| 391 // process of navigating to the landing page is longer than 1 second. | 393 // process of navigating to the landing page is longer than 1 second. |
| 392 timer_.reset(new base::ElapsedTimer()); | 394 timer_.reset(new base::ElapsedTimer()); |
| 393 } | 395 } |
| 394 | 396 |
| 395 void ManagePasswordsUIController::WasHidden() { | 397 void ManagePasswordsUIController::WasHidden() { |
| 396 #if !defined(OS_ANDROID) | 398 #if !defined(OS_ANDROID) |
| 397 TabDialogs::FromWebContents(web_contents())->HideManagePasswordsBubble(); | 399 TabDialogs::FromWebContents(web_contents())->HideManagePasswordsBubble(); |
| 398 #endif | 400 #endif |
| 399 } | 401 } |
| 400 | 402 |
| 401 #if !defined(OS_ANDROID) | |
| 402 void ManagePasswordsUIController::UpdateIconAndBubbleState( | |
| 403 ManagePasswordsIconView* icon) { | |
| 404 if (should_pop_up_bubble_) { | |
| 405 // We must display the icon before showing the bubble, as the bubble would | |
| 406 // be otherwise unanchored. | |
| 407 icon->SetState(GetState()); | |
| 408 ShowBubbleWithoutUserInteraction(); | |
| 409 } else { | |
| 410 icon->SetState(GetState()); | |
| 411 } | |
| 412 } | |
| 413 #endif | |
| 414 | |
| 415 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { | 403 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { |
| 416 DCHECK(should_pop_up_bubble_); | 404 DCHECK(should_pop_up_bubble_); |
| 417 #if !defined(OS_ANDROID) | 405 #if !defined(OS_ANDROID) |
| 418 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 406 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 419 if (!browser || browser->toolbar_model()->input_in_progress()) | 407 if (!browser || browser->toolbar_model()->input_in_progress()) |
| 420 return; | 408 return; |
| 421 | 409 |
| 422 CommandUpdater* updater = browser->command_controller()->command_updater(); | 410 CommandUpdater* updater = browser->command_controller()->command_updater(); |
| 423 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); | 411 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); |
| 424 #endif | 412 #endif |
| 425 } | 413 } |
| 426 | 414 |
| 427 void ManagePasswordsUIController::WebContentsDestroyed() { | 415 void ManagePasswordsUIController::WebContentsDestroyed() { |
| 428 password_manager::PasswordStore* password_store = | 416 password_manager::PasswordStore* password_store = |
| 429 GetPasswordStore(web_contents()); | 417 GetPasswordStore(web_contents()); |
| 430 if (password_store) | 418 if (password_store) |
| 431 password_store->RemoveObserver(this); | 419 password_store->RemoveObserver(this); |
| 432 } | 420 } |
| 421 |
| 422 void ManagePasswordsUIController:: |
| 423 UpdateAndroidAccountChooserInfoBarVisibility() { |
| 424 #if defined(OS_ANDROID) |
| 425 // Deletes itself on the event from Java counterpart, when user interacts with |
| 426 // dialog. |
| 427 AccountChooserDialogAndroid* acccount_chooser_dialog = |
| 428 new AccountChooserDialogAndroid(web_contents(), this); |
| 429 acccount_chooser_dialog->ShowDialog(); |
| 430 should_pop_up_bubble_ = false; |
| 431 #endif |
| 432 } |
| OLD | NEW |