Commit af6dd858 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[Android] Move knowledge of IntentHandler out of ExternalNavHandler

This CL moves knowledge of the //chrome-level IntentHandler out of
ExternalNavigationHandler.java. This dependence is to set
//chrome-level extras on the intent (and set state of IntentHandler
itself). We abstract this functionality through
ExternalNavigationDelegate, following the pattern of similar
already-existing delegate methods.

Bug: 1031465
Change-Id: I0301abdcf045dfdada1506cf5f14dd7c98315f86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2087404
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747621}
parent a232eeb7
...@@ -111,6 +111,15 @@ interface ExternalNavigationDelegate { ...@@ -111,6 +111,15 @@ interface ExternalNavigationDelegate {
/** Adds the package name of a specialized intent handler. */ /** Adds the package name of a specialized intent handler. */
void maybeRecordAppHandlersInIntent(Intent intent, List<ResolveInfo> info); void maybeRecordAppHandlersInIntent(Intent intent, List<ResolveInfo> info);
/** Records the pending referrer if desired. */
void maybeSetPendingReferrer(Intent intent, @NonNull String referrerUrl);
/**
* Records the pending incognito URL if desired. Called only if the
* navigation is occurring in the context of incognito mode.
*/
void maybeSetPendingIncognitoUrl(Intent intent);
/** /**
* Determine if the Chrome app is in the foreground. * Determine if the Chrome app is in the foreground.
*/ */
......
...@@ -587,6 +587,16 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat ...@@ -587,6 +587,16 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
getSpecializedHandlersWithFilter(infos, null)); getSpecializedHandlersWithFilter(infos, null));
} }
@Override
public void maybeSetPendingReferrer(Intent intent, String referrerUrl) {
IntentHandler.setPendingReferrer(intent, referrerUrl);
}
@Override
public void maybeSetPendingIncognitoUrl(Intent intent) {
IntentHandler.setPendingIncognitoUrl(intent);
}
@Override @Override
public boolean isSerpReferrer() { public boolean isSerpReferrer() {
// TODO (thildebr): Investigate whether or not we can use getLastCommittedUrl() instead of // TODO (thildebr): Investigate whether or not we can use getLastCommittedUrl() instead of
......
...@@ -26,7 +26,6 @@ import org.chromium.base.IntentUtils; ...@@ -26,7 +26,6 @@ import org.chromium.base.IntentUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.instantapps.InstantAppsHandler; import org.chromium.chrome.browser.instantapps.InstantAppsHandler;
import org.chromium.chrome.browser.tab.TabRedirectHandler; import org.chromium.chrome.browser.tab.TabRedirectHandler;
...@@ -671,10 +670,10 @@ public class ExternalNavigationHandler { ...@@ -671,10 +670,10 @@ public class ExternalNavigationHandler {
mDelegate.maybeRecordAppHandlersInIntent(targetIntent, resolvingInfos); mDelegate.maybeRecordAppHandlersInIntent(targetIntent, resolvingInfos);
if (params.getReferrerUrl() != null) { if (params.getReferrerUrl() != null) {
IntentHandler.setPendingReferrer(targetIntent, params.getReferrerUrl()); mDelegate.maybeSetPendingReferrer(targetIntent, params.getReferrerUrl());
} }
if (params.isIncognito()) IntentHandler.setPendingIncognitoUrl(targetIntent); if (params.isIncognito()) mDelegate.maybeSetPendingIncognitoUrl(targetIntent);
if (shouldProxyForInstantApps) { if (shouldProxyForInstantApps) {
RecordHistogram.recordEnumeratedHistogram("Android.InstantApps.DirectInstantAppsIntent", RecordHistogram.recordEnumeratedHistogram("Android.InstantApps.DirectInstantAppsIntent",
......
...@@ -20,6 +20,7 @@ import org.junit.runner.RunWith; ...@@ -20,6 +20,7 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.instantapps.InstantAppsHandler; import org.chromium.chrome.browser.instantapps.InstantAppsHandler;
...@@ -247,6 +248,42 @@ import java.util.List; ...@@ -247,6 +248,42 @@ import java.util.List;
delegate.isPdfDownload("http://somesampleurldne.com/copy.txt")); delegate.isPdfDownload("http://somesampleurldne.com/copy.txt"));
} }
@Test
@SmallTest
public void testMaybeSetPendingIncognitoUrl() {
ExternalNavigationDelegateImpl delegate = new ExternalNavigationDelegateImpl(
mActivityTestRule.getActivity().getActivityTab());
String url = "http://www.example.com";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
delegate.maybeSetPendingIncognitoUrl(intent);
Assert.assertTrue(
intent.getBooleanExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false));
Assert.assertEquals(url, IntentHandler.getPendingIncognitoUrl());
}
@Test
@SmallTest
public void testMaybeSetPendingReferrer() {
ExternalNavigationDelegateImpl delegate = new ExternalNavigationDelegateImpl(
mActivityTestRule.getActivity().getActivityTab());
String url = "http://www.example.com";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
String referrerUrl = "http://www.example-referrer.com";
delegate.maybeSetPendingReferrer(intent, referrerUrl);
Assert.assertEquals(
Uri.parse(referrerUrl), intent.getParcelableExtra(Intent.EXTRA_REFERRER));
Assert.assertEquals(1, intent.getIntExtra(IntentHandler.EXTRA_REFERRER_ID, 0));
Assert.assertEquals(referrerUrl, IntentHandler.getPendingReferrerUrl(1));
}
@Before @Before
public void setUp() throws InterruptedException { public void setUp() throws InterruptedException {
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
......
...@@ -33,7 +33,6 @@ import org.chromium.base.ContextUtils; ...@@ -33,7 +33,6 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.DisableIf; import org.chromium.base.test.util.DisableIf;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.ShortcutHelper; import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider; import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider;
import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.OverrideUrlLoadingResult; import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.OverrideUrlLoadingResult;
...@@ -1248,8 +1247,6 @@ public class ExternalNavigationHandlerTest { ...@@ -1248,8 +1247,6 @@ public class ExternalNavigationHandlerTest {
START_OTHER_ACTIVITY); START_OTHER_ACTIVITY);
Assert.assertEquals(Uri.parse(referrer), Assert.assertEquals(Uri.parse(referrer),
mDelegate.startActivityIntent.getParcelableExtra(Intent.EXTRA_REFERRER)); mDelegate.startActivityIntent.getParcelableExtra(Intent.EXTRA_REFERRER));
Assert.assertEquals(
1, mDelegate.startActivityIntent.getIntExtra(IntentHandler.EXTRA_REFERRER_ID, 0));
} }
@Test @Test
...@@ -1864,6 +1861,16 @@ public class ExternalNavigationHandlerTest { ...@@ -1864,6 +1861,16 @@ public class ExternalNavigationHandlerTest {
public void maybeRecordAppHandlersInIntent(Intent intent, List<ResolveInfo> info) { public void maybeRecordAppHandlersInIntent(Intent intent, List<ResolveInfo> info) {
} }
@Override
public void maybeSetPendingReferrer(Intent intent, String referrerUrl) {
// This is used in a test to check that ExternalNavigationHandler correctly passes
// this data to the delegate when the referrer URL is non-null.
intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(referrerUrl));
}
@Override
public void maybeSetPendingIncognitoUrl(Intent intent) {}
@Override @Override
public boolean isChromeAppInForeground() { public boolean isChromeAppInForeground() {
return mIsChromeAppInForeground; return mIsChromeAppInForeground;
......
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