Skip to content

Commit

Permalink
[Chromium] Record history
Browse files Browse the repository at this point in the history
GeckoSession uses a HistoryDelegate object (provided by Wolvic) to
keep track of history changes. In the case of Chromium the concept
is different. We can listen to the events dispatched by the
WebContents object and manyally call the HistoryDelegate to record
changes in the history. That way we don't need to change anything
in the Gecko port and we get history support in Chromium.
  • Loading branch information
svillar committed Oct 23, 2023
1 parent 6298da5 commit cc42251
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ public void didStartNavigationInPrimaryMainFrame(NavigationHandle navigationHand
navigationHandle.hasUserGesture(), navigationHandle.isRendererInitiated()));
}

private int toWSessionOnVisitedFlags(NavigationHandle navigationHandle) {
int flags = 0;
// TODO: get different types of redirection.
if (navigationHandle.isInPrimaryMainFrame())
flags |= WSession.HistoryDelegate.VISIT_TOP_LEVEL;
if (navigationHandle.isRedirect()) {
int statusCode = navigationHandle.httpStatusCode();
flags |= (statusCode == 301 || statusCode == 308) ?
WSession.HistoryDelegate.VISIT_REDIRECT_SOURCE_PERMANENT :
WSession.HistoryDelegate.VISIT_REDIRECT_SOURCE;
}
if (navigationHandle.isErrorPage())
flags |= WSession.HistoryDelegate.VISIT_UNRECOVERABLE_ERROR;
return flags;
}

/**
* Called when the navigation is committed. The commit can be an error page if the server
* responded with an error code or a successful document. See also:
Expand All @@ -65,16 +81,20 @@ public void didStartNavigationInPrimaryMainFrame(NavigationHandle navigationHand
*/
@Override
public void didFinishNavigationInPrimaryMainFrame(NavigationHandle navigationHandle) {
WSession.NavigationDelegate delegate = mSession.getNavigationDelegate();
if (delegate == null)
WSession.NavigationDelegate navigationDelegate = mSession.getNavigationDelegate();
if (navigationDelegate == null)
return;

if (navigationHandle.isErrorPage()) {
didFailLoad(true, navigationHandle.errorCode(), navigationHandle.getUrl(), 0);
return;
}

delegate.onLocationChange(mSession, navigationHandle.getUrl().getSpec());
navigationDelegate.onLocationChange(mSession, navigationHandle.getUrl().getSpec());
WSession.HistoryDelegate historyDelegate = mSession.getHistoryDelegate();
if (historyDelegate != null) {
historyDelegate.onVisited(mSession, navigationHandle.getUrl().getSpec(), navigationHandle.getReferrerUrl().getSpec(), toWSessionOnVisitedFlags(navigationHandle));
}
}

@Override
Expand Down

0 comments on commit cc42251

Please sign in to comment.