OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" |
| 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/ui/browser_finder.h" |
| 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 11 #include "content/public/browser/notification_service.h" |
| 12 |
| 13 using autofill::PasswordFormMap; |
| 14 |
| 15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsBubbleUIController); |
| 16 |
| 17 ManagePasswordsBubbleUIController::ManagePasswordsBubbleUIController( |
| 18 content::WebContents* web_contents) |
| 19 : content::WebContentsObserver(web_contents), |
| 20 manage_passwords_icon_to_be_shown_(false), |
| 21 password_to_be_saved_(false), |
| 22 manage_passwords_bubble_needs_showing_(false), |
| 23 password_submitted_(false) {} |
| 24 |
| 25 ManagePasswordsBubbleUIController::~ManagePasswordsBubbleUIController() {} |
| 26 |
| 27 void ManagePasswordsBubbleUIController::UpdateBubbleAndIconVisibility() { |
| 28 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 29 if (!browser) |
| 30 return; |
| 31 LocationBar* location_bar = browser->window()->GetLocationBar(); |
| 32 DCHECK(location_bar); |
| 33 location_bar->UpdateManagePasswordsIconAndBubble(); |
| 34 } |
| 35 |
| 36 void ManagePasswordsBubbleUIController::OnPasswordSubmitted( |
| 37 PasswordFormManager* form_manager) { |
| 38 form_manager_.reset(form_manager); |
| 39 password_form_map_ = form_manager_->best_matches(); |
| 40 manage_passwords_icon_to_be_shown_ = true; |
| 41 password_to_be_saved_ = true; |
| 42 manage_passwords_bubble_needs_showing_ = true; |
| 43 password_submitted_ = true; |
| 44 UpdateBubbleAndIconVisibility(); |
| 45 } |
| 46 |
| 47 void ManagePasswordsBubbleUIController::OnPasswordAutofilled( |
| 48 const PasswordFormMap& password_form_map) { |
| 49 password_form_map_ = password_form_map; |
| 50 manage_passwords_icon_to_be_shown_ = true; |
| 51 password_to_be_saved_ = false; |
| 52 manage_passwords_bubble_needs_showing_ = false; |
| 53 password_submitted_ = false; |
| 54 UpdateBubbleAndIconVisibility(); |
| 55 } |
| 56 |
| 57 void ManagePasswordsBubbleUIController::RemoveFromBestMatches( |
| 58 autofill::PasswordForm password_form) { |
| 59 password_form_map_.erase(password_form.username_value); |
| 60 } |
| 61 |
| 62 void ManagePasswordsBubbleUIController::OnBubbleShown() { |
| 63 unset_manage_passwords_bubble_needs_showing(); |
| 64 } |
| 65 |
| 66 void ManagePasswordsBubbleUIController::SavePassword() { |
| 67 DCHECK(form_manager_.get()); |
| 68 form_manager_->Save(); |
| 69 } |
| 70 |
| 71 void ManagePasswordsBubbleUIController::DidNavigateMainFrame( |
| 72 const content::LoadCommittedDetails& details, |
| 73 const content::FrameNavigateParams& params) { |
| 74 if (details.is_in_page) |
| 75 return; |
| 76 // Reset password states for next page. |
| 77 manage_passwords_icon_to_be_shown_ = false; |
| 78 password_to_be_saved_ = false; |
| 79 manage_passwords_bubble_needs_showing_ = false; |
| 80 password_submitted_ = false; |
| 81 UpdateBubbleAndIconVisibility(); |
| 82 } |
OLD | NEW |