Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 869 content_settings::ContentSettingToString(default_setting); | 869 content_settings::ContentSettingToString(default_setting); |
| 870 DCHECK(!setting_string.empty()); | 870 DCHECK(!setting_string.empty()); |
| 871 | 871 |
| 872 filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value", | 872 filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value", |
| 873 setting_string); | 873 setting_string); |
| 874 filter_settings.SetString( | 874 filter_settings.SetString( |
| 875 ContentSettingsTypeToGroupName(type) + ".managedBy", provider_id); | 875 ContentSettingsTypeToGroupName(type) + ".managedBy", provider_id); |
| 876 | 876 |
| 877 web_ui()->CallJavascriptFunction( | 877 web_ui()->CallJavascriptFunction( |
| 878 "ContentSettings.setContentFilterSettingsValue", filter_settings); | 878 "ContentSettings.setContentFilterSettingsValue", filter_settings); |
| 879 | |
| 880 // The special cases covered agive to get |provider_id| are not handled in | |
|
Bernhard Bauer
2016/04/07 15:30:13
"agive" seems like a typo, and I can't make out wh
huangs
2016/04/07 21:44:06
Fixed ("agive" => "above").
Bernhard Bauer
2016/04/08 14:44:35
Oh, that makes sense (and it's not that far apart
huangs
2016/04/11 19:01:03
Acknowledged. :)
| |
| 881 // GetMaybeEnablePrefExceptionsForType(). | |
| 882 bool maybe_enable_exceptions = | |
| 883 GetContentSettingsMap()->GetMaybeEnablePrefExceptionsForType(type); | |
| 884 | |
| 885 web_ui()->CallJavascriptFunction( | |
| 886 "ContentSettings.setAllowEnablePrefExceptions", | |
| 887 base::StringValue(ContentSettingsTypeToGroupName(type)), | |
| 888 base::FundamentalValue(maybe_enable_exceptions)); | |
| 879 } | 889 } |
| 880 | 890 |
| 881 void ContentSettingsHandler::UpdateMediaSettingsFromPrefs( | 891 void ContentSettingsHandler::UpdateMediaSettingsFromPrefs( |
| 882 ContentSettingsType type) { | 892 ContentSettingsType type) { |
| 883 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); | 893 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); |
| 884 MediaSettingsInfo::ForOneType& settings = media_settings_->forType(type); | 894 MediaSettingsInfo::ForOneType& settings = media_settings_->forType(type); |
| 885 std::string policy_pref = (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) | 895 std::string policy_pref = (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) |
| 886 ? prefs::kAudioCaptureAllowed | 896 ? prefs::kAudioCaptureAllowed |
| 887 : prefs::kVideoCaptureAllowed; | 897 : prefs::kVideoCaptureAllowed; |
| 888 | 898 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 954 std::string(), | 964 std::string(), |
| 955 &all_settings); | 965 &all_settings); |
| 956 | 966 |
| 957 // Group geolocation settings by primary_pattern. | 967 // Group geolocation settings by primary_pattern. |
| 958 site_settings::AllPatternsSettings all_patterns_settings; | 968 site_settings::AllPatternsSettings all_patterns_settings; |
| 959 for (ContentSettingsForOneType::iterator i = all_settings.begin(); | 969 for (ContentSettingsForOneType::iterator i = all_settings.begin(); |
| 960 i != all_settings.end(); ++i) { | 970 i != all_settings.end(); ++i) { |
| 961 // Don't add default settings. | 971 // Don't add default settings. |
| 962 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && | 972 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && |
| 963 i->secondary_pattern == ContentSettingsPattern::Wildcard() && | 973 i->secondary_pattern == ContentSettingsPattern::Wildcard() && |
| 964 i | 974 i->source != site_settings::kPreferencesSource) { |
| 965 ->source != site_settings::kPreferencesSource) { | |
| 966 continue; | 975 continue; |
| 967 } | 976 } |
| 968 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)] | 977 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)] |
| 969 [i->secondary_pattern] = i->setting; | 978 [i->secondary_pattern] = i->setting; |
| 970 } | 979 } |
| 971 | 980 |
| 972 base::ListValue exceptions; | 981 base::ListValue exceptions; |
| 973 AddExceptionsGrantedByHostedApps( | 982 AddExceptionsGrantedByHostedApps( |
| 974 profile, | 983 profile, |
| 975 HostedAppHasPermission<APIPermission::kGeolocation>, | 984 HostedAppHasPermission<APIPermission::kGeolocation>, |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1466 const ExceptionsInfoMap& exceptions_info_map = GetExceptionsInfoMap(); | 1475 const ExceptionsInfoMap& exceptions_info_map = GetExceptionsInfoMap(); |
| 1467 const auto& it = exceptions_info_map.find(content_type); | 1476 const auto& it = exceptions_info_map.find(content_type); |
| 1468 if (it != exceptions_info_map.end()) | 1477 if (it != exceptions_info_map.end()) |
| 1469 content::RecordAction(it->second.uma); | 1478 content::RecordAction(it->second.uma); |
| 1470 } | 1479 } |
| 1471 | 1480 |
| 1472 void ContentSettingsHandler::RemoveException(const base::ListValue* args) { | 1481 void ContentSettingsHandler::RemoveException(const base::ListValue* args) { |
| 1473 std::string type_string; | 1482 std::string type_string; |
| 1474 CHECK(args->GetString(0, &type_string)); | 1483 CHECK(args->GetString(0, &type_string)); |
| 1475 | 1484 |
| 1485 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | |
| 1486 | |
| 1487 // If preference exceptions are disabled for |type|, don't remove. | |
| 1488 if (!GetContentSettingsMap()->GetMaybeEnablePrefExceptionsForType(type)) | |
| 1489 return; | |
| 1490 | |
| 1476 // Zoom levels are no actual content type so we need to handle them | 1491 // Zoom levels are no actual content type so we need to handle them |
| 1477 // separately. They would not be recognized by | 1492 // separately. They would not be recognized by |
| 1478 // ContentSettingsTypeFromGroupName. | 1493 // ContentSettingsTypeFromGroupName. |
| 1479 if (type_string == kZoomContentType) { | 1494 if (type_string == kZoomContentType) { |
| 1480 RemoveZoomLevelException(args); | 1495 RemoveZoomLevelException(args); |
| 1481 return; | 1496 return; |
| 1482 } | 1497 } |
| 1483 | 1498 |
| 1484 const ChooserTypeNameEntry* chooser_type = | 1499 const ChooserTypeNameEntry* chooser_type = |
| 1485 ChooserTypeFromGroupName(type_string); | 1500 ChooserTypeFromGroupName(type_string); |
| 1486 if (chooser_type) { | 1501 if (chooser_type) { |
| 1487 RemoveChooserException(chooser_type, args); | 1502 RemoveChooserException(chooser_type, args); |
| 1488 return; | 1503 return; |
| 1489 } | 1504 } |
| 1490 | 1505 |
| 1491 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | |
| 1492 RemoveExceptionFromHostContentSettingsMap(args, type); | 1506 RemoveExceptionFromHostContentSettingsMap(args, type); |
| 1493 | 1507 |
| 1494 WebSiteSettingsUmaUtil::LogPermissionChange( | 1508 WebSiteSettingsUmaUtil::LogPermissionChange( |
| 1495 type, ContentSetting::CONTENT_SETTING_DEFAULT); | 1509 type, ContentSetting::CONTENT_SETTING_DEFAULT); |
| 1496 } | 1510 } |
| 1497 | 1511 |
| 1498 void ContentSettingsHandler::SetException(const base::ListValue* args) { | 1512 void ContentSettingsHandler::SetException(const base::ListValue* args) { |
| 1499 std::string type_string; | 1513 std::string type_string; |
| 1500 CHECK(args->GetString(0, &type_string)); | 1514 CHECK(args->GetString(0, &type_string)); |
| 1501 std::string mode; | 1515 std::string mode; |
| 1502 CHECK(args->GetString(1, &mode)); | 1516 CHECK(args->GetString(1, &mode)); |
| 1503 std::string pattern; | 1517 std::string pattern; |
| 1504 CHECK(args->GetString(2, &pattern)); | 1518 CHECK(args->GetString(2, &pattern)); |
| 1505 std::string setting; | 1519 std::string setting; |
| 1506 CHECK(args->GetString(3, &setting)); | 1520 CHECK(args->GetString(3, &setting)); |
| 1507 | 1521 |
| 1508 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 1522 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); |
| 1509 | 1523 |
| 1510 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || | 1524 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || |
| 1511 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 1525 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 1512 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 1526 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| 1513 NOTREACHED(); | 1527 NOTREACHED(); |
| 1514 } else { | 1528 } else { |
| 1529 // If preference exceptions are disabled for |type|, don't set. | |
| 1530 if (!GetContentSettingsMap()->GetMaybeEnablePrefExceptionsForType(type)) | |
| 1531 return; | |
| 1532 | |
| 1515 HostContentSettingsMap* settings_map = | 1533 HostContentSettingsMap* settings_map = |
| 1516 mode == "normal" ? GetContentSettingsMap() : | 1534 mode == "normal" ? GetContentSettingsMap() : |
| 1517 GetOTRContentSettingsMap(); | 1535 GetOTRContentSettingsMap(); |
| 1518 | 1536 |
| 1519 // The settings map could be null if the mode was OTR but the OTR profile | 1537 // The settings map could be null if the mode was OTR but the OTR profile |
| 1520 // got destroyed before we received this message. | 1538 // got destroyed before we received this message. |
| 1521 if (!settings_map) | 1539 if (!settings_map) |
| 1522 return; | 1540 return; |
| 1523 | 1541 |
| 1524 ContentSetting setting_type; | 1542 ContentSetting setting_type; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| OLD | NEW |