Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Improved History (#2417)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and MortimerGoro committed Dec 9, 2019
1 parent 3c4b0df commit 323d928
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,22 @@ class HistoryStore constructor(val context: Context) {
fun getDetailedHistory(): CompletableFuture<List<VisitInfo>?> = GlobalScope.future {
storage.getDetailedVisits(0, excludeTypes = listOf(
VisitType.NOT_A_VISIT,
VisitType.DOWNLOAD,
VisitType.REDIRECT_TEMPORARY,
VisitType.RELOAD,
VisitType.EMBED,
VisitType.FRAMED_LINK,
VisitType.REDIRECT_PERMANENT))
}

fun getVisitsPaginated(offset: Long, count: Long): CompletableFuture<List<VisitInfo>?> = GlobalScope.future {
storage.getVisitsPaginated(offset, count, excludeTypes = listOf(
VisitType.NOT_A_VISIT,
VisitType.DOWNLOAD,
VisitType.REDIRECT_TEMPORARY,
VisitType.RELOAD,
VisitType.EMBED,
VisitType.FRAMED_LINK,
VisitType.REDIRECT_PERMANENT))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.net.Uri;
import android.util.Log;
import android.util.Pair;
import android.view.KeyEvent;
Expand All @@ -27,7 +28,6 @@
import androidx.annotation.UiThread;

import org.jetbrains.annotations.NotNull;
import org.mozilla.geckoview.AllowOrDeny;
import org.mozilla.geckoview.GeckoResult;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.PanZoomController;
Expand Down Expand Up @@ -66,8 +66,11 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import mozilla.components.concept.storage.PageObservation;
import mozilla.components.concept.storage.PageVisit;
Expand Down Expand Up @@ -1613,28 +1616,86 @@ public GeckoResult<Boolean> onVisited(@NonNull GeckoSession geckoSession, @NonNu
return GeckoResult.fromValue(false);
}

// Check if we want this type of url.
if (!shouldStoreUri(url)) {
return GeckoResult.fromValue(false);
}

boolean isReload = lastVisitedURL != null && lastVisitedURL.equals(url);

PageVisit pageVisit;
VisitType visitType;
if (isReload) {
pageVisit = new PageVisit(VisitType.RELOAD, RedirectSource.NOT_A_SOURCE);
visitType = VisitType.RELOAD;

} else {
if ((flags & VISIT_REDIRECT_SOURCE_PERMANENT) != 0) {
pageVisit = new PageVisit(VisitType.REDIRECT_PERMANENT, RedirectSource.NOT_A_SOURCE);
} else if ((flags & VISIT_REDIRECT_SOURCE) != 0) {
pageVisit = new PageVisit(VisitType.REDIRECT_TEMPORARY, RedirectSource.NOT_A_SOURCE);
// Note the difference between `VISIT_REDIRECT_PERMANENT`,
// `VISIT_REDIRECT_TEMPORARY`, `VISIT_REDIRECT_SOURCE`, and
// `VISIT_REDIRECT_SOURCE_PERMANENT`.
//
// The former two indicate if the visited page is the *target*
// of a redirect; that is, another page redirected to it.
//
// The latter two indicate if the visited page is the *source*
// of a redirect: it's redirecting to another page, because the
// server returned an HTTP 3xy status code.
if ((flags & VISIT_REDIRECT_PERMANENT) != 0) {
visitType = VisitType.REDIRECT_PERMANENT;

} else if ((flags & VISIT_REDIRECT_TEMPORARY) != 0) {
visitType = VisitType.REDIRECT_TEMPORARY;

} else {
pageVisit = new PageVisit(VisitType.LINK, RedirectSource.NOT_A_SOURCE);
visitType = VisitType.LINK;
}
}
RedirectSource redirectSource;
if ((flags & GeckoSession.HistoryDelegate.VISIT_REDIRECT_SOURCE_PERMANENT) != 0) {
redirectSource = RedirectSource.PERMANENT;

} else if ((flags & GeckoSession.HistoryDelegate.VISIT_REDIRECT_SOURCE) != 0) {
redirectSource = RedirectSource.TEMPORARY;

} else {
redirectSource = RedirectSource.NOT_A_SOURCE;
}

SessionStore.get().getHistoryStore().recordVisit(url, pageVisit);
SessionStore.get().getHistoryStore().recordVisit(url, new PageVisit(visitType, redirectSource));
SessionStore.get().getHistoryStore().recordObservation(url, new PageObservation(url));

return GeckoResult.fromValue(true);
}

/**
* Filter out unwanted URIs, such as "chrome:", "about:", etc.
* Ported from nsAndroidHistory::CanAddURI
* See https://dxr.mozilla.org/mozilla-central/source/mobile/android/components/build/nsAndroidHistory.cpp#326
*/
private boolean shouldStoreUri(@NonNull String uri) {
Uri parsedUri = Uri.parse(uri);
String scheme = parsedUri.getScheme();
if (scheme == null) {
return false;
}

// Short-circuit most common schemes.
if (scheme.equals("http") || scheme.equals("https")) {
return true;
}

// Allow about about:reader uris. They are of the form:
// about:reader?url=http://some.interesting.page/to/read.html
if (uri.startsWith("about:reader")) {
return true;
}

List<String> schemasToIgnore = Stream.of(
"about", "imap", "news", "mailbox", "moz-anno", "moz-extension",
"view-source", "chrome", "resource", "data", "javascript", "blob"
).collect(Collectors.toList());

return !schemasToIgnore.contains(scheme);
}

@UiThread
@Nullable
public GeckoResult<boolean[]> getVisited(@NonNull GeckoSession geckoSession, @NonNull String[] urls) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

package org.mozilla.vrbrowser.utils;

import java.util.regex.Pattern;

import androidx.annotation.Nullable;

import java.util.regex.Pattern;


// This class refers from mozilla-mobile/focus-android
public class UrlUtils {
Expand Down

0 comments on commit 323d928

Please sign in to comment.