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

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

Issue 2335843002: Remove the logic of fetching metadata when launching WebAPKs. (Closed)
Patch Set: Update comment. Created 4 years, 3 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.graphics.Color; 9 import android.graphics.Color;
10 import android.graphics.drawable.Drawable; 10 import android.graphics.drawable.Drawable;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 226 }
227 227
228 /** 228 /**
229 * @return Structure containing data about the webapp currently displayed. 229 * @return Structure containing data about the webapp currently displayed.
230 * The return value should not be cached. 230 * The return value should not be cached.
231 */ 231 */
232 WebappInfo getWebappInfo() { 232 WebappInfo getWebappInfo() {
233 return mWebappInfo; 233 return mWebappInfo;
234 } 234 }
235 235
236 protected int getBackgroundColor() { 236 private void initializeWebappData() {
237 return ColorUtils.getOpaqueColor(mWebappInfo.backgroundColor( 237 final int backgroundColor = ColorUtils.getOpaqueColor(mWebappInfo.backgr oundColor(
238 ApiCompatibilityUtils.getColor(getResources(), R.color.webapp_de fault_bg))); 238 ApiCompatibilityUtils.getColor(getResources(), R.color.webapp_de fault_bg)));
239 }
240 239
241 private void initializeWebappData() {
242 mSplashScreen = new FrameLayout(this); 240 mSplashScreen = new FrameLayout(this);
243 mSplashScreen.setBackgroundColor(getBackgroundColor()); 241 mSplashScreen.setBackgroundColor(backgroundColor);
244 242
245 ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content); 243 ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
246 contentView.addView(mSplashScreen); 244 contentView.addView(mSplashScreen);
247 245
248 mWebappUma.splashscreenVisible(); 246 mWebappUma.splashscreenVisible();
249 mWebappUma.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgro undColor() 247 mWebappUma.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgro undColor()
250 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM 248 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
251 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT); 249 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);
250 mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor()
251 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
252 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);
252 253
254 initializeSplashScreenWidgets(backgroundColor);
255 }
256
257 protected void initializeSplashScreenWidgets(final int backgroundColor) {
253 WebappRegistry.getWebappDataStorage(this, mWebappInfo.id(), 258 WebappRegistry.getWebappDataStorage(this, mWebappInfo.id(),
254 new WebappRegistry.FetchWebappDataStorageCallback() { 259 new WebappRegistry.FetchWebappDataStorageCallback() {
255 @Override 260 @Override
256 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) { 261 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) {
257 onDataStorageFetched(storage); 262 if (storage == null) {
263 onStorageIsNull(backgroundColor);
264 return;
265 }
266 updateStorage(storage);
267
268 // Retrieve the splash image if it exists.
269 storage.getSplashScreenImage(new WebappDataStorage.Fetch Callback<Bitmap>() {
270 @Override
271 public void onDataRetrieved(Bitmap splashImage) {
272 initializeSplashScreenWidgets(backgroundColor, s plashImage);
273 }
274 });
258 } 275 }
259 } 276 }
260 ); 277 );
261 } 278 }
262 279
263 protected void recordSplashScreenThemeColorUma() { 280 protected void onStorageIsNull(int backgroundColor) {}
264 mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor()
265 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
266 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);
267 }
268 281
269 protected void onDataStorageFetched(WebappDataStorage storage) { 282 protected void updateStorage(WebappDataStorage storage) {
270 recordSplashScreenThemeColorUma();
271 if (storage == null) return;
272
273 // The information in the WebappDataStorage may have been purged by the 283 // The information in the WebappDataStorage may have been purged by the
274 // user clearing their history or not launching the web app recently. 284 // user clearing their history or not launching the web app recently.
275 // Restore the data if necessary from the intent. 285 // Restore the data if necessary from the intent.
276 storage.updateFromShortcutIntent(getIntent()); 286 storage.updateFromShortcutIntent(getIntent());
277 287
278 // A recent last used time is the indicator that the web app is still 288 // A recent last used time is the indicator that the web app is still
279 // present on the home screen, and enables sources such as notifications to 289 // present on the home screen, and enables sources such as notifications to
280 // launch web apps. Thus, we do not update the last used time when the w eb 290 // launch web apps. Thus, we do not update the last used time when the w eb
281 // app is not directly launched from the home screen, as this interferes 291 // app is not directly launched from the home screen, as this interferes
282 // with the heuristic. 292 // with the heuristic.
283 if (mWebappInfo.isLaunchedFromHomescreen()) { 293 if (mWebappInfo.isLaunchedFromHomescreen()) {
284 storage.updateLastUsedTime(); 294 storage.updateLastUsedTime();
285 } 295 }
286
287 retrieveSplashScreenImage(storage);
288 } 296 }
289 297
290 protected void retrieveSplashScreenImage(WebappDataStorage storage) { 298 protected void initializeSplashScreenWidgets(int backgroundColor, Bitmap spl ashImage) {
291 // Retrieve the splash image if it exists.
292 storage.getSplashScreenImage(new WebappDataStorage.FetchCallback<Bitmap> () {
293 @Override
294 public void onDataRetrieved(Bitmap splashImage) {
295 initializeSplashScreenWidgets(splashImage);
296 }
297 });
298 }
299
300 protected void initializeSplashScreenWidgets(Bitmap splashImage) {
301 Bitmap displayIcon = splashImage == null ? mWebappInfo.icon() : splashIm age; 299 Bitmap displayIcon = splashImage == null ? mWebappInfo.icon() : splashIm age;
302 int minimiumSizeThreshold = getResources().getDimensionPixelSize( 300 int minimiumSizeThreshold = getResources().getDimensionPixelSize(
303 R.dimen.webapp_splash_image_size_minimum); 301 R.dimen.webapp_splash_image_size_minimum);
304 int bigThreshold = getResources().getDimensionPixelSize( 302 int bigThreshold = getResources().getDimensionPixelSize(
305 R.dimen.webapp_splash_image_size_threshold); 303 R.dimen.webapp_splash_image_size_threshold);
306 304
307 // Inflate the correct layout for the image. 305 // Inflate the correct layout for the image.
308 int layoutId; 306 int layoutId;
309 if (displayIcon == null || displayIcon.getWidth() < minimiumSizeThreshol d 307 if (displayIcon == null || displayIcon.getWidth() < minimiumSizeThreshol d
310 || (displayIcon == mWebappInfo.icon() && mWebappInfo.isIconGener ated())) { 308 || (displayIcon == mWebappInfo.icon() && mWebappInfo.isIconGener ated())) {
(...skipping 28 matching lines...) Expand all
339 .inflate(layoutId, mSplashScreen, true); 337 .inflate(layoutId, mSplashScreen, true);
340 338
341 // Set up the elements of the splash screen. 339 // Set up the elements of the splash screen.
342 TextView appNameView = (TextView) subLayout.findViewById( 340 TextView appNameView = (TextView) subLayout.findViewById(
343 R.id.webapp_splash_screen_name); 341 R.id.webapp_splash_screen_name);
344 ImageView splashIconView = (ImageView) subLayout.findViewById( 342 ImageView splashIconView = (ImageView) subLayout.findViewById(
345 R.id.webapp_splash_screen_icon); 343 R.id.webapp_splash_screen_icon);
346 appNameView.setText(mWebappInfo.name()); 344 appNameView.setText(mWebappInfo.name());
347 if (splashIconView != null) splashIconView.setImageBitmap(displayIcon); 345 if (splashIconView != null) splashIconView.setImageBitmap(displayIcon);
348 346
349 if (ColorUtils.shouldUseLightForegroundOnBackground(getBackgroundColor() )) { 347 if (ColorUtils.shouldUseLightForegroundOnBackground(backgroundColor)) {
350 appNameView.setTextColor(ApiCompatibilityUtils.getColor(getResources (), 348 appNameView.setTextColor(ApiCompatibilityUtils.getColor(getResources (),
351 R.color.webapp_splash_title_light)); 349 R.color.webapp_splash_title_light));
352 } 350 }
353 } 351 }
354 352
355 private void updateUrlBar() { 353 private void updateUrlBar() {
356 Tab tab = getActivityTab(); 354 Tab tab = getActivityTab();
357 if (tab == null || mUrlBar == null) return; 355 if (tab == null || mUrlBar == null) return;
358 mUrlBar.update(tab.getUrl(), tab.getSecurityLevel()); 356 mUrlBar.update(tab.getUrl(), tab.getSecurityLevel());
359 } 357 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 return new WebappDelegateFactory(this); 575 return new WebappDelegateFactory(this);
578 } 576 }
579 577
580 // We're temporarily disable CS on webapp since there are some issues. (http ://crbug.com/471950) 578 // We're temporarily disable CS on webapp since there are some issues. (http ://crbug.com/471950)
581 // TODO(changwan): re-enable it once the issues are resolved. 579 // TODO(changwan): re-enable it once the issues are resolved.
582 @Override 580 @Override
583 protected boolean isContextualSearchAllowed() { 581 protected boolean isContextualSearchAllowed() {
584 return false; 582 return false;
585 } 583 }
586 } 584 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698