Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / website_settings / website_settings_ui.cc
blob5078ccfe5cae970a83db4288c1af5397b788fa82
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 resource_id = use_blocked ? IDR_BLOCKED_PLUGINS : IDR_ALLOWED_PLUGINS;
245 break;
246 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
247 resource_id = use_blocked ? IDR_BLOCKED_LOCATION : IDR_ALLOWED_LOCATION;
248 break;
249 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
250 resource_id =
251 use_blocked ? IDR_BLOCKED_NOTIFICATION : IDR_ALLOWED_NOTIFICATION;
252 break;
253 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
254 resource_id = IDR_ALLOWED_FULLSCREEN;
255 break;
256 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
257 resource_id =
258 use_blocked ? IDR_BLOCKED_MOUSE_CURSOR : IDR_ALLOWED_MOUSE_CURSOR;
259 break;
260 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
261 resource_id = use_blocked ? IDR_BLOCKED_MIC : IDR_ALLOWED_MIC;
262 break;
263 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
264 resource_id = use_blocked ? IDR_BLOCKED_CAMERA : IDR_ALLOWED_CAMERA;
265 break;
266 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
267 resource_id = use_blocked ? IDR_BLOCKED_DOWNLOADS
268 : IDR_ALLOWED_DOWNLOADS;
269 break;
270 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
271 resource_id = use_blocked ? IDR_BLOCKED_MIDI_SYSEX
272 : IDR_ALLOWED_MIDI_SYSEX;
273 break;
274 default:
275 NOTREACHED();
276 break;
278 return resource_id;
281 // static
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));
291 // static
292 int WebsiteSettingsUI::GetIdentityIconID(
293 WebsiteSettings::SiteIdentityStatus status) {
294 int resource_id = IDR_PAGEINFO_INFO;
295 switch (status) {
296 case WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN:
297 case WebsiteSettings::SITE_IDENTITY_STATUS_INTERNAL_PAGE:
298 break;
299 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT:
300 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT:
301 resource_id = IDR_PAGEINFO_GOOD;
302 break;
303 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN:
304 resource_id = IDR_PAGEINFO_WARNING_MINOR;
305 break;
306 case WebsiteSettings::SITE_IDENTITY_STATUS_NO_CERT:
307 resource_id = IDR_PAGEINFO_WARNING_MAJOR;
308 break;
309 case WebsiteSettings::SITE_IDENTITY_STATUS_ERROR:
310 resource_id = IDR_PAGEINFO_BAD;
311 break;
312 case WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT:
313 resource_id = IDR_PAGEINFO_ENTERPRISE_MANAGED;
314 break;
315 case WebsiteSettings::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM:
316 resource_id = IDR_PAGEINFO_WARNING_MINOR;
317 break;
318 default:
319 NOTREACHED();
320 break;
322 return resource_id;
325 // static
326 const gfx::Image& WebsiteSettingsUI::GetIdentityIcon(
327 WebsiteSettings::SiteIdentityStatus status) {
328 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
329 return rb.GetNativeImageNamed(GetIdentityIconID(status));
332 // static
333 int WebsiteSettingsUI::GetConnectionIconID(
334 WebsiteSettings::SiteConnectionStatus status) {
335 int resource_id = IDR_PAGEINFO_INFO;
336 switch (status) {
337 case WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN:
338 case WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE:
339 break;
340 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED:
341 resource_id = IDR_PAGEINFO_GOOD;
342 break;
343 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT:
344 resource_id = IDR_PAGEINFO_WARNING_MINOR;
345 break;
346 case WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED:
347 resource_id = IDR_PAGEINFO_WARNING_MAJOR;
348 break;
349 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR:
350 resource_id = IDR_PAGEINFO_BAD;
351 break;
352 default:
353 NOTREACHED();
354 break;
356 return resource_id;
359 // static
360 const gfx::Image& WebsiteSettingsUI::GetConnectionIcon(
361 WebsiteSettings::SiteConnectionStatus status) {
362 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
363 return rb.GetNativeImageNamed(GetConnectionIconID(status));