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

Commit

Permalink
Fix youtube viewport issues. (#3870)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored Aug 27, 2020
1 parent 8626139 commit 66adf63
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -95,7 +94,7 @@ public class Session implements ContentBlocking.Delegate, GeckoSession.Navigatio
private transient boolean mFirstContentfulPaint;
private transient long mKeepAlive;

private static final List<String> FORCE_MOBILE = Collections.singletonList(".youtube.com");
private static final List<String> FORCE_MOBILE_VIEWPORT = Collections.singletonList(".youtube.com");

public interface BitmapChangedListener {
void onBitmapChanged(Session aSession, Bitmap aBitmap);
Expand Down Expand Up @@ -1042,8 +1041,7 @@ public void setUaMode(int mode) {
mState.mSettings.setUserAgentMode(mode);
mState.mSession.getSettings().setUserAgentMode(mode);
String overrideUri = null;
boolean forceMobile = FORCE_MOBILE.stream().anyMatch(uri -> mState.mUri.contains(uri));
if (mode == GeckoSessionSettings.USER_AGENT_MODE_DESKTOP && !forceMobile) {
if (mode == GeckoSessionSettings.USER_AGENT_MODE_DESKTOP) {
mState.mSettings.setViewportMode(GeckoSessionSettings.VIEWPORT_MODE_DESKTOP);
overrideUri = checkForMobileSite(mState.mUri);
} else {
Expand Down Expand Up @@ -1089,6 +1087,13 @@ public void onLocationChange(@NonNull GeckoSession aSession, String aUri) {
mState.mPreviousUri = mState.mUri;
mState.mUri = aUri;

boolean forceMobileViewport = FORCE_MOBILE_VIEWPORT.stream().anyMatch(aUri::contains);
if (forceMobileViewport) {
mState.mSession.getSettings().setViewportMode(GeckoSessionSettings.VIEWPORT_MODE_MOBILE);
} else {
mState.mSession.getSettings().setViewportMode(mState.mSettings.getViewportMode());
}

for (GeckoSession.NavigationDelegate listener : mNavigationListeners) {
listener.onLocationChange(aSession, aUri);
}
Expand Down

0 comments on commit 66adf63

Please sign in to comment.