| 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" |
| 11 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 11 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 12 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 12 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 13 #include "chrome/browser/password_manager/password_store_factory.h" | 13 #include "chrome/browser/password_manager/password_store_factory.h" |
| 14 #include "chrome/browser/ui/browser_command_controller.h" | 14 #include "chrome/browser/ui/browser_command_controller.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
| 16 #include "chrome/browser/ui/browser_navigator_params.h" | 16 #include "chrome/browser/ui/browser_navigator_params.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/chrome_pages.h" | 18 #include "chrome/browser/ui/chrome_pages.h" |
| 19 #include "chrome/browser/ui/location_bar/location_bar.h" | 19 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 20 #include "chrome/browser/ui/passwords/manage_passwords_icon_view.h" | 20 #include "chrome/browser/ui/passwords/manage_passwords_icon_view.h" |
| 21 #include "chrome/browser/ui/passwords/password_dialog_controller_impl.h" | 21 #include "chrome/browser/ui/passwords/password_dialog_controller_impl.h" |
| 22 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" | 22 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" |
| 23 #include "chrome/browser/ui/passwords/passwords_model_delegate_proxy.h" |
| 23 #include "chrome/browser/ui/tab_dialogs.h" | 24 #include "chrome/browser/ui/tab_dialogs.h" |
| 24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 25 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
| 26 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" | 27 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" |
| 27 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 28 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
| 28 #include "components/password_manager/core/browser/password_form_manager.h" | 29 #include "components/password_manager/core/browser/password_form_manager.h" |
| 29 #include "components/password_manager/core/browser/password_manager_constants.h" | 30 #include "components/password_manager/core/browser/password_manager_constants.h" |
| 30 #include "components/password_manager/core/browser/statistics_table.h" | 31 #include "components/password_manager/core/browser/statistics_table.h" |
| 31 #include "components/password_manager/core/common/credential_manager_types.h" | 32 #include "components/password_manager/core/common/credential_manager_types.h" |
| 32 #include "content/public/browser/navigation_details.h" | 33 #include "content/public/browser/navigation_details.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 52 return result; | 53 return result; |
| 53 } | 54 } |
| 54 | 55 |
| 55 } // namespace | 56 } // namespace |
| 56 | 57 |
| 57 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController); | 58 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController); |
| 58 | 59 |
| 59 ManagePasswordsUIController::ManagePasswordsUIController( | 60 ManagePasswordsUIController::ManagePasswordsUIController( |
| 60 content::WebContents* web_contents) | 61 content::WebContents* web_contents) |
| 61 : content::WebContentsObserver(web_contents), | 62 : content::WebContentsObserver(web_contents), |
| 63 bubble_delegate_proxy_(new PasswordsModelDelegateProxy(this)), |
| 62 bubble_status_(NOT_SHOWN) { | 64 bubble_status_(NOT_SHOWN) { |
| 63 passwords_data_.set_client( | 65 passwords_data_.set_client( |
| 64 ChromePasswordManagerClient::FromWebContents(web_contents)); | 66 ChromePasswordManagerClient::FromWebContents(web_contents)); |
| 65 password_manager::PasswordStore* password_store = | 67 password_manager::PasswordStore* password_store = |
| 66 GetPasswordStore(web_contents); | 68 GetPasswordStore(web_contents); |
| 67 if (password_store) | 69 if (password_store) |
| 68 password_store->AddObserver(this); | 70 password_store->AddObserver(this); |
| 69 } | 71 } |
| 70 | 72 |
| 71 ManagePasswordsUIController::~ManagePasswordsUIController() {} | 73 ManagePasswordsUIController::~ManagePasswordsUIController() {} |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 password_manager::ui::State current_state = GetState(); | 169 password_manager::ui::State current_state = GetState(); |
| 168 passwords_data_.ProcessLoginsChanged(changes); | 170 passwords_data_.ProcessLoginsChanged(changes); |
| 169 if (current_state != GetState()) | 171 if (current_state != GetState()) |
| 170 UpdateBubbleAndIconVisibility(); | 172 UpdateBubbleAndIconVisibility(); |
| 171 } | 173 } |
| 172 | 174 |
| 173 void ManagePasswordsUIController::UpdateIconAndBubbleState( | 175 void ManagePasswordsUIController::UpdateIconAndBubbleState( |
| 174 ManagePasswordsIconView* icon) { | 176 ManagePasswordsIconView* icon) { |
| 175 if (bubble_status_ == SHOULD_POP_UP) { | 177 if (bubble_status_ == SHOULD_POP_UP) { |
| 176 DCHECK(!dialog_controller_); | 178 DCHECK(!dialog_controller_); |
| 179 // This will detach any existing bubble so OnBubbleHidden() isn't called. |
| 180 bubble_delegate_proxy_.reset(new PasswordsModelDelegateProxy(this)); |
| 177 // We must display the icon before showing the bubble, as the bubble would | 181 // We must display the icon before showing the bubble, as the bubble would |
| 178 // be otherwise unanchored. | 182 // be otherwise unanchored. |
| 179 icon->SetState(GetState()); | 183 icon->SetState(GetState()); |
| 180 ShowBubbleWithoutUserInteraction(); | 184 ShowBubbleWithoutUserInteraction(); |
| 181 // If the bubble appeared then the status is updated in OnBubbleShown(). | 185 // If the bubble appeared then the status is updated in OnBubbleShown(). |
| 182 if (bubble_status_ == SHOULD_POP_UP) | 186 if (bubble_status_ == SHOULD_POP_UP) |
| 183 bubble_status_ = NOT_SHOWN; | 187 bubble_status_ = NOT_SHOWN; |
| 184 } else { | 188 } else { |
| 185 password_manager::ui::State state = GetState(); | 189 password_manager::ui::State state = GetState(); |
| 186 // The dialog should hide the icon. | 190 // The dialog should hide the icon. |
| 187 if (dialog_controller_ && | 191 if (dialog_controller_ && |
| 188 state == password_manager::ui::CREDENTIAL_REQUEST_STATE) | 192 state == password_manager::ui::CREDENTIAL_REQUEST_STATE) |
| 189 state = password_manager::ui::INACTIVE_STATE; | 193 state = password_manager::ui::INACTIVE_STATE; |
| 190 icon->SetState(state); | 194 icon->SetState(state); |
| 191 } | 195 } |
| 192 } | 196 } |
| 193 | 197 |
| 198 content::WebContents* ManagePasswordsUIController::GetWebContents() const { |
| 199 return web_contents(); |
| 200 } |
| 201 |
| 194 const GURL& ManagePasswordsUIController::GetOrigin() const { | 202 const GURL& ManagePasswordsUIController::GetOrigin() const { |
| 195 return passwords_data_.origin(); | 203 return passwords_data_.origin(); |
| 196 } | 204 } |
| 197 | 205 |
| 198 password_manager::ui::State ManagePasswordsUIController::GetState() const { | 206 password_manager::ui::State ManagePasswordsUIController::GetState() const { |
| 199 return passwords_data_.state(); | 207 return passwords_data_.state(); |
| 200 } | 208 } |
| 201 | 209 |
| 202 const autofill::PasswordForm& ManagePasswordsUIController:: | 210 const autofill::PasswordForm& ManagePasswordsUIController:: |
| 203 GetPendingPassword() const { | 211 GetPendingPassword() const { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 299 |
| 292 void ManagePasswordsUIController::UpdatePassword( | 300 void ManagePasswordsUIController::UpdatePassword( |
| 293 const autofill::PasswordForm& password_form) { | 301 const autofill::PasswordForm& password_form) { |
| 294 DCHECK_EQ(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE, GetState()); | 302 DCHECK_EQ(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE, GetState()); |
| 295 UpdatePasswordInternal(password_form); | 303 UpdatePasswordInternal(password_form); |
| 296 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); | 304 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); |
| 297 UpdateBubbleAndIconVisibility(); | 305 UpdateBubbleAndIconVisibility(); |
| 298 } | 306 } |
| 299 | 307 |
| 300 void ManagePasswordsUIController::ChooseCredential( | 308 void ManagePasswordsUIController::ChooseCredential( |
| 301 autofill::PasswordForm form, | 309 const autofill::PasswordForm& form, |
| 302 password_manager::CredentialType credential_type) { | 310 password_manager::CredentialType credential_type) { |
| 303 DCHECK(dialog_controller_); | 311 DCHECK(dialog_controller_); |
| 304 DCHECK_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD, | 312 DCHECK_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD, |
| 305 credential_type); | 313 credential_type); |
| 314 // Copy the argument before destroying the controller. |form| is a member of |
| 315 // |dialog_controller_|. |
| 316 autofill::PasswordForm copy_form = form; |
| 306 dialog_controller_.reset(); | 317 dialog_controller_.reset(); |
| 307 passwords_data_.ChooseCredential(&form); | 318 passwords_data_.ChooseCredential(©_form); |
| 308 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); | 319 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); |
| 309 UpdateBubbleAndIconVisibility(); | 320 UpdateBubbleAndIconVisibility(); |
| 310 } | 321 } |
| 311 | 322 |
| 312 void ManagePasswordsUIController::NavigateToExternalPasswordManager() { | 323 void ManagePasswordsUIController::NavigateToExternalPasswordManager() { |
| 313 chrome::NavigateParams params( | 324 chrome::NavigateParams params( |
| 314 chrome::FindBrowserWithWebContents(web_contents()), | 325 chrome::FindBrowserWithWebContents(web_contents()), |
| 315 GURL(password_manager::kPasswordManagerAccountDashboardURL), | 326 GURL(password_manager::kPasswordManagerAccountDashboardURL), |
| 316 ui::PAGE_TRANSITION_LINK); | 327 ui::PAGE_TRANSITION_LINK); |
| 317 params.disposition = NEW_FOREGROUND_TAB; | 328 params.disposition = NEW_FOREGROUND_TAB; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); | 449 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); |
| 439 } | 450 } |
| 440 } | 451 } |
| 441 | 452 |
| 442 void ManagePasswordsUIController::WebContentsDestroyed() { | 453 void ManagePasswordsUIController::WebContentsDestroyed() { |
| 443 password_manager::PasswordStore* password_store = | 454 password_manager::PasswordStore* password_store = |
| 444 GetPasswordStore(web_contents()); | 455 GetPasswordStore(web_contents()); |
| 445 if (password_store) | 456 if (password_store) |
| 446 password_store->RemoveObserver(this); | 457 password_store->RemoveObserver(this); |
| 447 } | 458 } |
| OLD | NEW |