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 "components/autofill/core/common/password_form.h"
9 #include "components/password_manager/core/browser/affiliation_utils.h"
10 #include "net/base/net_util.h"
11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/geometry/size.h"
13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/gfx/image/image_skia_operations.h"
17 const int kAvatarImageSize
= 50;
19 gfx::ImageSkia
ScaleImageForAccountAvatar(gfx::ImageSkia skia_image
) {
20 gfx::Size size
= skia_image
.size();
21 if (size
.height() != size
.width()) {
22 gfx::Rect
target(size
);
23 int side
= std::min(size
.height(), size
.width());
24 target
.ClampToCenteredSize(gfx::Size(side
, side
));
25 skia_image
= gfx::ImageSkiaOperations::ExtractSubset(skia_image
, target
);
27 return gfx::ImageSkiaOperations::CreateResizedImage(
29 skia::ImageOperations::RESIZE_BEST
,
30 gfx::Size(kAvatarImageSize
, kAvatarImageSize
));
33 std::string
GetHumanReadableOrigin(const autofill::PasswordForm
& password_form
,
34 const std::string
& languages
) {
35 password_manager::FacetURI facet_uri
=
36 password_manager::FacetURI::FromPotentiallyInvalidSpec(
37 password_form
.signon_realm
);
38 if (facet_uri
.IsValidAndroidFacetURI())
39 return facet_uri
.scheme() + "://" + facet_uri
.android_package_name();
40 return base::UTF16ToUTF8(net::FormatUrl(password_form
.origin
, languages
));