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_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/passwords/manage_passwords_ui_controller.h" | 10 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
11 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" | 11 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" |
12 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
13 #include "components/password_manager/core/browser/password_manager_url_collecti on_experiment.h" | |
13 #include "components/password_manager/core/browser/password_store.h" | 14 #include "components/password_manager/core/browser/password_store.h" |
14 #include "components/password_manager/core/common/password_manager_ui.h" | 15 #include "components/password_manager/core/common/password_manager_ui.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
17 | 18 |
18 using autofill::PasswordFormMap; | 19 using autofill::PasswordFormMap; |
19 using content::WebContents; | 20 using content::WebContents; |
20 namespace metrics_util = password_manager::metrics_util; | 21 namespace metrics_util = password_manager::metrics_util; |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD }; | 25 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD }; |
25 | 26 |
26 const int kUsernameFieldSize = 30; | 27 const int kUsernameFieldSize = 30; |
27 const int kPasswordFieldSize = 22; | 28 const int kPasswordFieldSize = 22; |
28 | 29 |
29 // Returns the width of |type| field. | 30 // Returns the width of |type| field. |
30 int GetFieldWidth(FieldType type) { | 31 int GetFieldWidth(FieldType type) { |
31 return ui::ResourceBundle::GetSharedInstance() | 32 return ui::ResourceBundle::GetSharedInstance() |
32 .GetFontList(ui::ResourceBundle::SmallFont) | 33 .GetFontList(ui::ResourceBundle::SmallFont) |
33 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize | 34 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize |
34 : kPasswordFieldSize); | 35 : kPasswordFieldSize); |
35 } | 36 } |
36 | 37 |
38 Profile* GetProfileFromWebContents(content::WebContents* web_contents) { | |
39 if (!web_contents) | |
40 return nullptr; | |
41 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
42 } | |
43 | |
37 void RecordExperimentStatistics(content::WebContents* web_contents, | 44 void RecordExperimentStatistics(content::WebContents* web_contents, |
38 metrics_util::UIDismissalReason reason) { | 45 metrics_util::UIDismissalReason reason) { |
39 if (!web_contents) | 46 Profile* profile = GetProfileFromWebContents(web_contents); |
47 if (!profile) | |
40 return; | 48 return; |
41 Profile* profile = | |
42 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
43 password_bubble_experiment::RecordBubbleClosed(profile->GetPrefs(), reason); | 49 password_bubble_experiment::RecordBubbleClosed(profile->GetPrefs(), reason); |
44 } | 50 } |
45 | 51 |
46 base::string16 PendingStateTitleBasedOnSavePasswordPref( | 52 base::string16 PendingStateTitleBasedOnSavePasswordPref( |
47 bool never_save_passwords) { | 53 bool never_save_passwords) { |
48 return l10n_util::GetStringUTF16( | 54 return l10n_util::GetStringUTF16( |
49 never_save_passwords ? IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE | 55 never_save_passwords ? IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE |
50 : IDS_SAVE_PASSWORD); | 56 : IDS_SAVE_PASSWORD); |
51 } | 57 } |
52 | 58 |
59 void RecordURLSCollectionExperimentStatistics( | |
60 content::WebContents* web_contents) { | |
61 Profile* profile = GetProfileFromWebContents(web_contents); | |
62 if (!profile) | |
63 return; | |
64 password_manager::urls_collection_experiment::RecordBubbleClosed( | |
vabr (Chromium)
2014/12/08 11:19:33
It looks like this is called when the bubble is op
melandory
2014/12/08 13:05:31
Done.
Yep, you are right. There was reason why it
| |
65 profile->GetPrefs()); | |
66 } | |
67 | |
53 } // namespace | 68 } // namespace |
54 | 69 |
55 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( | 70 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( |
56 content::WebContents* web_contents) | 71 content::WebContents* web_contents) |
57 : content::WebContentsObserver(web_contents), | 72 : content::WebContentsObserver(web_contents), |
58 never_save_passwords_(false), | 73 never_save_passwords_(false), |
59 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), | 74 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), |
60 dismissal_reason_(metrics_util::NOT_DISPLAYED) { | 75 dismissal_reason_(metrics_util::NOT_DISPLAYED) { |
61 ManagePasswordsUIController* controller = | 76 ManagePasswordsUIController* controller = |
62 ManagePasswordsUIController::FromWebContents(web_contents); | 77 ManagePasswordsUIController::FromWebContents(web_contents); |
(...skipping 10 matching lines...) Expand all Loading... | |
73 if (password_manager::ui::IsPendingState(state_)) { | 88 if (password_manager::ui::IsPendingState(state_)) { |
74 title_ = PendingStateTitleBasedOnSavePasswordPref(never_save_passwords_); | 89 title_ = PendingStateTitleBasedOnSavePasswordPref(never_save_passwords_); |
75 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { | 90 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
76 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); | 91 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); |
77 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 92 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
78 title_ = | 93 title_ = |
79 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); | 94 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); |
80 } else if (password_manager::ui::IsCredentialsState(state_)) { | 95 } else if (password_manager::ui::IsCredentialsState(state_)) { |
81 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); | 96 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); |
82 } else if (password_manager::ui::IsAskSubmitURLState(state_)) { | 97 } else if (password_manager::ui::IsAskSubmitURLState(state_)) { |
98 RecordURLSCollectionExperimentStatistics(web_contents); | |
83 title_ = | 99 title_ = |
84 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_ASK_TO_SUBMIT_URL_TITLE); | 100 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_ASK_TO_SUBMIT_URL_TITLE); |
85 } else { | 101 } else { |
86 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); | 102 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); |
87 } | 103 } |
88 | 104 |
89 base::string16 save_confirmation_link = | 105 base::string16 save_confirmation_link = |
90 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK); | 106 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK); |
91 size_t offset; | 107 size_t offset; |
92 save_confirmation_text_ = | 108 save_confirmation_text_ = |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 | 275 |
260 // static | 276 // static |
261 int ManagePasswordsBubbleModel::UsernameFieldWidth() { | 277 int ManagePasswordsBubbleModel::UsernameFieldWidth() { |
262 return GetFieldWidth(USERNAME_FIELD); | 278 return GetFieldWidth(USERNAME_FIELD); |
263 } | 279 } |
264 | 280 |
265 // static | 281 // static |
266 int ManagePasswordsBubbleModel::PasswordFieldWidth() { | 282 int ManagePasswordsBubbleModel::PasswordFieldWidth() { |
267 return GetFieldWidth(PASSWORD_FIELD); | 283 return GetFieldWidth(PASSWORD_FIELD); |
268 } | 284 } |
OLD | NEW |