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

Only create one UserAgentOverride object #2254

Merged
merged 1 commit into from
Nov 14, 2019
Merged
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 @@ -60,6 +60,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 @@ -69,7 +71,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 @@ -141,9 +142,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) {
MortimerGoro marked this conversation as resolved.
Show resolved Hide resolved
sUserAgentOverride = new UserAgentOverride();
sUserAgentOverride.loadOverridesFromAssets((Activity)mContext, mContext.getString(R.string.user_agent_override_file));
}
}

Expand Down Expand Up @@ -849,7 +850,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