OLD | NEW |
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 = new StorageInfoFetcher(profile_); | 129 = new StorageInfoFetcher(profile_); |
130 storage_info_fetcher->FetchStorageInfo( | 130 storage_info_fetcher->FetchStorageInfo( |
131 base::Bind(&SiteSettingsHandler::OnGetUsageInfo, base::Unretained(this))); | 131 base::Bind(&SiteSettingsHandler::OnGetUsageInfo, base::Unretained(this))); |
132 } | 132 } |
133 | 133 |
134 void SiteSettingsHandler::HandleClearUsage( | 134 void SiteSettingsHandler::HandleClearUsage( |
135 const base::ListValue* args) { | 135 const base::ListValue* args) { |
136 CHECK_EQ(2U, args->GetSize()); | 136 CHECK_EQ(2U, args->GetSize()); |
137 std::string origin; | 137 std::string origin; |
138 CHECK(args->GetString(0, &origin)); | 138 CHECK(args->GetString(0, &origin)); |
139 double type; | 139 std::string type; |
140 CHECK(args->GetDouble(1, &type)); | 140 CHECK(args->GetString(1, &type)); |
141 | 141 |
142 GURL url(origin); | 142 GURL url(origin); |
| 143 LOG(ERROR) << url.spec().c_str() << " " << type; |
143 if (url.is_valid()) { | 144 if (url.is_valid()) { |
| 145 LOG(ERROR) << "Clearing!"; |
144 clearing_origin_ = origin; | 146 clearing_origin_ = origin; |
145 | 147 |
146 // Start by clearing the storage data asynchronously. | 148 // Start by clearing the storage data asynchronously. |
147 scoped_refptr<StorageInfoFetcher> storage_info_fetcher | 149 scoped_refptr<StorageInfoFetcher> storage_info_fetcher |
148 = new StorageInfoFetcher(profile_); | 150 = new StorageInfoFetcher(profile_); |
149 storage_info_fetcher->ClearStorage( | 151 storage_info_fetcher->ClearStorage( |
150 url.host(), | 152 url.host(), |
151 static_cast<storage::StorageType>(static_cast<int>(type)), | 153 static_cast<storage::StorageType>(static_cast<int>( |
| 154 site_settings::ContentSettingsTypeFromGroupName(type))), |
152 base::Bind(&SiteSettingsHandler::OnUsageInfoCleared, | 155 base::Bind(&SiteSettingsHandler::OnUsageInfoCleared, |
153 base::Unretained(this))); | 156 base::Unretained(this))); |
154 | 157 |
155 // Also clear the *local* storage data. | 158 // Also clear the *local* storage data. |
156 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper = | 159 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper = |
157 new BrowsingDataLocalStorageHelper(profile_); | 160 new BrowsingDataLocalStorageHelper(profile_); |
158 local_storage_helper->DeleteOrigin(url); | 161 local_storage_helper->DeleteOrigin(url); |
159 } | 162 } |
160 } | 163 } |
161 | 164 |
162 void SiteSettingsHandler::HandleSetDefaultValueForContentType( | 165 void SiteSettingsHandler::HandleSetDefaultValueForContentType( |
163 const base::ListValue* args) { | 166 const base::ListValue* args) { |
164 CHECK_EQ(2U, args->GetSize()); | 167 CHECK_EQ(2U, args->GetSize()); |
165 double content_type; | 168 std::string content_type; |
166 CHECK(args->GetDouble(0, &content_type)); | 169 CHECK(args->GetString(0, &content_type)); |
167 std::string setting; | 170 std::string setting; |
168 CHECK(args->GetString(1, &setting)); | 171 CHECK(args->GetString(1, &setting)); |
169 ContentSetting default_setting; | 172 ContentSetting default_setting; |
170 CHECK(content_settings::ContentSettingFromString(setting, &default_setting)); | 173 CHECK(content_settings::ContentSettingFromString(setting, &default_setting)); |
171 | 174 |
172 HostContentSettingsMap* map = | 175 HostContentSettingsMap* map = |
173 HostContentSettingsMapFactory::GetForProfile(profile_); | 176 HostContentSettingsMapFactory::GetForProfile(profile_); |
174 map->SetDefaultContentSetting( | 177 map->SetDefaultContentSetting( |
175 static_cast<ContentSettingsType>(static_cast<int>(content_type)), | 178 static_cast<ContentSettingsType>(static_cast<int>( |
| 179 site_settings::ContentSettingsTypeFromGroupName(content_type))), |
176 default_setting); | 180 default_setting); |
177 } | 181 } |
178 | 182 |
179 void SiteSettingsHandler::HandleGetDefaultValueForContentType( | 183 void SiteSettingsHandler::HandleGetDefaultValueForContentType( |
180 const base::ListValue* args) { | 184 const base::ListValue* args) { |
181 AllowJavascript(); | 185 AllowJavascript(); |
182 | 186 |
183 CHECK_EQ(2U, args->GetSize()); | 187 CHECK_EQ(2U, args->GetSize()); |
184 const base::Value* callback_id; | 188 const base::Value* callback_id; |
185 CHECK(args->Get(0, &callback_id)); | 189 CHECK(args->Get(0, &callback_id)); |
186 double type; | 190 std::string type; |
187 CHECK(args->GetDouble(1, &type)); | 191 CHECK(args->GetString(1, &type)); |
188 | 192 |
189 ContentSettingsType content_type = | 193 ContentSettingsType content_type = |
190 static_cast<ContentSettingsType>(static_cast<int>(type)); | 194 static_cast<ContentSettingsType>(static_cast<int>( |
| 195 site_settings::ContentSettingsTypeFromGroupName(type))); |
191 HostContentSettingsMap* map = | 196 HostContentSettingsMap* map = |
192 HostContentSettingsMapFactory::GetForProfile(profile_); | 197 HostContentSettingsMapFactory::GetForProfile(profile_); |
193 ContentSetting setting = map->GetDefaultContentSetting(content_type, nullptr); | 198 ContentSetting setting = map->GetDefaultContentSetting(content_type, nullptr); |
194 | 199 |
195 // FullScreen is Allow vs. Ask. | 200 // FullScreen is Allow vs. Ask. |
196 bool enabled; | 201 bool enabled; |
197 if (content_type == CONTENT_SETTINGS_TYPE_FULLSCREEN) | 202 if (content_type == CONTENT_SETTINGS_TYPE_FULLSCREEN) |
198 enabled = setting != CONTENT_SETTING_ASK; | 203 enabled = setting != CONTENT_SETTING_ASK; |
199 else | 204 else |
200 enabled = setting != CONTENT_SETTING_BLOCK; | 205 enabled = setting != CONTENT_SETTING_BLOCK; |
201 | 206 |
202 ResolveJavascriptCallback(*callback_id, base::FundamentalValue(enabled)); | 207 ResolveJavascriptCallback(*callback_id, base::FundamentalValue(enabled)); |
203 } | 208 } |
204 | 209 |
205 void SiteSettingsHandler::HandleGetExceptionList(const base::ListValue* args) { | 210 void SiteSettingsHandler::HandleGetExceptionList(const base::ListValue* args) { |
206 AllowJavascript(); | 211 AllowJavascript(); |
207 | 212 |
208 CHECK_EQ(2U, args->GetSize()); | 213 CHECK_EQ(2U, args->GetSize()); |
209 const base::Value* callback_id; | 214 const base::Value* callback_id; |
210 CHECK(args->Get(0, &callback_id)); | 215 CHECK(args->Get(0, &callback_id)); |
211 double type; | 216 std::string type; |
212 CHECK(args->GetDouble(1, &type)); | 217 CHECK(args->GetString(1, &type)); |
213 ContentSettingsType content_type = | 218 ContentSettingsType content_type = |
214 static_cast<ContentSettingsType>(static_cast<int>(type)); | 219 static_cast<ContentSettingsType>(static_cast<int>( |
| 220 site_settings::ContentSettingsTypeFromGroupName(type))); |
215 | 221 |
216 HostContentSettingsMap* map = | 222 HostContentSettingsMap* map = |
217 HostContentSettingsMapFactory::GetForProfile(profile_); | 223 HostContentSettingsMapFactory::GetForProfile(profile_); |
218 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); | 224 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); |
219 site_settings::GetExceptionsFromHostContentSettingsMap( | 225 site_settings::GetExceptionsFromHostContentSettingsMap( |
220 map, content_type, web_ui(), exceptions.get()); | 226 map, content_type, web_ui(), exceptions.get()); |
221 ResolveJavascriptCallback(*callback_id, *exceptions.get()); | 227 ResolveJavascriptCallback(*callback_id, *exceptions.get()); |
222 } | 228 } |
223 | 229 |
224 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( | 230 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( |
225 const base::ListValue* args) { | 231 const base::ListValue* args) { |
226 CHECK_EQ(3U, args->GetSize()); | 232 CHECK_EQ(3U, args->GetSize()); |
227 std::string primary_pattern; | 233 std::string primary_pattern; |
228 CHECK(args->GetString(0, &primary_pattern)); | 234 CHECK(args->GetString(0, &primary_pattern)); |
229 std::string secondary_pattern; | 235 std::string secondary_pattern; |
230 CHECK(args->GetString(1, &secondary_pattern)); | 236 CHECK(args->GetString(1, &secondary_pattern)); |
231 double type; | 237 std::string type; |
232 CHECK(args->GetDouble(2, &type)); | 238 CHECK(args->GetString(2, &type)); |
233 | 239 |
234 ContentSettingsType content_type = | 240 ContentSettingsType content_type = |
235 static_cast<ContentSettingsType>(static_cast<int>(type)); | 241 static_cast<ContentSettingsType>(static_cast<int>( |
| 242 site_settings::ContentSettingsTypeFromGroupName(type))); |
236 | 243 |
237 HostContentSettingsMap* map = | 244 HostContentSettingsMap* map = |
238 HostContentSettingsMapFactory::GetForProfile(profile_); | 245 HostContentSettingsMapFactory::GetForProfile(profile_); |
239 map->SetContentSettingCustomScope( | 246 map->SetContentSettingCustomScope( |
240 ContentSettingsPattern::FromString(primary_pattern), | 247 ContentSettingsPattern::FromString(primary_pattern), |
241 secondary_pattern.empty() ? | 248 secondary_pattern.empty() ? |
242 ContentSettingsPattern::Wildcard() : | 249 ContentSettingsPattern::Wildcard() : |
243 ContentSettingsPattern::FromString(secondary_pattern), | 250 ContentSettingsPattern::FromString(secondary_pattern), |
244 content_type, "", CONTENT_SETTING_DEFAULT); | 251 content_type, "", CONTENT_SETTING_DEFAULT); |
245 } | 252 } |
246 | 253 |
247 void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin( | 254 void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin( |
248 const base::ListValue* args) { | 255 const base::ListValue* args) { |
249 CHECK_EQ(4U, args->GetSize()); | 256 CHECK_EQ(4U, args->GetSize()); |
250 std::string primary_pattern; | 257 std::string primary_pattern; |
251 CHECK(args->GetString(0, &primary_pattern)); | 258 CHECK(args->GetString(0, &primary_pattern)); |
252 std::string secondary_pattern; | 259 std::string secondary_pattern; |
253 CHECK(args->GetString(1, &secondary_pattern)); | 260 CHECK(args->GetString(1, &secondary_pattern)); |
254 double type; | 261 std::string type; |
255 CHECK(args->GetDouble(2, &type)); | 262 CHECK(args->GetString(2, &type)); |
256 std::string value; | 263 std::string value; |
257 CHECK(args->GetString(3, &value)); | 264 CHECK(args->GetString(3, &value)); |
258 | 265 |
259 ContentSettingsType content_type = | 266 ContentSettingsType content_type = |
260 static_cast<ContentSettingsType>(static_cast<int>(type)); | 267 static_cast<ContentSettingsType>(static_cast<int>( |
| 268 site_settings::ContentSettingsTypeFromGroupName(type))); |
261 ContentSetting setting; | 269 ContentSetting setting; |
262 CHECK(content_settings::ContentSettingFromString(value, &setting)); | 270 CHECK(content_settings::ContentSettingFromString(value, &setting)); |
263 | 271 |
264 HostContentSettingsMap* map = | 272 HostContentSettingsMap* map = |
265 HostContentSettingsMapFactory::GetForProfile(profile_); | 273 HostContentSettingsMapFactory::GetForProfile(profile_); |
266 map->SetContentSettingCustomScope( | 274 map->SetContentSettingCustomScope( |
267 ContentSettingsPattern::FromString(primary_pattern), | 275 ContentSettingsPattern::FromString(primary_pattern), |
268 secondary_pattern.empty() ? | 276 secondary_pattern.empty() ? |
269 ContentSettingsPattern::Wildcard() : | 277 ContentSettingsPattern::Wildcard() : |
270 ContentSettingsPattern::FromString(secondary_pattern), | 278 ContentSettingsPattern::FromString(secondary_pattern), |
271 content_type, "", setting); | 279 content_type, "", setting); |
272 } | 280 } |
273 | 281 |
274 void SiteSettingsHandler::HandleIsPatternValid( | 282 void SiteSettingsHandler::HandleIsPatternValid( |
275 const base::ListValue* args) { | 283 const base::ListValue* args) { |
276 CHECK_EQ(2U, args->GetSize()); | 284 CHECK_EQ(2U, args->GetSize()); |
277 const base::Value* callback_id; | 285 const base::Value* callback_id; |
278 CHECK(args->Get(0, &callback_id)); | 286 CHECK(args->Get(0, &callback_id)); |
279 std::string pattern_string; | 287 std::string pattern_string; |
280 CHECK(args->GetString(1, &pattern_string)); | 288 CHECK(args->GetString(1, &pattern_string)); |
281 | 289 |
282 ContentSettingsPattern pattern = | 290 ContentSettingsPattern pattern = |
283 ContentSettingsPattern::FromString(pattern_string); | 291 ContentSettingsPattern::FromString(pattern_string); |
284 ResolveJavascriptCallback( | 292 ResolveJavascriptCallback( |
285 *callback_id, base::FundamentalValue(pattern.IsValid())); | 293 *callback_id, base::FundamentalValue(pattern.IsValid())); |
286 } | 294 } |
287 | 295 |
288 } // namespace settings | 296 } // namespace settings |
OLD | NEW |