Search in sources :

Example 1 with TabModelSelectorTabObserver

use of org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver in project AndroidChromium by JackyAndroid.

the class ChromeTabbedActivity method createTabModelSelectorImpl.

private void createTabModelSelectorImpl(Bundle savedInstanceState) {
    // We determine the model as soon as possible so every systems get initialized coherently.
    boolean startIncognito = savedInstanceState != null && savedInstanceState.getBoolean("is_incognito_selected", false);
    int index = savedInstanceState != null ? savedInstanceState.getInt(WINDOW_INDEX, 0) : 0;
    mTabModelSelectorImpl = (TabModelSelectorImpl) TabWindowManager.getInstance().requestSelector(this, getWindowAndroid(), index);
    if (mTabModelSelectorImpl == null) {
        Toast.makeText(this, getString(R.string.unsupported_number_of_windows), Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    setTabCreators(new TabbedModeTabCreator(this, getWindowAndroid(), false), new TabbedModeTabCreator(this, getWindowAndroid(), true));
    mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(mTabModelSelectorImpl) {

        private boolean mIsFirstPageLoadStart = true;

        @Override
        public void onPageLoadStarted(Tab tab, String url) {
            // 2nd navigation (in activity lifetime) in parallel.
            if (!mIsFirstPageLoadStart) {
                UmaUtils.setRunningApplicationStart(false);
            } else {
                mIsFirstPageLoadStart = false;
            }
        }

        @Override
        public void onDidNavigateMainFrame(Tab tab, String url, String baseUrl, boolean isNavigationToDifferentPage, boolean isFragmentNavigation, int statusCode) {
            DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(ChromeTabbedActivity.this, tab.getWebContents(), url, tab.isShowingErrorPage(), isFragmentNavigation, statusCode);
        }
    };
    if (startIncognito)
        mTabModelSelectorImpl.selectModel(true);
    setTabModelSelector(mTabModelSelectorImpl);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) TabModelSelectorTabObserver(org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver) SuppressLint(android.annotation.SuppressLint)

Example 2 with TabModelSelectorTabObserver

use of org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver in project AndroidChromium by JackyAndroid.

the class ChromeActivity method setTabModelSelector.

/**
     * Sets the {@link TabModelSelector} owned by this {@link ChromeActivity}.
     * @param tabModelSelector A {@link TabModelSelector} instance.
     */
protected void setTabModelSelector(TabModelSelector tabModelSelector) {
    mTabModelSelector = tabModelSelector;
    if (mTabModelSelectorTabObserver != null)
        mTabModelSelectorTabObserver.destroy();
    mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(tabModelSelector) {

        @Override
        public void didFirstVisuallyNonEmptyPaint(Tab tab) {
            if (DataUseTabUIManager.checkAndResetDataUseTrackingStarted(tab) && DataUseTabUIManager.shouldShowDataUseStartedUI()) {
                mDataUseSnackbarController.showDataUseTrackingStartedBar();
            } else if (DataUseTabUIManager.shouldShowDataUseEndedUI() && DataUseTabUIManager.shouldShowDataUseEndedSnackbar(getApplicationContext()) && DataUseTabUIManager.checkAndResetDataUseTrackingEnded(tab)) {
                mDataUseSnackbarController.showDataUseTrackingEndedBar();
            }
        }

        @Override
        public void onShown(Tab tab) {
            setStatusBarColor(tab, tab.getThemeColor());
        }

        @Override
        public void onHidden(Tab tab) {
            mDataUseSnackbarController.dismissDataUseBar();
        }

        @Override
        public void onDestroyed(Tab tab) {
            mDataUseSnackbarController.dismissDataUseBar();
        }

        @Override
        public void onLoadStopped(Tab tab, boolean toDifferentDocument) {
            postDeferredStartupIfNeeded();
        }

        @Override
        public void onPageLoadFinished(Tab tab) {
            postDeferredStartupIfNeeded();
            OfflinePageUtils.showOfflineSnackbarIfNecessary(ChromeActivity.this, tab);
        }

        @Override
        public void onCrash(Tab tab, boolean sadTabShown) {
            postDeferredStartupIfNeeded();
        }

        @Override
        public void onDidChangeThemeColor(Tab tab, int color) {
            if (getActivityTab() != tab)
                return;
            setStatusBarColor(tab, color);
            if (getToolbarManager() == null)
                return;
            getToolbarManager().updatePrimaryColor(color, true);
            ControlContainer controlContainer = (ControlContainer) findViewById(R.id.control_container);
            controlContainer.getToolbarResourceAdapter().invalidate(null);
        }
    };
    if (mAssistStatusHandler != null) {
        mAssistStatusHandler.setTabModelSelector(tabModelSelector);
    }
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) ToolbarControlContainer(org.chromium.chrome.browser.toolbar.ToolbarControlContainer) ControlContainer(org.chromium.chrome.browser.widget.ControlContainer) TabModelSelectorTabObserver(org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver) SuppressLint(android.annotation.SuppressLint)

Example 3 with TabModelSelectorTabObserver

use of org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver in project AndroidChromium by JackyAndroid.

the class ContextualSearchManager method listenForTabModelSelectorNotifications.

/**
     * Listens for notifications that should hide the Contextual Search bar.
     */
private void listenForTabModelSelectorNotifications() {
    TabModelSelector selector = mActivity.getTabModelSelector();
    mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(selector) {

        @Override
        public void onPageLoadStarted(Tab tab, String url) {
            hideContextualSearch(StateChangeReason.UNKNOWN);
            mDidBasePageLoadJustStart = true;
        }

        @Override
        public void onCrash(Tab tab, boolean sadTabShown) {
            if (sadTabShown) {
                // Hide contextual search if the foreground tab crashed
                hideContextualSearch(StateChangeReason.UNKNOWN);
            }
        }

        @Override
        public void onClosingStateChanged(Tab tab, boolean closing) {
            if (closing)
                hideContextualSearch(StateChangeReason.UNKNOWN);
        }
    };
    for (TabModel tabModel : selector.getModels()) {
        tabModel.addObserver(mTabModelObserver);
    }
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) TabModelSelector(org.chromium.chrome.browser.tabmodel.TabModelSelector) TabModelSelectorTabObserver(org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver) TabModel(org.chromium.chrome.browser.tabmodel.TabModel)

Example 4 with TabModelSelectorTabObserver

use of org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver in project AndroidChromium by JackyAndroid.

the class LayoutManagerDocument method init.

@Override
public void init(TabModelSelector selector, TabCreatorManager creator, TabContentManager content, ViewGroup androidContentContainer, ContextualSearchManagementDelegate contextualSearchDelegate, ReaderModeManagerDelegate readerModeDelegate, DynamicResourceLoader dynamicResourceLoader) {
    // Add any SceneOverlays to a layout.
    addAllSceneOverlays();
    // Save state
    mContextualSearchDelegate = contextualSearchDelegate;
    // Initialize Event Filters
    mStaticEdgeEventFilter.setTabModelSelector(selector);
    // Initialize Layouts
    mStaticLayout.setTabModelSelector(selector, content);
    // Initialize Contextual Search Panel
    mContextualSearchPanel.setManagementDelegate(contextualSearchDelegate);
    // Set back flow communication
    if (contextualSearchDelegate != null) {
        contextualSearchDelegate.setContextualSearchPanel(mContextualSearchPanel);
    }
    mReaderModePanel.setManagerDelegate(readerModeDelegate);
    if (readerModeDelegate != null) {
        readerModeDelegate.setReaderModePanel(mReaderModePanel);
    }
    // Set the dynamic resource loader for all overlay panels.
    mOverlayPanelManager.setDynamicResourceLoader(dynamicResourceLoader);
    mOverlayPanelManager.setContainerView(androidContentContainer);
    mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(selector) {

        @Override
        public void onContentChanged(Tab tab) {
            initLayoutTabFromHost(tab.getId());
        }

        @Override
        public void onBackgroundColorChanged(Tab tab, int color) {
            initLayoutTabFromHost(tab.getId());
        }

        @Override
        public void onDidChangeThemeColor(Tab tab, int color) {
            initLayoutTabFromHost(tab.getId());
        }
    };
    super.init(selector, creator, content, androidContentContainer, contextualSearchDelegate, readerModeDelegate, dynamicResourceLoader);
}
Also used : LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab) Tab(org.chromium.chrome.browser.tab.Tab) TabModelSelectorTabObserver(org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver)

Example 5 with TabModelSelectorTabObserver

use of org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver in project AndroidChromium by JackyAndroid.

the class LayoutManagerChrome method init.

@Override
public void init(TabModelSelector selector, TabCreatorManager creator, TabContentManager content, ViewGroup androidContentContainer, ContextualSearchManagementDelegate contextualSearchDelegate, ReaderModeManagerDelegate readerModeDelegate, DynamicResourceLoader dynamicResourceLoader) {
    // TODO: TitleCache should be a part of the ResourceManager.
    mTitleCache = mHost.getTitleCache();
    // Initialize Layouts
    mToolbarSwipeLayout.setTabModelSelector(selector, content);
    mOverviewListLayout.setTabModelSelector(selector, content);
    if (mOverviewLayout != null)
        mOverviewLayout.setTabModelSelector(selector, content);
    super.init(selector, creator, content, androidContentContainer, contextualSearchDelegate, readerModeDelegate, dynamicResourceLoader);
    mTabModelSelectorObserver = new EmptyTabModelSelectorObserver() {

        @Override
        public void onTabModelSelected(TabModel newModel, TabModel oldModel) {
            tabModelSwitched(newModel.isIncognito());
        }
    };
    selector.addObserver(mTabModelSelectorObserver);
    selector.setCloseAllTabsDelegate(this);
    mTabModelObserver = createTabModelObserver();
    for (TabModel model : selector.getModels()) model.addObserver(mTabModelObserver);
    mTabSelectorTabObserver = new TabModelSelectorTabObserver(selector) {

        @Override
        public void onLoadStarted(Tab tab, boolean toDifferentDocument) {
            tabLoadStarted(tab.getId(), tab.isIncognito());
        }

        @Override
        public void onLoadStopped(Tab tab, boolean toDifferentDocument) {
            tabLoadFinished(tab.getId(), tab.isIncognito());
        }

        @Override
        public void onPageLoadStarted(Tab tab, String url) {
            tabPageLoadStarted(tab.getId(), tab.isIncognito());
        }

        @Override
        public void onPageLoadFinished(Tab tab) {
            tabPageLoadFinished(tab.getId(), tab.isIncognito());
        }

        @Override
        public void onPageLoadFailed(Tab tab, int errorCode) {
            tabPageLoadFinished(tab.getId(), tab.isIncognito());
        }

        @Override
        public void onCrash(Tab tab, boolean sadTabShown) {
            tabPageLoadFinished(tab.getId(), tab.isIncognito());
        }
    };
}
Also used : EmptyTabModelSelectorObserver(org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver) LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab) Tab(org.chromium.chrome.browser.tab.Tab) TabModelSelectorTabObserver(org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver) TabModel(org.chromium.chrome.browser.tabmodel.TabModel)

Aggregations

Tab (org.chromium.chrome.browser.tab.Tab)8 TabModelSelectorTabObserver (org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver)8 TabModel (org.chromium.chrome.browser.tabmodel.TabModel)4 SuppressLint (android.annotation.SuppressLint)2 LayoutTab (org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)2 TabModelSelector (org.chromium.chrome.browser.tabmodel.TabModelSelector)2 ComponentCallbacks (android.content.ComponentCallbacks)1 Configuration (android.content.res.Configuration)1 Bitmap (android.graphics.Bitmap)1 ContextualSearchObserver (org.chromium.chrome.browser.contextualsearch.ContextualSearchObserver)1 EmptyTabModelObserver (org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver)1 EmptyTabModelSelectorObserver (org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver)1 TabSelectionType (org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType)1 ToolbarControlContainer (org.chromium.chrome.browser.toolbar.ToolbarControlContainer)1 ControlContainer (org.chromium.chrome.browser.widget.ControlContainer)1