Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: chrome/browser/ui/page_info/website_settings_ui.cc

Issue 2754383004: Rename WebsiteSettings code to PageInfo. (Closed)
Patch Set: Upload missing comment fix for WebSettingsUI -> PageInfoUI. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/page_info/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() : allowed(-1), blocked(-1) {}
131
132 WebsiteSettingsUI::PermissionInfo::PermissionInfo()
133 : type(CONTENT_SETTINGS_TYPE_DEFAULT),
134 setting(CONTENT_SETTING_DEFAULT),
135 default_setting(CONTENT_SETTING_DEFAULT),
136 source(content_settings::SETTING_SOURCE_NONE),
137 is_incognito(false) {}
138
139 WebsiteSettingsUI::ChosenObjectInfo::ChosenObjectInfo(
140 const WebsiteSettings::ChooserUIInfo& ui_info,
141 std::unique_ptr<base::DictionaryValue> object)
142 : ui_info(ui_info), object(std::move(object)) {}
143
144 WebsiteSettingsUI::ChosenObjectInfo::~ChosenObjectInfo() {}
145
146 WebsiteSettingsUI::IdentityInfo::IdentityInfo()
147 : identity_status(WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN),
148 connection_status(WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN),
149 show_ssl_decision_revoke_button(false) {}
150
151 WebsiteSettingsUI::IdentityInfo::~IdentityInfo() {}
152
153 std::unique_ptr<WebsiteSettingsUI::SecurityDescription>
154 WebsiteSettingsUI::IdentityInfo::GetSecurityDescription() const {
155 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description(
156 new WebsiteSettingsUI::SecurityDescription());
157
158 switch (identity_status) {
159 case WebsiteSettings::SITE_IDENTITY_STATUS_INTERNAL_PAGE:
160 // Internal pages have their own UI implementations which should never
161 // call this function.
162 NOTREACHED();
163 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT:
164 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT:
165 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN:
166 case WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT:
167 switch (connection_status) {
168 case WebsiteSettings::
169 SITE_CONNECTION_STATUS_INSECURE_ACTIVE_SUBRESOURCE:
170 return CreateSecurityDescription(IDS_PAGEINFO_NOT_SECURE_SUMMARY,
171 IDS_PAGEINFO_NOT_SECURE_DETAILS);
172 case WebsiteSettings::
173 SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE:
174 return CreateSecurityDescription(IDS_PAGEINFO_MIXED_CONTENT_SUMMARY,
175 IDS_PAGEINFO_MIXED_CONTENT_DETAILS);
176 default:
177 return CreateSecurityDescription(IDS_PAGEINFO_SECURE_SUMMARY,
178 IDS_PAGEINFO_SECURE_DETAILS);
179 }
180 case WebsiteSettings::SITE_IDENTITY_STATUS_MALWARE:
181 return CreateSecurityDescription(IDS_PAGEINFO_MALWARE_SUMMARY,
182 IDS_PAGEINFO_MALWARE_DETAILS);
183 case WebsiteSettings::SITE_IDENTITY_STATUS_SOCIAL_ENGINEERING:
184 return CreateSecurityDescription(IDS_PAGEINFO_SOCIAL_ENGINEERING_SUMMARY,
185 IDS_PAGEINFO_SOCIAL_ENGINEERING_DETAILS);
186 case WebsiteSettings::SITE_IDENTITY_STATUS_UNWANTED_SOFTWARE:
187 return CreateSecurityDescription(IDS_PAGEINFO_UNWANTED_SOFTWARE_SUMMARY,
188 IDS_PAGEINFO_UNWANTED_SOFTWARE_DETAILS);
189 case WebsiteSettings::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM:
190 case WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN:
191 case WebsiteSettings::SITE_IDENTITY_STATUS_NO_CERT:
192 default:
193 return CreateSecurityDescription(IDS_PAGEINFO_NOT_SECURE_SUMMARY,
194 IDS_PAGEINFO_NOT_SECURE_DETAILS);
195 }
196 }
197
198 WebsiteSettingsUI::~WebsiteSettingsUI() {}
199
200 // static
201 base::string16 WebsiteSettingsUI::PermissionTypeToUIString(
202 ContentSettingsType type) {
203 for (const PermissionsUIInfo& info : kPermissionsUIInfo) {
204 if (info.type == type)
205 return l10n_util::GetStringUTF16(info.string_id);
206 }
207 NOTREACHED();
208 return base::string16();
209 }
210
211 // static
212 base::string16 WebsiteSettingsUI::PermissionValueToUIString(
213 ContentSetting value) {
214 switch (value) {
215 case CONTENT_SETTING_ALLOW:
216 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_ALLOW);
217 case CONTENT_SETTING_BLOCK:
218 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_BLOCK);
219 case CONTENT_SETTING_ASK:
220 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_ASK);
221 default:
222 NOTREACHED();
223 return base::string16();
224 }
225 }
226
227 // static
228 base::string16 WebsiteSettingsUI::PermissionActionToUIString(
229 Profile* profile,
230 ContentSettingsType type,
231 ContentSetting setting,
232 ContentSetting default_setting,
233 content_settings::SettingSource source) {
234 ContentSetting effective_setting = setting;
235 if (effective_setting == CONTENT_SETTING_DEFAULT)
236 effective_setting = default_setting;
237
238 #if BUILDFLAG(ENABLE_PLUGINS)
239 HostContentSettingsMap* host_content_settings_map =
240 HostContentSettingsMapFactory::GetForProfile(profile);
241 effective_setting = PluginsFieldTrial::EffectiveContentSetting(
242 host_content_settings_map, type, effective_setting);
243
244 // Display the UI string for ASK instead of DETECT for HTML5 by Default.
245 // TODO(tommycli): Once HTML5 by Default is shipped and the feature flag
246 // is removed, just migrate the actual content setting to ASK.
247 if (PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map) &&
248 effective_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) {
249 effective_setting = CONTENT_SETTING_ASK;
250 }
251 #endif
252
253 const int* button_text_ids = NULL;
254 switch (source) {
255 case content_settings::SETTING_SOURCE_USER:
256 if (setting == CONTENT_SETTING_DEFAULT)
257 button_text_ids = kPermissionButtonTextIDDefaultSetting;
258 else
259 button_text_ids = kPermissionButtonTextIDUserManaged;
260 break;
261 case content_settings::SETTING_SOURCE_POLICY:
262 button_text_ids = kPermissionButtonTextIDPolicyManaged;
263 break;
264 case content_settings::SETTING_SOURCE_EXTENSION:
265 button_text_ids = kPermissionButtonTextIDExtensionManaged;
266 break;
267 case content_settings::SETTING_SOURCE_WHITELIST:
268 case content_settings::SETTING_SOURCE_NONE:
269 default:
270 NOTREACHED();
271 return base::string16();
272 }
273 int button_text_id = button_text_ids[effective_setting];
274 DCHECK_NE(button_text_id, kInvalidResourceID);
275 return l10n_util::GetStringUTF16(button_text_id);
276 }
277
278 // static
279 int WebsiteSettingsUI::GetPermissionIconID(ContentSettingsType type,
280 ContentSetting setting) {
281 bool use_blocked = (setting == CONTENT_SETTING_BLOCK);
282 for (const PermissionsUIInfo& info : kPermissionsUIInfo) {
283 if (info.type == type)
284 return use_blocked ? info.blocked_icon_id : info.allowed_icon_id;
285 }
286 NOTREACHED();
287 return IDR_INFO;
288 }
289
290 // static
291 const gfx::Image& WebsiteSettingsUI::GetPermissionIcon(
292 const PermissionInfo& info) {
293 ContentSetting setting = info.setting;
294 if (setting == CONTENT_SETTING_DEFAULT)
295 setting = info.default_setting;
296 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
297 return rb.GetNativeImageNamed(GetPermissionIconID(info.type, setting));
298 }
299
300 // static
301 base::string16 WebsiteSettingsUI::ChosenObjectToUIString(
302 const ChosenObjectInfo& object) {
303 base::string16 name;
304 object.object->GetString(object.ui_info.ui_name_key, &name);
305 return name;
306 }
307
308 // static
309 const gfx::Image& WebsiteSettingsUI::GetChosenObjectIcon(
310 const ChosenObjectInfo& object,
311 bool deleted) {
312 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
313 return rb.GetNativeImageNamed(deleted ? object.ui_info.blocked_icon_id
314 : object.ui_info.allowed_icon_id);
315 }
316
317 // static
318 int WebsiteSettingsUI::GetIdentityIconID(
319 WebsiteSettings::SiteIdentityStatus status) {
320 int resource_id = IDR_PAGEINFO_INFO;
321 switch (status) {
322 case WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN:
323 case WebsiteSettings::SITE_IDENTITY_STATUS_INTERNAL_PAGE:
324 break;
325 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT:
326 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT:
327 resource_id = IDR_PAGEINFO_GOOD;
328 break;
329 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN:
330 resource_id = IDR_PAGEINFO_WARNING_MINOR;
331 break;
332 case WebsiteSettings::SITE_IDENTITY_STATUS_NO_CERT:
333 resource_id = IDR_PAGEINFO_WARNING_MAJOR;
334 break;
335 case WebsiteSettings::SITE_IDENTITY_STATUS_ERROR:
336 resource_id = IDR_PAGEINFO_BAD;
337 break;
338 case WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT:
339 resource_id = IDR_PAGEINFO_ENTERPRISE_MANAGED;
340 break;
341 case WebsiteSettings::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM:
342 resource_id = IDR_PAGEINFO_WARNING_MINOR;
343 break;
344 default:
345 NOTREACHED();
346 break;
347 }
348 return resource_id;
349 }
350
351 // static
352 const gfx::Image& WebsiteSettingsUI::GetIdentityIcon(
353 WebsiteSettings::SiteIdentityStatus status) {
354 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
355 return rb.GetNativeImageNamed(GetIdentityIconID(status));
356 }
357
358 // static
359 int WebsiteSettingsUI::GetConnectionIconID(
360 WebsiteSettings::SiteConnectionStatus status) {
361 int resource_id = IDR_PAGEINFO_INFO;
362 switch (status) {
363 case WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN:
364 case WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE:
365 break;
366 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED:
367 resource_id = IDR_PAGEINFO_GOOD;
368 break;
369 case WebsiteSettings::SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE:
370 resource_id = IDR_PAGEINFO_WARNING_MINOR;
371 break;
372 case WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED:
373 resource_id = IDR_PAGEINFO_WARNING_MAJOR;
374 break;
375 case WebsiteSettings::SITE_CONNECTION_STATUS_INSECURE_ACTIVE_SUBRESOURCE:
376 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR:
377 resource_id = IDR_PAGEINFO_BAD;
378 break;
379 }
380 return resource_id;
381 }
382
383 // static
384 const gfx::Image& WebsiteSettingsUI::GetConnectionIcon(
385 WebsiteSettings::SiteConnectionStatus status) {
386 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
387 return rb.GetNativeImageNamed(GetConnectionIconID(status));
388 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/page_info/website_settings_ui.h ('k') | chrome/browser/ui/page_info/website_settings_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698