cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / browser / ui / passwords / manage_passwords_view_utils.cc
blobf50800eda14dd0c8e7694427668a5477d8eba480
1 // Copyright 2015 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_view_utils.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/grit/chromium_strings.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "components/password_manager/core/browser/affiliation_utils.h"
11 #include "components/url_formatter/elide_url.h"
12 #include "net/base/net_util.h"
13 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/size.h"
17 #include "ui/gfx/image/image_skia.h"
18 #include "ui/gfx/image/image_skia_operations.h"
19 #include "ui/gfx/range/range.h"
20 #include "url/gurl.h"
22 const int kAvatarImageSize = 40;
24 gfx::ImageSkia ScaleImageForAccountAvatar(gfx::ImageSkia skia_image) {
25 gfx::Size size = skia_image.size();
26 if (size.height() != size.width()) {
27 gfx::Rect target(size);
28 int side = std::min(size.height(), size.width());
29 target.ClampToCenteredSize(gfx::Size(side, side));
30 skia_image = gfx::ImageSkiaOperations::ExtractSubset(skia_image, target);
32 return gfx::ImageSkiaOperations::CreateResizedImage(
33 skia_image,
34 skia::ImageOperations::RESIZE_BEST,
35 gfx::Size(kAvatarImageSize, kAvatarImageSize));
38 void GetSavePasswordDialogTitleTextAndLinkRange(
39 const GURL& user_visible_url,
40 const GURL& form_origin_url,
41 bool is_smartlock_branding_enabled,
42 bool is_update_password_bubble,
43 base::string16* title,
44 gfx::Range* title_link_range) {
45 std::vector<size_t> offsets;
46 std::vector<base::string16> replacements;
47 int title_id =
48 is_update_password_bubble ? IDS_UPDATE_PASSWORD : IDS_SAVE_PASSWORD;
50 // Check whether the registry controlled domains for user-visible URL (i.e.
51 // the one seen in the omnibox) and the password form post-submit navigation
52 // URL differs or not.
53 bool target_domain_differs =
54 !net::registry_controlled_domains::SameDomainOrHost(
55 user_visible_url, form_origin_url,
56 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
57 if (target_domain_differs) {
58 title_id = IDS_SAVE_PASSWORD_TITLE;
59 replacements.push_back(url_formatter::FormatUrlForSecurityDisplay(
60 form_origin_url, std::string()));
63 if (is_smartlock_branding_enabled) {
64 // "Google Smart Lock" should be a hyperlink.
65 base::string16 title_link =
66 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK);
67 replacements.insert(replacements.begin(), title_link);
68 *title = l10n_util::GetStringFUTF16(title_id, replacements, &offsets);
69 *title_link_range =
70 gfx::Range(offsets[0], offsets[0] + title_link.length());
71 } else {
72 replacements.insert(
73 replacements.begin(),
74 l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD_TITLE_BRAND));
75 *title = l10n_util::GetStringFUTF16(title_id, replacements, &offsets);
79 void GetAccountChooserDialogTitleTextAndLinkRange(
80 bool is_smartlock_branding_enabled,
81 base::string16* title,
82 gfx::Range* title_link_range) {
83 if (is_smartlock_branding_enabled) {
84 size_t offset;
85 base::string16 title_link =
86 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK);
87 *title = l10n_util::GetStringFUTF16(
88 IDS_PASSWORD_MANAGER_ACCOUNT_CHOOSER_TITLE_SMART_LOCK, title_link,
89 &offset);
90 *title_link_range = gfx::Range(offset, offset + title_link.length());
91 } else {
92 *title =
93 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_ACCOUNT_CHOOSER_TITLE);