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