Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtils.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtils.java |
| index bfe11ea07f448d7f86bdd86b4d4051ed6020ecd1..79126b46d84cf832d65ebed818837c25dcf548bc 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtils.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtils.java |
| @@ -20,6 +20,9 @@ import org.chromium.content_public.common.ScreenOrientationValues; |
| import org.chromium.webapk.lib.common.WebApkConstants; |
| import org.chromium.webapk.lib.common.WebApkMetaDataKeys; |
| +import java.util.HashMap; |
| +import java.util.Map; |
| + |
| /** |
| * Contains methods for extracting meta data from WebAPK. |
| */ |
| @@ -48,7 +51,7 @@ public class WebApkMetaDataUtils { |
| return WebApkInfo.create(WebApkConstants.WEBAPK_ID_PREFIX + webApkPackageName, url, |
| metaData.scope, encodedIcon, metaData.name, metaData.shortName, |
| metaData.displayMode, metaData.orientation, source, metaData.themeColor, |
| - metaData.backgroundColor, TextUtils.isEmpty(metaData.iconUrl), webApkPackageName); |
| + metaData.backgroundColor, false, webApkPackageName); |
| } |
| /** |
| @@ -84,8 +87,7 @@ public class WebApkMetaDataUtils { |
| metaData.backgroundColor = getLongFromMetaData(bundle, WebApkMetaDataKeys.BACKGROUND_COLOR, |
| ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING); |
| metaData.iconId = IntentUtils.safeGetInt(bundle, WebApkMetaDataKeys.ICON_ID, 0); |
| - metaData.iconUrl = IntentUtils.safeGetString(bundle, WebApkMetaDataKeys.ICON_URL); |
| - metaData.iconMurmur2Hash = getIconMurmur2HashFromMetaData(bundle); |
| + metaData.iconURLAndHashMap = WebApkMetaDataUtils.getIconUrlAndHashMap(bundle); |
| if (TextUtils.isEmpty(metaData.scope)) { |
| metaData.scope = ShortcutHelper.getScopeFromUrl(metaData.startUrl); |
| @@ -120,19 +122,22 @@ public class WebApkMetaDataUtils { |
| } |
| /** |
| - * Extracts icon murmur2 hash from the WebAPK's meta data. Return value is a string because the |
| - * hash can take values up to 2^64-1 which is greater than {@link Long#MAX_VALUE}. |
| - * @param metaData WebAPK meta data to extract the hash from. |
| - * @return The hash. An empty string if the hash could not be extracted. |
| + * Extract the icon URLs and icon hashs from the WebAPK's meta data, and returns a map of these |
|
pkotwicz
2016/11/11 21:04:18
Nit: hashs -> hashes
Xi Han
2016/11/14 19:36:09
Done.
|
| + * {URL, hash} pairs. The icon URLs/icon hashs are stored as a space separated list in a |
| + * single meta data tag in the WebAPK's AndroidManifest.xml respectively. |
|
pkotwicz
2016/11/11 21:04:18
Perhaps it would be better to store this in a sing
Xi Han
2016/11/14 19:36:09
It easy to parse if they are stored in two metadat
pkotwicz
2016/11/14 22:43:10
If we have two lists we cannot remove the last "L"
|
| */ |
| - public static String getIconMurmur2HashFromMetaData(Bundle metaData) { |
| - String value = metaData.getString(WebApkMetaDataKeys.ICON_MURMUR2_HASH); |
| - |
| - // The value should be terminated with 'L' to force the value to be a string. |
| - if (value == null || !value.endsWith("L")) { |
| - return ""; |
| + public static Map<String, String> getIconUrlAndHashMap(Bundle metaData) { |
| + Map<String, String> iconUrlAndHashMap = new HashMap<String, String>(); |
| + String iconUrls = metaData.getString(WebApkMetaDataKeys.ICON_URLS); |
| + String iconHashs = metaData.getString(WebApkMetaDataKeys.ICON_MURMUR2_HASHS); |
|
pkotwicz
2016/11/11 21:04:18
Nit: iconHashs -> iconHashes
Xi Han
2016/11/14 19:36:09
Done.
|
| + if (TextUtils.isEmpty(iconUrls) || TextUtils.isEmpty(iconHashs)) return iconUrlAndHashMap; |
| + |
| + String[] urls = iconUrls.split(WebApkConstants.ICON_URL_SEPARATOR); |
| + String[] hashs = iconHashs.split(WebApkConstants.ICON_URL_SEPARATOR); |
|
pkotwicz
2016/11/11 21:04:18
Nit: hashs -> hashes
Xi Han
2016/11/14 19:36:09
Done.
|
| + for (int i = 0; i < urls.length; i++) { |
| + iconUrlAndHashMap.put(urls[i], murmur2HashFromString(hashs[i])); |
|
pkotwicz
2016/11/11 21:04:19
Won't you run into problems if hashes.length < url
Xi Han
2016/11/14 19:36:09
Talked with Glenn offline before, and he said serv
pkotwicz
2016/11/14 22:43:10
We should not assume that the WebAPK server is bug
|
| } |
| - return value.substring(0, value.length() - 1); |
| + return iconUrlAndHashMap; |
| } |
| /** |
| @@ -189,4 +194,16 @@ public class WebApkMetaDataUtils { |
| return ScreenOrientationValues.DEFAULT; |
| } |
| } |
| + |
| + /** |
| + * Return a string of the hash which can take values up to 2^64-1 which is greater than |
| + * {@link Long#MAX_VALUE}. An empty string if the hash could not be extracted. |
|
pkotwicz
2016/11/11 21:04:18
How about: Extracts the Murmur2 hash from a meta-d
Xi Han
2016/11/14 19:36:09
Done.
|
| + */ |
| + private static String murmur2HashFromString(String value) { |
| + // The value should be terminated with 'L' to force the value to be a string. |
| + if (value == null || !value.endsWith("L")) { |
| + return ""; |
| + } |
| + return value.substring(0, value.length() - 1); |
| + } |
| } |