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.ActivityNotFoundException; | 8 import android.content.ActivityNotFoundException; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.pm.ApplicationInfo; | |
11 import android.content.pm.PackageManager; | |
12 import android.content.pm.PackageManager.NameNotFoundException; | |
13 import android.net.Uri; | 10 import android.net.Uri; |
14 import android.os.Bundle; | 11 import android.os.Bundle; |
15 import android.util.Log; | 12 import android.util.Log; |
16 | 13 |
17 import org.chromium.webapk.lib.common.WebApkConstants; | 14 import org.chromium.webapk.lib.common.WebApkConstants; |
18 import org.chromium.webapk.lib.common.WebApkMetaDataKeys; | 15 import org.chromium.webapk.lib.common.WebApkMetaDataKeys; |
19 | 16 |
20 import java.net.URISyntaxException; | 17 import java.net.URISyntaxException; |
21 | 18 |
22 /** | 19 /** |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 protected void onCreate(Bundle savedInstanceState) { | 57 protected void onCreate(Bundle savedInstanceState) { |
61 super.onCreate(savedInstanceState); | 58 super.onCreate(savedInstanceState); |
62 launch(); | 59 launch(); |
63 finish(); | 60 finish(); |
64 } | 61 } |
65 | 62 |
66 /** | 63 /** |
67 * Launches WebAPK. | 64 * Launches WebAPK. |
68 */ | 65 */ |
69 private void launch() { | 66 private void launch() { |
70 String startUrl = getStartUrl(); | 67 String overrideUrl = getOverrideUrl(); |
68 if (launchHostBrowserInWebApkMode(overrideUrl)) { | |
69 return; | |
70 } | |
71 | |
72 String startUrl = overrideUrl; | |
73 if (startUrl == null) { | |
74 startUrl = getStartUrl(); | |
75 } | |
71 if (startUrl == null) { | 76 if (startUrl == null) { |
72 return; | 77 return; |
73 } | 78 } |
74 if (launchHostBrowserInWebApkMode(startUrl)) { | |
75 return; | |
76 } | |
77 if (launchBrowser(startUrl)) { | 79 if (launchBrowser(startUrl)) { |
78 return; | 80 return; |
79 } | 81 } |
80 installBrowser(); | 82 installBrowser(); |
81 } | 83 } |
82 | 84 |
83 /** | 85 /** |
84 * Launches host browser in WebAPK mode. | 86 * Launches host browser in WebAPK mode. |
85 * @return True if successful. | 87 * @return True if successful. |
86 */ | 88 */ |
87 private boolean launchHostBrowserInWebApkMode(String startUrl) { | 89 private boolean launchHostBrowserInWebApkMode(String overrideUrl) { |
88 Log.v(TAG, "Url of the WebAPK: " + startUrl); | 90 Log.v(TAG, "Url of the WebAPK: " + overrideUrl); |
89 String packageName = getPackageName(); | 91 String packageName = getPackageName(); |
90 Log.v(TAG, "Package name of the WebAPK:" + packageName); | 92 Log.v(TAG, "Package name of the WebAPK:" + packageName); |
91 | 93 |
92 String runtimeHost = WebApkUtils.getHostBrowserPackageName(this); | 94 String runtimeHost = WebApkUtils.getHostBrowserPackageName(this); |
93 int source = getIntent().getIntExtra(WebApkConstants.EXTRA_SOURCE, 0); | 95 int source = getIntent().getIntExtra(WebApkConstants.EXTRA_SOURCE, 0); |
94 Intent intent = new Intent(); | 96 Intent intent = new Intent(); |
95 intent.setAction(ACTION_START_WEBAPK); | 97 intent.setAction(ACTION_START_WEBAPK); |
96 intent.setPackage(runtimeHost); | 98 intent.setPackage(runtimeHost); |
97 intent.putExtra(WebApkConstants.EXTRA_URL, startUrl) | 99 intent.putExtra(WebApkConstants.EXTRA_URL, overrideUrl) |
98 .putExtra(WebApkConstants.EXTRA_SOURCE, source) | 100 .putExtra(WebApkConstants.EXTRA_SOURCE, source) |
99 .putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, packageName ); | 101 .putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, packageName ); |
100 | 102 |
101 try { | 103 try { |
102 startActivity(intent); | 104 startActivity(intent); |
103 return true; | 105 return true; |
104 } catch (ActivityNotFoundException e) { | 106 } catch (ActivityNotFoundException e) { |
105 Log.w(TAG, "Unable to launch browser in WebAPK mode."); | 107 Log.w(TAG, "Unable to launch browser in WebAPK mode."); |
106 e.printStackTrace(); | 108 e.printStackTrace(); |
107 return false; | 109 return false; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 if (hostBrowserPackageName == null) { | 150 if (hostBrowserPackageName == null) { |
149 return; | 151 return; |
150 } | 152 } |
151 | 153 |
152 try { | 154 try { |
153 startActivity(createInstallIntent(hostBrowserPackageName)); | 155 startActivity(createInstallIntent(hostBrowserPackageName)); |
154 } catch (ActivityNotFoundException e) { | 156 } catch (ActivityNotFoundException e) { |
155 } | 157 } |
156 } | 158 } |
157 | 159 |
160 /** Returns the URL in the data URL */ | |
161 private String getOverrideUrl() { | |
162 String overrideUrl = getIntent().getDataString(); | |
163 if (overrideUrl != null && overrideUrl.startsWith("https:")) { | |
164 return overrideUrl; | |
165 } | |
166 return null; | |
167 } | |
168 | |
158 /** | 169 /** |
159 * Returns the URL that the browser should navigate to. | 170 * Returns the start URL from the Android ManifesReturns the URL that the br owser should |
dominickn
2017/03/20 04:00:09
Something went wrong with this comment here. Plus
pkotwicz
2017/03/20 22:58:37
Fixed. Thank you very much for catching this
| |
171 * navigate to. | |
160 */ | 172 */ |
161 private String getStartUrl() { | 173 private String getStartUrl() { |
162 String overrideUrl = getIntent().getDataString(); | 174 String overrideUrl = getIntent().getDataString(); |
163 if (overrideUrl != null && overrideUrl.startsWith("https:")) { | 175 if (overrideUrl != null && overrideUrl.startsWith("https:")) { |
164 return overrideUrl; | 176 return overrideUrl; |
165 } | 177 } |
166 | 178 |
167 ApplicationInfo appInfo; | 179 return getApplicationInfo().metaData.getString(WebApkMetaDataKeys.START_ URL); |
168 try { | |
169 appInfo = getPackageManager().getApplicationInfo( | |
170 getPackageName(), PackageManager.GET_META_DATA); | |
171 } catch (NameNotFoundException e) { | |
172 return null; | |
173 } | |
174 return appInfo.metaData.getString(WebApkMetaDataKeys.START_URL); | |
175 } | 180 } |
176 } | 181 } |
OLD | NEW |