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

Side by Side Diff: chrome/browser/ui/webui/settings/site_settings_handler.cc

Issue 1698093007: Convert SiteSettingsCategory to use the HostContentSettingsMap instead of (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 10 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/settings/site_settings_handler.h" 5 #include "chrome/browser/ui/webui/settings/site_settings_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" 9 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "components/content_settings/core/browser/host_content_settings_map.h"
11 #include "components/content_settings/core/common/content_settings_types.h" 13 #include "components/content_settings/core/common/content_settings_types.h"
12 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/web_ui.h" 15 #include "content/public/browser/web_ui.h"
14 #include "storage/browser/quota/quota_manager.h" 16 #include "storage/browser/quota/quota_manager.h"
15 #include "storage/common/quota/quota_status_code.h" 17 #include "storage/common/quota/quota_status_code.h"
16 #include "ui/base/text/bytes_formatting.h" 18 #include "ui/base/text/bytes_formatting.h"
17 19
18 namespace settings { 20 namespace settings {
19 21
20 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) 22 SiteSettingsHandler::SiteSettingsHandler(Profile* profile)
21 : profile_(profile) { 23 : profile_(profile) {
22 } 24 }
23 25
24 SiteSettingsHandler::~SiteSettingsHandler() { 26 SiteSettingsHandler::~SiteSettingsHandler() {
25 } 27 }
26 28
27 void SiteSettingsHandler::RegisterMessages() { 29 void SiteSettingsHandler::RegisterMessages() {
28 web_ui()->RegisterMessageCallback( 30 web_ui()->RegisterMessageCallback(
29 "fetchUsageTotal", 31 "fetchUsageTotal",
30 base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal, 32 base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal,
31 base::Unretained(this))); 33 base::Unretained(this)));
32 web_ui()->RegisterMessageCallback( 34 web_ui()->RegisterMessageCallback(
33 "clearUsage", 35 "clearUsage",
34 base::Bind(&SiteSettingsHandler::HandleClearUsage, 36 base::Bind(&SiteSettingsHandler::HandleClearUsage,
35 base::Unretained(this))); 37 base::Unretained(this)));
38 web_ui()->RegisterMessageCallback(
39 "setDefaultValueForContentType",
40 base::Bind(&SiteSettingsHandler::HandleSetDefaultValueForContentType,
41 base::Unretained(this)));
42 web_ui()->RegisterMessageCallback(
43 "getDefaultValueForContentType",
44 base::Bind(&SiteSettingsHandler::HandleGetDefaultValueForContentType,
45 base::Unretained(this)));
36 } 46 }
37 47
38 void SiteSettingsHandler::OnGetUsageInfo( 48 void SiteSettingsHandler::OnGetUsageInfo(
39 const storage::UsageInfoEntries& entries) { 49 const storage::UsageInfoEntries& entries) {
40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
41 51
42 for (const auto& entry : entries) { 52 for (const auto& entry : entries) {
43 if (entry.usage <= 0) continue; 53 if (entry.usage <= 0) continue;
44 if (entry.host == usage_host_) { 54 if (entry.host == usage_host_) {
45 web_ui()->CallJavascriptFunction( 55 web_ui()->CallJavascriptFunction(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 base::Bind(&SiteSettingsHandler::OnUsageInfoCleared, 104 base::Bind(&SiteSettingsHandler::OnUsageInfoCleared,
95 base::Unretained(this))); 105 base::Unretained(this)));
96 106
97 // Also clear the *local* storage data. 107 // Also clear the *local* storage data.
98 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper = 108 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper =
99 new BrowsingDataLocalStorageHelper(profile_); 109 new BrowsingDataLocalStorageHelper(profile_);
100 local_storage_helper->DeleteOrigin(url); 110 local_storage_helper->DeleteOrigin(url);
101 } 111 }
102 } 112 }
103 113
114 void SiteSettingsHandler::HandleSetDefaultValueForContentType(
115 const base::ListValue* args) {
116 CHECK_EQ(2U, args->GetSize());
117 int content_type;
118 CHECK(args->GetInteger(0, &content_type));
119 int default_setting;
120 CHECK(args->GetInteger(1, &default_setting));
121
122 HostContentSettingsMap* map =
123 HostContentSettingsMapFactory::GetForProfile(profile_);
124 map->SetDefaultContentSetting(static_cast<ContentSettingsType>(content_type),
125 static_cast<ContentSetting>(default_setting));
126 }
127
128 void SiteSettingsHandler::HandleGetDefaultValueForContentType(
129 const base::ListValue* args) {
130 CHECK_EQ(2U, args->GetSize());
131 const base::Value* callback_id;
132 CHECK(args->Get(0, &callback_id));
133 int type;
134 CHECK(args->GetInteger(1, &type));
135
136 ContentSettingsType content_type = static_cast<ContentSettingsType>(type);
137 HostContentSettingsMap* map =
138 HostContentSettingsMapFactory::GetForProfile(profile_);
139 ContentSetting setting = map->GetDefaultContentSetting(content_type, nullptr);
140
141 // FullScreen is Allow vs. Ask.
142 bool enabled;
143 if (content_type == CONTENT_SETTINGS_TYPE_FULLSCREEN)
144 enabled = setting != CONTENT_SETTING_ASK;
145 else
146 enabled = setting != CONTENT_SETTING_BLOCK;
147
148 CallJavascriptCallback(*callback_id, base::FundamentalValue(enabled));
149 }
150
104 } // namespace settings 151 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698