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

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

Issue 2629573004: Add a chrome://webapks page. (Closed)
Patch Set: Makes the listWebApks method receive a callback on the Java side 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..a8cbfdd3eacae3eab951ed03e44fbcf867c4120f 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.LinkedList;
import java.util.List;
/**
@@ -648,5 +652,49 @@ public class ShortcutHelper {
return null;
}
+ /**
+ * Fetches the information of all WebAPKs installed on the device and returns them to the
+ * caller using a callback.
+ *
+ * @param callbackPointer Callback to be called with the information on the WebAPKs found.
+ */
+ @CalledByNative
+ public static void listWebApks(long callbackPointer) {
+ List<String> shortNames = new LinkedList<>();
pkotwicz 2017/01/18 02:08:20 Can you explain why you chose a LinkedList instead
gonzalon 2017/01/18 15:29:32 I only use ArrayList when I'm sure of the final si
+ List<String> packageNames = new LinkedList<>();
+ List<Integer> shellApkVersions = new LinkedList<>();
+ List<Integer> versionCodes = new LinkedList<>();
+
+ PackageManager packageManager = ContextUtils.getApplicationContext().getPackageManager();
+ for (PackageInfo packageInfo : packageManager.getInstalledPackages(0)) {
+ if (WebApkValidator.isValidWebApk(
+ ContextUtils.getApplicationContext(), packageInfo.packageName)) {
+ // We need to pass in a non-null URL as second parameter to fetch all the
+ // information about the WebAPK.
+ WebApkInfo webApkInfo = WebApkInfo.create(packageInfo.packageName, "", 0);
pkotwicz 2017/01/18 02:08:20 Nit: 0 -> ShortcutSource.UNKNOWN
gonzalon 2017/01/18 15:29:32 Done.
+ if (webApkInfo != null) {
+ shortNames.add(webApkInfo.shortName());
+ packageNames.add(packageInfo.packageName);
+ shellApkVersions.add(webApkInfo.shellApkVersion());
+ versionCodes.add(packageInfo.versionCode);
+ }
+ }
+ }
pkotwicz 2017/01/18 02:08:20 Nit: For the sake of clarity I would do: String[]
gonzalon 2017/01/18 15:29:32 It's not exactly the same, if the size of the arra
+ nativeOnWebApksFound(callbackPointer, shortNames.toArray(new String[shortNames.size()]),
+ packageNames.toArray(new String[packageNames.size()]),
+ integerListToIntArray(shellApkVersions), integerListToIntArray(versionCodes));
+ }
+
+ private static int[] integerListToIntArray(@NonNull List<Integer> list) {
pkotwicz 2017/01/18 02:08:20 +agrieve@ Cool! I did not know about this annotat
gonzalon 2017/01/18 15:29:32 This annotation doesn't actually enforce the argum
agrieve 2017/01/19 19:58:23 Yep, would love to see more support annotations be
+ int[] array = new int[list.size()];
+ int i = 0;
+ for (Integer integer : list) {
pkotwicz 2017/01/18 02:08:20 Nit: integer -> value I'm not a fan of naming a v
gonzalon 2017/01/18 15:29:32 Done.
+ array[i++] = integer;
+ }
+ return array;
+ }
+
private static native void nativeOnWebappDataStored(long callbackPointer);
+ private static native void nativeOnWebApksFound(long callbackPointer, String[] shortNames,
+ String[] packageName, int[] shellApkVersions, int[] versionCodes);
}

Powered by Google App Engine
This is Rietveld 408576698