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 || | |
newt (away)
2015/04/10 18:46:49
This is a good check to add. Thanks :0
Finnur
2015/04/13 12:59:32
Acknowledged.
| |
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 SetContentSettingDefault(JNIEnv* env, jobject obj, | |
newt (away)
2015/04/10 18:46:49
"SetContentSettingEnabled()"
Finnur
2015/04/13 12:59:32
Done.
| |
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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 static void SetTranslateEnabled(JNIEnv* env, jobject obj, jboolean enabled) { | 529 static void SetTranslateEnabled(JNIEnv* env, jobject obj, jboolean enabled) { |
460 GetPrefService()->SetBoolean(prefs::kEnableTranslate, enabled); | 530 GetPrefService()->SetBoolean(prefs::kEnableTranslate, enabled); |
461 } | 531 } |
462 | 532 |
463 static void ResetTranslateDefaults(JNIEnv* env, jobject obj) { | 533 static void ResetTranslateDefaults(JNIEnv* env, jobject obj) { |
464 scoped_ptr<translate::TranslatePrefs> translate_prefs = | 534 scoped_ptr<translate::TranslatePrefs> translate_prefs = |
465 ChromeTranslateClient::CreateTranslatePrefs(GetPrefService()); | 535 ChromeTranslateClient::CreateTranslatePrefs(GetPrefService()); |
466 translate_prefs->ResetToDefaults(); | 536 translate_prefs->ResetToDefaults(); |
467 } | 537 } |
468 | 538 |
469 static jboolean GetJavaScriptManaged(JNIEnv* env, jobject obj) { | |
470 return IsContentSettingManaged(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | |
471 } | |
472 | |
473 static void SetJavaScriptEnabled(JNIEnv* env, jobject obj, jboolean enabled) { | |
474 HostContentSettingsMap* host_content_settings_map = | |
475 GetOriginalProfile()->GetHostContentSettingsMap(); | |
476 host_content_settings_map->SetDefaultContentSetting( | |
477 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | |
478 enabled ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | |
479 } | |
480 | |
481 static jboolean GetJavaScriptEnabled(JNIEnv* env, jobject obj) { | |
482 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | |
483 } | |
484 | |
485 static void MigrateJavascriptPreference(JNIEnv* env, jobject obj) { | 539 static void MigrateJavascriptPreference(JNIEnv* env, jobject obj) { |
486 const PrefService::Preference* javascript_pref = | 540 const PrefService::Preference* javascript_pref = |
487 GetPrefService()->FindPreference(prefs::kWebKitJavascriptEnabled); | 541 GetPrefService()->FindPreference(prefs::kWebKitJavascriptEnabled); |
488 DCHECK(javascript_pref); | 542 DCHECK(javascript_pref); |
489 | 543 |
490 if (!javascript_pref->HasUserSetting()) | 544 if (!javascript_pref->HasUserSetting()) |
491 return; | 545 return; |
492 | 546 |
493 bool javascript_enabled = false; | 547 bool javascript_enabled = false; |
494 bool retval = javascript_pref->GetValue()->GetAsBoolean(&javascript_enabled); | 548 bool retval = javascript_pref->GetValue()->GetAsBoolean(&javascript_enabled); |
495 DCHECK(retval); | 549 DCHECK(retval); |
496 SetJavaScriptEnabled(env, obj, javascript_enabled); | 550 SetContentSettingDefault(env, obj, |
551 CONTENT_SETTINGS_TYPE_JAVASCRIPT, javascript_enabled); | |
497 GetPrefService()->ClearPref(prefs::kWebKitJavascriptEnabled); | 552 GetPrefService()->ClearPref(prefs::kWebKitJavascriptEnabled); |
498 } | 553 } |
499 | 554 |
500 static void MigrateLocationPreference(JNIEnv* env, jobject obj) { | 555 static void MigrateLocationPreference(JNIEnv* env, jobject obj) { |
501 const PrefService::Preference* pref = | 556 const PrefService::Preference* pref = |
502 GetPrefService()->FindPreference(prefs::kGeolocationEnabled); | 557 GetPrefService()->FindPreference(prefs::kGeolocationEnabled); |
503 if (!pref || !pref->HasUserSetting()) | 558 if (!pref || !pref->HasUserSetting()) |
504 return; | 559 return; |
505 bool location_enabled = false; | 560 bool location_enabled = false; |
506 bool retval = pref->GetValue()->GetAsBoolean(&location_enabled); | 561 bool retval = pref->GetValue()->GetAsBoolean(&location_enabled); |
(...skipping 19 matching lines...) Expand all Loading... | |
526 GetPrefService()->ClearPref(prefs::kProtectedMediaIdentifierEnabled); | 581 GetPrefService()->ClearPref(prefs::kProtectedMediaIdentifierEnabled); |
527 } | 582 } |
528 | 583 |
529 static void SetPasswordEchoEnabled(JNIEnv* env, | 584 static void SetPasswordEchoEnabled(JNIEnv* env, |
530 jobject obj, | 585 jobject obj, |
531 jboolean passwordEchoEnabled) { | 586 jboolean passwordEchoEnabled) { |
532 GetPrefService()->SetBoolean(prefs::kWebKitPasswordEchoEnabled, | 587 GetPrefService()->SetBoolean(prefs::kWebKitPasswordEchoEnabled, |
533 passwordEchoEnabled); | 588 passwordEchoEnabled); |
534 } | 589 } |
535 | 590 |
536 static jboolean GetAllowPopupsEnabled(JNIEnv* env, jobject obj) { | |
537 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_POPUPS); | |
538 } | |
539 | |
540 static jboolean GetAllowPopupsManaged(JNIEnv* env, jobject obj) { | |
541 return IsContentSettingManaged(CONTENT_SETTINGS_TYPE_POPUPS); | |
542 } | |
543 | |
544 static void SetAllowPopupsEnabled(JNIEnv* env, jobject obj, jboolean allow) { | |
545 HostContentSettingsMap* host_content_settings_map = | |
546 GetOriginalProfile()->GetHostContentSettingsMap(); | |
547 host_content_settings_map->SetDefaultContentSetting( | |
548 CONTENT_SETTINGS_TYPE_POPUPS, | |
549 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | |
550 } | |
551 | 591 |
552 static jboolean GetCameraMicEnabled(JNIEnv* env, jobject obj) { | 592 static jboolean GetCameraMicEnabled(JNIEnv* env, jobject obj) { |
553 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | 593 return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && |
554 GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 594 GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
555 } | 595 } |
556 | 596 |
557 static jboolean GetCameraMicUserModifiable(JNIEnv* env, jobject obj) { | 597 static jboolean GetCameraMicUserModifiable(JNIEnv* env, jobject obj) { |
558 return IsContentSettingUserModifiable( | 598 return IsContentSettingUserModifiable( |
559 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | 599 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && |
560 IsContentSettingUserModifiable( | 600 IsContentSettingUserModifiable( |
(...skipping 21 matching lines...) Expand all Loading... | |
582 HostContentSettingsMap* host_content_settings_map = | 622 HostContentSettingsMap* host_content_settings_map = |
583 GetOriginalProfile()->GetHostContentSettingsMap(); | 623 GetOriginalProfile()->GetHostContentSettingsMap(); |
584 host_content_settings_map->SetContentSetting( | 624 host_content_settings_map->SetContentSetting( |
585 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), | 625 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), |
586 ContentSettingsPattern::Wildcard(), | 626 ContentSettingsPattern::Wildcard(), |
587 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 627 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
588 "", | 628 "", |
589 static_cast<ContentSetting>(setting)); | 629 static_cast<ContentSetting>(setting)); |
590 } | 630 } |
591 | 631 |
592 static void GetJavaScriptExceptions(JNIEnv* env, jobject obj, jobject list) { | |
593 HostContentSettingsMap* host_content_settings_map = | |
594 GetOriginalProfile()->GetHostContentSettingsMap(); | |
595 ContentSettingsForOneType entries; | |
596 host_content_settings_map->GetSettingsForOneType( | |
597 CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", &entries); | |
598 for (size_t i = 0; i < entries.size(); ++i) { | |
599 Java_PrefServiceBridge_addJavaScriptExceptionToList( | |
600 env, list, | |
601 ConvertUTF8ToJavaString( | |
602 env, entries[i].primary_pattern.ToString()).obj(), | |
603 ConvertUTF8ToJavaString( | |
604 env, GetStringForContentSettingsType(entries[i].setting)).obj(), | |
605 ConvertUTF8ToJavaString(env, entries[i].source).obj()); | |
606 } | |
607 } | |
608 | |
609 static void SetPopupException(JNIEnv* env, jobject obj, jstring pattern, | 632 static void SetPopupException(JNIEnv* env, jobject obj, jstring pattern, |
610 int setting) { | 633 int setting) { |
611 HostContentSettingsMap* host_content_settings_map = | 634 HostContentSettingsMap* host_content_settings_map = |
612 GetOriginalProfile()->GetHostContentSettingsMap(); | 635 GetOriginalProfile()->GetHostContentSettingsMap(); |
613 host_content_settings_map->SetContentSetting( | 636 host_content_settings_map->SetContentSetting( |
614 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), | 637 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), |
615 ContentSettingsPattern::Wildcard(), | 638 ContentSettingsPattern::Wildcard(), |
616 CONTENT_SETTINGS_TYPE_POPUPS, | 639 CONTENT_SETTINGS_TYPE_POPUPS, |
617 "", | 640 "", |
618 static_cast<ContentSetting>(setting)); | 641 static_cast<ContentSetting>(setting)); |
619 } | 642 } |
620 | 643 |
621 static void GetPopupExceptions(JNIEnv* env, jobject obj, jobject list) { | |
622 HostContentSettingsMap* host_content_settings_map = | |
623 GetOriginalProfile()->GetHostContentSettingsMap(); | |
624 ContentSettingsForOneType entries; | |
625 host_content_settings_map->GetSettingsForOneType( | |
626 CONTENT_SETTINGS_TYPE_POPUPS, "", &entries); | |
627 for (size_t i = 0; i < entries.size(); ++i) { | |
628 Java_PrefServiceBridge_insertPopupExceptionToList( | |
629 env, list, | |
630 ConvertUTF8ToJavaString( | |
631 env, entries[i].primary_pattern.ToString()).obj(), | |
632 ConvertUTF8ToJavaString( | |
633 env, GetStringForContentSettingsType(entries[i].setting)).obj(), | |
634 ConvertUTF8ToJavaString(env, entries[i].source).obj()); | |
635 } | |
636 } | |
637 | |
638 static void SetSearchSuggestEnabled(JNIEnv* env, jobject obj, | 644 static void SetSearchSuggestEnabled(JNIEnv* env, jobject obj, |
639 jboolean enabled) { | 645 jboolean enabled) { |
640 GetPrefService()->SetBoolean(prefs::kSearchSuggestEnabled, enabled); | 646 GetPrefService()->SetBoolean(prefs::kSearchSuggestEnabled, enabled); |
641 } | 647 } |
642 | 648 |
643 static jstring GetContextualSearchPreference(JNIEnv* env, jobject obj) { | 649 static jstring GetContextualSearchPreference(JNIEnv* env, jobject obj) { |
644 return ConvertUTF8ToJavaString( | 650 return ConvertUTF8ToJavaString( |
645 env, GetPrefService()->GetString(prefs::kContextualSearchEnabled)). | 651 env, GetPrefService()->GetString(prefs::kContextualSearchEnabled)). |
646 Release(); | 652 Release(); |
647 } | 653 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 jobject obj) { | 815 jobject obj) { |
810 return ConvertUTF8ToJavaString( | 816 return ConvertUTF8ToJavaString( |
811 env, | 817 env, |
812 GetPrefService()->GetString( | 818 GetPrefService()->GetString( |
813 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); | 819 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); |
814 } | 820 } |
815 | 821 |
816 bool RegisterPrefServiceBridge(JNIEnv* env) { | 822 bool RegisterPrefServiceBridge(JNIEnv* env) { |
817 return RegisterNativesImpl(env); | 823 return RegisterNativesImpl(env); |
818 } | 824 } |
OLD | NEW |