Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 String name = null; | 47 String name = null; |
| 48 String url = null; | 48 String url = null; |
| 49 String scope = null; | 49 String scope = null; |
| 50 String encodedIcon = null; | 50 String encodedIcon = null; |
| 51 String runtimeHost = null; | 51 String runtimeHost = null; |
| 52 try { | 52 try { |
| 53 ApplicationInfo appInfo = getPackageManager().getApplicationInfo( | 53 ApplicationInfo appInfo = getPackageManager().getApplicationInfo( |
| 54 packageName, PackageManager.GET_META_DATA); | 54 packageName, PackageManager.GET_META_DATA); |
| 55 Bundle bundle = appInfo.metaData; | 55 Bundle bundle = appInfo.metaData; |
| 56 url = bundle.getString(META_DATA_HOST_URL); | 56 url = bundle.getString(META_DATA_HOST_URL); |
| 57 | |
| 58 String overrideUrl = getIntent().getDataString(); | |
| 59 // TODO(pkotwicz): Use same logic as {@code IntentHandler#shouldIgno reIntent()} | |
| 60 if (overrideUrl != null && overrideUrl.startsWith("https:")) { | |
| 61 url = overrideUrl; | |
| 62 } | |
| 63 | |
| 57 scope = bundle.getString(META_DATA_SCOPE); | 64 scope = bundle.getString(META_DATA_SCOPE); |
| 58 webappId = WebApkConstants.WEBAPK_ID_PREFIX + packageName; | 65 webappId = WebApkConstants.WEBAPK_ID_PREFIX + packageName; |
| 59 mac = bundle.getString(META_DATA_MAC); | 66 mac = bundle.getString(META_DATA_MAC); |
| 60 runtimeHost = bundle.getString(META_DATA_RUNTIME_HOST); | 67 runtimeHost = bundle.getString(META_DATA_RUNTIME_HOST); |
| 61 name = (String) getPackageManager().getApplicationLabel(appInfo); | 68 name = (String) getPackageManager().getApplicationLabel(appInfo); |
| 62 // TODO(hanxi): find a neat solution to avoid encode/decode each tim e launch the | 69 // TODO(hanxi): find a neat solution to avoid encode/decode each tim e launch the |
| 63 // activity. | 70 // activity. |
| 64 Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawabl e.app_icon); | 71 Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawabl e.app_icon); |
| 65 encodedIcon = encodeBitmapAsString(icon); | 72 encodedIcon = encodeBitmapAsString(icon); |
| 66 Log.w(TAG, "Url of the WebAPK: " + url); | 73 Log.w(TAG, "Url of the WebAPK: " + url); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 88 * The encoded string can be decoded using {@link decodeBitmapFromString(Str ing)}. | 95 * The encoded string can be decoded using {@link decodeBitmapFromString(Str ing)}. |
| 89 * @param bitmap The Bitmap to compress and encode. | 96 * @param bitmap The Bitmap to compress and encode. |
| 90 * @return the String encoding the Bitmap. | 97 * @return the String encoding the Bitmap. |
| 91 */ | 98 */ |
| 92 private static String encodeBitmapAsString(Bitmap bitmap) { | 99 private static String encodeBitmapAsString(Bitmap bitmap) { |
| 93 if (bitmap == null) return ""; | 100 if (bitmap == null) return ""; |
| 94 ByteArrayOutputStream output = new ByteArrayOutputStream(); | 101 ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| 95 bitmap.compress(Bitmap.CompressFormat.PNG, 100, output); | 102 bitmap.compress(Bitmap.CompressFormat.PNG, 100, output); |
| 96 return Base64.encodeToString(output.toByteArray(), Base64.DEFAULT); | 103 return Base64.encodeToString(output.toByteArray(), Base64.DEFAULT); |
| 97 } | 104 } |
| 105 | |
| 106 /** | |
| 107 * Returns whether a url is valid. | |
| 108 * @param url The url to check. | |
| 109 * @return Whether the url is valid. | |
| 110 */ | |
| 111 private static boolean isUrlValid(String url) { | |
|
Yaron
2016/05/12 13:45:12
nit: remove
| |
| 112 return url != null && url.startsWith("https:"); | |
| 113 } | |
| 98 } | 114 } |
| OLD | NEW |