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 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 exception->SetString(kSetting, ContentSettingToString(setting)); | 167 exception->SetString(kSetting, ContentSettingToString(setting)); |
168 exception->SetString(kOrigin, origin.ToString()); | 168 exception->SetString(kOrigin, origin.ToString()); |
169 exception->SetString(kEmbeddingOrigin, embedding_origin.ToString()); | 169 exception->SetString(kEmbeddingOrigin, embedding_origin.ToString()); |
170 return exception; | 170 return exception; |
171 } | 171 } |
172 | 172 |
173 // Create a DictionaryValue* that will act as a data source for a single row | 173 // Create a DictionaryValue* that will act as a data source for a single row |
174 // in the desktop notifications exceptions table. Ownership of the pointer is | 174 // in the desktop notifications exceptions table. Ownership of the pointer is |
175 // passed to the caller. | 175 // passed to the caller. |
176 base::DictionaryValue* GetNotificationExceptionForPage( | 176 base::DictionaryValue* GetNotificationExceptionForPage( |
177 const ContentSettingsPattern& pattern, | 177 const ContentSettingsPattern& primary_pattern, |
| 178 const ContentSettingsPattern& secondary_pattern, |
178 ContentSetting setting, | 179 ContentSetting setting, |
179 const std::string& provider_name) { | 180 const std::string& provider_name) { |
| 181 std::string embedding_origin; |
| 182 if (secondary_pattern != ContentSettingsPattern::Wildcard()) |
| 183 embedding_origin = secondary_pattern.ToString(); |
| 184 |
180 base::DictionaryValue* exception = new base::DictionaryValue(); | 185 base::DictionaryValue* exception = new base::DictionaryValue(); |
181 exception->SetString(kSetting, ContentSettingToString(setting)); | 186 exception->SetString(kSetting, ContentSettingToString(setting)); |
182 exception->SetString(kOrigin, pattern.ToString()); | 187 exception->SetString(kOrigin, primary_pattern.ToString()); |
| 188 exception->SetString(kEmbeddingOrigin, embedding_origin); |
183 exception->SetString(kSource, provider_name); | 189 exception->SetString(kSource, provider_name); |
184 return exception; | 190 return exception; |
185 } | 191 } |
186 | 192 |
187 // Returns true whenever the |extension| is hosted and has |permission|. | 193 // Returns true whenever the |extension| is hosted and has |permission|. |
188 // Must have the AppFilter signature. | 194 // Must have the AppFilter signature. |
189 template <APIPermission::ID permission> | 195 template <APIPermission::ID permission> |
190 bool HostedAppHasPermission(const extensions::Extension& extension, | 196 bool HostedAppHasPermission(const extensions::Extension& extension, |
191 content::BrowserContext* /* context */) { | 197 content::BrowserContext* /* context */) { |
192 return extension.is_hosted_app() && | 198 return extension.is_hosted_app() && |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 i != settings.end(); | 840 i != settings.end(); |
835 ++i) { | 841 ++i) { |
836 // Don't add default settings. | 842 // Don't add default settings. |
837 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && | 843 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && |
838 i->secondary_pattern == ContentSettingsPattern::Wildcard() && | 844 i->secondary_pattern == ContentSettingsPattern::Wildcard() && |
839 i->source != kPreferencesSource) { | 845 i->source != kPreferencesSource) { |
840 continue; | 846 continue; |
841 } | 847 } |
842 | 848 |
843 exceptions.Append( | 849 exceptions.Append( |
844 GetNotificationExceptionForPage(i->primary_pattern, i->setting, | 850 GetNotificationExceptionForPage(i->primary_pattern, |
| 851 i->secondary_pattern, |
| 852 i->setting, |
845 i->source)); | 853 i->source)); |
846 } | 854 } |
847 | 855 |
848 base::StringValue type_string( | 856 base::StringValue type_string( |
849 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 857 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
850 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", | 858 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", |
851 type_string, exceptions); | 859 type_string, exceptions); |
852 | 860 |
853 // This is mainly here to keep this function ideologically parallel to | 861 // This is mainly here to keep this function ideologically parallel to |
854 // UpdateExceptionsViewFromHostContentSettingsMap(). | 862 // UpdateExceptionsViewFromHostContentSettingsMap(). |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 } | 1128 } |
1121 } | 1129 } |
1122 | 1130 |
1123 for (size_t i = 0; i < all_provider_exceptions.size(); ++i) { | 1131 for (size_t i = 0; i < all_provider_exceptions.size(); ++i) { |
1124 for (size_t j = 0; j < all_provider_exceptions[i].size(); ++j) { | 1132 for (size_t j = 0; j < all_provider_exceptions[i].size(); ++j) { |
1125 exceptions->Append(all_provider_exceptions[i][j]); | 1133 exceptions->Append(all_provider_exceptions[i][j]); |
1126 } | 1134 } |
1127 } | 1135 } |
1128 } | 1136 } |
1129 | 1137 |
1130 void ContentSettingsHandler::RemoveNotificationException( | |
1131 const base::ListValue* args) { | |
1132 Profile* profile = Profile::FromWebUI(web_ui()); | |
1133 | |
1134 std::string origin; | |
1135 std::string setting; | |
1136 bool rv = args->GetString(1, &origin); | |
1137 DCHECK(rv); | |
1138 rv = args->GetString(2, &setting); | |
1139 DCHECK(rv); | |
1140 ContentSetting content_setting = ContentSettingFromString(setting); | |
1141 | |
1142 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | |
1143 content_setting == CONTENT_SETTING_BLOCK); | |
1144 DesktopNotificationProfileUtil::ClearSetting(profile, | |
1145 ContentSettingsPattern::FromString(origin)); | |
1146 } | |
1147 | |
1148 void ContentSettingsHandler::RemoveMediaException(const base::ListValue* args) { | 1138 void ContentSettingsHandler::RemoveMediaException(const base::ListValue* args) { |
1149 std::string mode; | 1139 std::string mode; |
1150 bool rv = args->GetString(1, &mode); | 1140 bool rv = args->GetString(1, &mode); |
1151 DCHECK(rv); | 1141 DCHECK(rv); |
1152 | 1142 |
1153 std::string pattern; | 1143 std::string pattern; |
1154 rv = args->GetString(2, &pattern); | 1144 rv = args->GetString(2, &pattern); |
1155 DCHECK(rv); | 1145 DCHECK(rv); |
1156 | 1146 |
1157 HostContentSettingsMap* settings_map = | 1147 HostContentSettingsMap* settings_map = |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 | 1310 |
1321 // Zoom levels are no actual content type so we need to handle them | 1311 // Zoom levels are no actual content type so we need to handle them |
1322 // separately. They would not be recognized by | 1312 // separately. They would not be recognized by |
1323 // ContentSettingsTypeFromGroupName. | 1313 // ContentSettingsTypeFromGroupName. |
1324 if (type_string == kZoomContentType) { | 1314 if (type_string == kZoomContentType) { |
1325 RemoveZoomLevelException(args); | 1315 RemoveZoomLevelException(args); |
1326 return; | 1316 return; |
1327 } | 1317 } |
1328 | 1318 |
1329 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 1319 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); |
1330 switch (type) { | 1320 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) |
1331 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 1321 RemoveMediaException(args); |
1332 RemoveNotificationException(args); | 1322 else |
1333 break; | 1323 RemoveExceptionFromHostContentSettingsMap(args, type); |
1334 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: | |
1335 RemoveMediaException(args); | |
1336 break; | |
1337 default: | |
1338 RemoveExceptionFromHostContentSettingsMap(args, type); | |
1339 break; | |
1340 } | |
1341 } | 1324 } |
1342 | 1325 |
1343 void ContentSettingsHandler::SetException(const base::ListValue* args) { | 1326 void ContentSettingsHandler::SetException(const base::ListValue* args) { |
1344 std::string type_string; | 1327 std::string type_string; |
1345 CHECK(args->GetString(0, &type_string)); | 1328 CHECK(args->GetString(0, &type_string)); |
1346 std::string mode; | 1329 std::string mode; |
1347 CHECK(args->GetString(1, &mode)); | 1330 CHECK(args->GetString(1, &mode)); |
1348 std::string pattern; | 1331 std::string pattern; |
1349 CHECK(args->GetString(2, &pattern)); | 1332 CHECK(args->GetString(2, &pattern)); |
1350 std::string setting; | 1333 std::string setting; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { | 1492 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { |
1510 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); | 1493 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); |
1511 // Exceptions apply only when the feature is enabled. | 1494 // Exceptions apply only when the feature is enabled. |
1512 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); | 1495 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); |
1513 web_ui()->CallJavascriptFunction( | 1496 web_ui()->CallJavascriptFunction( |
1514 "ContentSettings.enableProtectedContentExceptions", | 1497 "ContentSettings.enableProtectedContentExceptions", |
1515 base::FundamentalValue(enable_exceptions)); | 1498 base::FundamentalValue(enable_exceptions)); |
1516 } | 1499 } |
1517 | 1500 |
1518 } // namespace options | 1501 } // namespace options |
OLD | NEW |