 Chromium Code Reviews
 Chromium Code Reviews Issue 2247183008:
  [WebApk] Installation adds a homescreen shortcut.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2247183008:
  [WebApk] Installation adds a homescreen shortcut.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java | 
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java | 
| index e41e461cd3ea400b3a8b53d983d7944c5d7b64cd..3f69dc277168e427596dbbd1ef24b9be6c8fb9d3 100644 | 
| --- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java | 
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java | 
| @@ -5,14 +5,17 @@ | 
| package org.chromium.chrome.browser.webapps; | 
| import android.content.ActivityNotFoundException; | 
| +import android.content.BroadcastReceiver; | 
| import android.content.Context; | 
| import android.content.Intent; | 
| +import android.content.IntentFilter; | 
| import android.net.Uri; | 
| import android.provider.Settings; | 
| import org.chromium.base.ContextUtils; | 
| import org.chromium.base.Log; | 
| import org.chromium.base.annotations.CalledByNative; | 
| +import org.chromium.chrome.browser.ShortcutHelper; | 
| import java.io.File; | 
| @@ -22,7 +25,6 @@ import java.io.File; | 
| */ | 
| public class WebApkInstaller { | 
| private static final String TAG = "WebApkInstaller"; | 
| - | 
| 
Xi Han
2016/08/19 14:23:24
Revert please.
 | 
| /** | 
| * Installs a WebAPK. | 
| * @param filePath File to install. | 
| @@ -42,6 +44,7 @@ public class WebApkInstaller { | 
| intent.setDataAndType(fileUri, "application/vnd.android.package-archive"); | 
| intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
| try { | 
| + listenForPackageInstallation(packageName); | 
| ContextUtils.getApplicationContext().startActivity(intent); | 
| } catch (ActivityNotFoundException e) { | 
| return false; | 
| @@ -49,6 +52,36 @@ public class WebApkInstaller { | 
| return true; | 
| } | 
| + private static class WebApkInstallObserver extends BroadcastReceiver { | 
| + private final String mPackageName; | 
| + public WebApkInstallObserver(String packageName) { | 
| + mPackageName = packageName; | 
| + } | 
| + | 
| + private static String getPackageName(Intent intent) { | 
| + Uri uri = intent.getData(); | 
| + String pkg = uri != null ? uri.getSchemeSpecificPart() : null; | 
| + return pkg; | 
| + } | 
| + | 
| 
gone
2016/08/18 21:16:01
nit: extra newline
 | 
| + | 
| + @Override | 
| + public void onReceive(Context context, Intent intent) { | 
| + if (mPackageName.equals(getPackageName(intent))) { | 
| + ShortcutHelper.addWebApkShortcut(context, mPackageName); | 
| + context.unregisterReceiver(this); | 
| + } | 
| + } | 
| + | 
| + } | 
| + | 
| + private static void listenForPackageInstallation(String packageName) { | 
| + IntentFilter iFilter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); | 
| + iFilter.addDataScheme("package"); | 
| + ContextUtils.getApplicationContext().registerReceiver( | 
| + new WebApkInstallObserver(packageName), iFilter); | 
| + } | 
| + | 
| /** | 
| * Returns whether the user has enabled installing apps from sources other than the Google Play | 
| * Store. |