use of org.chromium.chrome.browser.tab.Tab 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.tab.Tab in project AndroidChromium by JackyAndroid.
the class ChromeTabbedActivity method onMenuOrKeyboardAction.
@Override
public boolean onMenuOrKeyboardAction(final int id, boolean fromMenu) {
final Tab currentTab = getActivityTab();
if (id == R.id.move_to_other_window_menu_id) {
if (currentTab != null)
moveTabToOtherWindow(currentTab);
} else if (id == R.id.new_tab_menu_id) {
getTabModelSelector().getModel(false).commitAllTabClosures();
RecordUserAction.record("MobileMenuNewTab");
RecordUserAction.record("MobileNewTabOpened");
reportNewTabShortcutUsed(false);
getTabCreator(false).launchUrl(UrlConstants.NTP_URL, TabLaunchType.FROM_CHROME_UI);
mLocaleManager.showSearchEnginePromoIfNeeded(this);
} else if (id == R.id.new_incognito_tab_menu_id) {
if (PrefServiceBridge.getInstance().isIncognitoModeEnabled()) {
getTabModelSelector().getModel(false).commitAllTabClosures();
// This action must be recorded before opening the incognito tab since UMA actions
// are dropped when an incognito tab is open.
RecordUserAction.record("MobileMenuNewIncognitoTab");
RecordUserAction.record("MobileNewTabOpened");
reportNewTabShortcutUsed(true);
getTabCreator(true).launchUrl(UrlConstants.NTP_URL, TabLaunchType.FROM_CHROME_UI);
}
} else if (id == R.id.all_bookmarks_menu_id) {
if (currentTab != null) {
getCompositorViewHolder().hideKeyboard(new Runnable() {
@Override
public void run() {
StartupMetrics.getInstance().recordOpenedBookmarks();
BookmarkUtils.showBookmarkManager(ChromeTabbedActivity.this);
}
});
RecordUserAction.record("MobileMenuAllBookmarks");
}
} else if (id == R.id.recent_tabs_menu_id) {
if (currentTab != null) {
currentTab.loadUrl(new LoadUrlParams(UrlConstants.RECENT_TABS_URL, PageTransition.AUTO_BOOKMARK));
RecordUserAction.record("MobileMenuOpenTabs");
}
} else if (id == R.id.close_all_tabs_menu_id) {
// Close both incognito and normal tabs
getTabModelSelector().closeAllTabs();
RecordUserAction.record("MobileMenuCloseAllTabs");
} else if (id == R.id.close_all_incognito_tabs_menu_id) {
// Close only incognito tabs
getTabModelSelector().getModel(true).closeAllTabs();
// TODO(nileshagrawal) Record unique action for this. See bug http://b/5542946.
RecordUserAction.record("MobileMenuCloseAllTabs");
} else if (id == R.id.find_in_page_id) {
mFindToolbarManager.showToolbar();
if (getContextualSearchManager() != null) {
getContextualSearchManager().hideContextualSearch(StateChangeReason.UNKNOWN);
}
if (fromMenu) {
RecordUserAction.record("MobileMenuFindInPage");
} else {
RecordUserAction.record("MobileShortcutFindInPage");
}
} else if (id == R.id.focus_url_bar) {
boolean isUrlBarVisible = !mLayoutManager.overviewVisible() && (!isTablet() || getCurrentTabModel().getCount() != 0);
if (isUrlBarVisible) {
getToolbarManager().setUrlBarFocus(true);
}
} else if (id == R.id.downloads_menu_id) {
DownloadUtils.showDownloadManager(this, currentTab);
RecordUserAction.record("MobileMenuDownloadManager");
} else if (id == R.id.open_recently_closed_tab) {
TabModel currentModel = mTabModelSelectorImpl.getCurrentModel();
if (!currentModel.isIncognito())
currentModel.openMostRecentlyClosedTab();
RecordUserAction.record("MobileTabClosedUndoShortCut");
} else if (id == R.id.enter_vr_id) {
mVrShellDelegate.enterVRIfNecessary(false);
} else {
return super.onMenuOrKeyboardAction(id, fromMenu);
}
return true;
}
use of org.chromium.chrome.browser.tab.Tab 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.tab.Tab in project AndroidChromium by JackyAndroid.
the class ChromeActivity method onShareMenuItemSelected.
/**
* Triggered when the share menu item is selected.
* This creates and shows a share intent picker dialog or starts a share intent directly.
* @param shareDirectly Whether it should share directly with the activity that was most
* recently used to share.
* @param isIncognito Whether currentTab is incognito.
*/
@VisibleForTesting
public void onShareMenuItemSelected(final boolean shareDirectly, final boolean isIncognito) {
final Tab currentTab = getActivityTab();
if (currentTab == null)
return;
PrintingController printingController = PrintingControllerImpl.getInstance();
if (printingController != null && !currentTab.isNativePage() && !printingController.isBusy() && PrefServiceBridge.getInstance().isPrintingEnabled()) {
PrintShareActivity.enablePrintShareOption(this, new Runnable() {
@Override
public void run() {
triggerShare(currentTab, shareDirectly, isIncognito);
}
});
return;
}
triggerShare(currentTab, shareDirectly, isIncognito);
}
use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.
the class ChromeActivity method onStopWithNative.
@Override
public void onStopWithNative() {
Tab tab = getActivityTab();
if (tab != null && !hasWindowFocus())
tab.onActivityHidden();
if (mAppMenuHandler != null)
mAppMenuHandler.hideAppMenu();
if (mGSAServiceClient != null) {
mGSAServiceClient.disconnect();
mGSAServiceClient = null;
if (mSyncStateChangedListener != null) {
ProfileSyncService syncService = ProfileSyncService.get();
if (syncService != null) {
syncService.removeSyncStateChangedListener(mSyncStateChangedListener);
}
mSyncStateChangedListener = null;
}
}
super.onStopWithNative();
}
Aggregations