Chromium Code Reviews| Index: chrome/browser/ui/webui/settings/site_settings_handler.cc |
| diff --git a/chrome/browser/ui/webui/settings/site_settings_handler.cc b/chrome/browser/ui/webui/settings/site_settings_handler.cc |
| index 803d0f064c9a55166614d35e44589155f25d152d..008ec4f67507a299fe88fae059091246a50df035 100644 |
| --- a/chrome/browser/ui/webui/settings/site_settings_handler.cc |
| +++ b/chrome/browser/ui/webui/settings/site_settings_handler.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/macros.h" |
| #include "base/values.h" |
| #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| #include "chrome/browser/permissions/chooser_context_base.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -20,6 +21,7 @@ |
| #include "components/content_settings/core/browser/host_content_settings_map.h" |
| #include "components/content_settings/core/common/content_settings_types.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/notification_service.h" |
| #include "content/public/browser/web_ui.h" |
| #include "extensions/browser/extension_registry.h" |
| #include "extensions/common/permissions/api_permission.h" |
| @@ -28,7 +30,6 @@ |
| #include "storage/common/quota/quota_status_code.h" |
| #include "ui/base/text/bytes_formatting.h" |
| - |
| namespace settings { |
| namespace { |
| @@ -107,6 +108,12 @@ void AddExceptionsGrantedByHostedApps(content::BrowserContext* context, |
| SiteSettingsHandler::SiteSettingsHandler(Profile* profile) |
| : profile_(profile), observer_(this) { |
| + notification_registrar_.Add( |
| + this, chrome::NOTIFICATION_PROFILE_CREATED, |
| + content::NotificationService::AllSources()); |
| + notification_registrar_.Add( |
| + this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| + content::NotificationService::AllSources()); |
| } |
| SiteSettingsHandler::~SiteSettingsHandler() { |
| @@ -153,6 +160,10 @@ void SiteSettingsHandler::RegisterMessages() { |
| "isPatternValid", |
| base::Bind(&SiteSettingsHandler::HandleIsPatternValid, |
| base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback( |
| + "updateIncognitoStatus", |
| + base::Bind(&SiteSettingsHandler::HandleUpdateIncognitoStatus, |
| + base::Unretained(this))); |
| } |
| void SiteSettingsHandler::OnJavascriptAllowed() { |
| @@ -219,6 +230,39 @@ void SiteSettingsHandler::OnContentSettingChanged( |
| } |
| } |
| +void SiteSettingsHandler::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + switch (type) { |
| + case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
| + Profile* profile = content::Source<Profile>(source).ptr(); |
| + if (profile != profile_ && !IsOurIncognitoProfile(profile)) |
|
stevenjb
2016/09/01 15:47:55
Can this just be if (!profile->IsSameProfile(prfof
Finnur
2016/09/01 16:48:17
I'm a little worried that TestingProfile offers qu
stevenjb
2016/09/01 17:07:54
Hmm. It seems unfortunate that we have to write ou
Finnur
2016/09/02 15:44:14
No problem. Fixed!
|
| + break; |
| + SendIncognitoStatus(true, profile); |
|
stevenjb
2016/09/01 15:47:55
SendIncognitoStatus(true /* destroy */, profile);
Finnur
2016/09/01 16:48:17
Done.
|
| + |
| + HostContentSettingsMap* settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(profile); |
| + if (profile->IsOffTheRecord() && |
| + observer_.IsObserving(settings_map)) { |
| + observer_.Remove(settings_map); |
| + } |
| + |
| + break; |
| + } |
| + |
| + case chrome::NOTIFICATION_PROFILE_CREATED: { |
| + Profile* profile = content::Source<Profile>(source).ptr(); |
| + if (profile != profile_ && !IsOurIncognitoProfile(profile)) |
| + break; |
| + SendIncognitoStatus(false, profile); |
| + |
| + observer_.Add(HostContentSettingsMapFactory::GetForProfile(profile)); |
| + break; |
| + } |
| + } |
| +} |
| + |
| void SiteSettingsHandler::HandleFetchUsageTotal( |
| const base::ListValue* args) { |
| AllowJavascript(); |
| @@ -353,34 +397,51 @@ void SiteSettingsHandler::HandleGetExceptionList(const base::ListValue* args) { |
| static_cast<ContentSettingsType>(static_cast<int>( |
| site_settings::ContentSettingsTypeFromGroupName(type))); |
| - HostContentSettingsMap* map = |
| - HostContentSettingsMapFactory::GetForProfile(profile_); |
| std::unique_ptr<base::ListValue> exceptions(new base::ListValue); |
| + HostContentSettingsMap* map = |
| + HostContentSettingsMapFactory::GetForProfile(profile_); |
| AddExceptionsGrantedByHostedApps(profile_, APIPermissionFromGroupName(type), |
| exceptions.get()); |
| - |
| site_settings::GetExceptionsFromHostContentSettingsMap( |
| - map, content_type, web_ui(), exceptions.get()); |
| + map, content_type, web_ui(), false, exceptions.get()); |
| + |
| + if (profile_->HasOffTheRecordProfile()) { |
| + Profile* incognito = profile_->GetOffTheRecordProfile(); |
| + map = HostContentSettingsMapFactory::GetForProfile(incognito); |
| + site_settings::GetExceptionsFromHostContentSettingsMap( |
| + map, content_type, web_ui(), true, exceptions.get()); |
| + } |
| + |
| ResolveJavascriptCallback(*callback_id, *exceptions.get()); |
| } |
| void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( |
| const base::ListValue* args) { |
| - CHECK_EQ(3U, args->GetSize()); |
| + CHECK_EQ(4U, args->GetSize()); |
| std::string primary_pattern; |
| CHECK(args->GetString(0, &primary_pattern)); |
| std::string secondary_pattern; |
| CHECK(args->GetString(1, &secondary_pattern)); |
| std::string type; |
| CHECK(args->GetString(2, &type)); |
| + bool incognito; |
| + CHECK(args->GetBoolean(3, &incognito)); |
| ContentSettingsType content_type = |
| static_cast<ContentSettingsType>(static_cast<int>( |
| site_settings::ContentSettingsTypeFromGroupName(type))); |
| + Profile* profile = incognito |
| + ? (profile_->HasOffTheRecordProfile() |
| + ? profile_->GetOffTheRecordProfile() |
| + : nullptr) |
| + : profile_; |
|
stevenjb
2016/09/01 15:47:55
This is super confusing, maybe:
if (incognito) {
Finnur
2016/09/01 16:48:17
Fair enough. Done.
|
| + if (!profile) |
| + return; |
| + |
| HostContentSettingsMap* map = |
| - HostContentSettingsMapFactory::GetForProfile(profile_); |
| + HostContentSettingsMapFactory::GetForProfile(profile); |
| map->SetContentSettingCustomScope( |
| ContentSettingsPattern::FromString(primary_pattern), |
| secondary_pattern.empty() ? |
| @@ -391,7 +452,7 @@ void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( |
| void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin( |
| const base::ListValue* args) { |
| - CHECK_EQ(4U, args->GetSize()); |
| + CHECK_EQ(5U, args->GetSize()); |
| std::string primary_pattern; |
| CHECK(args->GetString(0, &primary_pattern)); |
| std::string secondary_pattern; |
| @@ -400,6 +461,8 @@ void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin( |
| CHECK(args->GetString(2, &type)); |
| std::string value; |
| CHECK(args->GetString(3, &value)); |
| + bool incognito; |
| + CHECK(args->GetBoolean(4, &incognito)); |
| ContentSettingsType content_type = |
| static_cast<ContentSettingsType>(static_cast<int>( |
| @@ -407,8 +470,16 @@ void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin( |
| ContentSetting setting; |
| CHECK(content_settings::ContentSettingFromString(value, &setting)); |
| + Profile* profile = incognito |
| + ? (profile_->HasOffTheRecordProfile() |
| + ? profile_->GetOffTheRecordProfile() |
| + : nullptr) |
| + : profile_; |
| + if (!profile) |
| + return; |
|
stevenjb
2016/09/01 15:47:55
ditto
Finnur
2016/09/01 16:48:17
Done.
|
| + |
| HostContentSettingsMap* map = |
| - HostContentSettingsMapFactory::GetForProfile(profile_); |
| + HostContentSettingsMapFactory::GetForProfile(profile); |
| map->SetContentSettingCustomScope( |
| ContentSettingsPattern::FromString(primary_pattern), |
| secondary_pattern.empty() ? |
| @@ -431,4 +502,35 @@ void SiteSettingsHandler::HandleIsPatternValid( |
| *callback_id, base::FundamentalValue(pattern.IsValid())); |
| } |
| +void SiteSettingsHandler::HandleUpdateIncognitoStatus( |
| + const base::ListValue* args) { |
| + AllowJavascript(); |
| + SendIncognitoStatus(false, profile_); |
| +} |
| + |
| +bool SiteSettingsHandler::IsOurIncognitoProfile(Profile* profile) { |
| + return profile_->HasOffTheRecordProfile() && |
| + profile == profile_->GetOffTheRecordProfile(); |
| +} |
| + |
| +void SiteSettingsHandler::SendIncognitoStatus(bool destroy, Profile* profile) { |
| + if (!IsJavascriptAllowed()) |
| + return; |
| + |
| + // When an incognito profile is destroyed, it sends out the destruction |
| + // message before destroying, so HasOffTheRecordProfile for profile_ won't |
| + // return false until after the profile actually been destroyed. |
|
stevenjb
2016/09/01 15:47:55
"destroy" implies that this function does the dest
Finnur
2016/09/01 16:48:17
Makes sense. Done.
|
| + bool incognito_enabled = profile_->HasOffTheRecordProfile(); |
| + if (incognito_enabled && destroy && |
| + profile == profile_->GetOffTheRecordProfile()) { |
| + incognito_enabled = false; // Our incognito profile was just destroyed. |
| + } |
|
stevenjb
2016/09/01 15:47:55
Combine these:
bool incognito_enabled = profile_-
Finnur
2016/09/01 16:48:17
Done.
|
| + |
| + if (profile == profile_ || IsOurIncognitoProfile(profile)) { |
| + CallJavascriptFunction("cr.webUIListenerCallback", |
| + base::StringValue("onIncognitoStatusChanged"), |
| + base::FundamentalValue(incognito_enabled)); |
| + } |
| +} |
| + |
| } // namespace settings |