OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.chrome.browser.webapps; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.content.pm.ApplicationInfo; | 8 import android.content.pm.ApplicationInfo; |
9 import android.content.pm.PackageManager; | 9 import android.content.pm.PackageManager; |
10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
(...skipping 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 import java.util.HashMap; | 25 import java.util.HashMap; |
26 import java.util.Map; | 26 import java.util.Map; |
27 | 27 |
28 /** | 28 /** |
29 * Stores info for WebAPK. | 29 * Stores info for WebAPK. |
30 */ | 30 */ |
31 public class WebApkInfo extends WebappInfo { | 31 public class WebApkInfo extends WebappInfo { |
32 private static final String TAG = "WebApkInfo"; | 32 private static final String TAG = "WebApkInfo"; |
33 | 33 |
34 private boolean mShouldLoadUrlIfAlreadyRunning; | |
34 private String mWebApkPackageName; | 35 private String mWebApkPackageName; |
35 private int mShellApkVersion; | 36 private int mShellApkVersion; |
36 private String mManifestUrl; | 37 private String mManifestUrl; |
37 private String mManifestStartUrl; | 38 private String mManifestStartUrl; |
38 private Map<String, String> mIconUrlToMurmur2HashMap; | 39 private Map<String, String> mIconUrlToMurmur2HashMap; |
39 | 40 |
40 public static WebApkInfo createEmpty() { | 41 public static WebApkInfo createEmpty() { |
41 return new WebApkInfo(); | 42 return new WebApkInfo(); |
42 } | 43 } |
43 | 44 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 return create(WebApkConstants.WEBAPK_ID_PREFIX + webApkPackageName, url, scope, | 104 return create(WebApkConstants.WEBAPK_ID_PREFIX + webApkPackageName, url, scope, |
104 new Icon(icon), name, shortName, displayMode, orientation, sourc e, themeColor, | 105 new Icon(icon), name, shortName, displayMode, orientation, sourc e, themeColor, |
105 backgroundColor, webApkPackageName, shellApkVersion, manifestUrl , manifestStartUrl, | 106 backgroundColor, webApkPackageName, shellApkVersion, manifestUrl , manifestStartUrl, |
106 iconUrlToMurmur2HashMap); | 107 iconUrlToMurmur2HashMap); |
107 } | 108 } |
108 | 109 |
109 /** | 110 /** |
110 * Construct a {@link WebApkInfo} instance. | 111 * Construct a {@link WebApkInfo} instance. |
111 * | 112 * |
112 * @param id ID for the WebAPK. | 113 * @param id ID for the WebAPK. |
113 * @param url URL that the WebAPK should navigate to whe n launched. | 114 * @param url URL that the WebAPK should navigate to whe n launched. A null |
115 * URL should be passed if the WebAPK should stay at the current | |
116 * URL if it is already open. | |
114 * @param scope Scope for the WebAPK. | 117 * @param scope Scope for the WebAPK. |
115 * @param icon Icon to show for the WebAPK. | 118 * @param icon Icon to show for the WebAPK. |
116 * @param name Name of the WebAPK. | 119 * @param name Name of the WebAPK. |
117 * @param shortName The short name of the WebAPK. | 120 * @param shortName The short name of the WebAPK. |
118 * @param displayMode Display mode of the WebAPK. | 121 * @param displayMode Display mode of the WebAPK. |
119 * @param orientation Orientation of the WebAPK. | 122 * @param orientation Orientation of the WebAPK. |
120 * @param source Source that the WebAPK was launched from. | 123 * @param source Source that the WebAPK was launched from. |
121 * @param themeColor The theme color of the WebAPK. | 124 * @param themeColor The theme color of the WebAPK. |
122 * @param backgroundColor The background color of the WebAPK. | 125 * @param backgroundColor The background color of the WebAPK. |
123 * @param webApkPackageName The package of the WebAPK. | 126 * @param webApkPackageName The package of the WebAPK. |
124 * @param shellApkVersion Version of the code in //chrome/android/we bapk/shell_apk. | 127 * @param shellApkVersion Version of the code in //chrome/android/we bapk/shell_apk. |
125 * @param manifestUrl URL of the Web Manifest. | 128 * @param manifestUrl URL of the Web Manifest. |
126 * @param manifestStartUrl URL that the WebAPK should navigate to whe n launched from the | 129 * @param manifestStartUrl URL that the WebAPK should navigate to whe n launched from the |
127 * homescreen. Different from the {@link url} parameter if the | 130 * homescreen. Different from the {@link url} parameter if the |
128 * WebAPK is launched from a deep link. | 131 * WebAPK is launched from a deep link. |
129 * @param iconUrlToMurmur2HashMap Map of the WebAPK's icon URLs to Murmur2 h ashes of the | 132 * @param iconUrlToMurmur2HashMap Map of the WebAPK's icon URLs to Murmur2 h ashes of the |
130 * icon untransformed bytes. | 133 * icon untransformed bytes. |
131 */ | 134 */ |
132 public static WebApkInfo create(String id, String url, String scope, Icon ic on, String name, | 135 public static WebApkInfo create(String id, String url, String scope, Icon ic on, String name, |
133 String shortName, int displayMode, int orientation, int source, long themeColor, | 136 String shortName, int displayMode, int orientation, int source, long themeColor, |
134 long backgroundColor, String webApkPackageName, int shellApkVersion, String manifestUrl, | 137 long backgroundColor, String webApkPackageName, int shellApkVersion, String manifestUrl, |
135 String manifestStartUrl, Map<String, String> iconUrlToMurmur2HashMap ) { | 138 String manifestStartUrl, Map<String, String> iconUrlToMurmur2HashMap ) { |
136 if (id == null || url == null || manifestStartUrl == null || webApkPacka geName == null) { | 139 if (id == null || manifestStartUrl == null || webApkPackageName == null) { |
137 Log.e(TAG, | 140 Log.e(TAG, |
138 "Incomplete data provided: " + id + ", " + url + ", " + mani festStartUrl + ", " | 141 "Incomplete data provided: " + id + ", " + manifestStartUrl + ", " |
139 + webApkPackageName); | 142 + webApkPackageName); |
140 return null; | 143 return null; |
141 } | 144 } |
142 | 145 |
143 // The default scope should be computed from the Web Manifest start URL. If the WebAPK was | 146 // The default scope should be computed from the Web Manifest start URL. If the WebAPK was |
144 // launched from a deep link {@link startUrl} may be different from the Web Manifest start | 147 // launched from a deep link {@link startUrl} may be different from the Web Manifest start |
145 // URL. | 148 // URL. |
146 if (TextUtils.isEmpty(scope)) { | 149 if (TextUtils.isEmpty(scope)) { |
147 scope = ShortcutHelper.getScopeFromUrl(manifestStartUrl); | 150 scope = ShortcutHelper.getScopeFromUrl(manifestStartUrl); |
148 } | 151 } |
149 | 152 |
150 return new WebApkInfo(id, url, scope, icon, name, shortName, displayMode , | 153 boolean shouldLoadUrlIfAlreadyRunning = true; |
dominickn
2017/03/20 04:00:09
The null url parameter + this new boolean is reall
pkotwicz
2017/03/20 22:58:37
There are two situations where we hit WebApkActivi
| |
151 orientation, source, themeColor, backgroundColor, webApkPackageN ame, | 154 if (TextUtils.isEmpty(url)) { |
155 url = manifestStartUrl; | |
156 shouldLoadUrlIfAlreadyRunning = false; | |
157 } | |
158 | |
159 return new WebApkInfo(id, url, shouldLoadUrlIfAlreadyRunning, scope, ico n, name, shortName, | |
160 displayMode, orientation, source, themeColor, backgroundColor, w ebApkPackageName, | |
152 shellApkVersion, manifestUrl, manifestStartUrl, iconUrlToMurmur2 HashMap); | 161 shellApkVersion, manifestUrl, manifestStartUrl, iconUrlToMurmur2 HashMap); |
153 } | 162 } |
154 | 163 |
155 protected WebApkInfo(String id, String url, String scope, Icon icon, String name, | 164 protected WebApkInfo(String id, String url, boolean shouldLoadUrlIfAlreadyRu nning, String scope, |
156 String shortName, int displayMode, int orientation, int source, long themeColor, | 165 Icon icon, String name, String shortName, int displayMode, int orien tation, int source, |
157 long backgroundColor, String webApkPackageName, int shellApkVersion, String manifestUrl, | 166 long themeColor, long backgroundColor, String webApkPackageName, int shellApkVersion, |
158 String manifestStartUrl, Map<String, String> iconUrlToMurmur2HashMap ) { | 167 String manifestUrl, String manifestStartUrl, |
168 Map<String, String> iconUrlToMurmur2HashMap) { | |
159 super(id, url, scope, icon, name, shortName, displayMode, orientation, s ource, themeColor, | 169 super(id, url, scope, icon, name, shortName, displayMode, orientation, s ource, themeColor, |
160 backgroundColor, false); | 170 backgroundColor, false); |
171 mShouldLoadUrlIfAlreadyRunning = shouldLoadUrlIfAlreadyRunning; | |
161 mWebApkPackageName = webApkPackageName; | 172 mWebApkPackageName = webApkPackageName; |
162 mShellApkVersion = shellApkVersion; | 173 mShellApkVersion = shellApkVersion; |
163 mManifestUrl = manifestUrl; | 174 mManifestUrl = manifestUrl; |
164 mManifestStartUrl = manifestStartUrl; | 175 mManifestStartUrl = manifestStartUrl; |
165 mIconUrlToMurmur2HashMap = iconUrlToMurmur2HashMap; | 176 mIconUrlToMurmur2HashMap = iconUrlToMurmur2HashMap; |
166 } | 177 } |
167 | 178 |
168 protected WebApkInfo() {} | 179 protected WebApkInfo() {} |
169 | 180 |
170 @Override | 181 @Override |
182 public boolean shouldLoadUrlIfAlreadyRunning() { | |
183 return mShouldLoadUrlIfAlreadyRunning; | |
184 } | |
185 | |
186 @Override | |
171 public String webApkPackageName() { | 187 public String webApkPackageName() { |
172 return mWebApkPackageName; | 188 return mWebApkPackageName; |
173 } | 189 } |
174 | 190 |
175 public int shellApkVersion() { | 191 public int shellApkVersion() { |
176 return mShellApkVersion; | 192 return mShellApkVersion; |
177 } | 193 } |
178 | 194 |
179 public String manifestUrl() { | 195 public String manifestUrl() { |
180 return mManifestUrl; | 196 return mManifestUrl; |
181 } | 197 } |
182 | 198 |
183 public String manifestStartUrl() { | 199 public String manifestStartUrl() { |
184 return mManifestStartUrl; | 200 return mManifestStartUrl; |
185 } | 201 } |
186 | 202 |
187 public Map<String, String> iconUrlToMurmur2HashMap() { | 203 public Map<String, String> iconUrlToMurmur2HashMap() { |
188 return mIconUrlToMurmur2HashMap; | 204 return mIconUrlToMurmur2HashMap; |
189 } | 205 } |
190 | 206 |
191 @Override | 207 @Override |
192 public void setWebappIntentExtras(Intent intent) { | 208 public void setWebappIntentExtras(Intent intent) { |
193 // For launching a {@link WebApkActivity}. | 209 // For launching a {@link WebApkActivity}. |
194 intent.putExtra(ShortcutHelper.EXTRA_URL, uri().toString()); | 210 if (shouldLoadUrlIfAlreadyRunning()) { |
211 intent.putExtra(ShortcutHelper.EXTRA_URL, uri().toString()); | |
212 } | |
195 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, source()); | 213 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, source()); |
196 intent.putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackageN ame()); | 214 intent.putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackageN ame()); |
197 } | 215 } |
198 | 216 |
199 /** | 217 /** |
200 * Extracts meta data from a WebAPK's Android Manifest. | 218 * Extracts meta data from a WebAPK's Android Manifest. |
201 * @param webApkPackageName WebAPK's package name. | 219 * @param webApkPackageName WebAPK's package name. |
202 * @return Bundle with the extracted meta data. | 220 * @return Bundle with the extracted meta data. |
203 */ | 221 */ |
204 private static Bundle extractWebApkMetaData(String webApkPackageName) { | 222 private static Bundle extractWebApkMetaData(String webApkPackageName) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 return ScreenOrientationValues.PORTRAIT; | 368 return ScreenOrientationValues.PORTRAIT; |
351 } else if (orientation.equals("portrait-primary")) { | 369 } else if (orientation.equals("portrait-primary")) { |
352 return ScreenOrientationValues.PORTRAIT_PRIMARY; | 370 return ScreenOrientationValues.PORTRAIT_PRIMARY; |
353 } else if (orientation.equals("portrait-secondary")) { | 371 } else if (orientation.equals("portrait-secondary")) { |
354 return ScreenOrientationValues.PORTRAIT_SECONDARY; | 372 return ScreenOrientationValues.PORTRAIT_SECONDARY; |
355 } else { | 373 } else { |
356 return ScreenOrientationValues.DEFAULT; | 374 return ScreenOrientationValues.DEFAULT; |
357 } | 375 } |
358 } | 376 } |
359 } | 377 } |
OLD | NEW |