OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/ui/website_settings/website_settings_ui.h" | |
6 | |
7 #include "base/macros.h" | |
8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | |
9 #include "chrome/browser/plugins/plugin_utils.h" | |
10 #include "chrome/browser/plugins/plugins_field_trial.h" | |
11 #include "chrome/common/chrome_features.h" | |
12 #include "chrome/grit/chromium_strings.h" | |
13 #include "chrome/grit/generated_resources.h" | |
14 #include "chrome/grit/theme_resources.h" | |
15 #include "components/strings/grit/components_strings.h" | |
16 #include "ppapi/features/features.h" | |
17 #include "ui/base/l10n/l10n_util.h" | |
18 #include "ui/base/resource/resource_bundle.h" | |
19 #include "ui/gfx/image/image.h" | |
20 | |
21 namespace { | |
22 | |
23 const int kInvalidResourceID = -1; | |
24 | |
25 // The resource IDs for the strings that are displayed on the permissions | |
26 // button if the permission setting is managed by policy. | |
27 const int kPermissionButtonTextIDPolicyManaged[] = { | |
28 kInvalidResourceID, | |
29 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_POLICY, | |
30 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_POLICY, | |
31 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ASK_BY_POLICY, | |
32 kInvalidResourceID, | |
33 kInvalidResourceID}; | |
34 static_assert(arraysize(kPermissionButtonTextIDPolicyManaged) == | |
35 CONTENT_SETTING_NUM_SETTINGS, | |
36 "kPermissionButtonTextIDPolicyManaged array size is incorrect"); | |
37 | |
38 // The resource IDs for the strings that are displayed on the permissions | |
39 // button if the permission setting is managed by an extension. | |
40 const int kPermissionButtonTextIDExtensionManaged[] = { | |
41 kInvalidResourceID, | |
42 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_EXTENSION, | |
43 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_EXTENSION, | |
44 kInvalidResourceID, | |
45 kInvalidResourceID, | |
46 kInvalidResourceID}; | |
47 static_assert(arraysize(kPermissionButtonTextIDExtensionManaged) == | |
48 CONTENT_SETTING_NUM_SETTINGS, | |
49 "kPermissionButtonTextIDExtensionManaged array size is " | |
50 "incorrect"); | |
51 | |
52 // The resource IDs for the strings that are displayed on the permissions | |
53 // button if the permission setting is managed by the user. | |
54 const int kPermissionButtonTextIDUserManaged[] = { | |
55 kInvalidResourceID, | |
56 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_USER, | |
57 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_USER, | |
58 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ASK_BY_USER, | |
59 kInvalidResourceID, | |
60 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_DETECT_IMPORTANT_CONTENT_BY_USER}; | |
61 static_assert(arraysize(kPermissionButtonTextIDUserManaged) == | |
62 CONTENT_SETTING_NUM_SETTINGS, | |
63 "kPermissionButtonTextIDUserManaged array size is incorrect"); | |
64 | |
65 // The resource IDs for the strings that are displayed on the permissions | |
66 // button if the permission setting is the global default setting. | |
67 const int kPermissionButtonTextIDDefaultSetting[] = { | |
68 kInvalidResourceID, | |
69 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_DEFAULT, | |
70 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_DEFAULT, | |
71 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ASK_BY_DEFAULT, | |
72 kInvalidResourceID, | |
73 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_DETECT_IMPORTANT_CONTENT_BY_DEFAULT}; | |
74 static_assert(arraysize(kPermissionButtonTextIDDefaultSetting) == | |
75 CONTENT_SETTING_NUM_SETTINGS, | |
76 "kPermissionButtonTextIDDefaultSetting array size is incorrect"); | |
77 | |
78 struct PermissionsUIInfo { | |
79 ContentSettingsType type; | |
80 int string_id; | |
81 int blocked_icon_id; | |
82 int allowed_icon_id; | |
83 }; | |
84 | |
85 const PermissionsUIInfo kPermissionsUIInfo[] = { | |
86 {CONTENT_SETTINGS_TYPE_COOKIES, 0, IDR_BLOCKED_COOKIES, | |
87 IDR_ACCESSED_COOKIES}, | |
88 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_WEBSITE_SETTINGS_TYPE_IMAGES, | |
89 IDR_BLOCKED_IMAGES, IDR_ALLOWED_IMAGES}, | |
90 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_WEBSITE_SETTINGS_TYPE_JAVASCRIPT, | |
91 IDR_BLOCKED_JAVASCRIPT, IDR_ALLOWED_JAVASCRIPT}, | |
92 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_WEBSITE_SETTINGS_TYPE_POPUPS, | |
93 IDR_BLOCKED_POPUPS, IDR_ALLOWED_POPUPS}, | |
94 #if BUILDFLAG(ENABLE_PLUGINS) | |
95 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_WEBSITE_SETTINGS_TYPE_FLASH, | |
96 IDR_BLOCKED_PLUGINS, IDR_ALLOWED_PLUGINS}, | |
97 #endif | |
98 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_WEBSITE_SETTINGS_TYPE_LOCATION, | |
99 IDR_BLOCKED_LOCATION, IDR_ALLOWED_LOCATION}, | |
100 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
101 IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS, IDR_BLOCKED_NOTIFICATION, | |
102 IDR_ALLOWED_NOTIFICATION}, | |
103 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, IDS_WEBSITE_SETTINGS_TYPE_MIC, | |
104 IDR_BLOCKED_MIC, IDR_ALLOWED_MIC}, | |
105 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, IDS_WEBSITE_SETTINGS_TYPE_CAMERA, | |
106 IDR_BLOCKED_CAMERA, IDR_ALLOWED_CAMERA}, | |
107 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | |
108 IDS_AUTOMATIC_DOWNLOADS_TAB_LABEL, IDR_BLOCKED_DOWNLOADS, | |
109 IDR_ALLOWED_DOWNLOADS}, | |
110 {CONTENT_SETTINGS_TYPE_MIDI_SYSEX, IDS_WEBSITE_SETTINGS_TYPE_MIDI_SYSEX, | |
111 IDR_BLOCKED_MIDI_SYSEX, IDR_ALLOWED_MIDI_SYSEX}, | |
112 {CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC, | |
113 IDS_WEBSITE_SETTINGS_TYPE_BACKGROUND_SYNC, IDR_BLOCKED_BACKGROUND_SYNC, | |
114 IDR_ALLOWED_BACKGROUND_SYNC}, | |
115 // Autoplay is Android-only at the moment, and the Origin Info bubble in | |
116 // Android ignores these block/allow icon pairs, so we can specify 0 there. | |
117 {CONTENT_SETTINGS_TYPE_AUTOPLAY, IDS_WEBSITE_SETTINGS_TYPE_AUTOPLAY, 0, 0}, | |
118 }; | |
119 | |
120 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> | |
121 CreateSecurityDescription(int summary_id, int details_id) { | |
122 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description( | |
123 new WebsiteSettingsUI::SecurityDescription()); | |
124 security_description->summary = l10n_util::GetStringUTF16(summary_id); | |
125 security_description->details = l10n_util::GetStringUTF16(details_id); | |
126 return security_description; | |
127 } | |
128 } // namespace | |
129 | |
130 WebsiteSettingsUI::CookieInfo::CookieInfo() | |
131 : allowed(-1), blocked(-1) { | |
132 } | |
133 | |
134 WebsiteSettingsUI::PermissionInfo::PermissionInfo() | |
135 : type(CONTENT_SETTINGS_TYPE_DEFAULT), | |
136 setting(CONTENT_SETTING_DEFAULT), | |
137 default_setting(CONTENT_SETTING_DEFAULT), | |
138 source(content_settings::SETTING_SOURCE_NONE), | |
139 is_incognito(false) {} | |
140 | |
141 WebsiteSettingsUI::ChosenObjectInfo::ChosenObjectInfo( | |
142 const WebsiteSettings::ChooserUIInfo& ui_info, | |
143 std::unique_ptr<base::DictionaryValue> object) | |
144 : ui_info(ui_info), object(std::move(object)) {} | |
145 | |
146 WebsiteSettingsUI::ChosenObjectInfo::~ChosenObjectInfo() {} | |
147 | |
148 WebsiteSettingsUI::IdentityInfo::IdentityInfo() | |
149 : identity_status(WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN), | |
150 connection_status(WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN), | |
151 show_ssl_decision_revoke_button(false) { | |
152 } | |
153 | |
154 WebsiteSettingsUI::IdentityInfo::~IdentityInfo() {} | |
155 | |
156 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> | |
157 WebsiteSettingsUI::IdentityInfo::GetSecurityDescription() const { | |
158 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description( | |
159 new WebsiteSettingsUI::SecurityDescription()); | |
160 | |
161 switch (identity_status) { | |
162 case WebsiteSettings::SITE_IDENTITY_STATUS_INTERNAL_PAGE: | |
163 // Internal pages have their own UI implementations which should never | |
164 // call this function. | |
165 NOTREACHED(); | |
166 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT: | |
167 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT: | |
168 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN: | |
169 case WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT: | |
170 switch (connection_status) { | |
171 case WebsiteSettings:: | |
172 SITE_CONNECTION_STATUS_INSECURE_ACTIVE_SUBRESOURCE: | |
173 return CreateSecurityDescription( | |
174 IDS_PAGEINFO_NOT_SECURE_SUMMARY, | |
175 IDS_PAGEINFO_NOT_SECURE_DETAILS); | |
176 case WebsiteSettings:: | |
177 SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE: | |
178 return CreateSecurityDescription( | |
179 IDS_PAGEINFO_MIXED_CONTENT_SUMMARY, | |
180 IDS_PAGEINFO_MIXED_CONTENT_DETAILS); | |
181 default: | |
182 return CreateSecurityDescription(IDS_PAGEINFO_SECURE_SUMMARY, | |
183 IDS_PAGEINFO_SECURE_DETAILS); | |
184 } | |
185 case WebsiteSettings::SITE_IDENTITY_STATUS_MALWARE: | |
186 return CreateSecurityDescription(IDS_PAGEINFO_MALWARE_SUMMARY, | |
187 IDS_PAGEINFO_MALWARE_DETAILS); | |
188 case WebsiteSettings::SITE_IDENTITY_STATUS_SOCIAL_ENGINEERING: | |
189 return CreateSecurityDescription( | |
190 IDS_PAGEINFO_SOCIAL_ENGINEERING_SUMMARY, | |
191 IDS_PAGEINFO_SOCIAL_ENGINEERING_DETAILS); | |
192 case WebsiteSettings::SITE_IDENTITY_STATUS_UNWANTED_SOFTWARE: | |
193 return CreateSecurityDescription( | |
194 IDS_PAGEINFO_UNWANTED_SOFTWARE_SUMMARY, | |
195 IDS_PAGEINFO_UNWANTED_SOFTWARE_DETAILS); | |
196 case WebsiteSettings::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM: | |
197 case WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN: | |
198 case WebsiteSettings::SITE_IDENTITY_STATUS_NO_CERT: | |
199 default: | |
200 return CreateSecurityDescription(IDS_PAGEINFO_NOT_SECURE_SUMMARY, | |
201 IDS_PAGEINFO_NOT_SECURE_DETAILS); | |
202 } | |
203 } | |
204 | |
205 WebsiteSettingsUI::~WebsiteSettingsUI() { | |
206 } | |
207 | |
208 // static | |
209 base::string16 WebsiteSettingsUI::PermissionTypeToUIString( | |
210 ContentSettingsType type) { | |
211 for (const PermissionsUIInfo& info : kPermissionsUIInfo) { | |
212 if (info.type == type) | |
213 return l10n_util::GetStringUTF16(info.string_id); | |
214 } | |
215 NOTREACHED(); | |
216 return base::string16(); | |
217 } | |
218 | |
219 // static | |
220 base::string16 WebsiteSettingsUI::PermissionValueToUIString( | |
221 ContentSetting value) { | |
222 switch (value) { | |
223 case CONTENT_SETTING_ALLOW: | |
224 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_ALLOW); | |
225 case CONTENT_SETTING_BLOCK: | |
226 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_BLOCK); | |
227 case CONTENT_SETTING_ASK: | |
228 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_ASK); | |
229 default: | |
230 NOTREACHED(); | |
231 return base::string16(); | |
232 } | |
233 } | |
234 | |
235 // static | |
236 base::string16 WebsiteSettingsUI::PermissionActionToUIString( | |
237 Profile* profile, | |
238 ContentSettingsType type, | |
239 ContentSetting setting, | |
240 ContentSetting default_setting, | |
241 content_settings::SettingSource source) { | |
242 ContentSetting effective_setting = setting; | |
243 if (effective_setting == CONTENT_SETTING_DEFAULT) | |
244 effective_setting = default_setting; | |
245 | |
246 #if BUILDFLAG(ENABLE_PLUGINS) | |
247 HostContentSettingsMap* host_content_settings_map = | |
248 HostContentSettingsMapFactory::GetForProfile(profile); | |
249 effective_setting = PluginsFieldTrial::EffectiveContentSetting( | |
250 host_content_settings_map, type, effective_setting); | |
251 | |
252 // Display the UI string for ASK instead of DETECT for HTML5 by Default. | |
253 // TODO(tommycli): Once HTML5 by Default is shipped and the feature flag | |
254 // is removed, just migrate the actual content setting to ASK. | |
255 if (PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map) && | |
256 effective_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) { | |
257 effective_setting = CONTENT_SETTING_ASK; | |
258 } | |
259 #endif | |
260 | |
261 const int* button_text_ids = NULL; | |
262 switch (source) { | |
263 case content_settings::SETTING_SOURCE_USER: | |
264 if (setting == CONTENT_SETTING_DEFAULT) | |
265 button_text_ids = kPermissionButtonTextIDDefaultSetting; | |
266 else | |
267 button_text_ids = kPermissionButtonTextIDUserManaged; | |
268 break; | |
269 case content_settings::SETTING_SOURCE_POLICY: | |
270 button_text_ids = kPermissionButtonTextIDPolicyManaged; | |
271 break; | |
272 case content_settings::SETTING_SOURCE_EXTENSION: | |
273 button_text_ids = kPermissionButtonTextIDExtensionManaged; | |
274 break; | |
275 case content_settings::SETTING_SOURCE_WHITELIST: | |
276 case content_settings::SETTING_SOURCE_NONE: | |
277 default: | |
278 NOTREACHED(); | |
279 return base::string16(); | |
280 } | |
281 int button_text_id = button_text_ids[effective_setting]; | |
282 DCHECK_NE(button_text_id, kInvalidResourceID); | |
283 return l10n_util::GetStringUTF16(button_text_id); | |
284 } | |
285 | |
286 // static | |
287 int WebsiteSettingsUI::GetPermissionIconID(ContentSettingsType type, | |
288 ContentSetting setting) { | |
289 bool use_blocked = (setting == CONTENT_SETTING_BLOCK); | |
290 for (const PermissionsUIInfo& info : kPermissionsUIInfo) { | |
291 if (info.type == type) | |
292 return use_blocked ? info.blocked_icon_id : info.allowed_icon_id; | |
293 } | |
294 NOTREACHED(); | |
295 return IDR_INFO; | |
296 } | |
297 | |
298 // static | |
299 const gfx::Image& WebsiteSettingsUI::GetPermissionIcon( | |
300 const PermissionInfo& info) { | |
301 ContentSetting setting = info.setting; | |
302 if (setting == CONTENT_SETTING_DEFAULT) | |
303 setting = info.default_setting; | |
304 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
305 return rb.GetNativeImageNamed(GetPermissionIconID(info.type, setting)); | |
306 } | |
307 | |
308 // static | |
309 base::string16 WebsiteSettingsUI::ChosenObjectToUIString( | |
310 const ChosenObjectInfo& object) { | |
311 base::string16 name; | |
312 object.object->GetString(object.ui_info.ui_name_key, &name); | |
313 return name; | |
314 } | |
315 | |
316 // static | |
317 const gfx::Image& WebsiteSettingsUI::GetChosenObjectIcon( | |
318 const ChosenObjectInfo& object, | |
319 bool deleted) { | |
320 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
321 return rb.GetNativeImageNamed(deleted ? object.ui_info.blocked_icon_id | |
322 : object.ui_info.allowed_icon_id); | |
323 } | |
324 | |
325 // static | |
326 int WebsiteSettingsUI::GetIdentityIconID( | |
327 WebsiteSettings::SiteIdentityStatus status) { | |
328 int resource_id = IDR_PAGEINFO_INFO; | |
329 switch (status) { | |
330 case WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN: | |
331 case WebsiteSettings::SITE_IDENTITY_STATUS_INTERNAL_PAGE: | |
332 break; | |
333 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT: | |
334 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT: | |
335 resource_id = IDR_PAGEINFO_GOOD; | |
336 break; | |
337 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN: | |
338 resource_id = IDR_PAGEINFO_WARNING_MINOR; | |
339 break; | |
340 case WebsiteSettings::SITE_IDENTITY_STATUS_NO_CERT: | |
341 resource_id = IDR_PAGEINFO_WARNING_MAJOR; | |
342 break; | |
343 case WebsiteSettings::SITE_IDENTITY_STATUS_ERROR: | |
344 resource_id = IDR_PAGEINFO_BAD; | |
345 break; | |
346 case WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT: | |
347 resource_id = IDR_PAGEINFO_ENTERPRISE_MANAGED; | |
348 break; | |
349 case WebsiteSettings::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM: | |
350 resource_id = IDR_PAGEINFO_WARNING_MINOR; | |
351 break; | |
352 default: | |
353 NOTREACHED(); | |
354 break; | |
355 } | |
356 return resource_id; | |
357 } | |
358 | |
359 // static | |
360 const gfx::Image& WebsiteSettingsUI::GetIdentityIcon( | |
361 WebsiteSettings::SiteIdentityStatus status) { | |
362 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
363 return rb.GetNativeImageNamed(GetIdentityIconID(status)); | |
364 } | |
365 | |
366 // static | |
367 int WebsiteSettingsUI::GetConnectionIconID( | |
368 WebsiteSettings::SiteConnectionStatus status) { | |
369 int resource_id = IDR_PAGEINFO_INFO; | |
370 switch (status) { | |
371 case WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN: | |
372 case WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE: | |
373 break; | |
374 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED: | |
375 resource_id = IDR_PAGEINFO_GOOD; | |
376 break; | |
377 case WebsiteSettings::SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE: | |
378 resource_id = IDR_PAGEINFO_WARNING_MINOR; | |
379 break; | |
380 case WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED: | |
381 resource_id = IDR_PAGEINFO_WARNING_MAJOR; | |
382 break; | |
383 case WebsiteSettings::SITE_CONNECTION_STATUS_INSECURE_ACTIVE_SUBRESOURCE: | |
384 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR: | |
385 resource_id = IDR_PAGEINFO_BAD; | |
386 break; | |
387 } | |
388 return resource_id; | |
389 } | |
390 | |
391 // static | |
392 const gfx::Image& WebsiteSettingsUI::GetConnectionIcon( | |
393 WebsiteSettings::SiteConnectionStatus status) { | |
394 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
395 return rb.GetNativeImageNamed(GetConnectionIconID(status)); | |
396 } | |
OLD | NEW |