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

Side by Side Diff: components/content_settings/core/browser/website_settings_registry.cc

Issue 1252073002: Move pref names and default value into WebsiteSettingsInfo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@website-settings-registry-simple
Patch Set: Created 5 years, 4 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 2015 The Chromium Authors. All rights reserved. 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 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 "components/content_settings/core/browser/website_settings_registry.h" 5 #include "components/content_settings/core/browser/website_settings_registry.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "components/content_settings/core/common/content_settings.h"
8 10
9 namespace { 11 namespace {
10 12
11 base::LazyInstance<content_settings::WebsiteSettingsRegistry>::Leaky 13 base::LazyInstance<content_settings::WebsiteSettingsRegistry>::Leaky
12 g_instance = LAZY_INSTANCE_INITIALIZER; 14 g_instance = LAZY_INSTANCE_INITIALIZER;
13 15
14 } // namespace 16 } // namespace
15 17
16 namespace content_settings { 18 namespace content_settings {
17 19
18 // static 20 // static
19 WebsiteSettingsRegistry* WebsiteSettingsRegistry::GetInstance() { 21 WebsiteSettingsRegistry* WebsiteSettingsRegistry::GetInstance() {
20 return g_instance.Pointer(); 22 return g_instance.Pointer();
21 } 23 }
22 24
23 WebsiteSettingsRegistry::WebsiteSettingsRegistry() { 25 WebsiteSettingsRegistry::WebsiteSettingsRegistry() {
24 website_settings_info_.resize(CONTENT_SETTINGS_NUM_TYPES); 26 website_settings_info_.resize(CONTENT_SETTINGS_NUM_TYPES);
25 27
26 // TODO(raymes): This registration code should not have to be in a single 28 // 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 29 // location. It should be possible to register a setting from the code
28 // associated with it. 30 // associated with it.
29 31
30 Register(CONTENT_SETTINGS_TYPE_COOKIES, "cookies"); 32 // WARNING: The string names of the permissions passed in below are used to
31 Register(CONTENT_SETTINGS_TYPE_IMAGES, "images"); 33 // generate preference names and should never be changed!
32 Register(CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"); 34
33 Register(CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"); 35 // Content settings (those with allow/block/ask/etc. values).
34 Register(CONTENT_SETTINGS_TYPE_POPUPS, "popups"); 36 RegisterContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, "cookies",
35 Register(CONTENT_SETTINGS_TYPE_GEOLOCATION, "geolocation"); 37 CONTENT_SETTING_ALLOW);
36 Register(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"); 38 RegisterContentSetting(CONTENT_SETTINGS_TYPE_IMAGES, "images",
37 Register(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, 39 CONTENT_SETTING_ALLOW);
38 "auto-select-certificate"); 40 RegisterContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript",
39 Register(CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen"); 41 CONTENT_SETTING_ALLOW);
40 Register(CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock"); 42 RegisterContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, "plugins",
41 Register(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, "mixed-script"); 43 CONTENT_SETTING_DEFAULT);
42 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM, "media-stream"); 44 RegisterContentSetting(CONTENT_SETTINGS_TYPE_POPUPS, "popups",
43 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, "media-stream-mic"); 45 CONTENT_SETTING_BLOCK);
44 Register(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, "media-stream-camera"); 46 RegisterContentSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION, "geolocation",
45 Register(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, 47 CONTENT_SETTING_ASK);
46 "register-protocol-handler"); 48 RegisterContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications",
47 Register(CONTENT_SETTINGS_TYPE_PPAPI_BROKER, "ppapi-broker"); 49 CONTENT_SETTING_ASK);
48 Register(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, 50 RegisterContentSetting(CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen",
49 "multiple-automatic-downloads"); 51 CONTENT_SETTING_ASK);
50 Register(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, "midi-sysex"); 52 RegisterContentSetting(CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock",
51 Register(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, "push-messaging"); 53 CONTENT_SETTING_ASK);
52 Register(CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, "ssl-cert-decisions"); 54 RegisterContentSetting(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, "mixed-script",
55 CONTENT_SETTING_DEFAULT);
56 RegisterContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
57 "media-stream-mic", CONTENT_SETTING_ASK);
58 RegisterContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
59 "media-stream-camera", CONTENT_SETTING_ASK);
60 RegisterContentSetting(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS,
61 "protocol-handler", CONTENT_SETTING_DEFAULT);
62 RegisterContentSetting(CONTENT_SETTINGS_TYPE_PPAPI_BROKER, "ppapi-broker",
63 CONTENT_SETTING_ASK);
64 RegisterContentSetting(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
65 "automatic-downloads", CONTENT_SETTING_ASK);
66 RegisterContentSetting(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, "midi-sysex",
67 CONTENT_SETTING_ASK);
68 RegisterContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, "push-messaging",
69 CONTENT_SETTING_ASK);
70 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
71 RegisterContentSetting(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER,
72 "protected-media-identifier", CONTENT_SETTING_ASK);
73 #endif
74 RegisterContentSetting(CONTENT_SETTINGS_TYPE_DURABLE_STORAGE,
75 "durable-storage", CONTENT_SETTING_ASK);
76
77 // Website settings.
78 RegisterWebsiteSetting(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
79 "auto-select-certificate");
80 RegisterWebsiteSetting(CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS,
81 "ssl-cert-decisions");
82 RegisterWebsiteSetting(CONTENT_SETTINGS_TYPE_APP_BANNER, "app-banner");
83 RegisterWebsiteSetting(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
84 "site-engagement");
85
86 // Deprecated.
87 RegisterWebsiteSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM, "media-stream");
53 #if defined(OS_WIN) 88 #if defined(OS_WIN)
54 Register(CONTENT_SETTINGS_TYPE_METRO_SWITCH_TO_DESKTOP, 89 RegisterContentSetting(CONTENT_SETTINGS_TYPE_METRO_SWITCH_TO_DESKTOP,
55 "metro-switch-to-desktop"); 90 "metro-switch-to-desktop", CONTENT_SETTING_ASK);
56 #elif defined(OS_ANDROID) || defined(OS_CHROMEOS)
57 Register(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER,
58 "protected-media-identifier");
59 #endif 91 #endif
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");
63 } 92 }
64 93
65 WebsiteSettingsRegistry::~WebsiteSettingsRegistry() {} 94 WebsiteSettingsRegistry::~WebsiteSettingsRegistry() {}
66 95
67 const WebsiteSettingsInfo* WebsiteSettingsRegistry::Get( 96 const WebsiteSettingsInfo* WebsiteSettingsRegistry::Get(
68 ContentSettingsType type) const { 97 ContentSettingsType type) const {
69 DCHECK_GE(type, 0); 98 DCHECK_GE(type, 0);
70 DCHECK_LT(type, static_cast<int>(website_settings_info_.size())); 99 DCHECK_LT(type, static_cast<int>(website_settings_info_.size()));
71 return website_settings_info_[type]; 100 return website_settings_info_[type];
72 } 101 }
73 102
74 const WebsiteSettingsInfo* WebsiteSettingsRegistry::GetByName( 103 const WebsiteSettingsInfo* WebsiteSettingsRegistry::GetByName(
75 const std::string& name) const { 104 const std::string& name) const {
76 for (const auto& info : website_settings_info_) { 105 for (const auto& info : website_settings_info_) {
77 if (info && info->name() == name) 106 if (info && info->name() == name)
78 return info; 107 return info;
79 } 108 }
80 return nullptr; 109 return nullptr;
81 } 110 }
82 111
83 void WebsiteSettingsRegistry::Register(ContentSettingsType type, 112 void WebsiteSettingsRegistry::RegisterWebsiteSetting(ContentSettingsType type,
84 const std::string& name) { 113 const std::string& name) {
85 DCHECK_GE(type, 0); 114 StoreWebsiteSettingsInfo(new WebsiteSettingsInfo(type, name, nullptr));
86 DCHECK_LT(type, static_cast<int>(website_settings_info_.size())); 115 }
87 website_settings_info_[type] = new WebsiteSettingsInfo(type, name); 116
117 void WebsiteSettingsRegistry::RegisterContentSetting(
118 ContentSettingsType type,
119 const std::string& name,
120 ContentSetting initial_default_value) {
121 scoped_ptr<base::Value> default_value(
122 new base::FundamentalValue(static_cast<int>(initial_default_value)));
123 StoreWebsiteSettingsInfo(
124 new WebsiteSettingsInfo(type, name, default_value.Pass()));
125 }
126
127 void WebsiteSettingsRegistry::StoreWebsiteSettingsInfo(
128 WebsiteSettingsInfo* info) {
129 DCHECK_GE(info->type(), 0);
130 DCHECK_LT(info->type(), static_cast<int>(website_settings_info_.size()));
131 website_settings_info_[info->type()] = info;
88 } 132 }
89 133
90 } // namespace content_settings 134 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698