Commit cf064891 authored by pkotwicz's avatar pkotwicz Committed by Commit bot

[WebAPKs] Compute the default scope from the manifest start URL.

This CL changes how the scope is computed if the scope is unspecified in the
Android Manifest.
We used to compute the default scope based on the "URL the WebAPK navigates to
when launched." Deep links can open a WebAPK at an arbirtrary URL.
This CL changes the computation to be based on the Web Manifest start URL.

This change enables cleaning up
ManifestUpgradeDetectorFetcher#onDataAvailable(). We can now create the fetched
WebApkInfo using the current WebAPK's WebApkInfo#uri().

BUG=639536

Review-Url: https://codereview.chromium.org/2548333006
Cr-Commit-Position: refs/heads/master@{#437785}
parent 9b0866fd
...@@ -122,11 +122,20 @@ public class WebApkInfo extends WebappInfo { ...@@ -122,11 +122,20 @@ public class WebApkInfo extends WebappInfo {
String shortName, int displayMode, int orientation, int source, long themeColor, String shortName, int displayMode, int orientation, int source, long themeColor,
long backgroundColor, String webApkPackageName, int shellApkVersion, String manifestUrl, long backgroundColor, String webApkPackageName, int shellApkVersion, String manifestUrl,
String manifestStartUrl, Map<String, String> iconUrlToMurmur2HashMap) { String manifestStartUrl, Map<String, String> iconUrlToMurmur2HashMap) {
if (id == null || url == null || webApkPackageName == null) { if (id == null || url == null || manifestStartUrl == null || webApkPackageName == null) {
Log.e(TAG, "Incomplete data provided: " + id + ", " + url + ", " + webApkPackageName); Log.e(TAG,
"Incomplete data provided: " + id + ", " + url + ", " + manifestStartUrl + ", "
+ webApkPackageName);
return null; return null;
} }
// The default scope should be computed from the Web Manifest start URL. If the WebAPK was
// launched from a deep link {@link startUrl} may be different from the Web Manifest start
// URL.
if (TextUtils.isEmpty(scope)) {
scope = ShortcutHelper.getScopeFromUrl(manifestStartUrl);
}
return new WebApkInfo(id, url, scope, icon, name, shortName, displayMode, return new WebApkInfo(id, url, scope, icon, name, shortName, displayMode,
orientation, source, themeColor, backgroundColor, webApkPackageName, orientation, source, themeColor, backgroundColor, webApkPackageName,
shellApkVersion, manifestUrl, manifestStartUrl, iconUrlToMurmur2HashMap); shellApkVersion, manifestUrl, manifestStartUrl, iconUrlToMurmur2HashMap);
......
...@@ -103,8 +103,8 @@ public class WebApkUpdateDataFetcher extends EmptyTabObserver { ...@@ -103,8 +103,8 @@ public class WebApkUpdateDataFetcher extends EmptyTabObserver {
* Called when the updated Web Manifest has been fetched. * Called when the updated Web Manifest has been fetched.
*/ */
@CalledByNative @CalledByNative
protected void onDataAvailable(String startUrl, String scopeUrl, String name, String shortName, protected void onDataAvailable(String manifestStartUrl, String scopeUrl, String name,
String bestIconUrl, String bestIconMurmur2Hash, Bitmap bestIconBitmap, String shortName, String bestIconUrl, String bestIconMurmur2Hash, Bitmap bestIconBitmap,
String[] iconUrls, int displayMode, int orientation, long themeColor, String[] iconUrls, int displayMode, int orientation, long themeColor,
long backgroundColor) { long backgroundColor) {
HashMap<String, String> iconUrlToMurmur2HashMap = new HashMap<String, String>(); HashMap<String, String> iconUrlToMurmur2HashMap = new HashMap<String, String>();
...@@ -113,10 +113,10 @@ public class WebApkUpdateDataFetcher extends EmptyTabObserver { ...@@ -113,10 +113,10 @@ public class WebApkUpdateDataFetcher extends EmptyTabObserver {
iconUrlToMurmur2HashMap.put(iconUrl, murmur2Hash); iconUrlToMurmur2HashMap.put(iconUrl, murmur2Hash);
} }
WebApkInfo info = WebApkInfo.create(mOldInfo.id(), startUrl, scopeUrl, WebApkInfo info = WebApkInfo.create(mOldInfo.id(), mOldInfo.uri().toString(), scopeUrl,
new WebApkInfo.Icon(bestIconBitmap), name, shortName, displayMode, orientation, new WebApkInfo.Icon(bestIconBitmap), name, shortName, displayMode, orientation,
mOldInfo.source(), themeColor, backgroundColor, mOldInfo.webApkPackageName(), mOldInfo.source(), themeColor, backgroundColor, mOldInfo.webApkPackageName(),
mOldInfo.shellApkVersion(), mOldInfo.manifestUrl(), startUrl, mOldInfo.shellApkVersion(), mOldInfo.manifestUrl(), manifestStartUrl,
iconUrlToMurmur2HashMap); iconUrlToMurmur2HashMap);
mObserver.onGotManifestData(info, bestIconUrl); mObserver.onGotManifestData(info, bestIconUrl);
} }
......
...@@ -107,7 +107,7 @@ public class WebApkUpdateDataFetcherTest extends ChromeTabbedActivityTestBase { ...@@ -107,7 +107,7 @@ public class WebApkUpdateDataFetcherTest extends ChromeTabbedActivityTestBase {
@Override @Override
public void run() { public void run() {
WebApkInfo oldInfo = WebApkInfo.create("", "", scopeUrl, null, null, null, -1, -1, WebApkInfo oldInfo = WebApkInfo.create("", "", scopeUrl, null, null, null, -1, -1,
-1, -1, -1, "random.package", -1, manifestUrl, null, -1, -1, -1, "random.package", -1, manifestUrl, "",
new HashMap<String, String>()); new HashMap<String, String>());
fetcher.start(mTab, oldInfo, observer); fetcher.start(mTab, oldInfo, observer);
} }
......
...@@ -128,6 +128,34 @@ public class WebApkInfoTest { ...@@ -128,6 +128,34 @@ public class WebApkInfoTest {
Assert.assertEquals(START_URL, info.manifestStartUrl()); Assert.assertEquals(START_URL, info.manifestStartUrl());
} }
/**
* Test that if the scope is empty that the scope is computed from the "start URL specified from
* the Web Manifest" not the "URL the WebAPK initially navigated to". Deep links can open a
* WebAPK at an arbitrary URL.
*/
@Test
public void testDefaultScopeFromManifestStartUrl() {
String manifestStartUrl = START_URL;
String intentStartUrl = "https://www.google.com/a/b/c";
String scopeFromManifestStartUrl = ShortcutHelper.getScopeFromUrl(manifestStartUrl);
String scopeFromIntentStartUrl = ShortcutHelper.getScopeFromUrl(intentStartUrl);
Assert.assertNotEquals(scopeFromManifestStartUrl, scopeFromIntentStartUrl);
Bundle bundle = new Bundle();
bundle.putString(WebApkMetaDataKeys.START_URL, manifestStartUrl);
bundle.putString(WebApkMetaDataKeys.SCOPE, "");
WebApkTestHelper.registerWebApkWithMetaData(bundle);
Intent intent = new Intent();
intent.putExtra(
ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAPK_PACKAGE_NAME);
intent.putExtra(ShortcutHelper.EXTRA_URL, intentStartUrl);
WebApkInfo info = WebApkInfo.create(intent);
Assert.assertEquals(scopeFromManifestStartUrl, info.scopeUri().toString());
}
/** /**
* Test that {@link WebApkInfo#create} can read multiple icon URLs and multiple icon murmur2 * Test that {@link WebApkInfo#create} can read multiple icon URLs and multiple icon murmur2
* hashes from the WebAPK's meta data. * hashes from the WebAPK's meta data.
...@@ -140,6 +168,7 @@ public class WebApkInfoTest { ...@@ -140,6 +168,7 @@ public class WebApkInfoTest {
String murmur2Hash2 = "2"; String murmur2Hash2 = "2";
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(WebApkMetaDataKeys.START_URL, START_URL);
bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES,
iconUrl1 + " " + murmur2Hash1 + " " + iconUrl2 + " " + murmur2Hash2); iconUrl1 + " " + murmur2Hash1 + " " + iconUrl2 + " " + murmur2Hash2);
WebApkTestHelper.registerWebApkWithMetaData(bundle); WebApkTestHelper.registerWebApkWithMetaData(bundle);
...@@ -165,6 +194,7 @@ public class WebApkInfoTest { ...@@ -165,6 +194,7 @@ public class WebApkInfoTest {
String hash = "18446744073709551615"; // 2^64 - 1 String hash = "18446744073709551615"; // 2^64 - 1
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(WebApkMetaDataKeys.START_URL, START_URL);
bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, "randomUrl " + hash); bundle.putString(WebApkMetaDataKeys.ICON_URLS_AND_ICON_MURMUR2_HASHES, "randomUrl " + hash);
WebApkTestHelper.registerWebApkWithMetaData(bundle); WebApkTestHelper.registerWebApkWithMetaData(bundle);
Intent intent = new Intent(); Intent intent = new 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