| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" | 21 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" |
| 21 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 22 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 22 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 23 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 23 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 24 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 24 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 25 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
| 28 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 29 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 28 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 30 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
| 31 #include "chrome/grit/locale_settings.h" | 33 #include "chrome/grit/locale_settings.h" |
| 32 #include "components/content_settings/core/browser/content_settings_details.h" | 34 #include "components/content_settings/core/browser/content_settings_details.h" |
| 33 #include "components/content_settings/core/browser/content_settings_utils.h" | 35 #include "components/content_settings/core/browser/content_settings_utils.h" |
| 34 #include "components/content_settings/core/browser/host_content_settings_map.h" | 36 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 35 #include "components/content_settings/core/browser/plugins_field_trial.h" | 37 #include "components/content_settings/core/browser/plugins_field_trial.h" |
| 36 #include "components/content_settings/core/common/content_settings.h" | 38 #include "components/content_settings/core/common/content_settings.h" |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 pref_change_registrar_.Add( | 513 pref_change_registrar_.Add( |
| 512 prefs::kPepperFlashSettingsEnabled, | 514 prefs::kPepperFlashSettingsEnabled, |
| 513 base::Bind(&ContentSettingsHandler::OnPepperFlashPrefChanged, | 515 base::Bind(&ContentSettingsHandler::OnPepperFlashPrefChanged, |
| 514 base::Unretained(this))); | 516 base::Unretained(this))); |
| 515 pref_change_registrar_.Add( | 517 pref_change_registrar_.Add( |
| 516 prefs::kAudioCaptureAllowed, | 518 prefs::kAudioCaptureAllowed, |
| 517 base::Bind(&ContentSettingsHandler::UpdateSettingDefaultFromModel, | 519 base::Bind(&ContentSettingsHandler::UpdateSettingDefaultFromModel, |
| 518 base::Unretained(this), | 520 base::Unretained(this), |
| 519 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 521 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 520 pref_change_registrar_.Add( | 522 pref_change_registrar_.Add( |
| 523 prefs::kAudioCaptureAllowedUrls, |
| 524 base::Bind(&ContentSettingsHandler::UpdateExceptionsViewFromModel, |
| 525 base::Unretained(this), |
| 526 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 527 pref_change_registrar_.Add( |
| 521 prefs::kVideoCaptureAllowed, | 528 prefs::kVideoCaptureAllowed, |
| 522 base::Bind(&ContentSettingsHandler::UpdateSettingDefaultFromModel, | 529 base::Bind(&ContentSettingsHandler::UpdateSettingDefaultFromModel, |
| 523 base::Unretained(this), | 530 base::Unretained(this), |
| 524 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 531 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 525 pref_change_registrar_.Add( | 532 pref_change_registrar_.Add( |
| 533 prefs::kVideoCaptureAllowedUrls, |
| 534 base::Bind(&ContentSettingsHandler::UpdateExceptionsViewFromModel, |
| 535 base::Unretained(this), |
| 536 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 537 pref_change_registrar_.Add( |
| 526 prefs::kEnableDRM, | 538 prefs::kEnableDRM, |
| 527 base::Bind( | 539 base::Bind( |
| 528 &ContentSettingsHandler::UpdateProtectedContentExceptionsButton, | 540 &ContentSettingsHandler::UpdateProtectedContentExceptionsButton, |
| 529 base::Unretained(this))); | 541 base::Unretained(this))); |
| 530 | 542 |
| 531 // Here we only subscribe to the HostZoomMap for the default storage partition | 543 // Here we only subscribe to the HostZoomMap for the default storage partition |
| 532 // since we don't allow the user to manage the zoom levels for apps. | 544 // since we don't allow the user to manage the zoom levels for apps. |
| 533 // We're only interested in zoom-levels that are persisted, since the user | 545 // We're only interested in zoom-levels that are persisted, since the user |
| 534 // is given the opportunity to view/delete these in the content-settings page. | 546 // is given the opportunity to view/delete these in the content-settings page. |
| 535 host_zoom_map_subscription_ = | 547 host_zoom_map_subscription_ = |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); | 1104 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); |
| 1093 if (!otr_settings_map) | 1105 if (!otr_settings_map) |
| 1094 return; | 1106 return; |
| 1095 base::ListValue exceptions; | 1107 base::ListValue exceptions; |
| 1096 GetExceptionsFromHostContentSettingsMap(otr_settings_map, type, &exceptions); | 1108 GetExceptionsFromHostContentSettingsMap(otr_settings_map, type, &exceptions); |
| 1097 base::StringValue type_string(ContentSettingsTypeToGroupName(type)); | 1109 base::StringValue type_string(ContentSettingsTypeToGroupName(type)); |
| 1098 web_ui()->CallJavascriptFunction("ContentSettings.setOTRExceptions", | 1110 web_ui()->CallJavascriptFunction("ContentSettings.setOTRExceptions", |
| 1099 type_string, exceptions); | 1111 type_string, exceptions); |
| 1100 } | 1112 } |
| 1101 | 1113 |
| 1114 base::ListValue* ContentSettingsHandler::GetPolicyAllowedUrls( |
| 1115 ContentSettingsType type) { |
| 1116 DCHECK(type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 1117 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 1118 |
| 1119 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 1120 const base::ListValue* policy_urls = prefs->GetList( |
| 1121 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC |
| 1122 ? prefs::kAudioCaptureAllowedUrls |
| 1123 : prefs::kVideoCaptureAllowedUrls); |
| 1124 |
| 1125 // Convert the URLs to |ContentSettingsPattern|s. Ignore any invalid ones. |
| 1126 std::vector<ContentSettingsPattern> patterns; |
| 1127 for (const base::Value* entry : *policy_urls) { |
| 1128 std::string url; |
| 1129 bool valid_string = entry->GetAsString(&url); |
| 1130 if (!valid_string) |
| 1131 continue; |
| 1132 |
| 1133 ContentSettingsPattern pattern = ContentSettingsPattern::FromString(url); |
| 1134 if (!pattern.IsValid()) |
| 1135 continue; |
| 1136 |
| 1137 patterns.push_back(pattern); |
| 1138 } |
| 1139 |
| 1140 // The patterns are shown in the UI in a reverse order defined by |
| 1141 // |ContentSettingsPattern::operator<|. |
| 1142 std::sort( |
| 1143 patterns.begin(), patterns.end(), std::greater<ContentSettingsPattern>()); |
| 1144 |
| 1145 base::ListValue* exceptions = new base::ListValue(); |
| 1146 for (const ContentSettingsPattern& pattern : patterns) { |
| 1147 exceptions->Append(GetExceptionForPage( |
| 1148 pattern, |
| 1149 ContentSettingsPattern(), |
| 1150 CONTENT_SETTING_ALLOW, |
| 1151 kPolicyProviderId)); |
| 1152 } |
| 1153 |
| 1154 return exceptions; |
| 1155 } |
| 1156 |
| 1102 void ContentSettingsHandler::GetExceptionsFromHostContentSettingsMap( | 1157 void ContentSettingsHandler::GetExceptionsFromHostContentSettingsMap( |
| 1103 const HostContentSettingsMap* map, | 1158 const HostContentSettingsMap* map, |
| 1104 ContentSettingsType type, | 1159 ContentSettingsType type, |
| 1105 base::ListValue* exceptions) { | 1160 base::ListValue* exceptions) { |
| 1106 ContentSettingsForOneType entries; | 1161 ContentSettingsForOneType entries; |
| 1107 map->GetSettingsForOneType(type, std::string(), &entries); | 1162 map->GetSettingsForOneType(type, std::string(), &entries); |
| 1108 // Group settings by primary_pattern. | 1163 // Group settings by primary_pattern. |
| 1109 AllPatternsSettings all_patterns_settings; | 1164 AllPatternsSettings all_patterns_settings; |
| 1110 for (ContentSettingsForOneType::iterator i = entries.begin(); | 1165 for (ContentSettingsForOneType::iterator i = entries.begin(); |
| 1111 i != entries.end(); ++i) { | 1166 i != entries.end(); ++i) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 | 1228 |
| 1174 ContentSetting content_setting = j->second; | 1229 ContentSetting content_setting = j->second; |
| 1175 this_provider_exceptions->push_back(GetExceptionForPage( | 1230 this_provider_exceptions->push_back(GetExceptionForPage( |
| 1176 primary_pattern, | 1231 primary_pattern, |
| 1177 j->first, | 1232 j->first, |
| 1178 content_setting, | 1233 content_setting, |
| 1179 source)); | 1234 source)); |
| 1180 } | 1235 } |
| 1181 } | 1236 } |
| 1182 | 1237 |
| 1238 // For camera and microphone, we do not have policy exceptions, but we do have |
| 1239 // the policy-set allowed URLs, which should be displayed in the same manner. |
| 1240 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 1241 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| 1242 scoped_ptr<base::ListValue> exceptions_list(GetPolicyAllowedUrls(type)); |
| 1243 std::vector<base::Value*>& policy_exceptions = all_provider_exceptions.at( |
| 1244 HostContentSettingsMap::GetProviderTypeFromSource(kPolicyProviderId)); |
| 1245 |
| 1246 for (const base::Value* exception : *exceptions_list) |
| 1247 policy_exceptions.push_back(exception->DeepCopy()); |
| 1248 } |
| 1249 |
| 1183 for (size_t i = 0; i < all_provider_exceptions.size(); ++i) { | 1250 for (size_t i = 0; i < all_provider_exceptions.size(); ++i) { |
| 1184 for (size_t j = 0; j < all_provider_exceptions[i].size(); ++j) { | 1251 for (size_t j = 0; j < all_provider_exceptions[i].size(); ++j) { |
| 1185 exceptions->Append(all_provider_exceptions[i][j]); | 1252 exceptions->Append(all_provider_exceptions[i][j]); |
| 1186 } | 1253 } |
| 1187 } | 1254 } |
| 1188 } | 1255 } |
| 1189 | 1256 |
| 1190 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( | 1257 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( |
| 1191 const base::ListValue* args, | 1258 const base::ListValue* args, |
| 1192 ContentSettingsType type) { | 1259 ContentSettingsType type) { |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1566 | 1633 |
| 1567 // Exceptions apply only when the feature is enabled. | 1634 // Exceptions apply only when the feature is enabled. |
| 1568 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); | 1635 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); |
| 1569 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); | 1636 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); |
| 1570 web_ui()->CallJavascriptFunction( | 1637 web_ui()->CallJavascriptFunction( |
| 1571 "ContentSettings.enableProtectedContentExceptions", | 1638 "ContentSettings.enableProtectedContentExceptions", |
| 1572 base::FundamentalValue(enable_exceptions)); | 1639 base::FundamentalValue(enable_exceptions)); |
| 1573 } | 1640 } |
| 1574 | 1641 |
| 1575 } // namespace options | 1642 } // namespace options |
| OLD | NEW |