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

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

Issue 2629573004: Add a chrome://webapks page. (Closed)
Patch Set: Add a chrome://webapks page. Created 3 years, 11 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 9bb166773ac1199ec993a12a54d29685cb851db7..1d2e3cf0aaa1297646b8b26447ce01e485d7f05a 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java
@@ -9,6 +9,7 @@ import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
@@ -22,6 +23,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
+import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Base64;
@@ -34,6 +36,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.blink_public.platform.WebDisplayMode;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.webapps.ChromeWebApkHost;
+import org.chromium.chrome.browser.webapps.WebApkInfo;
import org.chromium.chrome.browser.webapps.WebappActivity;
import org.chromium.chrome.browser.webapps.WebappAuthenticator;
import org.chromium.chrome.browser.webapps.WebappDataStorage;
@@ -45,6 +48,7 @@ import org.chromium.ui.widget.Toast;
import org.chromium.webapk.lib.client.WebApkValidator;
import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -648,5 +652,48 @@ public class ShortcutHelper {
return null;
}
+ /**
+ * Calls the native |callbackPointer| with lists of information on all installed WebAPKs.
+ *
+ * @param callbackPointer Callback to call with the information on the WebAPKs found.
+ */
+ @CalledByNative
+ public static void retrieveWebApks(long callbackPointer) {
+ List<String> shortNames = new ArrayList<>();
+ List<String> packageNames = new ArrayList<>();
+ List<Integer> shellApkVersions = new ArrayList<>();
+ List<Integer> versionCodes = new ArrayList<>();
+
+ Context context = ContextUtils.getApplicationContext();
+ PackageManager packageManager = context.getPackageManager();
+ for (PackageInfo packageInfo : packageManager.getInstalledPackages(0)) {
+ if (WebApkValidator.isValidWebApk(context, packageInfo.packageName)) {
+ // Pass non-null URL parameter so that {@link WebApkInfo#create()}
+ // return value is non-null
+ WebApkInfo webApkInfo =
+ WebApkInfo.create(packageInfo.packageName, "", ShortcutSource.UNKNOWN);
+ if (webApkInfo != null) {
+ shortNames.add(webApkInfo.shortName());
+ packageNames.add(webApkInfo.webApkPackageName());
+ shellApkVersions.add(webApkInfo.shellApkVersion());
+ versionCodes.add(packageInfo.versionCode);
+ }
+ }
+ }
+ nativeOnWebApksRetrieved(callbackPointer, shortNames.toArray(new String[0]),
+ packageNames.toArray(new String[0]), integerListToIntArray(shellApkVersions),
+ integerListToIntArray(versionCodes));
+ }
+
+ private static int[] integerListToIntArray(@NonNull List<Integer> list) {
+ int[] array = new int[list.size()];
+ for (int i = 0; i < list.size(); i++) {
+ array[i] = list.get(i);
+ }
+ return array;
+ }
+
private static native void nativeOnWebappDataStored(long callbackPointer);
+ private static native void nativeOnWebApksRetrieved(long callbackPointer, String[] shortNames,
+ String[] packageName, int[] shellApkVersions, int[] versionCodes);
}

Powered by Google App Engine
This is Rietveld 408576698