Commit b48f7cd3 authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

Fix crash on TWA launch.

This CL fixes a crash due to ChromeFeatureList#isEnabled() being
called prior to native being loaded.

BUG=1074683

Change-Id: I38b6565626cea560ac2f35ef9ffd1629042c378a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2167539Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762866}
parent ec85d275
......@@ -43,8 +43,9 @@ import dagger.Lazy;
* Add methods here if other components need to communicate with Trusted Web Activity component.
*/
@ActivityScope
public class TrustedWebActivityCoordinator implements InflationObserver {
public class TrustedWebActivityCoordinator implements InflationObserver, NativeInitObserver {
private final Lazy<TrustedWebActivityDisclosureView> mDisclosureView;
private final Lazy<NewDisclosureSnackbar> mNewDisclosureView;
private final CurrentPageVerifier mCurrentPageVerifier;
private TrustedWebActivityBrowserControlsVisibilityManager mBrowserControlsVisibilityManager;
private final CustomTabToolbarColorController mToolbarColorController;
......@@ -81,6 +82,8 @@ public class TrustedWebActivityCoordinator implements InflationObserver {
CustomTabsConnection customTabsConnection) {
// We don't need to do anything with most of the classes above, we just need to resolve them
// so they start working.
mDisclosureView = disclosureView;
mNewDisclosureView = newDisclosureView;
mCurrentPageVerifier = currentPageVerifier;
mBrowserControlsVisibilityManager = browserControlsVisibilityManager;
mToolbarColorController = toolbarColorController;
......@@ -95,7 +98,6 @@ public class TrustedWebActivityCoordinator implements InflationObserver {
externalIntentsPolicyProvider.setPolicyCriteria(
verifier::shouldIgnoreExternalIntentHandlers);
initDisclosure(disclosureView, newDisclosureView);
initSplashScreen(splashController, intentDataProvider, umaRecorder);
currentPageVerifier.addVerificationObserver(this::onVerificationUpdate);
......@@ -104,17 +106,6 @@ public class TrustedWebActivityCoordinator implements InflationObserver {
new PostMessageDisabler(customTabsConnection, intentDataProvider));
}
private void initDisclosure(Lazy<TrustedWebActivityDisclosureView> disclosureView,
Lazy<NewDisclosureSnackbar> newDisclosureView) {
// Calling get on the appropriate Lazy instance will cause Dagger to create the class.
// The classes wire themselves up to the rest of the code in their constructors.
if (ChromeFeatureList.isEnabled(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_NEW_DISCLOSURE)) {
newDisclosureView.get();
} else {
disclosureView.get();
}
}
@Override
public void onPreInflationStartup() {
if (mCurrentPageVerifier.getState() == null) {
......@@ -131,6 +122,17 @@ public class TrustedWebActivityCoordinator implements InflationObserver {
}
}
@Override
public void onFinishNativeInitialization() {
// Calling get on the appropriate Lazy instance will cause Dagger to create the class.
// The classes wire themselves up to the rest of the code in their constructors.
if (ChromeFeatureList.isEnabled(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_NEW_DISCLOSURE)) {
mNewDisclosureView.get().showIfNeeded();
} else {
mDisclosureView.get().showIfNeeded();
}
}
private void initSplashScreen(Lazy<TwaSplashController> splashController,
BrowserServicesIntentDataProvider intentDataProvider,
TrustedWebActivityUmaRecorder umaRecorder) {
......
......@@ -71,6 +71,17 @@ public class TrustedWebActivityDisclosureView implements
lifecycleDispatcher.register(this);
}
public void showIfNeeded() {
if (mModel.get(DISCLOSURE_STATE) != DISCLOSURE_STATE_SHOWN) return;
Snackbar snackbar = makeRunningInChromeInfobar(mSnackbarController);
if (snackbar == null) {
return;
}
mSnackbarManager.get().showSnackbar(snackbar);
}
@Override
public void onPropertyChanged(PropertyObservable<PropertyKey> source,
@Nullable PropertyKey propertyKey) {
......@@ -89,9 +100,7 @@ public class TrustedWebActivityDisclosureView implements
@Override
public void onStartWithNative() {
// SnackbarManager removes all snackbars when Chrome goes to background. Restore if needed.
if (mModel.get(DISCLOSURE_STATE) == DISCLOSURE_STATE_SHOWN) {
showIfNeeded();
}
showIfNeeded();
}
@Override
......@@ -99,8 +108,7 @@ public class TrustedWebActivityDisclosureView implements
/**
* Creates the Infobar/Snackbar to show. The override of this method in
* {@link NewDisclosureSnackbar} may return {@code null}, meaning that no Infobar should be
* shown.
* {@link NewDisclosureSnackbar} may return {@code null}, if the infobar is already shown.
*/
@Nullable
protected Snackbar makeRunningInChromeInfobar(SnackbarManager.SnackbarController controller) {
......@@ -114,13 +122,4 @@ public class TrustedWebActivityDisclosureView implements
.setAction(action, null)
.setSingleLine(false);
}
private void showIfNeeded() {
Snackbar snackbar = makeRunningInChromeInfobar(mSnackbarController);
if (snackbar == null) {
return;
}
mSnackbarManager.get().showSnackbar(snackbar);
}
}
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