Commit 6e9271bf authored by Lijin Shen's avatar Lijin Shen Committed by Commit Bot

Add a param for default browser promo to allow promo with url launching

1. Remove intent data if this intent is sent out by default browser
promo utils to prevent from launching a new tab.
2. Promo with different category and action if url is provided.

Bug: 1090103
Change-Id: Icd982617d637f812511eb3872a005076f9882df5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2295207
Commit-Queue: Lijin Shen <lazzzis@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788186}
parent 99d4e504
...@@ -862,6 +862,7 @@ public class ChromeTabbedActivity extends ChromeActivity<ChromeActivityComponent ...@@ -862,6 +862,7 @@ public class ChromeTabbedActivity extends ChromeActivity<ChromeActivityComponent
return; return;
} }
DefaultBrowserPromoUtils.maybeRemoveIntentData(intent);
mIntentHandlingTimeMs = SystemClock.uptimeMillis(); mIntentHandlingTimeMs = SystemClock.uptimeMillis();
super.onNewIntent(intent); super.onNewIntent(intent);
} }
......
...@@ -9,6 +9,7 @@ import android.app.Activity; ...@@ -9,6 +9,7 @@ import android.app.Activity;
import android.app.role.RoleManager; import android.app.role.RoleManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.provider.Settings; import android.provider.Settings;
...@@ -32,6 +33,7 @@ import org.chromium.ui.base.WindowAndroid; ...@@ -32,6 +33,7 @@ import org.chromium.ui.base.WindowAndroid;
public class DefaultBrowserPromoManager implements PauseResumeWithNativeObserver, Destroyable { public class DefaultBrowserPromoManager implements PauseResumeWithNativeObserver, Destroyable {
private static final String SKIP_PRIMER_PARAM = "skip_primer"; private static final String SKIP_PRIMER_PARAM = "skip_primer";
private static final String DISABLE_DISAMBIGUATION_SHEET = "disable_disambiguation_sheet"; private static final String DISABLE_DISAMBIGUATION_SHEET = "disable_disambiguation_sheet";
private static final String DISAMBIGUATION_PROMO_URL = "disambiguation_promo_url";
private final Activity mActivity; private final Activity mActivity;
private DefaultBrowserPromoDialog mDialog; private DefaultBrowserPromoDialog mDialog;
...@@ -145,8 +147,17 @@ public class DefaultBrowserPromoManager implements PauseResumeWithNativeObserver ...@@ -145,8 +147,17 @@ public class DefaultBrowserPromoManager implements PauseResumeWithNativeObserver
DefaultBrowserPromoMetrics.recordUiDismissalReason( DefaultBrowserPromoMetrics.recordUiDismissalReason(
mCurrentState, UIDismissalReason.CHANGE_DEFAULT); mCurrentState, UIDismissalReason.CHANGE_DEFAULT);
Intent intent = new Intent(Intent.ACTION_MAIN); Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_APP_BROWSER); String url = ChromeFeatureList.getFieldTrialParamByFeature(
ChromeFeatureList.ANDROID_DEFAULT_BROWSER_PROMO, DISAMBIGUATION_PROMO_URL);
if (url != null && !url.isEmpty()) {
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(url));
} else {
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_BROWSER);
}
intent.putExtra(DefaultBrowserPromoUtils.DISAMBIGUATION_SHEET_PROMOED_KEY, true); intent.putExtra(DefaultBrowserPromoUtils.DISAMBIGUATION_SHEET_PROMOED_KEY, true);
mActivity.startActivity(intent); mActivity.startActivity(intent);
}); });
......
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.ui.default_browser_promo; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.ui.default_browser_promo;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
...@@ -192,6 +193,17 @@ public class DefaultBrowserPromoUtils { ...@@ -192,6 +193,17 @@ public class DefaultBrowserPromoUtils {
} }
} }
/**
* Remove intent data if this intent is triggered by default browser promo; Otherwise,
* chrome will open a new tab.
*/
public static void maybeRemoveIntentData(Intent intent) {
if (intent.getBooleanExtra(DISAMBIGUATION_SHEET_PROMOED_KEY, false)) {
// Intent with Uri.EMPTY as data will be ignored by the IntentHandler.
intent.setData(Uri.EMPTY);
}
}
@VisibleForTesting @VisibleForTesting
static boolean isChromePreStableInstalled() { static boolean isChromePreStableInstalled() {
for (ResolveInfo info : PackageManagerUtils.queryAllWebBrowsersInfo()) { for (ResolveInfo info : PackageManagerUtils.queryAllWebBrowsersInfo()) {
......
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