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

Unified Diff: components/url_formatter/elide_url.cc

Issue 1843063002: Don't show scheme in permission prompts if it is HTTPS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/url_formatter/elide_url.h ('k') | components/url_formatter/elide_url_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/url_formatter/elide_url.cc
diff --git a/components/url_formatter/elide_url.cc b/components/url_formatter/elide_url.cc
index 6e164f94508b1a9a06687f8c6372be00cf2c31b6..ad058c2262eca8db465959dfa9c851cb145a15b3 100644
--- a/components/url_formatter/elide_url.cc
+++ b/components/url_formatter/elide_url.cc
@@ -106,50 +106,23 @@ void SplitHost(const GURL& url,
url_subdomain->clear();
}
}
-
#endif // !defined(OS_ANDROID)
-base::string16 FormatUrlForSecurityDisplayInternal(const GURL& url,
- bool omit_scheme) {
- if (!url.is_valid() || url.is_empty() || !url.IsStandard())
- return url_formatter::FormatUrl(url);
+bool ShouldShowScheme(const GURL& url,
+ const url_formatter::SchemeDisplay scheme_display) {
+ switch (scheme_display) {
+ case url_formatter::SchemeDisplay::SHOW:
+ return true;
- const base::string16 colon(base::ASCIIToUTF16(":"));
- const base::string16 scheme_separator(
- base::ASCIIToUTF16(url::kStandardSchemeSeparator));
-
- if (url.SchemeIsFile()) {
- return base::ASCIIToUTF16(url::kFileScheme) + scheme_separator +
- base::UTF8ToUTF16(url.path());
- }
+ case url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS:
+ return !url.SchemeIs(url::kHttpsScheme) &&
+ !url.SchemeIs(url::kHttpScheme);
- if (url.SchemeIsFileSystem()) {
- const GURL* inner_url = url.inner_url();
- if (inner_url->SchemeIsFile()) {
- return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
- FormatUrlForSecurityDisplayInternal(*inner_url, false) +
- base::UTF8ToUTF16(url.path());
- }
- return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
- FormatUrlForSecurityDisplayInternal(*inner_url, false);
+ case url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC:
+ return !url.SchemeIsCryptographic();
}
- const GURL origin = url.GetOrigin();
- const std::string& scheme = origin.scheme();
- const std::string& host = origin.host();
-
- base::string16 result;
- if (!omit_scheme || !url.SchemeIsHTTPOrHTTPS())
- result = base::UTF8ToUTF16(scheme) + scheme_separator;
- result += base::UTF8ToUTF16(host);
-
- const int port = origin.IntPort();
- const int default_port = url::DefaultPortForScheme(
- scheme.c_str(), static_cast<int>(scheme.length()));
- if (port != url::PORT_UNSPECIFIED && port != default_port)
- result += colon + base::UTF8ToUTF16(origin.port());
-
- return result;
+ return true;
}
} // namespace
@@ -356,12 +329,47 @@ base::string16 ElideHost(const GURL& url,
#endif // !defined(OS_ANDROID)
-base::string16 FormatUrlForSecurityDisplay(const GURL& url) {
- return FormatUrlForSecurityDisplayInternal(url, false);
-}
+base::string16 FormatUrlForSecurityDisplay(const GURL& url,
+ const SchemeDisplay scheme_display) {
+ if (!url.is_valid() || url.is_empty() || !url.IsStandard())
+ return url_formatter::FormatUrl(url);
+
+ const base::string16 colon(base::ASCIIToUTF16(":"));
+ const base::string16 scheme_separator(
+ base::ASCIIToUTF16(url::kStandardSchemeSeparator));
+
+ if (url.SchemeIsFile()) {
+ return base::ASCIIToUTF16(url::kFileScheme) + scheme_separator +
+ base::UTF8ToUTF16(url.path());
+ }
+
+ if (url.SchemeIsFileSystem()) {
+ const GURL* inner_url = url.inner_url();
+ if (inner_url->SchemeIsFile()) {
+ return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
+ FormatUrlForSecurityDisplay(*inner_url) +
+ base::UTF8ToUTF16(url.path());
+ }
+ return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
+ FormatUrlForSecurityDisplay(*inner_url);
+ }
-base::string16 FormatUrlForSecurityDisplayOmitScheme(const GURL& url) {
- return FormatUrlForSecurityDisplayInternal(url, true);
+ const GURL origin = url.GetOrigin();
+ const std::string& scheme = origin.scheme();
+ const std::string& host = origin.host();
+
+ base::string16 result;
+ if (ShouldShowScheme(url, scheme_display))
+ result = base::UTF8ToUTF16(scheme) + scheme_separator;
+ result += base::UTF8ToUTF16(host);
+
+ const int port = origin.IntPort();
+ const int default_port = url::DefaultPortForScheme(
+ scheme.c_str(), static_cast<int>(scheme.length()));
+ if (port != url::PORT_UNSPECIFIED && port != default_port)
+ result += colon + base::UTF8ToUTF16(origin.port());
+
+ return result;
}
} // namespace url_formatter
« no previous file with comments | « components/url_formatter/elide_url.h ('k') | components/url_formatter/elide_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698