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

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

Issue 2021343003: MD Site Settings: Add five new top level categories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback and add icons Created 4 years, 6 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 "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" 8 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 base::StringValue(clearing_origin_)); 97 base::StringValue(clearing_origin_));
98 } 98 }
99 } 99 }
100 100
101 void SiteSettingsHandler::OnContentSettingChanged( 101 void SiteSettingsHandler::OnContentSettingChanged(
102 const ContentSettingsPattern& primary_pattern, 102 const ContentSettingsPattern& primary_pattern,
103 const ContentSettingsPattern& secondary_pattern, 103 const ContentSettingsPattern& secondary_pattern,
104 ContentSettingsType content_type, 104 ContentSettingsType content_type,
105 std::string resource_identifier) { 105 std::string resource_identifier) {
106 if (primary_pattern.ToString().empty()) { 106 if (primary_pattern.ToString().empty()) {
107 CallJavascriptFunction("cr.webUIListenerCallback", 107 CallJavascriptFunction(
108 base::StringValue("contentSettingCategoryChanged"), 108 "cr.webUIListenerCallback",
109 base::FundamentalValue(content_type)); 109 base::StringValue("contentSettingCategoryChanged"),
110 base::StringValue(site_settings::ContentSettingsTypeToGroupName(
111 content_type)));
110 } else { 112 } else {
111 CallJavascriptFunction( 113 CallJavascriptFunction(
112 "cr.webUIListenerCallback", 114 "cr.webUIListenerCallback",
113 base::StringValue("contentSettingSitePermissionChanged"), 115 base::StringValue("contentSettingSitePermissionChanged"),
114 base::FundamentalValue(content_type), 116 base::StringValue(site_settings::ContentSettingsTypeToGroupName(
117 content_type)),
115 base::StringValue(primary_pattern.ToString())); 118 base::StringValue(primary_pattern.ToString()));
116 } 119 }
117 } 120 }
118 121
119 void SiteSettingsHandler::HandleFetchUsageTotal( 122 void SiteSettingsHandler::HandleFetchUsageTotal(
120 const base::ListValue* args) { 123 const base::ListValue* args) {
121 AllowJavascript(); 124 AllowJavascript();
122 125
123 CHECK_EQ(1U, args->GetSize()); 126 CHECK_EQ(1U, args->GetSize());
124 std::string host; 127 std::string host;
125 CHECK(args->GetString(0, &host)); 128 CHECK(args->GetString(0, &host));
126 usage_host_ = host; 129 usage_host_ = host;
127 130
128 scoped_refptr<StorageInfoFetcher> storage_info_fetcher 131 scoped_refptr<StorageInfoFetcher> storage_info_fetcher
129 = new StorageInfoFetcher(profile_); 132 = new StorageInfoFetcher(profile_);
130 storage_info_fetcher->FetchStorageInfo( 133 storage_info_fetcher->FetchStorageInfo(
131 base::Bind(&SiteSettingsHandler::OnGetUsageInfo, base::Unretained(this))); 134 base::Bind(&SiteSettingsHandler::OnGetUsageInfo, base::Unretained(this)));
132 } 135 }
133 136
134 void SiteSettingsHandler::HandleClearUsage( 137 void SiteSettingsHandler::HandleClearUsage(
135 const base::ListValue* args) { 138 const base::ListValue* args) {
136 CHECK_EQ(2U, args->GetSize()); 139 CHECK_EQ(2U, args->GetSize());
137 std::string origin; 140 std::string origin;
138 CHECK(args->GetString(0, &origin)); 141 CHECK(args->GetString(0, &origin));
139 double type; 142 std::string type;
140 CHECK(args->GetDouble(1, &type)); 143 CHECK(args->GetString(1, &type));
141 144
142 GURL url(origin); 145 GURL url(origin);
143 if (url.is_valid()) { 146 if (url.is_valid()) {
144 clearing_origin_ = origin; 147 clearing_origin_ = origin;
145 148
146 // Start by clearing the storage data asynchronously. 149 // Start by clearing the storage data asynchronously.
147 scoped_refptr<StorageInfoFetcher> storage_info_fetcher 150 scoped_refptr<StorageInfoFetcher> storage_info_fetcher
148 = new StorageInfoFetcher(profile_); 151 = new StorageInfoFetcher(profile_);
149 storage_info_fetcher->ClearStorage( 152 storage_info_fetcher->ClearStorage(
150 url.host(), 153 url.host(),
151 static_cast<storage::StorageType>(static_cast<int>(type)), 154 static_cast<storage::StorageType>(static_cast<int>(
155 site_settings::ContentSettingsTypeFromGroupName(type))),
152 base::Bind(&SiteSettingsHandler::OnUsageInfoCleared, 156 base::Bind(&SiteSettingsHandler::OnUsageInfoCleared,
153 base::Unretained(this))); 157 base::Unretained(this)));
154 158
155 // Also clear the *local* storage data. 159 // Also clear the *local* storage data.
156 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper = 160 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper =
157 new BrowsingDataLocalStorageHelper(profile_); 161 new BrowsingDataLocalStorageHelper(profile_);
158 local_storage_helper->DeleteOrigin(url); 162 local_storage_helper->DeleteOrigin(url);
159 } 163 }
160 } 164 }
161 165
162 void SiteSettingsHandler::HandleSetDefaultValueForContentType( 166 void SiteSettingsHandler::HandleSetDefaultValueForContentType(
163 const base::ListValue* args) { 167 const base::ListValue* args) {
164 CHECK_EQ(2U, args->GetSize()); 168 CHECK_EQ(2U, args->GetSize());
165 double content_type; 169 std::string content_type;
166 CHECK(args->GetDouble(0, &content_type)); 170 CHECK(args->GetString(0, &content_type));
167 std::string setting; 171 std::string setting;
168 CHECK(args->GetString(1, &setting)); 172 CHECK(args->GetString(1, &setting));
169 ContentSetting default_setting; 173 ContentSetting default_setting;
170 CHECK(content_settings::ContentSettingFromString(setting, &default_setting)); 174 CHECK(content_settings::ContentSettingFromString(setting, &default_setting));
171 175
172 HostContentSettingsMap* map = 176 HostContentSettingsMap* map =
173 HostContentSettingsMapFactory::GetForProfile(profile_); 177 HostContentSettingsMapFactory::GetForProfile(profile_);
174 map->SetDefaultContentSetting( 178 map->SetDefaultContentSetting(
175 static_cast<ContentSettingsType>(static_cast<int>(content_type)), 179 static_cast<ContentSettingsType>(static_cast<int>(
180 site_settings::ContentSettingsTypeFromGroupName(content_type))),
176 default_setting); 181 default_setting);
177 } 182 }
178 183
179 void SiteSettingsHandler::HandleGetDefaultValueForContentType( 184 void SiteSettingsHandler::HandleGetDefaultValueForContentType(
180 const base::ListValue* args) { 185 const base::ListValue* args) {
181 AllowJavascript(); 186 AllowJavascript();
182 187
183 CHECK_EQ(2U, args->GetSize()); 188 CHECK_EQ(2U, args->GetSize());
184 const base::Value* callback_id; 189 const base::Value* callback_id;
185 CHECK(args->Get(0, &callback_id)); 190 CHECK(args->Get(0, &callback_id));
186 double type; 191 std::string type;
187 CHECK(args->GetDouble(1, &type)); 192 CHECK(args->GetString(1, &type));
188 193
189 ContentSettingsType content_type = 194 ContentSettingsType content_type =
190 static_cast<ContentSettingsType>(static_cast<int>(type)); 195 static_cast<ContentSettingsType>(static_cast<int>(
196 site_settings::ContentSettingsTypeFromGroupName(type)));
191 HostContentSettingsMap* map = 197 HostContentSettingsMap* map =
192 HostContentSettingsMapFactory::GetForProfile(profile_); 198 HostContentSettingsMapFactory::GetForProfile(profile_);
193 ContentSetting setting = map->GetDefaultContentSetting(content_type, nullptr); 199 ContentSetting setting = map->GetDefaultContentSetting(content_type, nullptr);
194 200
195 // FullScreen is Allow vs. Ask. 201 // FullScreen is Allow vs. Ask.
196 bool enabled; 202 bool enabled;
197 if (content_type == CONTENT_SETTINGS_TYPE_FULLSCREEN) 203 if (content_type == CONTENT_SETTINGS_TYPE_FULLSCREEN)
198 enabled = setting != CONTENT_SETTING_ASK; 204 enabled = setting != CONTENT_SETTING_ASK;
199 else 205 else
200 enabled = setting != CONTENT_SETTING_BLOCK; 206 enabled = setting != CONTENT_SETTING_BLOCK;
201 207
202 ResolveJavascriptCallback(*callback_id, base::FundamentalValue(enabled)); 208 ResolveJavascriptCallback(*callback_id, base::FundamentalValue(enabled));
203 } 209 }
204 210
205 void SiteSettingsHandler::HandleGetExceptionList(const base::ListValue* args) { 211 void SiteSettingsHandler::HandleGetExceptionList(const base::ListValue* args) {
206 AllowJavascript(); 212 AllowJavascript();
207 213
208 CHECK_EQ(2U, args->GetSize()); 214 CHECK_EQ(2U, args->GetSize());
209 const base::Value* callback_id; 215 const base::Value* callback_id;
210 CHECK(args->Get(0, &callback_id)); 216 CHECK(args->Get(0, &callback_id));
211 double type; 217 std::string type;
212 CHECK(args->GetDouble(1, &type)); 218 CHECK(args->GetString(1, &type));
213 ContentSettingsType content_type = 219 ContentSettingsType content_type =
214 static_cast<ContentSettingsType>(static_cast<int>(type)); 220 static_cast<ContentSettingsType>(static_cast<int>(
221 site_settings::ContentSettingsTypeFromGroupName(type)));
215 222
216 HostContentSettingsMap* map = 223 HostContentSettingsMap* map =
217 HostContentSettingsMapFactory::GetForProfile(profile_); 224 HostContentSettingsMapFactory::GetForProfile(profile_);
218 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); 225 std::unique_ptr<base::ListValue> exceptions(new base::ListValue);
219 site_settings::GetExceptionsFromHostContentSettingsMap( 226 site_settings::GetExceptionsFromHostContentSettingsMap(
220 map, content_type, web_ui(), exceptions.get()); 227 map, content_type, web_ui(), exceptions.get());
221 ResolveJavascriptCallback(*callback_id, *exceptions.get()); 228 ResolveJavascriptCallback(*callback_id, *exceptions.get());
222 } 229 }
223 230
224 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( 231 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin(
225 const base::ListValue* args) { 232 const base::ListValue* args) {
226 CHECK_EQ(3U, args->GetSize()); 233 CHECK_EQ(3U, args->GetSize());
227 std::string primary_pattern; 234 std::string primary_pattern;
228 CHECK(args->GetString(0, &primary_pattern)); 235 CHECK(args->GetString(0, &primary_pattern));
229 std::string secondary_pattern; 236 std::string secondary_pattern;
230 CHECK(args->GetString(1, &secondary_pattern)); 237 CHECK(args->GetString(1, &secondary_pattern));
231 double type; 238 std::string type;
232 CHECK(args->GetDouble(2, &type)); 239 CHECK(args->GetString(2, &type));
233 240
234 ContentSettingsType content_type = 241 ContentSettingsType content_type =
235 static_cast<ContentSettingsType>(static_cast<int>(type)); 242 static_cast<ContentSettingsType>(static_cast<int>(
243 site_settings::ContentSettingsTypeFromGroupName(type)));
236 244
237 HostContentSettingsMap* map = 245 HostContentSettingsMap* map =
238 HostContentSettingsMapFactory::GetForProfile(profile_); 246 HostContentSettingsMapFactory::GetForProfile(profile_);
239 map->SetContentSettingCustomScope( 247 map->SetContentSettingCustomScope(
240 ContentSettingsPattern::FromString(primary_pattern), 248 ContentSettingsPattern::FromString(primary_pattern),
241 secondary_pattern.empty() ? 249 secondary_pattern.empty() ?
242 ContentSettingsPattern::Wildcard() : 250 ContentSettingsPattern::Wildcard() :
243 ContentSettingsPattern::FromString(secondary_pattern), 251 ContentSettingsPattern::FromString(secondary_pattern),
244 content_type, "", CONTENT_SETTING_DEFAULT); 252 content_type, "", CONTENT_SETTING_DEFAULT);
245 } 253 }
246 254
247 void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin( 255 void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin(
248 const base::ListValue* args) { 256 const base::ListValue* args) {
249 CHECK_EQ(4U, args->GetSize()); 257 CHECK_EQ(4U, args->GetSize());
250 std::string primary_pattern; 258 std::string primary_pattern;
251 CHECK(args->GetString(0, &primary_pattern)); 259 CHECK(args->GetString(0, &primary_pattern));
252 std::string secondary_pattern; 260 std::string secondary_pattern;
253 CHECK(args->GetString(1, &secondary_pattern)); 261 CHECK(args->GetString(1, &secondary_pattern));
254 double type; 262 std::string type;
255 CHECK(args->GetDouble(2, &type)); 263 CHECK(args->GetString(2, &type));
256 std::string value; 264 std::string value;
257 CHECK(args->GetString(3, &value)); 265 CHECK(args->GetString(3, &value));
258 266
259 ContentSettingsType content_type = 267 ContentSettingsType content_type =
260 static_cast<ContentSettingsType>(static_cast<int>(type)); 268 static_cast<ContentSettingsType>(static_cast<int>(
269 site_settings::ContentSettingsTypeFromGroupName(type)));
261 ContentSetting setting; 270 ContentSetting setting;
262 CHECK(content_settings::ContentSettingFromString(value, &setting)); 271 CHECK(content_settings::ContentSettingFromString(value, &setting));
263 272
264 HostContentSettingsMap* map = 273 HostContentSettingsMap* map =
265 HostContentSettingsMapFactory::GetForProfile(profile_); 274 HostContentSettingsMapFactory::GetForProfile(profile_);
266 map->SetContentSettingCustomScope( 275 map->SetContentSettingCustomScope(
267 ContentSettingsPattern::FromString(primary_pattern), 276 ContentSettingsPattern::FromString(primary_pattern),
268 secondary_pattern.empty() ? 277 secondary_pattern.empty() ?
269 ContentSettingsPattern::Wildcard() : 278 ContentSettingsPattern::Wildcard() :
270 ContentSettingsPattern::FromString(secondary_pattern), 279 ContentSettingsPattern::FromString(secondary_pattern),
271 content_type, "", setting); 280 content_type, "", setting);
272 } 281 }
273 282
274 void SiteSettingsHandler::HandleIsPatternValid( 283 void SiteSettingsHandler::HandleIsPatternValid(
275 const base::ListValue* args) { 284 const base::ListValue* args) {
276 CHECK_EQ(2U, args->GetSize()); 285 CHECK_EQ(2U, args->GetSize());
277 const base::Value* callback_id; 286 const base::Value* callback_id;
278 CHECK(args->Get(0, &callback_id)); 287 CHECK(args->Get(0, &callback_id));
279 std::string pattern_string; 288 std::string pattern_string;
280 CHECK(args->GetString(1, &pattern_string)); 289 CHECK(args->GetString(1, &pattern_string));
281 290
282 ContentSettingsPattern pattern = 291 ContentSettingsPattern pattern =
283 ContentSettingsPattern::FromString(pattern_string); 292 ContentSettingsPattern::FromString(pattern_string);
284 ResolveJavascriptCallback( 293 ResolveJavascriptCallback(
285 *callback_id, base::FundamentalValue(pattern.IsValid())); 294 *callback_id, base::FundamentalValue(pattern.IsValid()));
286 } 295 }
287 296
288 } // namespace settings 297 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698