Commit 314637c0 authored by Bernhard Bauer's avatar Bernhard Bauer Committed by Commit Bot

Show publisher from trusted CDN publisher URL in page info bubble

If the trusted CDN publisher is not available, fall back to parsing the URL.

Bug: 814365
Change-Id: I8c51cf33f015ba251de492d336bdc50cdc6cd822
Reviewed-on: https://chromium-review.googlesource.com/983413Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Bernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547838}
parent 54afd68d
......@@ -180,18 +180,13 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
@Override
public void onNativeLibraryReady() {
super.onNativeLibraryReady();
mSecurityButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mSecurityButton.setOnClickListener(v -> {
Tab currentTab = getToolbarDataProvider().getTab();
if (currentTab == null || currentTab.getWebContents() == null) return;
Activity activity = currentTab.getWindowAndroid().getActivity().get();
if (activity == null) return;
String publisherName = mState == STATE_TITLE_ONLY
? parsePublisherNameFromUrl(currentTab.getUrl()) : null;
PageInfoPopup.show(
activity, currentTab, publisherName, PageInfoPopup.OPENED_FROM_TOOLBAR);
}
activity, currentTab, getContentPublisher(), PageInfoPopup.OPENED_FROM_TOOLBAR);
});
}
......@@ -334,10 +329,15 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
@Override
public String getContentPublisher() {
if (mState == STATE_TITLE_ONLY) {
if (getToolbarDataProvider().getTab() == null) return null;
return parsePublisherNameFromUrl(getToolbarDataProvider().getTab().getUrl());
}
Tab tab = getToolbarDataProvider().getTab();
if (tab == null) return null;
String publisherUrl = tab.getTrustedCdnPublisherUrl();
if (publisherUrl != null) return extractPublisherFromPublisherUrl(publisherUrl);
// TODO(bauerb): Remove this once trusted CDN publisher URLs have rolled out completely.
if (mState == STATE_TITLE_ONLY) return parsePublisherNameFromUrl(tab.getUrl());
return null;
}
......@@ -377,6 +377,11 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
updateSecurityIcon();
}
private static String extractPublisherFromPublisherUrl(String publisherUrl) {
return BidiFormatter.getInstance().unicodeWrap(
UrlFormatter.formatUrlForDisplayOmitScheme(GURLUtils.getOrigin(publisherUrl)));
}
@Override
public void setUrlToPageUrl() {
if (getCurrentTab() == null) {
......@@ -400,10 +405,8 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
}
CharSequence displayText;
if (publisherUrl != null) {
String publisherOrigin =
UrlFormatter.formatUrlForDisplayOmitScheme(GURLUtils.getOrigin(publisherUrl));
String plainDisplayText = getContext().getString(R.string.custom_tab_amp_publisher_url,
BidiFormatter.getInstance().unicodeWrap(publisherOrigin));
extractPublisherFromPublisherUrl(publisherUrl));
ColorStateList tint = mUseDarkColors ? mDarkModeTint : mLightModeTint;
displayText = SpanApplier.applySpans(plainDisplayText,
new SpanInfo("<bg>", "</bg>", new ForegroundColorSpan(tint.getDefaultColor())));
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -36,6 +36,7 @@ import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.test.util.AnnotationRule;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.firstrun.FirstRunStatus;
......@@ -44,6 +45,7 @@ import org.chromium.chrome.browser.test.ScreenShooter;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.content.browser.test.util.TestTouchUtils;
import org.chromium.net.test.util.TestWebServer;
import org.chromium.ui.base.DeviceFormFactor;
......@@ -210,6 +212,21 @@ public class TrustedCdnPublisherUrlTest {
runTrustedCdnPublisherUrlTest(
"https://example.com/test", "com.example.test", null, getDefaultSecurityIcon());
}
@Test
@SmallTest
@Feature({"UiCatalogue"})
@Features.EnableFeatures(ChromeFeatureList.SHOW_TRUSTED_PUBLISHER_URL)
@OverrideTrustedCdn
public void testPageInfo() throws Exception {
runTrustedCdnPublisherUrlTest("https://example.com/test", "com.example.test", "example.com",
R.drawable.omnibox_https_valid);
TestTouchUtils.performClickOnMainSync(InstrumentationRegistry.getInstrumentation(),
mCustomTabActivityTestRule.getActivity().findViewById(R.id.security_button));
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
mScreenShooter.shoot("Page Info");
}
// TODO(bauerb): Test an insecure HTTPS connection.
private void runTrustedCdnPublisherUrlTest(@Nullable String publisherUrl, String clientPackage,
......
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