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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/website_settings/website_settings_ui.h"
7 #include "chrome/grit/chromium_strings.h"
8 #include "chrome/grit/generated_resources.h"
9 #include "components/content_settings/core/browser/plugins_field_trial.h"
10 #include "grit/theme_resources.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/image/image.h"
17 const int kInvalidResourceID
= -1;
19 // The resource IDs for the strings that are displayed on the permissions
20 // button if the permission setting is managed by policy.
21 const int kPermissionButtonTextIDPolicyManaged
[] = {
23 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_POLICY
,
24 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_POLICY
,
25 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ASK_BY_POLICY
,
28 static_assert(arraysize(kPermissionButtonTextIDPolicyManaged
) ==
29 CONTENT_SETTING_NUM_SETTINGS
,
30 "kPermissionButtonTextIDPolicyManaged array size is incorrect");
32 // The resource IDs for the strings that are displayed on the permissions
33 // button if the permission setting is managed by an extension.
34 const int kPermissionButtonTextIDExtensionManaged
[] = {
36 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_EXTENSION
,
37 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_EXTENSION
,
41 static_assert(arraysize(kPermissionButtonTextIDExtensionManaged
) ==
42 CONTENT_SETTING_NUM_SETTINGS
,
43 "kPermissionButtonTextIDExtensionManaged array size is "
46 // The resource IDs for the strings that are displayed on the permissions
47 // button if the permission setting is managed by the user.
48 const int kPermissionButtonTextIDUserManaged
[] = {
50 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_USER
,
51 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_USER
,
52 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ASK_BY_USER
,
54 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_DETECT_IMPORTANT_CONTENT_BY_USER
};
55 static_assert(arraysize(kPermissionButtonTextIDUserManaged
) ==
56 CONTENT_SETTING_NUM_SETTINGS
,
57 "kPermissionButtonTextIDUserManaged array size is incorrect");
59 // The resource IDs for the strings that are displayed on the permissions
60 // button if the permission setting is the global default setting.
61 const int kPermissionButtonTextIDDefaultSetting
[] = {
63 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_DEFAULT
,
64 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_DEFAULT
,
65 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ASK_BY_DEFAULT
,
67 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_DETECT_IMPORTANT_CONTENT_BY_DEFAULT
};
68 static_assert(arraysize(kPermissionButtonTextIDDefaultSetting
) ==
69 CONTENT_SETTING_NUM_SETTINGS
,
70 "kPermissionButtonTextIDDefaultSetting array size is incorrect");
74 WebsiteSettingsUI::CookieInfo::CookieInfo()
75 : allowed(-1), blocked(-1) {
78 WebsiteSettingsUI::PermissionInfo::PermissionInfo()
79 : type(CONTENT_SETTINGS_TYPE_DEFAULT
),
80 setting(CONTENT_SETTING_DEFAULT
),
81 default_setting(CONTENT_SETTING_DEFAULT
),
82 source(content_settings::SETTING_SOURCE_NONE
) {
85 WebsiteSettingsUI::IdentityInfo::IdentityInfo()
86 : identity_status(WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN
),
88 connection_status(WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN
),
89 show_ssl_decision_revoke_button(false) {
92 WebsiteSettingsUI::IdentityInfo::~IdentityInfo() {}
94 base::string16
WebsiteSettingsUI::IdentityInfo::GetSecuritySummary() const {
95 switch (identity_status
) {
96 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT
:
97 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT
:
98 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN
:
99 switch (connection_status
) {
100 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT
:
101 return l10n_util::GetStringUTF16(
102 IDS_WEBSITE_SETTINGS_MIXED_PASSIVE_CONTENT
);
103 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_SCRIPT
:
104 return l10n_util::GetStringUTF16(
105 IDS_WEBSITE_SETTINGS_MIXED_ACTIVE_CONTENT
);
107 return l10n_util::GetStringUTF16(
108 IDS_WEBSITE_SETTINGS_SECURE_TRANSPORT
);
110 case WebsiteSettings::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM
:
111 return l10n_util::GetStringUTF16(
112 IDS_WEBSITE_DEPRECATED_SIGNATURE_ALGORITHM
);
113 case WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT
:
114 return l10n_util::GetStringUTF16(IDS_CERT_POLICY_PROVIDED_CERT_HEADER
);
115 case WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN
:
116 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_UNKNOWN_TRANSPORT
);
117 case WebsiteSettings::SITE_IDENTITY_STATUS_INTERNAL_PAGE
:
118 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_INTERNAL_PAGE
);
119 case WebsiteSettings::SITE_IDENTITY_STATUS_NO_CERT
:
121 return l10n_util::GetStringUTF16(
122 IDS_WEBSITE_SETTINGS_NON_SECURE_TRANSPORT
);
126 WebsiteSettingsUI::~WebsiteSettingsUI() {
130 base::string16
WebsiteSettingsUI::PermissionTypeToUIString(
131 ContentSettingsType type
) {
133 case CONTENT_SETTINGS_TYPE_IMAGES
:
134 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_IMAGES
);
135 case CONTENT_SETTINGS_TYPE_JAVASCRIPT
:
136 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_JAVASCRIPT
);
137 case CONTENT_SETTINGS_TYPE_POPUPS
:
138 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_POPUPS
);
139 case CONTENT_SETTINGS_TYPE_PLUGINS
:
140 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_PLUGINS
);
141 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
142 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_LOCATION
);
143 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
144 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
145 return l10n_util::GetStringUTF16(
146 IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS
);
147 case CONTENT_SETTINGS_TYPE_FULLSCREEN
:
148 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_FULLSCREEN
);
149 case CONTENT_SETTINGS_TYPE_MOUSELOCK
:
150 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_MOUSELOCK
);
151 case CONTENT_SETTINGS_TYPE_MEDIASTREAM
:
152 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM
);
153 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
:
154 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_MIC
);
155 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA
:
156 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_CAMERA
);
157 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS
:
158 return l10n_util::GetStringUTF16(IDS_AUTOMATIC_DOWNLOADS_TAB_LABEL
);
159 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
160 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_MIDI_SYSEX
);
163 return base::string16();
168 base::string16
WebsiteSettingsUI::PermissionValueToUIString(
169 ContentSetting value
) {
171 case CONTENT_SETTING_ALLOW
:
172 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_ALLOW
);
173 case CONTENT_SETTING_BLOCK
:
174 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_BLOCK
);
175 case CONTENT_SETTING_ASK
:
176 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_ASK
);
179 return base::string16();
184 base::string16
WebsiteSettingsUI::PermissionActionToUIString(
185 ContentSettingsType type
,
186 ContentSetting setting
,
187 ContentSetting default_setting
,
188 content_settings::SettingSource source
) {
189 ContentSetting effective_setting
= setting
;
190 if (effective_setting
== CONTENT_SETTING_DEFAULT
)
191 effective_setting
= default_setting
;
193 #if defined(ENABLE_PLUGINS)
195 content_settings::PluginsFieldTrial::EffectiveContentSetting(
196 type
, effective_setting
);
199 const int* button_text_ids
= NULL
;
201 case content_settings::SETTING_SOURCE_USER
:
202 if (setting
== CONTENT_SETTING_DEFAULT
)
203 button_text_ids
= kPermissionButtonTextIDDefaultSetting
;
205 button_text_ids
= kPermissionButtonTextIDUserManaged
;
207 case content_settings::SETTING_SOURCE_POLICY
:
208 button_text_ids
= kPermissionButtonTextIDPolicyManaged
;
210 case content_settings::SETTING_SOURCE_EXTENSION
:
211 button_text_ids
= kPermissionButtonTextIDExtensionManaged
;
213 case content_settings::SETTING_SOURCE_WHITELIST
:
214 case content_settings::SETTING_SOURCE_NONE
:
217 return base::string16();
219 int button_text_id
= button_text_ids
[effective_setting
];
220 DCHECK_NE(button_text_id
, kInvalidResourceID
);
221 return l10n_util::GetStringUTF16(button_text_id
);
225 int WebsiteSettingsUI::GetPermissionIconID(ContentSettingsType type
,
226 ContentSetting setting
) {
227 bool use_blocked
= (setting
== CONTENT_SETTING_BLOCK
);
228 int resource_id
= IDR_INFO
;
230 case CONTENT_SETTINGS_TYPE_IMAGES
:
231 resource_id
= use_blocked
? IDR_BLOCKED_IMAGES
: IDR_ALLOWED_IMAGES
;
233 case CONTENT_SETTINGS_TYPE_JAVASCRIPT
:
235 use_blocked
? IDR_BLOCKED_JAVASCRIPT
: IDR_ALLOWED_JAVASCRIPT
;
237 case CONTENT_SETTINGS_TYPE_COOKIES
:
238 resource_id
= use_blocked
? IDR_BLOCKED_COOKIES
: IDR_ACCESSED_COOKIES
;
240 case CONTENT_SETTINGS_TYPE_POPUPS
:
241 resource_id
= use_blocked
? IDR_BLOCKED_POPUPS
: IDR_ALLOWED_POPUPS
;
243 case CONTENT_SETTINGS_TYPE_PLUGINS
:
244 resource_id
= use_blocked
? IDR_BLOCKED_PLUGINS
: IDR_ALLOWED_PLUGINS
;
246 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
247 resource_id
= use_blocked
? IDR_BLOCKED_LOCATION
: IDR_ALLOWED_LOCATION
;
249 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
251 use_blocked
? IDR_BLOCKED_NOTIFICATION
: IDR_ALLOWED_NOTIFICATION
;
253 case CONTENT_SETTINGS_TYPE_FULLSCREEN
:
254 resource_id
= IDR_ALLOWED_FULLSCREEN
;
256 case CONTENT_SETTINGS_TYPE_MOUSELOCK
:
258 use_blocked
? IDR_BLOCKED_MOUSE_CURSOR
: IDR_ALLOWED_MOUSE_CURSOR
;
260 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
:
261 resource_id
= use_blocked
? IDR_BLOCKED_MIC
: IDR_ALLOWED_MIC
;
263 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA
:
264 resource_id
= use_blocked
? IDR_BLOCKED_CAMERA
: IDR_ALLOWED_CAMERA
;
266 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS
:
267 resource_id
= use_blocked
? IDR_BLOCKED_DOWNLOADS
268 : IDR_ALLOWED_DOWNLOADS
;
270 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
271 resource_id
= use_blocked
? IDR_BLOCKED_MIDI_SYSEX
272 : IDR_ALLOWED_MIDI_SYSEX
;
282 const gfx::Image
& WebsiteSettingsUI::GetPermissionIcon(
283 const PermissionInfo
& info
) {
284 ContentSetting setting
= info
.setting
;
285 if (setting
== CONTENT_SETTING_DEFAULT
)
286 setting
= info
.default_setting
;
287 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
288 return rb
.GetNativeImageNamed(GetPermissionIconID(info
.type
, setting
));
292 int WebsiteSettingsUI::GetIdentityIconID(
293 WebsiteSettings::SiteIdentityStatus status
) {
294 int resource_id
= IDR_PAGEINFO_INFO
;
296 case WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN
:
297 case WebsiteSettings::SITE_IDENTITY_STATUS_INTERNAL_PAGE
:
299 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT
:
300 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT
:
301 resource_id
= IDR_PAGEINFO_GOOD
;
303 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN
:
304 resource_id
= IDR_PAGEINFO_WARNING_MINOR
;
306 case WebsiteSettings::SITE_IDENTITY_STATUS_NO_CERT
:
307 resource_id
= IDR_PAGEINFO_WARNING_MAJOR
;
309 case WebsiteSettings::SITE_IDENTITY_STATUS_ERROR
:
310 resource_id
= IDR_PAGEINFO_BAD
;
312 case WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT
:
313 resource_id
= IDR_PAGEINFO_ENTERPRISE_MANAGED
;
315 case WebsiteSettings::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM
:
316 resource_id
= IDR_PAGEINFO_WARNING_MINOR
;
326 const gfx::Image
& WebsiteSettingsUI::GetIdentityIcon(
327 WebsiteSettings::SiteIdentityStatus status
) {
328 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
329 return rb
.GetNativeImageNamed(GetIdentityIconID(status
));
333 int WebsiteSettingsUI::GetConnectionIconID(
334 WebsiteSettings::SiteConnectionStatus status
) {
335 int resource_id
= IDR_PAGEINFO_INFO
;
337 case WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN
:
338 case WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE
:
340 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED
:
341 resource_id
= IDR_PAGEINFO_GOOD
;
343 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT
:
344 resource_id
= IDR_PAGEINFO_WARNING_MINOR
;
346 case WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED
:
347 resource_id
= IDR_PAGEINFO_WARNING_MAJOR
;
349 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
:
350 resource_id
= IDR_PAGEINFO_BAD
;
360 const gfx::Image
& WebsiteSettingsUI::GetConnectionIcon(
361 WebsiteSettings::SiteConnectionStatus status
) {
362 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
363 return rb
.GetNativeImageNamed(GetConnectionIconID(status
));