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

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

Issue 2629573004: Add a chrome://webapks page. (Closed)
Patch Set: Adds an about:webapks page with information about all installed Web APKs on the device 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/webapps/WebappRegistry.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java
index 9ee9075312b3efe99ab0b31b6abc1f194e7ce46e..804ee098d45c096e9cdabb14832dde75c22d630d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java
@@ -5,7 +5,9 @@
package org.chromium.chrome.browser.webapps;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.AsyncTask;
@@ -13,6 +15,7 @@ import android.os.AsyncTask;
import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
+import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.browsing_data.UrlFilter;
import org.chromium.chrome.browser.browsing_data.UrlFilterBridge;
@@ -42,6 +45,7 @@ public class WebappRegistry {
static final String REGISTRY_FILE_NAME = "webapp_registry";
static final String KEY_WEBAPP_SET = "webapp_set";
static final String KEY_LAST_CLEANUP = "last_cleanup";
+ static final String WEB_APK_PACKAGE_NAME_PREFIX = "org.chromium.webapk";
Xi Han 2017/01/13 15:50:15 You can use WebApkConstants#WEBAPK_PACKAGE_PREFIX
gonzalon 2017/01/13 20:24:39 Done.
/** Represents a period of 4 weeks in milliseconds */
static final long FULL_CLEANUP_DURATION = TimeUnit.DAYS.toMillis(4L * 7L);
@@ -168,6 +172,34 @@ public class WebappRegistry {
}
/**
+ * Fetches the information of all Web APKs installed on the device and returns them to the
+ * caller using a callback.
+ *
+ * @param webapkInfoCallback Callback to be called with each Web APK found on the device.
+ */
+ @CalledByNative
+ static void listWebAPKs(WebapkInfoCallback webapkInfoCallback) {
Xi Han 2017/01/13 15:50:15 Usually we put helper functions in ShorcutHelper.
gonzalon 2017/01/13 20:24:38 Sounds good! Sorry, I just didn't know where to pu
+ PackageManager packageManager = ContextUtils.getApplicationContext().getPackageManager();
+ for (PackageInfo packageInfo : packageManager.getInstalledPackages(0)) {
+ if (packageInfo.packageName.startsWith(WEB_APK_PACKAGE_NAME_PREFIX)) {
pkotwicz 2017/01/13 16:00:54 Perhaps, you can call WebApkValidator#isValidWebAp
gonzalon 2017/01/13 20:24:38 SG, done
+ Intent intent = new Intent();
+ intent.putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, packageInfo.packageName);
+ // Any URL is fine, since we're only doing this to get info on the Web APK.
+ intent.putExtra(ShortcutHelper.EXTRA_URL, "https://www.google.com/");
hartmanng 2017/01/13 15:40:21 I don't understand why a URL is required at all, c
gonzalon 2017/01/13 20:24:38 As Xi mentioned in the other comment, it was an at
+ WebApkInfo webApkInfo = WebApkInfo.create(intent);
Xi Han 2017/01/13 15:50:15 I understand you want to reuse the code, but it is
pkotwicz 2017/01/13 16:00:54 Can you create a new version of WebApkInfo#create(
pkotwicz 2017/01/13 16:23:19 I had code elsewhere which looked like what you ar
Xi Han 2017/01/13 17:52:43 That is fine, we can defer it to Dominick:)
+ if (webApkInfo != null) {
+ String appName = webApkInfo.shortName();
+ String packageName = webApkInfo.webApkPackageName();
+ int shellApkVersion = webApkInfo.shellApkVersion();
+ int versionCode = packageInfo.versionCode;
+ webapkInfoCallback.onWebApkFound(
+ appName, packageName, shellApkVersion, versionCode);
pkotwicz 2017/01/13 16:23:19 Nit: Inline lines 191 - 194
gonzalon 2017/01/13 20:24:38 Done.
+ }
+ }
+ }
+ }
+
+ /**
* Deletes the data for all "old" web apps, as well as all WebAPKs that have been uninstalled in
* the last month. "Old" web apps have not been opened by the user in the last 3 months, or have
* had their last used time set to 0 by the user clearing their history. Cleanup is run, at

Powered by Google App Engine
This is Rietveld 408576698