Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsitePreferences.java

Issue 1091253005: [Android] Update Protected Media Identifier Settings UI to reflect exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 14 matching lines...) Expand all
25 25
26 import org.chromium.chrome.R; 26 import org.chromium.chrome.R;
27 import org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference; 27 import org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference;
28 import org.chromium.chrome.browser.preferences.ChromeBasePreference; 28 import org.chromium.chrome.browser.preferences.ChromeBasePreference;
29 import org.chromium.chrome.browser.preferences.ChromeSwitchPreference; 29 import org.chromium.chrome.browser.preferences.ChromeSwitchPreference;
30 import org.chromium.chrome.browser.preferences.ExpandablePreferenceGroup; 30 import org.chromium.chrome.browser.preferences.ExpandablePreferenceGroup;
31 import org.chromium.chrome.browser.preferences.LocationSettings; 31 import org.chromium.chrome.browser.preferences.LocationSettings;
32 import org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate; 32 import org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate;
33 import org.chromium.chrome.browser.preferences.ManagedPreferencesUtils; 33 import org.chromium.chrome.browser.preferences.ManagedPreferencesUtils;
34 import org.chromium.chrome.browser.preferences.PrefServiceBridge; 34 import org.chromium.chrome.browser.preferences.PrefServiceBridge;
35 import org.chromium.chrome.browser.preferences.ProtectedContentResetCredentialCo nfirmDialogFragment;
35 import org.chromium.chrome.browser.widget.TintedDrawable; 36 import org.chromium.chrome.browser.widget.TintedDrawable;
37 import org.chromium.content.browser.MediaDrmCredentialManager;
38 import org.chromium.content.browser.MediaDrmCredentialManager.MediaDrmCredential ManagerCallback;
36 import org.chromium.ui.text.SpanApplier; 39 import org.chromium.ui.text.SpanApplier;
37 import org.chromium.ui.text.SpanApplier.SpanInfo; 40 import org.chromium.ui.text.SpanApplier.SpanInfo;
38 41
39 import java.util.ArrayList; 42 import java.util.ArrayList;
40 import java.util.Collections; 43 import java.util.Collections;
41 import java.util.HashSet; 44 import java.util.HashSet;
42 import java.util.List; 45 import java.util.List;
43 import java.util.Map; 46 import java.util.Map;
44 import java.util.Set; 47 import java.util.Set;
45 48
46 /** 49 /**
47 * Shows a list of sites with their associated HTML5 settings. When the 50 * Shows a list of sites with their associated HTML5 settings. When the
48 * users selects a site, a SingleWebsitePreferences fragment is launched to 51 * users selects a site, a SingleWebsitePreferences fragment is launched to
49 * allow the user to modify the settings. 52 * allow the user to modify the settings.
50 */ 53 */
51 public class WebsitePreferences extends PreferenceFragment 54 public class WebsitePreferences extends PreferenceFragment
52 implements OnPreferenceChangeListener, OnPreferenceClickListener, 55 implements OnPreferenceChangeListener, OnPreferenceClickListener,
53 AddExceptionPreference.SiteAddedCallback { 56 AddExceptionPreference.SiteAddedCallback,
57 ProtectedContentResetCredentialConfirmDialogFragment.Listener {
54 // The key to use to pass which category this preference should display, 58 // The key to use to pass which category this preference should display,
55 // e.g. Location/Popups/All sites (if blank). 59 // e.g. Location/Popups/All sites (if blank).
56 public static final String EXTRA_CATEGORY = "category"; 60 public static final String EXTRA_CATEGORY = "category";
57 public static final String EXTRA_TITLE = "title"; 61 public static final String EXTRA_TITLE = "title";
58 62
59 // The view to show when the list is empty. 63 // The view to show when the list is empty.
60 private TextView mEmptyView; 64 private TextView mEmptyView;
61 // The view for searching the list of items. 65 // The view for searching the list of items.
62 private SearchView mSearchView; 66 private SearchView mSearchView;
63 // What category the list is filtered by (e.g. show all, location, storage, 67 // What category the list is filtered by (e.g. show all, location, storage,
(...skipping 10 matching lines...) Expand all
74 // Whether the Allowed list should be shown expanded. 78 // Whether the Allowed list should be shown expanded.
75 private boolean mAllowListExpanded = true; 79 private boolean mAllowListExpanded = true;
76 // Whether this is the first time this screen is shown. 80 // Whether this is the first time this screen is shown.
77 private boolean mIsInitialRun = true; 81 private boolean mIsInitialRun = true;
78 // The number of sites that are on the Allowed list. 82 // The number of sites that are on the Allowed list.
79 private int mAllowedSiteCount = 0; 83 private int mAllowedSiteCount = 0;
80 84
81 // Keys for individual preferences. 85 // Keys for individual preferences.
82 public static final String READ_WRITE_TOGGLE_KEY = "read_write_toggle"; 86 public static final String READ_WRITE_TOGGLE_KEY = "read_write_toggle";
83 public static final String THIRD_PARTY_COOKIES_TOGGLE_KEY = "third_party_coo kies"; 87 public static final String THIRD_PARTY_COOKIES_TOGGLE_KEY = "third_party_coo kies";
88 public static final String EXPLAIN_PROTECTED_MEDIA_KEY = "protected_content_ learn_more";
84 private static final String ADD_EXCEPTION_KEY = "add_exception"; 89 private static final String ADD_EXCEPTION_KEY = "add_exception";
85 // Keys for Allowed/Blocked preference groups/headers. 90 // Keys for Allowed/Blocked preference groups/headers.
86 private static final String ALLOWED_GROUP = "allowed_group"; 91 private static final String ALLOWED_GROUP = "allowed_group";
87 private static final String BLOCKED_GROUP = "blocked_group"; 92 private static final String BLOCKED_GROUP = "blocked_group";
88 93
89 private void getInfoForOrigins() { 94 private void getInfoForOrigins() {
90 WebsitePermissionsFetcher fetcher = new WebsitePermissionsFetcher(new Re sultsPopulator()); 95 WebsitePermissionsFetcher fetcher = new WebsitePermissionsFetcher(new Re sultsPopulator());
91 fetcher.fetchPreferencesWithFilter(mCategoryFilter); 96 fetcher.fetchPreferencesWithFilter(mCategoryFilter);
92 } 97 }
93 98
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } else if (mFilter.showGeolocationSites(mCategoryFilter)) { 215 } else if (mFilter.showGeolocationSites(mCategoryFilter)) {
211 return website.site().getGeolocationPermission() == ContentSetting.B LOCK; 216 return website.site().getGeolocationPermission() == ContentSetting.B LOCK;
212 } else if (mFilter.showImagesSites(mCategoryFilter)) { 217 } else if (mFilter.showImagesSites(mCategoryFilter)) {
213 return website.site().getImagesPermission() == ContentSetting.BLOCK; 218 return website.site().getImagesPermission() == ContentSetting.BLOCK;
214 } else if (mFilter.showJavaScriptSites(mCategoryFilter)) { 219 } else if (mFilter.showJavaScriptSites(mCategoryFilter)) {
215 return website.site().getJavaScriptPermission() == ContentSetting.BL OCK; 220 return website.site().getJavaScriptPermission() == ContentSetting.BL OCK;
216 } else if (mFilter.showPopupSites(mCategoryFilter)) { 221 } else if (mFilter.showPopupSites(mCategoryFilter)) {
217 return website.site().getPopupPermission() == ContentSetting.BLOCK; 222 return website.site().getPopupPermission() == ContentSetting.BLOCK;
218 } else if (mFilter.showPushNotificationsSites(mCategoryFilter)) { 223 } else if (mFilter.showPushNotificationsSites(mCategoryFilter)) {
219 return website.site().getPushNotificationPermission() == ContentSett ing.BLOCK; 224 return website.site().getPushNotificationPermission() == ContentSett ing.BLOCK;
225 } else if (mFilter.showProtectedMediaSites(mCategoryFilter)) {
226 return website.site().getProtectedMediaIdentifierPermission() == Con tentSetting.BLOCK;
220 } 227 }
221 228
222 return false; 229 return false;
223 } 230 }
224 231
225 /** 232 /**
226 * Update the Category Header for the Allowed list. 233 * Update the Category Header for the Allowed list.
227 * @param numAllowed The number of sites that are on the Allowed list 234 * @param numAllowed The number of sites that are on the Allowed list
228 * @param toggleValue The value the global toggle will have once precessing ends. 235 * @param toggleValue The value the global toggle will have once precessing ends.
229 */ 236 */
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 super.onActivityCreated(savedInstanceState); 298 super.onActivityCreated(savedInstanceState);
292 } 299 }
293 300
294 @Override 301 @Override
295 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 302 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
296 inflater.inflate(R.menu.website_preferences_menu, menu); 303 inflater.inflate(R.menu.website_preferences_menu, menu);
297 304
298 MenuItem searchItem = menu.findItem(R.id.search); 305 MenuItem searchItem = menu.findItem(R.id.search);
299 mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem); 306 mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
300 mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN); 307 mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
301
302 SearchView.OnQueryTextListener queryTextListener = 308 SearchView.OnQueryTextListener queryTextListener =
303 new SearchView.OnQueryTextListener() { 309 new SearchView.OnQueryTextListener() {
304 @Override 310 @Override
305 public boolean onQueryTextSubmit(String query) { 311 public boolean onQueryTextSubmit(String query) {
306 return true; 312 return true;
307 } 313 }
308 314
309 @Override 315 @Override
310 public boolean onQueryTextChange(String query) { 316 public boolean onQueryTextChange(String query) {
311 if (query.equals(mSearch)) return true; 317 if (query.equals(mSearch)) return true;
312 318
313 mSearch = query; 319 mSearch = query;
314 getInfoForOrigins(); 320 getInfoForOrigins();
315 return true; 321 return true;
316 } 322 }
317 }; 323 };
318 mSearchView.setOnQueryTextListener(queryTextListener); 324 mSearchView.setOnQueryTextListener(queryTextListener);
325
326 if (!mFilter.showProtectedMediaSites(mCategoryFilter)) return;
newt (away) 2015/04/30 00:31:59 Early returns are dangerous. Other developers may
knn 2015/04/30 16:00:36 Looks really nasty, Done. Thanks for the explanati
327 // Add a menu item to reset protected media identifier device credential s.
328 MenuItem resetMenu =
329 menu.add(Menu.NONE, Menu.NONE, Menu.FIRST, R.string.reset_device _credentials);
330 resetMenu.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListene r() {
331 @Override
332 public boolean onMenuItemClick(MenuItem menuItem) {
333 new ProtectedContentResetCredentialConfirmDialogFragment(Website Preferences.this)
334 .show(getFragmentManager(), null);
335 return true;
336 }
337 });
319 } 338 }
320 339
321 @Override 340 @Override
322 public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference pre ference) { 341 public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference pre ference) {
323 // Do not show the toast if the System Location setting is disabled. 342 // Do not show the toast if the System Location setting is disabled.
324 if (getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY) != null 343 if (getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY) != null
325 && isCategoryManaged()) { 344 && isCategoryManaged()) {
326 showManagedToast(); 345 showManagedToast();
327 return false; 346 return false;
328 } 347 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } else if (mFilter.showFullscreenSites(mCategoryFilter)) { 379 } else if (mFilter.showFullscreenSites(mCategoryFilter)) {
361 PrefServiceBridge.getInstance().setFullscreenAllowed((boolean) n ewValue); 380 PrefServiceBridge.getInstance().setFullscreenAllowed((boolean) n ewValue);
362 } else if (mFilter.showImagesSites(mCategoryFilter)) { 381 } else if (mFilter.showImagesSites(mCategoryFilter)) {
363 PrefServiceBridge.getInstance().setImagesEnabled((boolean) newVa lue); 382 PrefServiceBridge.getInstance().setImagesEnabled((boolean) newVa lue);
364 } else if (mFilter.showJavaScriptSites(mCategoryFilter)) { 383 } else if (mFilter.showJavaScriptSites(mCategoryFilter)) {
365 PrefServiceBridge.getInstance().setJavaScriptEnabled((boolean) n ewValue); 384 PrefServiceBridge.getInstance().setJavaScriptEnabled((boolean) n ewValue);
366 } else if (mFilter.showPopupSites(mCategoryFilter)) { 385 } else if (mFilter.showPopupSites(mCategoryFilter)) {
367 PrefServiceBridge.getInstance().setAllowPopupsEnabled((boolean) newValue); 386 PrefServiceBridge.getInstance().setAllowPopupsEnabled((boolean) newValue);
368 } else if (mFilter.showPushNotificationsSites(mCategoryFilter)) { 387 } else if (mFilter.showPushNotificationsSites(mCategoryFilter)) {
369 PrefServiceBridge.getInstance().setPushNotificationsEnabled((boo lean) newValue); 388 PrefServiceBridge.getInstance().setPushNotificationsEnabled((boo lean) newValue);
389 } else if (mFilter.showProtectedMediaSites(mCategoryFilter)) {
390 PrefServiceBridge.getInstance().setProtectedMediaIdentifierEnabl ed(
391 (boolean) newValue);
370 } 392 }
371 393
372 // Categories that support adding exceptions also manage the 'Add si te' preference. 394 // Categories that support adding exceptions also manage the 'Add si te' preference.
373 if (mFilter.showImagesSites(mCategoryFilter) 395 if (mFilter.showImagesSites(mCategoryFilter)
374 || mFilter.showJavaScriptSites(mCategoryFilter)) { 396 || mFilter.showJavaScriptSites(mCategoryFilter)) {
375 if ((boolean) newValue) { 397 if ((boolean) newValue) {
376 Preference addException = getPreferenceScreen().findPreferen ce( 398 Preference addException = getPreferenceScreen().findPreferen ce(
377 ADD_EXCEPTION_KEY); 399 ADD_EXCEPTION_KEY);
378 if (addException != null) { // Can be null in testing. 400 if (addException != null) { // Can be null in testing.
379 getPreferenceScreen().removePreference(addException); 401 getPreferenceScreen().removePreference(addException);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 new AddExceptionPreference(getActivity(), ADD_EXCEPTION_KEY, 514 new AddExceptionPreference(getActivity(), ADD_EXCEPTION_KEY,
493 getAddExceptionDialogMessage(), this)); 515 getAddExceptionDialogMessage(), this));
494 } 516 }
495 } 517 }
496 518
497 private void configureGlobalToggles() { 519 private void configureGlobalToggles() {
498 // Only some have a global toggle at the top. 520 // Only some have a global toggle at the top.
499 ChromeSwitchPreference globalToggle = (ChromeSwitchPreference) 521 ChromeSwitchPreference globalToggle = (ChromeSwitchPreference)
500 getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY); 522 getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY);
501 523
524 // Configure/hide the third-party cookie toggle, as needed.
502 Preference thirdPartyCookies = getPreferenceScreen().findPreference( 525 Preference thirdPartyCookies = getPreferenceScreen().findPreference(
503 THIRD_PARTY_COOKIES_TOGGLE_KEY); 526 THIRD_PARTY_COOKIES_TOGGLE_KEY);
504
505 // Configure/hide the third-party cookie toggle, as needed.
506 if (mFilter.showCookiesSites(mCategoryFilter)) { 527 if (mFilter.showCookiesSites(mCategoryFilter)) {
507 thirdPartyCookies.setOnPreferenceChangeListener(this); 528 thirdPartyCookies.setOnPreferenceChangeListener(this);
508 updateThirdPartyCookiesCheckBox(); 529 updateThirdPartyCookiesCheckBox();
509 } else { 530 } else {
510 getPreferenceScreen().removePreference(thirdPartyCookies); 531 getPreferenceScreen().removePreference(thirdPartyCookies);
511 } 532 }
512 533
534 // Show/hide the link that explains protected media settings, as needed.
535 if (mFilter.showProtectedMediaSites(mCategoryFilter)) {
536 globalToggle.setDrawDivider(false);
newt (away) 2015/04/30 00:31:59 I think we should keep the divider, i.e. remove th
knn 2015/04/30 16:00:36 Done.
537 } else {
538 getPreferenceScreen().removePreference(
539 getPreferenceScreen().findPreference(EXPLAIN_PROTECTED_MEDIA _KEY));
540 }
541
513 if (mFilter.showAllSites(mCategoryFilter) 542 if (mFilter.showAllSites(mCategoryFilter)
514 || mFilter.showStorageSites(mCategoryFilter)) { 543 || mFilter.showStorageSites(mCategoryFilter)) {
515 getPreferenceScreen().removePreference(globalToggle); 544 getPreferenceScreen().removePreference(globalToggle);
516 getPreferenceScreen().removePreference( 545 getPreferenceScreen().removePreference(
517 getPreferenceScreen().findPreference(ALLOWED_GROUP)); 546 getPreferenceScreen().findPreference(ALLOWED_GROUP));
518 getPreferenceScreen().removePreference( 547 getPreferenceScreen().removePreference(
519 getPreferenceScreen().findPreference(BLOCKED_GROUP)); 548 getPreferenceScreen().findPreference(BLOCKED_GROUP));
520 } else { 549 } else {
521 // When this menu opens, make sure the Blocked list is collapsed. 550 // When this menu opens, make sure the Blocked list is collapsed.
522 if (!mGroupByAllowBlock) { 551 if (!mGroupByAllowBlock) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 } else if (mFilter.showImagesSites(mCategoryFilter)) { 613 } else if (mFilter.showImagesSites(mCategoryFilter)) {
585 globalToggle.setChecked( 614 globalToggle.setChecked(
586 PrefServiceBridge.getInstance().imagesEnabled()); 615 PrefServiceBridge.getInstance().imagesEnabled());
587 } else if (mFilter.showJavaScriptSites(mCategoryFilter)) { 616 } else if (mFilter.showJavaScriptSites(mCategoryFilter)) {
588 globalToggle.setChecked(PrefServiceBridge.getInstance().java ScriptEnabled()); 617 globalToggle.setChecked(PrefServiceBridge.getInstance().java ScriptEnabled());
589 } else if (mFilter.showPopupSites(mCategoryFilter)) { 618 } else if (mFilter.showPopupSites(mCategoryFilter)) {
590 globalToggle.setChecked(PrefServiceBridge.getInstance().popu psEnabled()); 619 globalToggle.setChecked(PrefServiceBridge.getInstance().popu psEnabled());
591 } else if (mFilter.showPushNotificationsSites(mCategoryFilter)) { 620 } else if (mFilter.showPushNotificationsSites(mCategoryFilter)) {
592 globalToggle.setChecked( 621 globalToggle.setChecked(
593 PrefServiceBridge.getInstance().isPushNotificationsE nabled()); 622 PrefServiceBridge.getInstance().isPushNotificationsE nabled());
623 } else if (mFilter.showProtectedMediaSites(mCategoryFilter)) {
624 globalToggle.setChecked(
625 PrefServiceBridge.getInstance().isProtectedMediaIden tifierEnabled());
594 } 626 }
595 } 627 }
596 } 628 }
597 } 629 }
598 630
599 private void updateThirdPartyCookiesCheckBox() { 631 private void updateThirdPartyCookiesCheckBox() {
600 ChromeBaseCheckBoxPreference thirdPartyCookiesPref = (ChromeBaseCheckBox Preference) 632 ChromeBaseCheckBoxPreference thirdPartyCookiesPref = (ChromeBaseCheckBox Preference)
601 getPreferenceScreen().findPreference(THIRD_PARTY_COOKIES_TOGGLE_ KEY); 633 getPreferenceScreen().findPreference(THIRD_PARTY_COOKIES_TOGGLE_ KEY);
602 thirdPartyCookiesPref.setEnabled(PrefServiceBridge.getInstance().isAccep tCookiesEnabled()); 634 thirdPartyCookiesPref.setEnabled(PrefServiceBridge.getInstance().isAccep tCookiesEnabled());
603 thirdPartyCookiesPref.setManagedPreferenceDelegate(new ManagedPreference Delegate() { 635 thirdPartyCookiesPref.setManagedPreferenceDelegate(new ManagedPreference Delegate() {
604 @Override 636 @Override
605 public boolean isPreferenceControlledByPolicy(Preference preference) { 637 public boolean isPreferenceControlledByPolicy(Preference preference) {
606 return PrefServiceBridge.getInstance().isBlockThirdPartyCookiesM anaged(); 638 return PrefServiceBridge.getInstance().isBlockThirdPartyCookiesM anaged();
607 } 639 }
608 }); 640 });
609 } 641 }
610 642
611 private void showManagedToast() { 643 private void showManagedToast() {
612 if (isCategoryManagedByCustodian()) { 644 if (isCategoryManagedByCustodian()) {
613 ManagedPreferencesUtils.showManagedByParentToast(getActivity()); 645 ManagedPreferencesUtils.showManagedByParentToast(getActivity());
614 } else { 646 } else {
615 ManagedPreferencesUtils.showManagedByAdministratorToast(getActivity( )); 647 ManagedPreferencesUtils.showManagedByAdministratorToast(getActivity( ));
616 } 648 }
617 } 649 }
650
651 @Override
newt (away) 2015/04/30 00:31:59 add // ProtectedContentResetCredentialConfirm
knn 2015/04/30 16:00:36 Done.
652 public void resetDeviceCredential() {
653 MediaDrmCredentialManager.resetCredentials(new MediaDrmCredentialManager Callback() {
654 @Override
655 public void onCredentialResetFinished(boolean succeeded) {
656 if (succeeded) return;
657 String message = getString(R.string.protected_content_reset_fail ed);
658 Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show( );
659 }
660 });
661 }
618 } 662 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698