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

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

Issue 2259553002: Make AppBannerInfoBar install WebAPK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move logic to WebApkInstaller. Created 4 years, 4 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/infobar/AppBannerInfoBarDelegateAndroid.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBarDelegateAndroid.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBarDelegateAndroid.java
index 989024241efeb1c31242977cc736eee29bf2dc45..6eb737b3f840e2f76f142a5843a7f022c4549ea1 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBarDelegateAndroid.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBarDelegateAndroid.java
@@ -13,13 +13,16 @@ import android.os.Looper;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.ContextUtils;
+import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
+import org.chromium.chrome.R;
import org.chromium.chrome.browser.banners.AppData;
import org.chromium.chrome.browser.banners.InstallerDelegate;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.ui.base.WindowAndroid;
+import org.chromium.ui.widget.Toast;
/**
* Handles the promotion and installation of an app specified by the current web page. This Java
@@ -39,16 +42,29 @@ public class AppBannerInfoBarDelegateAndroid {
/** Monitors for application state changes. */
private final ApplicationStatus.ApplicationStateListener mListener;
+ /**
+ * Indicates whether a request to install a WebPK has started. This flag is set before
+ * the package name of the WebAPK is available.
+ */
+ private boolean mIsWebApkInstalling = false;
+
+ /** The package name of the WebAPK. */
+ private String mWebApkPackage;
+
+ /** Indicates whether the banner is for installing a WebAPK. */
+ private boolean mIsWebApk;
+
/** Overrides the PackageManager for testing. */
@VisibleForTesting
public static void setPackageManagerForTesting(PackageManager manager) {
sPackageManagerForTests = manager;
}
- private AppBannerInfoBarDelegateAndroid(long nativePtr) {
+ private AppBannerInfoBarDelegateAndroid(long nativePtr, boolean isWebApk) {
mNativePointer = nativePtr;
mListener = createApplicationStateListener();
ApplicationStatus.registerApplicationStateListener(mListener);
+ mIsWebApk = isWebApk;
pkotwicz 2016/08/25 22:23:15 We don't seem to use |mIsWebApk| anymore.
Xi Han 2016/08/26 17:04:17 Good catch, removed.
}
private ApplicationStatus.ApplicationStateListener createApplicationStateListener() {
@@ -79,10 +95,7 @@ public class AppBannerInfoBarDelegateAndroid {
if (InstallerDelegate.isInstalled(packageManager, packageName)) {
// Open the app.
- Intent launchIntent = packageManager.getLaunchIntentForPackage(packageName);
- if (launchIntent == null) return true;
- context.startActivity(launchIntent);
- return true;
+ return openApp(context, packageName);
} else {
// Try installing the app. If the installation was kicked off, return false to prevent
// the infobar from disappearing.
@@ -96,6 +109,14 @@ public class AppBannerInfoBarDelegateAndroid {
}
}
+ private boolean openApp(Context context, String packageName) {
pkotwicz 2016/08/25 22:23:15 This function always returns true. Can it be void
Xi Han 2016/08/26 17:04:17 Done.
+ Intent launchIntent = getPackageManager(context).getLaunchIntentForPackage(packageName);
+ if (launchIntent != null) {
dominickn 2016/08/25 04:25:56 Nit: make this a single line if statement.
Xi Han 2016/08/26 17:04:17 Done.
+ context.startActivity(launchIntent);
+ }
+ return true;
+ }
+
private WindowAndroid.IntentCallback createIntentCallback(final AppData appData) {
return new WindowAndroid.IntentCallback() {
@Override
@@ -129,18 +150,59 @@ public class AppBannerInfoBarDelegateAndroid {
}
@CalledByNative
+ private boolean openWebApk(String packageName) {
+ Context context = ContextUtils.getApplicationContext();
+ PackageManager packageManager = getPackageManager(context);
+
+ if (InstallerDelegate.isInstalled(packageManager, packageName)) {
+ // Open the WebApk.
dominickn 2016/08/25 04:25:56 Nit: remove this redundant comment
Xi Han 2016/08/26 17:04:17 Done.
+ mWebApkPackage = null;
+ return openApp(context, packageName);
+ }
+ return true;
+ }
+
+ @CalledByNative
private void showAppDetails(Tab tab, AppData appData) {
tab.getWindowAndroid().showIntent(appData.detailsIntent(), null, null);
}
@CalledByNative
private int determineInstallState(AppData data) {
- if (mInstallTask != null) return AppBannerInfoBarAndroid.INSTALL_STATE_INSTALLING;
+ if (mInstallTask != null || mIsWebApkInstalling) {
+ return AppBannerInfoBarAndroid.INSTALL_STATE_INSTALLING;
+ }
PackageManager pm = getPackageManager(ContextUtils.getApplicationContext());
- boolean isInstalled = InstallerDelegate.isInstalled(pm, data.packageName());
+ String packageName = data != null ? data.packageName() : mWebApkPackage;
dominickn 2016/08/25 04:25:56 Nit: brackets around the conditional
Xi Han 2016/08/26 17:04:17 Done.
+ boolean isInstalled = InstallerDelegate.isInstalled(pm, packageName);
return isInstalled ? AppBannerInfoBarAndroid.INSTALL_STATE_INSTALLED
- : AppBannerInfoBarAndroid.INSTALL_STATE_NOT_INSTALLED;
+ : AppBannerInfoBarAndroid.INSTALL_STATE_NOT_INSTALLED;
+ }
+
+ @CalledByNative
+ /** Set the flag of whether a installation process is started for the WebAPK. */
+ private void setWebApkInstallingState(boolean isInstalling) {
+ mIsWebApkInstalling = isInstalling;
+ }
+
+ @CalledByNative
+ /** Sets the WebAPK package name. */
+ private void setWebApkPackageName(String webApkPackage) {
+ mWebApkPackage = webApkPackage;
+ }
+
+ @CalledByNative
+ private static void showWebApkInstallFailureToast() {
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Context applicationContext = ContextUtils.getApplicationContext();
+ Toast toast = Toast.makeText(applicationContext, R.string.fail_to_install_webapk,
+ Toast.LENGTH_SHORT);
+ toast.show();
+ }
+ });
}
private PackageManager getPackageManager(Context context) {
@@ -149,8 +211,8 @@ public class AppBannerInfoBarDelegateAndroid {
}
@CalledByNative
- private static AppBannerInfoBarDelegateAndroid create(long nativePtr) {
- return new AppBannerInfoBarDelegateAndroid(nativePtr);
+ private static AppBannerInfoBarDelegateAndroid create(long nativePtr, boolean isWebApk) {
+ return new AppBannerInfoBarDelegateAndroid(nativePtr, isWebApk);
}
private native void nativeOnInstallIntentReturned(

Powered by Google App Engine
This is Rietveld 408576698