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; ...@@ -43,8 +43,9 @@ import dagger.Lazy;
* Add methods here if other components need to communicate with Trusted Web Activity component. * Add methods here if other components need to communicate with Trusted Web Activity component.
*/ */
@ActivityScope @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 final CurrentPageVerifier mCurrentPageVerifier;
private TrustedWebActivityBrowserControlsVisibilityManager mBrowserControlsVisibilityManager; private TrustedWebActivityBrowserControlsVisibilityManager mBrowserControlsVisibilityManager;
private final CustomTabToolbarColorController mToolbarColorController; private final CustomTabToolbarColorController mToolbarColorController;
...@@ -81,6 +82,8 @@ public class TrustedWebActivityCoordinator implements InflationObserver { ...@@ -81,6 +82,8 @@ public class TrustedWebActivityCoordinator implements InflationObserver {
CustomTabsConnection customTabsConnection) { CustomTabsConnection customTabsConnection) {
// We don't need to do anything with most of the classes above, we just need to resolve them // We don't need to do anything with most of the classes above, we just need to resolve them
// so they start working. // so they start working.
mDisclosureView = disclosureView;
mNewDisclosureView = newDisclosureView;
mCurrentPageVerifier = currentPageVerifier; mCurrentPageVerifier = currentPageVerifier;
mBrowserControlsVisibilityManager = browserControlsVisibilityManager; mBrowserControlsVisibilityManager = browserControlsVisibilityManager;
mToolbarColorController = toolbarColorController; mToolbarColorController = toolbarColorController;
...@@ -95,7 +98,6 @@ public class TrustedWebActivityCoordinator implements InflationObserver { ...@@ -95,7 +98,6 @@ public class TrustedWebActivityCoordinator implements InflationObserver {
externalIntentsPolicyProvider.setPolicyCriteria( externalIntentsPolicyProvider.setPolicyCriteria(
verifier::shouldIgnoreExternalIntentHandlers); verifier::shouldIgnoreExternalIntentHandlers);
initDisclosure(disclosureView, newDisclosureView);
initSplashScreen(splashController, intentDataProvider, umaRecorder); initSplashScreen(splashController, intentDataProvider, umaRecorder);
currentPageVerifier.addVerificationObserver(this::onVerificationUpdate); currentPageVerifier.addVerificationObserver(this::onVerificationUpdate);
...@@ -104,17 +106,6 @@ public class TrustedWebActivityCoordinator implements InflationObserver { ...@@ -104,17 +106,6 @@ public class TrustedWebActivityCoordinator implements InflationObserver {
new PostMessageDisabler(customTabsConnection, intentDataProvider)); 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 @Override
public void onPreInflationStartup() { public void onPreInflationStartup() {
if (mCurrentPageVerifier.getState() == null) { if (mCurrentPageVerifier.getState() == null) {
...@@ -131,6 +122,17 @@ public class TrustedWebActivityCoordinator implements InflationObserver { ...@@ -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, private void initSplashScreen(Lazy<TwaSplashController> splashController,
BrowserServicesIntentDataProvider intentDataProvider, BrowserServicesIntentDataProvider intentDataProvider,
TrustedWebActivityUmaRecorder umaRecorder) { TrustedWebActivityUmaRecorder umaRecorder) {
......
...@@ -71,6 +71,17 @@ public class TrustedWebActivityDisclosureView implements ...@@ -71,6 +71,17 @@ public class TrustedWebActivityDisclosureView implements
lifecycleDispatcher.register(this); 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 @Override
public void onPropertyChanged(PropertyObservable<PropertyKey> source, public void onPropertyChanged(PropertyObservable<PropertyKey> source,
@Nullable PropertyKey propertyKey) { @Nullable PropertyKey propertyKey) {
...@@ -89,9 +100,7 @@ public class TrustedWebActivityDisclosureView implements ...@@ -89,9 +100,7 @@ public class TrustedWebActivityDisclosureView implements
@Override @Override
public void onStartWithNative() { public void onStartWithNative() {
// SnackbarManager removes all snackbars when Chrome goes to background. Restore if needed. // SnackbarManager removes all snackbars when Chrome goes to background. Restore if needed.
if (mModel.get(DISCLOSURE_STATE) == DISCLOSURE_STATE_SHOWN) { showIfNeeded();
showIfNeeded();
}
} }
@Override @Override
...@@ -99,8 +108,7 @@ public class TrustedWebActivityDisclosureView implements ...@@ -99,8 +108,7 @@ public class TrustedWebActivityDisclosureView implements
/** /**
* Creates the Infobar/Snackbar to show. The override of this method in * Creates the Infobar/Snackbar to show. The override of this method in
* {@link NewDisclosureSnackbar} may return {@code null}, meaning that no Infobar should be * {@link NewDisclosureSnackbar} may return {@code null}, if the infobar is already shown.
* shown.
*/ */
@Nullable @Nullable
protected Snackbar makeRunningInChromeInfobar(SnackbarManager.SnackbarController controller) { protected Snackbar makeRunningInChromeInfobar(SnackbarManager.SnackbarController controller) {
...@@ -114,13 +122,4 @@ public class TrustedWebActivityDisclosureView implements ...@@ -114,13 +122,4 @@ public class TrustedWebActivityDisclosureView implements
.setAction(action, null) .setAction(action, null)
.setSingleLine(false); .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