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 #if defined(ENABLE_PLUGINS)
245 resource_id
= use_blocked
? IDR_BLOCKED_PLUGINS
: IDR_ALLOWED_PLUGINS
;
248 resource_id
= kInvalidResourceID
;
251 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
252 resource_id
= use_blocked
? IDR_BLOCKED_LOCATION
: IDR_ALLOWED_LOCATION
;
254 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
256 use_blocked
? IDR_BLOCKED_NOTIFICATION
: IDR_ALLOWED_NOTIFICATION
;
258 case CONTENT_SETTINGS_TYPE_FULLSCREEN
:
259 resource_id
= IDR_ALLOWED_FULLSCREEN
;
261 case CONTENT_SETTINGS_TYPE_MOUSELOCK
:
263 use_blocked
? IDR_BLOCKED_MOUSE_CURSOR
: IDR_ALLOWED_MOUSE_CURSOR
;
265 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
:
266 resource_id
= use_blocked
? IDR_BLOCKED_MIC
: IDR_ALLOWED_MIC
;
268 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA
:
269 resource_id
= use_blocked
? IDR_BLOCKED_CAMERA
: IDR_ALLOWED_CAMERA
;
271 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS
:
272 resource_id
= use_blocked
? IDR_BLOCKED_DOWNLOADS
273 : IDR_ALLOWED_DOWNLOADS
;
275 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
276 resource_id
= use_blocked
? IDR_BLOCKED_MIDI_SYSEX
277 : IDR_ALLOWED_MIDI_SYSEX
;
287 const gfx::Image
& WebsiteSettingsUI::GetPermissionIcon(
288 const PermissionInfo
& info
) {
289 ContentSetting setting
= info
.setting
;
290 if (setting
== CONTENT_SETTING_DEFAULT
)
291 setting
= info
.default_setting
;
292 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
293 return rb
.GetNativeImageNamed(GetPermissionIconID(info
.type
, setting
));
297 int WebsiteSettingsUI::GetIdentityIconID(
298 WebsiteSettings::SiteIdentityStatus status
) {
299 int resource_id
= IDR_PAGEINFO_INFO
;
301 case WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN
:
302 case WebsiteSettings::SITE_IDENTITY_STATUS_INTERNAL_PAGE
:
304 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT
:
305 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT
:
306 resource_id
= IDR_PAGEINFO_GOOD
;
308 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN
:
309 resource_id
= IDR_PAGEINFO_WARNING_MINOR
;
311 case WebsiteSettings::SITE_IDENTITY_STATUS_NO_CERT
:
312 resource_id
= IDR_PAGEINFO_WARNING_MAJOR
;
314 case WebsiteSettings::SITE_IDENTITY_STATUS_ERROR
:
315 resource_id
= IDR_PAGEINFO_BAD
;
317 case WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT
:
318 resource_id
= IDR_PAGEINFO_ENTERPRISE_MANAGED
;
320 case WebsiteSettings::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM
:
321 resource_id
= IDR_PAGEINFO_WARNING_MINOR
;
331 const gfx::Image
& WebsiteSettingsUI::GetIdentityIcon(
332 WebsiteSettings::SiteIdentityStatus status
) {
333 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
334 return rb
.GetNativeImageNamed(GetIdentityIconID(status
));
338 int WebsiteSettingsUI::GetConnectionIconID(
339 WebsiteSettings::SiteConnectionStatus status
) {
340 int resource_id
= IDR_PAGEINFO_INFO
;
342 case WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN
:
343 case WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE
:
345 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED
:
346 resource_id
= IDR_PAGEINFO_GOOD
;
348 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT
:
349 resource_id
= IDR_PAGEINFO_WARNING_MINOR
;
351 case WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED
:
352 resource_id
= IDR_PAGEINFO_WARNING_MAJOR
;
354 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_SCRIPT
:
355 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
:
356 resource_id
= IDR_PAGEINFO_BAD
;
363 const gfx::Image
& WebsiteSettingsUI::GetConnectionIcon(
364 WebsiteSettings::SiteConnectionStatus status
) {
365 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
366 return rb
.GetNativeImageNamed(GetConnectionIconID(status
));