1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/content_settings/core/browser/website_settings_registry.h"
7 #include "base/logging.h"
11 base::LazyInstance
<content_settings::WebsiteSettingsRegistry
>::Leaky
12 g_instance
= LAZY_INSTANCE_INITIALIZER
;
16 namespace content_settings
{
19 WebsiteSettingsRegistry
* WebsiteSettingsRegistry::GetInstance() {
20 return g_instance
.Pointer();
23 WebsiteSettingsRegistry::WebsiteSettingsRegistry() {
24 website_settings_info_
.resize(CONTENT_SETTINGS_NUM_TYPES
);
26 // TODO(raymes): This registration code should not have to be in a single
27 // location. It should be possible to register a setting from the code
28 // associated with it.
30 Register(CONTENT_SETTINGS_TYPE_COOKIES
, "cookies");
31 Register(CONTENT_SETTINGS_TYPE_IMAGES
, "images");
32 Register(CONTENT_SETTINGS_TYPE_JAVASCRIPT
, "javascript");
33 Register(CONTENT_SETTINGS_TYPE_PLUGINS
, "plugins");
34 Register(CONTENT_SETTINGS_TYPE_POPUPS
, "popups");
35 Register(CONTENT_SETTINGS_TYPE_GEOLOCATION
, "geolocation");
36 Register(CONTENT_SETTINGS_TYPE_NOTIFICATIONS
, "notifications");
37 Register(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
38 "auto-select-certificate");
39 Register(CONTENT_SETTINGS_TYPE_FULLSCREEN
, "fullscreen");
40 Register(CONTENT_SETTINGS_TYPE_MOUSELOCK
, "mouselock");
41 Register(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT
, "mixed-script");
42 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM
, "media-stream");
43 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
, "media-stream-mic");
44 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA
, "media-stream-camera");
45 Register(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS
,
46 "register-protocol-handler");
47 Register(CONTENT_SETTINGS_TYPE_PPAPI_BROKER
, "ppapi-broker");
48 Register(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS
,
49 "multiple-automatic-downloads");
50 Register(CONTENT_SETTINGS_TYPE_MIDI_SYSEX
, "midi-sysex");
51 Register(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
, "push-messaging");
52 Register(CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS
, "ssl-cert-decisions");
54 Register(CONTENT_SETTINGS_TYPE_METRO_SWITCH_TO_DESKTOP
,
55 "metro-switch-to-desktop");
56 #elif defined(OS_ANDROID) || defined(OS_CHROMEOS)
57 Register(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
,
58 "protected-media-identifier");
60 Register(CONTENT_SETTINGS_TYPE_APP_BANNER
, "app-banner");
61 Register(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT
, "site-engagement");
62 Register(CONTENT_SETTINGS_TYPE_DURABLE_STORAGE
, "durable-storage");
65 WebsiteSettingsRegistry::~WebsiteSettingsRegistry() {}
67 const WebsiteSettingsInfo
* WebsiteSettingsRegistry::Get(
68 ContentSettingsType type
) const {
70 DCHECK_LT(type
, static_cast<int>(website_settings_info_
.size()));
71 return website_settings_info_
[type
];
74 const WebsiteSettingsInfo
* WebsiteSettingsRegistry::GetByName(
75 const std::string
& name
) const {
76 for (const auto& info
: website_settings_info_
) {
77 if (info
&& info
->name() == name
)
83 void WebsiteSettingsRegistry::Register(ContentSettingsType type
,
84 const std::string
& name
) {
86 DCHECK_LT(type
, static_cast<int>(website_settings_info_
.size()));
87 website_settings_info_
[type
] = new WebsiteSettingsInfo(type
, name
);
90 } // namespace content_settings