| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 PrefService* GetPrefService() { | 145 PrefService* GetPrefService() { |
| 146 return GetOriginalProfile()->GetPrefs(); | 146 return GetOriginalProfile()->GetPrefs(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 } // namespace | 149 } // namespace |
| 150 | 150 |
| 151 // ---------------------------------------------------------------------------- | 151 // ---------------------------------------------------------------------------- |
| 152 // Native JNI methods | 152 // Native JNI methods |
| 153 // ---------------------------------------------------------------------------- | 153 // ---------------------------------------------------------------------------- |
| 154 | 154 |
| 155 static jboolean IsContentSettingManaged(JNIEnv* env, jobject obj, |
| 156 int content_settings_type) { |
| 157 return IsContentSettingManaged( |
| 158 static_cast<ContentSettingsType>(content_settings_type)); |
| 159 } |
| 160 |
| 161 static jboolean IsContentSettingEnabled(JNIEnv* env, jobject obj, |
| 162 int content_settings_type) { |
| 163 // Before we migrate functions over to this central function, we must verify |
| 164 // that the functionality provided below is correct. |
| 165 DCHECK(content_settings_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || |
| 166 content_settings_type == CONTENT_SETTINGS_TYPE_IMAGES || |
| 167 content_settings_type == CONTENT_SETTINGS_TYPE_POPUPS); |
| 168 ContentSettingsType type = |
| 169 static_cast<ContentSettingsType>(content_settings_type); |
| 170 if (type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || |
| 171 type == CONTENT_SETTINGS_TYPE_POPUPS) |
| 172 return GetBooleanForContentSetting(type); |
| 173 |
| 174 HostContentSettingsMap* content_settings = |
| 175 GetOriginalProfile()->GetHostContentSettingsMap(); |
| 176 return content_settings->GetDefaultContentSetting( |
| 177 type, nullptr) == CONTENT_SETTING_ALLOW; |
| 178 } |
| 179 |
| 180 static void SetContentSettingEnabled(JNIEnv* env, jobject obj, |
| 181 int content_settings_type, jboolean allow) { |
| 182 // Before we migrate functions over to this central function, we must verify |
| 183 // that the new category supports ALLOW/BLOCK pairs and, if not, handle them. |
| 184 DCHECK(content_settings_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || |
| 185 content_settings_type == CONTENT_SETTINGS_TYPE_IMAGES || |
| 186 content_settings_type == CONTENT_SETTINGS_TYPE_POPUPS); |
| 187 HostContentSettingsMap* host_content_settings_map = |
| 188 GetOriginalProfile()->GetHostContentSettingsMap(); |
| 189 host_content_settings_map->SetDefaultContentSetting( |
| 190 static_cast<ContentSettingsType>(content_settings_type), |
| 191 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| 192 } |
| 193 |
| 194 static void SetContentSettingForPattern(JNIEnv* env, jobject obj, |
| 195 int content_settings_type, jstring pattern, int setting) { |
| 196 HostContentSettingsMap* host_content_settings_map = |
| 197 GetOriginalProfile()->GetHostContentSettingsMap(); |
| 198 host_content_settings_map->SetContentSetting( |
| 199 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), |
| 200 ContentSettingsPattern::Wildcard(), |
| 201 static_cast<ContentSettingsType>(content_settings_type), |
| 202 "", |
| 203 static_cast<ContentSetting>(setting)); |
| 204 } |
| 205 |
| 206 static void GetContentSettingsExceptions(JNIEnv* env, jobject obj, |
| 207 int content_settings_type, jobject list) { |
| 208 HostContentSettingsMap* host_content_settings_map = |
| 209 GetOriginalProfile()->GetHostContentSettingsMap(); |
| 210 ContentSettingsForOneType entries; |
| 211 host_content_settings_map->GetSettingsForOneType( |
| 212 static_cast<ContentSettingsType>(content_settings_type), "", &entries); |
| 213 for (size_t i = 0; i < entries.size(); ++i) { |
| 214 Java_PrefServiceBridge_addContentSettingExceptionToList( |
| 215 env, list, |
| 216 content_settings_type, |
| 217 ConvertUTF8ToJavaString( |
| 218 env, entries[i].primary_pattern.ToString()).obj(), |
| 219 ConvertUTF8ToJavaString( |
| 220 env, GetStringForContentSettingsType(entries[i].setting)).obj(), |
| 221 ConvertUTF8ToJavaString(env, entries[i].source).obj()); |
| 222 } |
| 223 } |
| 224 |
| 155 static jboolean GetAcceptCookiesEnabled(JNIEnv* env, jobject obj) { | 225 static jboolean GetAcceptCookiesEnabled(JNIEnv* env, jobject obj) { |
| 156 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); | 226 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); |
| 157 } | 227 } |
| 158 | 228 |
| 159 static jboolean GetAcceptCookiesManaged(JNIEnv* env, jobject obj) { | 229 static jboolean GetAcceptCookiesManaged(JNIEnv* env, jobject obj) { |
| 160 return IsContentSettingManaged(CONTENT_SETTINGS_TYPE_COOKIES); | 230 return IsContentSettingManaged(CONTENT_SETTINGS_TYPE_COOKIES); |
| 161 } | 231 } |
| 162 | 232 |
| 163 static jboolean GetBlockThirdPartyCookiesEnabled(JNIEnv* env, jobject obj) { | 233 static jboolean GetBlockThirdPartyCookiesEnabled(JNIEnv* env, jobject obj) { |
| 164 return GetPrefService()->GetBoolean(prefs::kBlockThirdPartyCookies); | 234 return GetPrefService()->GetBoolean(prefs::kBlockThirdPartyCookies); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 static void SetTranslateEnabled(JNIEnv* env, jobject obj, jboolean enabled) { | 539 static void SetTranslateEnabled(JNIEnv* env, jobject obj, jboolean enabled) { |
| 470 GetPrefService()->SetBoolean(prefs::kEnableTranslate, enabled); | 540 GetPrefService()->SetBoolean(prefs::kEnableTranslate, enabled); |
| 471 } | 541 } |
| 472 | 542 |
| 473 static void ResetTranslateDefaults(JNIEnv* env, jobject obj) { | 543 static void ResetTranslateDefaults(JNIEnv* env, jobject obj) { |
| 474 scoped_ptr<translate::TranslatePrefs> translate_prefs = | 544 scoped_ptr<translate::TranslatePrefs> translate_prefs = |
| 475 ChromeTranslateClient::CreateTranslatePrefs(GetPrefService()); | 545 ChromeTranslateClient::CreateTranslatePrefs(GetPrefService()); |
| 476 translate_prefs->ResetToDefaults(); | 546 translate_prefs->ResetToDefaults(); |
| 477 } | 547 } |
| 478 | 548 |
| 479 static jboolean GetJavaScriptManaged(JNIEnv* env, jobject obj) { | |
| 480 return IsContentSettingManaged(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | |
| 481 } | |
| 482 | |
| 483 static void SetJavaScriptEnabled(JNIEnv* env, jobject obj, jboolean enabled) { | |
| 484 HostContentSettingsMap* host_content_settings_map = | |
| 485 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 486 host_content_settings_map->SetDefaultContentSetting( | |
| 487 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | |
| 488 enabled ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | |
| 489 } | |
| 490 | |
| 491 static jboolean GetJavaScriptEnabled(JNIEnv* env, jobject obj) { | |
| 492 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | |
| 493 } | |
| 494 | |
| 495 static void MigrateJavascriptPreference(JNIEnv* env, jobject obj) { | 549 static void MigrateJavascriptPreference(JNIEnv* env, jobject obj) { |
| 496 const PrefService::Preference* javascript_pref = | 550 const PrefService::Preference* javascript_pref = |
| 497 GetPrefService()->FindPreference(prefs::kWebKitJavascriptEnabled); | 551 GetPrefService()->FindPreference(prefs::kWebKitJavascriptEnabled); |
| 498 DCHECK(javascript_pref); | 552 DCHECK(javascript_pref); |
| 499 | 553 |
| 500 if (!javascript_pref->HasUserSetting()) | 554 if (!javascript_pref->HasUserSetting()) |
| 501 return; | 555 return; |
| 502 | 556 |
| 503 bool javascript_enabled = false; | 557 bool javascript_enabled = false; |
| 504 bool retval = javascript_pref->GetValue()->GetAsBoolean(&javascript_enabled); | 558 bool retval = javascript_pref->GetValue()->GetAsBoolean(&javascript_enabled); |
| 505 DCHECK(retval); | 559 DCHECK(retval); |
| 506 SetJavaScriptEnabled(env, obj, javascript_enabled); | 560 SetContentSettingEnabled(env, obj, |
| 561 CONTENT_SETTINGS_TYPE_JAVASCRIPT, javascript_enabled); |
| 507 GetPrefService()->ClearPref(prefs::kWebKitJavascriptEnabled); | 562 GetPrefService()->ClearPref(prefs::kWebKitJavascriptEnabled); |
| 508 } | 563 } |
| 509 | 564 |
| 510 static void MigrateLocationPreference(JNIEnv* env, jobject obj) { | 565 static void MigrateLocationPreference(JNIEnv* env, jobject obj) { |
| 511 const PrefService::Preference* pref = | 566 const PrefService::Preference* pref = |
| 512 GetPrefService()->FindPreference(prefs::kGeolocationEnabled); | 567 GetPrefService()->FindPreference(prefs::kGeolocationEnabled); |
| 513 if (!pref || !pref->HasUserSetting()) | 568 if (!pref || !pref->HasUserSetting()) |
| 514 return; | 569 return; |
| 515 bool location_enabled = false; | 570 bool location_enabled = false; |
| 516 bool retval = pref->GetValue()->GetAsBoolean(&location_enabled); | 571 bool retval = pref->GetValue()->GetAsBoolean(&location_enabled); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 536 GetPrefService()->ClearPref(prefs::kProtectedMediaIdentifierEnabled); | 591 GetPrefService()->ClearPref(prefs::kProtectedMediaIdentifierEnabled); |
| 537 } | 592 } |
| 538 | 593 |
| 539 static void SetPasswordEchoEnabled(JNIEnv* env, | 594 static void SetPasswordEchoEnabled(JNIEnv* env, |
| 540 jobject obj, | 595 jobject obj, |
| 541 jboolean passwordEchoEnabled) { | 596 jboolean passwordEchoEnabled) { |
| 542 GetPrefService()->SetBoolean(prefs::kWebKitPasswordEchoEnabled, | 597 GetPrefService()->SetBoolean(prefs::kWebKitPasswordEchoEnabled, |
| 543 passwordEchoEnabled); | 598 passwordEchoEnabled); |
| 544 } | 599 } |
| 545 | 600 |
| 546 static jboolean GetAllowPopupsEnabled(JNIEnv* env, jobject obj) { | |
| 547 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_POPUPS); | |
| 548 } | |
| 549 | |
| 550 static jboolean GetAllowPopupsManaged(JNIEnv* env, jobject obj) { | |
| 551 return IsContentSettingManaged(CONTENT_SETTINGS_TYPE_POPUPS); | |
| 552 } | |
| 553 | |
| 554 static void SetAllowPopupsEnabled(JNIEnv* env, jobject obj, jboolean allow) { | |
| 555 HostContentSettingsMap* host_content_settings_map = | |
| 556 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 557 host_content_settings_map->SetDefaultContentSetting( | |
| 558 CONTENT_SETTINGS_TYPE_POPUPS, | |
| 559 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | |
| 560 } | |
| 561 | 601 |
| 562 static jboolean GetCameraMicEnabled(JNIEnv* env, jobject obj) { | 602 static jboolean GetCameraMicEnabled(JNIEnv* env, jobject obj) { |
| 563 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | 603 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && |
| 564 GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 604 GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 565 } | 605 } |
| 566 | 606 |
| 567 static jboolean GetCameraMicUserModifiable(JNIEnv* env, jobject obj) { | 607 static jboolean GetCameraMicUserModifiable(JNIEnv* env, jobject obj) { |
| 568 return IsContentSettingUserModifiable( | 608 return IsContentSettingUserModifiable( |
| 569 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | 609 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && |
| 570 IsContentSettingUserModifiable( | 610 IsContentSettingUserModifiable( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 592 HostContentSettingsMap* host_content_settings_map = | 632 HostContentSettingsMap* host_content_settings_map = |
| 593 GetOriginalProfile()->GetHostContentSettingsMap(); | 633 GetOriginalProfile()->GetHostContentSettingsMap(); |
| 594 host_content_settings_map->SetContentSetting( | 634 host_content_settings_map->SetContentSetting( |
| 595 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), | 635 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), |
| 596 ContentSettingsPattern::Wildcard(), | 636 ContentSettingsPattern::Wildcard(), |
| 597 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 637 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 598 "", | 638 "", |
| 599 static_cast<ContentSetting>(setting)); | 639 static_cast<ContentSetting>(setting)); |
| 600 } | 640 } |
| 601 | 641 |
| 602 static void GetJavaScriptExceptions(JNIEnv* env, jobject obj, jobject list) { | |
| 603 HostContentSettingsMap* host_content_settings_map = | |
| 604 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 605 ContentSettingsForOneType entries; | |
| 606 host_content_settings_map->GetSettingsForOneType( | |
| 607 CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", &entries); | |
| 608 for (size_t i = 0; i < entries.size(); ++i) { | |
| 609 Java_PrefServiceBridge_addJavaScriptExceptionToList( | |
| 610 env, list, | |
| 611 ConvertUTF8ToJavaString( | |
| 612 env, entries[i].primary_pattern.ToString()).obj(), | |
| 613 ConvertUTF8ToJavaString( | |
| 614 env, GetStringForContentSettingsType(entries[i].setting)).obj(), | |
| 615 ConvertUTF8ToJavaString(env, entries[i].source).obj()); | |
| 616 } | |
| 617 } | |
| 618 | |
| 619 static void SetPopupException(JNIEnv* env, jobject obj, jstring pattern, | 642 static void SetPopupException(JNIEnv* env, jobject obj, jstring pattern, |
| 620 int setting) { | 643 int setting) { |
| 621 HostContentSettingsMap* host_content_settings_map = | 644 HostContentSettingsMap* host_content_settings_map = |
| 622 GetOriginalProfile()->GetHostContentSettingsMap(); | 645 GetOriginalProfile()->GetHostContentSettingsMap(); |
| 623 host_content_settings_map->SetContentSetting( | 646 host_content_settings_map->SetContentSetting( |
| 624 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), | 647 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), |
| 625 ContentSettingsPattern::Wildcard(), | 648 ContentSettingsPattern::Wildcard(), |
| 626 CONTENT_SETTINGS_TYPE_POPUPS, | 649 CONTENT_SETTINGS_TYPE_POPUPS, |
| 627 "", | 650 "", |
| 628 static_cast<ContentSetting>(setting)); | 651 static_cast<ContentSetting>(setting)); |
| 629 } | 652 } |
| 630 | 653 |
| 631 static void GetPopupExceptions(JNIEnv* env, jobject obj, jobject list) { | |
| 632 HostContentSettingsMap* host_content_settings_map = | |
| 633 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 634 ContentSettingsForOneType entries; | |
| 635 host_content_settings_map->GetSettingsForOneType( | |
| 636 CONTENT_SETTINGS_TYPE_POPUPS, "", &entries); | |
| 637 for (size_t i = 0; i < entries.size(); ++i) { | |
| 638 Java_PrefServiceBridge_insertPopupExceptionToList( | |
| 639 env, list, | |
| 640 ConvertUTF8ToJavaString( | |
| 641 env, entries[i].primary_pattern.ToString()).obj(), | |
| 642 ConvertUTF8ToJavaString( | |
| 643 env, GetStringForContentSettingsType(entries[i].setting)).obj(), | |
| 644 ConvertUTF8ToJavaString(env, entries[i].source).obj()); | |
| 645 } | |
| 646 } | |
| 647 | |
| 648 static void SetSearchSuggestEnabled(JNIEnv* env, jobject obj, | 654 static void SetSearchSuggestEnabled(JNIEnv* env, jobject obj, |
| 649 jboolean enabled) { | 655 jboolean enabled) { |
| 650 GetPrefService()->SetBoolean(prefs::kSearchSuggestEnabled, enabled); | 656 GetPrefService()->SetBoolean(prefs::kSearchSuggestEnabled, enabled); |
| 651 } | 657 } |
| 652 | 658 |
| 653 static jstring GetContextualSearchPreference(JNIEnv* env, jobject obj) { | 659 static jstring GetContextualSearchPreference(JNIEnv* env, jobject obj) { |
| 654 return ConvertUTF8ToJavaString( | 660 return ConvertUTF8ToJavaString( |
| 655 env, GetPrefService()->GetString(prefs::kContextualSearchEnabled)). | 661 env, GetPrefService()->GetString(prefs::kContextualSearchEnabled)). |
| 656 Release(); | 662 Release(); |
| 657 } | 663 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 jobject obj) { | 825 jobject obj) { |
| 820 return ConvertUTF8ToJavaString( | 826 return ConvertUTF8ToJavaString( |
| 821 env, | 827 env, |
| 822 GetPrefService()->GetString( | 828 GetPrefService()->GetString( |
| 823 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); | 829 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); |
| 824 } | 830 } |
| 825 | 831 |
| 826 bool RegisterPrefServiceBridge(JNIEnv* env) { | 832 bool RegisterPrefServiceBridge(JNIEnv* env) { |
| 827 return RegisterNativesImpl(env); | 833 return RegisterNativesImpl(env); |
| 828 } | 834 } |
| OLD | NEW |