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 "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "chrome/browser/password_manager/password_store_factory.h" | 9 #include "chrome/browser/password_manager/password_store_factory.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
13 #include "components/password_manager/core/browser/password_store.h" | 13 #include "components/password_manager/core/browser/password_store.h" |
14 #include "components/password_manager/core/common/password_manager_ui.h" | 14 #include "components/password_manager/core/common/password_manager_ui.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.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 |
| 25 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD }; |
| 26 |
| 27 const int kUsernameFieldSize = 30; |
| 28 const int kPasswordFieldSize = 22; |
| 29 |
| 30 // Returns the width of |type| field. |
| 31 int GetFieldWidth(FieldType type) { |
| 32 return ui::ResourceBundle::GetSharedInstance() |
| 33 .GetFontList(ui::ResourceBundle::SmallFont) |
| 34 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize |
| 35 : kPasswordFieldSize); |
| 36 } |
| 37 |
24 void SetupLinkifiedText(const base::string16& string_with_separator, | 38 void SetupLinkifiedText(const base::string16& string_with_separator, |
25 base::string16* text, | 39 base::string16* text, |
26 gfx::Range* link_range) { | 40 gfx::Range* link_range) { |
27 std::vector<base::string16> pieces; | 41 std::vector<base::string16> pieces; |
28 base::SplitStringDontTrim(string_with_separator, | 42 base::SplitStringDontTrim(string_with_separator, |
29 '|', // separator | 43 '|', // separator |
30 &pieces); | 44 &pieces); |
31 DCHECK_EQ(3u, pieces.size()); | 45 DCHECK_EQ(3u, pieces.size()); |
32 *link_range = gfx::Range(pieces[0].size(), | 46 *link_range = gfx::Range(pieces[0].size(), |
33 pieces[0].size() + pieces[1].size()); | 47 pieces[0].size() + pieces[1].size()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 186 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
173 password_manager::PasswordStore* password_store = | 187 password_manager::PasswordStore* password_store = |
174 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) | 188 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) |
175 .get(); | 189 .get(); |
176 DCHECK(password_store); | 190 DCHECK(password_store); |
177 if (action == REMOVE_PASSWORD) | 191 if (action == REMOVE_PASSWORD) |
178 password_store->RemoveLogin(password_form); | 192 password_store->RemoveLogin(password_form); |
179 else | 193 else |
180 password_store->AddLogin(password_form); | 194 password_store->AddLogin(password_form); |
181 } | 195 } |
| 196 |
| 197 // static |
| 198 int ManagePasswordsBubbleModel::UsernameFieldWidth() { |
| 199 return GetFieldWidth(USERNAME_FIELD); |
| 200 } |
| 201 |
| 202 // static |
| 203 int ManagePasswordsBubbleModel::PasswordFieldWidth() { |
| 204 return GetFieldWidth(PASSWORD_FIELD); |
| 205 } |
OLD | NEW |