Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / website_settings / website_settings_ui.cc
blob2056f10f8c3b4bee56e2f94268d06d12d22e2032
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"
15 namespace {
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[] = {
22 kInvalidResourceID,
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,
26 kInvalidResourceID,
27 kInvalidResourceID};
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[] = {
35 kInvalidResourceID,
36 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_EXTENSION,
37 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_EXTENSION,
38 kInvalidResourceID,
39 kInvalidResourceID,
40 kInvalidResourceID};
41 static_assert(arraysize(kPermissionButtonTextIDExtensionManaged) ==
42 CONTENT_SETTING_NUM_SETTINGS,
43 "kPermissionButtonTextIDExtensionManaged array size is "
44 "incorrect");
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[] = {
49 kInvalidResourceID,
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,
53 kInvalidResourceID,
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[] = {
62 kInvalidResourceID,
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,
66 kInvalidResourceID,
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");
72 } // namespace
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),
87 cert_id(0),
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);
106 default:
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:
120 default:
121 return l10n_util::GetStringUTF16(
122 IDS_WEBSITE_SETTINGS_NON_SECURE_TRANSPORT);
126 WebsiteSettingsUI::~WebsiteSettingsUI() {
129 // static
130 base::string16 WebsiteSettingsUI::PermissionTypeToUIString(
131 ContentSettingsType type) {
132 switch (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);
161 default:
162 NOTREACHED();
163 return base::string16();
167 // static
168 base::string16 WebsiteSettingsUI::PermissionValueToUIString(
169 ContentSetting value) {
170 switch (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);
177 default:
178 NOTREACHED();
179 return base::string16();
183 // static
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)
194 effective_setting =
195 content_settings::PluginsFieldTrial::EffectiveContentSetting(
196 type, effective_setting);
197 #endif
199 const int* button_text_ids = NULL;
200 switch (source) {
201 case content_settings::SETTING_SOURCE_USER:
202 if (setting == CONTENT_SETTING_DEFAULT)
203 button_text_ids = kPermissionButtonTextIDDefaultSetting;
204 else
205 button_text_ids = kPermissionButtonTextIDUserManaged;
206 break;
207 case content_settings::SETTING_SOURCE_POLICY:
208 button_text_ids = kPermissionButtonTextIDPolicyManaged;
209 break;
210 case content_settings::SETTING_SOURCE_EXTENSION:
211 button_text_ids = kPermissionButtonTextIDExtensionManaged;
212 break;
213 case content_settings::SETTING_SOURCE_WHITELIST:
214 case content_settings::SETTING_SOURCE_NONE:
215 default:
216 NOTREACHED();
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);
224 // static
225 int WebsiteSettingsUI::GetPermissionIconID(ContentSettingsType type,
226 ContentSetting setting) {
227 bool use_blocked = (setting == CONTENT_SETTING_BLOCK);
228 int resource_id = IDR_INFO;
229 switch (type) {
230 case CONTENT_SETTINGS_TYPE_IMAGES:
231 resource_id = use_blocked ? IDR_BLOCKED_IMAGES : IDR_ALLOWED_IMAGES;
232 break;
233 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
234 resource_id =
235 use_blocked ? IDR_BLOCKED_JAVASCRIPT : IDR_ALLOWED_JAVASCRIPT;
236 break;
237 case CONTENT_SETTINGS_TYPE_COOKIES:
238 resource_id = use_blocked ? IDR_BLOCKED_COOKIES : IDR_ACCESSED_COOKIES;
239 break;
240 case CONTENT_SETTINGS_TYPE_POPUPS:
241 resource_id = use_blocked ? IDR_BLOCKED_POPUPS : IDR_ALLOWED_POPUPS;
242 break;
243 case CONTENT_SETTINGS_TYPE_PLUGINS:
244 #if defined(ENABLE_PLUGINS)
245 resource_id = use_blocked ? IDR_BLOCKED_PLUGINS : IDR_ALLOWED_PLUGINS;
246 #else
247 NOTREACHED();
248 resource_id = kInvalidResourceID;
249 #endif
250 break;
251 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
252 resource_id = use_blocked ? IDR_BLOCKED_LOCATION : IDR_ALLOWED_LOCATION;
253 break;
254 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
255 resource_id =
256 use_blocked ? IDR_BLOCKED_NOTIFICATION : IDR_ALLOWED_NOTIFICATION;
257 break;
258 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
259 resource_id = IDR_ALLOWED_FULLSCREEN;
260 break;
261 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
262 resource_id =
263 use_blocked ? IDR_BLOCKED_MOUSE_CURSOR : IDR_ALLOWED_MOUSE_CURSOR;
264 break;
265 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
266 resource_id = use_blocked ? IDR_BLOCKED_MIC : IDR_ALLOWED_MIC;
267 break;
268 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
269 resource_id = use_blocked ? IDR_BLOCKED_CAMERA : IDR_ALLOWED_CAMERA;
270 break;
271 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
272 resource_id = use_blocked ? IDR_BLOCKED_DOWNLOADS
273 : IDR_ALLOWED_DOWNLOADS;
274 break;
275 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
276 resource_id = use_blocked ? IDR_BLOCKED_MIDI_SYSEX
277 : IDR_ALLOWED_MIDI_SYSEX;
278 break;
279 default:
280 NOTREACHED();
281 break;
283 return resource_id;
286 // static
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));
296 // static
297 int WebsiteSettingsUI::GetIdentityIconID(
298 WebsiteSettings::SiteIdentityStatus status) {
299 int resource_id = IDR_PAGEINFO_INFO;
300 switch (status) {
301 case WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN:
302 case WebsiteSettings::SITE_IDENTITY_STATUS_INTERNAL_PAGE:
303 break;
304 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT:
305 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT:
306 resource_id = IDR_PAGEINFO_GOOD;
307 break;
308 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN:
309 resource_id = IDR_PAGEINFO_WARNING_MINOR;
310 break;
311 case WebsiteSettings::SITE_IDENTITY_STATUS_NO_CERT:
312 resource_id = IDR_PAGEINFO_WARNING_MAJOR;
313 break;
314 case WebsiteSettings::SITE_IDENTITY_STATUS_ERROR:
315 resource_id = IDR_PAGEINFO_BAD;
316 break;
317 case WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT:
318 resource_id = IDR_PAGEINFO_ENTERPRISE_MANAGED;
319 break;
320 case WebsiteSettings::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM:
321 resource_id = IDR_PAGEINFO_WARNING_MINOR;
322 break;
323 default:
324 NOTREACHED();
325 break;
327 return resource_id;
330 // static
331 const gfx::Image& WebsiteSettingsUI::GetIdentityIcon(
332 WebsiteSettings::SiteIdentityStatus status) {
333 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
334 return rb.GetNativeImageNamed(GetIdentityIconID(status));
337 // static
338 int WebsiteSettingsUI::GetConnectionIconID(
339 WebsiteSettings::SiteConnectionStatus status) {
340 int resource_id = IDR_PAGEINFO_INFO;
341 switch (status) {
342 case WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN:
343 case WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE:
344 break;
345 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED:
346 resource_id = IDR_PAGEINFO_GOOD;
347 break;
348 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT:
349 resource_id = IDR_PAGEINFO_WARNING_MINOR;
350 break;
351 case WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED:
352 resource_id = IDR_PAGEINFO_WARNING_MAJOR;
353 break;
354 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_SCRIPT:
355 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR:
356 resource_id = IDR_PAGEINFO_BAD;
357 break;
359 return resource_id;
362 // static
363 const gfx::Image& WebsiteSettingsUI::GetConnectionIcon(
364 WebsiteSettings::SiteConnectionStatus status) {
365 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
366 return rb.GetNativeImageNamed(GetConnectionIconID(status));