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. 10
      src/acr/browser/lightning/BrowserActivity.java
  4. 8
      src/acr/browser/lightning/IncognitoActivity.java
  5. 5
      src/acr/browser/lightning/LightningView.java
  6. 6
      src/acr/browser/lightning/MainActivity.java
  7. 1
      src/acr/browser/lightning/PreferenceConstants.java
  8. 64
      src/acr/browser/lightning/PrivacySettingsActivity.java

35
res/layout/privacy_settings.xml

@ -45,6 +45,41 @@ @@ -45,6 +45,41 @@
android:layout_centerVertical="true" />
</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
android:layout_width="match_parent"
android:layout_height="1dp"

2
res/values/strings.xml

@ -195,4 +195,6 @@ @@ -195,4 +195,6 @@
<string name="settings_about_explain">Details about version, author and license.</string>
<string name="close_tab">Close tab</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>

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

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

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

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

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

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

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

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

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

@ -40,6 +40,7 @@ public final class PreferenceConstants { @@ -40,6 +40,7 @@ public final class PreferenceConstants {
public static final String SAVE_URL = "saveUrl";
public static final String RENDERING_MODE = "renderMode";
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_HOST = "useProxyHost";

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

@ -7,6 +7,7 @@ import android.app.AlertDialog; @@ -7,6 +7,7 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@ -30,7 +31,8 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -30,7 +31,8 @@ public class PrivacySettingsActivity extends ActionBarActivity {
private static final int API = android.os.Build.VERSION.SDK_INT;
private SharedPreferences mPreferences;
private SharedPreferences.Editor mEditPrefs;
private CheckBox cbLocation, cbSavePasswords, cbClearCacheExit, cbClearHistoryExit, cbClearCookiesExit;
private CheckBox cbLocation, cbSavePasswords, cbClearCacheExit, cbClearHistoryExit,
cbClearCookiesExit, cbThirdParty;
private Context mContext;
private boolean mSystemBrowser;
private Handler messageHandler;
@ -41,10 +43,10 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -41,10 +43,10 @@ public class PrivacySettingsActivity extends ActionBarActivity {
setContentView(R.layout.privacy_settings);
// set up ActionBar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) {
@ -69,7 +71,7 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -69,7 +71,7 @@ public class PrivacySettingsActivity extends ActionBarActivity {
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);
rSavePasswords = (RelativeLayout) findViewById(R.id.rSavePasswords);
@ -79,20 +81,28 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -79,20 +81,28 @@ public class PrivacySettingsActivity extends ActionBarActivity {
rClearCache = (RelativeLayout) findViewById(R.id.rClearCache);
rClearHistory = (RelativeLayout) findViewById(R.id.rClearHistory);
rClearCookies = (RelativeLayout) findViewById(R.id.rClearCookies);
rThirdParty = (RelativeLayout) findViewById(R.id.rThirdParty);
cbLocation = (CheckBox) findViewById(R.id.cbLocation);
cbSavePasswords = (CheckBox) findViewById(R.id.cbSavePasswords);
cbClearCacheExit = (CheckBox) findViewById(R.id.cbClearCacheExit);
cbClearHistoryExit = (CheckBox) findViewById(R.id.cbClearHistoryExit);
cbClearCookiesExit = (CheckBox) findViewById(R.id.cbClearCookiesExit);
cbThirdParty = (CheckBox) findViewById(R.id.cbThirdParty);
cbLocation.setChecked(mPreferences.getBoolean(PreferenceConstants.LOCATION, false));
cbSavePasswords.setChecked(mPreferences.getBoolean(PreferenceConstants.SAVE_PASSWORDS, true));
cbClearCacheExit.setChecked(mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, false));
cbSavePasswords.setChecked(mPreferences
.getBoolean(PreferenceConstants.SAVE_PASSWORDS, true));
cbClearCacheExit.setChecked(mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT,
false));
cbClearHistoryExit.setChecked(mPreferences.getBoolean(
PreferenceConstants.CLEAR_HISTORY_EXIT, false));
cbClearCookiesExit.setChecked(mPreferences.getBoolean(
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);
rSavePasswords(rSavePasswords);
@ -102,11 +112,13 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -102,11 +112,13 @@ public class PrivacySettingsActivity extends ActionBarActivity {
rClearCache(rClearCache);
rClearHistory(rClearHistory);
rClearCookies(rClearCookies);
rThirdParty(rThirdParty);
cbLocation(cbLocation);
cbSavePasswords(cbSavePasswords);
cbClearCacheExit(cbClearCacheExit);
cbClearHistoryExit(cbClearHistoryExit);
cbClearCookiesExit(cbClearCookiesExit);
cbThirdParty(cbThirdParty);
TextView syncHistory = (TextView) findViewById(R.id.isBrowserAvailable);
@ -218,6 +230,18 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -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) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@ -266,6 +290,22 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -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) {
view.setOnClickListener(new OnClickListener() {
@ -409,10 +449,16 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -409,10 +449,16 @@ public class PrivacySettingsActivity extends ActionBarActivity {
messageHandler.sendEmptyMessage(1);
}
@SuppressWarnings("deprecation")
public void clearCookies() {
CookieManager c = CookieManager.getInstance();
CookieSyncManager.createInstance(this);
c.removeAllCookie();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
c.removeAllCookies(null);
} else {
CookieSyncManager.createInstance(this);
c.removeAllCookie();
}
messageHandler.sendEmptyMessage(2);
}
}

Loading…
Cancel
Save