Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4514)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java

Issue 1688603004: AGSA-initiated weblite intents should be rewritten if Chrome can use weblite (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bug fix Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java b/chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java
index 569eb7cbc3aeba429aefe2160b02333ce4260a63..5ffe3fd9191b8227fd8af49843a36f0045f8da99 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java
@@ -5,7 +5,10 @@
package org.chromium.chrome.browser.net.spdyproxy;
import android.content.Context;
+import android.net.Uri;
import android.preference.PreferenceManager;
+import android.text.TextUtils;
+import android.webkit.URLUtil;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
@@ -55,6 +58,10 @@ public class DataReductionProxySettings {
private static final String DATA_REDUCTION_ENABLED_PREF = "BANDWIDTH_REDUCTION_PROXY_ENABLED";
+ private static final String WEBLITE_HOSTNAME = "googleweblight.com";
+
+ private static final String WEBLITE_QUERY_PARAM = "lite_url";
+
/**
* Returns whether the data reduction proxy is enabled.
*
@@ -269,6 +276,39 @@ public class DataReductionProxySettings {
return map;
}
+ /**
+ * If the given URL is a WebLite URL and should be overridden because the Data
+ * Reduction Proxy is on, the user is in the Lo-Fi previews experiment, and the scheme of the
+ * lite_url param is HTTP, returns the URL contained in the lite_url param. Otherwise returns
+ * the given URL.
+ *
+ * @param url The URL to evaluate.
+ * @return The URL to be used. Returns null if the URL param is null.
+ */
+ public String maybeRewriteWebliteUrl(String url) {
+ if (url == null || !URLUtil.isValidUrl(url) || !areLoFiPreviewsEnabled()
+ || !isDataReductionProxyEnabled()) {
+ return url;
+ }
+ String rewritten = extractUrlFromWebliteQueryParams(url);
+ if (rewritten == null
+ || !TextUtils.equals(Uri.parse(rewritten).getScheme(), "http")) {
+ return url;
+ }
+
+ return rewritten;
+ }
+
+ private String extractUrlFromWebliteQueryParams(String url) {
+ Uri uri = Uri.parse(url);
+ if (!TextUtils.equals(uri.getHost(), WEBLITE_HOSTNAME)) return null;
+ return uri.getQueryParameter(WEBLITE_QUERY_PARAM);
+ }
+
+ private boolean areLoFiPreviewsEnabled() {
+ return nativeAreLoFiPreviewsEnabled(mNativeDataReductionProxySettings);
+ }
+
private native long nativeInit();
private native boolean nativeIsDataReductionProxyAllowed(
long nativeDataReductionProxySettingsAndroid);
@@ -304,6 +344,8 @@ public class DataReductionProxySettings {
long nativeDataReductionProxySettingsAndroid);
private native boolean nativeIsDataReductionProxyUnreachable(
long nativeDataReductionProxySettingsAndroid);
+ private native boolean nativeAreLoFiPreviewsEnabled(
+ long nativeDataReductionProxySettingsAndroid);
private native String nativeGetHttpProxyList(long nativeDataReductionProxySettingsAndroid);
private native String nativeGetHttpsProxyList(long nativeDataReductionProxySettingsAndroid);
private native String nativeGetLastBypassEvent(long nativeDataReductionProxySettingsAndroid);

Powered by Google App Engine
This is Rietveld 408576698