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

Side by Side Diff: chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java

Issue 1989283002: Upstream: Launch WebApkActivity from WebAPK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update ActivityAssigner. Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.webapk.shell_apk; 5 package org.chromium.webapk.shell_apk;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.content.ComponentName; 8 import android.content.ComponentName;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.content.pm.ApplicationInfo; 10 import android.content.pm.ApplicationInfo;
11 import android.content.pm.PackageManager; 11 import android.content.pm.PackageManager;
12 import android.content.pm.PackageManager.NameNotFoundException; 12 import android.content.pm.PackageManager.NameNotFoundException;
13 import android.graphics.Bitmap; 13 import android.graphics.Bitmap;
14 import android.graphics.BitmapFactory; 14 import android.graphics.BitmapFactory;
15 import android.os.Bundle; 15 import android.os.Bundle;
16 import android.util.Base64; 16 import android.util.Base64;
17 import android.util.Log; 17 import android.util.Log;
18 18
19 import org.chromium.webapk.lib.common.WebApkConstants; 19 import org.chromium.webapk.lib.common.WebApkConstants;
20 20
21 import java.io.ByteArrayOutputStream; 21 import java.io.ByteArrayOutputStream;
22 22
23 /** 23 /**
24 * WebAPK's main Activity. 24 * WebAPK's main Activity.
25 */ 25 */
26 public class MainActivity extends Activity { 26 public class MainActivity extends Activity {
27 private static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_i d"; 27 private static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_i d";
gone 2016/05/26 18:20:36 You should leave a note here that these values mus
Xi Han 2016/05/26 20:54:58 No, webapk/ doesn't depend on chrome/. Add this no
28 private static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp _icon"; 28 private static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp _icon";
29 private static final String EXTRA_NAME = "org.chromium.chrome.browser.webapp _name"; 29 private static final String EXTRA_NAME = "org.chromium.chrome.browser.webapp _name";
30 private static final String EXTRA_URL = "org.chromium.chrome.browser.webapp_ url"; 30 private static final String EXTRA_URL = "org.chromium.chrome.browser.webapp_ url";
31 private static final String EXTRA_MAC = "org.chromium.chrome.browser.webapp_ mac"; 31 private static final String EXTRA_MAC = "org.chromium.chrome.browser.webapp_ mac";
32 private static final String EXTRA_SCOPE = "org.chromium.chrome.browser.webap p_scope"; 32 private static final String EXTRA_WEBAPK_PACKAGE_NAME =
33 "org.chromium.chrome.browser.webapk_package_name";
33 private static final String META_DATA_HOST_URL = "hostUrl"; 34 private static final String META_DATA_HOST_URL = "hostUrl";
34 private static final String META_DATA_MAC = "mac"; 35 private static final String META_DATA_MAC = "mac";
35 private static final String META_DATA_SCOPE = "scope";
36 private static final String META_DATA_RUNTIME_HOST = "runtimeHost"; 36 private static final String META_DATA_RUNTIME_HOST = "runtimeHost";
37 37
38 private static final String TAG = "cr_MainActivity"; 38 private static final String TAG = "cr_MainActivity";
39 39
40 @Override 40 @Override
41 protected void onCreate(Bundle savedInstanceState) { 41 protected void onCreate(Bundle savedInstanceState) {
42 super.onCreate(savedInstanceState); 42 super.onCreate(savedInstanceState);
43 43
44 String packageName = getPackageName(); 44 String packageName = getPackageName();
45 String webappId = null; 45 String webappId = null;
46 String mac = null; 46 String mac = null;
47 String name = null; 47 String name = null;
48 String url = null; 48 String url = null;
49 String scope = null;
50 String encodedIcon = null; 49 String encodedIcon = null;
51 String runtimeHost = null; 50 String runtimeHost = null;
52 try { 51 try {
53 ApplicationInfo appInfo = getPackageManager().getApplicationInfo( 52 ApplicationInfo appInfo = getPackageManager().getApplicationInfo(
54 packageName, PackageManager.GET_META_DATA); 53 packageName, PackageManager.GET_META_DATA);
55 Bundle bundle = appInfo.metaData; 54 Bundle bundle = appInfo.metaData;
56 url = bundle.getString(META_DATA_HOST_URL); 55 url = bundle.getString(META_DATA_HOST_URL);
57 56
58 String overrideUrl = getIntent().getDataString(); 57 String overrideUrl = getIntent().getDataString();
59 // TODO(pkotwicz): Use same logic as {@code IntentHandler#shouldIgno reIntent()} 58 // TODO(pkotwicz): Use same logic as {@code IntentHandler#shouldIgno reIntent()}
60 if (overrideUrl != null && overrideUrl.startsWith("https:")) { 59 if (overrideUrl != null && overrideUrl.startsWith("https:")) {
61 url = overrideUrl; 60 url = overrideUrl;
62 } 61 }
63 62
64 scope = bundle.getString(META_DATA_SCOPE);
65 webappId = WebApkConstants.WEBAPK_ID_PREFIX + packageName; 63 webappId = WebApkConstants.WEBAPK_ID_PREFIX + packageName;
66 mac = bundle.getString(META_DATA_MAC); 64 mac = bundle.getString(META_DATA_MAC);
67 runtimeHost = bundle.getString(META_DATA_RUNTIME_HOST); 65 runtimeHost = bundle.getString(META_DATA_RUNTIME_HOST);
68 name = (String) getPackageManager().getApplicationLabel(appInfo); 66 name = (String) getPackageManager().getApplicationLabel(appInfo);
69 // TODO(hanxi): find a neat solution to avoid encode/decode each tim e launch the 67 // TODO(hanxi): find a neat solution to avoid encode/decode each tim e launch the
70 // activity. 68 // activity.
71 Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawabl e.app_icon); 69 Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawabl e.app_icon);
72 encodedIcon = encodeBitmapAsString(icon); 70 encodedIcon = encodeBitmapAsString(icon);
73 Log.w(TAG, "Url of the WebAPK: " + url); 71 Log.w(TAG, "Url of the WebAPK: " + url);
74 Log.w(TAG, "webappId of the WebAPK: " + webappId); 72 Log.w(TAG, "WebappId of the WebAPK: " + webappId);
75 Log.w(TAG, "name of the WebAPK:" + name); 73 Log.w(TAG, "Name of the WebAPK:" + name);
74 Log.w(TAG, "Package name of the WebAPK:" + packageName);
75
76 Intent newIntent = new Intent();
77 newIntent.setComponent(new ComponentName(runtimeHost,
78 "org.chromium.chrome.browser.webapps.WebappLauncherActivity" ));
79 newIntent.putExtra(EXTRA_ID, webappId)
80 .putExtra(EXTRA_NAME, name)
81 .putExtra(EXTRA_URL, url)
82 .putExtra(EXTRA_MAC, mac)
83 .putExtra(EXTRA_ICON, encodedIcon)
84 .putExtra(EXTRA_WEBAPK_PACKAGE_NAME, packageName);
85 startActivity(newIntent);
86 finish();
76 } catch (NameNotFoundException e) { 87 } catch (NameNotFoundException e) {
77 e.printStackTrace(); 88 e.printStackTrace();
78 } 89 }
79
80 Intent newIntent = new Intent();
81 newIntent.setComponent(new ComponentName(runtimeHost,
82 "org.chromium.chrome.browser.webapps.WebappLauncherActivity"));
83 newIntent.putExtra(EXTRA_ID, webappId);
84 newIntent.putExtra(EXTRA_NAME, name);
85 newIntent.putExtra(EXTRA_SCOPE, scope);
86 newIntent.putExtra(EXTRA_URL, url);
87 newIntent.putExtra(EXTRA_MAC, mac);
88 newIntent.putExtra(EXTRA_ICON, encodedIcon);
89 startActivity(newIntent);
90 finish();
91 } 90 }
92 91
93 /** 92 /**
94 * Compresses a bitmap into a PNG and converts into a Base64 encoded string. 93 * Compresses a bitmap into a PNG and converts into a Base64 encoded string.
95 * The encoded string can be decoded using {@link decodeBitmapFromString(Str ing)}. 94 * The encoded string can be decoded using {@link decodeBitmapFromString(Str ing)}.
96 * @param bitmap The Bitmap to compress and encode. 95 * @param bitmap The Bitmap to compress and encode.
97 * @return the String encoding the Bitmap. 96 * @return the String encoding the Bitmap.
98 */ 97 */
99 private static String encodeBitmapAsString(Bitmap bitmap) { 98 private static String encodeBitmapAsString(Bitmap bitmap) {
100 if (bitmap == null) return ""; 99 if (bitmap == null) return "";
101 ByteArrayOutputStream output = new ByteArrayOutputStream(); 100 ByteArrayOutputStream output = new ByteArrayOutputStream();
102 bitmap.compress(Bitmap.CompressFormat.PNG, 100, output); 101 bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
103 return Base64.encodeToString(output.toByteArray(), Base64.DEFAULT); 102 return Base64.encodeToString(output.toByteArray(), Base64.DEFAULT);
104 } 103 }
105 } 104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698