mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
remove-cookies-for-domain feature
This commit is contained in:
parent
8eb6cbfa29
commit
b3b85b4820
6 changed files with 43 additions and 5 deletions
|
@ -33,7 +33,6 @@ import com.google.android.gms.auth.GoogleAuthUtil;
|
|||
import com.google.android.gms.auth.UserRecoverableAuthException;
|
||||
import com.google.android.gms.common.*;
|
||||
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.cookie.Cookie;
|
||||
import org.apache.http.impl.cookie.BasicClientCookie2;
|
||||
|
||||
|
@ -74,7 +73,7 @@ public final class ActivityNetworkContext extends AndroidNetworkContext {
|
|||
break;
|
||||
case NetworkLibraryActivity.REQUEST_WEB_AUTHORISATION_SCREEN:
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
final CookieStore store = cookieStore();
|
||||
final ZLNetworkManager.CookieStore store = cookieStore();
|
||||
final Map<String,String> cookies =
|
||||
(Map<String,String>)data.getSerializableExtra(NetworkLibraryActivity.COOKIES_KEY);
|
||||
if (cookies != null) {
|
||||
|
|
|
@ -153,6 +153,9 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
|||
return;
|
||||
}
|
||||
|
||||
//myNetworkContext.removeCookiesForDomain(SyncOptions.DOMAIN);
|
||||
//myNetworkContext.setAccountName(SyncOptions.DOMAIN, SyncOptions.REALM, null);
|
||||
|
||||
UIUtil.createExecutor(PreferenceActivity.this, "tryConnect").execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
|
|
|
@ -37,6 +37,7 @@ public abstract class CookieDatabase {
|
|||
|
||||
protected abstract void removeObsolete(Date date);
|
||||
protected abstract void removeAll();
|
||||
protected abstract void removeForDomain(String domain);
|
||||
protected abstract void saveCookies(List<Cookie> cookies);
|
||||
protected abstract List<Cookie> loadCookies();
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.io.*;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.cookie.Cookie;
|
||||
|
||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||
|
@ -35,10 +34,14 @@ public abstract class ZLNetworkContext implements ZLNetworkManager.BearerAuthent
|
|||
protected ZLNetworkContext() {
|
||||
}
|
||||
|
||||
protected CookieStore cookieStore() {
|
||||
protected ZLNetworkManager.CookieStore cookieStore() {
|
||||
return myManager.CookieStore;
|
||||
}
|
||||
|
||||
public void removeCookiesForDomain(String domain) {
|
||||
myManager.CookieStore.clearDomain(domain);
|
||||
}
|
||||
|
||||
public String getCookieValue(String domain, String name) {
|
||||
for (Cookie c : cookieStore().getCookies()) {
|
||||
if (domain.equals(c.getDomain()) && name.equals(c.getName())) {
|
||||
|
|
|
@ -28,7 +28,6 @@ import java.util.zip.GZIPInputStream;
|
|||
import org.apache.http.*;
|
||||
import org.apache.http.auth.*;
|
||||
import org.apache.http.client.AuthenticationHandler;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.*;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
|
@ -48,6 +47,10 @@ import org.geometerplus.zlibrary.core.util.MiscUtil;
|
|||
import org.geometerplus.zlibrary.core.util.ZLNetworkUtil;
|
||||
|
||||
public class ZLNetworkManager {
|
||||
public static interface CookieStore extends org.apache.http.client.CookieStore {
|
||||
void clearDomain(String domain);
|
||||
}
|
||||
|
||||
private static ZLNetworkManager ourManager;
|
||||
|
||||
public static ZLNetworkManager Instance() {
|
||||
|
@ -261,6 +264,15 @@ public class ZLNetworkManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
public synchronized void clearDomain(String domain) {
|
||||
myCookies = null;
|
||||
|
||||
final CookieDatabase db = CookieDatabase.getInstance();
|
||||
if (db != null) {
|
||||
db.removeForDomain(domain);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized List<Cookie> getCookies() {
|
||||
if (myCookies == null) {
|
||||
myCookies = new HashMap<Key,Cookie>();
|
||||
|
|
|
@ -91,6 +91,26 @@ public class SQLiteCookieDatabase extends CookieDatabase {
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeForDomain(String domain) {
|
||||
if (domain == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SQLiteStatement statement = myDatabase.compileStatement(
|
||||
"DELETE FROM CookiePort WHERE cookie_id IN " +
|
||||
"(SELECT cookie_id FROM Cookie WHERE host=?)"
|
||||
);
|
||||
statement.bindString(1, domain);
|
||||
statement.execute();
|
||||
|
||||
statement = myDatabase.compileStatement(
|
||||
"DELETE FROM Cookie WHERE host=?"
|
||||
);
|
||||
statement.bindString(1, domain);
|
||||
statement.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeAll() {
|
||||
myDatabase.execSQL("DELETE FROM CookiePort");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue