Chromium Code Reviews| 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_EXTRA_INFO = "website_settings_extra_info"; | |
| 68 public static final String PREF_EXTRA_INFO_DIVIDER = "website_settings_extra _info_divider"; | |
| 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 Loading... | |
| 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. | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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) { | |
| 519 ContentSetting permission = mSite.getSubresourceFilterPermission(); | |
| 520 | |
| 521 // The subresource filter permission shows sometimes even if there is no permission set. | |
| 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, "")); | |
| 533 } else { | |
| 534 setUpListPreference(preference, null); | |
| 535 return; | |
| 536 } | |
| 537 } | |
| 538 assert permission != null; | |
| 539 setUpListPreference(preference, permission); | |
| 540 | |
| 541 // The list preference needs custom strings depending on activation stat e. | |
| 542 int blockString = activated ? R.string.subresource_filter_permission_blo ck_active | |
| 543 : R.string.subresource_filter_permission_blo ck_passive; | |
| 544 int allowString = activated ? R.string.subresource_filter_permission_all ow_active | |
| 545 : R.string.website_settings_permissions_allo w; | |
|
raymes
2017/05/17 00:07:43
nit: Not sure if we need to base this on whether i
Charlie Harrison
2017/05/17 00:38:52
Ah you're right that's my mistake. We don't need t
| |
| 546 ListPreference listPreference = (ListPreference) preference; | |
| 547 Resources res = getResources(); | |
| 548 listPreference.setEntries( | |
| 549 new String[] {res.getString(allowString), res.getString(blockStr ing)}); | |
| 550 listPreference.setValueIndex(permission == ContentSetting.ALLOW ? 0 : 1) ; | |
| 551 } | |
| 552 | |
| 499 /** | 553 /** |
| 500 * Returns true if the current host matches the default search engine host a nd location for the | 554 * 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. | 555 * default search engine is being granted via x-geo. |
| 502 * @param context The current context. | 556 * @param context The current context. |
| 503 */ | 557 */ |
| 504 private boolean hasXGeoLocationPermission(Context context) { | 558 private boolean hasXGeoLocationPermission(Context context) { |
| 505 if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEO LOCATION)) { | 559 if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEO LOCATION)) { |
| 506 return false; | 560 return false; |
| 507 } | 561 } |
| 508 | 562 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 723 if (mSite.getTotalUsage() > 0) { | 777 if (mSite.getTotalUsage() > 0) { |
| 724 clearStoredData(); | 778 clearStoredData(); |
| 725 } else { | 779 } else { |
| 726 // Clearing stored data implies popping back to parent menu if there | 780 // Clearing stored data implies popping back to parent menu if there |
| 727 // is nothing left to show. Therefore, we only need to explicitly | 781 // is nothing left to show. Therefore, we only need to explicitly |
| 728 // close the activity if there's no stored data to begin with. | 782 // close the activity if there's no stored data to begin with. |
| 729 getActivity().finish(); | 783 getActivity().finish(); |
| 730 } | 784 } |
| 731 } | 785 } |
| 732 } | 786 } |
| OLD | NEW |