| 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 bubble_status_(NOT_SHOWN) { | 62 bubble_status_(NOT_SHOWN), |
| 63 weak_ptr_factory_(this) { |
| 63 passwords_data_.set_client( | 64 passwords_data_.set_client( |
| 64 ChromePasswordManagerClient::FromWebContents(web_contents)); | 65 ChromePasswordManagerClient::FromWebContents(web_contents)); |
| 65 password_manager::PasswordStore* password_store = | 66 password_manager::PasswordStore* password_store = |
| 66 GetPasswordStore(web_contents); | 67 GetPasswordStore(web_contents); |
| 67 if (password_store) | 68 if (password_store) |
| 68 password_store->AddObserver(this); | 69 password_store->AddObserver(this); |
| 69 } | 70 } |
| 70 | 71 |
| 71 ManagePasswordsUIController::~ManagePasswordsUIController() {} | 72 ManagePasswordsUIController::~ManagePasswordsUIController() {} |
| 72 | 73 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 password_manager::ui::State current_state = GetState(); | 168 password_manager::ui::State current_state = GetState(); |
| 168 passwords_data_.ProcessLoginsChanged(changes); | 169 passwords_data_.ProcessLoginsChanged(changes); |
| 169 if (current_state != GetState()) | 170 if (current_state != GetState()) |
| 170 UpdateBubbleAndIconVisibility(); | 171 UpdateBubbleAndIconVisibility(); |
| 171 } | 172 } |
| 172 | 173 |
| 173 void ManagePasswordsUIController::UpdateIconAndBubbleState( | 174 void ManagePasswordsUIController::UpdateIconAndBubbleState( |
| 174 ManagePasswordsIconView* icon) { | 175 ManagePasswordsIconView* icon) { |
| 175 if (bubble_status_ == SHOULD_POP_UP) { | 176 if (bubble_status_ == SHOULD_POP_UP) { |
| 176 DCHECK(!dialog_controller_); | 177 DCHECK(!dialog_controller_); |
| 178 // This will detach any existing bubble so OnBubbleHidden() isn't called. |
| 179 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 177 // We must display the icon before showing the bubble, as the bubble would | 180 // We must display the icon before showing the bubble, as the bubble would |
| 178 // be otherwise unanchored. | 181 // be otherwise unanchored. |
| 179 icon->SetState(GetState()); | 182 icon->SetState(GetState()); |
| 180 ShowBubbleWithoutUserInteraction(); | 183 ShowBubbleWithoutUserInteraction(); |
| 181 // If the bubble appeared then the status is updated in OnBubbleShown(). | 184 // If the bubble appeared then the status is updated in OnBubbleShown(). |
| 182 if (bubble_status_ == SHOULD_POP_UP) | 185 if (bubble_status_ == SHOULD_POP_UP) |
| 183 bubble_status_ = NOT_SHOWN; | 186 bubble_status_ = NOT_SHOWN; |
| 184 } else { | 187 } else { |
| 185 password_manager::ui::State state = GetState(); | 188 password_manager::ui::State state = GetState(); |
| 186 // The dialog should hide the icon. | 189 // The dialog should hide the icon. |
| 187 if (dialog_controller_ && | 190 if (dialog_controller_ && |
| 188 state == password_manager::ui::CREDENTIAL_REQUEST_STATE) | 191 state == password_manager::ui::CREDENTIAL_REQUEST_STATE) |
| 189 state = password_manager::ui::INACTIVE_STATE; | 192 state = password_manager::ui::INACTIVE_STATE; |
| 190 icon->SetState(state); | 193 icon->SetState(state); |
| 191 } | 194 } |
| 192 } | 195 } |
| 193 | 196 |
| 197 base::WeakPtr<PasswordsModelDelegate> |
| 198 ManagePasswordsUIController::GetModelDelegateProxy() { |
| 199 return weak_ptr_factory_.GetWeakPtr(); |
| 200 } |
| 201 |
| 202 content::WebContents* ManagePasswordsUIController::GetWebContents() const { |
| 203 return web_contents(); |
| 204 } |
| 205 |
| 194 const GURL& ManagePasswordsUIController::GetOrigin() const { | 206 const GURL& ManagePasswordsUIController::GetOrigin() const { |
| 195 return passwords_data_.origin(); | 207 return passwords_data_.origin(); |
| 196 } | 208 } |
| 197 | 209 |
| 198 password_manager::ui::State ManagePasswordsUIController::GetState() const { | 210 password_manager::ui::State ManagePasswordsUIController::GetState() const { |
| 199 return passwords_data_.state(); | 211 return passwords_data_.state(); |
| 200 } | 212 } |
| 201 | 213 |
| 202 const autofill::PasswordForm& ManagePasswordsUIController:: | 214 const autofill::PasswordForm& ManagePasswordsUIController:: |
| 203 GetPendingPassword() const { | 215 GetPendingPassword() const { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 303 |
| 292 void ManagePasswordsUIController::UpdatePassword( | 304 void ManagePasswordsUIController::UpdatePassword( |
| 293 const autofill::PasswordForm& password_form) { | 305 const autofill::PasswordForm& password_form) { |
| 294 DCHECK_EQ(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE, GetState()); | 306 DCHECK_EQ(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE, GetState()); |
| 295 UpdatePasswordInternal(password_form); | 307 UpdatePasswordInternal(password_form); |
| 296 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); | 308 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); |
| 297 UpdateBubbleAndIconVisibility(); | 309 UpdateBubbleAndIconVisibility(); |
| 298 } | 310 } |
| 299 | 311 |
| 300 void ManagePasswordsUIController::ChooseCredential( | 312 void ManagePasswordsUIController::ChooseCredential( |
| 301 autofill::PasswordForm form, | 313 const autofill::PasswordForm& form, |
| 302 password_manager::CredentialType credential_type) { | 314 password_manager::CredentialType credential_type) { |
| 303 DCHECK(dialog_controller_); | 315 DCHECK(dialog_controller_); |
| 304 DCHECK_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD, | 316 DCHECK_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD, |
| 305 credential_type); | 317 credential_type); |
| 318 // Copy the argument before destroying the controller. |form| is a member of |
| 319 // |dialog_controller_|. |
| 320 autofill::PasswordForm copy_form = form; |
| 306 dialog_controller_.reset(); | 321 dialog_controller_.reset(); |
| 307 passwords_data_.ChooseCredential(&form); | 322 passwords_data_.ChooseCredential(©_form); |
| 308 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); | 323 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); |
| 309 UpdateBubbleAndIconVisibility(); | 324 UpdateBubbleAndIconVisibility(); |
| 310 } | 325 } |
| 311 | 326 |
| 312 void ManagePasswordsUIController::NavigateToExternalPasswordManager() { | 327 void ManagePasswordsUIController::NavigateToExternalPasswordManager() { |
| 313 chrome::NavigateParams params( | 328 chrome::NavigateParams params( |
| 314 chrome::FindBrowserWithWebContents(web_contents()), | 329 chrome::FindBrowserWithWebContents(web_contents()), |
| 315 GURL(password_manager::kPasswordManagerAccountDashboardURL), | 330 GURL(password_manager::kPasswordManagerAccountDashboardURL), |
| 316 ui::PAGE_TRANSITION_LINK); | 331 ui::PAGE_TRANSITION_LINK); |
| 317 params.disposition = NEW_FOREGROUND_TAB; | 332 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); | 453 passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); |
| 439 } | 454 } |
| 440 } | 455 } |
| 441 | 456 |
| 442 void ManagePasswordsUIController::WebContentsDestroyed() { | 457 void ManagePasswordsUIController::WebContentsDestroyed() { |
| 443 password_manager::PasswordStore* password_store = | 458 password_manager::PasswordStore* password_store = |
| 444 GetPasswordStore(web_contents()); | 459 GetPasswordStore(web_contents()); |
| 445 if (password_store) | 460 if (password_store) |
| 446 password_store->RemoveObserver(this); | 461 password_store->RemoveObserver(this); |
| 447 } | 462 } |
| OLD | NEW |