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

Commit

Permalink
Fix user agent override when the page has iframes. (#910)
Browse files Browse the repository at this point in the history
GeckoView is calling onLoadRequest multiple times for a single page with different URLs. The additional calls were breaking the UA override code. This work around prevents the UA override code from being called more than once and only for the first onLoadRequest.
  • Loading branch information
bluemarvin authored Dec 20, 2018
1 parent f666370 commit 2096a29
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -945,10 +945,17 @@ public void onCanGoForward(GeckoSession aSession, boolean aCanGoForward) {
}
}

public boolean mFirstOnLoadRequest = true;

@Override
public @Nullable GeckoResult<AllowOrDeny> onLoadRequest(@NonNull GeckoSession aSession, @NonNull LoadRequest aRequest) {
final GeckoResult<AllowOrDeny> result = new GeckoResult<>();
aSession.getSettings().setString(GeckoSessionSettings.USER_AGENT_OVERRIDE, mUserAgentOverride.lookupOverride(aRequest.uri));
Log.d(LOGTAG, "onLoadRequest: " + aRequest.uri);
if (mFirstOnLoadRequest && (aSession == mCurrentSession)) {
Log.d(LOGTAG, "Testing for UA override");
aSession.getSettings().setString(GeckoSessionSettings.USER_AGENT_OVERRIDE, mUserAgentOverride.lookupOverride(aRequest.uri));
mFirstOnLoadRequest = false;
}
if (PRIVATE_BROWSING_URI.equalsIgnoreCase(aRequest.uri)) {
switchPrivateMode();
result.complete(AllowOrDeny.ALLOW);
Expand Down Expand Up @@ -1076,6 +1083,7 @@ public void onPageStop(GeckoSession aSession, boolean b) {
}

if (mCurrentSession == aSession) {
mFirstOnLoadRequest = true;
for (GeckoSession.ProgressDelegate listener : mProgressListeners) {
listener.onPageStop(aSession, b);
}
Expand Down

0 comments on commit 2096a29

Please sign in to comment.