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; | 10 import android.content.pm.ApplicationInfo; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 protected void onCreate(Bundle savedInstanceState) { | 60 protected void onCreate(Bundle savedInstanceState) { |
61 super.onCreate(savedInstanceState); | 61 super.onCreate(savedInstanceState); |
62 launch(); | 62 launch(); |
63 finish(); | 63 finish(); |
64 } | 64 } |
65 | 65 |
66 /** | 66 /** |
67 * Launches WebAPK. | 67 * Launches WebAPK. |
68 */ | 68 */ |
69 private void launch() { | 69 private void launch() { |
70 String startUrl = getStartUrl(); | 70 String overrideUrl = getOverrideUrl(); |
| 71 String startUrl = (overrideUrl != null) ? overrideUrl : getStartUrl(); |
71 if (startUrl == null) { | 72 if (startUrl == null) { |
72 return; | 73 return; |
73 } | 74 } |
74 if (launchHostBrowserInWebApkMode(startUrl)) { | 75 |
| 76 if (launchHostBrowserInWebApkMode(startUrl, overrideUrl)) { |
75 return; | 77 return; |
76 } | 78 } |
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 startUrl, String overri
deUrl) { |
88 Log.v(TAG, "Url of the WebAPK: " + startUrl); | 90 Log.v(TAG, "Url of the WebAPK: " + startUrl); |
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); |
| 96 |
| 97 // The override URL is non null when the WebAPK is launched from a deep
link. The WebAPK |
| 98 // should navigate to the URL in the deep link even if the WebAPK is alr
eady open. |
94 Intent intent = new Intent(); | 99 Intent intent = new Intent(); |
95 intent.setAction(ACTION_START_WEBAPK); | 100 intent.setAction(ACTION_START_WEBAPK); |
96 intent.setPackage(runtimeHost); | 101 intent.setPackage(runtimeHost); |
97 intent.putExtra(WebApkConstants.EXTRA_URL, startUrl) | 102 intent.putExtra(WebApkConstants.EXTRA_URL, startUrl) |
98 .putExtra(WebApkConstants.EXTRA_SOURCE, source) | 103 .putExtra(WebApkConstants.EXTRA_SOURCE, source) |
99 .putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, packageName
); | 104 .putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, packageName
) |
| 105 .putExtra(WebApkConstants.EXTRA_WEBAPK_FORCE_NAVIGATION, (overri
deUrl != null)); |
100 | 106 |
101 try { | 107 try { |
102 startActivity(intent); | 108 startActivity(intent); |
103 return true; | 109 return true; |
104 } catch (ActivityNotFoundException e) { | 110 } catch (ActivityNotFoundException e) { |
105 Log.w(TAG, "Unable to launch browser in WebAPK mode."); | 111 Log.w(TAG, "Unable to launch browser in WebAPK mode."); |
106 e.printStackTrace(); | 112 e.printStackTrace(); |
107 return false; | 113 return false; |
108 } | 114 } |
109 } | 115 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 if (hostBrowserPackageName == null) { | 154 if (hostBrowserPackageName == null) { |
149 return; | 155 return; |
150 } | 156 } |
151 | 157 |
152 try { | 158 try { |
153 startActivity(createInstallIntent(hostBrowserPackageName)); | 159 startActivity(createInstallIntent(hostBrowserPackageName)); |
154 } catch (ActivityNotFoundException e) { | 160 } catch (ActivityNotFoundException e) { |
155 } | 161 } |
156 } | 162 } |
157 | 163 |
158 /** | 164 /** Retrieves URL from the intent's data. Returns null if a URL could not be
retrieved. */ |
159 * Returns the URL that the browser should navigate to. | 165 private String getOverrideUrl() { |
160 */ | |
161 private String getStartUrl() { | |
162 String overrideUrl = getIntent().getDataString(); | 166 String overrideUrl = getIntent().getDataString(); |
163 if (overrideUrl != null && overrideUrl.startsWith("https:")) { | 167 if (overrideUrl != null && overrideUrl.startsWith("https:")) { |
164 return overrideUrl; | 168 return overrideUrl; |
165 } | 169 } |
| 170 return null; |
| 171 } |
166 | 172 |
| 173 /** Returns the start URL from the Android Manifest. */ |
| 174 private String getStartUrl() { |
167 ApplicationInfo appInfo; | 175 ApplicationInfo appInfo; |
168 try { | 176 try { |
169 appInfo = getPackageManager().getApplicationInfo( | 177 appInfo = getPackageManager().getApplicationInfo( |
170 getPackageName(), PackageManager.GET_META_DATA); | 178 getPackageName(), PackageManager.GET_META_DATA); |
171 } catch (NameNotFoundException e) { | 179 } catch (NameNotFoundException e) { |
172 return null; | 180 return null; |
173 } | 181 } |
174 return appInfo.metaData.getString(WebApkMetaDataKeys.START_URL); | 182 return appInfo.metaData.getString(WebApkMetaDataKeys.START_URL); |
175 } | 183 } |
176 } | 184 } |
OLD | NEW |