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

Commit

Permalink
Disable polymer on youtube via URL override (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored Nov 24, 2018
1 parent c48ec49 commit 6307d91
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
Expand Down Expand Up @@ -946,8 +947,14 @@ public void onCanGoForward(GeckoSession aSession, boolean aCanGoForward) {
if (PRIVATE_BROWSING_URI.equalsIgnoreCase(aRequest.uri)) {
switchPrivateMode();
result.complete(AllowOrDeny.ALLOW);

} else {
String override = checkYoutubeOverride(aRequest.uri);
if (override != null) {
aSession.loadUri(override);
result.complete(AllowOrDeny.DENY);
return result;
}

AtomicInteger count = new AtomicInteger(0);
AtomicBoolean allowed = new AtomicBoolean(false);
for (GeckoSession.NavigationDelegate listener: mNavigationListeners) {
Expand All @@ -968,6 +975,29 @@ public void onCanGoForward(GeckoSession aSession, boolean aCanGoForward) {
return result;
}

/*
* Polymer makes youtube very slow. Disable it via URL parameter.
*/
private String checkYoutubeOverride(String aUri) {
try {
Uri uri = Uri.parse(aUri);
if (!uri.getHost().toLowerCase().contains("www.youtube.")) {
return null;
}
String query = uri.getQueryParameter("disable_polymer");
if (query != null) {
return null;
}
String result = aUri;
result += aUri.contains("?") ? "&" : "?";
result += "disable_polymer=1";
return result;
}
catch (Exception ex) {
return null;
}
}

@Override
public GeckoResult<GeckoSession> onNewSession(@NonNull GeckoSession aSession, @NonNull String aUri) {
Log.d(LOGTAG, "SessionStore onNewSession: " + aUri);
Expand Down

0 comments on commit 6307d91

Please sign in to comment.