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);
}
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);
}
}
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);
}
}
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);
}
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());
}
};
}
Aggregations