From 6e940b0a1536ccbadc7f0798da306669dbb45d8c Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Thu, 24 Mar 2016 21:41:31 -0400 Subject: [PATCH] Only Kitkat and up supports changing headers, disable on lower API versions --- .../lightning/fragment/PrivacySettingsFragment.java | 7 +++++-- .../main/java/acr/browser/lightning/utils/Utils.java | 5 +++++ .../browser/lightning/view/LightningWebClient.java | 11 ++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java index 60a68cd..24162a1 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java @@ -95,8 +95,11 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme cbcookiesexit.setChecked(mPreferenceManager.getClearCookiesExitEnabled()); cb3cookies.setChecked(mPreferenceManager.getBlockThirdPartyCookiesEnabled()); cbwebstorageexit.setChecked(mPreferenceManager.getClearWebStorageExitEnabled()); - cbDoNotTrack.setChecked(mPreferenceManager.getDoNotTrackEnabled()); - cbIdentifyingHeaders.setChecked(mPreferenceManager.getRemoveIdentifyingHeadersEnabled()); + cbDoNotTrack.setChecked(mPreferenceManager.getDoNotTrackEnabled() && Utils.doesSupportHeaders()); + cbIdentifyingHeaders.setChecked(mPreferenceManager.getRemoveIdentifyingHeadersEnabled() && Utils.doesSupportHeaders()); + + cbDoNotTrack.setEnabled(Utils.doesSupportHeaders()); + cbIdentifyingHeaders.setEnabled(Utils.doesSupportHeaders()); String identifyingHeadersSummary = LightningView.HEADER_REQUESTED_WITH + ", " + LightningView.HEADER_WAP_PROFILE; cbIdentifyingHeaders.setSummary(identifyingHeadersSummary); diff --git a/app/src/main/java/acr/browser/lightning/utils/Utils.java b/app/src/main/java/acr/browser/lightning/utils/Utils.java index bd55129..705ed2c 100644 --- a/app/src/main/java/acr/browser/lightning/utils/Utils.java +++ b/app/src/main/java/acr/browser/lightning/utils/Utils.java @@ -21,6 +21,7 @@ import android.graphics.Paint; import android.graphics.Path; import android.graphics.Shader; import android.net.Uri; +import android.os.Build; import android.os.Environment; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -53,6 +54,10 @@ import acr.browser.lightning.preference.PreferenceManager; public final class Utils { + public static boolean doesSupportHeaders() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; + } + /** * Downloads a file from the specified URL. Handles permissions * requests, and creates all the necessary dialogs that must be diff --git a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java index 6d309bf..0e8284c 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java @@ -47,11 +47,9 @@ import acr.browser.lightning.utils.Utils; public class LightningWebClient extends WebViewClient { - @NonNull private final Activity mActivity; @NonNull private final LightningView mLightningView; @NonNull private final UIController mUIController; - @NonNull private final Bus mEventBus; @NonNull private final IntentUtils mIntentUtils; @Inject ProxyUtils mProxyUtils; @@ -65,7 +63,6 @@ public class LightningWebClient extends WebViewClient { mUIController = (UIController) activity; mLightningView = lightningView; mAdBlock.updatePreference(); - mEventBus = BrowserApp.getBus(activity); mIntentUtils = new IntentUtils(activity); } @@ -285,11 +282,11 @@ public class LightningWebClient extends WebViewClient { Map headers = mLightningView.getRequestHeaders(); - if (mLightningView.isIncognito()) { + if (mLightningView.isIncognito() && Utils.doesSupportHeaders()) { view.loadUrl(url, headers); return true; } - if (url.startsWith("about:")) { + if (url.startsWith("about:") && Utils.doesSupportHeaders()) { view.loadUrl(url, headers); return true; } @@ -322,9 +319,9 @@ public class LightningWebClient extends WebViewClient { } } - if (!mIntentUtils.startActivityForUrl(view, url)) { + if (!mIntentUtils.startActivityForUrl(view, url) && Utils.doesSupportHeaders()) { view.loadUrl(url, headers); } - return true; + return Utils.doesSupportHeaders() || super.shouldOverrideUrlLoading(view, url); } }