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

Side by Side Diff: chrome/browser/ui/webui/options/content_settings_handler.cc

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/options/content_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/content_settings_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8
8 #include <algorithm> 9 #include <algorithm>
9 #include <utility> 10 #include <utility>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h"
17 #include "base/stl_util.h" 19 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
20 #include "base/values.h" 22 #include "base/values.h"
21 #include "build/build_config.h" 23 #include "build/build_config.h"
22 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 26 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
25 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" 27 #include "chrome/browser/content_settings/web_site_settings_uma_util.h"
26 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 const std::string& name) { 288 const std::string& name) {
287 for (const auto& chooser_type : kChooserTypeGroupNames) { 289 for (const auto& chooser_type : kChooserTypeGroupNames) {
288 if (chooser_type.name == name) 290 if (chooser_type.name == name)
289 return &chooser_type; 291 return &chooser_type;
290 } 292 }
291 return nullptr; 293 return nullptr;
292 } 294 }
293 295
294 // Create a DictionaryValue* that will act as a data source for a single row 296 // Create a DictionaryValue* that will act as a data source for a single row
295 // in the Geolocation exceptions table. 297 // in the Geolocation exceptions table.
296 scoped_ptr<base::DictionaryValue> GetGeolocationExceptionForPage( 298 std::unique_ptr<base::DictionaryValue> GetGeolocationExceptionForPage(
297 const ContentSettingsPattern& origin, 299 const ContentSettingsPattern& origin,
298 const ContentSettingsPattern& embedding_origin, 300 const ContentSettingsPattern& embedding_origin,
299 ContentSetting setting) { 301 ContentSetting setting) {
300 base::DictionaryValue* exception = new base::DictionaryValue(); 302 base::DictionaryValue* exception = new base::DictionaryValue();
301 303
302 std::string setting_string = 304 std::string setting_string =
303 content_settings::ContentSettingToString(setting); 305 content_settings::ContentSettingToString(setting);
304 DCHECK(!setting_string.empty()); 306 DCHECK(!setting_string.empty());
305 307
306 exception->SetString(site_settings::kSetting, setting_string); 308 exception->SetString(site_settings::kSetting, setting_string);
307 exception->SetString(site_settings::kOrigin, origin.ToString()); 309 exception->SetString(site_settings::kOrigin, origin.ToString());
308 exception->SetString( 310 exception->SetString(
309 site_settings::kEmbeddingOrigin, embedding_origin.ToString()); 311 site_settings::kEmbeddingOrigin, embedding_origin.ToString());
310 return make_scoped_ptr(exception); 312 return base::WrapUnique(exception);
311 } 313 }
312 314
313 // Create a DictionaryValue* that will act as a data source for a single row 315 // Create a DictionaryValue* that will act as a data source for a single row
314 // in the desktop notifications exceptions table. 316 // in the desktop notifications exceptions table.
315 scoped_ptr<base::DictionaryValue> GetNotificationExceptionForPage( 317 std::unique_ptr<base::DictionaryValue> GetNotificationExceptionForPage(
316 const ContentSettingsPattern& primary_pattern, 318 const ContentSettingsPattern& primary_pattern,
317 const ContentSettingsPattern& secondary_pattern, 319 const ContentSettingsPattern& secondary_pattern,
318 ContentSetting setting, 320 ContentSetting setting,
319 const std::string& provider_name) { 321 const std::string& provider_name) {
320 std::string embedding_origin; 322 std::string embedding_origin;
321 if (secondary_pattern != ContentSettingsPattern::Wildcard()) 323 if (secondary_pattern != ContentSettingsPattern::Wildcard())
322 embedding_origin = secondary_pattern.ToString(); 324 embedding_origin = secondary_pattern.ToString();
323 325
324 base::DictionaryValue* exception = new base::DictionaryValue(); 326 base::DictionaryValue* exception = new base::DictionaryValue();
325 327
326 std::string setting_string = 328 std::string setting_string =
327 content_settings::ContentSettingToString(setting); 329 content_settings::ContentSettingToString(setting);
328 DCHECK(!setting_string.empty()); 330 DCHECK(!setting_string.empty());
329 331
330 exception->SetString(site_settings::kSetting, setting_string); 332 exception->SetString(site_settings::kSetting, setting_string);
331 exception->SetString(site_settings::kOrigin, primary_pattern.ToString()); 333 exception->SetString(site_settings::kOrigin, primary_pattern.ToString());
332 exception->SetString(site_settings::kEmbeddingOrigin, embedding_origin); 334 exception->SetString(site_settings::kEmbeddingOrigin, embedding_origin);
333 exception->SetString(site_settings::kSource, provider_name); 335 exception->SetString(site_settings::kSource, provider_name);
334 return make_scoped_ptr(exception); 336 return base::WrapUnique(exception);
335 } 337 }
336 338
337 // Create a DictionaryValue* that will act as a data source for a single row 339 // Create a DictionaryValue* that will act as a data source for a single row
338 // in a chooser permission exceptions table. 340 // in a chooser permission exceptions table.
339 scoped_ptr<base::DictionaryValue> GetChooserExceptionForPage( 341 std::unique_ptr<base::DictionaryValue> GetChooserExceptionForPage(
340 const GURL& requesting_origin, 342 const GURL& requesting_origin,
341 const GURL& embedding_origin, 343 const GURL& embedding_origin,
342 const std::string& provider_name, 344 const std::string& provider_name,
343 const std::string& name, 345 const std::string& name,
344 const base::DictionaryValue* object) { 346 const base::DictionaryValue* object) {
345 scoped_ptr<base::DictionaryValue> exception(new base::DictionaryValue()); 347 std::unique_ptr<base::DictionaryValue> exception(new base::DictionaryValue());
346 348
347 std::string setting_string = 349 std::string setting_string =
348 content_settings::ContentSettingToString(CONTENT_SETTING_DEFAULT); 350 content_settings::ContentSettingToString(CONTENT_SETTING_DEFAULT);
349 DCHECK(!setting_string.empty()); 351 DCHECK(!setting_string.empty());
350 352
351 exception->SetString(site_settings::kSetting, setting_string); 353 exception->SetString(site_settings::kSetting, setting_string);
352 exception->SetString(site_settings::kOrigin, requesting_origin.spec()); 354 exception->SetString(site_settings::kOrigin, requesting_origin.spec());
353 exception->SetString( 355 exception->SetString(
354 site_settings::kEmbeddingOrigin, embedding_origin.spec()); 356 site_settings::kEmbeddingOrigin, embedding_origin.spec());
355 exception->SetString(site_settings::kSource, provider_name); 357 exception->SetString(site_settings::kSource, provider_name);
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 std::sort(zoom_levels.begin(), zoom_levels.end(), 1149 std::sort(zoom_levels.begin(), zoom_levels.end(),
1148 [](const content::HostZoomMap::ZoomLevelChange& a, 1150 [](const content::HostZoomMap::ZoomLevelChange& a,
1149 const content::HostZoomMap::ZoomLevelChange& b) { 1151 const content::HostZoomMap::ZoomLevelChange& b) {
1150 return a.host == b.host ? a.scheme < b.scheme : a.host < b.host; 1152 return a.host == b.host ? a.scheme < b.scheme : a.host < b.host;
1151 }); 1153 });
1152 1154
1153 for (content::HostZoomMap::ZoomLevelVector::const_iterator i = 1155 for (content::HostZoomMap::ZoomLevelVector::const_iterator i =
1154 zoom_levels.begin(); 1156 zoom_levels.begin();
1155 i != zoom_levels.end(); 1157 i != zoom_levels.end();
1156 ++i) { 1158 ++i) {
1157 scoped_ptr<base::DictionaryValue> exception(new base::DictionaryValue); 1159 std::unique_ptr<base::DictionaryValue> exception(new base::DictionaryValue);
1158 switch (i->mode) { 1160 switch (i->mode) {
1159 case content::HostZoomMap::ZOOM_CHANGED_FOR_HOST: { 1161 case content::HostZoomMap::ZOOM_CHANGED_FOR_HOST: {
1160 exception->SetString(site_settings::kOrigin, i->host); 1162 exception->SetString(site_settings::kOrigin, i->host);
1161 std::string host = i->host; 1163 std::string host = i->host;
1162 if (host == content::kUnreachableWebDataURL) { 1164 if (host == content::kUnreachableWebDataURL) {
1163 host = 1165 host =
1164 l10n_util::GetStringUTF8(IDS_ZOOMLEVELS_CHROME_ERROR_PAGES_LABEL); 1166 l10n_util::GetStringUTF8(IDS_ZOOMLEVELS_CHROME_ERROR_PAGES_LABEL);
1165 } 1167 }
1166 exception->SetString(site_settings::kOrigin, host); 1168 exception->SetString(site_settings::kOrigin, host);
1167 break; 1169 break;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 base::ListValue* exceptions) { 1249 base::ListValue* exceptions) {
1248 Profile* profile = Profile::FromWebUI(web_ui()); 1250 Profile* profile = Profile::FromWebUI(web_ui());
1249 if (incognito) { 1251 if (incognito) {
1250 if (profile->HasOffTheRecordProfile()) 1252 if (profile->HasOffTheRecordProfile())
1251 profile = profile->GetOffTheRecordProfile(); 1253 profile = profile->GetOffTheRecordProfile();
1252 else 1254 else
1253 return; 1255 return;
1254 } 1256 }
1255 1257
1256 ChooserContextBase* chooser_context = chooser_type.get_context(profile); 1258 ChooserContextBase* chooser_context = chooser_type.get_context(profile);
1257 std::vector<scoped_ptr<ChooserContextBase::Object>> objects = 1259 std::vector<std::unique_ptr<ChooserContextBase::Object>> objects =
1258 chooser_context->GetAllGrantedObjects(); 1260 chooser_context->GetAllGrantedObjects();
1259 AllOriginObjects all_origin_objects; 1261 AllOriginObjects all_origin_objects;
1260 for (const auto& object : objects) { 1262 for (const auto& object : objects) {
1261 std::string name; 1263 std::string name;
1262 bool found = object->object.GetString(chooser_type.ui_name_key, &name); 1264 bool found = object->object.GetString(chooser_type.ui_name_key, &name);
1263 DCHECK(found); 1265 DCHECK(found);
1264 // It is safe for this structure to hold references into |objects| because 1266 // It is safe for this structure to hold references into |objects| because
1265 // they are both destroyed at the end of this function. 1267 // they are both destroyed at the end of this function.
1266 all_origin_objects[make_pair(object->requesting_origin, 1268 all_origin_objects[make_pair(object->requesting_origin,
1267 object->source)][object->embedding_origin] 1269 object->source)][object->embedding_origin]
1268 .insert(make_pair(name, &object->object)); 1270 .insert(make_pair(name, &object->object));
1269 } 1271 }
1270 1272
1271 // Keep the exceptions sorted by provider so they will be displayed in 1273 // Keep the exceptions sorted by provider so they will be displayed in
1272 // precedence order. 1274 // precedence order.
1273 std::vector<scoped_ptr<base::DictionaryValue>> 1275 std::vector<std::unique_ptr<base::DictionaryValue>>
1274 all_provider_exceptions[HostContentSettingsMap::NUM_PROVIDER_TYPES]; 1276 all_provider_exceptions[HostContentSettingsMap::NUM_PROVIDER_TYPES];
1275 1277
1276 for (const auto& all_origin_objects_entry : all_origin_objects) { 1278 for (const auto& all_origin_objects_entry : all_origin_objects) {
1277 const GURL& requesting_origin = all_origin_objects_entry.first.first; 1279 const GURL& requesting_origin = all_origin_objects_entry.first.first;
1278 const std::string& source = all_origin_objects_entry.first.second; 1280 const std::string& source = all_origin_objects_entry.first.second;
1279 const OneOriginObjects& one_origin_objects = 1281 const OneOriginObjects& one_origin_objects =
1280 all_origin_objects_entry.second; 1282 all_origin_objects_entry.second;
1281 1283
1282 auto& this_provider_exceptions = all_provider_exceptions 1284 auto& this_provider_exceptions = all_provider_exceptions
1283 [HostContentSettingsMap::GetProviderTypeFromSource(source)]; 1285 [HostContentSettingsMap::GetProviderTypeFromSource(source)];
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 1705
1704 // Exceptions apply only when the feature is enabled. 1706 // Exceptions apply only when the feature is enabled.
1705 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); 1707 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui()));
1706 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); 1708 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM);
1707 web_ui()->CallJavascriptFunction( 1709 web_ui()->CallJavascriptFunction(
1708 "ContentSettings.enableProtectedContentExceptions", 1710 "ContentSettings.enableProtectedContentExceptions",
1709 base::FundamentalValue(enable_exceptions)); 1711 base::FundamentalValue(enable_exceptions));
1710 } 1712 }
1711 1713
1712 } // namespace options 1714 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/content_settings_handler.h ('k') | chrome/browser/ui/webui/options/cookies_view_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698