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

Commit

Permalink
Only create one UserAgentOverride object (#2254)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluemarvin authored and MortimerGoro committed Nov 14, 2019
1 parent c4b0ce7 commit f17853a
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class Session implements ContentBlocking.Delegate, GeckoSession.Navigatio
GeckoSession.SelectionActionDelegate, SharedPreferences.OnSharedPreferenceChangeListener, SessionChangeListener {

private static final String LOGTAG = SystemUtils.createLogtag(Session.class);
private static UserAgentOverride sUserAgentOverride;


private transient LinkedList<GeckoSession.NavigationDelegate> mNavigationListeners;
private transient LinkedList<GeckoSession.ProgressDelegate> mProgressListeners;
Expand All @@ -70,7 +72,6 @@ public class Session implements ContentBlocking.Delegate, GeckoSession.Navigatio
private transient LinkedList<VideoAvailabilityListener> mVideoAvailabilityListeners;
private transient LinkedList<BitmapChangedListener> mBitmapChangedListeners;
private transient LinkedList<GeckoSession.SelectionActionDelegate> mSelectionActionListeners;
private transient UserAgentOverride mUserAgentOverride;

private SessionState mState;
private LinkedList<Runnable> mQueuedCalls = new LinkedList<>();
Expand Down Expand Up @@ -142,9 +143,9 @@ private void initialize() {
InternalPages.PageResources pageResources = InternalPages.PageResources.create(R.raw.private_mode, R.raw.private_style);
mPrivatePage = InternalPages.createAboutPage(mContext, pageResources);

if (mUserAgentOverride == null) {
mUserAgentOverride = new UserAgentOverride();
mUserAgentOverride.loadOverridesFromAssets((Activity)mContext, mContext.getString(R.string.user_agent_override_file));
if (sUserAgentOverride == null) {
sUserAgentOverride = new UserAgentOverride();
sUserAgentOverride.loadOverridesFromAssets((Activity)mContext, mContext.getString(R.string.user_agent_override_file));
}
}

Expand Down Expand Up @@ -847,7 +848,7 @@ public void onCanGoForward(@NonNull GeckoSession aSession, boolean aCanGoForward
if (aSession == mState.mSession) {
Log.d(LOGTAG, "Testing for UA override");

final String userAgentOverride = mUserAgentOverride.lookupOverride(uri);
final String userAgentOverride = sUserAgentOverride.lookupOverride(uri);
aSession.getSettings().setUserAgentOverride(userAgentOverride);
if (mState.mSettings != null) {
mState.mSettings.setUserAgentOverride(userAgentOverride);
Expand Down

0 comments on commit f17853a

Please sign in to comment.