Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
| index f0fb5f6b19b69373748ad5137a19b25ccb0c2b40..aa2fd5b83d8e3bd7ceed7c0e9108b66113d2c6de 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
| @@ -58,6 +58,7 @@ public class ShortcutHelper { |
| public static final String EXTRA_NAME = "org.chromium.chrome.browser.webapp_name"; |
| public static final String EXTRA_SHORT_NAME = "org.chromium.chrome.browser.webapp_short_name"; |
| public static final String EXTRA_URL = "org.chromium.chrome.browser.webapp_url"; |
| + public static final String EXTRA_SCOPE = "org.chromium.chrome.browser.webapp_scope"; |
| public static final String EXTRA_ORIENTATION = ScreenOrientationConstants.EXTRA_ORIENTATION; |
| public static final String EXTRA_SOURCE = "org.chromium.chrome.browser.webapp_source"; |
| public static final String EXTRA_THEME_COLOR = "org.chromium.chrome.browser.theme_color"; |
| @@ -124,25 +125,14 @@ public class ShortcutHelper { |
| @CalledByNative |
| private static void addShortcut(Context context, String id, String url, final String userTitle, |
| String name, String shortName, Bitmap icon, boolean isWebappCapable, int orientation, |
| - int source, long themeColor, long backgroundColor, boolean isIconGenerated) { |
| + int source, long themeColor, long backgroundColor, boolean isIconGenerated, |
| + final long callbackPointer) { |
| Intent shortcutIntent; |
| if (isWebappCapable) { |
| - // Encode the icon as a base64 string (Launcher drops Bitmaps in the Intent). |
| - String encodedIcon = encodeBitmapAsString(icon); |
| - |
| - // Add the shortcut as a launcher icon for a full-screen Activity. |
| - shortcutIntent = new Intent(); |
| - shortcutIntent.setAction(sDelegate.getFullscreenAction()) |
| - .putExtra(EXTRA_ICON, encodedIcon) |
| - .putExtra(EXTRA_ID, id) |
| - .putExtra(EXTRA_NAME, name) |
| - .putExtra(EXTRA_SHORT_NAME, shortName) |
| - .putExtra(EXTRA_URL, url) |
| - .putExtra(EXTRA_ORIENTATION, orientation) |
| - .putExtra(EXTRA_MAC, getEncodedMac(context, url)) |
| - .putExtra(EXTRA_THEME_COLOR, themeColor) |
| - .putExtra(EXTRA_BACKGROUND_COLOR, backgroundColor) |
| - .putExtra(EXTRA_IS_ICON_GENERATED, isIconGenerated); |
| + shortcutIntent = createWebappShortcutIntent(id, sDelegate.getFullscreenAction(), url, |
| + name, shortName, icon, orientation, themeColor, backgroundColor, |
| + isIconGenerated); |
| + shortcutIntent.putExtra(EXTRA_MAC, getEncodedMac(context, url)); |
| } else { |
| // Add the shortcut as a launcher icon to open in the browser Activity. |
| shortcutIntent = createShortcutIntent(url); |
| @@ -155,6 +145,19 @@ public class ShortcutHelper { |
| sDelegate.sendBroadcast( |
| context, createAddToHomeIntent(url, userTitle, icon, shortcutIntent)); |
| + if (isWebappCapable) { |
| + // Store the webapp data so that we can access it. |
| + WebappRegistry.registerWebapp(context, id).updateFromShortcutIntent(shortcutIntent, |
| + new Runnable() { |
| + @Override |
| + public void run() { |
| + nativeOnWebappDataStored(callbackPointer, true); |
| + } |
| + }); |
| + } else { |
| + nativeOnWebappDataStored(callbackPointer, false); |
| + } |
| + |
| // Alert the user about adding the shortcut. |
| Handler handler = new Handler(Looper.getMainLooper()); |
| handler.post(new Runnable() { |
| @@ -173,16 +176,24 @@ public class ShortcutHelper { |
| * Creates a storage location and stores the data for a web app using {@link WebappDataStorage}. |
| * @param context Context to open the WebappDataStorage with. |
| * @param id ID of the webapp which is storing data. |
| - * @param scope scope of the webapp which is storing data. |
| * @param splashImage Image which should be displayed on the splash screen of |
| * the webapp. This can be null of there is no image to show. |
| */ |
| @SuppressWarnings("unused") |
| @CalledByNative |
| - private static void storeWebappData(Context context, String id, String scope, |
| - Bitmap splashImage) { |
| - WebappRegistry.registerWebapp(context, id, scope); |
| - WebappDataStorage.open(context, id).updateSplashScreenImage(splashImage); |
| + private static void storeWebappSplashImage(final Context context, final String id, |
| + final Bitmap splashImage) { |
| + WebappRegistry.getWebappDataStorage(context, id, |
| + new WebappRegistry.FetchWebappDataStorageCallback() { |
| + @Override |
| + public void onWebappDataStorageRetrieved(WebappDataStorage storage) { |
| + if (storage == null) return; |
| + |
| + storage.updateSplashScreenImage(splashImage); |
| + } |
| + |
| + } |
| + ); |
| } |
| /** |
| @@ -215,6 +226,42 @@ public class ShortcutHelper { |
| } |
| /** |
| + * Webapp-capable shortcut intent for icon on home screen. |
| + * @param action Intent action to open a full screen activity. |
| + * @param id Id of the webapp. |
|
gone
2016/04/01 23:44:48
nit: Align these maybe? It's kind of blobby atm.
dominickn
2016/04/04 07:26:23
Done.
|
| + * @param url Url of the webapp. |
| + * @param name Name of the webapp. |
| + * @param shortName Short name of the webapp. @param icon Icon of the webapp. |
| + * @param orientation Orientation of the webapp. |
| + * @param themeColor Theme color of the webapp. |
| + * @param backgroundColor Background color of the webapp. |
| + * @param isIconGenerated True if the icon is generated by Chromium. |
| + * @return Intent for onclick action of the shortcut. |
| + */ |
| + public static Intent createWebappShortcutIntent(String id, String action, String url, |
| + String name, String shortName, Bitmap icon, int orientation, long themeColor, |
| + long backgroundColor, boolean isIconGenerated) { |
| + // Encode the icon as a base64 string (Launcher drops Bitmaps in the Intent). |
| + String encodedIcon = encodeBitmapAsString(icon); |
| + |
| + // Create an intent as a launcher icon for a full-screen Activity. |
| + // The scope is set to the URL until the manifest scope member is available. |
| + Intent shortcutIntent = new Intent(); |
| + shortcutIntent.setAction(action) |
| + .putExtra(EXTRA_ID, id) |
| + .putExtra(EXTRA_URL, url) |
| + .putExtra(EXTRA_SCOPE, url) |
| + .putExtra(EXTRA_NAME, name) |
| + .putExtra(EXTRA_SHORT_NAME, shortName) |
| + .putExtra(EXTRA_ICON, encodedIcon) |
| + .putExtra(EXTRA_ORIENTATION, orientation) |
| + .putExtra(EXTRA_THEME_COLOR, themeColor) |
| + .putExtra(EXTRA_BACKGROUND_COLOR, backgroundColor) |
| + .putExtra(EXTRA_IS_ICON_GENERATED, isIconGenerated); |
| + return shortcutIntent; |
| + } |
| + |
| + /** |
| * Shortcut intent for icon on home screen. |
| * @param url Url of the shortcut. |
| * @return Intent for onclick action of the shortcut. |
| @@ -461,4 +508,6 @@ public class ShortcutHelper { |
| assert false : "The drawable was not a bitmap drawable as expected"; |
| return null; |
| } |
| + |
| + private static native void nativeOnWebappDataStored(long callbackPointer, boolean wasStored); |
| } |