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/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 9 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/omnibox/location_bar.h" | 11 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 11 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
| 12 | 13 |
| 13 using autofill::PasswordFormMap; | 14 using autofill::PasswordFormMap; |
| 14 | 15 |
| 15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsBubbleUIController); | 16 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsBubbleUIController); |
| 16 | 17 |
| 17 ManagePasswordsBubbleUIController::ManagePasswordsBubbleUIController( | 18 ManagePasswordsBubbleUIController::ManagePasswordsBubbleUIController( |
| 18 content::WebContents* web_contents) | 19 content::WebContents* web_contents) |
| 19 : content::WebContentsObserver(web_contents), | 20 : content::WebContentsObserver(web_contents), |
| 20 manage_passwords_icon_to_be_shown_(false), | 21 manage_passwords_icon_to_be_shown_(false), |
| 21 password_to_be_saved_(false), | 22 password_to_be_saved_(false), |
| 22 manage_passwords_bubble_needs_showing_(false), | 23 manage_passwords_bubble_needs_showing_(false), |
| 23 password_submitted_(false), | 24 autofill_blocked_(false), |
| 24 autofill_blocked_(false) {} | 25 origin_(GURL()) { |
|
vabr (Chromium)
2014/04/08 13:08:34
This initializer is not necessary, origin_ will be
Mike West
2014/04/09 07:06:51
Done.
| |
| 26 PasswordStore* password_store = GetPasswordStore(web_contents); | |
| 27 if (password_store) | |
| 28 password_store->AddObserver(this); | |
| 29 } | |
| 25 | 30 |
| 26 ManagePasswordsBubbleUIController::~ManagePasswordsBubbleUIController() {} | 31 ManagePasswordsBubbleUIController::~ManagePasswordsBubbleUIController() {} |
| 27 | 32 |
| 28 void ManagePasswordsBubbleUIController::UpdateBubbleAndIconVisibility() { | 33 void ManagePasswordsBubbleUIController::UpdateBubbleAndIconVisibility() { |
| 29 #if !defined(OS_ANDROID) | 34 #if !defined(OS_ANDROID) |
| 30 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 35 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 31 if (!browser) | 36 if (!browser) |
| 32 return; | 37 return; |
| 33 LocationBar* location_bar = browser->window()->GetLocationBar(); | 38 LocationBar* location_bar = browser->window()->GetLocationBar(); |
| 34 DCHECK(location_bar); | 39 DCHECK(location_bar); |
| 35 location_bar->UpdateManagePasswordsIconAndBubble(); | 40 location_bar->UpdateManagePasswordsIconAndBubble(); |
| 36 #endif | 41 #endif |
| 37 } | 42 } |
| 38 | 43 |
| 39 void ManagePasswordsBubbleUIController::OnPasswordSubmitted( | 44 void ManagePasswordsBubbleUIController::OnPasswordSubmitted( |
| 40 PasswordFormManager* form_manager) { | 45 PasswordFormManager* form_manager) { |
| 41 form_manager_.reset(form_manager); | 46 form_manager_.reset(form_manager); |
| 42 password_form_map_ = form_manager_->best_matches(); | 47 password_form_map_ = form_manager_->best_matches(); |
| 48 origin_ = pending_credentials().origin; | |
| 43 manage_passwords_icon_to_be_shown_ = true; | 49 manage_passwords_icon_to_be_shown_ = true; |
| 44 password_to_be_saved_ = true; | 50 password_to_be_saved_ = true; |
| 45 manage_passwords_bubble_needs_showing_ = true; | 51 manage_passwords_bubble_needs_showing_ = true; |
| 46 password_submitted_ = true; | |
| 47 autofill_blocked_ = false; | 52 autofill_blocked_ = false; |
| 48 UpdateBubbleAndIconVisibility(); | 53 UpdateBubbleAndIconVisibility(); |
| 49 } | 54 } |
| 50 | 55 |
| 51 void ManagePasswordsBubbleUIController::OnPasswordAutofilled( | 56 void ManagePasswordsBubbleUIController::OnPasswordAutofilled( |
| 52 const PasswordFormMap& password_form_map) { | 57 const PasswordFormMap& password_form_map) { |
| 53 password_form_map_ = password_form_map; | 58 password_form_map_ = password_form_map; |
| 59 origin_ = password_form_map_.begin()->second->origin; | |
| 54 manage_passwords_icon_to_be_shown_ = true; | 60 manage_passwords_icon_to_be_shown_ = true; |
| 55 password_to_be_saved_ = false; | 61 password_to_be_saved_ = false; |
| 56 manage_passwords_bubble_needs_showing_ = false; | 62 manage_passwords_bubble_needs_showing_ = false; |
| 57 password_submitted_ = false; | |
| 58 autofill_blocked_ = false; | 63 autofill_blocked_ = false; |
| 59 UpdateBubbleAndIconVisibility(); | 64 UpdateBubbleAndIconVisibility(); |
| 60 } | 65 } |
| 61 | 66 |
| 62 void ManagePasswordsBubbleUIController::OnBlacklistBlockedAutofill() { | 67 void ManagePasswordsBubbleUIController::OnBlacklistBlockedAutofill() { |
| 63 manage_passwords_icon_to_be_shown_ = true; | 68 manage_passwords_icon_to_be_shown_ = true; |
| 64 password_to_be_saved_ = false; | 69 password_to_be_saved_ = false; |
| 65 manage_passwords_bubble_needs_showing_ = false; | 70 manage_passwords_bubble_needs_showing_ = false; |
| 66 password_submitted_ = false; | |
| 67 autofill_blocked_ = true; | 71 autofill_blocked_ = true; |
| 68 UpdateBubbleAndIconVisibility(); | 72 UpdateBubbleAndIconVisibility(); |
| 69 } | 73 } |
| 70 | 74 |
| 71 void ManagePasswordsBubbleUIController::RemoveFromBestMatches( | 75 void ManagePasswordsBubbleUIController::WebContentsDestroyed( |
| 72 autofill::PasswordForm password_form) { | 76 content::WebContents* web_contents) { |
| 73 password_form_map_.erase(password_form.username_value); | 77 PasswordStore* password_store = GetPasswordStore(web_contents); |
| 78 if (password_store) | |
| 79 password_store->RemoveObserver(this); | |
| 80 } | |
| 81 | |
| 82 void ManagePasswordsBubbleUIController::OnLoginsChanged( | |
| 83 const PasswordStoreChangeList& changes) { | |
| 84 for (PasswordStoreChangeList::const_iterator it = changes.begin(); | |
| 85 it != changes.end(); | |
| 86 it++) { | |
| 87 const autofill::PasswordForm& changed_form = it->form(); | |
| 88 if (changed_form.origin != origin_) | |
| 89 continue; | |
| 90 | |
| 91 if (it->type() == PasswordStoreChange::REMOVE) { | |
| 92 password_form_map_.erase(changed_form.username_value); | |
| 93 } else { | |
| 94 autofill::PasswordForm* new_form = | |
| 95 new autofill::PasswordForm(changed_form); | |
| 96 password_form_map_[changed_form.username_value] = new_form; | |
| 97 } | |
| 98 } | |
| 74 } | 99 } |
| 75 | 100 |
| 76 void ManagePasswordsBubbleUIController::OnBubbleShown() { | 101 void ManagePasswordsBubbleUIController::OnBubbleShown() { |
| 77 unset_manage_passwords_bubble_needs_showing(); | 102 unset_manage_passwords_bubble_needs_showing(); |
| 78 } | 103 } |
| 79 | 104 |
| 80 void ManagePasswordsBubbleUIController::SavePassword() { | 105 void ManagePasswordsBubbleUIController::SavePassword() { |
| 81 DCHECK(form_manager_.get()); | 106 DCHECK(form_manager_.get()); |
| 82 form_manager_->Save(); | 107 form_manager_->Save(); |
| 83 } | 108 } |
| 84 | 109 |
| 85 void ManagePasswordsBubbleUIController::NeverSavePassword() { | 110 void ManagePasswordsBubbleUIController::NeverSavePassword() { |
| 86 DCHECK(form_manager_.get()); | 111 DCHECK(form_manager_.get()); |
| 87 form_manager_->PermanentlyBlacklist(); | 112 form_manager_->PermanentlyBlacklist(); |
| 88 } | 113 } |
| 89 | 114 |
| 90 void ManagePasswordsBubbleUIController::DidNavigateMainFrame( | 115 void ManagePasswordsBubbleUIController::DidNavigateMainFrame( |
| 91 const content::LoadCommittedDetails& details, | 116 const content::LoadCommittedDetails& details, |
| 92 const content::FrameNavigateParams& params) { | 117 const content::FrameNavigateParams& params) { |
| 93 if (details.is_in_page) | 118 if (details.is_in_page) |
| 94 return; | 119 return; |
| 95 // Reset password states for next page. | 120 // Reset password states for next page. |
| 96 manage_passwords_icon_to_be_shown_ = false; | 121 manage_passwords_icon_to_be_shown_ = false; |
| 97 password_to_be_saved_ = false; | 122 password_to_be_saved_ = false; |
| 98 manage_passwords_bubble_needs_showing_ = false; | 123 manage_passwords_bubble_needs_showing_ = false; |
| 99 password_submitted_ = false; | |
| 100 UpdateBubbleAndIconVisibility(); | 124 UpdateBubbleAndIconVisibility(); |
| 101 } | 125 } |
| 126 | |
| 127 PasswordStore* ManagePasswordsBubbleUIController::GetPasswordStore( | |
| 128 content::WebContents* web_contents) { | |
| 129 return PasswordStoreFactory::GetForProfile( | |
| 130 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | |
| 131 Profile::EXPLICIT_ACCESS).get(); | |
| 132 } | |
| OLD | NEW |