| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 return result; | 52 return result; |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController); | 57 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController); |
| 58 | 58 |
| 59 ManagePasswordsUIController::ManagePasswordsUIController( | 59 ManagePasswordsUIController::ManagePasswordsUIController( |
| 60 content::WebContents* web_contents) | 60 content::WebContents* web_contents) |
| 61 : content::WebContentsObserver(web_contents), | 61 : content::WebContentsObserver(web_contents), |
| 62 should_pop_up_bubble_(false) { | 62 bubble_status_(NOT_SHOWN) { |
| 63 passwords_data_.set_client( | 63 passwords_data_.set_client( |
| 64 ChromePasswordManagerClient::FromWebContents(web_contents)); | 64 ChromePasswordManagerClient::FromWebContents(web_contents)); |
| 65 password_manager::PasswordStore* password_store = | 65 password_manager::PasswordStore* password_store = |
| 66 GetPasswordStore(web_contents); | 66 GetPasswordStore(web_contents); |
| 67 if (password_store) | 67 if (password_store) |
| 68 password_store->AddObserver(this); | 68 password_store->AddObserver(this); |
| 69 } | 69 } |
| 70 | 70 |
| 71 ManagePasswordsUIController::~ManagePasswordsUIController() {} | 71 ManagePasswordsUIController::~ManagePasswordsUIController() {} |
| 72 | 72 |
| 73 void ManagePasswordsUIController::OnPasswordSubmitted( | 73 void ManagePasswordsUIController::OnPasswordSubmitted( |
| 74 scoped_ptr<PasswordFormManager> form_manager) { | 74 scoped_ptr<PasswordFormManager> form_manager) { |
| 75 bool show_bubble = !form_manager->IsBlacklisted(); | 75 bool show_bubble = !form_manager->IsBlacklisted(); |
| 76 DestroyAccountChooser(); | 76 DestroyAccountChooser(); |
| 77 passwords_data_.OnPendingPassword(std::move(form_manager)); | 77 passwords_data_.OnPendingPassword(std::move(form_manager)); |
| 78 if (show_bubble) { | 78 if (show_bubble) { |
| 79 password_manager::InteractionsStats* stats = GetCurrentInteractionStats(); | 79 password_manager::InteractionsStats* stats = GetCurrentInteractionStats(); |
| 80 const int show_threshold = | 80 const int show_threshold = |
| 81 password_bubble_experiment::GetSmartBubbleDismissalThreshold(); | 81 password_bubble_experiment::GetSmartBubbleDismissalThreshold(); |
| 82 if (stats && show_threshold > 0 && stats->dismissal_count >= show_threshold) | 82 if (stats && show_threshold > 0 && stats->dismissal_count >= show_threshold) |
| 83 show_bubble = false; | 83 show_bubble = false; |
| 84 } | 84 } |
| 85 base::AutoReset<bool> resetter(&should_pop_up_bubble_, show_bubble); | 85 if (show_bubble) |
| 86 bubble_status_ = SHOULD_POP_UP; |
| 86 UpdateBubbleAndIconVisibility(); | 87 UpdateBubbleAndIconVisibility(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void ManagePasswordsUIController::OnUpdatePasswordSubmitted( | 90 void ManagePasswordsUIController::OnUpdatePasswordSubmitted( |
| 90 scoped_ptr<PasswordFormManager> form_manager) { | 91 scoped_ptr<PasswordFormManager> form_manager) { |
| 91 DestroyAccountChooser(); | 92 DestroyAccountChooser(); |
| 92 passwords_data_.OnUpdatePassword(std::move(form_manager)); | 93 passwords_data_.OnUpdatePassword(std::move(form_manager)); |
| 93 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true); | 94 bubble_status_ = SHOULD_POP_UP; |
| 94 UpdateBubbleAndIconVisibility(); | 95 UpdateBubbleAndIconVisibility(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 bool ManagePasswordsUIController::OnChooseCredentials( | 98 bool ManagePasswordsUIController::OnChooseCredentials( |
| 98 ScopedVector<autofill::PasswordForm> local_credentials, | 99 ScopedVector<autofill::PasswordForm> local_credentials, |
| 99 ScopedVector<autofill::PasswordForm> federated_credentials, | 100 ScopedVector<autofill::PasswordForm> federated_credentials, |
| 100 const GURL& origin, | 101 const GURL& origin, |
| 101 base::Callback<void(const password_manager::CredentialInfo&)> callback) { | 102 base::Callback<void(const password_manager::CredentialInfo&)> callback) { |
| 102 DCHECK(!local_credentials.empty() || !federated_credentials.empty()); | 103 DCHECK(!local_credentials.empty() || !federated_credentials.empty()); |
| 103 PasswordDialogController::FormsVector locals = | 104 PasswordDialogController::FormsVector locals = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 115 std::move(locals), std::move(federations)); | 116 std::move(locals), std::move(federations)); |
| 116 UpdateBubbleAndIconVisibility(); | 117 UpdateBubbleAndIconVisibility(); |
| 117 return true; | 118 return true; |
| 118 } | 119 } |
| 119 | 120 |
| 120 void ManagePasswordsUIController::OnAutoSignin( | 121 void ManagePasswordsUIController::OnAutoSignin( |
| 121 ScopedVector<autofill::PasswordForm> local_forms) { | 122 ScopedVector<autofill::PasswordForm> local_forms) { |
| 122 DCHECK(!local_forms.empty()); | 123 DCHECK(!local_forms.empty()); |
| 123 DestroyAccountChooser(); | 124 DestroyAccountChooser(); |
| 124 passwords_data_.OnAutoSignin(std::move(local_forms)); | 125 passwords_data_.OnAutoSignin(std::move(local_forms)); |
| 125 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true); | 126 bubble_status_ = SHOULD_POP_UP; |
| 126 UpdateBubbleAndIconVisibility(); | 127 UpdateBubbleAndIconVisibility(); |
| 127 } | 128 } |
| 128 | 129 |
| 129 void ManagePasswordsUIController::OnPromptEnableAutoSignin() { | 130 void ManagePasswordsUIController::OnPromptEnableAutoSignin() { |
| 130 // Both the account chooser and the previous prompt shouldn't be closed. | 131 // Both the account chooser and the previous prompt shouldn't be closed. |
| 131 if (dialog_controller_) | 132 if (dialog_controller_) |
| 132 return; | 133 return; |
| 133 dialog_controller_.reset(new PasswordDialogControllerImpl( | 134 dialog_controller_.reset(new PasswordDialogControllerImpl( |
| 134 Profile::FromBrowserContext(web_contents()->GetBrowserContext()), | 135 Profile::FromBrowserContext(web_contents()->GetBrowserContext()), |
| 135 this)); | 136 this)); |
| 136 dialog_controller_->ShowAutosigninPrompt( | 137 dialog_controller_->ShowAutosigninPrompt( |
| 137 CreateAutoSigninPrompt(dialog_controller_.get())); | 138 CreateAutoSigninPrompt(dialog_controller_.get())); |
| 138 } | 139 } |
| 139 | 140 |
| 140 void ManagePasswordsUIController::OnAutomaticPasswordSave( | 141 void ManagePasswordsUIController::OnAutomaticPasswordSave( |
| 141 scoped_ptr<PasswordFormManager> form_manager) { | 142 scoped_ptr<PasswordFormManager> form_manager) { |
| 142 DestroyAccountChooser(); | 143 DestroyAccountChooser(); |
| 143 passwords_data_.OnAutomaticPasswordSave(std::move(form_manager)); | 144 passwords_data_.OnAutomaticPasswordSave(std::move(form_manager)); |
| 144 base::AutoReset<bool> resetter(&should_pop_up_bubble_, true); | 145 bubble_status_ = SHOULD_POP_UP; |
| 145 UpdateBubbleAndIconVisibility(); | 146 UpdateBubbleAndIconVisibility(); |
| 146 } | 147 } |
| 147 | 148 |
| 148 void ManagePasswordsUIController::OnPasswordAutofilled( | 149 void ManagePasswordsUIController::OnPasswordAutofilled( |
| 149 const PasswordFormMap& password_form_map, | 150 const PasswordFormMap& password_form_map, |
| 150 const GURL& origin) { | 151 const GURL& origin) { |
| 151 // If we fill a form while a dialog is open, then skip the state change; we | 152 // If we fill a form while a dialog is open, then skip the state change; we |
| 152 // have | 153 // have |
| 153 // the information we need, and the dialog will change its own state once the | 154 // the information we need, and the dialog will change its own state once the |
| 154 // interaction is complete. | 155 // interaction is complete. |
| 155 if (passwords_data_.state() != | 156 if (passwords_data_.state() != |
| 156 password_manager::ui::AUTO_SIGNIN_STATE && | 157 password_manager::ui::AUTO_SIGNIN_STATE && |
| 157 passwords_data_.state() != | 158 passwords_data_.state() != |
| 158 password_manager::ui::CREDENTIAL_REQUEST_STATE) { | 159 password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
| 159 passwords_data_.OnPasswordAutofilled(password_form_map, origin); | 160 passwords_data_.OnPasswordAutofilled(password_form_map, origin); |
| 160 UpdateBubbleAndIconVisibility(); | 161 UpdateBubbleAndIconVisibility(); |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 | 164 |
| 164 void ManagePasswordsUIController::OnLoginsChanged( | 165 void ManagePasswordsUIController::OnLoginsChanged( |
| 165 const password_manager::PasswordStoreChangeList& changes) { | 166 const password_manager::PasswordStoreChangeList& changes) { |
| 166 password_manager::ui::State current_state = GetState(); | 167 password_manager::ui::State current_state = GetState(); |
| 167 passwords_data_.ProcessLoginsChanged(changes); | 168 passwords_data_.ProcessLoginsChanged(changes); |
| 168 if (current_state != GetState()) | 169 if (current_state != GetState()) |
| 169 UpdateBubbleAndIconVisibility(); | 170 UpdateBubbleAndIconVisibility(); |
| 170 } | 171 } |
| 171 | 172 |
| 172 void ManagePasswordsUIController::UpdateIconAndBubbleState( | 173 void ManagePasswordsUIController::UpdateIconAndBubbleState( |
| 173 ManagePasswordsIconView* icon) { | 174 ManagePasswordsIconView* icon) { |
| 174 if (should_pop_up_bubble_) { | 175 if (bubble_status_ == SHOULD_POP_UP) { |
| 175 DCHECK(!dialog_controller_); | 176 DCHECK(!dialog_controller_); |
| 176 // We must display the icon before showing the bubble, as the bubble would | 177 // We must display the icon before showing the bubble, as the bubble would |
| 177 // be otherwise unanchored. | 178 // be otherwise unanchored. |
| 178 icon->SetState(GetState()); | 179 icon->SetState(GetState()); |
| 179 ShowBubbleWithoutUserInteraction(); | 180 ShowBubbleWithoutUserInteraction(); |
| 181 // If the bubble appeared then the status is updated in OnBubbleShown(). |
| 182 if (bubble_status_ == SHOULD_POP_UP) |
| 183 bubble_status_ = NOT_SHOWN; |
| 180 } else { | 184 } else { |
| 181 password_manager::ui::State state = GetState(); | 185 password_manager::ui::State state = GetState(); |
| 182 // The dialog should hide the icon. | 186 // The dialog should hide the icon. |
| 183 if (dialog_controller_ && | 187 if (dialog_controller_ && |
| 184 state == password_manager::ui::CREDENTIAL_REQUEST_STATE) | 188 state == password_manager::ui::CREDENTIAL_REQUEST_STATE) |
| 185 state = password_manager::ui::INACTIVE_STATE; | 189 state = password_manager::ui::INACTIVE_STATE; |
| 186 icon->SetState(state); | 190 icon->SetState(state); |
| 187 } | 191 } |
| 188 } | 192 } |
| 189 | 193 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 ManagePasswordsUIController::GetCurrentInteractionStats() const { | 233 ManagePasswordsUIController::GetCurrentInteractionStats() const { |
| 230 DCHECK_EQ(password_manager::ui::PENDING_PASSWORD_STATE, GetState()); | 234 DCHECK_EQ(password_manager::ui::PENDING_PASSWORD_STATE, GetState()); |
| 231 password_manager::PasswordFormManager* form_manager = | 235 password_manager::PasswordFormManager* form_manager = |
| 232 passwords_data_.form_manager(); | 236 passwords_data_.form_manager(); |
| 233 return password_manager::FindStatsByUsername( | 237 return password_manager::FindStatsByUsername( |
| 234 form_manager->interactions_stats(), | 238 form_manager->interactions_stats(), |
| 235 form_manager->pending_credentials().username_value); | 239 form_manager->pending_credentials().username_value); |
| 236 } | 240 } |
| 237 | 241 |
| 238 void ManagePasswordsUIController::OnBubbleShown() { | 242 void ManagePasswordsUIController::OnBubbleShown() { |
| 239 should_pop_up_bubble_ = false; | 243 bubble_status_ = SHOWN; |
| 240 } | 244 } |
| 241 | 245 |
| 242 void ManagePasswordsUIController::OnBubbleHidden() { | 246 void ManagePasswordsUIController::OnBubbleHidden() { |
| 247 bubble_status_ = NOT_SHOWN; |
| 243 if (GetState() == password_manager::ui::CONFIRMATION_STATE || | 248 if (GetState() == password_manager::ui::CONFIRMATION_STATE || |
| 244 GetState() == password_manager::ui::AUTO_SIGNIN_STATE) { | 249 GetState() == password_manager::ui::AUTO_SIGNIN_STATE) { |
| 245 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); | 250 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); |
| 246 UpdateBubbleAndIconVisibility(); | 251 UpdateBubbleAndIconVisibility(); |
| 247 } | 252 } |
| 248 } | 253 } |
| 249 | 254 |
| 250 void ManagePasswordsUIController::OnNoInteractionOnUpdate() { | 255 void ManagePasswordsUIController::OnNoInteractionOnUpdate() { |
| 251 if (GetState() != password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { | 256 if (GetState() != password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { |
| 252 // Do nothing if the state was changed. It can happen for example when the | 257 // Do nothing if the state was changed. It can happen for example when the |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 return CreateAutoSigninPromptView(controller, web_contents()); | 386 return CreateAutoSigninPromptView(controller, web_contents()); |
| 382 } | 387 } |
| 383 | 388 |
| 384 void ManagePasswordsUIController::DidNavigateMainFrame( | 389 void ManagePasswordsUIController::DidNavigateMainFrame( |
| 385 const content::LoadCommittedDetails& details, | 390 const content::LoadCommittedDetails& details, |
| 386 const content::FrameNavigateParams& params) { | 391 const content::FrameNavigateParams& params) { |
| 387 // Don't react to in-page (fragment) navigations. | 392 // Don't react to in-page (fragment) navigations. |
| 388 if (details.is_in_page) | 393 if (details.is_in_page) |
| 389 return; | 394 return; |
| 390 | 395 |
| 391 // Don't do anything if a redirect occurs. It is possible that the user was | 396 // It is possible that the user was not able to interact with the password |
| 392 // not able to interact with the password bubble. | 397 // bubble. |
| 393 if (ui::PageTransitionIsRedirect(params.transition)) | 398 if (bubble_status_ == SHOWN) |
| 394 return; | 399 return; |
| 395 | 400 |
| 396 // Otherwise, reset the password manager and the timer. | 401 // Otherwise, reset the password manager. |
| 397 DestroyAccountChooser(); | 402 DestroyAccountChooser(); |
| 398 passwords_data_.OnInactive(); | 403 passwords_data_.OnInactive(); |
| 399 UpdateBubbleAndIconVisibility(); | 404 UpdateBubbleAndIconVisibility(); |
| 400 } | 405 } |
| 401 | 406 |
| 402 void ManagePasswordsUIController::WasHidden() { | 407 void ManagePasswordsUIController::WasHidden() { |
| 403 TabDialogs::FromWebContents(web_contents())->HideManagePasswordsBubble(); | 408 TabDialogs::FromWebContents(web_contents())->HideManagePasswordsBubble(); |
| 404 } | 409 } |
| 405 | 410 |
| 406 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { | 411 void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { |
| 407 DCHECK(should_pop_up_bubble_); | 412 DCHECK(IsAutomaticallyOpeningBubble()); |
| 408 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 413 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 409 if (!browser || browser->toolbar_model()->input_in_progress()) | 414 if (!browser || browser->toolbar_model()->input_in_progress()) |
| 410 return; | 415 return; |
| 411 | 416 |
| 412 CommandUpdater* updater = browser->command_controller()->command_updater(); | 417 CommandUpdater* updater = browser->command_controller()->command_updater(); |
| 413 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); | 418 updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); |
| 414 } | 419 } |
| 415 | 420 |
| 416 void ManagePasswordsUIController::DestroyAccountChooser() { | 421 void ManagePasswordsUIController::DestroyAccountChooser() { |
| 417 if (dialog_controller_ && dialog_controller_->IsShowingAccountChooser()) { | 422 if (dialog_controller_ && dialog_controller_->IsShowingAccountChooser()) { |
| 418 dialog_controller_.reset(); | 423 dialog_controller_.reset(); |
| 419 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); | 424 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); |
| 420 } | 425 } |
| 421 } | 426 } |
| 422 | 427 |
| 423 void ManagePasswordsUIController::WebContentsDestroyed() { | 428 void ManagePasswordsUIController::WebContentsDestroyed() { |
| 424 password_manager::PasswordStore* password_store = | 429 password_manager::PasswordStore* password_store = |
| 425 GetPasswordStore(web_contents()); | 430 GetPasswordStore(web_contents()); |
| 426 if (password_store) | 431 if (password_store) |
| 427 password_store->RemoveObserver(this); | 432 password_store->RemoveObserver(this); |
| 428 } | 433 } |
| OLD | NEW |