OLD | NEW |
---|---|
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 #include "chrome/browser/android/preferences/pref_service_bridge.h" | 5 #include "chrome/browser/android/preferences/pref_service_bridge.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 | 223 |
224 static jboolean GetSearchSuggestEnabled(JNIEnv* env, jobject obj) { | 224 static jboolean GetSearchSuggestEnabled(JNIEnv* env, jobject obj) { |
225 return GetPrefService()->GetBoolean(prefs::kSearchSuggestEnabled); | 225 return GetPrefService()->GetBoolean(prefs::kSearchSuggestEnabled); |
226 } | 226 } |
227 | 227 |
228 static jboolean GetSearchSuggestManaged(JNIEnv* env, jobject obj) { | 228 static jboolean GetSearchSuggestManaged(JNIEnv* env, jobject obj) { |
229 return GetPrefService()->IsManagedPreference(prefs::kSearchSuggestEnabled); | 229 return GetPrefService()->IsManagedPreference(prefs::kSearchSuggestEnabled); |
230 } | 230 } |
231 | 231 |
232 static jboolean GetProtectedMediaIdentifierEnabled(JNIEnv* env, jobject obj) { | 232 static jboolean GetProtectedMediaIdentifierEnabled(JNIEnv* env, jobject obj) { |
233 // Migrate Settings from Preferences to the Host Content Settings Map. | |
234 // TODO (knn): Remove this once users have migrated. | |
235 PrefService* prefs = GetPrefService(); | |
236 if (!prefs->GetBoolean(prefs::kProtectedMediaIdentifierEnabled)) { | |
237 prefs->SetBoolean(prefs::kProtectedMediaIdentifierEnabled, true); | |
238 SetProtectedMediaIdentifierEnabled(env, obj, false); | |
239 } | |
240 return GetBooleanForContentSetting( | 233 return GetBooleanForContentSetting( |
241 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); | 234 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
242 } | 235 } |
243 | 236 |
244 static jboolean GetPushNotificationsEnabled(JNIEnv* env, jobject obj) { | 237 static jboolean GetPushNotificationsEnabled(JNIEnv* env, jobject obj) { |
245 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 238 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
246 } | 239 } |
247 | 240 |
248 static jboolean GetAllowLocationEnabled(JNIEnv* env, jobject obj) { | 241 static jboolean GetAllowLocationEnabled(JNIEnv* env, jobject obj) { |
249 // Migrate Settings from Preferences to the Host Content Settings Map. | |
250 // TODO (knn): Remove this once users have migrated. | |
251 PrefService* prefs = GetPrefService(); | |
252 // Non-user-modifiable preference levels should have been migrated already. | |
253 DCHECK(prefs->IsUserModifiablePreference(prefs::kGeolocationEnabled)); | |
254 if (!prefs->GetBoolean(prefs::kGeolocationEnabled)) { | |
255 prefs->SetBoolean(prefs::kGeolocationEnabled, true); | |
256 SetAllowLocationEnabled(env, obj, false); | |
257 } | |
258 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 242 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
259 } | 243 } |
260 | 244 |
261 static jboolean GetAllowLocationUserModifiable(JNIEnv* env, jobject obj) { | 245 static jboolean GetAllowLocationUserModifiable(JNIEnv* env, jobject obj) { |
262 return IsContentSettingUserModifiable(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 246 return IsContentSettingUserModifiable(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
263 } | 247 } |
264 | 248 |
265 static jboolean GetAllowLocationManagedByCustodian(JNIEnv* env, jobject obj) { | 249 static jboolean GetAllowLocationManagedByCustodian(JNIEnv* env, jobject obj) { |
266 return IsContentSettingManagedByCustodian(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 250 return IsContentSettingManagedByCustodian(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
267 } | 251 } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 if (!javascript_pref->HasUserSetting()) | 490 if (!javascript_pref->HasUserSetting()) |
507 return; | 491 return; |
508 | 492 |
509 bool javascript_enabled = false; | 493 bool javascript_enabled = false; |
510 bool retval = javascript_pref->GetValue()->GetAsBoolean(&javascript_enabled); | 494 bool retval = javascript_pref->GetValue()->GetAsBoolean(&javascript_enabled); |
511 DCHECK(retval); | 495 DCHECK(retval); |
512 SetJavaScriptEnabled(env, obj, javascript_enabled); | 496 SetJavaScriptEnabled(env, obj, javascript_enabled); |
513 GetPrefService()->ClearPref(prefs::kWebKitJavascriptEnabled); | 497 GetPrefService()->ClearPref(prefs::kWebKitJavascriptEnabled); |
514 } | 498 } |
515 | 499 |
500 static void MigrateLocationPreference(JNIEnv* env, jobject obj) { | |
501 const PrefService::Preference* pref = | |
502 GetPrefService()->FindPreference(prefs::kGeolocationEnabled); | |
503 if (!pref || !pref->HasUserSetting()) | |
504 return; | |
505 bool location_enabled = false; | |
506 bool retval = pref->GetValue()->GetAsBoolean(&location_enabled); | |
507 DCHECK(retval); | |
508 // Do a restrictive migration. GetAllowLocationEnabled could be | |
509 // non-usermodifiable and we don't want to migrate that. | |
510 if (!location_enabled) | |
511 SetAllowLocationEnabled(env, obj, false); | |
512 GetPrefService()->ClearPref(prefs::kGeolocationEnabled); | |
513 } | |
514 | |
515 static void MigrateProtectedMediaPreference(JNIEnv* env, jobject obj) { | |
516 const PrefService::Preference* pref = | |
517 GetPrefService()->FindPreference(prefs::kProtectedMediaIdentifierEnabled); | |
518 if (!pref || !pref->HasUserSetting()) | |
519 return; | |
520 bool pmi_enabled = false; | |
521 bool retval = pref->GetValue()->GetAsBoolean(&pmi_enabled); | |
522 DCHECK(retval); | |
523 // Do a restrictive migration if values disagree. | |
524 pmi_enabled &= GetProtectedMediaIdentifierEnabled(env, obj); | |
newt (away)
2015/04/03 01:12:40
I'd use the same form here that you use in Migrate
| |
525 SetProtectedMediaIdentifierEnabled(env, obj, pmi_enabled); | |
526 GetPrefService()->ClearPref(prefs::kProtectedMediaIdentifierEnabled); | |
527 } | |
528 | |
516 static void SetPasswordEchoEnabled(JNIEnv* env, | 529 static void SetPasswordEchoEnabled(JNIEnv* env, |
517 jobject obj, | 530 jobject obj, |
518 jboolean passwordEchoEnabled) { | 531 jboolean passwordEchoEnabled) { |
519 GetPrefService()->SetBoolean(prefs::kWebKitPasswordEchoEnabled, | 532 GetPrefService()->SetBoolean(prefs::kWebKitPasswordEchoEnabled, |
520 passwordEchoEnabled); | 533 passwordEchoEnabled); |
521 } | 534 } |
522 | 535 |
523 static jboolean GetAllowPopupsEnabled(JNIEnv* env, jobject obj) { | 536 static jboolean GetAllowPopupsEnabled(JNIEnv* env, jobject obj) { |
524 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_POPUPS); | 537 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_POPUPS); |
525 } | 538 } |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
796 jobject obj) { | 809 jobject obj) { |
797 return ConvertUTF8ToJavaString( | 810 return ConvertUTF8ToJavaString( |
798 env, | 811 env, |
799 GetPrefService()->GetString( | 812 GetPrefService()->GetString( |
800 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); | 813 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); |
801 } | 814 } |
802 | 815 |
803 bool RegisterPrefServiceBridge(JNIEnv* env) { | 816 bool RegisterPrefServiceBridge(JNIEnv* env) { |
804 return RegisterNativesImpl(env); | 817 return RegisterNativesImpl(env); |
805 } | 818 } |
OLD | NEW |