summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser
diff options
context:
space:
mode:
authorPatrick Scott <phanna@android.com>2011-03-14 13:21:52 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-03-14 13:21:52 -0700
commitac7538e0a49911b926eeebb811f61c6996c68ae3 (patch)
tree0f927891eaab92a89ef4392550df3b410dc337e1 /src/com/android/browser
parent22d96edeb1d77a76399febfd56453d1c59cf0280 (diff)
parentd43e75adea6f394730828cbf830438e2bddaed4b (diff)
downloadpackages_apps_browser-ac7538e0a49911b926eeebb811f61c6996c68ae3.zip
packages_apps_browser-ac7538e0a49911b926eeebb811f61c6996c68ae3.tar.gz
packages_apps_browser-ac7538e0a49911b926eeebb811f61c6996c68ae3.tar.bz2
Merge "Remove pre-login on every tab." into honeycomb-mr1
Diffstat (limited to 'src/com/android/browser')
-rw-r--r--src/com/android/browser/BrowserSettings.java39
-rw-r--r--src/com/android/browser/Controller.java16
-rw-r--r--src/com/android/browser/GoogleAccountLogin.java74
-rw-r--r--src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java56
4 files changed, 16 insertions, 169 deletions
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 75e0cfb..357d1e9 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -92,9 +92,6 @@ public class BrowserSettings extends Observable implements OnSharedPreferenceCha
private String databasePath; // default value set in loadFromDb()
private String geolocationDatabasePath; // default value set in loadFromDb()
private WebStorageSizeManager webStorageSizeManager;
- // Autologin settings
- private boolean autoLoginEnabled;
- private String autoLoginAccount;
private String jsFlags = "";
@@ -168,8 +165,6 @@ public class BrowserSettings extends Observable implements OnSharedPreferenceCha
public final static String PREF_QUICK_CONTROLS = "enable_quick_controls";
public final static String PREF_MOST_VISITED_HOMEPAGE = "use_most_visited_homepage";
- public final static String PREF_AUTOLOGIN = "enable_autologin";
- public final static String PREF_AUTOLOGIN_ACCOUNT = "autologin_account";
public final static String PREF_PLUGIN_STATE = "plugin_state";
public final static String PREF_USE_INSTANT = "use_instant_search";
@@ -537,11 +532,6 @@ public class BrowserSettings extends Observable implements OnSharedPreferenceCha
geolocationEnabled = p.getBoolean("enable_geolocation", geolocationEnabled);
workersEnabled = p.getBoolean("enable_workers", workersEnabled);
- // Autologin account settings. The account preference may be null until
- // the user explicitly changes the account in the settings.
- autoLoginEnabled = p.getBoolean(PREF_AUTOLOGIN, autoLoginEnabled);
- autoLoginAccount = p.getString(PREF_AUTOLOGIN_ACCOUNT, autoLoginAccount);
-
update();
}
@@ -632,32 +622,6 @@ public class BrowserSettings extends Observable implements OnSharedPreferenceCha
update();
}
- public boolean isAutoLoginEnabled() {
- return autoLoginEnabled;
- }
-
- public String getAutoLoginAccount(Context context) {
- // Each time we attempt to get the account, we need to verify that the
- // account is still valid.
- return GoogleAccountLogin.validateAccount(context, autoLoginAccount);
- }
-
- public void setAutoLoginAccount(Context context, String name) {
- Editor ed = PreferenceManager.
- getDefaultSharedPreferences(context).edit();
- ed.putString(PREF_AUTOLOGIN_ACCOUNT, name);
- ed.apply();
- autoLoginAccount = name;
- }
-
- public void setAutoLoginEnabled(Context context, boolean enable) {
- Editor ed = PreferenceManager.
- getDefaultSharedPreferences(context).edit();
- ed.putBoolean(PREF_AUTOLOGIN, enable);
- ed.apply();
- autoLoginEnabled = enable;
- }
-
public void setAutoFillProfile(Context ctx, AutoFillProfile profile, Message msg) {
if (profile != null) {
setActiveAutoFillProfileId(ctx, profile.getUniqueId());
@@ -854,9 +818,6 @@ public class BrowserSettings extends Observable implements OnSharedPreferenceCha
domStorageEnabled = true;
geolocationEnabled = true;
workersEnabled = true; // only affects V8. JSC does not have a similar setting
- // Autologin default is true. The account will be populated when
- // reading from the DB as that is when a context is available.
- autoLoginEnabled = true;
}
private abstract class AutoFillProfileDbTask<T> extends AsyncTask<T, Void, Void> {
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index b04c956..82aea47 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -279,7 +279,7 @@ public class Controller
CookieManager.getInstance().removeSessionCookie();
}
- GoogleAccountLogin.startLoginIfNeeded(mActivity, mSettings,
+ GoogleAccountLogin.startLoginIfNeeded(mActivity,
new Runnable() {
@Override public void run() {
start(icicle, intent, currentTab, restoreIncognitoTabs);
@@ -2229,17 +2229,9 @@ public class Controller
// animation behavior.
addTab(tab);
setActiveTab(tab);
-
- // Callback to load the url data.
- final Runnable load = new Runnable() {
- @Override public void run() {
- if (!urlData.isEmpty()) {
- loadUrlDataIn(tab, urlData);
- }
- }
- };
-
- GoogleAccountLogin.startLoginIfNeeded(mActivity, mSettings, load);
+ if (!urlData.isEmpty()) {
+ loadUrlDataIn(tab, urlData);
+ }
return tab;
} else {
// Get rid of the subwindow if it exists
diff --git a/src/com/android/browser/GoogleAccountLogin.java b/src/com/android/browser/GoogleAccountLogin.java
index f4ccfd1..0bde010 100644
--- a/src/com/android/browser/GoogleAccountLogin.java
+++ b/src/com/android/browser/GoogleAccountLogin.java
@@ -40,7 +40,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
-import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
@@ -80,10 +79,10 @@ public class GoogleAccountLogin implements Runnable,
private int mState; // {NONE(0), SID(1), LSID(2)}
private boolean mTokensInvalidated;
- private GoogleAccountLogin(Activity activity, String name,
+ private GoogleAccountLogin(Activity activity, Account account,
Runnable runnable) {
mActivity = activity;
- mAccount = new Account(name, GOOGLE);
+ mAccount = account;
mWebView = new WebView(mActivity);
mRunnable = runnable;
@@ -233,28 +232,22 @@ public class GoogleAccountLogin implements Runnable,
// Start the login process if auto-login is enabled and the user is not
// already logged in.
public static void startLoginIfNeeded(Activity activity,
- BrowserSettings settings, Runnable runnable) {
- // Auto login not enabled?
- if (!settings.isAutoLoginEnabled()) {
+ Runnable runnable) {
+ // Already logged in?
+ if (isLoggedIn(activity)) {
runnable.run();
return;
}
// No account found?
- String account = settings.getAutoLoginAccount(activity);
- if (account == null) {
- runnable.run();
- return;
- }
-
- // Already logged in?
- if (isLoggedIn(activity)) {
+ Account[] accounts = getAccounts(activity);
+ if (accounts == null || accounts.length == 0) {
runnable.run();
return;
}
GoogleAccountLogin login =
- new GoogleAccountLogin(activity, account, runnable);
+ new GoogleAccountLogin(activity, accounts[0], runnable);
login.startLogin();
}
@@ -271,31 +264,12 @@ public class GoogleAccountLogin implements Runnable,
mAccount, "SID", null, mActivity, this, null);
}
- // Returns the account name passed in if the account exists, otherwise
- // returns the default account.
- public static String validateAccount(Context ctx, String name) {
- Account[] accounts = getAccounts(ctx);
- if (accounts.length == 0) {
- return null;
- }
- if (name != null) {
- // Make sure the account still exists.
- for (Account a : accounts) {
- if (a.name.equals(name)) {
- return name;
- }
- }
- }
- // Return the first entry.
- return accounts[0].name;
- }
-
- public static Account[] getAccounts(Context ctx) {
+ private static Account[] getAccounts(Context ctx) {
return AccountManager.get(ctx).getAccountsByType(GOOGLE);
}
- // Checks for the presence of the SID cookie on google.com.
- public static boolean isLoggedIn(Context ctx) {
+ // Checks if we already did pre-login.
+ private static boolean isLoggedIn(Context ctx) {
// See if we last logged in less than a week ago.
long lastLogin = PreferenceManager.
getDefaultSharedPreferences(ctx).
@@ -303,31 +277,7 @@ public class GoogleAccountLogin implements Runnable,
if (lastLogin == -1) {
return false;
}
- long diff = System.currentTimeMillis() - lastLogin;
- if (diff > WEEK_IN_MILLIS) {
- Log.d(LOGTAG, "Forcing login after " + diff + "ms");
- return false;
- }
-
- // This will potentially block the UI thread but we have to have the
- // most updated cookies.
- // FIXME: Figure out how to avoid waiting to clear session cookies.
- CookieManager.getInstance().waitForCookieOperationsToComplete();
-
- // Use /a/ to grab hosted cookies as well as the base set of google.com
- // cookies.
- String cookies = CookieManager.getInstance().getCookie(
- "http://www.google.com/a/");
- if (cookies != null) {
- StringTokenizer tokenizer = new StringTokenizer(cookies, ";");
- while (tokenizer.hasMoreTokens()) {
- String cookie = tokenizer.nextToken().trim();
- if (cookie.startsWith("SID=") || cookie.startsWith("ASIDAP=")) {
- return true;
- }
- }
- }
- return false;
+ return true;
}
// Used to indicate that the Browser should continue loading the main page.
diff --git a/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java b/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java
index 2b2ee3e..2266608 100644
--- a/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java
+++ b/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java
@@ -17,14 +17,11 @@
package com.android.browser.preferences;
import com.android.browser.BrowserSettings;
-import com.android.browser.GoogleAccountLogin;
import com.android.browser.R;
-import android.accounts.Account;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
-import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
@@ -44,53 +41,11 @@ public class PrivacySecurityPreferencesFragment extends PreferenceFragment
Preference e = findPreference(BrowserSettings.PREF_CLEAR_HISTORY);
e.setOnPreferenceChangeListener(this);
- setupAutoLoginPreference();
}
@Override
public void onResume() {
super.onResume();
- setupAutoLoginPreference();
- }
-
- void setupAutoLoginPreference() {
- ListPreference autologinPref = (ListPreference) findPreference(
- BrowserSettings.PREF_AUTOLOGIN_ACCOUNT);
- autologinPref.setOnPreferenceChangeListener(this);
- updateAutoLoginSummary(autologinPref);
- Account[] accounts = GoogleAccountLogin.getAccounts(getActivity());
- // +1 for disable
- CharSequence[] names = new CharSequence[accounts.length + 1];
- CharSequence[] values = new CharSequence[names.length];
- int i = 0;
- int defaultAccount = 0;
- for (Account a : accounts) {
- values[i] = names[i] = a.name;
- i++;
- }
- names[i] = getResources().getString(R.string.pref_autologin_disable);
- values[i] = "";
- autologinPref.setEntries(names);
- autologinPref.setEntryValues(values);
- BrowserSettings bs = BrowserSettings.getInstance();
- if (bs.isAutoLoginEnabled()) {
- autologinPref.setValue(bs.getAutoLoginAccount(getActivity()));
- } else {
- autologinPref.setValue("");
- }
- }
-
- private void updateAutoLoginSummary(Preference pref) {
- if (!mSettings.isAutoLoginEnabled()) {
- pref.setSummary(R.string.pref_autologin_disable);
- } else {
- String account = mSettings.getAutoLoginAccount(getActivity());
- if (account == null) {
- pref.setSummary(R.string.pref_autologin_no_account);
- } else {
- pref.setSummary(getString(R.string.pref_autologin_summary, account));
- }
- }
}
@Override
@@ -102,17 +57,6 @@ public class PrivacySecurityPreferencesFragment extends PreferenceFragment
getActivity().setResult(Activity.RESULT_OK, (new Intent()).putExtra(Intent.EXTRA_TEXT,
pref.getKey()));
return true;
- } else if (pref.getKey().equals(BrowserSettings.PREF_AUTOLOGIN_ACCOUNT)) {
- String account = (String) objValue;
- if (account.length() == 0) {
- // Disable
- mSettings.setAutoLoginEnabled(getActivity(), false);
- } else {
- mSettings.setAutoLoginEnabled(getActivity(), true);
- }
- mSettings.setAutoLoginAccount(getActivity(), account);
- updateAutoLoginSummary(pref);
- return true;
}
return false;