| 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; | 129 mSource = source; |
| 125 mThemeColor = themeColor; | 130 mThemeColor = themeColor; |
| 126 mBackgroundColor = backgroundColor; | 131 mBackgroundColor = backgroundColor; |
| 127 mIsIconGenerated = isIconGenerated; | 132 mIsIconGenerated = isIconGenerated; |
| 128 mIsInitialized = mUri != null; | 133 mIsInitialized = mUri != null; |
| 134 mWebApkPackageName = webApkPackageName; |
| 129 } | 135 } |
| 130 | 136 |
| 131 private WebappInfo() { | 137 private WebappInfo() { |
| 132 } | 138 } |
| 133 | 139 |
| 134 public boolean isInitialized() { | 140 public boolean isInitialized() { |
| 135 return mIsInitialized; | 141 return mIsInitialized; |
| 136 } | 142 } |
| 137 | 143 |
| 138 public String id() { | 144 public String id() { |
| 139 return mId; | 145 return mId; |
| 140 } | 146 } |
| 141 | 147 |
| 142 public Uri uri() { | 148 public Uri uri() { |
| 143 return mUri; | 149 return mUri; |
| 144 } | 150 } |
| 145 | 151 |
| 146 public String name() { | 152 public String name() { |
| 147 return mName; | 153 return mName; |
| 148 } | 154 } |
| 149 | 155 |
| 150 public String shortName() { | 156 public String shortName() { |
| 151 return mShortName; | 157 return mShortName; |
| 152 } | 158 } |
| 153 | 159 |
| 154 public int displayMode() { | 160 public int displayMode() { |
| 155 return mDisplayMode; | 161 return mDisplayMode; |
| 156 } | 162 } |
| 157 | 163 |
| 164 public String webApkPackageName() { |
| 165 return mWebApkPackageName; |
| 166 } |
| 167 |
| 158 public int orientation() { | 168 public int orientation() { |
| 159 return mOrientation; | 169 return mOrientation; |
| 160 } | 170 } |
| 161 | 171 |
| 162 public int source() { | 172 public int source() { |
| 163 return mSource; | 173 return mSource; |
| 164 } | 174 } |
| 165 | 175 |
| 166 /** | 176 /** |
| 167 * Theme color is actually a 32 bit unsigned integer which encodes a color | 177 * Theme color is actually a 32 bit unsigned integer which encodes a color |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 intent.putExtra(ShortcutHelper.EXTRA_ICON, encodedIcon()); | 249 intent.putExtra(ShortcutHelper.EXTRA_ICON, encodedIcon()); |
| 240 intent.putExtra(ShortcutHelper.EXTRA_VERSION, ShortcutHelper.WEBAPP_SHOR
TCUT_VERSION); | 250 intent.putExtra(ShortcutHelper.EXTRA_VERSION, ShortcutHelper.WEBAPP_SHOR
TCUT_VERSION); |
| 241 intent.putExtra(ShortcutHelper.EXTRA_NAME, name()); | 251 intent.putExtra(ShortcutHelper.EXTRA_NAME, name()); |
| 242 intent.putExtra(ShortcutHelper.EXTRA_SHORT_NAME, shortName()); | 252 intent.putExtra(ShortcutHelper.EXTRA_SHORT_NAME, shortName()); |
| 243 intent.putExtra(ShortcutHelper.EXTRA_DISPLAY_MODE, displayMode()); | 253 intent.putExtra(ShortcutHelper.EXTRA_DISPLAY_MODE, displayMode()); |
| 244 intent.putExtra(ShortcutHelper.EXTRA_ORIENTATION, orientation()); | 254 intent.putExtra(ShortcutHelper.EXTRA_ORIENTATION, orientation()); |
| 245 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, source()); | 255 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, source()); |
| 246 intent.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, themeColor()); | 256 intent.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, themeColor()); |
| 247 intent.putExtra(ShortcutHelper.EXTRA_BACKGROUND_COLOR, backgroundColor()
); | 257 intent.putExtra(ShortcutHelper.EXTRA_BACKGROUND_COLOR, backgroundColor()
); |
| 248 intent.putExtra(ShortcutHelper.EXTRA_IS_ICON_GENERATED, isIconGenerated(
)); | 258 intent.putExtra(ShortcutHelper.EXTRA_IS_ICON_GENERATED, isIconGenerated(
)); |
| 259 if (webApkPackageName() != null) { |
| 260 intent.putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, webApkPack
ageName()); |
| 261 } |
| 249 } | 262 } |
| 250 | 263 |
| 251 /** | 264 /** |
| 252 * Returns true if the WebappInfo was created for an Intent fired from a lau
ncher shortcut (as | 265 * 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). | 266 * opposed to an intent from a push notification or other internal source). |
| 254 */ | 267 */ |
| 255 public boolean isLaunchedFromHomescreen() { | 268 public boolean isLaunchedFromHomescreen() { |
| 256 return source() != ShortcutSource.NOTIFICATION; | 269 return source() != ShortcutSource.NOTIFICATION; |
| 257 } | 270 } |
| 258 } | 271 } |
| OLD | NEW |