Commit e0c07108 authored by Bernhard Bauer's avatar Bernhard Bauer Committed by Commit Bot

Trim prefixes from publisher hostname in custom tabs.

Bug: 814365
Change-Id: I34a05ddbf20c74efeffc2c1081cbc79ed60b49db
Reviewed-on: https://chromium-review.googlesource.com/1005034Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Commit-Queue: Bernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549891}
parent b03e67a5
......@@ -69,6 +69,7 @@ import org.chromium.ui.text.SpanApplier.SpanInfo;
import org.chromium.ui.widget.Toast;
import java.util.List;
import java.util.regex.Pattern;
/**
* The Toolbar layout to be used for a custom tab. This is used for both phone and tablet UIs.
......@@ -115,6 +116,10 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
private static final int STATE_TITLE_ONLY = 1;
private static final int STATE_DOMAIN_AND_TITLE = 2;
/** Regular expression for prefixes to strip from publisher hostnames. */
private static final Pattern HOSTNAME_PREFIX_PATTERN =
Pattern.compile("^(www[0-9]*|web|ftp|wap|home|mobile|amp)\\.");
private View mLocationBarFrameLayout;
private View mTitleUrlContainer;
private UrlBar mUrlBar;
......@@ -382,9 +387,13 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
updateSecurityIcon();
}
private static String extractPublisherFromPublisherUrl(String publisherUrl) {
return BidiFormatter.getInstance().unicodeWrap(
UrlFormatter.formatUrlForDisplayOmitScheme(GURLUtils.getOrigin(publisherUrl)));
@VisibleForTesting
public static String extractPublisherFromPublisherUrl(String publisherUrl) {
String publisher =
UrlFormatter.formatUrlForDisplayOmitScheme(GURLUtils.getOrigin(publisherUrl));
String trimmedPublisher = HOSTNAME_PREFIX_PATTERN.matcher(publisher).replaceFirst("");
return BidiFormatter.getInstance().unicodeWrap(trimmedPublisher);
}
@Override
......
......@@ -130,8 +130,8 @@ public class TrustedCdnPublisherUrlTest {
@Features.EnableFeatures(ChromeFeatureList.SHOW_TRUSTED_PUBLISHER_URL)
@OverrideTrustedCdn
public void testHttps() throws Exception {
runTrustedCdnPublisherUrlTest("https://example.com/test", "com.example.test", "example.com",
org.chromium.chrome.R.drawable.omnibox_https_valid);
runTrustedCdnPublisherUrlTest("https://www.example.com/test", "com.example.test",
"example.com", org.chromium.chrome.R.drawable.omnibox_https_valid);
mScreenShooter.shoot("trustedPublisherUrlHttps");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment