Java Code Examples for org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType#FROM_LONGPRESS_BACKGROUND

The following examples show how to use org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType#FROM_LONGPRESS_BACKGROUND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LayoutManagerChrome.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType launchType) {
    int tabId = tab.getId();
    if (launchType != TabLaunchType.FROM_RESTORE) {
        boolean incognito = tab.isIncognito();
        boolean willBeSelected = launchType != TabLaunchType.FROM_LONGPRESS_BACKGROUND
                || (!getTabModelSelector().isIncognitoSelected() && incognito);
        float lastTapX = LocalizationUtils.isLayoutRtl() ? mLastContentWidthDp : 0.f;
        float lastTapY = 0.f;
        if (launchType != TabLaunchType.FROM_CHROME_UI) {
            float heightDelta =
                    mLastFullscreenViewportDp.height() - mLastVisibleViewportDp.height();
            lastTapX = mPxToDp * mLastTapX;
            lastTapY = mPxToDp * mLastTapY - heightDelta;
        }

        tabCreated(tabId, getTabModelSelector().getCurrentTabId(), launchType, incognito,
                willBeSelected, lastTapX, lastTapY);
    }
}
 
Example 2
Source File: InterceptNavigationDelegateImpl.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Returns ExternalNavigationParams.Builder to generate ExternalNavigationParams for
 * ExternalNavigationHandler#shouldOverrideUrlLoading().
 */
public ExternalNavigationParams.Builder buildExternalNavigationParams(
        NavigationParams navigationParams, TabRedirectHandler tabRedirectHandler,
        boolean shouldCloseTab) {
    boolean isInitialTabLaunchInBackground =
            mTab.getLaunchType() == TabLaunchType.FROM_LONGPRESS_BACKGROUND && shouldCloseTab;
    // http://crbug.com/448977: If a new tab is closed by this overriding, we should open an
    // Intent in a new tab when Chrome receives it again.
    return new ExternalNavigationParams
            .Builder(navigationParams.url, mTab.isIncognito(), navigationParams.referrer,
                    navigationParams.pageTransitionType, navigationParams.isRedirect)
            .setTab(mTab)
            .setApplicationMustBeInForeground(true)
            .setRedirectHandler(tabRedirectHandler)
            .setOpenInNewTab(shouldCloseTab)
            .setIsBackgroundTabNavigation(mTab.isHidden() && !isInitialTabLaunchInBackground)
            .setIsMainFrame(navigationParams.isMainFrame)
            .setHasUserGesture(navigationParams.hasUserGesture)
            .setShouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent(
                    shouldCloseTab && navigationParams.isMainFrame);
}
 
Example 3
Source File: LayoutManagerChrome.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType launchType) {
    int tabId = tab.getId();
    if (launchType == TabLaunchType.FROM_RESTORE) {
        getActiveLayout().onTabRestored(time(), tabId);
    } else {
        boolean incognito = tab.isIncognito();
        boolean willBeSelected = launchType != TabLaunchType.FROM_LONGPRESS_BACKGROUND
                || (!getTabModelSelector().isIncognitoSelected() && incognito);
        float lastTapX = LocalizationUtils.isLayoutRtl() ? mLastContentWidthDp : 0.f;
        float lastTapY = 0.f;
        if (launchType != TabLaunchType.FROM_CHROME_UI) {
            float heightDelta =
                    mLastFullscreenViewportDp.height() - mLastVisibleViewportDp.height();
            lastTapX = mPxToDp * mLastTapX;
            lastTapY = mPxToDp * mLastTapY - heightDelta;
        }

        tabCreated(tabId, getTabModelSelector().getCurrentTabId(), launchType, incognito,
                willBeSelected, lastTapX, lastTapY);
    }
}
 
Example 4
Source File: InterceptNavigationDelegateImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Returns ExternalNavigationParams.Builder to generate ExternalNavigationParams for
 * ExternalNavigationHandler#shouldOverrideUrlLoading().
 */
public ExternalNavigationParams.Builder buildExternalNavigationParams(
        NavigationParams navigationParams, TabRedirectHandler tabRedirectHandler,
        boolean shouldCloseTab) {
    boolean isInitialTabLaunchInBackground =
            mTab.getLaunchType() == TabLaunchType.FROM_LONGPRESS_BACKGROUND && shouldCloseTab;
    // http://crbug.com/448977: If a new tab is closed by this overriding, we should open an
    // Intent in a new tab when Chrome receives it again.
    return new ExternalNavigationParams
            .Builder(navigationParams.url, mTab.isIncognito(), navigationParams.referrer,
                    navigationParams.pageTransitionType, navigationParams.isRedirect)
            .setTab(mTab)
            .setApplicationMustBeInForeground(true)
            .setRedirectHandler(tabRedirectHandler)
            .setOpenInNewTab(shouldCloseTab)
            .setIsBackgroundTabNavigation(mTab.isHidden() && !isInitialTabLaunchInBackground)
            .setIsMainFrame(navigationParams.isMainFrame)
            .setHasUserGesture(navigationParams.hasUserGesture)
            .setShouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent(
                    shouldCloseTab && navigationParams.isMainFrame);
}
 
Example 5
Source File: LayoutManagerChrome.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType launchType) {
    int tabId = tab.getId();
    if (launchType == TabLaunchType.FROM_RESTORE) {
        getActiveLayout().onTabRestored(time(), tabId);
    } else {
        boolean incognito = tab.isIncognito();
        boolean willBeSelected = launchType != TabLaunchType.FROM_LONGPRESS_BACKGROUND
                || (!getTabModelSelector().isIncognitoSelected() && incognito);
        float lastTapX = LocalizationUtils.isLayoutRtl()
                ? mHost.getWidth() * mPxToDp : 0.f;
        float lastTapY = 0.f;
        if (launchType != TabLaunchType.FROM_CHROME_UI) {
            float heightDelta = mHost.getHeightMinusBrowserControls() * mPxToDp;
            lastTapX = mPxToDp * mLastTapX;
            lastTapY = mPxToDp * mLastTapY - heightDelta;
        }

        tabCreated(tabId, getTabModelSelector().getCurrentTabId(), launchType, incognito,
                willBeSelected, lastTapX, lastTapY);
    }
}
 
Example 6
Source File: InterceptNavigationDelegateImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Returns ExternalNavigationParams.Builder to generate ExternalNavigationParams for
 * ExternalNavigationHandler#shouldOverrideUrlLoading().
 */
public ExternalNavigationParams.Builder buildExternalNavigationParams(
        NavigationParams navigationParams, TabRedirectHandler tabRedirectHandler,
        boolean shouldCloseTab) {
    boolean isInitialTabLaunchInBackground =
            mTab.getLaunchType() == TabLaunchType.FROM_LONGPRESS_BACKGROUND && shouldCloseTab;
    // http://crbug.com/448977: If a new tab is closed by this overriding, we should open an
    // Intent in a new tab when Chrome receives it again.
    return new ExternalNavigationParams
            .Builder(navigationParams.url, mTab.isIncognito(), navigationParams.referrer,
                    navigationParams.pageTransitionType, navigationParams.isRedirect)
            .setTab(mTab)
            .setApplicationMustBeInForeground(true)
            .setRedirectHandler(tabRedirectHandler)
            .setOpenInNewTab(shouldCloseTab)
            .setIsBackgroundTabNavigation(mTab.isHidden() && !isInitialTabLaunchInBackground)
            .setIsMainFrame(navigationParams.isMainFrame)
            .setHasUserGesture(navigationParams.hasUserGesture)
            .setShouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent(
                    shouldCloseTab && navigationParams.isMainFrame);
}
 
Example 7
Source File: TabModelOrderController.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Determine if a launch type is the result of linked being clicked.
 */
static boolean linkClicked(TabLaunchType type) {
    return type == TabLaunchType.FROM_LINK
            || type == TabLaunchType.FROM_LONGPRESS_FOREGROUND
            || type == TabLaunchType.FROM_LONGPRESS_BACKGROUND;
}
 
Example 8
Source File: ChromeTabbedActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void initializeCompositor() {
    try {
        TraceEvent.begin("ChromeTabbedActivity.initializeCompositor");
        super.initializeCompositor();

        mTabModelSelectorImpl.onNativeLibraryReady(getTabContentManager());
        mVrShellDelegate.onNativeLibraryReady();

        mTabModelObserver = new TabModelSelectorTabModelObserver(mTabModelSelectorImpl) {
            @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);
            }
        };

        Bundle state = getSavedInstanceState();
        if (state != null && state.containsKey(FRE_RUNNING)) {
            mIsOnFirstRun = state.getBoolean(FRE_RUNNING);
        }
    } finally {
        TraceEvent.end("ChromeTabbedActivity.initializeCompositor");
    }
}
 
Example 9
Source File: TabModelOrderController.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Determine if a launch type is the result of linked being clicked.
 */
static boolean linkClicked(TabLaunchType type) {
    return type == TabLaunchType.FROM_LINK
            || type == TabLaunchType.FROM_LONGPRESS_FOREGROUND
            || type == TabLaunchType.FROM_LONGPRESS_BACKGROUND;
}
 
Example 10
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void initializeCompositor() {
    try {
        TraceEvent.begin("ChromeTabbedActivity.initializeCompositor");
        super.initializeCompositor();

        mTabModelSelectorImpl.onNativeLibraryReady(getTabContentManager());

        mTabModelObserver = new TabModelSelectorTabModelObserver(mTabModelSelectorImpl) {
            @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()) {
                    Toast.makeText(ChromeTabbedActivity.this,
                            R.string.open_in_new_tab_toast,
                            Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void allTabsPendingClosure(List<Tab> tabs) {
                NewTabPageUma.recordNTPImpression(
                        NewTabPageUma.NTP_IMPESSION_POTENTIAL_NOTAB);
            }
        };

        Bundle state = getSavedInstanceState();
        if (state != null && state.containsKey(FRE_RUNNING)) {
            mIsOnFirstRun = state.getBoolean(FRE_RUNNING);
        }
    } finally {
        TraceEvent.end("ChromeTabbedActivity.initializeCompositor");
    }
}
 
Example 11
Source File: TabModelOrderController.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Determine if a launch type is the result of linked being clicked.
 */
static boolean linkClicked(TabLaunchType type) {
    return type == TabLaunchType.FROM_LINK
            || type == TabLaunchType.FROM_LONGPRESS_FOREGROUND
            || type == TabLaunchType.FROM_LONGPRESS_BACKGROUND;
}
 
Example 12
Source File: TabModelOrderController.java    From delion with Apache License 2.0 3 votes vote down vote up
/**
 * Determine if a launch type will result in the tab being opened in the
 * foreground.
 * @param type               The type of opening event.
 * @param isNewTabIncognito  True if the new opened tab is incognito.
 * @return                   True if the tab will be in the foreground
 */
public boolean willOpenInForeground(TabLaunchType type, boolean isNewTabIncognito) {
    // Restore is handling the active index by itself.
    if (type == TabLaunchType.FROM_RESTORE) return false;
    return type != TabLaunchType.FROM_LONGPRESS_BACKGROUND
            || (!mTabModelSelector.isIncognitoSelected() && isNewTabIncognito);
}
 
Example 13
Source File: TabModelOrderController.java    From AndroidChromium with Apache License 2.0 3 votes vote down vote up
/**
 * Determine if a launch type will result in the tab being opened in the
 * foreground.
 * @param type               The type of opening event.
 * @param isNewTabIncognito  True if the new opened tab is incognito.
 * @return                   True if the tab will be in the foreground
 */
public boolean willOpenInForeground(TabLaunchType type, boolean isNewTabIncognito) {
    // Restore is handling the active index by itself.
    if (type == TabLaunchType.FROM_RESTORE) return false;
    return type != TabLaunchType.FROM_LONGPRESS_BACKGROUND
            || (!mTabModelSelector.isIncognitoSelected() && isNewTabIncognito);
}
 
Example 14
Source File: TabModelOrderController.java    From 365browser with Apache License 2.0 3 votes vote down vote up
/**
 * Determine if a launch type will result in the tab being opened in the
 * foreground.
 * @param type               The type of opening event.
 * @param isNewTabIncognito  True if the new opened tab is incognito.
 * @return                   True if the tab will be in the foreground
 */
public boolean willOpenInForeground(TabLaunchType type, boolean isNewTabIncognito) {
    // Restore is handling the active index by itself.
    if (type == TabLaunchType.FROM_RESTORE) return false;
    return type != TabLaunchType.FROM_LONGPRESS_BACKGROUND
            || (!mTabModelSelector.isIncognitoSelected() && isNewTabIncognito);
}