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, ...@@ -180,18 +180,13 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
@Override @Override
public void onNativeLibraryReady() { public void onNativeLibraryReady() {
super.onNativeLibraryReady(); super.onNativeLibraryReady();
mSecurityButton.setOnClickListener(new OnClickListener() { mSecurityButton.setOnClickListener(v -> {
@Override Tab currentTab = getToolbarDataProvider().getTab();
public void onClick(View v) { if (currentTab == null || currentTab.getWebContents() == null) return;
Tab currentTab = getToolbarDataProvider().getTab(); Activity activity = currentTab.getWindowAndroid().getActivity().get();
if (currentTab == null || currentTab.getWebContents() == null) return; if (activity == null) return;
Activity activity = currentTab.getWindowAndroid().getActivity().get(); PageInfoPopup.show(
if (activity == null) return; activity, currentTab, getContentPublisher(), PageInfoPopup.OPENED_FROM_TOOLBAR);
String publisherName = mState == STATE_TITLE_ONLY
? parsePublisherNameFromUrl(currentTab.getUrl()) : null;
PageInfoPopup.show(
activity, currentTab, publisherName, PageInfoPopup.OPENED_FROM_TOOLBAR);
}
}); });
} }
...@@ -334,10 +329,15 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar, ...@@ -334,10 +329,15 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
@Override @Override
public String getContentPublisher() { public String getContentPublisher() {
if (mState == STATE_TITLE_ONLY) { Tab tab = getToolbarDataProvider().getTab();
if (getToolbarDataProvider().getTab() == null) return null; if (tab == null) return null;
return parsePublisherNameFromUrl(getToolbarDataProvider().getTab().getUrl());
} 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; return null;
} }
...@@ -377,6 +377,11 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar, ...@@ -377,6 +377,11 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
updateSecurityIcon(); updateSecurityIcon();
} }
private static String extractPublisherFromPublisherUrl(String publisherUrl) {
return BidiFormatter.getInstance().unicodeWrap(
UrlFormatter.formatUrlForDisplayOmitScheme(GURLUtils.getOrigin(publisherUrl)));
}
@Override @Override
public void setUrlToPageUrl() { public void setUrlToPageUrl() {
if (getCurrentTab() == null) { if (getCurrentTab() == null) {
...@@ -400,10 +405,8 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar, ...@@ -400,10 +405,8 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
} }
CharSequence displayText; CharSequence displayText;
if (publisherUrl != null) { if (publisherUrl != null) {
String publisherOrigin =
UrlFormatter.formatUrlForDisplayOmitScheme(GURLUtils.getOrigin(publisherUrl));
String plainDisplayText = getContext().getString(R.string.custom_tab_amp_publisher_url, String plainDisplayText = getContext().getString(R.string.custom_tab_amp_publisher_url,
BidiFormatter.getInstance().unicodeWrap(publisherOrigin)); extractPublisherFromPublisherUrl(publisherUrl));
ColorStateList tint = mUseDarkColors ? mDarkModeTint : mLightModeTint; ColorStateList tint = mUseDarkColors ? mDarkModeTint : mLightModeTint;
displayText = SpanApplier.applySpans(plainDisplayText, displayText = SpanApplier.applySpans(plainDisplayText,
new SpanInfo("<bg>", "</bg>", new ForegroundColorSpan(tint.getDefaultColor()))); 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -36,6 +36,7 @@ import org.chromium.base.library_loader.LibraryProcessType; ...@@ -36,6 +36,7 @@ import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.test.util.AnnotationRule; import org.chromium.base.test.util.AnnotationRule;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.firstrun.FirstRunStatus; import org.chromium.chrome.browser.firstrun.FirstRunStatus;
...@@ -44,6 +45,7 @@ import org.chromium.chrome.browser.test.ScreenShooter; ...@@ -44,6 +45,7 @@ import org.chromium.chrome.browser.test.ScreenShooter;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.components.url_formatter.UrlFormatter; 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.net.test.util.TestWebServer;
import org.chromium.ui.base.DeviceFormFactor; import org.chromium.ui.base.DeviceFormFactor;
...@@ -210,6 +212,21 @@ public class TrustedCdnPublisherUrlTest { ...@@ -210,6 +212,21 @@ public class TrustedCdnPublisherUrlTest {
runTrustedCdnPublisherUrlTest( runTrustedCdnPublisherUrlTest(
"https://example.com/test", "com.example.test", null, getDefaultSecurityIcon()); "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. // TODO(bauerb): Test an insecure HTTPS connection.
private void runTrustedCdnPublisherUrlTest(@Nullable String publisherUrl, String clientPackage, 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