Chromium Code Reviews| 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()) { | |
|
newt (away)
2015/04/02 04:15:18
nit: don't need curly braces for two-line if state
knn
2015/04/02 11:16:40
Done.
| |
| 504 return; | |
| 505 } | |
| 506 bool location_enabled = false; | |
| 507 bool retval = pref->GetValue()->GetAsBoolean(&location_enabled); | |
| 508 DCHECK(retval); | |
| 509 location_enabled &= GetAllowLocationEnabled(env, obj); | |
|
newt (away)
2015/04/02 04:15:18
Do we really need to check GetAllowLocationEnabled
knn
2015/04/02 11:16:40
Yes, I was migrating this before by setting the va
| |
| 510 SetAllowLocationEnabled(env, obj, location_enabled); | |
| 511 GetPrefService()->ClearPref(prefs::kGeolocationEnabled); | |
| 512 } | |
| 513 | |
| 514 static void MigrateProtectedMediaPreference(JNIEnv* env, jobject obj) { | |
| 515 const PrefService::Preference* pref = | |
| 516 GetPrefService()->FindPreference(prefs::kProtectedMediaIdentifierEnabled); | |
| 517 if (!pref || !pref->HasUserSetting()) { | |
| 518 return; | |
| 519 } | |
| 520 bool pmi_enabled = false; | |
| 521 bool retval = pref->GetValue()->GetAsBoolean(&pmi_enabled); | |
| 522 DCHECK(retval); | |
| 523 pmi_enabled &= GetProtectedMediaIdentifierEnabled(env, obj); | |
| 524 SetProtectedMediaIdentifierEnabled(env, obj, pmi_enabled); | |
| 525 GetPrefService()->ClearPref(prefs::kProtectedMediaIdentifierEnabled); | |
| 526 } | |
| 527 | |
| 516 static void SetPasswordEchoEnabled(JNIEnv* env, | 528 static void SetPasswordEchoEnabled(JNIEnv* env, |
| 517 jobject obj, | 529 jobject obj, |
| 518 jboolean passwordEchoEnabled) { | 530 jboolean passwordEchoEnabled) { |
| 519 GetPrefService()->SetBoolean(prefs::kWebKitPasswordEchoEnabled, | 531 GetPrefService()->SetBoolean(prefs::kWebKitPasswordEchoEnabled, |
| 520 passwordEchoEnabled); | 532 passwordEchoEnabled); |
| 521 } | 533 } |
| 522 | 534 |
| 523 static jboolean GetAllowPopupsEnabled(JNIEnv* env, jobject obj) { | 535 static jboolean GetAllowPopupsEnabled(JNIEnv* env, jobject obj) { |
| 524 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_POPUPS); | 536 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_POPUPS); |
| 525 } | 537 } |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 jobject obj) { | 808 jobject obj) { |
| 797 return ConvertUTF8ToJavaString( | 809 return ConvertUTF8ToJavaString( |
| 798 env, | 810 env, |
| 799 GetPrefService()->GetString( | 811 GetPrefService()->GetString( |
| 800 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); | 812 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); |
| 801 } | 813 } |
| 802 | 814 |
| 803 bool RegisterPrefServiceBridge(JNIEnv* env) { | 815 bool RegisterPrefServiceBridge(JNIEnv* env) { |
| 804 return RegisterNativesImpl(env); | 816 return RegisterNativesImpl(env); |
| 805 } | 817 } |
| OLD | NEW |