Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/page_info/page_info_ui.h" | 5 #include "chrome/browser/ui/page_info/page_info_ui.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/permissions/permission_manager.h" | |
| 10 #include "chrome/browser/permissions/permission_result.h" | |
| 11 #include "chrome/browser/permissions/permission_util.h" | |
| 9 #include "chrome/browser/plugins/plugin_utils.h" | 12 #include "chrome/browser/plugins/plugin_utils.h" |
| 10 #include "chrome/browser/plugins/plugins_field_trial.h" | 13 #include "chrome/browser/plugins/plugins_field_trial.h" |
| 11 #include "chrome/common/chrome_features.h" | 14 #include "chrome/common/chrome_features.h" |
| 12 #include "chrome/grit/chromium_strings.h" | 15 #include "chrome/grit/chromium_strings.h" |
| 13 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 14 #include "chrome/grit/theme_resources.h" | 17 #include "chrome/grit/theme_resources.h" |
| 15 #include "components/strings/grit/components_strings.h" | 18 #include "components/strings/grit/components_strings.h" |
| 16 #include "ppapi/features/features.h" | 19 #include "ppapi/features/features.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 23 #include "url/gurl.h" | |
| 20 | 24 |
| 21 namespace { | 25 namespace { |
| 22 | 26 |
| 23 const int kInvalidResourceID = -1; | 27 const int kInvalidResourceID = -1; |
| 24 | 28 |
| 25 // The resource IDs for the strings that are displayed on the permissions | 29 // 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_PAGE_INFO_BUTTON_TEXT_ALLOWED_BY_POLICY, | |
| 30 IDS_PAGE_INFO_BUTTON_TEXT_BLOCKED_BY_POLICY, | |
| 31 IDS_PAGE_INFO_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_PAGE_INFO_BUTTON_TEXT_ALLOWED_BY_EXTENSION, | |
| 43 IDS_PAGE_INFO_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. | 30 // button if the permission setting is managed by the user. |
| 54 const int kPermissionButtonTextIDUserManaged[] = { | 31 const int kPermissionButtonTextIDUserManaged[] = { |
| 55 kInvalidResourceID, | 32 kInvalidResourceID, |
| 56 IDS_PAGE_INFO_BUTTON_TEXT_ALLOWED_BY_USER, | 33 IDS_PAGE_INFO_BUTTON_TEXT_ALLOWED_BY_USER, |
| 57 IDS_PAGE_INFO_BUTTON_TEXT_BLOCKED_BY_USER, | 34 IDS_PAGE_INFO_BUTTON_TEXT_BLOCKED_BY_USER, |
| 58 IDS_PAGE_INFO_BUTTON_TEXT_ASK_BY_USER, | 35 IDS_PAGE_INFO_BUTTON_TEXT_ASK_BY_USER, |
| 59 kInvalidResourceID, | 36 kInvalidResourceID, |
| 60 IDS_PAGE_INFO_BUTTON_TEXT_DETECT_IMPORTANT_CONTENT_BY_USER}; | 37 IDS_PAGE_INFO_BUTTON_TEXT_DETECT_IMPORTANT_CONTENT_BY_USER}; |
| 61 static_assert(arraysize(kPermissionButtonTextIDUserManaged) == | 38 static_assert(arraysize(kPermissionButtonTextIDUserManaged) == |
| 62 CONTENT_SETTING_NUM_SETTINGS, | 39 CONTENT_SETTING_NUM_SETTINGS, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 // is removed, just migrate the actual content setting to ASK. | 218 // is removed, just migrate the actual content setting to ASK. |
| 242 if (PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map) && | 219 if (PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map) && |
| 243 effective_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) { | 220 effective_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) { |
| 244 effective_setting = CONTENT_SETTING_ASK; | 221 effective_setting = CONTENT_SETTING_ASK; |
| 245 } | 222 } |
| 246 #endif | 223 #endif |
| 247 | 224 |
| 248 const int* button_text_ids = NULL; | 225 const int* button_text_ids = NULL; |
| 249 switch (source) { | 226 switch (source) { |
| 250 case content_settings::SETTING_SOURCE_USER: | 227 case content_settings::SETTING_SOURCE_USER: |
| 251 if (setting == CONTENT_SETTING_DEFAULT) | 228 |
|
lgarron
2017/03/29 05:49:26
Nit: avoid adding unneeded whitespace.
Patti Lor
2017/03/30 03:27:29
Done.
| |
| 229 if (setting == CONTENT_SETTING_DEFAULT) { | |
| 252 button_text_ids = kPermissionButtonTextIDDefaultSetting; | 230 button_text_ids = kPermissionButtonTextIDDefaultSetting; |
| 253 else | 231 break; |
| 254 button_text_ids = kPermissionButtonTextIDUserManaged; | 232 } |
| 255 break; | 233 // Fallthrough. |
| 256 case content_settings::SETTING_SOURCE_POLICY: | 234 case content_settings::SETTING_SOURCE_POLICY: |
| 257 button_text_ids = kPermissionButtonTextIDPolicyManaged; | |
| 258 break; | |
| 259 case content_settings::SETTING_SOURCE_EXTENSION: | 235 case content_settings::SETTING_SOURCE_EXTENSION: |
| 260 button_text_ids = kPermissionButtonTextIDExtensionManaged; | 236 button_text_ids = kPermissionButtonTextIDUserManaged; |
| 261 break; | 237 break; |
| 262 case content_settings::SETTING_SOURCE_WHITELIST: | 238 case content_settings::SETTING_SOURCE_WHITELIST: |
| 263 case content_settings::SETTING_SOURCE_NONE: | 239 case content_settings::SETTING_SOURCE_NONE: |
| 264 default: | 240 default: |
| 265 NOTREACHED(); | 241 NOTREACHED(); |
| 266 return base::string16(); | 242 return base::string16(); |
| 267 } | 243 } |
| 268 int button_text_id = button_text_ids[effective_setting]; | 244 int button_text_id = button_text_ids[effective_setting]; |
| 269 DCHECK_NE(button_text_id, kInvalidResourceID); | 245 DCHECK_NE(button_text_id, kInvalidResourceID); |
| 270 return l10n_util::GetStringUTF16(button_text_id); | 246 return l10n_util::GetStringUTF16(button_text_id); |
| 271 } | 247 } |
| 272 | 248 |
| 273 // static | 249 // static |
| 274 int PageInfoUI::GetPermissionIconID(ContentSettingsType type, | 250 int PageInfoUI::GetPermissionIconID(ContentSettingsType type, |
| 275 ContentSetting setting) { | 251 ContentSetting setting) { |
| 276 bool use_blocked = (setting == CONTENT_SETTING_BLOCK); | 252 bool use_blocked = (setting == CONTENT_SETTING_BLOCK); |
| 277 for (const PermissionsUIInfo& info : kPermissionsUIInfo) { | 253 for (const PermissionsUIInfo& info : kPermissionsUIInfo) { |
| 278 if (info.type == type) | 254 if (info.type == type) |
| 279 return use_blocked ? info.blocked_icon_id : info.allowed_icon_id; | 255 return use_blocked ? info.blocked_icon_id : info.allowed_icon_id; |
| 280 } | 256 } |
| 281 NOTREACHED(); | 257 NOTREACHED(); |
| 282 return IDR_INFO; | 258 return IDR_INFO; |
| 283 } | 259 } |
| 284 | 260 |
| 285 // static | 261 // static |
| 262 base::string16 PageInfoUI::PermissionDecisionReasonToUIString( | |
| 263 Profile* profile, | |
| 264 const PageInfoUI::PermissionInfo& permission, | |
| 265 const GURL& url) { | |
| 266 int message_id = kInvalidResourceID; | |
| 267 switch (permission.source) { | |
| 268 case content_settings::SettingSource::SETTING_SOURCE_POLICY: | |
| 269 message_id = IDS_WEBSITE_SETTINGS_PERMISSION_SET_BY_POLICY; | |
| 270 break; | |
| 271 case content_settings::SettingSource::SETTING_SOURCE_EXTENSION: | |
| 272 message_id = IDS_WEBSITE_SETTINGS_PERMISSION_SET_BY_EXTENSION; | |
| 273 break; | |
| 274 default: | |
| 275 break; | |
| 276 } | |
| 277 | |
| 278 if (permission.setting == CONTENT_SETTING_BLOCK && | |
| 279 PermissionUtil::IsPermission(permission.type)) { | |
| 280 PermissionResult permission_result = | |
| 281 PermissionManager::Get(profile)->GetPermissionStatus(permission.type, | |
| 282 url, url); | |
| 283 switch (permission_result.source) { | |
| 284 case PermissionStatusSource::MULTIPLE_DISMISSALS: | |
| 285 case PermissionStatusSource::SAFE_BROWSING_BLACKLIST: | |
| 286 message_id = IDS_WEBSITE_SETTINGS_PERMISSION_AUTOMATICALLY_BLOCKED; | |
| 287 break; | |
| 288 default: | |
| 289 break; | |
| 290 } | |
| 291 } | |
| 292 | |
| 293 if (message_id == kInvalidResourceID) | |
| 294 return base::string16(); | |
| 295 return l10n_util::GetStringUTF16(message_id); | |
| 296 } | |
| 297 | |
| 298 // static | |
| 286 const gfx::Image& PageInfoUI::GetPermissionIcon(const PermissionInfo& info) { | 299 const gfx::Image& PageInfoUI::GetPermissionIcon(const PermissionInfo& info) { |
| 287 ContentSetting setting = info.setting; | 300 ContentSetting setting = info.setting; |
| 288 if (setting == CONTENT_SETTING_DEFAULT) | 301 if (setting == CONTENT_SETTING_DEFAULT) |
| 289 setting = info.default_setting; | 302 setting = info.default_setting; |
| 290 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 303 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 291 return rb.GetNativeImageNamed(GetPermissionIconID(info.type, setting)); | 304 return rb.GetNativeImageNamed(GetPermissionIconID(info.type, setting)); |
| 292 } | 305 } |
| 293 | 306 |
| 294 // static | 307 // static |
| 295 base::string16 PageInfoUI::ChosenObjectToUIString( | 308 base::string16 PageInfoUI::ChosenObjectToUIString( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 } | 384 } |
| 372 return resource_id; | 385 return resource_id; |
| 373 } | 386 } |
| 374 | 387 |
| 375 // static | 388 // static |
| 376 const gfx::Image& PageInfoUI::GetConnectionIcon( | 389 const gfx::Image& PageInfoUI::GetConnectionIcon( |
| 377 PageInfo::SiteConnectionStatus status) { | 390 PageInfo::SiteConnectionStatus status) { |
| 378 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 391 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 379 return rb.GetNativeImageNamed(GetConnectionIconID(status)); | 392 return rb.GetNativeImageNamed(GetConnectionIconID(status)); |
| 380 } | 393 } |
| OLD | NEW |