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

Commit

Permalink
Ensure session tracking protection level is updated (#3278)
Browse files Browse the repository at this point in the history
Fixes #3264
  • Loading branch information
bluemarvin authored Apr 29, 2020
1 parent 4a2c1f7 commit 6a40b4b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,16 @@ private void cleanSessionListeners(GeckoSession aSession) {
aSession.setContentBlockingDelegate(null);
}

public void updateTrackingProtection() {
if ((mState != null) && (mState.mSettings != null)) {
TrackingProtectionPolicy policy = TrackingProtectionStore.getTrackingProtectionPolicy(mContext);
mState.mSettings.setTrackingProtectionEnabled(mState.mSettings.isPrivateBrowsingEnabled() || policy.shouldBlockContent());
if (mState.mSession != null) {
mState.mSession.getSettings().setUseTrackingProtection(mState.mSettings.isTrackingProtectionEnabled());
}
}
}

public void suspend() {
if (mState.isActive()) {
Log.e(LOGTAG, "Active Sessions can not be suspended");
Expand Down Expand Up @@ -450,6 +460,8 @@ private void restore() {
settings = new SessionSettings.Builder()
.withDefaultSettings(mContext)
.build();
} else {
updateTrackingProtection();
}

mState.mSession = createGeckoSession(settings);
Expand Down Expand Up @@ -521,9 +533,6 @@ public void recreateSession() {
SessionState previous = mState;
mState = mState.recreate();

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

restore();

GeckoSession previousGeckoSession = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ public void onExcludedTrackingProtectionChange(@NonNull String url, boolean excl

@Override
public void onTrackingProtectionLevelUpdated(int level) {
mSessions.forEach(Session::recreateSession);
mSessions.forEach(session -> {
if (session.isActive()) {
session.updateTrackingProtection();
session.reload(GeckoSession.LOAD_FLAGS_BYPASS_CACHE);
} else {
session.suspend();
}
});
}
});
}
Expand Down

0 comments on commit 6a40b4b

Please sign in to comment.