Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / passwords / manage_passwords_bubble_model.cc
blob9934ee9d6d3588797f7c198494bc2d9916078c73
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_model.h"
7 #include "chrome/browser/password_manager/password_store.h"
8 #include "chrome/browser/password_manager/password_store_factory.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/chrome_pages.h"
12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
13 #include "chrome/common/url_constants.h"
14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
17 using content::WebContents;
18 using autofill::PasswordFormMap;
20 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
21 content::WebContents* web_contents)
22 : content::WebContentsObserver(web_contents),
23 web_contents_(web_contents) {
24 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller =
25 ManagePasswordsBubbleUIController::FromWebContents(web_contents_);
27 password_submitted_ =
28 manage_passwords_bubble_ui_controller->password_submitted();
29 if (password_submitted_) {
30 if (manage_passwords_bubble_ui_controller->password_to_be_saved())
31 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED;
32 else
33 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING;
34 } else {
35 manage_passwords_bubble_state_ = MANAGE_PASSWORDS;
38 title_ = l10n_util::GetStringUTF16(
39 (manage_passwords_bubble_state_ == PASSWORD_TO_BE_SAVED) ?
40 IDS_SAVE_PASSWORD : IDS_MANAGE_PASSWORDS);
41 if (password_submitted_) {
42 pending_credentials_ =
43 manage_passwords_bubble_ui_controller->pending_credentials();
45 best_matches_ = manage_passwords_bubble_ui_controller->best_matches();
46 manage_link_ =
47 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK);
50 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {}
52 void ManagePasswordsBubbleModel::OnCancelClicked() {
53 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED;
56 void ManagePasswordsBubbleModel::OnSaveClicked() {
57 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller =
58 ManagePasswordsBubbleUIController::FromWebContents(web_contents_);
59 manage_passwords_bubble_ui_controller->SavePassword();
60 manage_passwords_bubble_ui_controller->unset_password_to_be_saved();
61 manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING;
64 void ManagePasswordsBubbleModel::OnManageLinkClicked() {
65 chrome::ShowSettingsSubPage(chrome::FindBrowserWithWebContents(web_contents_),
66 chrome::kPasswordManagerSubPage);
69 void ManagePasswordsBubbleModel::OnPasswordAction(
70 autofill::PasswordForm password_form,
71 bool remove) {
72 if (!web_contents_)
73 return;
74 Profile* profile =
75 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
76 PasswordStore* password_store = PasswordStoreFactory::GetForProfile(
77 profile, Profile::EXPLICIT_ACCESS).get();
78 DCHECK(password_store);
79 if (remove)
80 password_store->RemoveLogin(password_form);
81 else
82 password_store->AddLogin(password_form);
83 // This is necessary in case the bubble is instantiated again, we thus do not
84 // display the pending credentials if they were deleted.
85 if (password_form.username_value == pending_credentials_.username_value) {
86 ManagePasswordsBubbleUIController::FromWebContents(web_contents_)->
87 set_password_submitted(!remove);
91 void ManagePasswordsBubbleModel::DeleteFromBestMatches(
92 autofill::PasswordForm password_form) {
93 ManagePasswordsBubbleUIController::FromWebContents(web_contents_)->
94 RemoveFromBestMatches(password_form);
97 void ManagePasswordsBubbleModel::WebContentsDestroyed(
98 content::WebContents* web_contents) {
99 // The WebContents have been destroyed.
100 web_contents_ = NULL;