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

Commit

Permalink
Restore userAgentOverride when restoring state (#1125) (#1913)
Browse files Browse the repository at this point in the history
When restoring state using session.restoreState, `onLoadRequest` is not called
which causes FxR's UA override logic to not run. To fix this, we remember the
UA override string and restore it.
  • Loading branch information
agi authored and bluemarvin committed Oct 4, 2019
1 parent 1e408bf commit 4f9f8cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SessionSettings {
private int userAgentMode;
private int viewportMode;
private boolean isServoEnabled;
private String userAgentOverride;

private SessionSettings(@NotNull Builder builder) {
this.isMultiprocessEnabled = builder.isMultiprocessEnabled;
Expand All @@ -22,6 +23,7 @@ private SessionSettings(@NotNull Builder builder) {
this.userAgentMode = builder.userAgentMode;
this.viewportMode = builder.viewportMode;
this.isServoEnabled = builder.isServoEnabled;
this.userAgentOverride = builder.userAgentOverride;
}

public boolean isMultiprocessEnabled() {
Expand Down Expand Up @@ -52,6 +54,14 @@ public void setUserAgentMode(int mode) {
userAgentMode = mode;
}

public void setUserAgentOverride(String userAgentOverride) {
this.userAgentOverride = userAgentOverride;
}

public String getUserAgentOverride() {
return userAgentOverride;
}

public int getViewportMode() { return viewportMode; }

public void setViewportMode(final int mode) { viewportMode = mode; }
Expand All @@ -72,6 +82,7 @@ public static class Builder {
private int userAgentMode;
private int viewportMode;
private boolean isServoEnabled;
private String userAgentOverride;

public Builder() {
}
Expand Down Expand Up @@ -106,6 +117,11 @@ public Builder withServo(boolean isServoEnabled){
return this;
}

public Builder withUserAgentOverride(String userAgentOverride) {
this.userAgentOverride = userAgentOverride;
return this;
}

public Builder withDefaultSettings(Context context) {
return new SessionSettings.Builder()
.withMultiprocess(SettingsStore.getInstance(context).isMultiprocessEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public void restore(SessionStack store, int currentSessionId) {
.useMultiprocess(state.mSettings.isMultiprocessEnabled())
.usePrivateMode(mUsePrivateMode)
.userAgentMode(state.mSettings.getUserAgentMode())
.userAgentOverride(state.mSettings.getUserAgentOverride())
.suspendMediaWhenInactive(state.mSettings.isSuspendMediaWhenInactiveEnabled())
.useTrackingProtection(state.mSettings.isTrackingProtectionEnabled())
.build();
Expand Down Expand Up @@ -366,6 +367,7 @@ private int createSession(@NonNull SessionSettings aSettings) {

state.mSession.getSettings().setSuspendMediaWhenInactive(aSettings.isSuspendMediaWhenInactiveEnabled());
state.mSession.getSettings().setUserAgentMode(aSettings.getUserAgentMode());
state.mSession.getSettings().setUserAgentOverride(aSettings.getUserAgentOverride());
state.mSession.setNavigationDelegate(this);
state.mSession.setProgressDelegate(this);
state.mSession.setContentDelegate(this);
Expand Down Expand Up @@ -954,8 +956,12 @@ public void onCanGoForward(@NonNull GeckoSession aSession, boolean aCanGoForward
}

if (aSession == mCurrentSession) {
SessionState state = mSessions.get(getCurrentSessionId());
Log.d(LOGTAG, "Testing for UA override");
aSession.getSettings().setUserAgentOverride(mUserAgentOverride.lookupOverride(uri));

final String userAgentOverride = mUserAgentOverride.lookupOverride(uri);
aSession.getSettings().setUserAgentOverride(userAgentOverride);
state.mSettings.setUserAgentOverride(userAgentOverride);
}

if (mContext.getString(R.string.about_private_browsing).equalsIgnoreCase(uri)) {
Expand Down

0 comments on commit 4f9f8cf

Please sign in to comment.