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

Side by Side Diff: chrome/browser/ui/webui/options/content_settings_handler.cc

Issue 1855393006: [Chrome Settings UI] If User Exceptions are not allowed, prevent editing / viewing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Making ExceptionsList.allowEdit_ a private member. Created 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/webui/options/content_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/content_settings_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 content_settings::ContentSettingToString(default_setting); 871 content_settings::ContentSettingToString(default_setting);
872 DCHECK(!setting_string.empty()); 872 DCHECK(!setting_string.empty());
873 873
874 filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value", 874 filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value",
875 setting_string); 875 setting_string);
876 filter_settings.SetString( 876 filter_settings.SetString(
877 ContentSettingsTypeToGroupName(type) + ".managedBy", provider_id); 877 ContentSettingsTypeToGroupName(type) + ".managedBy", provider_id);
878 878
879 web_ui()->CallJavascriptFunction( 879 web_ui()->CallJavascriptFunction(
880 "ContentSettings.setContentFilterSettingsValue", filter_settings); 880 "ContentSettings.setContentFilterSettingsValue", filter_settings);
881
882 // We assume that special cases covered above to get |provider_id| are not
883 // needed in AreUserExceptionsAllowedForType().
884 bool maybe_enable_exceptions =
885 GetContentSettingsMap()->AreUserExceptionsAllowedForType(type);
886
887 web_ui()->CallJavascriptFunction(
888 "ContentSettings.setUserExceptionsAllowed",
889 base::StringValue(ContentSettingsTypeToGroupName(type)),
890 base::FundamentalValue(maybe_enable_exceptions));
881 } 891 }
882 892
883 void ContentSettingsHandler::UpdateMediaSettingsFromPrefs( 893 void ContentSettingsHandler::UpdateMediaSettingsFromPrefs(
884 ContentSettingsType type) { 894 ContentSettingsType type) {
885 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); 895 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui()));
886 MediaSettingsInfo::ForOneType& settings = media_settings_->forType(type); 896 MediaSettingsInfo::ForOneType& settings = media_settings_->forType(type);
887 std::string policy_pref = (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) 897 std::string policy_pref = (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)
888 ? prefs::kAudioCaptureAllowed 898 ? prefs::kAudioCaptureAllowed
889 : prefs::kVideoCaptureAllowed; 899 : prefs::kVideoCaptureAllowed;
890 900
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 std::string(), 966 std::string(),
957 &all_settings); 967 &all_settings);
958 968
959 // Group geolocation settings by primary_pattern. 969 // Group geolocation settings by primary_pattern.
960 site_settings::AllPatternsSettings all_patterns_settings; 970 site_settings::AllPatternsSettings all_patterns_settings;
961 for (ContentSettingsForOneType::iterator i = all_settings.begin(); 971 for (ContentSettingsForOneType::iterator i = all_settings.begin();
962 i != all_settings.end(); ++i) { 972 i != all_settings.end(); ++i) {
963 // Don't add default settings. 973 // Don't add default settings.
964 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && 974 if (i->primary_pattern == ContentSettingsPattern::Wildcard() &&
965 i->secondary_pattern == ContentSettingsPattern::Wildcard() && 975 i->secondary_pattern == ContentSettingsPattern::Wildcard() &&
966 i 976 i->source != site_settings::kPreferencesSource) {
967 ->source != site_settings::kPreferencesSource) {
968 continue; 977 continue;
969 } 978 }
970 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)] 979 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)]
971 [i->secondary_pattern] = i->setting; 980 [i->secondary_pattern] = i->setting;
972 } 981 }
973 982
974 base::ListValue exceptions; 983 base::ListValue exceptions;
975 AddExceptionsGrantedByHostedApps( 984 AddExceptionsGrantedByHostedApps(
976 profile, 985 profile,
977 HostedAppHasPermission<APIPermission::kGeolocation>, 986 HostedAppHasPermission<APIPermission::kGeolocation>,
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 const ExceptionsInfoMap& exceptions_info_map = GetExceptionsInfoMap(); 1477 const ExceptionsInfoMap& exceptions_info_map = GetExceptionsInfoMap();
1469 const auto& it = exceptions_info_map.find(content_type); 1478 const auto& it = exceptions_info_map.find(content_type);
1470 if (it != exceptions_info_map.end()) 1479 if (it != exceptions_info_map.end())
1471 content::RecordAction(it->second.uma); 1480 content::RecordAction(it->second.uma);
1472 } 1481 }
1473 1482
1474 void ContentSettingsHandler::RemoveException(const base::ListValue* args) { 1483 void ContentSettingsHandler::RemoveException(const base::ListValue* args) {
1475 std::string type_string; 1484 std::string type_string;
1476 CHECK(args->GetString(0, &type_string)); 1485 CHECK(args->GetString(0, &type_string));
1477 1486
1487 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string);
1488
1489 // If user exceptions are disabled for |type|, don't remove.
1490 if (!GetContentSettingsMap()->AreUserExceptionsAllowedForType(type))
1491 return;
1492
1478 // Zoom levels are no actual content type so we need to handle them 1493 // Zoom levels are no actual content type so we need to handle them
1479 // separately. They would not be recognized by 1494 // separately. They would not be recognized by
1480 // ContentSettingsTypeFromGroupName. 1495 // ContentSettingsTypeFromGroupName.
1481 if (type_string == kZoomContentType) { 1496 if (type_string == kZoomContentType) {
1482 RemoveZoomLevelException(args); 1497 RemoveZoomLevelException(args);
1483 return; 1498 return;
1484 } 1499 }
1485 1500
1486 const ChooserTypeNameEntry* chooser_type = 1501 const ChooserTypeNameEntry* chooser_type =
1487 ChooserTypeFromGroupName(type_string); 1502 ChooserTypeFromGroupName(type_string);
1488 if (chooser_type) { 1503 if (chooser_type) {
1489 RemoveChooserException(chooser_type, args); 1504 RemoveChooserException(chooser_type, args);
1490 return; 1505 return;
1491 } 1506 }
1492 1507
1493 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string);
1494 RemoveExceptionFromHostContentSettingsMap(args, type); 1508 RemoveExceptionFromHostContentSettingsMap(args, type);
1495 1509
1496 WebSiteSettingsUmaUtil::LogPermissionChange( 1510 WebSiteSettingsUmaUtil::LogPermissionChange(
1497 type, ContentSetting::CONTENT_SETTING_DEFAULT); 1511 type, ContentSetting::CONTENT_SETTING_DEFAULT);
1498 } 1512 }
1499 1513
1500 void ContentSettingsHandler::SetException(const base::ListValue* args) { 1514 void ContentSettingsHandler::SetException(const base::ListValue* args) {
1501 std::string type_string; 1515 std::string type_string;
1502 CHECK(args->GetString(0, &type_string)); 1516 CHECK(args->GetString(0, &type_string));
1503 std::string mode; 1517 std::string mode;
1504 CHECK(args->GetString(1, &mode)); 1518 CHECK(args->GetString(1, &mode));
1505 std::string pattern; 1519 std::string pattern;
1506 CHECK(args->GetString(2, &pattern)); 1520 CHECK(args->GetString(2, &pattern));
1507 std::string setting; 1521 std::string setting;
1508 CHECK(args->GetString(3, &setting)); 1522 CHECK(args->GetString(3, &setting));
1509 1523
1510 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); 1524 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string);
1511 1525
1512 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || 1526 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION ||
1513 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || 1527 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC ||
1514 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { 1528 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
1515 NOTREACHED(); 1529 NOTREACHED();
1516 } else { 1530 } else {
1531 // If user exceptions are disabled for |type|, don't set.
1532 if (!GetContentSettingsMap()->AreUserExceptionsAllowedForType(type))
1533 return;
1534
1517 HostContentSettingsMap* settings_map = 1535 HostContentSettingsMap* settings_map =
1518 mode == "normal" ? GetContentSettingsMap() : 1536 mode == "normal" ? GetContentSettingsMap() :
1519 GetOTRContentSettingsMap(); 1537 GetOTRContentSettingsMap();
1520 1538
1521 // The settings map could be null if the mode was OTR but the OTR profile 1539 // The settings map could be null if the mode was OTR but the OTR profile
1522 // got destroyed before we received this message. 1540 // got destroyed before we received this message.
1523 if (!settings_map) 1541 if (!settings_map)
1524 return; 1542 return;
1525 1543
1526 ContentSetting setting_type; 1544 ContentSetting setting_type;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 1723
1706 // Exceptions apply only when the feature is enabled. 1724 // Exceptions apply only when the feature is enabled.
1707 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); 1725 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui()));
1708 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); 1726 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM);
1709 web_ui()->CallJavascriptFunction( 1727 web_ui()->CallJavascriptFunction(
1710 "ContentSettings.enableProtectedContentExceptions", 1728 "ContentSettings.enableProtectedContentExceptions",
1711 base::FundamentalValue(enable_exceptions)); 1729 base::FundamentalValue(enable_exceptions));
1712 } 1730 }
1713 1731
1714 } // namespace options 1732 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/content_settings_exceptions_area.js ('k') | ui/webui/resources/js/cr/ui/array_data_model.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698