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

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

Issue 376253005: Migrate the notification permission to the new common permission classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 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 | Annotate | Revision Log
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
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/command_line.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/content_settings/content_settings_details.h" 20 #include "chrome/browser/content_settings/content_settings_details.h"
21 #include "chrome/browser/content_settings/content_settings_provider.h"
21 #include "chrome/browser/content_settings/content_settings_utils.h" 22 #include "chrome/browser/content_settings/content_settings_utils.h"
22 #include "chrome/browser/content_settings/host_content_settings_map.h" 23 #include "chrome/browser/content_settings/host_content_settings_map.h"
23 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 24 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
24 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 25 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
25 #include "chrome/browser/extensions/extension_special_storage_policy.h" 26 #include "chrome/browser/extensions/extension_special_storage_policy.h"
26 #include "chrome/browser/notifications/desktop_notification_service.h" 27 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
27 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
28 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/ui/browser_list.h" 29 #include "chrome/browser/ui/browser_list.h"
30 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/content_settings.h" 31 #include "chrome/common/content_settings.h"
32 #include "chrome/common/content_settings_pattern.h" 32 #include "chrome/common/content_settings_pattern.h"
33 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 33 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
34 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
35 #include "chrome/common/url_constants.h" 35 #include "chrome/common/url_constants.h"
36 #include "components/google/core/browser/google_util.h" 36 #include "components/google/core/browser/google_util.h"
37 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 media_ui_settings.SetString("bubbleText", std::string()); 670 media_ui_settings.SetString("bubbleText", std::string());
671 671
672 web_ui()->CallJavascriptFunction("ContentSettings.updateMediaUI", 672 web_ui()->CallJavascriptFunction("ContentSettings.updateMediaUI",
673 media_ui_settings); 673 media_ui_settings);
674 } 674 }
675 675
676 std::string ContentSettingsHandler::GetSettingDefaultFromModel( 676 std::string ContentSettingsHandler::GetSettingDefaultFromModel(
677 ContentSettingsType type, std::string* provider_id) { 677 ContentSettingsType type, std::string* provider_id) {
678 Profile* profile = Profile::FromWebUI(web_ui()); 678 Profile* profile = Profile::FromWebUI(web_ui());
679 ContentSetting default_setting; 679 ContentSetting default_setting;
680 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 680 default_setting =
681 default_setting = 681 profile->GetHostContentSettingsMap()->GetDefaultContentSetting(
682 DesktopNotificationServiceFactory::GetForProfile(profile)-> 682 type, provider_id);
683 GetDefaultContentSetting(provider_id);
684 } else {
685 default_setting =
686 profile->GetHostContentSettingsMap()->
687 GetDefaultContentSetting(type, provider_id);
688 }
689 683
690 return ContentSettingToString(default_setting); 684 return ContentSettingToString(default_setting);
691 } 685 }
692 686
693 void ContentSettingsHandler::UpdateHandlersEnabledRadios() { 687 void ContentSettingsHandler::UpdateHandlersEnabledRadios() {
694 base::FundamentalValue handlers_enabled( 688 base::FundamentalValue handlers_enabled(
695 GetProtocolHandlerRegistry()->enabled()); 689 GetProtocolHandlerRegistry()->enabled());
696 690
697 web_ui()->CallJavascriptFunction( 691 web_ui()->CallJavascriptFunction(
698 "ContentSettings.updateHandlersEnabledRadios", 692 "ContentSettings.updateHandlersEnabledRadios",
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", 836 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions",
843 type_string, exceptions); 837 type_string, exceptions);
844 838
845 // This is mainly here to keep this function ideologically parallel to 839 // This is mainly here to keep this function ideologically parallel to
846 // UpdateExceptionsViewFromHostContentSettingsMap(). 840 // UpdateExceptionsViewFromHostContentSettingsMap().
847 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); 841 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION);
848 } 842 }
849 843
850 void ContentSettingsHandler::UpdateNotificationExceptionsView() { 844 void ContentSettingsHandler::UpdateNotificationExceptionsView() {
851 Profile* profile = Profile::FromWebUI(web_ui()); 845 Profile* profile = Profile::FromWebUI(web_ui());
852 DesktopNotificationService* service =
853 DesktopNotificationServiceFactory::GetForProfile(profile);
854
855 ContentSettingsForOneType settings; 846 ContentSettingsForOneType settings;
856 service->GetNotificationsSettings(&settings); 847 DesktopNotificationProfileUtil::GetNotificationsSettings(profile, &settings);
857 848
858 base::ListValue exceptions; 849 base::ListValue exceptions;
859 AddExceptionsGrantedByHostedApps(profile, 850 AddExceptionsGrantedByHostedApps(profile,
860 HostedAppHasPermission<APIPermission::kNotification>, 851 HostedAppHasPermission<APIPermission::kNotification>,
861 &exceptions); 852 &exceptions);
862 853
863 for (ContentSettingsForOneType::const_iterator i = 854 for (ContentSettingsForOneType::const_iterator i =
864 settings.begin(); 855 settings.begin();
865 i != settings.end(); 856 i != settings.end();
866 ++i) { 857 ++i) {
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 std::string origin; 1154 std::string origin;
1164 std::string setting; 1155 std::string setting;
1165 bool rv = args->GetString(1, &origin); 1156 bool rv = args->GetString(1, &origin);
1166 DCHECK(rv); 1157 DCHECK(rv);
1167 rv = args->GetString(2, &setting); 1158 rv = args->GetString(2, &setting);
1168 DCHECK(rv); 1159 DCHECK(rv);
1169 ContentSetting content_setting = ContentSettingFromString(setting); 1160 ContentSetting content_setting = ContentSettingFromString(setting);
1170 1161
1171 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 1162 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
1172 content_setting == CONTENT_SETTING_BLOCK); 1163 content_setting == CONTENT_SETTING_BLOCK);
1173 DesktopNotificationServiceFactory::GetForProfile(profile)-> 1164 DesktopNotificationProfileUtil::ClearSetting(profile,
1174 ClearSetting(ContentSettingsPattern::FromString(origin)); 1165 ContentSettingsPattern::FromString(origin));
1175 } 1166 }
1176 1167
1177 void ContentSettingsHandler::RemoveMediaException(const base::ListValue* args) { 1168 void ContentSettingsHandler::RemoveMediaException(const base::ListValue* args) {
1178 std::string mode; 1169 std::string mode;
1179 bool rv = args->GetString(1, &mode); 1170 bool rv = args->GetString(1, &mode);
1180 DCHECK(rv); 1171 DCHECK(rv);
1181 1172
1182 std::string pattern; 1173 std::string pattern;
1183 rv = args->GetString(2, &pattern); 1174 rv = args->GetString(2, &pattern);
1184 DCHECK(rv); 1175 DCHECK(rv);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); 1297 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group);
1307 Profile* profile = Profile::FromWebUI(web_ui()); 1298 Profile* profile = Profile::FromWebUI(web_ui());
1308 1299
1309 #if defined(OS_CHROMEOS) 1300 #if defined(OS_CHROMEOS)
1310 // ChromeOS special case : in Guest mode settings are opened in Incognito 1301 // ChromeOS special case : in Guest mode settings are opened in Incognito
1311 // mode, so we need original profile to actually modify settings. 1302 // mode, so we need original profile to actually modify settings.
1312 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) 1303 if (chromeos::UserManager::Get()->IsLoggedInAsGuest())
1313 profile = profile->GetOriginalProfile(); 1304 profile = profile->GetOriginalProfile();
1314 #endif 1305 #endif
1315 1306
1316 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 1307
1317 DesktopNotificationServiceFactory::GetForProfile(profile)-> 1308 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
1318 SetDefaultContentSetting(default_setting); 1309 ApplyWhitelist(content_type, default_setting);
1319 } else { 1310 map->SetDefaultContentSetting(content_type, default_setting);
1320 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); 1311
1321 ApplyWhitelist(content_type, default_setting);
1322 map->SetDefaultContentSetting(content_type, default_setting);
1323 }
1324 switch (content_type) { 1312 switch (content_type) {
1325 case CONTENT_SETTINGS_TYPE_COOKIES: 1313 case CONTENT_SETTINGS_TYPE_COOKIES:
1326 content::RecordAction( 1314 content::RecordAction(
1327 UserMetricsAction("Options_DefaultCookieSettingChanged")); 1315 UserMetricsAction("Options_DefaultCookieSettingChanged"));
1328 break; 1316 break;
1329 case CONTENT_SETTINGS_TYPE_IMAGES: 1317 case CONTENT_SETTINGS_TYPE_IMAGES:
1330 content::RecordAction( 1318 content::RecordAction(
1331 UserMetricsAction("Options_DefaultImagesSettingChanged")); 1319 UserMetricsAction("Options_DefaultImagesSettingChanged"));
1332 break; 1320 break;
1333 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: 1321 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { 1558 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() {
1571 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 1559 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
1572 // Exceptions apply only when the feature is enabled. 1560 // Exceptions apply only when the feature is enabled.
1573 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); 1561 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM);
1574 web_ui()->CallJavascriptFunction( 1562 web_ui()->CallJavascriptFunction(
1575 "ContentSettings.enableProtectedContentExceptions", 1563 "ContentSettings.enableProtectedContentExceptions",
1576 base::FundamentalValue(enable_exceptions)); 1564 base::FundamentalValue(enable_exceptions));
1577 } 1565 }
1578 1566
1579 } // namespace options 1567 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/profile_resetter/profile_resetter_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698