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

Commit 323d928

Browse files
keianhzoMortimerGoro
authored andcommitted
Improved History (#2417)
1 parent 3c4b0df commit 323d928

File tree

3 files changed

+80
-11
lines changed

3 files changed

+80
-11
lines changed

app/src/common/shared/org/mozilla/vrbrowser/browser/HistoryStore.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,22 @@ class HistoryStore constructor(val context: Context) {
7373
fun getDetailedHistory(): CompletableFuture<List<VisitInfo>?> = GlobalScope.future {
7474
storage.getDetailedVisits(0, excludeTypes = listOf(
7575
VisitType.NOT_A_VISIT,
76+
VisitType.DOWNLOAD,
7677
VisitType.REDIRECT_TEMPORARY,
78+
VisitType.RELOAD,
79+
VisitType.EMBED,
80+
VisitType.FRAMED_LINK,
7781
VisitType.REDIRECT_PERMANENT))
7882
}
7983

8084
fun getVisitsPaginated(offset: Long, count: Long): CompletableFuture<List<VisitInfo>?> = GlobalScope.future {
8185
storage.getVisitsPaginated(offset, count, excludeTypes = listOf(
8286
VisitType.NOT_A_VISIT,
87+
VisitType.DOWNLOAD,
8388
VisitType.REDIRECT_TEMPORARY,
89+
VisitType.RELOAD,
90+
VisitType.EMBED,
91+
VisitType.FRAMED_LINK,
8492
VisitType.REDIRECT_PERMANENT))
8593
}
8694

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.graphics.PointF;
1212
import android.graphics.Rect;
1313
import android.graphics.SurfaceTexture;
14+
import android.net.Uri;
1415
import android.util.Log;
1516
import android.util.Pair;
1617
import android.view.KeyEvent;
@@ -27,7 +28,6 @@
2728
import androidx.annotation.UiThread;
2829

2930
import org.jetbrains.annotations.NotNull;
30-
import org.mozilla.geckoview.AllowOrDeny;
3131
import org.mozilla.geckoview.GeckoResult;
3232
import org.mozilla.geckoview.GeckoSession;
3333
import org.mozilla.geckoview.PanZoomController;
@@ -66,8 +66,11 @@
6666
import java.util.Arrays;
6767
import java.util.Calendar;
6868
import java.util.GregorianCalendar;
69+
import java.util.List;
6970
import java.util.concurrent.CopyOnWriteArrayList;
7071
import java.util.concurrent.Executor;
72+
import java.util.stream.Collectors;
73+
import java.util.stream.Stream;
7174

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

1619+
// Check if we want this type of url.
1620+
if (!shouldStoreUri(url)) {
1621+
return GeckoResult.fromValue(false);
1622+
}
1623+
16161624
boolean isReload = lastVisitedURL != null && lastVisitedURL.equals(url);
16171625

1618-
PageVisit pageVisit;
1626+
VisitType visitType;
16191627
if (isReload) {
1620-
pageVisit = new PageVisit(VisitType.RELOAD, RedirectSource.NOT_A_SOURCE);
1628+
visitType = VisitType.RELOAD;
16211629

16221630
} else {
1623-
if ((flags & VISIT_REDIRECT_SOURCE_PERMANENT) != 0) {
1624-
pageVisit = new PageVisit(VisitType.REDIRECT_PERMANENT, RedirectSource.NOT_A_SOURCE);
1625-
} else if ((flags & VISIT_REDIRECT_SOURCE) != 0) {
1626-
pageVisit = new PageVisit(VisitType.REDIRECT_TEMPORARY, RedirectSource.NOT_A_SOURCE);
1631+
// Note the difference between `VISIT_REDIRECT_PERMANENT`,
1632+
// `VISIT_REDIRECT_TEMPORARY`, `VISIT_REDIRECT_SOURCE`, and
1633+
// `VISIT_REDIRECT_SOURCE_PERMANENT`.
1634+
//
1635+
// The former two indicate if the visited page is the *target*
1636+
// of a redirect; that is, another page redirected to it.
1637+
//
1638+
// The latter two indicate if the visited page is the *source*
1639+
// of a redirect: it's redirecting to another page, because the
1640+
// server returned an HTTP 3xy status code.
1641+
if ((flags & VISIT_REDIRECT_PERMANENT) != 0) {
1642+
visitType = VisitType.REDIRECT_PERMANENT;
1643+
1644+
} else if ((flags & VISIT_REDIRECT_TEMPORARY) != 0) {
1645+
visitType = VisitType.REDIRECT_TEMPORARY;
1646+
16271647
} else {
1628-
pageVisit = new PageVisit(VisitType.LINK, RedirectSource.NOT_A_SOURCE);
1648+
visitType = VisitType.LINK;
16291649
}
16301650
}
1651+
RedirectSource redirectSource;
1652+
if ((flags & GeckoSession.HistoryDelegate.VISIT_REDIRECT_SOURCE_PERMANENT) != 0) {
1653+
redirectSource = RedirectSource.PERMANENT;
1654+
1655+
} else if ((flags & GeckoSession.HistoryDelegate.VISIT_REDIRECT_SOURCE) != 0) {
1656+
redirectSource = RedirectSource.TEMPORARY;
1657+
1658+
} else {
1659+
redirectSource = RedirectSource.NOT_A_SOURCE;
1660+
}
16311661

1632-
SessionStore.get().getHistoryStore().recordVisit(url, pageVisit);
1662+
SessionStore.get().getHistoryStore().recordVisit(url, new PageVisit(visitType, redirectSource));
16331663
SessionStore.get().getHistoryStore().recordObservation(url, new PageObservation(url));
16341664

16351665
return GeckoResult.fromValue(true);
16361666
}
16371667

1668+
/**
1669+
* Filter out unwanted URIs, such as "chrome:", "about:", etc.
1670+
* Ported from nsAndroidHistory::CanAddURI
1671+
* See https://dxr.mozilla.org/mozilla-central/source/mobile/android/components/build/nsAndroidHistory.cpp#326
1672+
*/
1673+
private boolean shouldStoreUri(@NonNull String uri) {
1674+
Uri parsedUri = Uri.parse(uri);
1675+
String scheme = parsedUri.getScheme();
1676+
if (scheme == null) {
1677+
return false;
1678+
}
1679+
1680+
// Short-circuit most common schemes.
1681+
if (scheme.equals("http") || scheme.equals("https")) {
1682+
return true;
1683+
}
1684+
1685+
// Allow about about:reader uris. They are of the form:
1686+
// about:reader?url=http://some.interesting.page/to/read.html
1687+
if (uri.startsWith("about:reader")) {
1688+
return true;
1689+
}
1690+
1691+
List<String> schemasToIgnore = Stream.of(
1692+
"about", "imap", "news", "mailbox", "moz-anno", "moz-extension",
1693+
"view-source", "chrome", "resource", "data", "javascript", "blob"
1694+
).collect(Collectors.toList());
1695+
1696+
return !schemasToIgnore.contains(scheme);
1697+
}
1698+
16381699
@UiThread
16391700
@Nullable
16401701
public GeckoResult<boolean[]> getVisited(@NonNull GeckoSession geckoSession, @NonNull String[] urls) {

app/src/common/shared/org/mozilla/vrbrowser/utils/UrlUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
package org.mozilla.vrbrowser.utils;
77

8-
import java.util.regex.Pattern;
9-
108
import androidx.annotation.Nullable;
119

10+
import java.util.regex.Pattern;
11+
1212

1313
// This class refers from mozilla-mobile/focus-android
1414
public class UrlUtils {

0 commit comments

Comments
 (0)