OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 package org.chromium.chrome.browser.preferences.website; | 5 package org.chromium.chrome.browser.preferences.website; |
6 | 6 |
7 import android.os.Bundle; | 7 import android.os.Bundle; |
8 import android.preference.Preference; | 8 import android.preference.Preference; |
9 import android.preference.Preference.OnPreferenceChangeListener; | 9 import android.preference.Preference.OnPreferenceChangeListener; |
10 import android.preference.Preference.OnPreferenceClickListener; | 10 import android.preference.Preference.OnPreferenceClickListener; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // Whether the Allowed list should be shown expanded. | 73 // Whether the Allowed list should be shown expanded. |
74 private boolean mAllowListExpanded = true; | 74 private boolean mAllowListExpanded = true; |
75 // Whether this is the first time this screen is shown. | 75 // Whether this is the first time this screen is shown. |
76 private boolean mIsInitialRun = true; | 76 private boolean mIsInitialRun = true; |
77 // The number of sites that are on the Allowed list. | 77 // The number of sites that are on the Allowed list. |
78 private int mAllowedSiteCount = 0; | 78 private int mAllowedSiteCount = 0; |
79 | 79 |
80 // Keys for individual preferences. | 80 // Keys for individual preferences. |
81 public static final String READ_WRITE_TOGGLE_KEY = "read_write_toggle"; | 81 public static final String READ_WRITE_TOGGLE_KEY = "read_write_toggle"; |
82 public static final String THIRD_PARTY_COOKIES_TOGGLE_KEY = "third_party_coo
kies"; | 82 public static final String THIRD_PARTY_COOKIES_TOGGLE_KEY = "third_party_coo
kies"; |
| 83 public static final String NOTIFICATIONS_VIBRATE_TOGGLE_KEY = "notifications
_vibrate"; |
83 public static final String EXPLAIN_PROTECTED_MEDIA_KEY = "protected_content_
learn_more"; | 84 public static final String EXPLAIN_PROTECTED_MEDIA_KEY = "protected_content_
learn_more"; |
84 private static final String ADD_EXCEPTION_KEY = "add_exception"; | 85 private static final String ADD_EXCEPTION_KEY = "add_exception"; |
85 // Keys for Allowed/Blocked preference groups/headers. | 86 // Keys for Allowed/Blocked preference groups/headers. |
86 private static final String ALLOWED_GROUP = "allowed_group"; | 87 private static final String ALLOWED_GROUP = "allowed_group"; |
87 private static final String BLOCKED_GROUP = "blocked_group"; | 88 private static final String BLOCKED_GROUP = "blocked_group"; |
88 | 89 |
89 private void getInfoForOrigins() { | 90 private void getInfoForOrigins() { |
90 if (!mCategory.enabledInAndroid(getActivity())) { | 91 if (!mCategory.enabledInAndroid(getActivity())) { |
91 // No need to fetch any data if we're not going to show it, but we d
o need to update | 92 // No need to fetch any data if we're not going to show it, but we d
o need to update |
92 // the global toggle to reflect updates in Android settings (e.g. Lo
cation). | 93 // the global toggle to reflect updates in Android settings (e.g. Lo
cation). |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 } else if (mCategory.showFullscreenSites()) { | 411 } else if (mCategory.showFullscreenSites()) { |
411 PrefServiceBridge.getInstance().setFullscreenAllowed((boolean) n
ewValue); | 412 PrefServiceBridge.getInstance().setFullscreenAllowed((boolean) n
ewValue); |
412 } else if (mCategory.showGeolocationSites()) { | 413 } else if (mCategory.showGeolocationSites()) { |
413 PrefServiceBridge.getInstance().setAllowLocationEnabled((boolean
) newValue); | 414 PrefServiceBridge.getInstance().setAllowLocationEnabled((boolean
) newValue); |
414 } else if (mCategory.showJavaScriptSites()) { | 415 } else if (mCategory.showJavaScriptSites()) { |
415 PrefServiceBridge.getInstance().setJavaScriptEnabled((boolean) n
ewValue); | 416 PrefServiceBridge.getInstance().setJavaScriptEnabled((boolean) n
ewValue); |
416 } else if (mCategory.showMicrophoneSites()) { | 417 } else if (mCategory.showMicrophoneSites()) { |
417 PrefServiceBridge.getInstance().setMicEnabled((boolean) newValue
); | 418 PrefServiceBridge.getInstance().setMicEnabled((boolean) newValue
); |
418 } else if (mCategory.showNotificationsSites()) { | 419 } else if (mCategory.showNotificationsSites()) { |
419 PrefServiceBridge.getInstance().setNotificationsEnabled((boolean
) newValue); | 420 PrefServiceBridge.getInstance().setNotificationsEnabled((boolean
) newValue); |
| 421 updateNotificationsVibrateCheckBox(); |
420 } else if (mCategory.showPopupSites()) { | 422 } else if (mCategory.showPopupSites()) { |
421 PrefServiceBridge.getInstance().setAllowPopupsEnabled((boolean)
newValue); | 423 PrefServiceBridge.getInstance().setAllowPopupsEnabled((boolean)
newValue); |
422 } else if (mCategory.showProtectedMediaSites()) { | 424 } else if (mCategory.showProtectedMediaSites()) { |
423 PrefServiceBridge.getInstance().setProtectedMediaIdentifierEnabl
ed( | 425 PrefServiceBridge.getInstance().setProtectedMediaIdentifierEnabl
ed( |
424 (boolean) newValue); | 426 (boolean) newValue); |
425 } | 427 } |
426 | 428 |
427 // Categories that support adding exceptions also manage the 'Add si
te' preference. | 429 // Categories that support adding exceptions also manage the 'Add si
te' preference. |
428 if (mCategory.showAutoplaySites() || mCategory.showBackgroundSyncSit
es() | 430 if (mCategory.showAutoplaySites() || mCategory.showBackgroundSyncSit
es() |
429 || mCategory.showJavaScriptSites()) { | 431 || mCategory.showJavaScriptSites()) { |
(...skipping 10 matching lines...) Expand all Loading... |
440 } | 442 } |
441 } | 443 } |
442 | 444 |
443 ChromeSwitchPreference globalToggle = (ChromeSwitchPreference) | 445 ChromeSwitchPreference globalToggle = (ChromeSwitchPreference) |
444 getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY); | 446 getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY); |
445 updateAllowedHeader(mAllowedSiteCount, !globalToggle.isChecked()); | 447 updateAllowedHeader(mAllowedSiteCount, !globalToggle.isChecked()); |
446 | 448 |
447 getInfoForOrigins(); | 449 getInfoForOrigins(); |
448 } else if (THIRD_PARTY_COOKIES_TOGGLE_KEY.equals(preference.getKey())) { | 450 } else if (THIRD_PARTY_COOKIES_TOGGLE_KEY.equals(preference.getKey())) { |
449 PrefServiceBridge.getInstance().setBlockThirdPartyCookiesEnabled(!((
boolean) newValue)); | 451 PrefServiceBridge.getInstance().setBlockThirdPartyCookiesEnabled(!((
boolean) newValue)); |
| 452 } else if (NOTIFICATIONS_VIBRATE_TOGGLE_KEY.equals(preference.getKey()))
{ |
| 453 PrefServiceBridge.getInstance().setNotificationsVibrateEnabled((bool
ean) newValue); |
450 } | 454 } |
451 return true; | 455 return true; |
452 } | 456 } |
453 | 457 |
454 private String getAddExceptionDialogMessage() { | 458 private String getAddExceptionDialogMessage() { |
455 int resource = 0; | 459 int resource = 0; |
456 if (mCategory.showAutoplaySites()) { | 460 if (mCategory.showAutoplaySites()) { |
457 resource = R.string.website_settings_add_site_description_autoplay; | 461 resource = R.string.website_settings_add_site_description_autoplay; |
458 } else if (mCategory.showBackgroundSyncSites()) { | 462 } else if (mCategory.showBackgroundSyncSites()) { |
459 resource = R.string.website_settings_add_site_description_background
_sync; | 463 resource = R.string.website_settings_add_site_description_background
_sync; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 // Configure/hide the third-party cookie toggle, as needed. | 534 // Configure/hide the third-party cookie toggle, as needed. |
531 Preference thirdPartyCookies = getPreferenceScreen().findPreference( | 535 Preference thirdPartyCookies = getPreferenceScreen().findPreference( |
532 THIRD_PARTY_COOKIES_TOGGLE_KEY); | 536 THIRD_PARTY_COOKIES_TOGGLE_KEY); |
533 if (mCategory.showCookiesSites()) { | 537 if (mCategory.showCookiesSites()) { |
534 thirdPartyCookies.setOnPreferenceChangeListener(this); | 538 thirdPartyCookies.setOnPreferenceChangeListener(this); |
535 updateThirdPartyCookiesCheckBox(); | 539 updateThirdPartyCookiesCheckBox(); |
536 } else { | 540 } else { |
537 getPreferenceScreen().removePreference(thirdPartyCookies); | 541 getPreferenceScreen().removePreference(thirdPartyCookies); |
538 } | 542 } |
539 | 543 |
| 544 // Configure/hide the notifications vibrate toggle, as needed. |
| 545 Preference notificationsVibrate = |
| 546 getPreferenceScreen().findPreference(NOTIFICATIONS_VIBRATE_TOGGL
E_KEY); |
| 547 if (mCategory.showNotificationsSites()) { |
| 548 notificationsVibrate.setOnPreferenceChangeListener(this); |
| 549 updateNotificationsVibrateCheckBox(); |
| 550 } else { |
| 551 getPreferenceScreen().removePreference(notificationsVibrate); |
| 552 } |
| 553 |
540 // Show/hide the link that explains protected media settings, as needed. | 554 // Show/hide the link that explains protected media settings, as needed. |
541 if (!mCategory.showProtectedMediaSites()) { | 555 if (!mCategory.showProtectedMediaSites()) { |
542 getPreferenceScreen().removePreference( | 556 getPreferenceScreen().removePreference( |
543 getPreferenceScreen().findPreference(EXPLAIN_PROTECTED_MEDIA
_KEY)); | 557 getPreferenceScreen().findPreference(EXPLAIN_PROTECTED_MEDIA
_KEY)); |
544 } | 558 } |
545 | 559 |
546 if (mCategory.showAllSites() | 560 if (mCategory.showAllSites() |
547 || mCategory.showStorageSites()) { | 561 || mCategory.showStorageSites()) { |
548 getPreferenceScreen().removePreference(globalToggle); | 562 getPreferenceScreen().removePreference(globalToggle); |
549 getPreferenceScreen().removePreference( | 563 getPreferenceScreen().removePreference( |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 getPreferenceScreen().findPreference(THIRD_PARTY_COOKIES_TOGGLE_
KEY); | 658 getPreferenceScreen().findPreference(THIRD_PARTY_COOKIES_TOGGLE_
KEY); |
645 thirdPartyCookiesPref.setEnabled(PrefServiceBridge.getInstance().isAccep
tCookiesEnabled()); | 659 thirdPartyCookiesPref.setEnabled(PrefServiceBridge.getInstance().isAccep
tCookiesEnabled()); |
646 thirdPartyCookiesPref.setManagedPreferenceDelegate(new ManagedPreference
Delegate() { | 660 thirdPartyCookiesPref.setManagedPreferenceDelegate(new ManagedPreference
Delegate() { |
647 @Override | 661 @Override |
648 public boolean isPreferenceControlledByPolicy(Preference preference)
{ | 662 public boolean isPreferenceControlledByPolicy(Preference preference)
{ |
649 return PrefServiceBridge.getInstance().isBlockThirdPartyCookiesM
anaged(); | 663 return PrefServiceBridge.getInstance().isBlockThirdPartyCookiesM
anaged(); |
650 } | 664 } |
651 }); | 665 }); |
652 } | 666 } |
653 | 667 |
| 668 private void updateNotificationsVibrateCheckBox() { |
| 669 ChromeBaseCheckBoxPreference preference = |
| 670 (ChromeBaseCheckBoxPreference) getPreferenceScreen().findPrefere
nce( |
| 671 NOTIFICATIONS_VIBRATE_TOGGLE_KEY); |
| 672 preference.setEnabled(PrefServiceBridge.getInstance().isNotificationsEna
bled()); |
| 673 } |
| 674 |
654 private void showManagedToast() { | 675 private void showManagedToast() { |
655 if (mCategory.isManagedByCustodian()) { | 676 if (mCategory.isManagedByCustodian()) { |
656 ManagedPreferencesUtils.showManagedByParentToast(getActivity()); | 677 ManagedPreferencesUtils.showManagedByParentToast(getActivity()); |
657 } else { | 678 } else { |
658 ManagedPreferencesUtils.showManagedByAdministratorToast(getActivity(
)); | 679 ManagedPreferencesUtils.showManagedByAdministratorToast(getActivity(
)); |
659 } | 680 } |
660 } | 681 } |
661 | 682 |
662 // ProtectedContentResetCredentialConfirmDialogFragment.Listener: | 683 // ProtectedContentResetCredentialConfirmDialogFragment.Listener: |
663 @Override | 684 @Override |
664 public void resetDeviceCredential() { | 685 public void resetDeviceCredential() { |
665 MediaDrmCredentialManager.resetCredentials(new MediaDrmCredentialManager
Callback() { | 686 MediaDrmCredentialManager.resetCredentials(new MediaDrmCredentialManager
Callback() { |
666 @Override | 687 @Override |
667 public void onCredentialResetFinished(boolean succeeded) { | 688 public void onCredentialResetFinished(boolean succeeded) { |
668 if (succeeded) return; | 689 if (succeeded) return; |
669 String message = getString(R.string.protected_content_reset_fail
ed); | 690 String message = getString(R.string.protected_content_reset_fail
ed); |
670 Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show(
); | 691 Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show(
); |
671 } | 692 } |
672 }); | 693 }); |
673 } | 694 } |
674 } | 695 } |
OLD | NEW |