Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_bubble_model.cc

Issue 232753002: Password bubble: Deplatformify ManagePasswordsBubbleView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_model.h" 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
6 6
7 #include "chrome/browser/password_manager/password_store_factory.h" 7 #include "chrome/browser/password_manager/password_store_factory.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_finder.h" 9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/chrome_pages.h"
11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" 10 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
12 #include "chrome/common/url_constants.h"
13 #include "components/password_manager/core/browser/password_store.h" 11 #include "components/password_manager/core/browser/password_store.h"
14 #include "grit/generated_resources.h" 12 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
16 14
17 using content::WebContents; 15 using content::WebContents;
18 using autofill::PasswordFormMap; 16 using autofill::PasswordFormMap;
19 17
20 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( 18 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
21 content::WebContents* web_contents) 19 content::WebContents* web_contents)
22 : content::WebContentsObserver(web_contents), 20 : content::WebContentsObserver(web_contents),
23 web_contents_(web_contents) { 21 web_contents_(web_contents),
22 display_disposition_(
23 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING),
24 dismissal_reason_(password_manager::metrics_util::NOT_DISPLAYED) {
24 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = 25 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller =
25 ManagePasswordsBubbleUIController::FromWebContents(web_contents_); 26 ManagePasswordsBubbleUIController::FromWebContents(web_contents_);
26 27
27 if (manage_passwords_bubble_ui_controller->password_to_be_saved()) 28 if (manage_passwords_bubble_ui_controller->password_to_be_saved())
28 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; 29 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED;
29 else 30 else
30 manage_passwords_bubble_state_ = MANAGE_PASSWORDS; 31 manage_passwords_bubble_state_ = MANAGE_PASSWORDS;
31 32
32 title_ = l10n_util::GetStringUTF16( 33 title_ = l10n_util::GetStringUTF16(
33 (manage_passwords_bubble_state_ == PASSWORD_TO_BE_SAVED) ? 34 (manage_passwords_bubble_state_ == PASSWORD_TO_BE_SAVED) ?
34 IDS_SAVE_PASSWORD : IDS_MANAGE_PASSWORDS); 35 IDS_SAVE_PASSWORD : IDS_MANAGE_PASSWORDS);
35 pending_credentials_ = 36 pending_credentials_ =
36 manage_passwords_bubble_ui_controller->pending_credentials(); 37 manage_passwords_bubble_ui_controller->PendingCredentials();
37 best_matches_ = manage_passwords_bubble_ui_controller->best_matches(); 38 best_matches_ = manage_passwords_bubble_ui_controller->best_matches();
38 manage_link_ = 39 manage_link_ =
39 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK); 40 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK);
40 } 41 }
41 42
42 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {} 43 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {}
43 44
45 void ManagePasswordsBubbleModel::OnBubbleShown(
46 ManagePasswordsBubble::DisplayReason reason) {
47 DCHECK(WaitingToSavePassword() ||
48 reason == ManagePasswordsBubble::USER_ACTION);
49 if (reason == ManagePasswordsBubble::USER_ACTION) {
50 if (WaitingToSavePassword()) {
51 display_disposition_ =
52 password_manager::metrics_util::MANUAL_WITH_PASSWORD_PENDING;
53 } else {
54 // TODO(mkwst): Deal with "Never save passwords" once we've decided how
55 // that flow should work.
56 display_disposition_ =
57 password_manager::metrics_util::MANUAL_MANAGE_PASSWORDS;
58 }
59 } else {
60 display_disposition_ =
61 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING;
62 }
63 password_manager::metrics_util::LogUIDisplayDisposition(display_disposition_);
64
65 // Default to a dismissal reason of "no interaction". If the user interacts
66 // with the button in such a way that it closes, we'll reset this value
67 // accordingly.
68 dismissal_reason_ = password_manager::metrics_util::NO_DIRECT_INTERACTION;
69 }
70
71 void ManagePasswordsBubbleModel::OnBubbleHidden() {
72 if (dismissal_reason_ == password_manager::metrics_util::NOT_DISPLAYED)
73 return;
74
75 password_manager::metrics_util::LogUIDismissalReason(dismissal_reason_);
76 }
77
78 void ManagePasswordsBubbleModel::OnCloseWithoutLogging() {
79 dismissal_reason_ = password_manager::metrics_util::NOT_DISPLAYED;
80 }
81
44 void ManagePasswordsBubbleModel::OnNopeClicked() { 82 void ManagePasswordsBubbleModel::OnNopeClicked() {
83 dismissal_reason_ = password_manager::metrics_util::CLICKED_NOPE;
45 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED; 84 manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED;
46 } 85 }
47 86
48 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { 87 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() {
88 dismissal_reason_ = password_manager::metrics_util::CLICKED_NEVER;
49 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = 89 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller =
50 ManagePasswordsBubbleUIController::FromWebContents(web_contents_); 90 ManagePasswordsBubbleUIController::FromWebContents(web_contents_);
51 manage_passwords_bubble_ui_controller->NeverSavePassword(); 91 manage_passwords_bubble_ui_controller->NeverSavePassword();
52 manage_passwords_bubble_ui_controller->unset_password_to_be_saved(); 92 manage_passwords_bubble_ui_controller->unset_password_to_be_saved();
53 manage_passwords_bubble_state_ = NEVER_SAVE_PASSWORDS; 93 manage_passwords_bubble_state_ = NEVER_SAVE_PASSWORDS;
54 } 94 }
55 95
56 void ManagePasswordsBubbleModel::OnSaveClicked() { 96 void ManagePasswordsBubbleModel::OnSaveClicked() {
97 dismissal_reason_ = password_manager::metrics_util::CLICKED_SAVE;
57 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = 98 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller =
58 ManagePasswordsBubbleUIController::FromWebContents(web_contents_); 99 ManagePasswordsBubbleUIController::FromWebContents(web_contents_);
59 manage_passwords_bubble_ui_controller->SavePassword(); 100 manage_passwords_bubble_ui_controller->SavePassword();
60 manage_passwords_bubble_ui_controller->unset_password_to_be_saved(); 101 manage_passwords_bubble_ui_controller->unset_password_to_be_saved();
61 manage_passwords_bubble_state_ = MANAGE_PASSWORDS; 102 manage_passwords_bubble_state_ = MANAGE_PASSWORDS;
62 } 103 }
63 104
105 void ManagePasswordsBubbleModel::OnDoneClicked() {
106 dismissal_reason_ = password_manager::metrics_util::CLICKED_DONE;
107 }
108
64 void ManagePasswordsBubbleModel::OnManageLinkClicked() { 109 void ManagePasswordsBubbleModel::OnManageLinkClicked() {
65 chrome::ShowSettingsSubPage(chrome::FindBrowserWithWebContents(web_contents_), 110 dismissal_reason_ = password_manager::metrics_util::CLICKED_MANAGE;
66 chrome::kPasswordManagerSubPage); 111 ManagePasswordsBubbleUIController::FromWebContents(web_contents_)
112 ->NavigateToPasswordManagerSettingsPage();
67 } 113 }
68 114
69 void ManagePasswordsBubbleModel::OnPasswordAction( 115 void ManagePasswordsBubbleModel::OnPasswordAction(
70 const autofill::PasswordForm& password_form, 116 const autofill::PasswordForm& password_form,
71 PasswordAction action) { 117 PasswordAction action) {
72 if (!web_contents_) 118 if (!web_contents_)
73 return; 119 return;
74 Profile* profile = 120 Profile* profile =
75 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 121 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
76 password_manager::PasswordStore* password_store = 122 password_manager::PasswordStore* password_store =
77 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) 123 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS)
78 .get(); 124 .get();
79 DCHECK(password_store); 125 DCHECK(password_store);
80 if (action == REMOVE_PASSWORD) 126 if (action == REMOVE_PASSWORD)
81 password_store->RemoveLogin(password_form); 127 password_store->RemoveLogin(password_form);
82 else 128 else
83 password_store->AddLogin(password_form); 129 password_store->AddLogin(password_form);
84 } 130 }
85 131
86 void ManagePasswordsBubbleModel::WebContentsDestroyed( 132 void ManagePasswordsBubbleModel::WebContentsDestroyed(
87 content::WebContents* web_contents) { 133 content::WebContents* web_contents) {
88 // The WebContents have been destroyed. 134 // The WebContents have been destroyed.
89 web_contents_ = NULL; 135 web_contents_ = NULL;
90 } 136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698