| 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.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; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 private Bitmap mDecodedIcon; | 25 private Bitmap mDecodedIcon; |
| 26 private Uri mUri; | 26 private Uri mUri; |
| 27 private String mName; | 27 private String mName; |
| 28 private String mShortName; | 28 private String mShortName; |
| 29 private int mDisplayMode; | 29 private int mDisplayMode; |
| 30 private int mOrientation; | 30 private int mOrientation; |
| 31 private int mSource; | 31 private int mSource; |
| 32 private long mThemeColor; | 32 private long mThemeColor; |
| 33 private long mBackgroundColor; | 33 private long mBackgroundColor; |
| 34 private boolean mIsIconGenerated; | 34 private boolean mIsIconGenerated; |
| 35 private String mWebApkPackageName; |
| 35 | 36 |
| 36 public static WebappInfo createEmpty() { | 37 public static WebappInfo createEmpty() { |
| 37 return new WebappInfo(); | 38 return new WebappInfo(); |
| 38 } | 39 } |
| 39 | 40 |
| 40 private static String titleFromIntent(Intent intent) { | 41 private static String titleFromIntent(Intent intent) { |
| 41 // The reference to title has been kept for reasons of backward compatib
ility. For intents | 42 // The reference to title has been kept for reasons of backward compatib
ility. For intents |
| 42 // and shortcuts which were created before we utilized the concept of na
me and shortName, | 43 // and shortcuts which were created before we utilized the concept of na
me and shortName, |
| 43 // we set the name and shortName to be the title. | 44 // we set the name and shortName to be the title. |
| 44 String title = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXT
RA_TITLE); | 45 String title = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXT
RA_TITLE); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 73 ShortcutHelper.EXTRA_THEME_COLOR, | 74 ShortcutHelper.EXTRA_THEME_COLOR, |
| 74 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING); | 75 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING); |
| 75 long backgroundColor = IntentUtils.safeGetLongExtra(intent, | 76 long backgroundColor = IntentUtils.safeGetLongExtra(intent, |
| 76 ShortcutHelper.EXTRA_BACKGROUND_COLOR, | 77 ShortcutHelper.EXTRA_BACKGROUND_COLOR, |
| 77 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING); | 78 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING); |
| 78 boolean isIconGenerated = IntentUtils.safeGetBooleanExtra(intent, | 79 boolean isIconGenerated = IntentUtils.safeGetBooleanExtra(intent, |
| 79 ShortcutHelper.EXTRA_IS_ICON_GENERATED, false); | 80 ShortcutHelper.EXTRA_IS_ICON_GENERATED, false); |
| 80 | 81 |
| 81 String name = nameFromIntent(intent); | 82 String name = nameFromIntent(intent); |
| 82 String shortName = shortNameFromIntent(intent); | 83 String shortName = shortNameFromIntent(intent); |
| 84 String webApkPackageName = IntentUtils.safeGetStringExtra(intent, |
| 85 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME); |
| 83 | 86 |
| 84 return create(id, url, icon, name, shortName, displayMode, orientation,
source, | 87 return create(id, url, icon, name, shortName, displayMode, orientation,
source, |
| 85 themeColor, backgroundColor, isIconGenerated); | 88 themeColor, backgroundColor, isIconGenerated, webApkPackageName)
; |
| 86 } | 89 } |
| 87 | 90 |
| 88 /** | 91 /** |
| 89 * Construct a WebappInfo. | 92 * Construct a WebappInfo. |
| 90 * @param id ID for the webapp. | 93 * @param id ID for the webapp. |
| 91 * @param url URL for the webapp. | 94 * @param url URL for the webapp. |
| 92 * @param icon Icon to show for the webapp. | 95 * @param icon Icon to show for the webapp. |
| 93 * @param name Name of the webapp. | 96 * @param name Name of the webapp. |
| 94 * @param shortName The short name of the webapp. | 97 * @param shortName The short name of the webapp. |
| 95 * @param displayMode Display mode of the webapp. | 98 * @param displayMode Display mode of the webapp. |
| 96 * @param orientation Orientation of the webapp. | 99 * @param orientation Orientation of the webapp. |
| 97 * @param source Source where the webapp was added from. | 100 * @param source Source where the webapp was added from. |
| 98 * @param themeColor The theme color of the webapp. | 101 * @param themeColor The theme color of the webapp. |
| 99 * @param isIconGenerated Whether the |icon| was generated by Chromium. | 102 * @param isIconGenerated Whether the |icon| was generated by Chromium. |
| 103 * @param webApkPackageName The package of the WebAPK associated with the we
bapp. Null if |
| 104 * no WebAPK is associated with the webapp. |
| 100 */ | 105 */ |
| 101 public static WebappInfo create(String id, String url, String icon, String n
ame, | 106 public static WebappInfo create(String id, String url, String icon, String n
ame, |
| 102 String shortName, int displayMode, int orientation, int source, long
themeColor, | 107 String shortName, int displayMode, int orientation, int source, long
themeColor, |
| 103 long backgroundColor, boolean isIconGenerated) { | 108 long backgroundColor, boolean isIconGenerated, String webApkPackageN
ame) { |
| 104 if (id == null || url == null) { | 109 if (id == null || url == null) { |
| 105 Log.e("WebappInfo", "Data passed in was incomplete: " + id + ", " +
url); | 110 Log.e("WebappInfo", "Data passed in was incomplete: " + id + ", " +
url); |
| 106 return null; | 111 return null; |
| 107 } | 112 } |
| 108 | 113 |
| 109 Uri uri = Uri.parse(url); | 114 Uri uri = Uri.parse(url); |
| 110 return new WebappInfo(id, uri, icon, name, shortName, displayMode, orien
tation, source, | 115 return new WebappInfo(id, uri, icon, name, shortName, displayMode, orien
tation, source, |
| 111 themeColor, backgroundColor, isIconGenerated); | 116 themeColor, backgroundColor, isIconGenerated, webApkPackageName)
; |
| 112 } | 117 } |
| 113 | 118 |
| 114 private WebappInfo(String id, Uri uri, String encodedIcon, String name, Stri
ng shortName, | 119 private WebappInfo(String id, Uri uri, String encodedIcon, String name, Stri
ng shortName, |
| 115 int displayMode, int orientation, int source, long themeColor, | 120 int displayMode, int orientation, int source, long themeColor, |
| 116 long backgroundColor, boolean isIconGenerated) { | 121 long backgroundColor, boolean isIconGenerated, String webApkPackageN
ame) { |
| 117 mEncodedIcon = encodedIcon; | 122 mEncodedIcon = encodedIcon; |
| 118 mId = id; | 123 mId = id; |
| 119 mName = name; | 124 mName = name; |
| 120 mShortName = shortName; | 125 mShortName = shortName; |
| 121 mUri = uri; | 126 mUri = uri; |
| 122 mDisplayMode = displayMode; | 127 mDisplayMode = displayMode; |
| 123 mOrientation = orientation; | 128 mOrientation = orientation; |
| 124 mSource = source; | |
| 125 mThemeColor = themeColor; | 129 mThemeColor = themeColor; |
| 126 mBackgroundColor = backgroundColor; | 130 mBackgroundColor = backgroundColor; |
| 127 mIsIconGenerated = isIconGenerated; | 131 mIsIconGenerated = isIconGenerated; |
| 128 mIsInitialized = mUri != null; | 132 mIsInitialized = mUri != null; |
| 133 mWebApkPackageName = webApkPackageName; |
| 129 } | 134 } |
| 130 | 135 |
| 131 private WebappInfo() { | 136 private WebappInfo() { |
| 132 } | 137 } |
| 133 | 138 |
| 134 public boolean isInitialized() { | 139 public boolean isInitialized() { |
| 135 return mIsInitialized; | 140 return mIsInitialized; |
| 136 } | 141 } |
| 137 | 142 |
| 138 public String id() { | 143 public String id() { |
| 139 return mId; | 144 return mId; |
| 140 } | 145 } |
| 141 | 146 |
| 142 public Uri uri() { | 147 public Uri uri() { |
| 143 return mUri; | 148 return mUri; |
| 144 } | 149 } |
| 145 | 150 |
| 146 public String name() { | 151 public String name() { |
| 147 return mName; | 152 return mName; |
| 148 } | 153 } |
| 149 | 154 |
| 150 public String shortName() { | 155 public String shortName() { |
| 151 return mShortName; | 156 return mShortName; |
| 152 } | 157 } |
| 153 | 158 |
| 154 public int displayMode() { | 159 public int displayMode() { |
| 155 return mDisplayMode; | 160 return mDisplayMode; |
| 156 } | 161 } |
| 157 | 162 |
| 163 public String webApkPackageName() { |
| 164 return mWebApkPackageName; |
| 165 } |
| 166 |
| 158 public int orientation() { | 167 public int orientation() { |
| 159 return mOrientation; | 168 return mOrientation; |
| 160 } | 169 } |
| 161 | 170 |
| 162 public int source() { | 171 public int source() { |
| 163 return mSource; | 172 return mSource; |
| 164 } | 173 } |
| 165 | 174 |
| 166 /** | 175 /** |
| 167 * Theme color is actually a 32 bit unsigned integer which encodes a color | 176 * 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 Loading... |
| 227 return mIsIconGenerated; | 236 return mIsIconGenerated; |
| 228 } | 237 } |
| 229 | 238 |
| 230 /** | 239 /** |
| 231 * Sets extras on an Intent that will launch a WebappActivity. | 240 * Sets extras on an Intent that will launch a WebappActivity. |
| 232 * @param intent Intent that will be used to launch a WebappActivity. | 241 * @param intent Intent that will be used to launch a WebappActivity. |
| 233 */ | 242 */ |
| 234 public void setWebappIntentExtras(Intent intent) { | 243 public void setWebappIntentExtras(Intent intent) { |
| 235 intent.putExtra(ShortcutHelper.EXTRA_ID, id()); | 244 intent.putExtra(ShortcutHelper.EXTRA_ID, id()); |
| 236 intent.putExtra(ShortcutHelper.EXTRA_URL, uri().toString()); | 245 intent.putExtra(ShortcutHelper.EXTRA_URL, uri().toString()); |
| 237 intent.putExtra(ShortcutHelper.EXTRA_SCOPE, | |
| 238 ShortcutHelper.getScopeFromUrl(uri().toString())); | |
| 239 intent.putExtra(ShortcutHelper.EXTRA_ICON, encodedIcon()); | 246 intent.putExtra(ShortcutHelper.EXTRA_ICON, encodedIcon()); |
| 240 intent.putExtra(ShortcutHelper.EXTRA_VERSION, ShortcutHelper.WEBAPP_SHOR
TCUT_VERSION); | 247 intent.putExtra(ShortcutHelper.EXTRA_VERSION, ShortcutHelper.WEBAPP_SHOR
TCUT_VERSION); |
| 241 intent.putExtra(ShortcutHelper.EXTRA_NAME, name()); | 248 intent.putExtra(ShortcutHelper.EXTRA_NAME, name()); |
| 242 intent.putExtra(ShortcutHelper.EXTRA_SHORT_NAME, shortName()); | 249 intent.putExtra(ShortcutHelper.EXTRA_SHORT_NAME, shortName()); |
| 243 intent.putExtra(ShortcutHelper.EXTRA_DISPLAY_MODE, displayMode()); | 250 intent.putExtra(ShortcutHelper.EXTRA_DISPLAY_MODE, displayMode()); |
| 244 intent.putExtra(ShortcutHelper.EXTRA_ORIENTATION, orientation()); | 251 intent.putExtra(ShortcutHelper.EXTRA_ORIENTATION, orientation()); |
| 245 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, source()); | 252 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, source()); |
| 246 intent.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, themeColor()); | 253 intent.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, themeColor()); |
| 247 intent.putExtra(ShortcutHelper.EXTRA_BACKGROUND_COLOR, backgroundColor()
); | 254 intent.putExtra(ShortcutHelper.EXTRA_BACKGROUND_COLOR, backgroundColor()
); |
| 248 intent.putExtra(ShortcutHelper.EXTRA_IS_ICON_GENERATED, isIconGenerated(
)); | 255 intent.putExtra(ShortcutHelper.EXTRA_IS_ICON_GENERATED, isIconGenerated(
)); |
| 256 if (webApkPackageName() != null) { |
| 257 intent.putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, webApkPack
ageName()); |
| 258 } |
| 249 } | 259 } |
| 250 | 260 |
| 251 /** | 261 /** |
| 252 * Returns true if the WebappInfo was created for an Intent fired from a lau
ncher shortcut (as | 262 * Returns true if the WebappInfo was created for an Intent fired from a lau
ncher shortcut (as |
| 253 * opposed to an intent from a push notification or other internal source). | 263 * opposed to an intent from a push notification or other internal source). |
| 254 */ | 264 */ |
| 255 public boolean isLaunchedFromHomescreen() { | 265 public boolean isLaunchedFromHomescreen() { |
| 256 return source() != ShortcutSource.NOTIFICATION; | 266 return source() != ShortcutSource.NOTIFICATION; |
| 257 } | 267 } |
| 258 } | 268 } |
| OLD | NEW |