Commit 3cbea12a authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[Android] Abstract ExternalNavHandler setting of user gesture in intent

ExternalNavigationHandler currently directly calls into
IntentWithGesturesHandler when launching an external intent with a user
gesture to record that fact in case the intent ends up coming back into
Chrome. This is //chrome-level behavior, as it is relevant only in the
case where the app handles incoming intents. In addition,
IntentWithGesturesHandler would not be straightforword to componentize.

This CL abstracts this dependence through ExternalNavigationDelegate,
similar to how we have done for other such dependences.

Bug: 1031465
Change-Id: I2138400f7a62d1911073b1fd7b31ef484e7fbc17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095130
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749191}
parent 47a1665c
......@@ -121,6 +121,9 @@ interface ExternalNavigationDelegate {
*/
void maybeAdjustInstantAppExtras(Intent intent, boolean isIntentToInstantApp);
/** Invoked for intents with user gestures and records the user gesture if desired. */
void maybeSetUserGesture(Intent intent);
/**
* Records the pending incognito URL if desired. Called only if the
* navigation is occurring in the context of incognito mode.
......
......@@ -598,6 +598,13 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
}
}
@Override
public void maybeSetUserGesture(Intent intent) {
// The intent can be used to launch Chrome itself, record the user
// gesture here so that it can be used later.
IntentWithGesturesHandler.getInstance().onNewIntentWithGesture(intent);
}
@Override
public void maybeSetPendingReferrer(Intent intent, String referrerUrl) {
IntentHandler.setPendingReferrer(intent, referrerUrl);
......
......@@ -687,11 +687,7 @@ public class ExternalNavigationHandler {
AiaIntent.SERP, AiaIntent.NUM_ENTRIES);
}
// The intent can be used to launch Chrome itself, record the user
// gesture here so that it can be used later.
if (params.hasUserGesture()) {
IntentWithGesturesHandler.getInstance().onNewIntentWithGesture(targetIntent);
}
if (params.hasUserGesture()) mDelegate.maybeSetUserGesture(targetIntent);
}
private @OverrideUrlLoadingResult int handleExternalIncognitoIntent(Intent targetIntent,
......
......@@ -334,6 +334,20 @@ import java.util.List;
Assert.assertFalse(intent.hasExtra(InstantAppsHandler.IS_GOOGLE_SEARCH_REFERRER));
}
@Test
@SmallTest
public void testMaybeSetUserGesture() {
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.maybeSetUserGesture(intent);
Assert.assertTrue(IntentWithGesturesHandler.getInstance().getUserGestureAndClear(intent));
}
@Test
@SmallTest
public void testMaybeSetPendingReferrer() {
......
......@@ -1548,8 +1548,7 @@ public class ExternalNavigationHandlerTest {
.withHasUserGesture(true)
.expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT,
START_OTHER_ACTIVITY);
Assert.assertTrue(IntentWithGesturesHandler.getInstance().getUserGestureAndClear(
mDelegate.startActivityIntent));
Assert.assertTrue(mDelegate.maybeSetUserGestureCalled);
Assert.assertFalse(mDelegate.startIncognitoIntentCalled);
}
......@@ -1565,8 +1564,7 @@ public class ExternalNavigationHandlerTest {
.withIsIncognito(true)
.expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_ASYNC_ACTION,
START_INCOGNITO | START_OTHER_ACTIVITY);
Assert.assertTrue(IntentWithGesturesHandler.getInstance().getUserGestureAndClear(
mDelegate.startActivityIntent));
Assert.assertTrue(mDelegate.maybeSetUserGestureCalled);
Assert.assertTrue(mDelegate.startIncognitoIntentCalled);
}
......@@ -1866,6 +1864,11 @@ public class ExternalNavigationHandlerTest {
}
}
@Override
public void maybeSetUserGesture(Intent intent) {
maybeSetUserGestureCalled = true;
}
@Override
public void maybeSetPendingIncognitoUrl(Intent intent) {}
......@@ -1991,6 +1994,7 @@ public class ExternalNavigationHandlerTest {
public Intent startActivityIntent;
public boolean startIncognitoIntentCalled;
public boolean maybeSetUserGestureCalled;
public boolean startFileIntentCalled;
public String defaultSmsPackageName;
......
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