Commit aca98f1a authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android Webapp] Always navigate as a result of clients#openWindow()

This CL makes webapps always navigate as a result of
clients#openWindow()
In particular:
- The CL moves WebApkConstants#EXTRA_WEBAPK_FORCE_NAVIGATION to
ShortcutHelper
- Sets the extra in ServiceTabLauncher#launchTab() for webapps

BUG=744843
NOPRESUBMIT=true
(Because the version in shell_apk_version.gni does not need to
be incremented because although I renamed
WebApkConstants#EXTRA_WEBAPK_FORCE_NAVIGATION I did not change
its value)

Change-Id: I98465c1f8773a705dc7177792256d901bf9aa6bc
Reviewed-on: https://chromium-review.googlesource.com/575328
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488831}
parent e87d3b9b
...@@ -118,6 +118,7 @@ public class ServiceTabLauncher { ...@@ -118,6 +118,7 @@ public class ServiceTabLauncher {
// webapp's scope, so it is valid. // webapp's scope, so it is valid.
intent.putExtra(ShortcutHelper.EXTRA_URL, url); intent.putExtra(ShortcutHelper.EXTRA_URL, url);
intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION); intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION);
intent.putExtra(ShortcutHelper.EXTRA_FORCE_NAVIGATION, true);
tabDelegate.createNewStandaloneFrame(intent); tabDelegate.createNewStandaloneFrame(intent);
} }
} }
......
...@@ -83,6 +83,10 @@ public class ShortcutHelper { ...@@ -83,6 +83,10 @@ public class ShortcutHelper {
"org.chromium.chrome.browser.webapp_shortcut_version"; "org.chromium.chrome.browser.webapp_shortcut_version";
public static final String REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB = public static final String REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB =
"REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB"; "REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB";
// Whether the webapp should navigate to the URL in {@link EXTRA_URL} if the webapp is already
// open. Applies to webapps and WebAPKs. Value contains "webapk" for backward compatibility.
public static final String EXTRA_FORCE_NAVIGATION =
"org.chromium.chrome.browser.webapk_force_navigation";
// When a new field is added to the intent, this version should be incremented so that it will // When a new field is added to the intent, this version should be incremented so that it will
// be correctly populated into the WebappRegistry/WebappDataStorage. // be correctly populated into the WebappRegistry/WebappDataStorage.
......
...@@ -35,7 +35,6 @@ public class WebApkInfo extends WebappInfo { ...@@ -35,7 +35,6 @@ public class WebApkInfo extends WebappInfo {
private static final String TAG = "WebApkInfo"; private static final String TAG = "WebApkInfo";
private boolean mForceNavigation;
private Icon mBadgeIcon; private Icon mBadgeIcon;
private String mWebApkPackageName; private String mWebApkPackageName;
private int mShellApkVersion; private int mShellApkVersion;
...@@ -63,10 +62,10 @@ public class WebApkInfo extends WebappInfo { ...@@ -63,10 +62,10 @@ public class WebApkInfo extends WebappInfo {
int source = sourceFromIntent(intent); int source = sourceFromIntent(intent);
// Force navigation if the extra is not specified to avoid breaking deep linking for old // Force navigation if the extra is not specified to avoid breaking deep linking for old
// WebAPKs which don't specify the {@link WebApkConstants#EXTRA_WEBAPK_FORCE_NAVIGATION} // WebAPKs which don't specify the {@link ShortcutHelper#EXTRA_FORCE_NAVIGATION} intent
// intent extra. // extra.
boolean forceNavigation = IntentUtils.safeGetBooleanExtra( boolean forceNavigation = IntentUtils.safeGetBooleanExtra(
intent, WebApkConstants.EXTRA_WEBAPK_FORCE_NAVIGATION, true); intent, ShortcutHelper.EXTRA_FORCE_NAVIGATION, true);
return create(webApkPackageName, url, source, forceNavigation); return create(webApkPackageName, url, source, forceNavigation);
} }
...@@ -135,10 +134,11 @@ public class WebApkInfo extends WebappInfo { ...@@ -135,10 +134,11 @@ public class WebApkInfo extends WebappInfo {
int badgeIconId = IntentUtils.safeGetInt(bundle, WebApkMetaDataKeys.BADGE_ICON_ID, 0); int badgeIconId = IntentUtils.safeGetInt(bundle, WebApkMetaDataKeys.BADGE_ICON_ID, 0);
Bitmap badgeIcon = decodeImageResource(res, badgeIconId); Bitmap badgeIcon = decodeImageResource(res, badgeIconId);
return create(WebApkConstants.WEBAPK_ID_PREFIX + webApkPackageName, url, forceNavigation, return create(WebApkConstants.WEBAPK_ID_PREFIX + webApkPackageName, url, scope,
scope, new Icon(primaryIcon), new Icon(badgeIcon), name, shortName, displayMode, new Icon(primaryIcon), new Icon(badgeIcon), name, shortName, displayMode,
orientation, source, themeColor, backgroundColor, webApkPackageName, orientation, source, themeColor, backgroundColor, webApkPackageName,
shellApkVersion, manifestUrl, manifestStartUrl, iconUrlToMurmur2HashMap); shellApkVersion, manifestUrl, manifestStartUrl, iconUrlToMurmur2HashMap,
forceNavigation);
} }
/** /**
...@@ -146,8 +146,6 @@ public class WebApkInfo extends WebappInfo { ...@@ -146,8 +146,6 @@ public class WebApkInfo extends WebappInfo {
* *
* @param id ID for the WebAPK. * @param id ID for the WebAPK.
* @param url URL that the WebAPK should navigate to when launched. * @param url URL that the WebAPK should navigate to when launched.
* @param forceNavigation Whether the WebAPK should navigate to {@link url} if the
* WebAPK is already open.
* @param scope Scope for the WebAPK. * @param scope Scope for the WebAPK.
* @param primaryIcon Primary icon to show for the WebAPK. * @param primaryIcon Primary icon to show for the WebAPK.
* @param badgeIcon Badge icon to use for notifications. * @param badgeIcon Badge icon to use for notifications.
...@@ -166,12 +164,14 @@ public class WebApkInfo extends WebappInfo { ...@@ -166,12 +164,14 @@ public class WebApkInfo extends WebappInfo {
* WebAPK is launched from a deep link. * WebAPK is launched from a deep link.
* @param iconUrlToMurmur2HashMap Map of the WebAPK's icon URLs to Murmur2 hashes of the * @param iconUrlToMurmur2HashMap Map of the WebAPK's icon URLs to Murmur2 hashes of the
* icon untransformed bytes. * icon untransformed bytes.
* @param forceNavigation Whether the WebAPK should navigate to {@link url} if the
* WebAPK is already open.
*/ */
public static WebApkInfo create(String id, String url, boolean forceNavigation, String scope, public static WebApkInfo create(String id, String url, String scope, Icon primaryIcon,
Icon primaryIcon, Icon badgeIcon, String name, String shortName, int displayMode, Icon badgeIcon, String name, String shortName, int displayMode, int orientation,
int orientation, int source, long themeColor, long backgroundColor, int source, long themeColor, long backgroundColor, String webApkPackageName,
String webApkPackageName, int shellApkVersion, String manifestUrl, int shellApkVersion, String manifestUrl, String manifestStartUrl,
String manifestStartUrl, Map<String, String> iconUrlToMurmur2HashMap) { Map<String, String> iconUrlToMurmur2HashMap, boolean forceNavigation) {
if (id == null || url == null || manifestStartUrl == null || webApkPackageName == null) { if (id == null || url == null || manifestStartUrl == null || webApkPackageName == null) {
Log.e(TAG, Log.e(TAG,
"Incomplete data provided: " + id + ", " + url + ", " + manifestStartUrl + ", " "Incomplete data provided: " + id + ", " + url + ", " + manifestStartUrl + ", "
...@@ -186,21 +186,19 @@ public class WebApkInfo extends WebappInfo { ...@@ -186,21 +186,19 @@ public class WebApkInfo extends WebappInfo {
scope = ShortcutHelper.getScopeFromUrl(manifestStartUrl); scope = ShortcutHelper.getScopeFromUrl(manifestStartUrl);
} }
return new WebApkInfo(id, url, forceNavigation, scope, primaryIcon, badgeIcon, name, return new WebApkInfo(id, url, scope, primaryIcon, badgeIcon, name, shortName, displayMode,
shortName, displayMode, orientation, source, themeColor, backgroundColor, orientation, source, themeColor, backgroundColor, webApkPackageName,
webApkPackageName, shellApkVersion, manifestUrl, manifestStartUrl, shellApkVersion, manifestUrl, manifestStartUrl, iconUrlToMurmur2HashMap,
iconUrlToMurmur2HashMap); forceNavigation);
} }
protected WebApkInfo(String id, String url, boolean forceNavigation, String scope, protected WebApkInfo(String id, String url, String scope, Icon primaryIcon, Icon badgeIcon,
Icon primaryIcon, Icon badgeIcon, String name, String shortName, int displayMode, String name, String shortName, int displayMode, int orientation, int source,
int orientation, int source, long themeColor, long backgroundColor, long themeColor, long backgroundColor, String webApkPackageName, int shellApkVersion,
String webApkPackageName, int shellApkVersion, String manifestUrl, String manifestUrl, String manifestStartUrl,
String manifestStartUrl, Map<String, String> iconUrlToMurmur2HashMap) { Map<String, String> iconUrlToMurmur2HashMap, boolean forceNavigation) {
super(id, url, scope, primaryIcon, name, shortName, displayMode, orientation, source, super(id, url, scope, primaryIcon, name, shortName, displayMode, orientation, source,
themeColor, themeColor, backgroundColor, false /* isIconGenerated */, forceNavigation);
backgroundColor, false);
mForceNavigation = forceNavigation;
mBadgeIcon = badgeIcon; mBadgeIcon = badgeIcon;
mWebApkPackageName = webApkPackageName; mWebApkPackageName = webApkPackageName;
mShellApkVersion = shellApkVersion; mShellApkVersion = shellApkVersion;
...@@ -211,11 +209,6 @@ public class WebApkInfo extends WebappInfo { ...@@ -211,11 +209,6 @@ public class WebApkInfo extends WebappInfo {
protected WebApkInfo() {} protected WebApkInfo() {}
@Override
public boolean shouldForceNavigation() {
return mForceNavigation;
}
/** /**
* Returns the badge icon in Bitmap form. * Returns the badge icon in Bitmap form.
*/ */
...@@ -250,7 +243,7 @@ public class WebApkInfo extends WebappInfo { ...@@ -250,7 +243,7 @@ public class WebApkInfo extends WebappInfo {
intent.putExtra(ShortcutHelper.EXTRA_URL, uri().toString()); intent.putExtra(ShortcutHelper.EXTRA_URL, uri().toString());
intent.putExtra(ShortcutHelper.EXTRA_SOURCE, source()); intent.putExtra(ShortcutHelper.EXTRA_SOURCE, source());
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackageName()); intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackageName());
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_FORCE_NAVIGATION, mForceNavigation); intent.putExtra(ShortcutHelper.EXTRA_FORCE_NAVIGATION, shouldForceNavigation());
} }
/** /**
......
...@@ -116,12 +116,11 @@ public class WebApkUpdateDataFetcher extends EmptyTabObserver { ...@@ -116,12 +116,11 @@ public class WebApkUpdateDataFetcher extends EmptyTabObserver {
iconUrlToMurmur2HashMap.put(iconUrl, murmur2Hash); iconUrlToMurmur2HashMap.put(iconUrl, murmur2Hash);
} }
WebApkInfo info = WebApkInfo.create(mOldInfo.id(), mOldInfo.uri().toString(), WebApkInfo info = WebApkInfo.create(mOldInfo.id(), mOldInfo.uri().toString(), scopeUrl,
mOldInfo.shouldForceNavigation(), scopeUrl, new WebApkInfo.Icon(primaryIconBitmap), new WebApkInfo.Icon(primaryIconBitmap), new WebApkInfo.Icon(badgeIconBitmap), name,
new WebApkInfo.Icon(badgeIconBitmap), name, shortName, displayMode, orientation, shortName, displayMode, orientation, mOldInfo.source(), themeColor, backgroundColor,
mOldInfo.source(), themeColor, backgroundColor, mOldInfo.webApkPackageName(), mOldInfo.webApkPackageName(), mOldInfo.shellApkVersion(), mOldInfo.manifestUrl(),
mOldInfo.shellApkVersion(), mOldInfo.manifestUrl(), manifestStartUrl, manifestStartUrl, iconUrlToMurmur2HashMap, mOldInfo.shouldForceNavigation());
iconUrlToMurmur2HashMap);
mObserver.onGotManifestData(info, primaryIconUrl, badgeIconUrl); mObserver.onGotManifestData(info, primaryIconUrl, badgeIconUrl);
} }
......
...@@ -66,6 +66,7 @@ public class WebappInfo { ...@@ -66,6 +66,7 @@ public class WebappInfo {
private long mThemeColor; private long mThemeColor;
private long mBackgroundColor; private long mBackgroundColor;
private boolean mIsIconGenerated; private boolean mIsIconGenerated;
private boolean mForceNavigation;
public static WebappInfo createEmpty() { public static WebappInfo createEmpty() {
return new WebappInfo(); return new WebappInfo();
...@@ -124,12 +125,14 @@ public class WebappInfo { ...@@ -124,12 +125,14 @@ public class WebappInfo {
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING); ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING);
boolean isIconGenerated = IntentUtils.safeGetBooleanExtra(intent, boolean isIconGenerated = IntentUtils.safeGetBooleanExtra(intent,
ShortcutHelper.EXTRA_IS_ICON_GENERATED, false); ShortcutHelper.EXTRA_IS_ICON_GENERATED, false);
boolean forceNavigation = IntentUtils.safeGetBooleanExtra(
intent, ShortcutHelper.EXTRA_FORCE_NAVIGATION, false);
String name = nameFromIntent(intent); String name = nameFromIntent(intent);
String shortName = shortNameFromIntent(intent); String shortName = shortNameFromIntent(intent);
return create(id, url, scope, new Icon(icon), name, shortName, displayMode, return create(id, url, scope, new Icon(icon), name, shortName, displayMode, orientation,
orientation, source, themeColor, backgroundColor, isIconGenerated); source, themeColor, backgroundColor, isIconGenerated, forceNavigation);
} }
/** /**
...@@ -146,22 +149,24 @@ public class WebappInfo { ...@@ -146,22 +149,24 @@ public class WebappInfo {
* @param themeColor The theme color of the webapp. * @param themeColor The theme color of the webapp.
* @param backgroundColor The background color of the webapp. * @param backgroundColor The background color of the webapp.
* @param isIconGenerated Whether the |icon| was generated by Chromium. * @param isIconGenerated Whether the |icon| was generated by Chromium.
* @param forceNavigation Whether the webapp should navigate to {@link url} if the
* webapp is already open.
*/ */
public static WebappInfo create(String id, String url, String scope, Icon icon, String name, public static WebappInfo create(String id, String url, String scope, Icon icon, String name,
String shortName, int displayMode, int orientation, int source, long themeColor, String shortName, int displayMode, int orientation, int source, long themeColor,
long backgroundColor, boolean isIconGenerated) { long backgroundColor, boolean isIconGenerated, boolean forceNavigation) {
if (id == null || url == null) { if (id == null || url == null) {
Log.e(TAG, "Incomplete data provided: " + id + ", " + url); Log.e(TAG, "Incomplete data provided: " + id + ", " + url);
return null; return null;
} }
return new WebappInfo(id, url, scope, icon, name, shortName, displayMode, orientation, return new WebappInfo(id, url, scope, icon, name, shortName, displayMode,
source, themeColor, backgroundColor, isIconGenerated); orientation, source, themeColor, backgroundColor, isIconGenerated, forceNavigation);
} }
protected WebappInfo(String id, String url, String scope, Icon icon, String name, protected WebappInfo(String id, String url, String scope, Icon icon, String name,
String shortName, int displayMode, int orientation, int source, long themeColor, String shortName, int displayMode, int orientation, int source, long themeColor,
long backgroundColor, boolean isIconGenerated) { long backgroundColor, boolean isIconGenerated, boolean forceNavigation) {
Uri uri = Uri.parse(url); Uri uri = Uri.parse(url);
if (TextUtils.isEmpty(scope)) { if (TextUtils.isEmpty(scope)) {
scope = ShortcutHelper.getScopeFromUrl(url); scope = ShortcutHelper.getScopeFromUrl(url);
...@@ -180,6 +185,7 @@ public class WebappInfo { ...@@ -180,6 +185,7 @@ public class WebappInfo {
mThemeColor = themeColor; mThemeColor = themeColor;
mBackgroundColor = backgroundColor; mBackgroundColor = backgroundColor;
mIsIconGenerated = isIconGenerated; mIsIconGenerated = isIconGenerated;
mForceNavigation = forceNavigation;
mIsInitialized = mUri != null; mIsInitialized = mUri != null;
} }
...@@ -203,7 +209,7 @@ public class WebappInfo { ...@@ -203,7 +209,7 @@ public class WebappInfo {
* Chrome receives a ACTION_START_WEBAPP intent. * Chrome receives a ACTION_START_WEBAPP intent.
*/ */
public boolean shouldForceNavigation() { public boolean shouldForceNavigation() {
return false; return mForceNavigation;
} }
public Uri scopeUri() { public Uri scopeUri() {
...@@ -303,6 +309,7 @@ public class WebappInfo { ...@@ -303,6 +309,7 @@ public class WebappInfo {
public void setWebappIntentExtras(Intent intent) { public void setWebappIntentExtras(Intent intent) {
intent.putExtra(ShortcutHelper.EXTRA_ID, id()); intent.putExtra(ShortcutHelper.EXTRA_ID, id());
intent.putExtra(ShortcutHelper.EXTRA_URL, uri().toString()); intent.putExtra(ShortcutHelper.EXTRA_URL, uri().toString());
intent.putExtra(ShortcutHelper.EXTRA_FORCE_NAVIGATION, shouldForceNavigation());
intent.putExtra(ShortcutHelper.EXTRA_SCOPE, scopeUri().toString()); intent.putExtra(ShortcutHelper.EXTRA_SCOPE, scopeUri().toString());
intent.putExtra(ShortcutHelper.EXTRA_ICON, encodedIcon()); intent.putExtra(ShortcutHelper.EXTRA_ICON, encodedIcon());
intent.putExtra(ShortcutHelper.EXTRA_VERSION, ShortcutHelper.WEBAPP_SHORTCUT_VERSION); intent.putExtra(ShortcutHelper.EXTRA_VERSION, ShortcutHelper.WEBAPP_SHORTCUT_VERSION);
......
...@@ -122,9 +122,9 @@ public class WebApkUpdateDataFetcherTest { ...@@ -122,9 +122,9 @@ public class WebApkUpdateDataFetcherTest {
ThreadUtils.runOnUiThread(new Runnable() { ThreadUtils.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
WebApkInfo oldInfo = WebApkInfo.create("", "", false /* forceNavigation */, WebApkInfo oldInfo = WebApkInfo.create("", "", scopeUrl, null, null, null, null, -1,
scopeUrl, null, null, null, null, -1, -1, -1, -1, -1, "random.package", -1, -1, -1, -1, -1, "random.package", -1, manifestUrl, "",
manifestUrl, "", new HashMap<String, String>()); new HashMap<String, String>(), false /* forceNavigation */);
fetcher.start(mTab, oldInfo, observer); fetcher.start(mTab, oldInfo, observer);
} }
}); });
......
...@@ -163,12 +163,12 @@ public class WebApkUpdateManagerTest { ...@@ -163,12 +163,12 @@ public class WebApkUpdateManagerTest {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
WebApkInfo info = WebApkInfo.create(WEBAPK_ID, "", false /* forceNavigation */, WebApkInfo info = WebApkInfo.create(WEBAPK_ID, "", creationData.scope, null, null,
creationData.scope, null, null, creationData.name, creationData.shortName, creationData.name, creationData.shortName, creationData.displayMode,
creationData.displayMode, creationData.orientation, 0, creationData.orientation, 0, creationData.themeColor,
creationData.themeColor, creationData.backgroundColor, "", creationData.backgroundColor, "", WebApkVersion.CURRENT_SHELL_APK_VERSION,
WebApkVersion.CURRENT_SHELL_APK_VERSION, creationData.manifestUrl, creationData.manifestUrl, creationData.startUrl,
creationData.startUrl, creationData.iconUrlToMurmur2HashMap); creationData.iconUrlToMurmur2HashMap, false /* forceNavigation */);
updateManager.updateIfNeeded(mTab, info); updateManager.updateIfNeeded(mTab, info);
} }
}); });
......
...@@ -94,7 +94,8 @@ public class WebappModeTest { ...@@ -94,7 +94,8 @@ public class WebappModeTest {
WebappInfo webappInfo = WebappInfo.create(id, url, null, new WebappInfo.Icon(icon), title, WebappInfo webappInfo = WebappInfo.create(id, url, null, new WebappInfo.Icon(icon), title,
null, WebDisplayMode.STANDALONE, ScreenOrientationValues.PORTRAIT, null, WebDisplayMode.STANDALONE, ScreenOrientationValues.PORTRAIT,
ShortcutSource.UNKNOWN, ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, ShortcutSource.UNKNOWN, ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING,
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false); ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false /* isIconGenerated */,
false /* forceNavigation */);
webappInfo.setWebappIntentExtras(intent); webappInfo.setWebappIntentExtras(intent);
return intent; return intent;
......
...@@ -124,12 +124,12 @@ public class WebappVisibilityTest { ...@@ -124,12 +124,12 @@ public class WebappVisibilityTest {
WebappInfo info; WebappInfo info;
if (type == Type.WEBAPP) { if (type == Type.WEBAPP) {
delegate = new WebappBrowserControlsDelegate(null, new Tab(0, false, null)); delegate = new WebappBrowserControlsDelegate(null, new Tab(0, false, null));
info = WebappInfo.create( info = WebappInfo.create("", webappStartUrlOrScopeUrl, null, null, null, null, 0,
"", webappStartUrlOrScopeUrl, null, null, null, null, 0, 0, 0, 0, 0, false); 0, 0, 0, 0, false /* isIconGenerated */, false /* forceNavigation */);
} else { } else {
delegate = new WebApkBrowserControlsDelegate(null, new Tab(0, false, null)); delegate = new WebApkBrowserControlsDelegate(null, new Tab(0, false, null));
info = WebApkInfo.create("", "", false /* forceNavigation */, webappStartUrlOrScopeUrl, info = WebApkInfo.create("", "", webappStartUrlOrScopeUrl, null, null, null, null, 0, 0,
null, null, null, null, 0, 0, 0, 0, 0, "", 0, null, "", null); 0, 0, 0, "", 0, null, "", null, false /* forceNavigation */);
} }
return delegate.shouldShowBrowserControls(info, url, securityLevel); return delegate.shouldShowBrowserControls(info, url, securityLevel);
} }
......
...@@ -118,7 +118,7 @@ public class WebApkInfoTest { ...@@ -118,7 +118,7 @@ public class WebApkInfoTest {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WEBAPK_PACKAGE_NAME); intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, WEBAPK_PACKAGE_NAME);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_FORCE_NAVIGATION, true); intent.putExtra(ShortcutHelper.EXTRA_FORCE_NAVIGATION, true);
intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL); intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL);
intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION); intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION);
...@@ -256,7 +256,7 @@ public class WebApkInfoTest { ...@@ -256,7 +256,7 @@ public class WebApkInfoTest {
/** /**
* Prior to SHELL_APK_VERSION 2, WebAPKs did not specify * Prior to SHELL_APK_VERSION 2, WebAPKs did not specify
* {@link WebApkConstants.EXTRA_WEBAPK_FORCE_NAVIGATION} in the intent. Test that * {@link ShortcutHelper#EXTRA_FORCE_NAVIGATION} in the intent. Test that
* {@link WebApkInfo#shouldForceNavigation()} defaults to true when the intent extra is not * {@link WebApkInfo#shouldForceNavigation()} defaults to true when the intent extra is not
* specified. * specified.
*/ */
......
...@@ -263,12 +263,13 @@ public class WebApkUpdateManagerTest { ...@@ -263,12 +263,13 @@ public class WebApkUpdateManagerTest {
if (manifestData == null) return null; if (manifestData == null) return null;
final String kPackageName = "org.random.webapk"; final String kPackageName = "org.random.webapk";
return WebApkInfo.create(getWebApkId(kPackageName), "", false /* forceNavigation */, return WebApkInfo.create(getWebApkId(kPackageName), "", manifestData.scopeUrl,
manifestData.scopeUrl, new WebApkInfo.Icon(manifestData.primaryIcon), new WebApkInfo.Icon(manifestData.primaryIcon),
new WebApkInfo.Icon(manifestData.badgeIcon), manifestData.name, new WebApkInfo.Icon(manifestData.badgeIcon), manifestData.name,
manifestData.shortName, manifestData.displayMode, manifestData.orientation, -1, manifestData.shortName, manifestData.displayMode, manifestData.orientation, -1,
manifestData.themeColor, manifestData.backgroundColor, kPackageName, -1, manifestData.themeColor, manifestData.backgroundColor, kPackageName, -1,
WEB_MANIFEST_URL, manifestData.startUrl, manifestData.iconUrlToMurmur2HashMap); WEB_MANIFEST_URL, manifestData.startUrl, manifestData.iconUrlToMurmur2HashMap,
false /* forceNavigation */);
} }
/** /**
......
...@@ -33,7 +33,8 @@ public class WebappInfoTest { ...@@ -33,7 +33,8 @@ public class WebappInfoTest {
WebappInfo info = WebappInfo.create(id, url, null, null, name, shortName, WebappInfo info = WebappInfo.create(id, url, null, null, name, shortName,
WebDisplayMode.STANDALONE, ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN, WebDisplayMode.STANDALONE, ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN,
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING,
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false); ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false /* isIconGenerated */,
false /* forceNavigation */);
Assert.assertNotNull(info); Assert.assertNotNull(info);
} }
...@@ -47,7 +48,8 @@ public class WebappInfoTest { ...@@ -47,7 +48,8 @@ public class WebappInfoTest {
WebappInfo info = WebappInfo.create(id, url, null, null, name, shortName, WebappInfo info = WebappInfo.create(id, url, null, null, name, shortName,
WebDisplayMode.STANDALONE, ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN, WebDisplayMode.STANDALONE, ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN,
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING,
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false); ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false /* isIconGenerated */,
false /* forceNavigation */);
Assert.assertNotNull(info); Assert.assertNotNull(info);
} }
...@@ -130,7 +132,8 @@ public class WebappInfoTest { ...@@ -130,7 +132,8 @@ public class WebappInfoTest {
WebappInfo info = WebappInfo.create(id, url, null, null, name, shortName, WebappInfo info = WebappInfo.create(id, url, null, null, name, shortName,
WebDisplayMode.FULLSCREEN, ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN, WebDisplayMode.FULLSCREEN, ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN,
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING,
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false); ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false /* isIconGenerated */,
false /* forceNavigation */);
Assert.assertEquals(WebDisplayMode.FULLSCREEN, info.displayMode()); Assert.assertEquals(WebDisplayMode.FULLSCREEN, info.displayMode());
Assert.assertEquals(ScreenOrientationValues.DEFAULT, info.orientation()); Assert.assertEquals(ScreenOrientationValues.DEFAULT, info.orientation());
Assert.assertEquals(ShortcutSource.UNKNOWN, info.source()); Assert.assertEquals(ShortcutSource.UNKNOWN, info.source());
...@@ -145,9 +148,10 @@ public class WebappInfoTest { ...@@ -145,9 +148,10 @@ public class WebappInfoTest {
long themeColor = 0xFF00FF00L; long themeColor = 0xFF00FF00L;
long backgroundColor = 0xFF0000FFL; long backgroundColor = 0xFF0000FFL;
WebappInfo info = WebappInfo.create(id, url, null, null, name, shortName, WebappInfo info =
WebDisplayMode.STANDALONE, ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN, WebappInfo.create(id, url, null, null, name, shortName, WebDisplayMode.STANDALONE,
themeColor, backgroundColor, false); ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN, themeColor,
backgroundColor, false /* isIconGenerated */, false /* forceNavigation */);
Assert.assertEquals(themeColor, info.themeColor()); Assert.assertEquals(themeColor, info.themeColor());
Assert.assertEquals(backgroundColor, info.backgroundColor()); Assert.assertEquals(backgroundColor, info.backgroundColor());
} }
...@@ -162,7 +166,8 @@ public class WebappInfoTest { ...@@ -162,7 +166,8 @@ public class WebappInfoTest {
WebappInfo info = WebappInfo.create(id, url, null, null, name, shortName, WebappInfo info = WebappInfo.create(id, url, null, null, name, shortName,
WebDisplayMode.STANDALONE, ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN, WebDisplayMode.STANDALONE, ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN,
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING,
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false); ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false /* isIconGenerated */,
false /* forceNavigation */);
Assert.assertEquals(ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, info.themeColor()); Assert.assertEquals(ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, info.themeColor());
Assert.assertEquals( Assert.assertEquals(
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, info.backgroundColor()); ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, info.backgroundColor());
...@@ -271,6 +276,18 @@ public class WebappInfoTest { ...@@ -271,6 +276,18 @@ public class WebappInfoTest {
} }
} }
/**
* Test that {@link WebappInfo#shouldForceNavigation()} defaults to false when the
* {@link ShortcutHelper#EXTRA_FORCE_NAVIGATION} intent extra is not specified.
*/
@Test
public void testForceNavigationNotSpecified() {
Intent intent = new Intent();
intent.putExtra(ShortcutHelper.EXTRA_ID, "webapp_id");
intent.putExtra(ShortcutHelper.EXTRA_URL, "about:blank");
Assert.assertFalse(WebappInfo.create(intent).shouldForceNavigation());
}
/** /**
* Creates intent with url and id. If the url or id are not set WebappInfo#create() returns * Creates intent with url and id. If the url or id are not set WebappInfo#create() returns
* null. * null.
......
...@@ -32,7 +32,7 @@ public class WebApkNavigationClient { ...@@ -32,7 +32,7 @@ public class WebApkNavigationClient {
intent.setPackage(webApkPackageName); intent.setPackage(webApkPackageName);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_FORCE_NAVIGATION, forceNavigation); intent.putExtra(WebApkConstants.EXTRA_FORCE_NAVIGATION, forceNavigation);
return intent; return intent;
} }
} }
...@@ -19,9 +19,7 @@ public final class WebApkConstants { ...@@ -19,9 +19,7 @@ public final class WebApkConstants {
public static final String EXTRA_SOURCE = "org.chromium.chrome.browser.webapp_source"; public static final String EXTRA_SOURCE = "org.chromium.chrome.browser.webapp_source";
public static final String EXTRA_WEBAPK_PACKAGE_NAME = public static final String EXTRA_WEBAPK_PACKAGE_NAME =
"org.chromium.chrome.browser.webapk_package_name"; "org.chromium.chrome.browser.webapk_package_name";
// Whether the WebAPK should navigate to the URL in {@link EXTRA_URL} if the WebAPK is already public static final String EXTRA_FORCE_NAVIGATION =
// open.
public static final String EXTRA_WEBAPK_FORCE_NAVIGATION =
"org.chromium.chrome.browser.webapk_force_navigation"; "org.chromium.chrome.browser.webapk_force_navigation";
public static final String DEFAULT_HOST_BROWSER = "com.android.chrome"; public static final String DEFAULT_HOST_BROWSER = "com.android.chrome";
......
...@@ -156,8 +156,8 @@ public class MainActivity extends Activity { ...@@ -156,8 +156,8 @@ public class MainActivity extends Activity {
if (source == WebApkConstants.SHORTCUT_SOURCE_UNKNOWN) { if (source == WebApkConstants.SHORTCUT_SOURCE_UNKNOWN) {
source = WebApkConstants.SHORTCUT_SOURCE_EXTERNAL_INTENT; source = WebApkConstants.SHORTCUT_SOURCE_EXTERNAL_INTENT;
} }
forceNavigation = getIntent().getBooleanExtra( forceNavigation =
WebApkConstants.EXTRA_WEBAPK_FORCE_NAVIGATION, true); getIntent().getBooleanExtra(WebApkConstants.EXTRA_FORCE_NAVIGATION, true);
} }
// The override URL is non null when the WebAPK is launched from a deep link. The WebAPK // The override URL is non null when the WebAPK is launched from a deep link. The WebAPK
...@@ -168,7 +168,7 @@ public class MainActivity extends Activity { ...@@ -168,7 +168,7 @@ public class MainActivity extends Activity {
intent.putExtra(WebApkConstants.EXTRA_URL, mStartUrl) intent.putExtra(WebApkConstants.EXTRA_URL, mStartUrl)
.putExtra(WebApkConstants.EXTRA_SOURCE, source) .putExtra(WebApkConstants.EXTRA_SOURCE, source)
.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, getPackageName()) .putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, getPackageName())
.putExtra(WebApkConstants.EXTRA_WEBAPK_FORCE_NAVIGATION, forceNavigation); .putExtra(WebApkConstants.EXTRA_FORCE_NAVIGATION, forceNavigation);
try { try {
startActivity(intent); startActivity(intent);
......
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