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 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 ++j) { | 869 ++j) { |
870 // Skip the non-embedded setting which we already added above. | 870 // Skip the non-embedded setting which we already added above. |
871 if (j == parent) | 871 if (j == parent) |
872 continue; | 872 continue; |
873 | 873 |
874 exceptions.Append(GetGeolocationExceptionForPage( | 874 exceptions.Append(GetGeolocationExceptionForPage( |
875 primary_pattern, j->first, j->second)); | 875 primary_pattern, j->first, j->second)); |
876 } | 876 } |
877 } | 877 } |
878 | 878 |
879 base::StringValue type_string(site_settings::ContentSettingsTypeToGroupName( | 879 base::Value type_string(site_settings::ContentSettingsTypeToGroupName( |
880 CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 880 CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
881 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", | 881 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", |
882 type_string, exceptions); | 882 type_string, exceptions); |
883 | 883 |
884 // This is mainly here to keep this function ideologically parallel to | 884 // This is mainly here to keep this function ideologically parallel to |
885 // UpdateExceptionsViewFromHostContentSettingsMap(). | 885 // UpdateExceptionsViewFromHostContentSettingsMap(). |
886 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 886 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
887 } | 887 } |
888 | 888 |
889 void ContentSettingsHandler::UpdateNotificationExceptionsView() { | 889 void ContentSettingsHandler::UpdateNotificationExceptionsView() { |
(...skipping 19 matching lines...) Expand all Loading... |
909 continue; | 909 continue; |
910 } | 910 } |
911 | 911 |
912 exceptions.Append( | 912 exceptions.Append( |
913 GetNotificationExceptionForPage(i->primary_pattern, | 913 GetNotificationExceptionForPage(i->primary_pattern, |
914 i->secondary_pattern, | 914 i->secondary_pattern, |
915 i->setting, | 915 i->setting, |
916 i->source)); | 916 i->source)); |
917 } | 917 } |
918 | 918 |
919 base::StringValue type_string(site_settings::ContentSettingsTypeToGroupName( | 919 base::Value type_string(site_settings::ContentSettingsTypeToGroupName( |
920 CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 920 CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
921 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", | 921 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", |
922 type_string, exceptions); | 922 type_string, exceptions); |
923 | 923 |
924 // This is mainly here to keep this function ideologically parallel to | 924 // This is mainly here to keep this function ideologically parallel to |
925 // UpdateExceptionsViewFromHostContentSettingsMap(). | 925 // UpdateExceptionsViewFromHostContentSettingsMap(). |
926 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 926 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
927 } | 927 } |
928 | 928 |
929 void ContentSettingsHandler::CompareMediaExceptionsWithFlash( | 929 void ContentSettingsHandler::CompareMediaExceptionsWithFlash( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 for (const site_settings::ChooserTypeNameEntry& chooser_type : | 983 for (const site_settings::ChooserTypeNameEntry& chooser_type : |
984 site_settings::kChooserTypeGroupNames) | 984 site_settings::kChooserTypeGroupNames) |
985 UpdateOTRChooserExceptionsViewFromModel(chooser_type); | 985 UpdateOTRChooserExceptionsViewFromModel(chooser_type); |
986 } | 986 } |
987 | 987 |
988 void ContentSettingsHandler::UpdateChooserExceptionsViewFromModel( | 988 void ContentSettingsHandler::UpdateChooserExceptionsViewFromModel( |
989 const site_settings::ChooserTypeNameEntry& chooser_type) { | 989 const site_settings::ChooserTypeNameEntry& chooser_type) { |
990 base::ListValue exceptions; | 990 base::ListValue exceptions; |
991 site_settings::GetChooserExceptionsFromProfile( | 991 site_settings::GetChooserExceptionsFromProfile( |
992 Profile::FromWebUI(web_ui()), false, chooser_type, &exceptions); | 992 Profile::FromWebUI(web_ui()), false, chooser_type, &exceptions); |
993 base::StringValue type_string(chooser_type.name); | 993 base::Value type_string(chooser_type.name); |
994 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", | 994 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", |
995 type_string, exceptions); | 995 type_string, exceptions); |
996 | 996 |
997 UpdateOTRChooserExceptionsViewFromModel(chooser_type); | 997 UpdateOTRChooserExceptionsViewFromModel(chooser_type); |
998 } | 998 } |
999 | 999 |
1000 void ContentSettingsHandler::UpdateOTRChooserExceptionsViewFromModel( | 1000 void ContentSettingsHandler::UpdateOTRChooserExceptionsViewFromModel( |
1001 const site_settings::ChooserTypeNameEntry& chooser_type) { | 1001 const site_settings::ChooserTypeNameEntry& chooser_type) { |
1002 if (!Profile::FromWebUI(web_ui())->HasOffTheRecordProfile()) | 1002 if (!Profile::FromWebUI(web_ui())->HasOffTheRecordProfile()) |
1003 return; | 1003 return; |
1004 | 1004 |
1005 base::ListValue exceptions; | 1005 base::ListValue exceptions; |
1006 site_settings::GetChooserExceptionsFromProfile( | 1006 site_settings::GetChooserExceptionsFromProfile( |
1007 Profile::FromWebUI(web_ui()), true, chooser_type, &exceptions); | 1007 Profile::FromWebUI(web_ui()), true, chooser_type, &exceptions); |
1008 base::StringValue type_string(chooser_type.name); | 1008 base::Value type_string(chooser_type.name); |
1009 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setOTRExceptions", | 1009 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setOTRExceptions", |
1010 type_string, exceptions); | 1010 type_string, exceptions); |
1011 } | 1011 } |
1012 | 1012 |
1013 void ContentSettingsHandler::UpdateZoomLevelsExceptionsView() { | 1013 void ContentSettingsHandler::UpdateZoomLevelsExceptionsView() { |
1014 base::ListValue zoom_levels_exceptions; | 1014 base::ListValue zoom_levels_exceptions; |
1015 | 1015 |
1016 content::HostZoomMap* host_zoom_map = | 1016 content::HostZoomMap* host_zoom_map = |
1017 content::HostZoomMap::GetDefaultForBrowserContext( | 1017 content::HostZoomMap::GetDefaultForBrowserContext( |
1018 GetBrowserContext(web_ui())); | 1018 GetBrowserContext(web_ui())); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 // number. | 1063 // number. |
1064 int zoom_percent = static_cast<int>( | 1064 int zoom_percent = static_cast<int>( |
1065 content::ZoomLevelToZoomFactor(i->zoom_level) * 100 + 0.5); | 1065 content::ZoomLevelToZoomFactor(i->zoom_level) * 100 + 0.5); |
1066 exception->SetString(kZoom, base::FormatPercent(zoom_percent)); | 1066 exception->SetString(kZoom, base::FormatPercent(zoom_percent)); |
1067 exception->SetString( | 1067 exception->SetString( |
1068 site_settings::kSource, site_settings::kPreferencesSource); | 1068 site_settings::kSource, site_settings::kPreferencesSource); |
1069 // Append the new entry to the list and map. | 1069 // Append the new entry to the list and map. |
1070 zoom_levels_exceptions.Append(std::move(exception)); | 1070 zoom_levels_exceptions.Append(std::move(exception)); |
1071 } | 1071 } |
1072 | 1072 |
1073 base::StringValue type_string(kZoomContentType); | 1073 base::Value type_string(kZoomContentType); |
1074 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", | 1074 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", |
1075 type_string, zoom_levels_exceptions); | 1075 type_string, zoom_levels_exceptions); |
1076 } | 1076 } |
1077 | 1077 |
1078 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( | 1078 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( |
1079 ContentSettingsType type) { | 1079 ContentSettingsType type) { |
1080 base::ListValue exceptions; | 1080 base::ListValue exceptions; |
1081 HostContentSettingsMap* settings_map = | 1081 HostContentSettingsMap* settings_map = |
1082 HostContentSettingsMapFactory::GetForProfile(GetProfile()); | 1082 HostContentSettingsMapFactory::GetForProfile(GetProfile()); |
1083 const auto* extension_registry = | 1083 const auto* extension_registry = |
1084 extensions::ExtensionRegistry::Get(GetProfile()); | 1084 extensions::ExtensionRegistry::Get(GetProfile()); |
1085 site_settings::GetExceptionsFromHostContentSettingsMap( | 1085 site_settings::GetExceptionsFromHostContentSettingsMap( |
1086 settings_map, type, extension_registry, web_ui(), /*incognito=*/false, | 1086 settings_map, type, extension_registry, web_ui(), /*incognito=*/false, |
1087 /*filter=*/nullptr, &exceptions); | 1087 /*filter=*/nullptr, &exceptions); |
1088 base::StringValue type_string( | 1088 base::Value type_string(site_settings::ContentSettingsTypeToGroupName(type)); |
1089 site_settings::ContentSettingsTypeToGroupName(type)); | |
1090 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", | 1089 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", |
1091 type_string, exceptions); | 1090 type_string, exceptions); |
1092 | 1091 |
1093 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); | 1092 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); |
1094 | 1093 |
1095 #if defined(OS_CHROMEOS) | 1094 #if defined(OS_CHROMEOS) |
1096 // Also the default for protected contents is managed in another place. | 1095 // Also the default for protected contents is managed in another place. |
1097 if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) | 1096 if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) |
1098 return; | 1097 return; |
1099 #endif | 1098 #endif |
1100 | 1099 |
1101 // The default may also have changed (we won't get a separate notification). | 1100 // The default may also have changed (we won't get a separate notification). |
1102 // If it hasn't changed, this call will be harmless. | 1101 // If it hasn't changed, this call will be harmless. |
1103 UpdateSettingDefaultFromModel(type); | 1102 UpdateSettingDefaultFromModel(type); |
1104 } | 1103 } |
1105 | 1104 |
1106 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( | 1105 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( |
1107 ContentSettingsType type) { | 1106 ContentSettingsType type) { |
1108 const HostContentSettingsMap* otr_settings_map = | 1107 const HostContentSettingsMap* otr_settings_map = |
1109 HostContentSettingsMapFactory::GetForProfile(GetOTRProfile()); | 1108 HostContentSettingsMapFactory::GetForProfile(GetOTRProfile()); |
1110 if (!otr_settings_map) | 1109 if (!otr_settings_map) |
1111 return; | 1110 return; |
1112 const auto* extension_registry = | 1111 const auto* extension_registry = |
1113 extensions::ExtensionRegistry::Get(GetOTRProfile()); | 1112 extensions::ExtensionRegistry::Get(GetOTRProfile()); |
1114 base::ListValue exceptions; | 1113 base::ListValue exceptions; |
1115 site_settings::GetExceptionsFromHostContentSettingsMap( | 1114 site_settings::GetExceptionsFromHostContentSettingsMap( |
1116 otr_settings_map, type, extension_registry, web_ui(), /*incognito=*/true, | 1115 otr_settings_map, type, extension_registry, web_ui(), /*incognito=*/true, |
1117 /*filter=*/nullptr, &exceptions); | 1116 /*filter=*/nullptr, &exceptions); |
1118 base::StringValue type_string( | 1117 base::Value type_string(site_settings::ContentSettingsTypeToGroupName(type)); |
1119 site_settings::ContentSettingsTypeToGroupName(type)); | |
1120 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setOTRExceptions", | 1118 web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setOTRExceptions", |
1121 type_string, exceptions); | 1119 type_string, exceptions); |
1122 } | 1120 } |
1123 | 1121 |
1124 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( | 1122 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( |
1125 const base::ListValue* args, | 1123 const base::ListValue* args, |
1126 ContentSettingsType type) { | 1124 ContentSettingsType type) { |
1127 std::string mode; | 1125 std::string mode; |
1128 bool rv = args->GetString(1, &mode); | 1126 bool rv = args->GetString(1, &mode); |
1129 DCHECK(rv); | 1127 DCHECK(rv); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 CHECK(args->GetString(0, &type_string)); | 1341 CHECK(args->GetString(0, &type_string)); |
1344 std::string mode_string; | 1342 std::string mode_string; |
1345 CHECK(args->GetString(1, &mode_string)); | 1343 CHECK(args->GetString(1, &mode_string)); |
1346 std::string pattern_string; | 1344 std::string pattern_string; |
1347 CHECK(args->GetString(2, &pattern_string)); | 1345 CHECK(args->GetString(2, &pattern_string)); |
1348 | 1346 |
1349 ContentSettingsPattern pattern = | 1347 ContentSettingsPattern pattern = |
1350 ContentSettingsPattern::FromString(pattern_string); | 1348 ContentSettingsPattern::FromString(pattern_string); |
1351 | 1349 |
1352 web_ui()->CallJavascriptFunctionUnsafe( | 1350 web_ui()->CallJavascriptFunctionUnsafe( |
1353 "ContentSettings.patternValidityCheckComplete", | 1351 "ContentSettings.patternValidityCheckComplete", base::Value(type_string), |
1354 base::StringValue(type_string), base::StringValue(mode_string), | 1352 base::Value(mode_string), base::Value(pattern_string), |
1355 base::StringValue(pattern_string), base::Value(pattern.IsValid())); | 1353 base::Value(pattern.IsValid())); |
1356 } | 1354 } |
1357 | 1355 |
1358 Profile* ContentSettingsHandler::GetProfile() { | 1356 Profile* ContentSettingsHandler::GetProfile() { |
1359 return Profile::FromWebUI(web_ui()); | 1357 return Profile::FromWebUI(web_ui()); |
1360 } | 1358 } |
1361 | 1359 |
1362 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { | 1360 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { |
1363 return ProtocolHandlerRegistryFactory::GetForBrowserContext( | 1361 return ProtocolHandlerRegistryFactory::GetForBrowserContext( |
1364 GetBrowserContext(web_ui())); | 1362 GetBrowserContext(web_ui())); |
1365 } | 1363 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 MediaSettingsInfo::ForOneType& settings = | 1404 MediaSettingsInfo::ForOneType& settings = |
1407 media_settings_->forType(content_type); | 1405 media_settings_->forType(content_type); |
1408 | 1406 |
1409 bool& show_link = link_type == DEFAULT_SETTING ? | 1407 bool& show_link = link_type == DEFAULT_SETTING ? |
1410 settings.show_flash_default_link : | 1408 settings.show_flash_default_link : |
1411 settings.show_flash_exceptions_link; | 1409 settings.show_flash_exceptions_link; |
1412 | 1410 |
1413 if (show_link != show) { | 1411 if (show_link != show) { |
1414 web_ui()->CallJavascriptFunctionUnsafe( | 1412 web_ui()->CallJavascriptFunctionUnsafe( |
1415 "ContentSettings.showMediaPepperFlashLink", | 1413 "ContentSettings.showMediaPepperFlashLink", |
1416 base::StringValue(link_type == DEFAULT_SETTING ? "default" | 1414 base::Value(link_type == DEFAULT_SETTING ? "default" : "exceptions"), |
1417 : "exceptions"), | 1415 base::Value(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC |
1418 base::StringValue(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | 1416 ? "mic" |
1419 ? "mic" | 1417 : "camera"), |
1420 : "camera"), | |
1421 base::Value(show)); | 1418 base::Value(show)); |
1422 show_link = show; | 1419 show_link = show; |
1423 } | 1420 } |
1424 } | 1421 } |
1425 | 1422 |
1426 void ContentSettingsHandler::UpdateFlashMediaLinksVisibility( | 1423 void ContentSettingsHandler::UpdateFlashMediaLinksVisibility( |
1427 ContentSettingsType type) { | 1424 ContentSettingsType type) { |
1428 MediaSettingsInfo::ForOneType& settings = media_settings_->forType(type); | 1425 MediaSettingsInfo::ForOneType& settings = media_settings_->forType(type); |
1429 MediaSettingsInfo::ForFlash& flash_settings = media_settings_->forFlash(); | 1426 MediaSettingsInfo::ForFlash& flash_settings = media_settings_->forFlash(); |
1430 | 1427 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 ShowFlashMediaLink(EXCEPTIONS, type, true); | 1465 ShowFlashMediaLink(EXCEPTIONS, type, true); |
1469 } | 1466 } |
1470 } | 1467 } |
1471 | 1468 |
1472 void ContentSettingsHandler::UpdateMediaDeviceDropdownVisibility( | 1469 void ContentSettingsHandler::UpdateMediaDeviceDropdownVisibility( |
1473 ContentSettingsType type) { | 1470 ContentSettingsType type) { |
1474 MediaSettingsInfo::ForOneType& settings = media_settings_->forType(type); | 1471 MediaSettingsInfo::ForOneType& settings = media_settings_->forType(type); |
1475 | 1472 |
1476 web_ui()->CallJavascriptFunctionUnsafe( | 1473 web_ui()->CallJavascriptFunctionUnsafe( |
1477 "ContentSettings.setDevicesMenuVisibility", | 1474 "ContentSettings.setDevicesMenuVisibility", |
1478 base::StringValue(site_settings::ContentSettingsTypeToGroupName(type)), | 1475 base::Value(site_settings::ContentSettingsTypeToGroupName(type)), |
1479 base::Value(!settings.policy_disable)); | 1476 base::Value(!settings.policy_disable)); |
1480 } | 1477 } |
1481 | 1478 |
1482 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { | 1479 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { |
1483 #if defined(OS_CHROMEOS) | 1480 #if defined(OS_CHROMEOS) |
1484 // Guests cannot modify exceptions. UIAccountTweaks will disabled the button. | 1481 // Guests cannot modify exceptions. UIAccountTweaks will disabled the button. |
1485 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) | 1482 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) |
1486 return; | 1483 return; |
1487 #endif | 1484 #endif |
1488 | 1485 |
1489 // Exceptions apply only when the feature is enabled. | 1486 // Exceptions apply only when the feature is enabled. |
1490 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); | 1487 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); |
1491 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); | 1488 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); |
1492 web_ui()->CallJavascriptFunctionUnsafe( | 1489 web_ui()->CallJavascriptFunctionUnsafe( |
1493 "ContentSettings.enableProtectedContentExceptions", | 1490 "ContentSettings.enableProtectedContentExceptions", |
1494 base::Value(enable_exceptions)); | 1491 base::Value(enable_exceptions)); |
1495 } | 1492 } |
1496 | 1493 |
1497 } // namespace options | 1494 } // namespace options |
OLD | NEW |