| // Copyright 2019 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package org.chromium.chrome.browser.customtabs; |
| |
| import org.chromium.base.supplier.ObservableSupplier; |
| import org.chromium.base.supplier.OneShotCallback; |
| import org.chromium.base.supplier.OneshotSupplierImpl; |
| import org.chromium.base.supplier.Supplier; |
| import org.chromium.chrome.browser.ActivityTabProvider; |
| import org.chromium.chrome.browser.app.ChromeActivity; |
| import org.chromium.chrome.browser.app.reengagement.ReengagementActivity; |
| import org.chromium.chrome.browser.bookmarks.BookmarkBridge; |
| import org.chromium.chrome.browser.contextualsearch.ContextualSearchManager; |
| import org.chromium.chrome.browser.customtabs.content.CustomTabActivityNavigationController; |
| import org.chromium.chrome.browser.customtabs.features.toolbar.CustomTabToolbarCoordinator; |
| import org.chromium.chrome.browser.feature_engagement.TrackerFactory; |
| import org.chromium.chrome.browser.profiles.Profile; |
| import org.chromium.chrome.browser.reengagement.ReengagementNotificationController; |
| import org.chromium.chrome.browser.share.ShareDelegate; |
| import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| import org.chromium.chrome.browser.ui.RootUiCoordinator; |
| import org.chromium.components.feature_engagement.Tracker; |
| |
| /** |
| * A {@link RootUiCoordinator} variant that controls UI for {@link BaseCustomTabActivity}. |
| */ |
| public class BaseCustomTabRootUiCoordinator extends RootUiCoordinator { |
| private final Supplier<CustomTabToolbarCoordinator> mToolbarCoordinator; |
| private final Supplier<CustomTabActivityNavigationController> mNavigationController; |
| |
| public BaseCustomTabRootUiCoordinator(ChromeActivity activity, |
| ObservableSupplier<ShareDelegate> shareDelegateSupplier, |
| Supplier<CustomTabToolbarCoordinator> customTabToolbarCoordinator, |
| Supplier<CustomTabActivityNavigationController> customTabNavigationController, |
| ActivityTabProvider tabProvider, ObservableSupplier<Profile> profileSupplier, |
| ObservableSupplier<BookmarkBridge> bookmarkBridgeSupplier, |
| Supplier<ContextualSearchManager> contextualSearchManagerSupplier, |
| ObservableSupplier<TabModelSelector> tabModelSelectorSupplier) { |
| super(activity, null, shareDelegateSupplier, tabProvider, profileSupplier, |
| bookmarkBridgeSupplier, contextualSearchManagerSupplier, tabModelSelectorSupplier, |
| new OneshotSupplierImpl<>(), new OneshotSupplierImpl<>(), |
| new OneshotSupplierImpl<>(), () -> null); |
| mToolbarCoordinator = customTabToolbarCoordinator; |
| mNavigationController = customTabNavigationController; |
| } |
| |
| @Override |
| protected void initializeToolbar() { |
| super.initializeToolbar(); |
| |
| mToolbarCoordinator.get().onToolbarInitialized(mToolbarManager); |
| mNavigationController.get().onToolbarInitialized(mToolbarManager); |
| } |
| |
| @Override |
| public void onFinishNativeInitialization() { |
| super.onFinishNativeInitialization(); |
| if (!ReengagementNotificationController.isEnabled()) return; |
| new OneShotCallback<>(mProfileSupplier, mCallbackController.makeCancelable(profile -> { |
| assert profile != null : "Unexpectedly null profile from TabModel."; |
| if (profile == null) return; |
| Tracker tracker = TrackerFactory.getTrackerForProfile(profile); |
| ReengagementNotificationController controller = new ReengagementNotificationController( |
| mActivity, tracker, ReengagementActivity.class); |
| controller.tryToReengageTheUser(); |
| })); |
| } |
| } |