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.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: " + 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); |
| 96 // The override URL is non null when the WebAPK is launched from a deep link. The WebAPK | |
| 97 // should navigate to the URL in the deep link even if the WebAPK is alr eady open. | |
| 98 boolean navigateIfAlreadyOpen = (overrideUrl != null); | |
|
dominickn
2017/03/21 02:09:33
Inline this in the putExtra call (but leave the co
| |
| 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_NAVIGATE_IF_ALREADY_OPEN, | |
| 106 navigateIfAlreadyOpen); | |
| 100 | 107 |
| 101 try { | 108 try { |
| 102 startActivity(intent); | 109 startActivity(intent); |
| 103 return true; | 110 return true; |
| 104 } catch (ActivityNotFoundException e) { | 111 } catch (ActivityNotFoundException e) { |
| 105 Log.w(TAG, "Unable to launch browser in WebAPK mode."); | 112 Log.w(TAG, "Unable to launch browser in WebAPK mode."); |
| 106 e.printStackTrace(); | 113 e.printStackTrace(); |
| 107 return false; | 114 return false; |
| 108 } | 115 } |
| 109 } | 116 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 if (hostBrowserPackageName == null) { | 155 if (hostBrowserPackageName == null) { |
| 149 return; | 156 return; |
| 150 } | 157 } |
| 151 | 158 |
| 152 try { | 159 try { |
| 153 startActivity(createInstallIntent(hostBrowserPackageName)); | 160 startActivity(createInstallIntent(hostBrowserPackageName)); |
| 154 } catch (ActivityNotFoundException e) { | 161 } catch (ActivityNotFoundException e) { |
| 155 } | 162 } |
| 156 } | 163 } |
| 157 | 164 |
| 158 /** | 165 /** 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. | 166 private String getOverrideUrl() { |
| 160 */ | |
| 161 private String getStartUrl() { | |
| 162 String overrideUrl = getIntent().getDataString(); | 167 String overrideUrl = getIntent().getDataString(); |
| 163 if (overrideUrl != null && overrideUrl.startsWith("https:")) { | 168 if (overrideUrl != null && overrideUrl.startsWith("https:")) { |
| 164 return overrideUrl; | 169 return overrideUrl; |
| 165 } | 170 } |
| 171 return null; | |
| 172 } | |
| 166 | 173 |
| 174 /** Returns the start URL from the Android Manifest. */ | |
| 175 private String getStartUrl() { | |
| 167 ApplicationInfo appInfo; | 176 ApplicationInfo appInfo; |
| 168 try { | 177 try { |
| 169 appInfo = getPackageManager().getApplicationInfo( | 178 appInfo = getPackageManager().getApplicationInfo( |
| 170 getPackageName(), PackageManager.GET_META_DATA); | 179 getPackageName(), PackageManager.GET_META_DATA); |
| 171 } catch (NameNotFoundException e) { | 180 } catch (NameNotFoundException e) { |
| 172 return null; | 181 return null; |
| 173 } | 182 } |
| 174 return appInfo.metaData.getString(WebApkMetaDataKeys.START_URL); | 183 return appInfo.metaData.getString(WebApkMetaDataKeys.START_URL); |
| 175 } | 184 } |
| 176 } | 185 } |
| OLD | NEW |