Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4236)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java

Issue 2031213004: Upstream: Create WebAPK when user selects "Add to Home screen" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 2df81fc5ba4c1246095dc997f120cb3ba5cb8a21..729e1a5be6ffcbee556bff1ceb90c7af4ecaa8f2 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java
@@ -28,6 +28,7 @@ import android.text.TextUtils;
import android.util.Base64;
import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
@@ -35,12 +36,14 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.blink_public.platform.WebDisplayMode;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.webapps.WebApkBuilder;
import org.chromium.chrome.browser.webapps.WebappAuthenticator;
import org.chromium.chrome.browser.webapps.WebappDataStorage;
import org.chromium.chrome.browser.webapps.WebappLauncherActivity;
import org.chromium.chrome.browser.webapps.WebappRegistry;
import org.chromium.chrome.browser.widget.RoundedIconGenerator;
import org.chromium.content_public.common.ScreenOrientationConstants;
+import org.chromium.net.GURLUtils;
import org.chromium.ui.widget.Toast;
import java.io.ByteArrayOutputStream;
@@ -137,15 +140,24 @@ public class ShortcutHelper {
*/
@SuppressWarnings("unused")
@CalledByNative
- private static void addShortcut(Context context, String id, String url, final String userTitle,
+ private static void addShortcut(String id, String url, final String userTitle,
String name, String shortName, Bitmap icon, int displayMode, int orientation,
int source, long themeColor, long backgroundColor, boolean isIconGenerated,
final long callbackPointer) {
assert !ThreadUtils.runningOnUiThread();
+
+ Context context = ContextUtils.getApplicationContext();
final Intent shortcutIntent;
boolean isWebappCapable = (displayMode == WebDisplayMode.Standalone
|| displayMode == WebDisplayMode.Fullscreen);
if (isWebappCapable) {
+ if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK)) {
+ WebApkBuilder apkBuilder = ((ChromeApplication) context).createWebApkBuilder();
+ if (apkBuilder != null) {
+ apkBuilder.buildWebApkAsync(url, GURLUtils.getOrigin(url), shortName, icon);
+ return;
+ }
+ }
shortcutIntent = createWebappShortcutIntent(id, sDelegate.getFullscreenAction(), url,
getScopeFromUrl(url), name, shortName, icon, WEBAPP_SHORTCUT_VERSION,
displayMode, orientation, themeColor, backgroundColor, isIconGenerated);
@@ -192,16 +204,14 @@ 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 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 storeWebappSplashImage(final Context context, final String id,
- final Bitmap splashImage) {
- WebappRegistry.getWebappDataStorage(context, id,
+ private static void storeWebappSplashImage(final String id, final Bitmap splashImage) {
+ WebappRegistry.getWebappDataStorage(ContextUtils.getApplicationContext(), id,
new WebappRegistry.FetchWebappDataStorageCallback() {
@Override
public void onWebappDataStorageRetrieved(WebappDataStorage storage) {
@@ -210,8 +220,7 @@ public class ShortcutHelper {
storage.updateSplashScreenImage(splashImage);
}
- }
- );
+ });
}
/**
@@ -310,13 +319,13 @@ public class ShortcutHelper {
/**
* Returns whether the given icon matches the size requirements to be used on the home screen.
- * @param context Context used to create the intent.
* @param width Icon width, in pixels.
* @param height Icon height, in pixels.
* @return whether the given icon matches the size requirements to be used on the home screen.
*/
@CalledByNative
- public static boolean isIconLargeEnoughForLauncher(Context context, int width, int height) {
+ public static boolean isIconLargeEnoughForLauncher(int width, int height) {
+ Context context = ContextUtils.getApplicationContext();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
final int minimalSize = am.getLauncherLargeIconSize() / 2;
return width >= minimalSize && height >= minimalSize;
@@ -331,12 +340,13 @@ public class ShortcutHelper {
* @return Bitmap Either the touch-icon or the newly created favicon.
*/
@CalledByNative
- public static Bitmap createHomeScreenIconFromWebIcon(Context context, Bitmap webIcon) {
+ public static Bitmap createHomeScreenIconFromWebIcon(Bitmap webIcon) {
// getLauncherLargeIconSize() is just a guess at the launcher icon size, and is often
// wrong -- the launcher can show icons at any size it pleases. Instead of resizing the
// icon to the supposed launcher size and then having the launcher resize the icon again,
// just leave the icon at its original size and let the launcher do a single rescaling.
// Unless the icon is much too big; then scale it down here too.
+ Context context = ContextUtils.getApplicationContext();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
int maxInnerSize = Math.round(am.getLauncherLargeIconSize() * MAX_INNER_SIZE_RATIO);
int innerSize = Math.min(maxInnerSize, Math.max(webIcon.getWidth(), webIcon.getHeight()));
@@ -374,7 +384,6 @@ public class ShortcutHelper {
* Generates a generic icon to be used in the launcher. This is just a rounded rectangle with
* a letter in the middle taken from the website's domain name.
*
- * @param context Context used to create the intent.
* @param url URL of the shortcut.
* @param red Red component of the dominant icon color.
* @param green Green component of the dominant icon color.
@@ -382,8 +391,9 @@ public class ShortcutHelper {
* @return Bitmap Either the touch-icon or the newly created favicon.
*/
@CalledByNative
- public static Bitmap generateHomeScreenIcon(Context context, String url, int red, int green,
+ public static Bitmap generateHomeScreenIcon(String url, int red, int green,
int blue) {
+ Context context = ContextUtils.getApplicationContext();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
final int outerSize = am.getLauncherLargeIconSize();
final int iconDensity = am.getLauncherLargeIconDensity();
@@ -535,7 +545,8 @@ public class ShortcutHelper {
* icon and the ideal and minimum sizes of the splash screen image in that order.
*/
@CalledByNative
- private static int[] getHomeScreenIconAndSplashImageSizes(Context context) {
+ private static int[] getHomeScreenIconAndSplashImageSizes() {
+ Context context = ContextUtils.getApplicationContext();
// This ordering must be kept up to date with the C++ ShortcutHelper.
return new int[] {
getIdealHomescreenIconSizeInDp(context),

Powered by Google App Engine
This is Rietveld 408576698