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 "grit/generated_resources.h" 8 #include "grit/theme_resources.h" 9 #include "grit/ui_resources.h" 10 #include "ui/base/l10n/l10n_util.h" 11 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/gfx/image/image.h" 13 14 namespace { 15 16 const int kInvalidResourceID = -1; 17 18 // The resource id's for the strings that are displayed on the permissions 19 // button if the permission setting is managed by policy. 20 const int kPermissionButtonTextIDPolicyManaged[] = { 21 kInvalidResourceID, 22 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_POLICY, 23 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_POLICY, 24 kInvalidResourceID, 25 kInvalidResourceID 26 }; 27 COMPILE_ASSERT(arraysize(kPermissionButtonTextIDPolicyManaged) == 28 CONTENT_SETTING_NUM_SETTINGS, 29 button_text_id_array_size_incorrect); 30 31 // The resource id's for the strings that are displayed on the permissions 32 // button if the permission setting is managed by an extension. 33 const int kPermissionButtonTextIDExtensionManaged[] = { 34 kInvalidResourceID, 35 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_EXTENSION, 36 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_EXTENSION, 37 kInvalidResourceID, 38 kInvalidResourceID 39 }; 40 COMPILE_ASSERT(arraysize(kPermissionButtonTextIDExtensionManaged) == 41 CONTENT_SETTING_NUM_SETTINGS, 42 button_text_id_array_size_incorrect); 43 44 // The resource id's for the strings that are displayed on the permissions 45 // button if the permission setting is managed by the user. 46 const int kPermissionButtonTextIDUserManaged[] = { 47 kInvalidResourceID, 48 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_USER, 49 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_USER, 50 kInvalidResourceID, 51 kInvalidResourceID 52 }; 53 COMPILE_ASSERT(arraysize(kPermissionButtonTextIDUserManaged) == 54 CONTENT_SETTING_NUM_SETTINGS, 55 button_text_id_array_size_incorrect); 56 57 // The resource id's for the strings that are displayed on the permissions 58 // button if the permission setting is the global default setting. 59 const int kPermissionButtonTextIDDefaultSetting[] = { 60 kInvalidResourceID, 61 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ALLOWED_BY_DEFAULT, 62 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_BLOCKED_BY_DEFAULT, 63 IDS_WEBSITE_SETTINGS_BUTTON_TEXT_ASK_BY_DEFAULT, 64 kInvalidResourceID 65 }; 66 COMPILE_ASSERT(arraysize(kPermissionButtonTextIDDefaultSetting) == 67 CONTENT_SETTING_NUM_SETTINGS, 68 button_text_id_array_size_incorrect); 69 70 } // namespace 71 72 WebsiteSettingsUI::CookieInfo::CookieInfo() 73 : allowed(-1), blocked(-1) { 74 } 75 76 WebsiteSettingsUI::PermissionInfo::PermissionInfo() 77 : type(CONTENT_SETTINGS_TYPE_DEFAULT), 78 setting(CONTENT_SETTING_DEFAULT), 79 default_setting(CONTENT_SETTING_DEFAULT), 80 source(content_settings::SETTING_SOURCE_NONE) { 81 } 82 83 WebsiteSettingsUI::IdentityInfo::IdentityInfo() 84 : identity_status(WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN), 85 cert_id(0), 86 connection_status(WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN) { 87 } 88 89 base::string16 WebsiteSettingsUI::IdentityInfo::GetIdentityStatusText() const { 90 if (identity_status == WebsiteSettings::SITE_IDENTITY_STATUS_CERT || 91 identity_status == WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT) { 92 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_IDENTITY_VERIFIED); 93 } 94 if (identity_status == 95 WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT) { 96 return l10n_util::GetStringUTF16(IDS_CERT_POLICY_PROVIDED_CERT_HEADER); 97 } 98 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_IDENTITY_NOT_VERIFIED); 99 } 100 101 WebsiteSettingsUI::~WebsiteSettingsUI() { 102 } 103 104 // static 105 base::string16 WebsiteSettingsUI::PermissionTypeToUIString( 106 ContentSettingsType type) { 107 switch (type) { 108 case CONTENT_SETTINGS_TYPE_IMAGES: 109 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_IMAGES); 110 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: 111 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_JAVASCRIPT); 112 case CONTENT_SETTINGS_TYPE_POPUPS: 113 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_POPUPS); 114 case CONTENT_SETTINGS_TYPE_PLUGINS: 115 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_PLUGINS); 116 case CONTENT_SETTINGS_TYPE_GEOLOCATION: 117 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_LOCATION); 118 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 119 return l10n_util::GetStringUTF16( 120 IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS); 121 case CONTENT_SETTINGS_TYPE_FULLSCREEN: 122 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_FULLSCREEN); 123 case CONTENT_SETTINGS_TYPE_MOUSELOCK: 124 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_MOUSELOCK); 125 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: 126 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM); 127 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: 128 return l10n_util::GetStringUTF16(IDS_AUTOMATIC_DOWNLOADS_TAB_LABEL); 129 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: 130 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_MIDI_SYSEX); 131 default: 132 NOTREACHED(); 133 return base::string16(); 134 } 135 } 136 137 // static 138 base::string16 WebsiteSettingsUI::PermissionValueToUIString( 139 ContentSetting value) { 140 switch (value) { 141 case CONTENT_SETTING_ALLOW: 142 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_ALLOW); 143 case CONTENT_SETTING_BLOCK: 144 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_BLOCK); 145 case CONTENT_SETTING_ASK: 146 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_ASK); 147 default: 148 NOTREACHED(); 149 return base::string16(); 150 } 151 } 152 153 // static 154 base::string16 WebsiteSettingsUI::PermissionActionToUIString( 155 ContentSetting setting, 156 ContentSetting default_setting, 157 content_settings::SettingSource source) { 158 ContentSetting effective_setting = setting; 159 if (effective_setting == CONTENT_SETTING_DEFAULT) 160 effective_setting = default_setting; 161 162 const int* button_text_ids = NULL; 163 switch (source) { 164 case content_settings::SETTING_SOURCE_USER: 165 if (setting == CONTENT_SETTING_DEFAULT) 166 button_text_ids = kPermissionButtonTextIDDefaultSetting; 167 else 168 button_text_ids = kPermissionButtonTextIDUserManaged; 169 break; 170 case content_settings::SETTING_SOURCE_POLICY: 171 button_text_ids = kPermissionButtonTextIDPolicyManaged; 172 break; 173 case content_settings::SETTING_SOURCE_EXTENSION: 174 button_text_ids = kPermissionButtonTextIDExtensionManaged; 175 break; 176 case content_settings::SETTING_SOURCE_WHITELIST: 177 case content_settings::SETTING_SOURCE_NONE: 178 default: 179 NOTREACHED(); 180 return base::string16(); 181 } 182 int button_text_id = button_text_ids[effective_setting]; 183 DCHECK_NE(button_text_id, kInvalidResourceID); 184 return l10n_util::GetStringUTF16(button_text_id); 185 } 186 187 // static 188 int WebsiteSettingsUI::GetPermissionIconID(ContentSettingsType type, 189 ContentSetting setting) { 190 bool use_blocked = (setting == CONTENT_SETTING_BLOCK); 191 int resource_id = IDR_INFO; 192 switch (type) { 193 case CONTENT_SETTINGS_TYPE_IMAGES: 194 resource_id = use_blocked ? IDR_BLOCKED_IMAGES : IDR_ALLOWED_IMAGES; 195 break; 196 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: 197 resource_id = 198 use_blocked ? IDR_BLOCKED_JAVASCRIPT : IDR_ALLOWED_JAVASCRIPT; 199 break; 200 case CONTENT_SETTINGS_TYPE_COOKIES: 201 resource_id = use_blocked ? IDR_BLOCKED_COOKIES : IDR_ACCESSED_COOKIES; 202 break; 203 case CONTENT_SETTINGS_TYPE_POPUPS: 204 resource_id = use_blocked ? IDR_BLOCKED_POPUPS : IDR_ALLOWED_POPUPS; 205 break; 206 case CONTENT_SETTINGS_TYPE_PLUGINS: 207 resource_id = use_blocked ? IDR_BLOCKED_PLUGINS : IDR_ALLOWED_PLUGINS; 208 break; 209 case CONTENT_SETTINGS_TYPE_GEOLOCATION: 210 resource_id = use_blocked ? IDR_BLOCKED_LOCATION : IDR_ALLOWED_LOCATION; 211 break; 212 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 213 resource_id = 214 use_blocked ? IDR_BLOCKED_NOTIFICATION : IDR_ALLOWED_NOTIFICATION; 215 break; 216 case CONTENT_SETTINGS_TYPE_FULLSCREEN: 217 resource_id = IDR_ALLOWED_FULLSCREEN; 218 break; 219 case CONTENT_SETTINGS_TYPE_MOUSELOCK: 220 resource_id = 221 use_blocked ? IDR_BLOCKED_MOUSE_CURSOR : IDR_ALLOWED_MOUSE_CURSOR; 222 break; 223 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: 224 resource_id = use_blocked ? IDR_BLOCKED_MEDIA : IDR_ASK_MEDIA; 225 break; 226 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: 227 resource_id = use_blocked ? IDR_BLOCKED_DOWNLOADS 228 : IDR_ALLOWED_DOWNLOADS; 229 break; 230 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: 231 resource_id = use_blocked ? IDR_BLOCKED_MIDI_SYSEX 232 : IDR_ALLOWED_MIDI_SYSEX; 233 break; 234 default: 235 NOTREACHED(); 236 break; 237 } 238 return resource_id; 239 } 240 241 // static 242 const gfx::Image& WebsiteSettingsUI::GetPermissionIcon( 243 ContentSettingsType type, 244 ContentSetting setting) { 245 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 246 return rb.GetNativeImageNamed(GetPermissionIconID(type, setting)); 247 } 248 249 // static 250 int WebsiteSettingsUI::GetIdentityIconID( 251 WebsiteSettings::SiteIdentityStatus status) { 252 int resource_id = IDR_PAGEINFO_INFO; 253 switch (status) { 254 case WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN: 255 break; 256 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT: 257 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT: 258 resource_id = IDR_PAGEINFO_GOOD; 259 break; 260 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN: 261 resource_id = IDR_PAGEINFO_WARNING_MINOR; 262 break; 263 case WebsiteSettings::SITE_IDENTITY_STATUS_NO_CERT: 264 resource_id = IDR_PAGEINFO_WARNING_MAJOR; 265 break; 266 case WebsiteSettings::SITE_IDENTITY_STATUS_ERROR: 267 resource_id = IDR_PAGEINFO_BAD; 268 break; 269 case WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT: 270 resource_id = IDR_PAGEINFO_ENTERPRISE_MANAGED; 271 break; 272 default: 273 NOTREACHED(); 274 break; 275 } 276 return resource_id; 277 } 278 279 // static 280 const gfx::Image& WebsiteSettingsUI::GetIdentityIcon( 281 WebsiteSettings::SiteIdentityStatus status) { 282 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 283 return rb.GetNativeImageNamed(GetIdentityIconID(status)); 284 } 285 286 // static 287 int WebsiteSettingsUI::GetConnectionIconID( 288 WebsiteSettings::SiteConnectionStatus status) { 289 int resource_id = IDR_PAGEINFO_INFO; 290 switch (status) { 291 case WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN: 292 break; 293 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED: 294 resource_id = IDR_PAGEINFO_GOOD; 295 break; 296 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT: 297 resource_id = IDR_PAGEINFO_WARNING_MINOR; 298 break; 299 case WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED: 300 resource_id = IDR_PAGEINFO_WARNING_MAJOR; 301 break; 302 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR: 303 resource_id = IDR_PAGEINFO_BAD; 304 break; 305 default: 306 NOTREACHED(); 307 break; 308 } 309 return resource_id; 310 } 311 312 // static 313 const gfx::Image& WebsiteSettingsUI::GetConnectionIcon( 314 WebsiteSettings::SiteConnectionStatus status) { 315 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 316 return rb.GetNativeImageNamed(GetConnectionIconID(status)); 317 } 318 319 // static 320 int WebsiteSettingsUI::GetFirstVisitIconID(const base::string16& first_visit) { 321 // FIXME(markusheintz): Display a minor warning icon if the page is visited 322 // the first time. 323 return IDR_PAGEINFO_INFO; 324 } 325 326 // static 327 const gfx::Image& WebsiteSettingsUI::GetFirstVisitIcon( 328 const base::string16& first_visit) { 329 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 330 return rb.GetNativeImageNamed(GetFirstVisitIconID(first_visit)); 331 } 332