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

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

Issue 528333002: Make it possible to revoke Web Notification exceptions in content settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « chrome/browser/resources/options/content_settings_exceptions_area.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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
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) {
180 base::DictionaryValue* exception = new base::DictionaryValue(); 181 base::DictionaryValue* exception = new base::DictionaryValue();
181 exception->SetString(kSetting, ContentSettingToString(setting)); 182 exception->SetString(kSetting, ContentSettingToString(setting));
182 exception->SetString(kOrigin, pattern.ToString()); 183 exception->SetString(kOrigin, primary_pattern.ToString());
184 exception->SetString(kEmbeddingOrigin,
185 secondary_pattern == ContentSettingsPattern::Wildcard() ?
186 std::string() :
Bernhard Bauer 2014/09/11 14:56:35 Nit: I would probably use a local variable for thi
Peter Beverloo 2014/09/11 15:30:43 Done.
187 secondary_pattern.ToString());
183 exception->SetString(kSource, provider_name); 188 exception->SetString(kSource, provider_name);
184 return exception; 189 return exception;
185 } 190 }
186 191
187 // Returns true whenever the |extension| is hosted and has |permission|. 192 // Returns true whenever the |extension| is hosted and has |permission|.
188 // Must have the AppFilter signature. 193 // Must have the AppFilter signature.
189 template <APIPermission::ID permission> 194 template <APIPermission::ID permission>
190 bool HostedAppHasPermission(const extensions::Extension& extension, 195 bool HostedAppHasPermission(const extensions::Extension& extension,
191 content::BrowserContext* /* context */) { 196 content::BrowserContext* /* context */) {
192 return extension.is_hosted_app() && 197 return extension.is_hosted_app() &&
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 base::StringValue type_string( 816 base::StringValue type_string(
812 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_GEOLOCATION)); 817 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_GEOLOCATION));
813 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", 818 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions",
814 type_string, exceptions); 819 type_string, exceptions);
815 820
816 // This is mainly here to keep this function ideologically parallel to 821 // This is mainly here to keep this function ideologically parallel to
817 // UpdateExceptionsViewFromHostContentSettingsMap(). 822 // UpdateExceptionsViewFromHostContentSettingsMap().
818 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); 823 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION);
819 } 824 }
820 825
821 void ContentSettingsHandler::UpdateNotificationExceptionsView() { 826 void ContentSettingsHandler::UpdateNotificationExceptionsView() {
Bernhard Bauer 2014/09/11 14:56:35 Could we do this with the regular UpdateExceptions
Peter Beverloo 2014/09/11 15:30:43 I am not sure. We also add exceptions granted to h
Bernhard Bauer 2014/09/11 15:52:43 AFAICT, mostly historical reasons.
822 Profile* profile = Profile::FromWebUI(web_ui()); 827 Profile* profile = Profile::FromWebUI(web_ui());
823 ContentSettingsForOneType settings; 828 ContentSettingsForOneType settings;
824 DesktopNotificationProfileUtil::GetNotificationsSettings(profile, &settings); 829 DesktopNotificationProfileUtil::GetNotificationsSettings(profile, &settings);
825 830
826 base::ListValue exceptions; 831 base::ListValue exceptions;
827 AddExceptionsGrantedByHostedApps( 832 AddExceptionsGrantedByHostedApps(
828 profile, 833 profile,
829 HostedAppHasPermission<APIPermission::kNotifications>, 834 HostedAppHasPermission<APIPermission::kNotifications>,
830 &exceptions); 835 &exceptions);
831 836
832 for (ContentSettingsForOneType::const_iterator i = 837 for (ContentSettingsForOneType::const_iterator i =
833 settings.begin(); 838 settings.begin();
834 i != settings.end(); 839 i != settings.end();
835 ++i) { 840 ++i) {
836 // Don't add default settings. 841 // Don't add default settings.
837 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && 842 if (i->primary_pattern == ContentSettingsPattern::Wildcard() &&
838 i->secondary_pattern == ContentSettingsPattern::Wildcard() && 843 i->secondary_pattern == ContentSettingsPattern::Wildcard() &&
839 i->source != kPreferencesSource) { 844 i->source != kPreferencesSource) {
840 continue; 845 continue;
841 } 846 }
842 847
843 exceptions.Append( 848 exceptions.Append(
844 GetNotificationExceptionForPage(i->primary_pattern, i->setting, 849 GetNotificationExceptionForPage(i->primary_pattern,
850 i->secondary_pattern,
851 i->setting,
845 i->source)); 852 i->source));
846 } 853 }
847 854
848 base::StringValue type_string( 855 base::StringValue type_string(
849 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); 856 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
850 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", 857 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions",
851 type_string, exceptions); 858 type_string, exceptions);
852 859
853 // This is mainly here to keep this function ideologically parallel to 860 // This is mainly here to keep this function ideologically parallel to
854 // UpdateExceptionsViewFromHostContentSettingsMap(). 861 // UpdateExceptionsViewFromHostContentSettingsMap().
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 } 1127 }
1121 } 1128 }
1122 1129
1123 for (size_t i = 0; i < all_provider_exceptions.size(); ++i) { 1130 for (size_t i = 0; i < all_provider_exceptions.size(); ++i) {
1124 for (size_t j = 0; j < all_provider_exceptions[i].size(); ++j) { 1131 for (size_t j = 0; j < all_provider_exceptions[i].size(); ++j) {
1125 exceptions->Append(all_provider_exceptions[i][j]); 1132 exceptions->Append(all_provider_exceptions[i][j]);
1126 } 1133 }
1127 } 1134 }
1128 } 1135 }
1129 1136
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) { 1137 void ContentSettingsHandler::RemoveMediaException(const base::ListValue* args) {
1149 std::string mode; 1138 std::string mode;
1150 bool rv = args->GetString(1, &mode); 1139 bool rv = args->GetString(1, &mode);
1151 DCHECK(rv); 1140 DCHECK(rv);
1152 1141
1153 std::string pattern; 1142 std::string pattern;
1154 rv = args->GetString(2, &pattern); 1143 rv = args->GetString(2, &pattern);
1155 DCHECK(rv); 1144 DCHECK(rv);
1156 1145
1157 HostContentSettingsMap* settings_map = 1146 HostContentSettingsMap* settings_map =
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 1309
1321 // Zoom levels are no actual content type so we need to handle them 1310 // Zoom levels are no actual content type so we need to handle them
1322 // separately. They would not be recognized by 1311 // separately. They would not be recognized by
1323 // ContentSettingsTypeFromGroupName. 1312 // ContentSettingsTypeFromGroupName.
1324 if (type_string == kZoomContentType) { 1313 if (type_string == kZoomContentType) {
1325 RemoveZoomLevelException(args); 1314 RemoveZoomLevelException(args);
1326 return; 1315 return;
1327 } 1316 }
1328 1317
1329 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); 1318 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string);
1330 switch (type) { 1319 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM)
1331 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 1320 RemoveMediaException(args);
1332 RemoveNotificationException(args); 1321 else
1333 break; 1322 RemoveExceptionFromHostContentSettingsMap(args, type);
1334 case CONTENT_SETTINGS_TYPE_MEDIASTREAM:
1335 RemoveMediaException(args);
1336 break;
1337 default:
1338 RemoveExceptionFromHostContentSettingsMap(args, type);
1339 break;
1340 }
1341 } 1323 }
1342 1324
1343 void ContentSettingsHandler::SetException(const base::ListValue* args) { 1325 void ContentSettingsHandler::SetException(const base::ListValue* args) {
1344 std::string type_string; 1326 std::string type_string;
1345 CHECK(args->GetString(0, &type_string)); 1327 CHECK(args->GetString(0, &type_string));
1346 std::string mode; 1328 std::string mode;
1347 CHECK(args->GetString(1, &mode)); 1329 CHECK(args->GetString(1, &mode));
1348 std::string pattern; 1330 std::string pattern;
1349 CHECK(args->GetString(2, &pattern)); 1331 CHECK(args->GetString(2, &pattern));
1350 std::string setting; 1332 std::string setting;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { 1491 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() {
1510 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); 1492 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui()));
1511 // Exceptions apply only when the feature is enabled. 1493 // Exceptions apply only when the feature is enabled.
1512 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); 1494 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM);
1513 web_ui()->CallJavascriptFunction( 1495 web_ui()->CallJavascriptFunction(
1514 "ContentSettings.enableProtectedContentExceptions", 1496 "ContentSettings.enableProtectedContentExceptions",
1515 base::FundamentalValue(enable_exceptions)); 1497 base::FundamentalValue(enable_exceptions));
1516 } 1498 }
1517 1499
1518 } // namespace options 1500 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/content_settings_exceptions_area.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698