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

Force tracking protection for Private Sessions #3090

Merged
merged 4 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,26 @@ public void fetchAll(Function<List<SitePermission>, Void> onResult) {

public void add(@NonNull Session session) {
mContentBlockingController.addException(session.getGeckoSession());
mListeners.forEach(listener -> listener.onExcludedTrackingProtectionChange(
UrlUtils.getHost(session.getCurrentUri()),
true));
persist();
// Private sessions don't persist to the content blocking controller exceptions list so we just notify
if (session.isPrivateMode()) {
mListeners.forEach(listener -> listener.onExcludedTrackingProtectionChange(
UrlUtils.getHost(session.getCurrentUri()),
true));
} else {
persist();
}
}

public void remove(@NonNull Session session) {
mContentBlockingController.removeException(session.getGeckoSession());
mListeners.forEach(listener -> listener.onExcludedTrackingProtectionChange(
UrlUtils.getHost(session.getCurrentUri()),
false));
persist();
// Private sessions don't persist to the content blocking controller exceptions list so we just notify
if (session.isPrivateMode()) {
mListeners.forEach(listener -> listener.onExcludedTrackingProtectionChange(
UrlUtils.getHost(session.getCurrentUri()),
true));
} else {
persist();
}
}

public void remove(@NonNull SitePermission permission) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public void recreateSession() {
mState = mState.recreate();

TrackingProtectionPolicy policy = TrackingProtectionStore.getTrackingProtectionPolicy(mContext);
mState.mSettings.setTrackingProtectionEnabled(policy.shouldBlockContent());
mState.mSettings.setTrackingProtectionEnabled(mState.mSettings.isPrivateBrowsingEnabled() || policy.shouldBlockContent());

restore();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ public Builder() {

public Builder withPrivateBrowsing(boolean enabled) {
isPrivateBrowsingEnabled = enabled;
isTrackingProtectionEnabled = isPrivateBrowsingEnabled || isTrackingProtectionEnabled;

return this;
}

public Builder withTrackingProtection(boolean isTrackingProtectionEnabled){
this.isTrackingProtectionEnabled = isTrackingProtectionEnabled;
this.isTrackingProtectionEnabled = isPrivateBrowsingEnabled || isTrackingProtectionEnabled;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void onExcludedTrackingProtectionChange(@NonNull String host, boolean exc
mSessions.forEach(existingSession -> {
String existingHost = UrlUtils.getHost(existingSession.getCurrentUri());
if (existingHost.equals(host)) {
existingSession.recreateSession();
existingSession.reload(GeckoSession.LOAD_FLAGS_BYPASS_CACHE);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public void onChanged(Spannable aUrl) {
!isLibraryVisible.getValue().get() &&
!UrlUtils.isContentFeed(getApplication(), aUrl.toString()) &&
!UrlUtils.isFileUri(aUrl.toString()) &&
!UrlUtils.isPrivateAboutPage(getApplication(), aUrl.toString()) &&
(
(SettingsStore.getInstance(getApplication()).getTrackingProtectionLevel() != ContentBlocking.EtpLevel.NONE) ||
isPopUpAvailable.getValue().get() ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ public void detachFromWindow() {
mViewModel.getIsFullscreen().removeObserver(mIsFullscreenObserver);
mViewModel.getIsActiveWindow().removeObserver(mIsActiveWindowObserver);
mViewModel.getIsPopUpBlocked().removeObserver(mIsPopUpBlockedListener);
mViewModel.getUrl().removeObserver(mUrlObserver);
mViewModel = null;
}

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

mTrackingDelegate.addListener(mTrackingListener);
Expand Down Expand Up @@ -803,6 +801,15 @@ private void closeFloatingMenus() {
}
}

// NavigationDelegate

@Override
public void onLocationChange(@NonNull GeckoSession geckoSession, @Nullable String s) {
if (getSession() != null && getSession().getGeckoSession() == geckoSession) {
updateTrackingProtection();
}
}

// Content delegate

private Observer<ObservableBoolean> mIsFullscreenObserver = isFullScreen -> {
Expand Down Expand Up @@ -835,8 +842,6 @@ private void closeFloatingMenus() {
}
};

private Observer<Spannable> mUrlObserver = sitePermissions -> updateTrackingProtection();

private Observer<ObservableBoolean> mIsActiveWindowObserver = aIsActiveWindow -> updateTrackingProtection();

private Observer<ObservableBoolean> mIsPopUpBlockedListener = observableBoolean -> {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/navigation_url.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
android:src="@{viewmodel.isTrackingEnabled ? @drawable/ic_icon_tracking_enabled : @drawable/ic_icon_tracking_disabled}"
app:privateMode="@{viewmodel.isPrivateSession}"
android:tint="@color/fog"
app:visibleGone="@{settingsViewmodel.isTrackingProtectionEnabled}"
app:visibleGone="@{!UrlUtils.isPrivateAboutPage(context, viewmodel.url.toString()) &amp;&amp; settingsViewmodel.isTrackingProtectionEnabled &amp;&amp; !UrlUtils.isContentFeed(context, viewmodel.url.toString())}"
android:tooltipText="@{viewmodel.isTrackingEnabled ? @string/tracking_allowed_tooltip : @string/tracking_disabled_tooltip}" />

<LinearLayout
Expand Down