Commit b6c54b82 authored by hanxi's avatar hanxi Committed by Commit bot

Remove the logic of fetching metadata when launching WebAPKs.

The logic was introduced in CL (https://codereview.chromium.org/2126583002/).
Since all its metadata are stored in the WebAPK's AndroidManifest.xml, so
there is no need to fetch metadata like theme color etc. during launch
the WebAPK. Revert the logic back.

BUG=624834

Review-Url: https://codereview.chromium.org/2335843002
Cr-Commit-Position: refs/heads/master@{#418918}
parent 58dce46b
......@@ -17,7 +17,6 @@ import org.chromium.chrome.browser.tab.TabDelegateFactory;
import org.chromium.chrome.browser.tab.TabRedirectHandler;
import org.chromium.components.navigation_interception.NavigationParams;
import org.chromium.content.browser.ChildProcessCreationParams;
import org.chromium.content.browser.ScreenOrientationProvider;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.ui.base.PageTransition;
import org.chromium.webapk.lib.client.WebApkServiceConnectionManager;
......@@ -48,43 +47,29 @@ public class WebApkActivity extends WebappActivity {
}
@Override
protected void onDataStorageFetched(WebappDataStorage storage) {
if (storage == null) {
recordSplashScreenThemeColorUma();
initializeSplashScreenWidgets(null);
// Register the WebAPK. It is possible that a WebAPK's meta data was deleted when user
// cleared Chrome's data. When it is launching again, we know that the WebAPK is
// still installed, so re-register it.
WebappRegistry.registerWebapp(WebApkActivity.this, getId(),
new WebappRegistry.FetchWebappDataStorageCallback() {
@Override
public void onWebappDataStorageRetrieved(
WebappDataStorage storage) {
storage.updateFromShortcutIntent(getIntent());
// Initialize the update related timestamps to the registration time.
storage.updateTimeOfLastCheckForUpdatedWebManifest();
storage.updateTimeOfLastWebApkUpdateRequestCompletion();
}
});
return;
}
// Update WebappInfo from WebappDataStorage because the information in WebappDataStorage
// is more up to date than the information in the launch intent. Whenever the Web Manifest
// changes, WebappDataStorage is updated. Depending on which of the Web Manifest's fields
// change a new WebAPK may or may not be downloaded from the WebAPK server.
// TODO(hanxi): Introduces data fetcher to detect web manifest changes and update
// SharedPreference for WebAPKs.
int orientation = storage.getOrientation();
if (mWebappInfo.orientation() != orientation) {
mWebappInfo.updateOrientation(orientation);
ScreenOrientationProvider.lockOrientation(
(byte) mWebappInfo.orientation(), WebApkActivity.this);
}
mWebappInfo.updateThemeColor(storage.getThemeColor());
recordSplashScreenThemeColorUma();
storage.updateLastUsedTime();
retrieveSplashScreenImage(storage);
protected void onStorageIsNull(final int backgroundColor) {
// Register the WebAPK. It is possible that a WebAPK's meta data was deleted when user
// cleared Chrome's data. When it is launched again, we know that the WebAPK is still
// installed, so re-register it.
WebappRegistry.registerWebapp(WebApkActivity.this, getId(),
new WebappRegistry.FetchWebappDataStorageCallback() {
@Override
public void onWebappDataStorageRetrieved(WebappDataStorage storage) {
updateStorage(storage);
// Initialize the update related timestamps to the registration time.
storage.updateTimeOfLastCheckForUpdatedWebManifest();
storage.updateTimeOfLastWebApkUpdateRequestCompletion();
// The downloading of the splash screen image happens before a WebAPK's
// package name is available. If we want to use the image in the first
// launch, we need to cache the image, register the WebAPK and store the
// image in the SharedPreference when the WebAPK is installed
// (before the first launch), and delete the cached image if it's not
// installed. Therefore, lots of complexity will be introduced. To simplify
// the logic, WebAPKs are registered during the first launch, and don't
// retrieve splash screen image but use app icon for initialization.
initializeSplashScreenWidgets(backgroundColor, null);
}
});
}
@Override
......
......@@ -233,14 +233,12 @@ public class WebappActivity extends FullScreenActivity {
return mWebappInfo;
}
protected int getBackgroundColor() {
return ColorUtils.getOpaqueColor(mWebappInfo.backgroundColor(
private void initializeWebappData() {
final int backgroundColor = ColorUtils.getOpaqueColor(mWebappInfo.backgroundColor(
ApiCompatibilityUtils.getColor(getResources(), R.color.webapp_default_bg)));
}
private void initializeWebappData() {
mSplashScreen = new FrameLayout(this);
mSplashScreen.setBackgroundColor(getBackgroundColor());
mSplashScreen.setBackgroundColor(backgroundColor);
ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
contentView.addView(mSplashScreen);
......@@ -249,27 +247,39 @@ public class WebappActivity extends FullScreenActivity {
mWebappUma.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgroundColor()
? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
: WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);
mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor()
? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
: WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);
initializeSplashScreenWidgets(backgroundColor);
}
protected void initializeSplashScreenWidgets(final int backgroundColor) {
WebappRegistry.getWebappDataStorage(this, mWebappInfo.id(),
new WebappRegistry.FetchWebappDataStorageCallback() {
@Override
public void onWebappDataStorageRetrieved(WebappDataStorage storage) {
onDataStorageFetched(storage);
if (storage == null) {
onStorageIsNull(backgroundColor);
return;
}
updateStorage(storage);
// Retrieve the splash image if it exists.
storage.getSplashScreenImage(new WebappDataStorage.FetchCallback<Bitmap>() {
@Override
public void onDataRetrieved(Bitmap splashImage) {
initializeSplashScreenWidgets(backgroundColor, splashImage);
}
});
}
}
);
}
protected void recordSplashScreenThemeColorUma() {
mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor()
? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
: WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);
}
protected void onDataStorageFetched(WebappDataStorage storage) {
recordSplashScreenThemeColorUma();
if (storage == null) return;
protected void onStorageIsNull(int backgroundColor) {}
protected void updateStorage(WebappDataStorage storage) {
// The information in the WebappDataStorage may have been purged by the
// user clearing their history or not launching the web app recently.
// Restore the data if necessary from the intent.
......@@ -283,21 +293,9 @@ public class WebappActivity extends FullScreenActivity {
if (mWebappInfo.isLaunchedFromHomescreen()) {
storage.updateLastUsedTime();
}
retrieveSplashScreenImage(storage);
}
protected void retrieveSplashScreenImage(WebappDataStorage storage) {
// Retrieve the splash image if it exists.
storage.getSplashScreenImage(new WebappDataStorage.FetchCallback<Bitmap>() {
@Override
public void onDataRetrieved(Bitmap splashImage) {
initializeSplashScreenWidgets(splashImage);
}
});
}
protected void initializeSplashScreenWidgets(Bitmap splashImage) {
protected void initializeSplashScreenWidgets(int backgroundColor, Bitmap splashImage) {
Bitmap displayIcon = splashImage == null ? mWebappInfo.icon() : splashImage;
int minimiumSizeThreshold = getResources().getDimensionPixelSize(
R.dimen.webapp_splash_image_size_minimum);
......@@ -346,7 +344,7 @@ public class WebappActivity extends FullScreenActivity {
appNameView.setText(mWebappInfo.name());
if (splashIconView != null) splashIconView.setImageBitmap(displayIcon);
if (ColorUtils.shouldUseLightForegroundOnBackground(getBackgroundColor())) {
if (ColorUtils.shouldUseLightForegroundOnBackground(backgroundColor)) {
appNameView.setTextColor(ApiCompatibilityUtils.getColor(getResources(),
R.color.webapp_splash_title_light));
}
......
......@@ -388,23 +388,6 @@ public class WebappDataStorage {
return mPreferences.getString(KEY_URL, URL_INVALID);
}
/**
* Returns the theme color stored in this object, or
* ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING if it is not stored.
*/
long getThemeColor() {
return mPreferences.getLong(KEY_THEME_COLOR,
ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING);
}
/**
* Returns the orientation stored in this object, or ScreenOrientationValues.DEFAULT if it is
* not stored.
*/
int getOrientation() {
return mPreferences.getInt(KEY_ORIENTATION, ScreenOrientationValues.DEFAULT);
}
/**
* Updates the last used time of this object.
*/
......@@ -477,6 +460,7 @@ public class WebappDataStorage {
boolean getDidLastWebApkUpdateRequestSucceed() {
return mPreferences.getBoolean(KEY_DID_LAST_WEBAPK_UPDATE_REQUEST_SUCCEED, false);
}
/**
* Returns true if this web app has been launched from home screen recently (within
* WEBAPP_LAST_OPEN_MAX_TIME milliseconds).
......
......@@ -233,10 +233,6 @@ public class WebappInfo {
return mOrientation;
}
public void updateOrientation(int orientation) {
mOrientation = orientation;
}
public int source() {
return mSource;
}
......@@ -250,10 +246,6 @@ public class WebappInfo {
return mThemeColor;
}
public void updateThemeColor(long themeColor) {
mThemeColor = themeColor;
}
/**
* Returns whether the theme color specified in the Intent is valid.
* A theme color isn't valid if its value is ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING;
......
......@@ -338,29 +338,6 @@ public class WebappInfoTest extends InstrumentationTestCase {
assertEquals(packageName, info.webApkPackageName());
}
@SmallTest
@Feature({"Webapps"})
public void testUpdateThemeColorAndOrientation() {
long themeColor = 0xFF00FF00L;
int orientation = ScreenOrientationValues.DEFAULT;
Intent intent = createIntentWithUrlAndId();
intent.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, themeColor);
intent.putExtra(ShortcutHelper.EXTRA_ORIENTATION, orientation);
WebappInfo info = WebappInfo.create(intent);
assertEquals(themeColor, info.themeColor());
assertEquals(orientation, info.orientation());
// Updates the theme color and orientation.
themeColor = 0xFF0000FFL;
orientation = ScreenOrientationValues.LANDSCAPE;
info.updateThemeColor(themeColor);
info.updateOrientation(orientation);
assertEquals(themeColor, info.themeColor());
assertEquals(orientation, info.orientation());
}
/**
* Creates intent with url and id. If the url or id are not set WebappInfo#create() returns
* null.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment