Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: components/password_manager/core/browser/password_ui_utils.cc

Issue 1841653003: Drop |languages| from {Format,Elide}Url* and IDNToUnicode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in elide_url.cc Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/password_manager/core/browser/password_ui_utils.h" 5 #include "components/password_manager/core/browser/password_ui_utils.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/autofill/core/common/password_form.h" 11 #include "components/autofill/core/common/password_form.h"
12 #include "components/password_manager/core/browser/affiliation_utils.h" 12 #include "components/password_manager/core/browser/affiliation_utils.h"
13 #include "components/url_formatter/elide_url.h" 13 #include "components/url_formatter/elide_url.h"
14 14
15 namespace password_manager { 15 namespace password_manager {
16 16
17 namespace { 17 namespace {
18 18
19 // The URL prefixes that are removed from shown origin. 19 // The URL prefixes that are removed from shown origin.
20 const char* const kRemovedPrefixes[] = {"m.", "mobile.", "www."}; 20 const char* const kRemovedPrefixes[] = {"m.", "mobile.", "www."};
21 21
22 } // namespace 22 } // namespace
23 23
24 std::string GetShownOriginAndLinkUrl( 24 std::string GetShownOriginAndLinkUrl(
25 const autofill::PasswordForm& password_form, 25 const autofill::PasswordForm& password_form,
26 const std::string& languages,
27 bool* is_android_uri, 26 bool* is_android_uri,
28 GURL* link_url, 27 GURL* link_url,
29 bool* origin_is_clickable) { 28 bool* origin_is_clickable) {
30 DCHECK(is_android_uri); 29 DCHECK(is_android_uri);
31 DCHECK(origin_is_clickable); 30 DCHECK(origin_is_clickable);
32 DCHECK(link_url); 31 DCHECK(link_url);
33 32
34 password_manager::FacetURI facet_uri = 33 password_manager::FacetURI facet_uri =
35 password_manager::FacetURI::FromPotentiallyInvalidSpec( 34 password_manager::FacetURI::FromPotentiallyInvalidSpec(
36 password_form.signon_realm); 35 password_form.signon_realm);
37 *is_android_uri = facet_uri.IsValidAndroidFacetURI(); 36 *is_android_uri = facet_uri.IsValidAndroidFacetURI();
38 if (*is_android_uri) { 37 if (*is_android_uri) {
39 if (password_form.affiliated_web_realm.empty()) { 38 if (password_form.affiliated_web_realm.empty()) {
40 *origin_is_clickable = false; 39 *origin_is_clickable = false;
41 // Since the full url should be shown in the tooltip even for 40 // Since the full url should be shown in the tooltip even for
42 // non-clickable origins, return it as |link_url|. 41 // non-clickable origins, return it as |link_url|.
43 *link_url = GURL(password_form.signon_realm); 42 *link_url = GURL(password_form.signon_realm);
44 return GetHumanReadableOriginForAndroidUri(facet_uri); 43 return GetHumanReadableOriginForAndroidUri(facet_uri);
45 } 44 }
46 *origin_is_clickable = true; 45 *origin_is_clickable = true;
47 *link_url = GURL(password_form.affiliated_web_realm); 46 *link_url = GURL(password_form.affiliated_web_realm);
48 return GetShownOrigin(*link_url, languages); 47 return GetShownOrigin(*link_url);
49 } 48 }
50 *origin_is_clickable = true; 49 *origin_is_clickable = true;
51 *link_url = password_form.origin; 50 *link_url = password_form.origin;
52 return GetShownOrigin(password_form.origin, languages); 51 return GetShownOrigin(password_form.origin);
53 } 52 }
54 53
55 std::string GetShownOrigin(const GURL& origin, const std::string& languages) { 54 std::string GetShownOrigin(const GURL& origin) {
56 std::string original = base::UTF16ToUTF8( 55 std::string original = base::UTF16ToUTF8(
57 url_formatter::FormatUrlForSecurityDisplayOmitScheme(origin, languages)); 56 url_formatter::FormatUrlForSecurityDisplayOmitScheme(origin));
58 base::StringPiece result = original; 57 base::StringPiece result = original;
59 for (base::StringPiece prefix : kRemovedPrefixes) { 58 for (base::StringPiece prefix : kRemovedPrefixes) {
60 if (base::StartsWith(result, prefix, 59 if (base::StartsWith(result, prefix,
61 base::CompareCase::INSENSITIVE_ASCII)) { 60 base::CompareCase::INSENSITIVE_ASCII)) {
62 result.remove_prefix(prefix.length()); 61 result.remove_prefix(prefix.length());
63 break; // Remove only one prefix (e.g. www.mobile.de). 62 break; // Remove only one prefix (e.g. www.mobile.de).
64 } 63 }
65 } 64 }
66 65
67 return result.find('.') != base::StringPiece::npos ? result.as_string() 66 return result.find('.') != base::StringPiece::npos ? result.as_string()
68 : original; 67 : original;
69 } 68 }
70 69
71 } // namespace password_manager 70 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698