Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_bubble_ui_controller.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/password_manager/password_store_factory.h" | 8 #include "chrome/browser/password_manager/password_store_factory.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/chrome_pages.h" | 11 #include "chrome/browser/ui/chrome_pages.h" |
| 12 #include "chrome/browser/ui/omnibox/location_bar.h" | 12 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 13 #include "chrome/browser/ui/passwords/manage_passwords_icon.h" | |
| 13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 14 #include "components/password_manager/core/browser/password_store.h" | 15 #include "components/password_manager/core/browser/password_store.h" |
| 15 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 16 | 17 |
| 17 using autofill::PasswordFormMap; | 18 using autofill::PasswordFormMap; |
| 18 using password_manager::PasswordFormManager; | 19 using password_manager::PasswordFormManager; |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 password_manager::PasswordStore* GetPasswordStore( | 23 password_manager::PasswordStore* GetPasswordStore( |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 51 if (!browser) | 52 if (!browser) |
| 52 return; | 53 return; |
| 53 LocationBar* location_bar = browser->window()->GetLocationBar(); | 54 LocationBar* location_bar = browser->window()->GetLocationBar(); |
| 54 DCHECK(location_bar); | 55 DCHECK(location_bar); |
| 55 location_bar->UpdateManagePasswordsIconAndBubble(); | 56 location_bar->UpdateManagePasswordsIconAndBubble(); |
| 56 #endif | 57 #endif |
| 57 } | 58 } |
| 58 | 59 |
| 59 void ManagePasswordsBubbleUIController::OnPasswordSubmitted( | 60 void ManagePasswordsBubbleUIController::OnPasswordSubmitted( |
| 60 PasswordFormManager* form_manager) { | 61 PasswordFormManager* form_manager) { |
| 61 form_manager_.reset(form_manager); | 62 // The |form_manager| might be NULL during testing. |
| 62 password_form_map_ = form_manager_->best_matches(); | 63 if (form_manager) { |
|
vabr (Chromium)
2014/04/24 12:56:12
nit: I'm always a bit uneasy about modifying produ
Mike West
2014/04/24 14:27:59
Naah, you're right. I shouldn't have taken the eas
| |
| 64 form_manager_.reset(form_manager); | |
| 65 password_form_map_ = form_manager_->best_matches(); | |
| 66 } | |
| 63 origin_ = PendingCredentials().origin; | 67 origin_ = PendingCredentials().origin; |
| 64 manage_passwords_icon_to_be_shown_ = true; | 68 manage_passwords_icon_to_be_shown_ = true; |
| 65 password_to_be_saved_ = true; | 69 password_to_be_saved_ = true; |
| 66 manage_passwords_bubble_needs_showing_ = true; | 70 manage_passwords_bubble_needs_showing_ = true; |
| 67 autofill_blocked_ = false; | 71 autofill_blocked_ = false; |
| 68 UpdateBubbleAndIconVisibility(); | 72 UpdateBubbleAndIconVisibility(); |
| 69 } | 73 } |
| 70 | 74 |
| 71 void ManagePasswordsBubbleUIController::OnPasswordAutofilled( | 75 void ManagePasswordsBubbleUIController::OnPasswordAutofilled( |
| 72 const PasswordFormMap& password_form_map) { | 76 const PasswordFormMap& password_form_map) { |
| 73 password_form_map_ = password_form_map; | 77 // An empty |password_form_map| might be provided during testing. |
| 74 origin_ = password_form_map_.begin()->second->origin; | 78 if (!password_form_map_.empty()) { |
|
vabr (Chromium)
2014/04/24 12:56:12
Ditto about putting test-only provisions into prod
Mike West
2014/04/24 14:27:59
Done.
| |
| 79 password_form_map_ = password_form_map; | |
| 80 origin_ = password_form_map_.begin()->second->origin; | |
| 81 } | |
| 75 manage_passwords_icon_to_be_shown_ = true; | 82 manage_passwords_icon_to_be_shown_ = true; |
| 76 password_to_be_saved_ = false; | 83 password_to_be_saved_ = false; |
| 77 manage_passwords_bubble_needs_showing_ = false; | 84 manage_passwords_bubble_needs_showing_ = false; |
| 78 autofill_blocked_ = false; | 85 autofill_blocked_ = false; |
| 79 UpdateBubbleAndIconVisibility(); | 86 UpdateBubbleAndIconVisibility(); |
| 80 } | 87 } |
| 81 | 88 |
| 82 void ManagePasswordsBubbleUIController::OnBlacklistBlockedAutofill() { | 89 void ManagePasswordsBubbleUIController::OnBlacklistBlockedAutofill() { |
| 83 manage_passwords_icon_to_be_shown_ = true; | 90 manage_passwords_icon_to_be_shown_ = true; |
| 84 password_to_be_saved_ = false; | 91 password_to_be_saved_ = false; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 108 if (it->type() == password_manager::PasswordStoreChange::REMOVE) { | 115 if (it->type() == password_manager::PasswordStoreChange::REMOVE) { |
| 109 password_form_map_.erase(changed_form.username_value); | 116 password_form_map_.erase(changed_form.username_value); |
| 110 } else { | 117 } else { |
| 111 autofill::PasswordForm* new_form = | 118 autofill::PasswordForm* new_form = |
| 112 new autofill::PasswordForm(changed_form); | 119 new autofill::PasswordForm(changed_form); |
| 113 password_form_map_[changed_form.username_value] = new_form; | 120 password_form_map_[changed_form.username_value] = new_form; |
| 114 } | 121 } |
| 115 } | 122 } |
| 116 } | 123 } |
| 117 | 124 |
| 118 void ManagePasswordsBubbleUIController::OnBubbleShown() { | |
| 119 unset_manage_passwords_bubble_needs_showing(); | |
| 120 } | |
| 121 | |
| 122 void ManagePasswordsBubbleUIController:: | 125 void ManagePasswordsBubbleUIController:: |
| 123 NavigateToPasswordManagerSettingsPage() { | 126 NavigateToPasswordManagerSettingsPage() { |
| 124 // TODO(mkwst): chrome_pages.h is compiled out of Android. Need to figure out | 127 // TODO(mkwst): chrome_pages.h is compiled out of Android. Need to figure out |
| 125 // how this navigation should work there. | 128 // how this navigation should work there. |
| 126 #if !defined(OS_ANDROID) | 129 #if !defined(OS_ANDROID) |
| 127 chrome::ShowSettingsSubPage( | 130 chrome::ShowSettingsSubPage( |
| 128 chrome::FindBrowserWithWebContents(web_contents()), | 131 chrome::FindBrowserWithWebContents(web_contents()), |
| 129 chrome::kPasswordManagerSubPage); | 132 chrome::kPasswordManagerSubPage); |
| 130 #endif | 133 #endif |
| 131 } | 134 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 150 password_to_be_saved_ = false; | 153 password_to_be_saved_ = false; |
| 151 manage_passwords_bubble_needs_showing_ = false; | 154 manage_passwords_bubble_needs_showing_ = false; |
| 152 UpdateBubbleAndIconVisibility(); | 155 UpdateBubbleAndIconVisibility(); |
| 153 } | 156 } |
| 154 | 157 |
| 155 const autofill::PasswordForm& ManagePasswordsBubbleUIController:: | 158 const autofill::PasswordForm& ManagePasswordsBubbleUIController:: |
| 156 PendingCredentials() const { | 159 PendingCredentials() const { |
| 157 DCHECK(form_manager_); | 160 DCHECK(form_manager_); |
| 158 return form_manager_->pending_credentials(); | 161 return form_manager_->pending_credentials(); |
| 159 } | 162 } |
| 163 | |
| 164 void ManagePasswordsBubbleUIController::UpdateIconAndBubbleState( | |
| 165 ManagePasswordsIcon* icon) { | |
| 166 ManagePasswordsIcon::State state = ManagePasswordsIcon::INACTIVE_STATE; | |
| 167 | |
| 168 if (autofill_blocked_) | |
| 169 state = ManagePasswordsIcon::BLACKLISTED_STATE; | |
| 170 else if (password_to_be_saved_) | |
| 171 state = ManagePasswordsIcon::PENDING_STATE; | |
| 172 else if (manage_passwords_icon_to_be_shown_) | |
| 173 state = ManagePasswordsIcon::MANAGE_STATE; | |
| 174 | |
| 175 icon->SetState(state); | |
| 176 | |
| 177 if (manage_passwords_bubble_needs_showing_) { | |
| 178 DCHECK(state == ManagePasswordsIcon::PENDING_STATE); | |
| 179 icon->ShowBubbleWithoutUserInteraction(); | |
| 180 manage_passwords_bubble_needs_showing_ = false; | |
| 181 } | |
| 182 } | |
| OLD | NEW |