Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java

Issue 920583002: [Android] Migrate javascript settings to a content setting from a pref. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address newt@'s comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.preferences; 5 package org.chromium.chrome.browser.preferences;
6 6
7 import android.content.Context;
8 import android.content.SharedPreferences;
9 import android.preference.PreferenceManager;
7 import android.text.TextUtils; 10 import android.text.TextUtils;
11 import android.util.Log;
8 12
9 import org.chromium.base.CalledByNative; 13 import org.chromium.base.CalledByNative;
10 import org.chromium.base.ThreadUtils; 14 import org.chromium.base.ThreadUtils;
11 import org.chromium.chrome.browser.search_engines.TemplateUrlService; 15 import org.chromium.chrome.browser.search_engines.TemplateUrlService;
12 16
13 import java.util.ArrayList; 17 import java.util.ArrayList;
14 import java.util.List; 18 import java.util.List;
15 19
16 /** 20 /**
17 * PrefServiceBridge is a singleton which provides access to some native prefere nces. Ideally 21 * PrefServiceBridge is a singleton which provides access to some native prefere nces. Ideally
18 * preferences should be grouped with their relevant functionality but this is a grab-bag for other 22 * preferences should be grouped with their relevant functionality but this is a grab-bag for other
19 * preferences. 23 * preferences.
20 */ 24 */
21 public final class PrefServiceBridge { 25 public final class PrefServiceBridge {
22 26
23 // Does not need sync with native; used for the popup settings check 27 // Does not need sync with native; used for the popup settings check
24 public static final String EXCEPTION_SETTING_ALLOW = "allow"; 28 public static final String EXCEPTION_SETTING_ALLOW = "allow";
25 public static final String EXCEPTION_SETTING_BLOCK = "block"; 29 public static final String EXCEPTION_SETTING_BLOCK = "block";
26 public static final String EXCEPTION_SETTING_DEFAULT = "default"; 30 public static final String EXCEPTION_SETTING_DEFAULT = "default";
27 31
28 // These values must match the native enum values in 32 // These values must match the native enum values in
29 // SupervisedUserURLFilter::FilteringBehavior 33 // SupervisedUserURLFilter::FilteringBehavior
30 public static final int SUPERVISED_USER_FILTERING_ALLOW = 0; 34 public static final int SUPERVISED_USER_FILTERING_ALLOW = 0;
31 public static final int SUPERVISED_USER_FILTERING_WARN = 1; 35 public static final int SUPERVISED_USER_FILTERING_WARN = 1;
32 public static final int SUPERVISED_USER_FILTERING_BLOCK = 2; 36 public static final int SUPERVISED_USER_FILTERING_BLOCK = 2;
33 37
38 private static final String MIGRATION_PREF_KEY = "PrefMigrationVersion";
39 private static final int MIGRATION_CURRENT_VERSION = 1;
40
34 private static String sProfilePath; 41 private static String sProfilePath;
35 42
36 // Object to notify when "clear browsing data" completes. 43 // Object to notify when "clear browsing data" completes.
37 private OnClearBrowsingDataListener mClearBrowsingDataListener; 44 private OnClearBrowsingDataListener mClearBrowsingDataListener;
38 private static final String LOG_TAG = "PrefServiceBridge"; 45 private static final String LOG_TAG = "PrefServiceBridge";
39 46
40 // Constants related to the Contextual Search preference. 47 // Constants related to the Contextual Search preference.
41 private static final String CONTEXTUAL_SEARCH_DISABLED = "false"; 48 private static final String CONTEXTUAL_SEARCH_DISABLED = "false";
42 private static final String CONTEXTUAL_SEARCH_ENABLED = "true"; 49 private static final String CONTEXTUAL_SEARCH_ENABLED = "true";
43 50
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 143 }
137 144
138 /** 145 /**
139 * @return Whether the preferences have been initialized. 146 * @return Whether the preferences have been initialized.
140 */ 147 */
141 public static boolean isInitialized() { 148 public static boolean isInitialized() {
142 return sInstance != null; 149 return sInstance != null;
143 } 150 }
144 151
145 /** 152 /**
153 * Migrates (synchronously) the preferences to the most recent version.
154 */
155 public void migratePreferences(Context context) {
156 SharedPreferences preferences = PreferenceManager.getDefaultSharedPrefer ences(context);
157 int currentVersion = preferences.getInt(MIGRATION_PREF_KEY, 0);
158 if (currentVersion > MIGRATION_CURRENT_VERSION) {
159 Log.e(LOG_TAG, "Saved preferences version is newer than supported. Attempting to "
160 + "run an older version of Chrome without clearing data is u nsupported and "
161 + "the results may be unpredictable.");
162 }
163 if (currentVersion == MIGRATION_CURRENT_VERSION) return;
newt (away) 2015/02/12 01:25:02 nit: I'd put this if check first, since it's the c
Ted C 2015/02/12 17:18:19 Done.
164
165 if (currentVersion <= 0) {
166 nativeMigrateJavascriptPreference();
167 }
168 preferences.edit().putInt(MIGRATION_PREF_KEY, MIGRATION_CURRENT_VERSION) .commit();
169 }
170
171 /**
146 * Returns the path to the user's profile directory via a callback. The call back may be 172 * Returns the path to the user's profile directory via a callback. The call back may be
147 * called synchronously or asynchronously. 173 * called synchronously or asynchronously.
148 */ 174 */
149 public void getProfilePath(ProfilePathCallback callback) { 175 public void getProfilePath(ProfilePathCallback callback) {
150 if (!TextUtils.isEmpty(sProfilePath)) { 176 if (!TextUtils.isEmpty(sProfilePath)) {
151 callback.onGotProfilePath(sProfilePath); 177 callback.onGotProfilePath(sProfilePath);
152 } else { 178 } else {
153 nativeGetProfilePath(callback); 179 nativeGetProfilePath(callback);
154 } 180 }
155 } 181 }
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 private native boolean nativeGetCrashReportManaged(); 765 private native boolean nativeGetCrashReportManaged();
740 private native boolean nativeGetIncognitoModeEnabled(); 766 private native boolean nativeGetIncognitoModeEnabled();
741 private native boolean nativeGetIncognitoModeManaged(); 767 private native boolean nativeGetIncognitoModeManaged();
742 private native boolean nativeGetPrintingEnabled(); 768 private native boolean nativeGetPrintingEnabled();
743 private native boolean nativeGetPrintingManaged(); 769 private native boolean nativeGetPrintingManaged();
744 private native boolean nativeGetForceSafeSearch(); 770 private native boolean nativeGetForceSafeSearch();
745 private native void nativeSetTranslateEnabled(boolean enabled); 771 private native void nativeSetTranslateEnabled(boolean enabled);
746 private native void nativeResetTranslateDefaults(); 772 private native void nativeResetTranslateDefaults();
747 private native boolean nativeGetJavaScriptEnabled(); 773 private native boolean nativeGetJavaScriptEnabled();
748 private native void nativeSetJavaScriptEnabled(boolean enabled); 774 private native void nativeSetJavaScriptEnabled(boolean enabled);
775 private native void nativeMigrateJavascriptPreference();
749 private native void nativeClearBrowsingData(boolean history, boolean cache, 776 private native void nativeClearBrowsingData(boolean history, boolean cache,
750 boolean cookiesAndSiteData, boolean passwords, boolean formData); 777 boolean cookiesAndSiteData, boolean passwords, boolean formData);
751 private native void nativeSetAllowCookiesEnabled(boolean allow); 778 private native void nativeSetAllowCookiesEnabled(boolean allow);
752 private native void nativeSetBlockThirdPartyCookiesEnabled(boolean enabled); 779 private native void nativeSetBlockThirdPartyCookiesEnabled(boolean enabled);
753 private native void nativeSetDoNotTrackEnabled(boolean enabled); 780 private native void nativeSetDoNotTrackEnabled(boolean enabled);
754 private native void nativeSetRememberPasswordsEnabled(boolean allow); 781 private native void nativeSetRememberPasswordsEnabled(boolean allow);
755 private native void nativeSetProtectedMediaIdentifierEnabled(boolean enabled ); 782 private native void nativeSetProtectedMediaIdentifierEnabled(boolean enabled );
756 private native boolean nativeGetAllowLocationEnabled(); 783 private native boolean nativeGetAllowLocationEnabled();
757 private native boolean nativeGetPushNotificationsEnabled(); 784 private native boolean nativeGetPushNotificationsEnabled();
758 private native void nativeSetAllowLocationEnabled(boolean allow); 785 private native void nativeSetAllowLocationEnabled(boolean allow);
(...skipping 30 matching lines...) Expand all
789 private native void nativeResetAcceptLanguages(String defaultLocale); 816 private native void nativeResetAcceptLanguages(String defaultLocale);
790 private native String nativeGetSyncLastAccountName(); 817 private native String nativeGetSyncLastAccountName();
791 private native String nativeGetSupervisedUserCustodianName(); 818 private native String nativeGetSupervisedUserCustodianName();
792 private native String nativeGetSupervisedUserCustodianEmail(); 819 private native String nativeGetSupervisedUserCustodianEmail();
793 private native String nativeGetSupervisedUserCustodianProfileImageURL(); 820 private native String nativeGetSupervisedUserCustodianProfileImageURL();
794 private native int nativeGetDefaultSupervisedUserFilteringBehavior(); 821 private native int nativeGetDefaultSupervisedUserFilteringBehavior();
795 private native String nativeGetSupervisedUserSecondCustodianName(); 822 private native String nativeGetSupervisedUserSecondCustodianName();
796 private native String nativeGetSupervisedUserSecondCustodianEmail(); 823 private native String nativeGetSupervisedUserSecondCustodianEmail();
797 private native String nativeGetSupervisedUserSecondCustodianProfileImageURL( ); 824 private native String nativeGetSupervisedUserSecondCustodianProfileImageURL( );
798 } 825 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698