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

Commit 07cad82

Browse files
keianhzobluemarvin
andauthored
Force tracking protection for Private Sessions (#3090)
* Hide ETP button in PB and force tracking protection for Private Sessions * Show ETP in private mode except PB page. Padding fixes * Use reload instead of recreateSession when adding/removing exceptions * Remove extra tracking exclusion notifications Update tracking protection on location change instead of url change Rebase fixes Co-authored-by: Randall E. Barker <[email protected]>
1 parent c40d2d8 commit 07cad82

File tree

7 files changed

+32
-16
lines changed

7 files changed

+32
-16
lines changed

app/src/common/shared/org/mozilla/vrbrowser/browser/content/TrackingProtectionStore.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,26 @@ public void fetchAll(Function<List<SitePermission>, Void> onResult) {
226226

227227
public void add(@NonNull Session session) {
228228
mContentBlockingController.addException(session.getGeckoSession());
229-
mListeners.forEach(listener -> listener.onExcludedTrackingProtectionChange(
230-
UrlUtils.getHost(session.getCurrentUri()),
231-
true));
232-
persist();
229+
// Private sessions don't persist to the content blocking controller exceptions list so we just notify
230+
if (session.isPrivateMode()) {
231+
mListeners.forEach(listener -> listener.onExcludedTrackingProtectionChange(
232+
UrlUtils.getHost(session.getCurrentUri()),
233+
true));
234+
} else {
235+
persist();
236+
}
233237
}
234238

235239
public void remove(@NonNull Session session) {
236240
mContentBlockingController.removeException(session.getGeckoSession());
237-
mListeners.forEach(listener -> listener.onExcludedTrackingProtectionChange(
238-
UrlUtils.getHost(session.getCurrentUri()),
239-
false));
240-
persist();
241+
// Private sessions don't persist to the content blocking controller exceptions list so we just notify
242+
if (session.isPrivateMode()) {
243+
mListeners.forEach(listener -> listener.onExcludedTrackingProtectionChange(
244+
UrlUtils.getHost(session.getCurrentUri()),
245+
true));
246+
} else {
247+
persist();
248+
}
241249
}
242250

243251
public void remove(@NonNull SitePermission permission) {

app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public void recreateSession() {
522522
mState = mState.recreate();
523523

524524
TrackingProtectionPolicy policy = TrackingProtectionStore.getTrackingProtectionPolicy(mContext);
525-
mState.mSettings.setTrackingProtectionEnabled(policy.shouldBlockContent());
525+
mState.mSettings.setTrackingProtectionEnabled(mState.mSettings.isPrivateBrowsingEnabled() || policy.shouldBlockContent());
526526

527527
restore();
528528

app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionSettings.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ public Builder() {
8989

9090
public Builder withPrivateBrowsing(boolean enabled) {
9191
isPrivateBrowsingEnabled = enabled;
92+
isTrackingProtectionEnabled = isPrivateBrowsingEnabled || isTrackingProtectionEnabled;
93+
9294
return this;
9395
}
9496

9597
public Builder withTrackingProtection(boolean isTrackingProtectionEnabled){
96-
this.isTrackingProtectionEnabled = isTrackingProtectionEnabled;
98+
this.isTrackingProtectionEnabled = isPrivateBrowsingEnabled || isTrackingProtectionEnabled;
9799
return this;
98100
}
99101

app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void onExcludedTrackingProtectionChange(@NonNull String host, boolean exc
7070
mSessions.forEach(existingSession -> {
7171
String existingHost = UrlUtils.getHost(existingSession.getCurrentUri());
7272
if (existingHost.equals(host)) {
73-
existingSession.recreateSession();
73+
existingSession.reload(GeckoSession.LOAD_FLAGS_BYPASS_CACHE);
7474
}
7575
});
7676
}

app/src/common/shared/org/mozilla/vrbrowser/ui/viewmodel/WindowViewModel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ public void onChanged(Spannable aUrl) {
317317
!isLibraryVisible.getValue().get() &&
318318
!UrlUtils.isContentFeed(getApplication(), aUrl.toString()) &&
319319
!UrlUtils.isFileUri(aUrl.toString()) &&
320+
!UrlUtils.isPrivateAboutPage(getApplication(), aUrl.toString()) &&
320321
(
321322
(SettingsStore.getInstance(getApplication()).getTrackingProtectionLevel() != ContentBlocking.EtpLevel.NONE) ||
322323
isPopUpAvailable.getValue().get() ||

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ public void detachFromWindow() {
491491
mViewModel.getIsFullscreen().removeObserver(mIsFullscreenObserver);
492492
mViewModel.getIsActiveWindow().removeObserver(mIsActiveWindowObserver);
493493
mViewModel.getIsPopUpBlocked().removeObserver(mIsPopUpBlockedListener);
494-
mViewModel.getUrl().removeObserver(mUrlObserver);
495494
mViewModel = null;
496495
}
497496

@@ -518,7 +517,6 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {
518517
mViewModel.getIsFullscreen().observeForever( mIsFullscreenObserver);
519518
mViewModel.getIsActiveWindow().observeForever(mIsActiveWindowObserver);
520519
mViewModel.getIsPopUpBlocked().observeForever(mIsPopUpBlockedListener);
521-
mViewModel.getUrl().observeForever(mUrlObserver);
522520
mBinding.navigationBarNavigation.urlBar.attachToWindow(mAttachedWindow);
523521

524522
mTrackingDelegate.addListener(mTrackingListener);
@@ -803,6 +801,15 @@ private void closeFloatingMenus() {
803801
}
804802
}
805803

804+
// NavigationDelegate
805+
806+
@Override
807+
public void onLocationChange(@NonNull GeckoSession geckoSession, @Nullable String s) {
808+
if (getSession() != null && getSession().getGeckoSession() == geckoSession) {
809+
updateTrackingProtection();
810+
}
811+
}
812+
806813
// Content delegate
807814

808815
private Observer<ObservableBoolean> mIsFullscreenObserver = isFullScreen -> {
@@ -835,8 +842,6 @@ private void closeFloatingMenus() {
835842
}
836843
};
837844

838-
private Observer<Spannable> mUrlObserver = sitePermissions -> updateTrackingProtection();
839-
840845
private Observer<ObservableBoolean> mIsActiveWindowObserver = aIsActiveWindow -> updateTrackingProtection();
841846

842847
private Observer<ObservableBoolean> mIsPopUpBlockedListener = observableBoolean -> {

app/src/main/res/layout/navigation_url.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
android:src="@{viewmodel.isTrackingEnabled ? @drawable/ic_icon_tracking_enabled : @drawable/ic_icon_tracking_disabled}"
5454
app:privateMode="@{viewmodel.isPrivateSession}"
5555
android:tint="@color/fog"
56-
app:visibleGone="@{settingsViewmodel.isTrackingProtectionEnabled}"
56+
app:visibleGone="@{!UrlUtils.isPrivateAboutPage(context, viewmodel.url.toString()) &amp;&amp; settingsViewmodel.isTrackingProtectionEnabled &amp;&amp; !UrlUtils.isContentFeed(context, viewmodel.url.toString())}"
5757
android:tooltipText="@{viewmodel.isTrackingEnabled ? @string/tracking_allowed_tooltip : @string/tracking_disabled_tooltip}" />
5858

5959
<LinearLayout

0 commit comments

Comments
 (0)