Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java |
index 29cb18fcc650fafd93f2b9bed62fcd7ea80a5f94..2fe49c1c6500383487f4b6a650657234f6de3f7c 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java |
@@ -18,7 +18,9 @@ import org.chromium.chrome.browser.ShortcutSource; |
import org.chromium.chrome.browser.util.IntentUtils; |
import org.chromium.content_public.common.ScreenOrientationValues; |
+import java.util.Collections; |
import java.util.Map; |
+import java.util.Set; |
import java.util.concurrent.TimeUnit; |
/** |
@@ -45,6 +47,7 @@ public class WebappDataStorage { |
static final String KEY_IS_ICON_GENERATED = "is_icon_generated"; |
static final String KEY_VERSION = "version"; |
static final String KEY_WEBAPK_PACKAGE_NAME = "webapk_package_name"; |
+ static final String KEY_ICON_URLS = "icon_urls"; |
// Unset/invalid constants for last used times and URLs. 0 is used as the null last |
// used time as WebappRegistry assumes that this is always a valid timestamp. |
@@ -284,6 +287,10 @@ public class WebappDataStorage { |
* @param shortcutIntent The intent to pull web app data from. |
*/ |
public void updateFromShortcutIntent(Intent shortcutIntent) { |
+ updateFromShortcutIntent(shortcutIntent, false); |
+ } |
+ |
+ public void updateFromShortcutIntent(Intent shortcutIntent, boolean bypassVersionCheck) { |
if (shortcutIntent == null) return; |
SharedPreferences.Editor editor = mPreferences.edit(); |
@@ -313,7 +320,7 @@ public class WebappDataStorage { |
// updated. All fields except for the last used time, scope, and URL are either set or |
// cleared together. |
if (mPreferences.getInt(KEY_VERSION, VERSION_INVALID) |
- != ShortcutHelper.WEBAPP_SHORTCUT_VERSION) { |
+ != ShortcutHelper.WEBAPP_SHORTCUT_VERSION || bypassVersionCheck) { |
editor.putString(KEY_NAME, IntentUtils.safeGetStringExtra( |
shortcutIntent, ShortcutHelper.EXTRA_NAME)); |
editor.putString(KEY_SHORT_NAME, IntentUtils.safeGetStringExtra( |
@@ -349,6 +356,33 @@ public class WebappDataStorage { |
} |
/** |
+ * Updates the data stored in this object to match the given WebappInfo. |
+ */ |
+ public void updateFromWebappInfo(WebappInfo info, Set<String> iconUrls) { |
+ if (info == null) return; |
+ |
+ SharedPreferences.Editor editor = mPreferences.edit(); |
+ |
+ String url = info.uri().toString(); |
+ editor.putString(KEY_URL, url); |
+ editor.putString(KEY_SCOPE, ShortcutHelper.getScopeFromUrl(url)); |
+ editor.putString(KEY_NAME, info.name()); |
+ editor.putString(KEY_SHORT_NAME, info.shortName()); |
+ editor.putString(KEY_ICON, ShortcutHelper.encodeBitmapAsString(info.icon())); |
+ editor.putInt(KEY_DISPLAY_MODE, info.displayMode()); |
+ editor.putInt(KEY_ORIENTATION, info.orientation()); |
+ editor.putLong(KEY_THEME_COLOR, info.themeColor()); |
+ editor.putLong(KEY_BACKGROUND_COLOR, info.backgroundColor()); |
+ editor.putBoolean(KEY_IS_ICON_GENERATED, info.isIconGenerated()); |
+ // Stores an empty set when no icon url is declared in the Web Manifest. |
+ if (iconUrls == null) { |
+ iconUrls = Collections.emptySet(); |
+ } |
+ editor.putStringSet(KEY_ICON_URLS, iconUrls); |
+ editor.apply(); |
+ } |
+ |
+ /** |
* Returns the scope stored in this object, or URL_INVALID if it is not stored. |
*/ |
String getScope() { |
@@ -401,6 +435,28 @@ public class WebappDataStorage { |
} |
/** |
+ * Returns the set of icon urls defined in the web manifest. |
+ * Returns null when the icon urls haven't been set yet. This happens when WebAPK is registered |
+ * from launching Intent without icon urls data available. |
+ * Returns an empty set if icon urls are set but there isn't any icon url declared in the Web |
+ * Manifest. |
+ */ |
+ Set<String> getIconUrls() { |
+ return mPreferences.getStringSet(KEY_ICON_URLS, null); |
+ } |
+ |
+ /** |
+ * Sets the icon urls. |
+ */ |
+ @VisibleForTesting |
+ public void setIconUrls(Set<String> iconUrls) { |
+ if (iconUrls == null) { |
+ iconUrls = Collections.emptySet(); |
+ } |
+ mPreferences.edit().putStringSet(KEY_ICON_URLS, iconUrls).apply(); |
+ } |
+ |
+ /** |
* Returns true if this web app has been launched from home screen recently (within |
* WEBAPP_LAST_OPEN_MAX_TIME milliseconds). |
*/ |