Search in sources :

Example 1 with NavigationController

use of org.chromium.content_public.browser.NavigationController in project AndroidChromium by JackyAndroid.

the class ExternalNavigationDelegateImpl method isSerpReferrer.

@Override
public boolean isSerpReferrer(String referrerUrl, Tab tab) {
    if (tab == null || tab.getWebContents() == null) {
        return false;
    }
    NavigationController nController = tab.getWebContents().getNavigationController();
    int index = nController.getLastCommittedEntryIndex();
    if (index == -1)
        return false;
    NavigationEntry entry = nController.getEntryAtIndex(index);
    if (entry == null)
        return false;
    return UrlUtilities.nativeIsGoogleSearchUrl(entry.getUrl());
}
Also used : NavigationController(org.chromium.content_public.browser.NavigationController) NavigationEntry(org.chromium.content_public.browser.NavigationEntry)

Example 2 with NavigationController

use of org.chromium.content_public.browser.NavigationController in project AndroidChromium by JackyAndroid.

the class InterceptNavigationDelegateImpl method maybeUpdateNavigationHistory.

/**
     * Updates navigation history if navigation is canceled due to intent handler. We go back to the
     * last committed entry index which was saved before the navigation, and remove the empty
     * entries from the navigation history. See crbug.com/426679
     */
public void maybeUpdateNavigationHistory() {
    WebContents webContents = mTab.getWebContents();
    if (mClearAllForwardHistoryRequired && webContents != null) {
        NavigationController navigationController = webContents.getNavigationController();
        int lastCommittedEntryIndex = getLastCommittedEntryIndex();
        while (navigationController.canGoForward()) {
            boolean ret = navigationController.removeEntryAtIndex(lastCommittedEntryIndex + 1);
            assert ret;
        }
    } else if (mShouldClearRedirectHistoryForTabClobbering && webContents != null) {
        // http://crbug/479056: Even if we clobber the current tab, we want to remove
        // redirect history to be consistent.
        NavigationController navigationController = webContents.getNavigationController();
        int indexBeforeRedirection = mTab.getTabRedirectHandler().getLastCommittedEntryIndexBeforeStartingNavigation();
        int lastCommittedEntryIndex = getLastCommittedEntryIndex();
        for (int i = lastCommittedEntryIndex - 1; i > indexBeforeRedirection; --i) {
            boolean ret = navigationController.removeEntryAtIndex(i);
            assert ret;
        }
    }
    mClearAllForwardHistoryRequired = false;
    mShouldClearRedirectHistoryForTabClobbering = false;
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) NavigationController(org.chromium.content_public.browser.NavigationController)

Example 3 with NavigationController

use of org.chromium.content_public.browser.NavigationController in project AndroidChromium by JackyAndroid.

the class NewTabPage method getScrollPositionFromNavigationEntry.

/**
     * Returns the value of the adapter scroll position that was stored in the last committed
     * navigation entry. Returns {@code RecyclerView.NO_POSITION} if there is no last committed
     * navigation entry, or if no data is found.
     * @return The adapter scroll position.
     */
private int getScrollPositionFromNavigationEntry() {
    if (mTab.getWebContents() == null)
        return RecyclerView.NO_POSITION;
    NavigationController controller = mTab.getWebContents().getNavigationController();
    int index = controller.getLastCommittedEntryIndex();
    String scrollPositionData = controller.getEntryExtraData(index, NAVIGATION_ENTRY_SCROLL_POSITION_KEY);
    if (TextUtils.isEmpty(scrollPositionData))
        return RecyclerView.NO_POSITION;
    try {
        return Integer.parseInt(scrollPositionData);
    } catch (NumberFormatException e) {
        Log.w(TAG, "Bad data found for scroll position: %s", scrollPositionData, e);
        return RecyclerView.NO_POSITION;
    }
}
Also used : NavigationController(org.chromium.content_public.browser.NavigationController) Point(android.graphics.Point)

Aggregations

NavigationController (org.chromium.content_public.browser.NavigationController)3 Point (android.graphics.Point)1 NavigationEntry (org.chromium.content_public.browser.NavigationEntry)1 WebContents (org.chromium.content_public.browser.WebContents)1