use of org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType in project AndroidChromium by JackyAndroid.
the class ChromeTabbedActivity method handleBackPressed.
@Override
public boolean handleBackPressed() {
if (!mUIInitialized)
return false;
final Tab currentTab = getActivityTab();
if (mVrShellDelegate.exitVRIfNecessary())
return true;
if (currentTab == null) {
recordBackPressedUma("currentTab is null", BACK_PRESSED_TAB_IS_NULL);
moveTaskToBack(true);
return true;
}
// If we are in overview mode and not a tablet, then leave overview mode on back.
if (mLayoutManager.overviewVisible() && !isTablet()) {
recordBackPressedUma("Hid overview", BACK_PRESSED_EXITED_TAB_SWITCHER);
mLayoutManager.hideOverview(true);
return true;
}
if (exitFullscreenIfShowing()) {
recordBackPressedUma("Exited fullscreen", BACK_PRESSED_EXITED_FULLSCREEN);
return true;
}
if (getToolbarManager().back()) {
recordBackPressedUma("Navigating backward", BACK_PRESSED_NAVIGATED_BACK);
RecordUserAction.record("MobileTabClobbered");
return true;
}
// If the current tab url is HELP_URL, then the back button should close the tab to
// get back to the previous state. The reason for startsWith check is that the
// actual redirected URL is a different system language based help url.
final TabLaunchType type = currentTab.getLaunchType();
final boolean helpUrl = currentTab.getUrl().startsWith(HELP_URL_PREFIX);
if (type == TabLaunchType.FROM_CHROME_UI && helpUrl) {
getCurrentTabModel().closeTab(currentTab);
recordBackPressedUma("Closed tab for help URL", BACK_PRESSED_HELP_URL_CLOSED);
return true;
}
// [true]: Reached the bottom of the back stack on a tab the user did not explicitly
// create (i.e. it was created by an external app or opening a link in background, etc).
// [false]: Reached the bottom of the back stack on a tab that the user explicitly
// created (e.g. selecting "new tab" from menu).
final int parentId = currentTab.getParentId();
final boolean shouldCloseTab = type == TabLaunchType.FROM_LINK || type == TabLaunchType.FROM_EXTERNAL_APP || type == TabLaunchType.FROM_LONGPRESS_FOREGROUND || type == TabLaunchType.FROM_LONGPRESS_BACKGROUND || (type == TabLaunchType.FROM_RESTORE && parentId != Tab.INVALID_TAB_ID);
// Minimize the app if either:
// - we decided not to close the tab
// - we decided to close the tab, but it was opened by an external app, so we will go
// exit Chrome on top of closing the tab
final boolean minimizeApp = !shouldCloseTab || currentTab.isCreatedForExternalApp();
if (minimizeApp) {
if (shouldCloseTab) {
recordBackPressedUma("Minimized and closed tab", BACK_PRESSED_MINIMIZED_TAB_CLOSED);
mActivityStopMetrics.setStopReason(ActivityStopMetrics.STOP_REASON_BACK_BUTTON);
sendToBackground(currentTab);
return true;
} else {
recordBackPressedUma("Minimized, kept tab", BACK_PRESSED_MINIMIZED_NO_TAB_CLOSED);
mActivityStopMetrics.setStopReason(ActivityStopMetrics.STOP_REASON_BACK_BUTTON);
sendToBackground(null);
return true;
}
} else if (shouldCloseTab) {
recordBackPressedUma("Tab closed", BACK_PRESSED_TAB_CLOSED);
getCurrentTabModel().closeTab(currentTab, true, false, false);
return true;
}
assert false : "The back button should have already been handled by this point";
recordBackPressedUma("Unhandled", BACK_PRESSED_NOTHING_HAPPENED);
return false;
}
use of org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType in project AndroidChromium by JackyAndroid.
the class ChromeTabbedActivity method initializeCompositor.
@Override
public void initializeCompositor() {
try {
TraceEvent.begin("ChromeTabbedActivity.initializeCompositor");
super.initializeCompositor();
mTabModelSelectorImpl.onNativeLibraryReady(getTabContentManager());
mVrShellDelegate.onNativeLibraryReady();
mTabModelObserver = new EmptyTabModelObserver() {
@Override
public void didCloseTab(int tabId, boolean incognito) {
closeIfNoTabsAndHomepageEnabled(false);
}
@Override
public void tabPendingClosure(Tab tab) {
closeIfNoTabsAndHomepageEnabled(true);
}
@Override
public void tabRemoved(Tab tab) {
closeIfNoTabsAndHomepageEnabled(false);
}
private void closeIfNoTabsAndHomepageEnabled(boolean isPendingClosure) {
if (getTabModelSelector().getTotalTabCount() == 0) {
// If the last tab is closed, and homepage is enabled, then exit Chrome.
if (HomepageManager.isHomepageEnabled(getApplicationContext())) {
finish();
} else if (isPendingClosure) {
NewTabPageUma.recordNTPImpression(NewTabPageUma.NTP_IMPESSION_POTENTIAL_NOTAB);
}
}
}
@Override
public void didAddTab(Tab tab, TabLaunchType type) {
if (type == TabLaunchType.FROM_LONGPRESS_BACKGROUND && !DeviceClassManager.enableAnimations(getApplicationContext())) {
Toast.makeText(ChromeTabbedActivity.this, R.string.open_in_new_tab_toast, Toast.LENGTH_SHORT).show();
}
}
@Override
public void allTabsPendingClosure(List<Integer> tabIds) {
NewTabPageUma.recordNTPImpression(NewTabPageUma.NTP_IMPESSION_POTENTIAL_NOTAB);
}
};
for (TabModel model : mTabModelSelectorImpl.getModels()) {
model.addObserver(mTabModelObserver);
}
Bundle state = getSavedInstanceState();
if (state != null && state.containsKey(FRE_RUNNING)) {
mIsOnFirstRun = state.getBoolean(FRE_RUNNING);
}
} finally {
TraceEvent.end("ChromeTabbedActivity.initializeCompositor");
}
}
use of org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType in project AndroidChromium by JackyAndroid.
the class IncognitoToggleButtonTablet method setTabModelSelector.
/**
* Sets the {@link TabModelSelector} that will be queried for information about the state of
* the system.
* @param selector A {@link TabModelSelector} that represents the state of the system.
*/
public void setTabModelSelector(TabModelSelector selector) {
mTabModelSelector = selector;
if (selector != null) {
updateButtonResource();
updateButtonVisibility();
mTabModelSelectorObserver = new EmptyTabModelSelectorObserver() {
@Override
public void onTabModelSelected(TabModel newModel, TabModel oldModel) {
updateButtonResource();
}
};
mTabModelSelector.addObserver(mTabModelSelectorObserver);
mTabModelObserver = new EmptyTabModelObserver() {
@Override
public void didAddTab(Tab tab, TabLaunchType type) {
updateButtonVisibility();
}
@Override
public void willCloseTab(Tab tab, boolean animate) {
updateButtonVisibility();
}
@Override
public void tabRemoved(Tab tab) {
updateButtonVisibility();
}
};
for (TabModel model : mTabModelSelector.getModels()) {
model.addObserver(mTabModelObserver);
}
}
}
use of org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType in project AndroidChromium by JackyAndroid.
the class Tab method openNewTab.
@CalledByNative
protected void openNewTab(String url, String extraHeaders, ResourceRequestBody postData, int disposition, boolean hasParent, boolean isRendererInitiated) {
if (isClosing())
return;
boolean incognito = isIncognito();
TabLaunchType tabLaunchType = TabLaunchType.FROM_LONGPRESS_FOREGROUND;
Tab parentTab = hasParent ? this : null;
switch(disposition) {
// fall through
case WindowOpenDisposition.NEW_WINDOW:
case WindowOpenDisposition.NEW_FOREGROUND_TAB:
break;
// fall through
case WindowOpenDisposition.NEW_POPUP:
case WindowOpenDisposition.NEW_BACKGROUND_TAB:
tabLaunchType = TabLaunchType.FROM_LONGPRESS_BACKGROUND;
break;
case WindowOpenDisposition.OFF_THE_RECORD:
assert incognito;
incognito = true;
break;
default:
assert false;
}
// is not accessible, then we can't open a new tab.
if (shouldIgnoreNewTab(url, incognito) || getTabModelSelector() == null)
return;
LoadUrlParams loadUrlParams = new LoadUrlParams(url);
loadUrlParams.setVerbatimHeaders(extraHeaders);
loadUrlParams.setPostData(postData);
loadUrlParams.setIsRendererInitiated(isRendererInitiated);
getTabModelSelector().openNewTab(loadUrlParams, tabLaunchType, parentTab, incognito);
}
use of org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType in project AndroidChromium by JackyAndroid.
the class FullScreenActivity method preInflationStartup.
@Override
public void preInflationStartup() {
super.preInflationStartup();
setTabCreators(createTabDelegate(false), createTabDelegate(true));
setTabModelSelector(new SingleTabModelSelector(this, false, false) {
@Override
public Tab openNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent, boolean incognito) {
getTabCreator(incognito).createNewTab(loadUrlParams, type, parent);
return null;
}
});
}
Aggregations