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.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 Loading... | |
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_SUBRESOURCE_FILTER_EXTRA_INFO = | |
68 "subresource_filter_permission_extra_info"; | |
69 public static final String PREF_SUBRESOURCE_FILTER_EXTRA_INFO_DIVIDER = | |
70 "subresource_filter_permission_extra_info_divider"; | |
67 // Actions at the top (if adding new, see hasUsagePreferences below): | 71 // Actions at the top (if adding new, see hasUsagePreferences below): |
68 public static final String PREF_CLEAR_DATA = "clear_data"; | 72 public static final String PREF_CLEAR_DATA = "clear_data"; |
69 // Buttons: | 73 // Buttons: |
70 public static final String PREF_RESET_SITE = "reset_site_button"; | 74 public static final String PREF_RESET_SITE = "reset_site_button"; |
71 // Website permissions (if adding new, see hasPermissionsPreferences and res etSite below): | 75 // Website permissions (if adding new, see hasPermissionsPreferences and res etSite below): |
72 public static final String PREF_AUTOPLAY_PERMISSION = "autoplay_permission_l ist"; | 76 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"; | 77 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"; | 78 public static final String PREF_CAMERA_CAPTURE_PERMISSION = "camera_permissi on_list"; |
75 public static final String PREF_COOKIES_PERMISSION = "cookies_permission_lis t"; | 79 public static final String PREF_COOKIES_PERMISSION = "cookies_permission_lis t"; |
76 public static final String PREF_JAVASCRIPT_PERMISSION = "javascript_permissi on_list"; | 80 public static final String PREF_JAVASCRIPT_PERMISSION = "javascript_permissi on_list"; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 && (origin.equals(info.getEmbedderSafe()) || "*".equals(info.get EmbedderSafe())); | 266 && (origin.equals(info.getEmbedderSafe()) || "*".equals(info.get EmbedderSafe())); |
263 } | 267 } |
264 | 268 |
265 /** | 269 /** |
266 * Updates the permissions displayed in the UI by fetching them from mSite. | 270 * Updates the permissions displayed in the UI by fetching them from mSite. |
267 * Must only be called once mSite is set. | 271 * Must only be called once mSite is set. |
268 */ | 272 */ |
269 private void displaySitePermissions() { | 273 private void displaySitePermissions() { |
270 addPreferencesFromResource(R.xml.single_website_preferences); | 274 addPreferencesFromResource(R.xml.single_website_preferences); |
271 | 275 |
276 // If the subresource filter is activated, then this site will have reso urces filtered | |
277 // unless there is an explicit permission disallowing the filtering. | |
278 // | |
279 // This activation is encoded in |subresourceFilterActivated|, which con trols how the | |
280 // subresource filter list preference behaves. If it is true, there is a lso an additional | |
281 // extra informational banner which shows at the top of the UI. | |
282 boolean subresourceFilterActivated = WebsitePreferenceBridge.getSubresou rceFilterActivated( | |
283 mSite.getAddress().getOrigin()); | |
284 | |
272 Set<String> permissionPreferenceKeys = | 285 Set<String> permissionPreferenceKeys = |
273 new HashSet<>(Arrays.asList(PERMISSION_PREFERENCE_KEYS)); | 286 new HashSet<>(Arrays.asList(PERMISSION_PREFERENCE_KEYS)); |
274 int maxPermissionOrder = 0; | 287 int maxPermissionOrder = 0; |
275 ListAdapter preferences = getPreferenceScreen().getRootAdapter(); | 288 ListAdapter preferences = getPreferenceScreen().getRootAdapter(); |
276 for (int i = 0; i < preferences.getCount(); ++i) { | 289 for (int i = 0; i < preferences.getCount(); ++i) { |
277 Preference preference = (Preference) preferences.getItem(i); | 290 Preference preference = (Preference) preferences.getItem(i); |
278 if (PREF_SITE_TITLE.equals(preference.getKey())) { | 291 if (PREF_SITE_TITLE.equals(preference.getKey())) { |
279 preference.setTitle(mSite.getTitle()); | 292 preference.setTitle(mSite.getTitle()); |
280 } else if (PREF_CLEAR_DATA.equals(preference.getKey())) { | 293 } else if (PREF_CLEAR_DATA.equals(preference.getKey())) { |
281 long usage = mSite.getTotalUsage(); | 294 long usage = mSite.getTotalUsage(); |
(...skipping 24 matching lines...) Expand all Loading... | |
306 setUpListPreference(preference, mSite.getMicrophonePermission()) ; | 319 setUpListPreference(preference, mSite.getMicrophonePermission()) ; |
307 } else if (PREF_MIDI_SYSEX_PERMISSION.equals(preference.getKey())) { | 320 } else if (PREF_MIDI_SYSEX_PERMISSION.equals(preference.getKey())) { |
308 setUpListPreference(preference, mSite.getMidiPermission()); | 321 setUpListPreference(preference, mSite.getMidiPermission()); |
309 } else if (PREF_NOTIFICATIONS_PERMISSION.equals(preference.getKey()) ) { | 322 } else if (PREF_NOTIFICATIONS_PERMISSION.equals(preference.getKey()) ) { |
310 setUpListPreference(preference, mSite.getNotificationPermission( )); | 323 setUpListPreference(preference, mSite.getNotificationPermission( )); |
311 } else if (PREF_POPUP_PERMISSION.equals(preference.getKey())) { | 324 } else if (PREF_POPUP_PERMISSION.equals(preference.getKey())) { |
312 setUpListPreference(preference, mSite.getPopupPermission()); | 325 setUpListPreference(preference, mSite.getPopupPermission()); |
313 } else if (PREF_PROTECTED_MEDIA_IDENTIFIER_PERMISSION.equals(prefere nce.getKey())) { | 326 } else if (PREF_PROTECTED_MEDIA_IDENTIFIER_PERMISSION.equals(prefere nce.getKey())) { |
314 setUpListPreference(preference, mSite.getProtectedMediaIdentifie rPermission()); | 327 setUpListPreference(preference, mSite.getProtectedMediaIdentifie rPermission()); |
315 } else if (PREF_SUBRESOURCE_FILTER_PERMISSION.equals(preference.getK ey())) { | 328 } else if (PREF_SUBRESOURCE_FILTER_PERMISSION.equals(preference.getK ey())) { |
316 setUpListPreference(preference, mSite.getSubresourceFilterPermis sion()); | 329 setUpSubresourceFilterPreference(preference, subresourceFilterAc tivated); |
317 } | 330 } |
318 | 331 |
319 if (permissionPreferenceKeys.contains(preference.getKey())) { | 332 if (permissionPreferenceKeys.contains(preference.getKey())) { |
320 maxPermissionOrder = Math.max(maxPermissionOrder, preference.get Order()); | 333 maxPermissionOrder = Math.max(maxPermissionOrder, preference.get Order()); |
321 } | 334 } |
322 } | 335 } |
323 | 336 |
324 for (UsbInfo info : mSite.getUsbInfo()) { | 337 for (UsbInfo info : mSite.getUsbInfo()) { |
325 Preference preference = new Preference(getActivity()); | 338 Preference preference = new Preference(getActivity()); |
326 preference.getExtras().putSerializable(EXTRA_USB_INFO, info); | 339 preference.getExtras().putSerializable(EXTRA_USB_INFO, info); |
(...skipping 24 matching lines...) Expand all Loading... | |
351 osWarning, osWarningExtra, getActivity(), false); | 364 osWarning, osWarningExtra, getActivity(), false); |
352 if (osWarning.getTitle() == null) { | 365 if (osWarning.getTitle() == null) { |
353 getPreferenceScreen().removePreference( | 366 getPreferenceScreen().removePreference( |
354 preferenceScreen.findPreference(PREF_OS_PERMISSIONS_WARN ING)); | 367 preferenceScreen.findPreference(PREF_OS_PERMISSIONS_WARN ING)); |
355 } else if (osWarningExtra.getTitle() == null) { | 368 } else if (osWarningExtra.getTitle() == null) { |
356 getPreferenceScreen().removePreference( | 369 getPreferenceScreen().removePreference( |
357 preferenceScreen.findPreference(PREF_OS_PERMISSIONS_WARN ING_EXTRA)); | 370 preferenceScreen.findPreference(PREF_OS_PERMISSIONS_WARN ING_EXTRA)); |
358 } | 371 } |
359 } | 372 } |
360 | 373 |
374 // The subresource filter permission includes a header with some additio nal information, if | |
375 // it is being displayed on a site that is activated. | |
376 Preference subresourceFilterExtraInfo = | |
377 preferenceScreen.findPreference(PREF_SUBRESOURCE_FILTER_EXTRA_IN FO); | |
378 Preference subresourceFilterExtraInfoDivider = | |
379 preferenceScreen.findPreference(PREF_SUBRESOURCE_FILTER_EXTRA_IN FO_DIVIDER); | |
380 if (getPreferenceScreen().findPreference(PREF_SUBRESOURCE_FILTER_PERMISS ION) != null | |
381 && subresourceFilterActivated) { | |
382 subresourceFilterExtraInfo.setTitle(R.string.subresource_filter_perm ission_extra_info); | |
383 } else { | |
384 getPreferenceScreen().removePreference(subresourceFilterExtraInfo); | |
385 getPreferenceScreen().removePreference(subresourceFilterExtraInfoDiv ider); | |
386 } | |
387 | |
361 // Remove categories if no sub-items. | 388 // Remove categories if no sub-items. |
362 if (!hasUsagePreferences()) { | 389 if (!hasUsagePreferences()) { |
363 Preference heading = preferenceScreen.findPreference(PREF_USAGE); | 390 Preference heading = preferenceScreen.findPreference(PREF_USAGE); |
364 preferenceScreen.removePreference(heading); | 391 preferenceScreen.removePreference(heading); |
365 } | 392 } |
366 if (!hasPermissionsPreferences()) { | 393 if (!hasPermissionsPreferences()) { |
367 Preference heading = preferenceScreen.findPreference(PREF_PERMISSION S); | 394 Preference heading = preferenceScreen.findPreference(PREF_PERMISSION S); |
368 preferenceScreen.removePreference(heading); | 395 preferenceScreen.removePreference(heading); |
369 } | 396 } |
370 } | 397 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 String origin = mSite.getAddress().getOrigin(); | 517 String origin = mSite.getAddress().getOrigin(); |
491 mSite.setGeolocationInfo(new GeolocationInfo(origin, origin, false)) ; | 518 mSite.setGeolocationInfo(new GeolocationInfo(origin, origin, false)) ; |
492 setUpListPreference(preference, (boolean) locationAllowed | 519 setUpListPreference(preference, (boolean) locationAllowed |
493 ? ContentSetting.ALLOW : ContentSetting.BLOCK); | 520 ? ContentSetting.ALLOW : ContentSetting.BLOCK); |
494 } else { | 521 } else { |
495 setUpListPreference(preference, permission); | 522 setUpListPreference(preference, permission); |
496 } | 523 } |
497 } | 524 } |
498 | 525 |
499 /** | 526 /** |
527 * Updates the subresource filter list preference based on subresource filte r activation. This | |
528 * has some custom behavior. | |
529 * 1. If the site is activated, the permission should show up even if it is set as the default | |
Finnur
2017/05/24 10:37:22
s/site/filtering/ ?
Charlie Harrison
2017/05/25 15:57:19
Done.
| |
530 * (e.g. |preference| is null). | |
531 * 2. The BLOCK string is custom. | |
532 * @param activated Whether the subresource filter is activated for this sit e (i.e. whether or | |
533 * not the site is a candidate for resource filtering). | |
534 */ | |
535 private void setUpSubresourceFilterPreference(Preference preference, boolean activated) { | |
536 ContentSetting permission = mSite.getSubresourceFilterPermission(); | |
537 | |
538 // If |permission| is null, there is no explicit (non-default) permissio n set for this site. | |
539 // If the site is activated, we still want to show the permission as BLO CK. | |
540 if (permission == null) { | |
541 if (activated) { | |
542 permission = ContentSetting.BLOCK; | |
543 | |
544 // Set the subresource filter exception on the associated websit e. This is necessary | |
545 // because we require an exception to be set in order to change content setting | |
546 // (see setSubresourceFilterPermission). Otherwise the UI will c hange but the | |
547 // underlying data will remain unchanged. | |
548 String origin = mSite.getAddress().getOrigin(); | |
549 mSite.setSubresourceFilterException(new ContentSettingException( | |
550 ContentSettingsType.CONTENT_SETTINGS_TYPE_SUBRESOURCE_FI LTER, origin, | |
551 permission, "")); | |
552 } else { | |
553 setUpListPreference(preference, null); | |
554 return; | |
555 } | |
556 } | |
557 assert permission != null; | |
558 setUpListPreference(preference, permission); | |
559 | |
560 // The subresource filter permission has a custom BLOCK string. | |
561 ListPreference listPreference = (ListPreference) preference; | |
562 Resources res = getResources(); | |
563 listPreference.setEntries( | |
564 new String[] {res.getString(R.string.website_settings_permission s_allow), | |
565 res.getString(R.string.subresource_filter_permission_blo ck)}); | |
566 listPreference.setValueIndex(permission == ContentSetting.ALLOW ? 0 : 1) ; | |
567 } | |
568 | |
569 /** | |
500 * Returns true if the current host matches the default search engine host a nd location for the | 570 * 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. | 571 * default search engine is being granted via x-geo. |
502 * @param context The current context. | 572 * @param context The current context. |
503 */ | 573 */ |
504 private boolean hasXGeoLocationPermission(Context context) { | 574 private boolean hasXGeoLocationPermission(Context context) { |
505 if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEO LOCATION)) { | 575 if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEO LOCATION)) { |
506 return false; | 576 return false; |
507 } | 577 } |
508 | 578 |
509 String searchUrl = TemplateUrlService.getInstance().getUrlForSearchQuery ("foo"); | 579 String searchUrl = TemplateUrlService.getInstance().getUrlForSearchQuery ("foo"); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
723 if (mSite.getTotalUsage() > 0) { | 793 if (mSite.getTotalUsage() > 0) { |
724 clearStoredData(); | 794 clearStoredData(); |
725 } else { | 795 } else { |
726 // Clearing stored data implies popping back to parent menu if there | 796 // Clearing stored data implies popping back to parent menu if there |
727 // is nothing left to show. Therefore, we only need to explicitly | 797 // is nothing left to show. Therefore, we only need to explicitly |
728 // close the activity if there's no stored data to begin with. | 798 // close the activity if there's no stored data to begin with. |
729 getActivity().finish(); | 799 getActivity().finish(); |
730 } | 800 } |
731 } | 801 } |
732 } | 802 } |
OLD | NEW |