Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappInfo.java

Issue 1989283002: Upstream: Launch WebApkActivity from WebAPK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.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.graphics.Bitmap; 8 import android.graphics.Bitmap;
9 import android.net.Uri; 9 import android.net.Uri;
10 import android.util.Log; 10 import android.util.Log;
11 11
12 import org.chromium.chrome.browser.ShortcutHelper; 12 import org.chromium.chrome.browser.ShortcutHelper;
13 import org.chromium.chrome.browser.ShortcutSource; 13 import org.chromium.chrome.browser.ShortcutSource;
14 import org.chromium.chrome.browser.util.IntentUtils; 14 import org.chromium.chrome.browser.util.IntentUtils;
15 import org.chromium.content_public.common.ScreenOrientationValues; 15 import org.chromium.content_public.common.ScreenOrientationValues;
16 16
17 /** 17 /**
18 * Stores info about a web app. 18 * Stores info about a web app.
19 */ 19 */
20 public class WebappInfo { 20 public class WebappInfo {
21 private boolean mIsInitialized; 21 private boolean mIsInitialized;
22 private String mId; 22 private String mId;
23 private String mEncodedIcon; 23 private String mEncodedIcon;
24 private Bitmap mDecodedIcon; 24 private Bitmap mDecodedIcon;
25 private Uri mUri; 25 private Uri mUri;
26 private Uri mScope;
pkotwicz 2016/05/18 23:00:17 I don't think that this member is needed at all. I
Xi Han 2016/05/19 18:31:49 Since WebAPK will have two scopes, the "launch sco
26 private String mName; 27 private String mName;
27 private String mShortName; 28 private String mShortName;
28 private int mOrientation; 29 private int mOrientation;
29 private int mSource; 30 private int mSource;
30 private long mThemeColor; 31 private long mThemeColor;
31 private long mBackgroundColor; 32 private long mBackgroundColor;
32 private boolean mIsIconGenerated; 33 private boolean mIsIconGenerated;
34 private String mPackageName;
33 35
34 public static WebappInfo createEmpty() { 36 public static WebappInfo createEmpty() {
35 return new WebappInfo(); 37 return new WebappInfo();
36 } 38 }
37 39
40 public static String scopeFromIntent(Intent intent) {
41 String scope = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXT RA_SCOPE);
42 return scope == null ? "" : scope;
43 }
44
38 private static String titleFromIntent(Intent intent) { 45 private static String titleFromIntent(Intent intent) {
39 // The reference to title has been kept for reasons of backward compatib ility. For intents 46 // The reference to title has been kept for reasons of backward compatib ility. For intents
40 // and shortcuts which were created before we utilized the concept of na me and shortName, 47 // and shortcuts which were created before we utilized the concept of na me and shortName,
41 // we set the name and shortName to be the title. 48 // we set the name and shortName to be the title.
42 String title = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXT RA_TITLE); 49 String title = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXT RA_TITLE);
43 return title == null ? "" : title; 50 return title == null ? "" : title;
44 } 51 }
45 52
46 public static String nameFromIntent(Intent intent) { 53 public static String nameFromIntent(Intent intent) {
47 String name = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTR A_NAME); 54 String name = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTR A_NAME);
48 return name == null ? titleFromIntent(intent) : name; 55 return name == null ? titleFromIntent(intent) : name;
49 } 56 }
50 57
51 public static String shortNameFromIntent(Intent intent) { 58 public static String shortNameFromIntent(Intent intent) {
52 String shortName = IntentUtils.safeGetStringExtra(intent, ShortcutHelper .EXTRA_SHORT_NAME); 59 String shortName = IntentUtils.safeGetStringExtra(intent, ShortcutHelper .EXTRA_SHORT_NAME);
53 return shortName == null ? titleFromIntent(intent) : shortName; 60 return shortName == null ? titleFromIntent(intent) : shortName;
54 } 61 }
55 62
63 public static String packageNameFromIntent(Intent intent) {
64 String packageName = IntentUtils.safeGetStringExtra(
65 intent, ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME);
66 return packageName == null ? "" : packageName;
67 }
68
56 /** 69 /**
57 * Construct a WebappInfo. 70 * Construct a WebappInfo.
58 * @param intent Intent containing info about the app. 71 * @param intent Intent containing info about the app.
59 */ 72 */
60 public static WebappInfo create(Intent intent) { 73 public static WebappInfo create(Intent intent) {
61 String id = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_ ID); 74 String id = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_ ID);
62 String icon = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTR A_ICON); 75 String icon = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTR A_ICON);
63 String url = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA _URL); 76 String url = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA _URL);
77 String scope = scopeFromIntent(intent);
64 int orientation = IntentUtils.safeGetIntExtra(intent, 78 int orientation = IntentUtils.safeGetIntExtra(intent,
65 ShortcutHelper.EXTRA_ORIENTATION, ScreenOrientationValues.DEFAUL T); 79 ShortcutHelper.EXTRA_ORIENTATION, ScreenOrientationValues.DEFAUL T);
66 int source = IntentUtils.safeGetIntExtra(intent, 80 int source = IntentUtils.safeGetIntExtra(intent,
67 ShortcutHelper.EXTRA_SOURCE, ShortcutSource.UNKNOWN); 81 ShortcutHelper.EXTRA_SOURCE, ShortcutSource.UNKNOWN);
68 long themeColor = IntentUtils.safeGetLongExtra(intent, 82 long themeColor = IntentUtils.safeGetLongExtra(intent,
69 ShortcutHelper.EXTRA_THEME_COLOR, 83 ShortcutHelper.EXTRA_THEME_COLOR,
70 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING); 84 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING);
71 long backgroundColor = IntentUtils.safeGetLongExtra(intent, 85 long backgroundColor = IntentUtils.safeGetLongExtra(intent,
72 ShortcutHelper.EXTRA_BACKGROUND_COLOR, 86 ShortcutHelper.EXTRA_BACKGROUND_COLOR,
73 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING); 87 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING);
74 boolean isIconGenerated = IntentUtils.safeGetBooleanExtra(intent, 88 boolean isIconGenerated = IntentUtils.safeGetBooleanExtra(intent,
75 ShortcutHelper.EXTRA_IS_ICON_GENERATED, false); 89 ShortcutHelper.EXTRA_IS_ICON_GENERATED, false);
76 90
77 String name = nameFromIntent(intent); 91 String name = nameFromIntent(intent);
78 String shortName = shortNameFromIntent(intent); 92 String shortName = shortNameFromIntent(intent);
93 String packageName = packageNameFromIntent(intent);
79 94
80 return create(id, url, icon, name, shortName, orientation, source, 95 return create(id, url, scope, icon, name, shortName, orientation, source ,
81 themeColor, backgroundColor, isIconGenerated); 96 themeColor, backgroundColor, isIconGenerated, packageName);
82 } 97 }
83 98
84 /** 99 /**
85 * Construct a WebappInfo. 100 * Construct a WebappInfo.
86 * @param id ID for the webapp. 101 * @param id ID for the webapp.
87 * @param url URL for the webapp. 102 * @param url URL for the webapp.
103 * @param scope Scope of URLs that the WebAPK can navigate to.
88 * @param icon Icon to show for the webapp. 104 * @param icon Icon to show for the webapp.
89 * @param name Name of the webapp. 105 * @param name Name of the webapp.
90 * @param shortName The short name of the webapp. 106 * @param shortName The short name of the webapp.
91 * @param orientation Orientation of the webapp. 107 * @param orientation Orientation of the webapp.
92 * @param source Source where the webapp was added from. 108 * @param source Source where the webapp was added from.
93 * @param themeColor The theme color of the webapp. 109 * @param themeColor The theme color of the webapp.
94 * @param isIconGenerated Whether the |icon| was generated by Chromium. 110 * @param isIconGenerated Whether the |icon| was generated by Chromium.
111 * @param packageName The package name of the WebAPK that intents to start t he WebApp
112 * activity.
95 */ 113 */
96 public static WebappInfo create(String id, String url, String icon, String n ame, 114 public static WebappInfo create(String id, String url, String scope, String icon, String name,
97 String shortName, int orientation, int source, long themeColor, 115 String shortName, int orientation, int source, long themeColor, long backgroundColor,
98 long backgroundColor, boolean isIconGenerated) { 116 boolean isIconGenerated, String packageName) {
99 if (id == null || url == null) { 117 if (id == null || url == null) {
100 Log.e("WebappInfo", "Data passed in was incomplete: " + id + ", " + url); 118 Log.e("WebappInfo", "Data passed in was incomplete: " + id + ", " + url);
101 return null; 119 return null;
102 } 120 }
103 121
104 Uri uri = Uri.parse(url); 122 Uri uri = Uri.parse(url);
105 return new WebappInfo(id, uri, icon, name, shortName, orientation, sourc e, 123 Uri scope_uri = scope == null ? Uri.parse("") : Uri.parse(scope);
106 themeColor, backgroundColor, isIconGenerated); 124 return new WebappInfo(id, uri, scope_uri, icon, name, shortName, orienta tion, source,
125 themeColor, backgroundColor, isIconGenerated, packageName);
107 } 126 }
108 127
109 private WebappInfo(String id, Uri uri, String encodedIcon, String name, 128 private WebappInfo(String id, Uri uri, Uri scope, String encodedIcon, String name,
110 String shortName, int orientation, int source, long themeColor, 129 String shortName, int orientation, int source, long themeColor, long backgroundColor,
111 long backgroundColor, boolean isIconGenerated) { 130 boolean isIconGenerated, String packageName) {
112 mEncodedIcon = encodedIcon; 131 mEncodedIcon = encodedIcon;
113 mId = id; 132 mId = id;
114 mName = name; 133 mName = name;
115 mShortName = shortName; 134 mShortName = shortName;
116 mUri = uri; 135 mUri = uri;
136 mScope = scope;
117 mOrientation = orientation; 137 mOrientation = orientation;
118 mSource = source; 138 mSource = source;
119 mThemeColor = themeColor; 139 mThemeColor = themeColor;
120 mBackgroundColor = backgroundColor; 140 mBackgroundColor = backgroundColor;
121 mIsIconGenerated = isIconGenerated; 141 mIsIconGenerated = isIconGenerated;
122 mIsInitialized = mUri != null; 142 mIsInitialized = mUri != null;
143 mPackageName = packageName;
123 } 144 }
124 145
125 private WebappInfo() { 146 private WebappInfo() {
126 } 147 }
127 148
128 /**
129 * Copies all the fields from the given WebappInfo into this instance.
130 * @param newInfo Information about the new webapp.
131 */
132 void copy(WebappInfo newInfo) {
133 mIsInitialized = newInfo.mIsInitialized;
134 mEncodedIcon = newInfo.mEncodedIcon;
135 mDecodedIcon = newInfo.mDecodedIcon;
136 mId = newInfo.mId;
137 mUri = newInfo.mUri;
138 mName = newInfo.mName;
139 mShortName = newInfo.mShortName;
140 mOrientation = newInfo.mOrientation;
141 mSource = newInfo.mSource;
142 mThemeColor = newInfo.mThemeColor;
143 mBackgroundColor = newInfo.mBackgroundColor;
144 mIsIconGenerated = newInfo.mIsIconGenerated;
145 }
146
147 public boolean isInitialized() { 149 public boolean isInitialized() {
148 return mIsInitialized; 150 return mIsInitialized;
149 } 151 }
150 152
151 public String id() { 153 public String id() {
152 return mId; 154 return mId;
153 } 155 }
154 156
155 public Uri uri() { 157 public Uri uri() {
156 return mUri; 158 return mUri;
157 } 159 }
158 160
161 public Uri scope() {
162 return mScope;
163 }
164
159 public String name() { 165 public String name() {
160 return mName; 166 return mName;
161 } 167 }
162 168
163 public String shortName() { 169 public String shortName() {
164 return mShortName; 170 return mShortName;
165 } 171 }
166 172
pkotwicz 2016/05/18 23:00:17 Can we rename this function to getWebApkPackage()
Xi Han 2016/05/19 18:31:50 Change to WebApkPackageName.
173 public String packageName() {
174 return mPackageName;
175 }
176
167 public int orientation() { 177 public int orientation() {
168 return mOrientation; 178 return mOrientation;
169 } 179 }
170 180
171 public int source() { 181 public int source() {
172 return mSource; 182 return mSource;
173 } 183 }
174 184
175 /** 185 /**
176 * Theme color is actually a 32 bit unsigned integer which encodes a color 186 * Theme color is actually a 32 bit unsigned integer which encodes a color
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 return mIsIconGenerated; 246 return mIsIconGenerated;
237 } 247 }
238 248
239 /** 249 /**
240 * Sets extras on an Intent that will launch a WebappActivity. 250 * Sets extras on an Intent that will launch a WebappActivity.
241 * @param intent Intent that will be used to launch a WebappActivity. 251 * @param intent Intent that will be used to launch a WebappActivity.
242 */ 252 */
243 public void setWebappIntentExtras(Intent intent) { 253 public void setWebappIntentExtras(Intent intent) {
244 intent.putExtra(ShortcutHelper.EXTRA_ID, id()); 254 intent.putExtra(ShortcutHelper.EXTRA_ID, id());
245 intent.putExtra(ShortcutHelper.EXTRA_URL, uri().toString()); 255 intent.putExtra(ShortcutHelper.EXTRA_URL, uri().toString());
246 intent.putExtra(ShortcutHelper.EXTRA_SCOPE, 256 intent.putExtra(ShortcutHelper.EXTRA_SCOPE, scope().toString());
247 ShortcutHelper.getScopeFromUrl(uri().toString()));
248 intent.putExtra(ShortcutHelper.EXTRA_ICON, encodedIcon()); 257 intent.putExtra(ShortcutHelper.EXTRA_ICON, encodedIcon());
249 intent.putExtra(ShortcutHelper.EXTRA_VERSION, ShortcutHelper.WEBAPP_SHOR TCUT_VERSION); 258 intent.putExtra(ShortcutHelper.EXTRA_VERSION, ShortcutHelper.WEBAPP_SHOR TCUT_VERSION);
250 intent.putExtra(ShortcutHelper.EXTRA_NAME, name()); 259 intent.putExtra(ShortcutHelper.EXTRA_NAME, name());
251 intent.putExtra(ShortcutHelper.EXTRA_SHORT_NAME, shortName()); 260 intent.putExtra(ShortcutHelper.EXTRA_SHORT_NAME, shortName());
252 intent.putExtra(ShortcutHelper.EXTRA_ORIENTATION, orientation()); 261 intent.putExtra(ShortcutHelper.EXTRA_ORIENTATION, orientation());
253 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, source()); 262 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, source());
254 intent.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, themeColor()); 263 intent.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, themeColor());
255 intent.putExtra(ShortcutHelper.EXTRA_BACKGROUND_COLOR, backgroundColor() ); 264 intent.putExtra(ShortcutHelper.EXTRA_BACKGROUND_COLOR, backgroundColor() );
256 intent.putExtra(ShortcutHelper.EXTRA_IS_ICON_GENERATED, isIconGenerated( )); 265 intent.putExtra(ShortcutHelper.EXTRA_IS_ICON_GENERATED, isIconGenerated( ));
266 intent.putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, packageName()) ;
257 } 267 }
258 268
259 /** 269 /**
260 * Returns true if the WebappInfo was created for an Intent fired from a lau ncher shortcut (as 270 * Returns true if the WebappInfo was created for an Intent fired from a lau ncher shortcut (as
261 * opposed to an intent from a push notification or other internal source). 271 * opposed to an intent from a push notification or other internal source).
262 */ 272 */
263 public boolean isLaunchedFromHomescreen() { 273 public boolean isLaunchedFromHomescreen() {
264 return source() != ShortcutSource.NOTIFICATION; 274 return source() != ShortcutSource.NOTIFICATION;
265 } 275 }
266 } 276 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698