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

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

Issue 2888473003: [subresource_filter] Site Details UI for default state (Closed)
Patch Set: raymes review: remove some strings Created 3 years, 7 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.content.Context; 7 import android.content.Context;
8 import android.content.DialogInterface; 8 import android.content.DialogInterface;
9 import android.content.res.Resources; 9 import android.content.res.Resources;
10 import android.net.Uri; 10 import android.net.Uri;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 // Preference keys, see single_website_preferences.xml 58 // Preference keys, see single_website_preferences.xml
59 // Headings: 59 // Headings:
60 public static final String PREF_SITE_TITLE = "site_title"; 60 public static final String PREF_SITE_TITLE = "site_title";
61 public static final String PREF_USAGE = "site_usage"; 61 public static final String PREF_USAGE = "site_usage";
62 public static final String PREF_PERMISSIONS = "site_permissions"; 62 public static final String PREF_PERMISSIONS = "site_permissions";
63 public static final String PREF_OS_PERMISSIONS_WARNING = "os_permissions_war ning"; 63 public static final String PREF_OS_PERMISSIONS_WARNING = "os_permissions_war ning";
64 public static final String PREF_OS_PERMISSIONS_WARNING_EXTRA = "os_permissio ns_warning_extra"; 64 public static final String PREF_OS_PERMISSIONS_WARNING_EXTRA = "os_permissio ns_warning_extra";
65 public static final String PREF_OS_PERMISSIONS_WARNING_DIVIDER = 65 public static final String PREF_OS_PERMISSIONS_WARNING_DIVIDER =
66 "os_permissions_warning_divider"; 66 "os_permissions_warning_divider";
67 public static final String PREF_EXTRA_INFO = "website_settings_extra_info";
68 public static final String PREF_EXTRA_INFO_DIVIDER = "website_settings_extra _info_divider";
Finnur 2017/05/23 15:37:13 These key names are a bit generic, as if to suppor
Charlie Harrison 2017/05/23 17:12:19 Renamed to subresource_filter_permission_extra_inf
67 // Actions at the top (if adding new, see hasUsagePreferences below): 69 // Actions at the top (if adding new, see hasUsagePreferences below):
68 public static final String PREF_CLEAR_DATA = "clear_data"; 70 public static final String PREF_CLEAR_DATA = "clear_data";
69 // Buttons: 71 // Buttons:
70 public static final String PREF_RESET_SITE = "reset_site_button"; 72 public static final String PREF_RESET_SITE = "reset_site_button";
71 // Website permissions (if adding new, see hasPermissionsPreferences and res etSite below): 73 // Website permissions (if adding new, see hasPermissionsPreferences and res etSite below):
72 public static final String PREF_AUTOPLAY_PERMISSION = "autoplay_permission_l ist"; 74 public static final String PREF_AUTOPLAY_PERMISSION = "autoplay_permission_l ist";
73 public static final String PREF_BACKGROUND_SYNC_PERMISSION = "background_syn c_permission_list"; 75 public static final String PREF_BACKGROUND_SYNC_PERMISSION = "background_syn c_permission_list";
74 public static final String PREF_CAMERA_CAPTURE_PERMISSION = "camera_permissi on_list"; 76 public static final String PREF_CAMERA_CAPTURE_PERMISSION = "camera_permissi on_list";
75 public static final String PREF_COOKIES_PERMISSION = "cookies_permission_lis t"; 77 public static final String PREF_COOKIES_PERMISSION = "cookies_permission_lis t";
76 public static final String PREF_JAVASCRIPT_PERMISSION = "javascript_permissi on_list"; 78 public static final String PREF_JAVASCRIPT_PERMISSION = "javascript_permissi on_list";
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 && (origin.equals(info.getEmbedderSafe()) || "*".equals(info.get EmbedderSafe())); 264 && (origin.equals(info.getEmbedderSafe()) || "*".equals(info.get EmbedderSafe()));
263 } 265 }
264 266
265 /** 267 /**
266 * Updates the permissions displayed in the UI by fetching them from mSite. 268 * Updates the permissions displayed in the UI by fetching them from mSite.
267 * Must only be called once mSite is set. 269 * Must only be called once mSite is set.
268 */ 270 */
269 private void displaySitePermissions() { 271 private void displaySitePermissions() {
270 addPreferencesFromResource(R.xml.single_website_preferences); 272 addPreferencesFromResource(R.xml.single_website_preferences);
271 273
274 // This boolean controls how the subresource filter list preference beha ves, as well as
275 // gating the extra info header for subresource filtering.
Finnur 2017/05/23 15:37:13 nit: "gating a header" is language that I (as a no
Charlie Harrison 2017/05/23 17:12:19 I tried to rephrase the comment.
276 boolean subresourceFilterActivated = WebsitePreferenceBridge.getSubresou rceFilterActivated(
277 mSite.getAddress().getOrigin());
278
272 Set<String> permissionPreferenceKeys = 279 Set<String> permissionPreferenceKeys =
273 new HashSet<>(Arrays.asList(PERMISSION_PREFERENCE_KEYS)); 280 new HashSet<>(Arrays.asList(PERMISSION_PREFERENCE_KEYS));
274 int maxPermissionOrder = 0; 281 int maxPermissionOrder = 0;
275 ListAdapter preferences = getPreferenceScreen().getRootAdapter(); 282 ListAdapter preferences = getPreferenceScreen().getRootAdapter();
276 for (int i = 0; i < preferences.getCount(); ++i) { 283 for (int i = 0; i < preferences.getCount(); ++i) {
277 Preference preference = (Preference) preferences.getItem(i); 284 Preference preference = (Preference) preferences.getItem(i);
278 if (PREF_SITE_TITLE.equals(preference.getKey())) { 285 if (PREF_SITE_TITLE.equals(preference.getKey())) {
279 preference.setTitle(mSite.getTitle()); 286 preference.setTitle(mSite.getTitle());
280 } else if (PREF_CLEAR_DATA.equals(preference.getKey())) { 287 } else if (PREF_CLEAR_DATA.equals(preference.getKey())) {
281 long usage = mSite.getTotalUsage(); 288 long usage = mSite.getTotalUsage();
(...skipping 24 matching lines...) Expand all
306 setUpListPreference(preference, mSite.getMicrophonePermission()) ; 313 setUpListPreference(preference, mSite.getMicrophonePermission()) ;
307 } else if (PREF_MIDI_SYSEX_PERMISSION.equals(preference.getKey())) { 314 } else if (PREF_MIDI_SYSEX_PERMISSION.equals(preference.getKey())) {
308 setUpListPreference(preference, mSite.getMidiPermission()); 315 setUpListPreference(preference, mSite.getMidiPermission());
309 } else if (PREF_NOTIFICATIONS_PERMISSION.equals(preference.getKey()) ) { 316 } else if (PREF_NOTIFICATIONS_PERMISSION.equals(preference.getKey()) ) {
310 setUpListPreference(preference, mSite.getNotificationPermission( )); 317 setUpListPreference(preference, mSite.getNotificationPermission( ));
311 } else if (PREF_POPUP_PERMISSION.equals(preference.getKey())) { 318 } else if (PREF_POPUP_PERMISSION.equals(preference.getKey())) {
312 setUpListPreference(preference, mSite.getPopupPermission()); 319 setUpListPreference(preference, mSite.getPopupPermission());
313 } else if (PREF_PROTECTED_MEDIA_IDENTIFIER_PERMISSION.equals(prefere nce.getKey())) { 320 } else if (PREF_PROTECTED_MEDIA_IDENTIFIER_PERMISSION.equals(prefere nce.getKey())) {
314 setUpListPreference(preference, mSite.getProtectedMediaIdentifie rPermission()); 321 setUpListPreference(preference, mSite.getProtectedMediaIdentifie rPermission());
315 } else if (PREF_SUBRESOURCE_FILTER_PERMISSION.equals(preference.getK ey())) { 322 } else if (PREF_SUBRESOURCE_FILTER_PERMISSION.equals(preference.getK ey())) {
316 setUpListPreference(preference, mSite.getSubresourceFilterPermis sion()); 323 setUpSubresourceFilterPreference(preference, subresourceFilterAc tivated);
317 } 324 }
318 325
319 if (permissionPreferenceKeys.contains(preference.getKey())) { 326 if (permissionPreferenceKeys.contains(preference.getKey())) {
320 maxPermissionOrder = Math.max(maxPermissionOrder, preference.get Order()); 327 maxPermissionOrder = Math.max(maxPermissionOrder, preference.get Order());
321 } 328 }
322 } 329 }
323 330
324 for (UsbInfo info : mSite.getUsbInfo()) { 331 for (UsbInfo info : mSite.getUsbInfo()) {
325 Preference preference = new Preference(getActivity()); 332 Preference preference = new Preference(getActivity());
326 preference.getExtras().putSerializable(EXTRA_USB_INFO, info); 333 preference.getExtras().putSerializable(EXTRA_USB_INFO, info);
(...skipping 24 matching lines...) Expand all
351 osWarning, osWarningExtra, getActivity(), false); 358 osWarning, osWarningExtra, getActivity(), false);
352 if (osWarning.getTitle() == null) { 359 if (osWarning.getTitle() == null) {
353 getPreferenceScreen().removePreference( 360 getPreferenceScreen().removePreference(
354 preferenceScreen.findPreference(PREF_OS_PERMISSIONS_WARN ING)); 361 preferenceScreen.findPreference(PREF_OS_PERMISSIONS_WARN ING));
355 } else if (osWarningExtra.getTitle() == null) { 362 } else if (osWarningExtra.getTitle() == null) {
356 getPreferenceScreen().removePreference( 363 getPreferenceScreen().removePreference(
357 preferenceScreen.findPreference(PREF_OS_PERMISSIONS_WARN ING_EXTRA)); 364 preferenceScreen.findPreference(PREF_OS_PERMISSIONS_WARN ING_EXTRA));
358 } 365 }
359 } 366 }
360 367
368 // The subresource filter permission includes a header with some additio nal information, if
369 // it is being displayed on a site that is activated.
370 Preference extraInfo = preferenceScreen.findPreference(PREF_EXTRA_INFO);
371 Preference extraInfoDivider = preferenceScreen.findPreference(PREF_EXTRA _INFO_DIVIDER);
372 if (getPreferenceScreen().findPreference(PREF_SUBRESOURCE_FILTER_PERMISS ION) != null
373 && subresourceFilterActivated) {
374 extraInfo.setTitle(R.string.subresource_filter_permission_extra_info );
375 } else {
376 getPreferenceScreen().removePreference(extraInfo);
377 getPreferenceScreen().removePreference(extraInfoDivider);
378 }
379
361 // Remove categories if no sub-items. 380 // Remove categories if no sub-items.
362 if (!hasUsagePreferences()) { 381 if (!hasUsagePreferences()) {
363 Preference heading = preferenceScreen.findPreference(PREF_USAGE); 382 Preference heading = preferenceScreen.findPreference(PREF_USAGE);
364 preferenceScreen.removePreference(heading); 383 preferenceScreen.removePreference(heading);
365 } 384 }
366 if (!hasPermissionsPreferences()) { 385 if (!hasPermissionsPreferences()) {
367 Preference heading = preferenceScreen.findPreference(PREF_PERMISSION S); 386 Preference heading = preferenceScreen.findPreference(PREF_PERMISSION S);
368 preferenceScreen.removePreference(heading); 387 preferenceScreen.removePreference(heading);
369 } 388 }
370 } 389 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 } else if (permission == null && locationAllowed != null) { 508 } else if (permission == null && locationAllowed != null) {
490 String origin = mSite.getAddress().getOrigin(); 509 String origin = mSite.getAddress().getOrigin();
491 mSite.setGeolocationInfo(new GeolocationInfo(origin, origin, false)) ; 510 mSite.setGeolocationInfo(new GeolocationInfo(origin, origin, false)) ;
492 setUpListPreference(preference, (boolean) locationAllowed 511 setUpListPreference(preference, (boolean) locationAllowed
493 ? ContentSetting.ALLOW : ContentSetting.BLOCK); 512 ? ContentSetting.ALLOW : ContentSetting.BLOCK);
494 } else { 513 } else {
495 setUpListPreference(preference, permission); 514 setUpListPreference(preference, permission);
496 } 515 }
497 } 516 }
498 517
518 private void setUpSubresourceFilterPreference(Preference preference, boolean activated) {
Finnur 2017/05/23 15:37:13 This function has some non-obvious functionality t
Charlie Harrison 2017/05/23 17:12:19 Added a comment.
519 ContentSetting permission = mSite.getSubresourceFilterPermission();
520
521 // The subresource filter permission shows sometimes even if there is no permission set.
Finnur 2017/05/23 15:37:13 I don't understand this comment, nor it's placemen
Charlie Harrison 2017/05/23 17:12:19 It's describing how the implementation works. I've
522 if (permission == null) {
523 // If there is activation, we want the setting to show BLOCK by defa ult. Set an explicit
524 // exception on the website that isn't backed by an explicit content setting. Note that
525 // this will never trigger an actual update to content settings, as those go through
526 // setSubresourceFilterPermission.
527 if (activated) {
528 permission = ContentSetting.BLOCK;
529 String origin = mSite.getAddress().getOrigin();
530 mSite.setSubresourceFilterException(new ContentSettingException(
531 ContentSettingsType.CONTENT_SETTINGS_TYPE_SUBRESOURCE_FI LTER, origin,
532 permission, ""));
Finnur 2017/05/23 15:37:13 This feels a bit hacky... I'm a little concerned t
Charlie Harrison 2017/05/23 17:12:19 Is is necessary due to how we've implemented setSu
Finnur 2017/05/24 10:37:22 If the problem you are facing is only while changi
Charlie Harrison 2017/05/25 15:57:19 Yeah that works for me. Done.
533 } else {
534 setUpListPreference(preference, null);
535 return;
536 }
537 }
538 assert permission != null;
539 setUpListPreference(preference, permission);
540
541 // The subresource filter permission has a custom BLOCK string.
542 ListPreference listPreference = (ListPreference) preference;
543 Resources res = getResources();
544 listPreference.setEntries(
545 new String[] {res.getString(R.string.website_settings_permission s_allow),
546 res.getString(R.string.subresource_filter_permission_blo ck)});
547 listPreference.setValueIndex(permission == ContentSetting.ALLOW ? 0 : 1) ;
548 }
549
499 /** 550 /**
500 * Returns true if the current host matches the default search engine host a nd location for the 551 * Returns true if the current host matches the default search engine host a nd location for the
501 * default search engine is being granted via x-geo. 552 * default search engine is being granted via x-geo.
502 * @param context The current context. 553 * @param context The current context.
503 */ 554 */
504 private boolean hasXGeoLocationPermission(Context context) { 555 private boolean hasXGeoLocationPermission(Context context) {
505 if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEO LOCATION)) { 556 if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEO LOCATION)) {
506 return false; 557 return false;
507 } 558 }
508 559
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 if (mSite.getTotalUsage() > 0) { 774 if (mSite.getTotalUsage() > 0) {
724 clearStoredData(); 775 clearStoredData();
725 } else { 776 } else {
726 // Clearing stored data implies popping back to parent menu if there 777 // Clearing stored data implies popping back to parent menu if there
727 // is nothing left to show. Therefore, we only need to explicitly 778 // is nothing left to show. Therefore, we only need to explicitly
728 // close the activity if there's no stored data to begin with. 779 // close the activity if there's no stored data to begin with.
729 getActivity().finish(); 780 getActivity().finish();
730 } 781 }
731 } 782 }
732 } 783 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698