Browse Source

Added option to block third party cookies

master
Anthony Restaino 10 years ago
parent
commit
a897ae4d3e
  1. 35
      res/layout/privacy_settings.xml
  2. 2
      res/values/strings.xml
  3. 6
      src/acr/browser/lightning/BrowserActivity.java
  4. 4
      src/acr/browser/lightning/IncognitoActivity.java
  5. 5
      src/acr/browser/lightning/LightningView.java
  6. 4
      src/acr/browser/lightning/MainActivity.java
  7. 1
      src/acr/browser/lightning/PreferenceConstants.java
  8. 54
      src/acr/browser/lightning/PrivacySettingsActivity.java

35
res/layout/privacy_settings.xml

@ -45,6 +45,41 @@
android:layout_centerVertical="true" /> android:layout_centerVertical="true" />
</RelativeLayout> </RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#cdcdcd" />
<RelativeLayout
android:id="@+id/rThirdParty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:paddingRight="30dp"
android:text="@string/third_party"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="@+id/cbThirdParty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"

2
res/values/strings.xml

@ -195,4 +195,6 @@
<string name="settings_about_explain">Details about version, author and license.</string> <string name="settings_about_explain">Details about version, author and license.</string>
<string name="close_tab">Close tab</string> <string name="close_tab">Close tab</string>
<string name="close_all_tabs">Close all tabs</string> <string name="close_all_tabs">Close all tabs</string>
<string name="third_party">Block 3rd Party Cookies</string>
<string name="available_lollipop">This feature is only available on Android 5.0+</string>
</resources> </resources>

6
src/acr/browser/lightning/BrowserActivity.java

@ -31,6 +31,7 @@ import android.graphics.drawable.Drawable;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
@ -1429,11 +1430,16 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
Utils.trimCache(this); Utils.trimCache(this);
} }
@SuppressWarnings("deprecation")
public void clearCookies() { public void clearCookies() {
CookieManager c = CookieManager.getInstance(); CookieManager c = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
c.removeAllCookies(null);
} else {
CookieSyncManager.createInstance(this); CookieSyncManager.createInstance(this);
c.removeAllCookie(); c.removeAllCookie();
} }
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {

4
src/acr/browser/lightning/IncognitoActivity.java

@ -2,6 +2,7 @@ package acr.browser.lightning;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.webkit.CookieManager; import android.webkit.CookieManager;
@ -19,13 +20,16 @@ public class IncognitoActivity extends BrowserActivity {
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
} }
@SuppressWarnings("deprecation")
@Override @Override
public void updateCookiePreference() { public void updateCookiePreference() {
if (mPreferences == null) { if (mPreferences == null) {
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
} }
mCookieManager = CookieManager.getInstance(); mCookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(this); CookieSyncManager.createInstance(this);
}
mCookieManager.setAcceptCookie(mPreferences.getBoolean( mCookieManager.setAcceptCookie(mPreferences.getBoolean(
PreferenceConstants.INCOGNITO_COOKIES, false)); PreferenceConstants.INCOGNITO_COOKIES, false));
super.updateCookiePreference(); super.updateCookiePreference();

5
src/acr/browser/lightning/LightningView.java

@ -28,6 +28,7 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.View.OnTouchListener; import android.view.View.OnTouchListener;
import android.webkit.*; import android.webkit.*;
import android.webkit.CookieManager;
import android.webkit.WebSettings.LayoutAlgorithm; import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebSettings.PluginState; import android.webkit.WebSettings.PluginState;
import android.widget.EditText; import android.widget.EditText;
@ -361,6 +362,10 @@ public class LightningView {
mSettings.setTextZoom(50); mSettings.setTextZoom(50);
break; break;
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView,
!mPreferences.getBoolean(PreferenceConstants.BLOCK_THIRD_PARTY, false));
}
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

4
src/acr/browser/lightning/MainActivity.java

@ -2,6 +2,7 @@ package acr.browser.lightning;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.webkit.CookieManager; import android.webkit.CookieManager;
@ -19,13 +20,16 @@ public class MainActivity extends BrowserActivity {
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
} }
@SuppressWarnings("deprecation")
@Override @Override
public void updateCookiePreference() { public void updateCookiePreference() {
if (mPreferences == null) { if (mPreferences == null) {
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
} }
mCookieManager = CookieManager.getInstance(); mCookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(this); CookieSyncManager.createInstance(this);
}
mCookieManager.setAcceptCookie(mPreferences.getBoolean(PreferenceConstants.COOKIES, true)); mCookieManager.setAcceptCookie(mPreferences.getBoolean(PreferenceConstants.COOKIES, true));
super.updateCookiePreference(); super.updateCookiePreference();
} }

1
src/acr/browser/lightning/PreferenceConstants.java

@ -40,6 +40,7 @@ public final class PreferenceConstants {
public static final String SAVE_URL = "saveUrl"; public static final String SAVE_URL = "saveUrl";
public static final String RENDERING_MODE = "renderMode"; public static final String RENDERING_MODE = "renderMode";
public static final String SYNC_HISTORY = "syncHistory"; public static final String SYNC_HISTORY = "syncHistory";
public static final String BLOCK_THIRD_PARTY = "thirdParty";
public static final String USE_PROXY = "useProxy"; public static final String USE_PROXY = "useProxy";
public static final String USE_PROXY_HOST = "useProxyHost"; public static final String USE_PROXY_HOST = "useProxyHost";

54
src/acr/browser/lightning/PrivacySettingsActivity.java

@ -7,6 +7,7 @@ import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
@ -30,7 +31,8 @@ public class PrivacySettingsActivity extends ActionBarActivity {
private static final int API = android.os.Build.VERSION.SDK_INT; private static final int API = android.os.Build.VERSION.SDK_INT;
private SharedPreferences mPreferences; private SharedPreferences mPreferences;
private SharedPreferences.Editor mEditPrefs; private SharedPreferences.Editor mEditPrefs;
private CheckBox cbLocation, cbSavePasswords, cbClearCacheExit, cbClearHistoryExit, cbClearCookiesExit; private CheckBox cbLocation, cbSavePasswords, cbClearCacheExit, cbClearHistoryExit,
cbClearCookiesExit, cbThirdParty;
private Context mContext; private Context mContext;
private boolean mSystemBrowser; private boolean mSystemBrowser;
private Handler messageHandler; private Handler messageHandler;
@ -69,7 +71,7 @@ public class PrivacySettingsActivity extends ActionBarActivity {
private void initialize() { private void initialize() {
RelativeLayout rLocation, rSavePasswords, rClearCacheExit, rClearHistoryExit, rClearCookiesExit, rClearCache, rClearHistory, rClearCookies; RelativeLayout rLocation, rSavePasswords, rClearCacheExit, rClearHistoryExit, rClearCookiesExit, rClearCache, rClearHistory, rClearCookies, rThirdParty;
rLocation = (RelativeLayout) findViewById(R.id.rLocation); rLocation = (RelativeLayout) findViewById(R.id.rLocation);
rSavePasswords = (RelativeLayout) findViewById(R.id.rSavePasswords); rSavePasswords = (RelativeLayout) findViewById(R.id.rSavePasswords);
@ -79,20 +81,28 @@ public class PrivacySettingsActivity extends ActionBarActivity {
rClearCache = (RelativeLayout) findViewById(R.id.rClearCache); rClearCache = (RelativeLayout) findViewById(R.id.rClearCache);
rClearHistory = (RelativeLayout) findViewById(R.id.rClearHistory); rClearHistory = (RelativeLayout) findViewById(R.id.rClearHistory);
rClearCookies = (RelativeLayout) findViewById(R.id.rClearCookies); rClearCookies = (RelativeLayout) findViewById(R.id.rClearCookies);
rThirdParty = (RelativeLayout) findViewById(R.id.rThirdParty);
cbLocation = (CheckBox) findViewById(R.id.cbLocation); cbLocation = (CheckBox) findViewById(R.id.cbLocation);
cbSavePasswords = (CheckBox) findViewById(R.id.cbSavePasswords); cbSavePasswords = (CheckBox) findViewById(R.id.cbSavePasswords);
cbClearCacheExit = (CheckBox) findViewById(R.id.cbClearCacheExit); cbClearCacheExit = (CheckBox) findViewById(R.id.cbClearCacheExit);
cbClearHistoryExit = (CheckBox) findViewById(R.id.cbClearHistoryExit); cbClearHistoryExit = (CheckBox) findViewById(R.id.cbClearHistoryExit);
cbClearCookiesExit = (CheckBox) findViewById(R.id.cbClearCookiesExit); cbClearCookiesExit = (CheckBox) findViewById(R.id.cbClearCookiesExit);
cbThirdParty = (CheckBox) findViewById(R.id.cbThirdParty);
cbLocation.setChecked(mPreferences.getBoolean(PreferenceConstants.LOCATION, false)); cbLocation.setChecked(mPreferences.getBoolean(PreferenceConstants.LOCATION, false));
cbSavePasswords.setChecked(mPreferences.getBoolean(PreferenceConstants.SAVE_PASSWORDS, true)); cbSavePasswords.setChecked(mPreferences
cbClearCacheExit.setChecked(mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, false)); .getBoolean(PreferenceConstants.SAVE_PASSWORDS, true));
cbClearCacheExit.setChecked(mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT,
false));
cbClearHistoryExit.setChecked(mPreferences.getBoolean( cbClearHistoryExit.setChecked(mPreferences.getBoolean(
PreferenceConstants.CLEAR_HISTORY_EXIT, false)); PreferenceConstants.CLEAR_HISTORY_EXIT, false));
cbClearCookiesExit.setChecked(mPreferences.getBoolean( cbClearCookiesExit.setChecked(mPreferences.getBoolean(
PreferenceConstants.CLEAR_COOKIES_EXIT, false)); PreferenceConstants.CLEAR_COOKIES_EXIT, false));
cbThirdParty.setChecked(mPreferences.getBoolean(PreferenceConstants.BLOCK_THIRD_PARTY,
false));
cbThirdParty.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
rLocation(rLocation); rLocation(rLocation);
rSavePasswords(rSavePasswords); rSavePasswords(rSavePasswords);
@ -102,11 +112,13 @@ public class PrivacySettingsActivity extends ActionBarActivity {
rClearCache(rClearCache); rClearCache(rClearCache);
rClearHistory(rClearHistory); rClearHistory(rClearHistory);
rClearCookies(rClearCookies); rClearCookies(rClearCookies);
rThirdParty(rThirdParty);
cbLocation(cbLocation); cbLocation(cbLocation);
cbSavePasswords(cbSavePasswords); cbSavePasswords(cbSavePasswords);
cbClearCacheExit(cbClearCacheExit); cbClearCacheExit(cbClearCacheExit);
cbClearHistoryExit(cbClearHistoryExit); cbClearHistoryExit(cbClearHistoryExit);
cbClearCookiesExit(cbClearCookiesExit); cbClearCookiesExit(cbClearCookiesExit);
cbThirdParty(cbThirdParty);
TextView syncHistory = (TextView) findViewById(R.id.isBrowserAvailable); TextView syncHistory = (TextView) findViewById(R.id.isBrowserAvailable);
@ -218,6 +230,18 @@ public class PrivacySettingsActivity extends ActionBarActivity {
}); });
} }
private void cbThirdParty(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.BLOCK_THIRD_PARTY, isChecked);
mEditPrefs.commit();
}
});
}
private void cbClearCookiesExit(CheckBox view) { private void cbClearCookiesExit(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() { view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@ -266,6 +290,22 @@ public class PrivacySettingsActivity extends ActionBarActivity {
}); });
} }
private void rThirdParty(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cbThirdParty.setChecked(!cbThirdParty.isChecked());
} else {
Utils.showToast(mContext, mContext.getString(R.string.available_lollipop));
}
}
});
}
private void rClearHistoryExit(RelativeLayout view) { private void rClearHistoryExit(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() { view.setOnClickListener(new OnClickListener() {
@ -409,10 +449,16 @@ public class PrivacySettingsActivity extends ActionBarActivity {
messageHandler.sendEmptyMessage(1); messageHandler.sendEmptyMessage(1);
} }
@SuppressWarnings("deprecation")
public void clearCookies() { public void clearCookies() {
CookieManager c = CookieManager.getInstance(); CookieManager c = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
c.removeAllCookies(null);
} else {
CookieSyncManager.createInstance(this); CookieSyncManager.createInstance(this);
c.removeAllCookie(); c.removeAllCookie();
}
messageHandler.sendEmptyMessage(2); messageHandler.sendEmptyMessage(2);
} }
} }

Loading…
Cancel
Save