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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 bool IsContentSettingManaged(ContentSettingsType content_settings_type) { | 97 bool IsContentSettingManaged(ContentSettingsType content_settings_type) { |
| 98 std::string source; | 98 std::string source; |
| 99 HostContentSettingsMap* content_settings = | 99 HostContentSettingsMap* content_settings = |
| 100 GetOriginalProfile()->GetHostContentSettingsMap(); | 100 GetOriginalProfile()->GetHostContentSettingsMap(); |
| 101 content_settings->GetDefaultContentSetting(content_settings_type, &source); | 101 content_settings->GetDefaultContentSetting(content_settings_type, &source); |
| 102 HostContentSettingsMap::ProviderType provider = | 102 HostContentSettingsMap::ProviderType provider = |
| 103 content_settings->GetProviderTypeFromSource(source); | 103 content_settings->GetProviderTypeFromSource(source); |
| 104 return provider == HostContentSettingsMap::POLICY_PROVIDER; | 104 return provider == HostContentSettingsMap::POLICY_PROVIDER; |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool IsContentSettingManagedByCustodian( | |
| 108 ContentSettingsType content_settings_type) { | |
| 109 std::string source; | |
| 110 HostContentSettingsMap* content_settings = | |
| 111 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 112 content_settings->GetDefaultContentSetting(content_settings_type, &source); | |
| 113 HostContentSettingsMap::ProviderType provider = | |
| 114 content_settings->GetProviderTypeFromSource(source); | |
| 115 return provider == HostContentSettingsMap::SUPERVISED_PROVIDER; | |
| 116 } | |
| 117 | |
| 107 bool IsContentSettingUserModifiable(ContentSettingsType content_settings_type) { | 118 bool IsContentSettingUserModifiable(ContentSettingsType content_settings_type) { |
| 108 std::string source; | 119 std::string source; |
| 109 HostContentSettingsMap* content_settings = | 120 HostContentSettingsMap* content_settings = |
| 110 GetOriginalProfile()->GetHostContentSettingsMap(); | 121 GetOriginalProfile()->GetHostContentSettingsMap(); |
| 111 content_settings->GetDefaultContentSetting(content_settings_type, &source); | 122 content_settings->GetDefaultContentSetting(content_settings_type, &source); |
| 112 HostContentSettingsMap::ProviderType provider = | 123 HostContentSettingsMap::ProviderType provider = |
| 113 content_settings->GetProviderTypeFromSource(source); | 124 content_settings->GetProviderTypeFromSource(source); |
| 114 return provider >= HostContentSettingsMap::PREF_PROVIDER; | 125 return provider >= HostContentSettingsMap::PREF_PROVIDER; |
| 115 } | 126 } |
| 116 | 127 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 GetPrefService()->GetBoolean(prefs::kGeolocationEnabled); | 234 GetPrefService()->GetBoolean(prefs::kGeolocationEnabled); |
| 224 } | 235 } |
| 225 | 236 |
| 226 static jboolean GetAllowLocationUserModifiable(JNIEnv* env, jobject obj) { | 237 static jboolean GetAllowLocationUserModifiable(JNIEnv* env, jobject obj) { |
| 227 return IsContentSettingUserModifiable(CONTENT_SETTINGS_TYPE_GEOLOCATION) && | 238 return IsContentSettingUserModifiable(CONTENT_SETTINGS_TYPE_GEOLOCATION) && |
| 228 GetPrefService()->IsUserModifiablePreference( | 239 GetPrefService()->IsUserModifiablePreference( |
| 229 prefs::kGeolocationEnabled); | 240 prefs::kGeolocationEnabled); |
| 230 } | 241 } |
| 231 | 242 |
| 232 static jboolean GetAllowLocationManagedByCustodian(JNIEnv* env, jobject obj) { | 243 static jboolean GetAllowLocationManagedByCustodian(JNIEnv* env, jobject obj) { |
| 233 return GetPrefService()->IsPreferenceManagedByCustodian( | 244 return IsContentSettingManagedByCustodian(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 234 prefs::kGeolocationEnabled); | |
| 235 } | 245 } |
| 236 | 246 |
| 237 static jboolean GetResolveNavigationErrorEnabled(JNIEnv* env, jobject obj) { | 247 static jboolean GetResolveNavigationErrorEnabled(JNIEnv* env, jobject obj) { |
| 238 return GetPrefService()->GetBoolean(prefs::kAlternateErrorPagesEnabled); | 248 return GetPrefService()->GetBoolean(prefs::kAlternateErrorPagesEnabled); |
| 239 } | 249 } |
| 240 | 250 |
| 241 static jboolean GetResolveNavigationErrorManaged(JNIEnv* env, jobject obj) { | 251 static jboolean GetResolveNavigationErrorManaged(JNIEnv* env, jobject obj) { |
| 242 return GetPrefService()->IsManagedPreference( | 252 return GetPrefService()->IsManagedPreference( |
| 243 prefs::kAlternateErrorPagesEnabled); | 253 prefs::kAlternateErrorPagesEnabled); |
| 244 } | 254 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 enabled ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | 430 enabled ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| 421 } | 431 } |
| 422 | 432 |
| 423 static jboolean GetJavaScriptEnabled(JNIEnv* env, jobject obj) { | 433 static jboolean GetJavaScriptEnabled(JNIEnv* env, jobject obj) { |
| 424 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | 434 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); |
| 425 } | 435 } |
| 426 | 436 |
| 427 static void MigrateJavascriptPreference(JNIEnv* env, jobject obj) { | 437 static void MigrateJavascriptPreference(JNIEnv* env, jobject obj) { |
| 428 const PrefService::Preference* javascript_pref = | 438 const PrefService::Preference* javascript_pref = |
| 429 GetPrefService()->FindPreference(prefs::kWebKitJavascriptEnabled); | 439 GetPrefService()->FindPreference(prefs::kWebKitJavascriptEnabled); |
| 430 DCHECK(javascript_pref); | 440 DCHECK(javascript_pref); |
|
Bernhard Bauer
2015/02/26 12:44:57
If |javascript_pref| is indeed null, you will cras
| |
| 431 | 441 |
| 432 if (!javascript_pref->HasUserSetting()) | 442 if (!javascript_pref->HasUserSetting()) |
| 433 return; | 443 return; |
| 434 | 444 |
| 435 bool javascript_enabled = false; | 445 bool javascript_enabled = false; |
| 436 bool retval = javascript_pref->GetValue()->GetAsBoolean(&javascript_enabled); | 446 bool retval = javascript_pref->GetValue()->GetAsBoolean(&javascript_enabled); |
| 437 DCHECK(retval); | 447 DCHECK(retval); |
| 438 SetJavaScriptEnabled(env, obj, javascript_enabled); | 448 SetJavaScriptEnabled(env, obj, javascript_enabled); |
|
Bernhard Bauer
2015/02/26 12:44:57
Is this going to work for user-defined preferences
| |
| 439 GetPrefService()->ClearPref(prefs::kWebKitJavascriptEnabled); | 449 GetPrefService()->ClearPref(prefs::kWebKitJavascriptEnabled); |
| 440 } | 450 } |
| 441 | 451 |
| 442 static void SetPasswordEchoEnabled(JNIEnv* env, | 452 static void SetPasswordEchoEnabled(JNIEnv* env, |
| 443 jobject obj, | 453 jobject obj, |
| 444 jboolean passwordEchoEnabled) { | 454 jboolean passwordEchoEnabled) { |
| 445 GetPrefService()->SetBoolean(prefs::kWebKitPasswordEchoEnabled, | 455 GetPrefService()->SetBoolean(prefs::kWebKitPasswordEchoEnabled, |
| 446 passwordEchoEnabled); | 456 passwordEchoEnabled); |
| 447 } | 457 } |
| 448 | 458 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 470 } | 480 } |
| 471 | 481 |
| 472 static jboolean GetCameraMicUserModifiable(JNIEnv* env, jobject obj) { | 482 static jboolean GetCameraMicUserModifiable(JNIEnv* env, jobject obj) { |
| 473 PrefService* prefs = GetPrefService(); | 483 PrefService* prefs = GetPrefService(); |
| 474 return IsContentSettingUserModifiable(CONTENT_SETTINGS_TYPE_MEDIASTREAM) && | 484 return IsContentSettingUserModifiable(CONTENT_SETTINGS_TYPE_MEDIASTREAM) && |
| 475 prefs->IsUserModifiablePreference(prefs::kAudioCaptureAllowed) && | 485 prefs->IsUserModifiablePreference(prefs::kAudioCaptureAllowed) && |
| 476 prefs->IsUserModifiablePreference(prefs::kVideoCaptureAllowed); | 486 prefs->IsUserModifiablePreference(prefs::kVideoCaptureAllowed); |
| 477 } | 487 } |
| 478 | 488 |
| 479 static jboolean GetCameraMicManagedByCustodian(JNIEnv* env, jobject obj) { | 489 static jboolean GetCameraMicManagedByCustodian(JNIEnv* env, jobject obj) { |
| 480 PrefService* prefs = GetPrefService(); | 490 return IsContentSettingManagedByCustodian(CONTENT_SETTINGS_TYPE_MEDIASTREAM); |
| 481 if (prefs->IsPreferenceManagedByCustodian(prefs::kVideoCaptureAllowed)) | |
| 482 return true; | |
| 483 if (prefs->IsPreferenceManagedByCustodian(prefs::kAudioCaptureAllowed)) | |
| 484 return true; | |
| 485 return false; | |
| 486 } | 491 } |
| 487 | 492 |
| 488 static jboolean GetAutologinEnabled(JNIEnv* env, jobject obj) { | 493 static jboolean GetAutologinEnabled(JNIEnv* env, jobject obj) { |
| 489 return GetPrefService()->GetBoolean(prefs::kAutologinEnabled); | 494 return GetPrefService()->GetBoolean(prefs::kAutologinEnabled); |
| 490 } | 495 } |
| 491 | 496 |
| 492 static void SetAutologinEnabled(JNIEnv* env, jobject obj, | 497 static void SetAutologinEnabled(JNIEnv* env, jobject obj, |
| 493 jboolean autologinEnabled) { | 498 jboolean autologinEnabled) { |
| 494 GetPrefService()->SetBoolean(prefs::kAutologinEnabled, autologinEnabled); | 499 GetPrefService()->SetBoolean(prefs::kAutologinEnabled, autologinEnabled); |
| 495 } | 500 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 jobject obj) { | 713 jobject obj) { |
| 709 return ConvertUTF8ToJavaString( | 714 return ConvertUTF8ToJavaString( |
| 710 env, | 715 env, |
| 711 GetPrefService()->GetString( | 716 GetPrefService()->GetString( |
| 712 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); | 717 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); |
| 713 } | 718 } |
| 714 | 719 |
| 715 bool RegisterPrefServiceBridge(JNIEnv* env) { | 720 bool RegisterPrefServiceBridge(JNIEnv* env) { |
| 716 return RegisterNativesImpl(env); | 721 return RegisterNativesImpl(env); |
| 717 } | 722 } |
| OLD | NEW |