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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 static void SetTranslateEnabled(JNIEnv* env, jobject obj, jboolean enabled) { | 459 static void SetTranslateEnabled(JNIEnv* env, jobject obj, jboolean enabled) { |
| 460 GetPrefService()->SetBoolean(prefs::kEnableTranslate, enabled); | 460 GetPrefService()->SetBoolean(prefs::kEnableTranslate, enabled); |
| 461 } | 461 } |
| 462 | 462 |
| 463 static void ResetTranslateDefaults(JNIEnv* env, jobject obj) { | 463 static void ResetTranslateDefaults(JNIEnv* env, jobject obj) { |
| 464 scoped_ptr<translate::TranslatePrefs> translate_prefs = | 464 scoped_ptr<translate::TranslatePrefs> translate_prefs = |
| 465 ChromeTranslateClient::CreateTranslatePrefs(GetPrefService()); | 465 ChromeTranslateClient::CreateTranslatePrefs(GetPrefService()); |
| 466 translate_prefs->ResetToDefaults(); | 466 translate_prefs->ResetToDefaults(); |
| 467 } | 467 } |
| 468 | 468 |
| 469 static jboolean GetImagesManaged(JNIEnv* env, jobject obj) { | |
| 470 return IsContentSettingManaged(CONTENT_SETTINGS_TYPE_IMAGES); | |
| 471 } | |
| 472 | |
| 473 static jboolean GetImagesEnabled(JNIEnv* env, jobject obj) { | |
| 474 HostContentSettingsMap* content_settings = | |
| 475 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 476 return content_settings->GetDefaultContentSetting( | |
| 477 CONTENT_SETTINGS_TYPE_IMAGES, NULL) == CONTENT_SETTING_ALLOW; | |
|
newt (away)
2015/04/09 23:43:20
use nullptr
Finnur
2015/04/10 17:03:26
Done.
| |
| 478 } | |
| 479 | |
| 480 static void SetImagesEnabled(JNIEnv* env, jobject obj, jboolean allow) { | |
| 481 HostContentSettingsMap* host_content_settings_map = | |
| 482 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 483 host_content_settings_map->SetDefaultContentSetting( | |
| 484 CONTENT_SETTINGS_TYPE_IMAGES, | |
| 485 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | |
| 486 } | |
| 487 | |
| 469 static jboolean GetJavaScriptManaged(JNIEnv* env, jobject obj) { | 488 static jboolean GetJavaScriptManaged(JNIEnv* env, jobject obj) { |
| 470 return IsContentSettingManaged(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | 489 return IsContentSettingManaged(CONTENT_SETTINGS_TYPE_JAVASCRIPT); |
| 471 } | 490 } |
| 472 | 491 |
| 473 static void SetJavaScriptEnabled(JNIEnv* env, jobject obj, jboolean enabled) { | 492 static void SetJavaScriptEnabled(JNIEnv* env, jobject obj, jboolean enabled) { |
| 474 HostContentSettingsMap* host_content_settings_map = | 493 HostContentSettingsMap* host_content_settings_map = |
| 475 GetOriginalProfile()->GetHostContentSettingsMap(); | 494 GetOriginalProfile()->GetHostContentSettingsMap(); |
| 476 host_content_settings_map->SetDefaultContentSetting( | 495 host_content_settings_map->SetDefaultContentSetting( |
| 477 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 496 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 478 enabled ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | 497 enabled ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 | 589 |
| 571 static jboolean GetAutologinEnabled(JNIEnv* env, jobject obj) { | 590 static jboolean GetAutologinEnabled(JNIEnv* env, jobject obj) { |
| 572 return GetPrefService()->GetBoolean(prefs::kAutologinEnabled); | 591 return GetPrefService()->GetBoolean(prefs::kAutologinEnabled); |
| 573 } | 592 } |
| 574 | 593 |
| 575 static void SetAutologinEnabled(JNIEnv* env, jobject obj, | 594 static void SetAutologinEnabled(JNIEnv* env, jobject obj, |
| 576 jboolean autologinEnabled) { | 595 jboolean autologinEnabled) { |
| 577 GetPrefService()->SetBoolean(prefs::kAutologinEnabled, autologinEnabled); | 596 GetPrefService()->SetBoolean(prefs::kAutologinEnabled, autologinEnabled); |
| 578 } | 597 } |
| 579 | 598 |
| 599 static void SetImagesAllowed(JNIEnv* env, jobject obj, jstring pattern, | |
|
newt (away)
2015/04/09 23:43:20
The proliferation of these almost-identical method
Finnur
2015/04/10 17:03:26
Yeah, I agree. This is ripe for a cleanup and I ta
| |
| 600 int setting) { | |
| 601 HostContentSettingsMap* host_content_settings_map = | |
| 602 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 603 host_content_settings_map->SetContentSetting( | |
| 604 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), | |
| 605 ContentSettingsPattern::Wildcard(), | |
| 606 CONTENT_SETTINGS_TYPE_IMAGES, | |
| 607 "", | |
| 608 static_cast<ContentSetting>(setting)); | |
| 609 } | |
| 610 | |
| 611 static void GetImagesExceptions(JNIEnv* env, jobject obj, jobject list) { | |
| 612 HostContentSettingsMap* host_content_settings_map = | |
| 613 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 614 ContentSettingsForOneType entries; | |
| 615 host_content_settings_map->GetSettingsForOneType( | |
| 616 CONTENT_SETTINGS_TYPE_IMAGES, "", &entries); | |
| 617 for (size_t i = 0; i < entries.size(); ++i) { | |
| 618 Java_PrefServiceBridge_addImagesExceptionToList( | |
| 619 env, list, | |
| 620 ConvertUTF8ToJavaString( | |
| 621 env, entries[i].primary_pattern.ToString()).obj(), | |
| 622 ConvertUTF8ToJavaString( | |
| 623 env, GetStringForContentSettingsType(entries[i].setting)).obj(), | |
| 624 ConvertUTF8ToJavaString(env, entries[i].source).obj()); | |
| 625 } | |
| 626 } | |
| 627 | |
| 580 static void SetJavaScriptAllowed(JNIEnv* env, jobject obj, jstring pattern, | 628 static void SetJavaScriptAllowed(JNIEnv* env, jobject obj, jstring pattern, |
| 581 int setting) { | 629 int setting) { |
| 582 HostContentSettingsMap* host_content_settings_map = | 630 HostContentSettingsMap* host_content_settings_map = |
| 583 GetOriginalProfile()->GetHostContentSettingsMap(); | 631 GetOriginalProfile()->GetHostContentSettingsMap(); |
| 584 host_content_settings_map->SetContentSetting( | 632 host_content_settings_map->SetContentSetting( |
| 585 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), | 633 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), |
| 586 ContentSettingsPattern::Wildcard(), | 634 ContentSettingsPattern::Wildcard(), |
| 587 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 635 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 588 "", | 636 "", |
| 589 static_cast<ContentSetting>(setting)); | 637 static_cast<ContentSetting>(setting)); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 jobject obj) { | 857 jobject obj) { |
| 810 return ConvertUTF8ToJavaString( | 858 return ConvertUTF8ToJavaString( |
| 811 env, | 859 env, |
| 812 GetPrefService()->GetString( | 860 GetPrefService()->GetString( |
| 813 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); | 861 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); |
| 814 } | 862 } |
| 815 | 863 |
| 816 bool RegisterPrefServiceBridge(JNIEnv* env) { | 864 bool RegisterPrefServiceBridge(JNIEnv* env) { |
| 817 return RegisterNativesImpl(env); | 865 return RegisterNativesImpl(env); |
| 818 } | 866 } |
| OLD | NEW |