Chromium Code Reviews| Index: chrome/browser/ui/webui/options/content_settings_handler.cc |
| diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc |
| index 990daf5487d587a0cd3dbdabe0bc8aa3914e6e2c..f04ce10763c083d4fe580a9111521922ad68bfd5 100644 |
| --- a/chrome/browser/ui/webui/options/content_settings_handler.cc |
| +++ b/chrome/browser/ui/webui/options/content_settings_handler.cc |
| @@ -30,6 +30,8 @@ |
| #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| #include "chrome/browser/permissions/chooser_context_base.h" |
| +#include "chrome/browser/permissions/permission_uma_util.h" |
| +#include "chrome/browser/permissions/permission_util.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/browser_list.h" |
| #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
| @@ -790,7 +792,8 @@ void ContentSettingsHandler::UpdateSettingDefaultFromModel( |
| ContentSettingsType type) { |
| std::string provider_id; |
| ContentSetting default_setting = |
| - GetContentSettingsMap()->GetDefaultContentSetting(type, &provider_id); |
| + HostContentSettingsMapFactory::GetForProfile(GetProfile()) |
| + ->GetDefaultContentSetting(type, &provider_id); |
| #if defined(ENABLE_PLUGINS) |
| default_setting = |
| @@ -832,6 +835,8 @@ void ContentSettingsHandler::UpdateSettingDefaultFromModel( |
| void ContentSettingsHandler::UpdateMediaSettingsFromPrefs( |
| ContentSettingsType type) { |
| PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); |
| + HostContentSettingsMap* settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(GetProfile()); |
| MediaSettingsInfo::ForOneType& settings = media_settings_->forType(type); |
| std::string policy_pref = (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) |
| ? prefs::kAudioCaptureAllowed |
| @@ -840,7 +845,7 @@ void ContentSettingsHandler::UpdateMediaSettingsFromPrefs( |
| settings.policy_disable = !prefs->GetBoolean(policy_pref) && |
| prefs->IsManagedPreference(policy_pref); |
| settings.default_setting = |
| - GetContentSettingsMap()->GetDefaultContentSetting(type, NULL); |
| + settings_map->GetDefaultContentSetting(type, nullptr); |
| settings.default_setting_initialized = true; |
| UpdateFlashMediaLinksVisibility(type); |
| @@ -1007,13 +1012,12 @@ void ContentSettingsHandler::UpdateNotificationExceptionsView() { |
| void ContentSettingsHandler::CompareMediaExceptionsWithFlash( |
| ContentSettingsType type) { |
| MediaSettingsInfo::ForOneType& settings = media_settings_->forType(type); |
| + HostContentSettingsMap* settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(GetProfile()); |
| base::ListValue exceptions; |
| - site_settings::GetExceptionsFromHostContentSettingsMap( |
| - GetContentSettingsMap(), |
| - type, |
| - web_ui(), |
| - &exceptions); |
| + site_settings::GetExceptionsFromHostContentSettingsMap(settings_map, type, |
| + web_ui(), &exceptions); |
| settings.exceptions.clear(); |
| for (base::ListValue::const_iterator entry = exceptions.begin(); |
| @@ -1151,8 +1155,10 @@ void ContentSettingsHandler::UpdateZoomLevelsExceptionsView() { |
| void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( |
| ContentSettingsType type) { |
| base::ListValue exceptions; |
| - site_settings::GetExceptionsFromHostContentSettingsMap( |
| - GetContentSettingsMap(), type, web_ui(), &exceptions); |
| + HostContentSettingsMap* settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(GetProfile()); |
| + site_settings::GetExceptionsFromHostContentSettingsMap(settings_map, type, |
| + web_ui(), &exceptions); |
| base::StringValue type_string( |
| site_settings::ContentSettingsTypeToGroupName(type)); |
| web_ui()->CallJavascriptFunctionUnsafe("ContentSettings.setExceptions", |
| @@ -1182,7 +1188,8 @@ void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( |
| void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( |
| ContentSettingsType type) { |
| - const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); |
| + const HostContentSettingsMap* otr_settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(GetOTRProfile()); |
| if (!otr_settings_map) |
| return; |
| base::ListValue exceptions; |
| @@ -1297,22 +1304,29 @@ void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( |
| DCHECK(rv); |
| // The fourth argument to this handler is optional. |
| - std::string secondary_pattern; |
| + std::string secondary_pattern_string; |
| if (args->GetSize() >= 4U) { |
| - rv = args->GetString(3, &secondary_pattern); |
| + rv = args->GetString(3, &secondary_pattern_string); |
| DCHECK(rv); |
| } |
| - HostContentSettingsMap* settings_map = |
| - mode == "normal" ? GetContentSettingsMap() : |
| - GetOTRContentSettingsMap(); |
| - if (settings_map) { |
| - settings_map->SetContentSettingCustomScope( |
| - ContentSettingsPattern::FromString(pattern), |
| - secondary_pattern.empty() |
| + Profile* profile = mode == "normal" ? GetProfile() : GetOTRProfile(); |
| + if (profile) { |
|
stevenjb
2016/07/27 16:37:07
if (!profile) return;
stefanocs
2016/07/28 02:03:30
Done.
|
| + HostContentSettingsMap* settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(profile); |
| + ContentSettingsPattern primary_pattern = |
| + ContentSettingsPattern::FromString(pattern); |
| + ContentSettingsPattern secondary_pattern = |
| + secondary_pattern_string.empty() |
| ? ContentSettingsPattern::Wildcard() |
| - : ContentSettingsPattern::FromString(secondary_pattern), |
| - type, std::string(), CONTENT_SETTING_DEFAULT); |
| + : ContentSettingsPattern::FromString(secondary_pattern_string); |
| + PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| + profile, primary_pattern, secondary_pattern, type, |
| + PermissionSourceUI::SITE_SETTINGS); |
| + |
| + settings_map->SetContentSettingCustomScope( |
| + primary_pattern, secondary_pattern, type, std::string(), |
| + CONTENT_SETTING_DEFAULT); |
| } |
| } |
| @@ -1468,13 +1482,11 @@ void ContentSettingsHandler::SetException(const base::ListValue* args) { |
| type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| NOTREACHED(); |
|
stevenjb
2016/07/27 16:37:07
Can you replace this with a DCHECK?
stefanocs
2016/07/28 02:03:30
Done.
|
| } else { |
|
stevenjb
2016/07/27 16:37:07
No else.
stefanocs
2016/07/28 02:03:30
Done.
|
| - HostContentSettingsMap* settings_map = |
| - mode == "normal" ? GetContentSettingsMap() : |
| - GetOTRContentSettingsMap(); |
| + Profile* profile = mode == "normal" ? GetProfile() : GetOTRProfile(); |
| - // The settings map could be null if the mode was OTR but the OTR profile |
| + // The profile could be nullptr if the mode was OTR but the OTR profile |
| // got destroyed before we received this message. |
| - if (!settings_map) |
| + if (!profile) |
| return; |
| ContentSetting setting_type; |
| @@ -1482,6 +1494,14 @@ void ContentSettingsHandler::SetException(const base::ListValue* args) { |
| content_settings::ContentSettingFromString(setting, &setting_type); |
| DCHECK(result); |
| + HostContentSettingsMap* settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(profile); |
| + |
| + PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| + profile, ContentSettingsPattern::FromString(pattern), |
| + ContentSettingsPattern::Wildcard(), type, |
| + PermissionSourceUI::SITE_SETTINGS); |
| + |
| settings_map->SetContentSettingCustomScope( |
| ContentSettingsPattern::FromString(pattern), |
| ContentSettingsPattern::Wildcard(), type, std::string(), setting_type); |
| @@ -1508,9 +1528,8 @@ void ContentSettingsHandler::CheckExceptionPatternValidity( |
| base::FundamentalValue(pattern.IsValid())); |
| } |
| -HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { |
| - return HostContentSettingsMapFactory::GetForProfile( |
| - Profile::FromWebUI(web_ui())); |
| +Profile* ContentSettingsHandler::GetProfile() { |
| + return Profile::FromWebUI(web_ui()); |
| } |
| ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { |
| @@ -1518,13 +1537,10 @@ ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { |
| GetBrowserContext(web_ui())); |
| } |
| -HostContentSettingsMap* |
| - ContentSettingsHandler::GetOTRContentSettingsMap() { |
| - Profile* profile = Profile::FromWebUI(web_ui()); |
| - if (profile->HasOffTheRecordProfile()) |
| - return HostContentSettingsMapFactory::GetForProfile( |
| - profile->GetOffTheRecordProfile()); |
| - return NULL; |
| +Profile* ContentSettingsHandler::GetOTRProfile() { |
| + return GetProfile()->HasOffTheRecordProfile() |
| + ? GetProfile()->GetOffTheRecordProfile() |
| + : nullptr; |
| } |
| void ContentSettingsHandler::RefreshFlashMediaSettings() { |