Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / passwords / manage_passwords_bubble_ui_controller.cc
blobe103dc132d5d45503dfcb4c13b7a5c7811dc44ad
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.
5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
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"
13 using autofill::PasswordFormMap;
15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsBubbleUIController);
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) {}
25 ManagePasswordsBubbleUIController::~ManagePasswordsBubbleUIController() {}
27 void ManagePasswordsBubbleUIController::UpdateBubbleAndIconVisibility() {
28 #if !defined(OS_ANDROID)
29 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
30 if (!browser)
31 return;
32 LocationBar* location_bar = browser->window()->GetLocationBar();
33 DCHECK(location_bar);
34 location_bar->UpdateManagePasswordsIconAndBubble();
35 #endif
38 void ManagePasswordsBubbleUIController::OnPasswordSubmitted(
39 PasswordFormManager* form_manager) {
40 form_manager_.reset(form_manager);
41 password_form_map_ = form_manager_->best_matches();
42 manage_passwords_icon_to_be_shown_ = true;
43 password_to_be_saved_ = true;
44 manage_passwords_bubble_needs_showing_ = true;
45 password_submitted_ = true;
46 UpdateBubbleAndIconVisibility();
49 void ManagePasswordsBubbleUIController::OnPasswordAutofilled(
50 const PasswordFormMap& password_form_map) {
51 password_form_map_ = password_form_map;
52 manage_passwords_icon_to_be_shown_ = true;
53 password_to_be_saved_ = false;
54 manage_passwords_bubble_needs_showing_ = false;
55 password_submitted_ = false;
56 UpdateBubbleAndIconVisibility();
59 void ManagePasswordsBubbleUIController::RemoveFromBestMatches(
60 autofill::PasswordForm password_form) {
61 password_form_map_.erase(password_form.username_value);
64 void ManagePasswordsBubbleUIController::OnBubbleShown() {
65 unset_manage_passwords_bubble_needs_showing();
68 void ManagePasswordsBubbleUIController::SavePassword() {
69 DCHECK(form_manager_.get());
70 form_manager_->Save();
73 void ManagePasswordsBubbleUIController::DidNavigateMainFrame(
74 const content::LoadCommittedDetails& details,
75 const content::FrameNavigateParams& params) {
76 if (details.is_in_page)
77 return;
78 // Reset password states for next page.
79 manage_passwords_icon_to_be_shown_ = false;
80 password_to_be_saved_ = false;
81 manage_passwords_bubble_needs_showing_ = false;
82 password_submitted_ = false;
83 UpdateBubbleAndIconVisibility();