Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_view_utils.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/elide_url.h" | |
| 9 #include "chrome/grit/chromium_strings.h" | |
| 10 #include "chrome/grit/generated_resources.h" | |
| 8 #include "components/password_manager/core/browser/affiliation_utils.h" | 11 #include "components/password_manager/core/browser/affiliation_utils.h" |
| 9 #include "net/base/net_util.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" | |
| 10 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 12 #include "ui/gfx/image/image_skia.h" | 17 #include "ui/gfx/image/image_skia.h" |
| 13 #include "ui/gfx/image/image_skia_operations.h" | 18 #include "ui/gfx/image/image_skia_operations.h" |
| 19 #include "ui/gfx/range/range.h" | |
| 14 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 15 | 21 |
| 16 const int kAvatarImageSize = 50; | 22 const int kAvatarImageSize = 50; |
| 17 | 23 |
| 18 gfx::ImageSkia ScaleImageForAccountAvatar(gfx::ImageSkia skia_image) { | 24 gfx::ImageSkia ScaleImageForAccountAvatar(gfx::ImageSkia skia_image) { |
| 19 gfx::Size size = skia_image.size(); | 25 gfx::Size size = skia_image.size(); |
| 20 if (size.height() != size.width()) { | 26 if (size.height() != size.width()) { |
| 21 gfx::Rect target(size); | 27 gfx::Rect target(size); |
| 22 int side = std::min(size.height(), size.width()); | 28 int side = std::min(size.height(), size.width()); |
| 23 target.ClampToCenteredSize(gfx::Size(side, side)); | 29 target.ClampToCenteredSize(gfx::Size(side, side)); |
| 24 skia_image = gfx::ImageSkiaOperations::ExtractSubset(skia_image, target); | 30 skia_image = gfx::ImageSkiaOperations::ExtractSubset(skia_image, target); |
| 25 } | 31 } |
| 26 return gfx::ImageSkiaOperations::CreateResizedImage( | 32 return gfx::ImageSkiaOperations::CreateResizedImage( |
| 27 skia_image, | 33 skia_image, |
| 28 skia::ImageOperations::RESIZE_BEST, | 34 skia::ImageOperations::RESIZE_BEST, |
| 29 gfx::Size(kAvatarImageSize, kAvatarImageSize)); | 35 gfx::Size(kAvatarImageSize, kAvatarImageSize)); |
| 30 } | 36 } |
| 37 | |
| 38 void GetSavePasswordDialogTitleTextAndLinkRange( | |
| 39 const GURL& user_visible_url, | |
| 40 const GURL& form_origin_url, | |
| 41 bool is_smartlock_branding_enabled, | |
| 42 base::string16* title, | |
| 43 gfx::Range* title_link_range) { | |
| 44 std::vector<size_t> offsets; | |
| 45 std::vector<base::string16> replacements; | |
| 46 int title_id = IDS_SAVE_PASSWORD; | |
| 47 | |
| 48 // Check whether the registry controlled domains for user-visible URL (i.e. | |
|
palmer
2015/06/26 17:59:58
Nit: Arguably, this comment is unnecessary. (I thi
Pritam Nikam
2015/06/27 10:10:03
In that case, I'll prefer to keep this as is :)
| |
| 49 // the one seen in the omnibox) and the password form post-submit navigation | |
| 50 // URL differs or not. | |
| 51 bool target_domain_differs = | |
| 52 !net::registry_controlled_domains::SameDomainOrHost( | |
| 53 user_visible_url, form_origin_url, | |
| 54 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | |
| 55 if (target_domain_differs) { | |
| 56 title_id = IDS_SAVE_PASSWORD_TITLE; | |
| 57 replacements.push_back( | |
| 58 FormatUrlForSecurityDisplay(form_origin_url, std::string())); | |
| 59 } | |
| 60 | |
| 61 if (is_smartlock_branding_enabled) { | |
| 62 // "Google Smart Lock" should be a hyperlink. | |
| 63 base::string16 title_link = | |
| 64 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK); | |
| 65 replacements.insert(replacements.begin(), title_link); | |
| 66 *title = l10n_util::GetStringFUTF16(title_id, replacements, &offsets); | |
| 67 *title_link_range = | |
| 68 gfx::Range(offsets[0], offsets[0] + title_link.length()); | |
| 69 } else { | |
| 70 replacements.insert( | |
| 71 replacements.begin(), | |
| 72 l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD_TITLE_BRAND)); | |
| 73 *title = l10n_util::GetStringFUTF16(title_id, replacements, &offsets); | |
| 74 } | |
| 75 } | |
| OLD | NEW |