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" | 9 #include "chrome/browser/permissions/permission_manager.h" |
| 10 #include "chrome/browser/permissions/permission_result.h" | 10 #include "chrome/browser/permissions/permission_result.h" |
| 11 #include "chrome/browser/permissions/permission_util.h" | 11 #include "chrome/browser/permissions/permission_util.h" |
| 12 #include "chrome/browser/plugins/plugin_utils.h" | 12 #include "chrome/browser/plugins/plugin_utils.h" |
| 13 #include "chrome/browser/plugins/plugins_field_trial.h" | 13 #include "chrome/browser/plugins/plugins_field_trial.h" |
| 14 #include "chrome/common/chrome_features.h" | 14 #include "chrome/common/chrome_features.h" |
| 15 #include "chrome/grit/chromium_strings.h" | 15 #include "chrome/grit/chromium_strings.h" |
| 16 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 17 #include "chrome/grit/theme_resources.h" | 17 #include "chrome/grit/theme_resources.h" |
| 18 #include "components/strings/grit/components_strings.h" | 18 #include "components/strings/grit/components_strings.h" |
| 19 #include "ppapi/features/features.h" | 19 #include "ppapi/features/features.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const int kInvalidResourceID = -1; | 27 const int kInvalidResourceID = -1; |
| 28 | 28 |
| 29 // 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 |
| 30 // button if the permission setting is managed by policy. | |
| 31 const int kPermissionButtonTextIDPolicyManaged[] = { | |
| 32 kInvalidResourceID, | |
| 33 IDS_PAGE_INFO_PERMISSION_ALLOWED_BY_POLICY, | |
| 34 IDS_PAGE_INFO_PERMISSION_BLOCKED_BY_POLICY, | |
| 35 IDS_PAGE_INFO_PERMISSION_ASK_BY_POLICY, | |
|
lgarron
2017/04/18 06:40:00
The enterprise policy control page doesn't seem to
Patti Lor
2017/04/19 04:16:31
Acknowledged.
| |
| 36 kInvalidResourceID, | |
| 37 kInvalidResourceID}; | |
| 38 static_assert(arraysize(kPermissionButtonTextIDPolicyManaged) == | |
| 39 CONTENT_SETTING_NUM_SETTINGS, | |
| 40 "kPermissionButtonTextIDPolicyManaged array size is incorrect"); | |
| 41 | |
| 42 // The resource IDs for the strings that are displayed on the permissions | |
| 43 // button if the permission setting is managed by an extension. | |
| 44 const int kPermissionButtonTextIDExtensionManaged[] = { | |
| 45 kInvalidResourceID, | |
| 46 IDS_PAGE_INFO_PERMISSION_ALLOWED_BY_EXTENSION, | |
| 47 IDS_PAGE_INFO_PERMISSION_BLOCKED_BY_EXTENSION, | |
| 48 kInvalidResourceID, | |
|
lgarron
2017/04/18 06:40:00
ASK is possible: https://developer.chrome.com/exte
Patti Lor
2017/04/19 04:16:31
Oops, thanks for digging deeper here - fixed.
| |
| 49 kInvalidResourceID, | |
| 50 kInvalidResourceID}; | |
| 51 static_assert(arraysize(kPermissionButtonTextIDExtensionManaged) == | |
| 52 CONTENT_SETTING_NUM_SETTINGS, | |
| 53 "kPermissionButtonTextIDExtensionManaged array size is " | |
| 54 "incorrect"); | |
| 55 | |
| 56 // The resource IDs for the strings that are displayed on the permissions | |
| 30 // button if the permission setting is managed by the user. | 57 // button if the permission setting is managed by the user. |
| 31 const int kPermissionButtonTextIDUserManaged[] = { | 58 const int kPermissionButtonTextIDUserManaged[] = { |
| 32 kInvalidResourceID, | 59 kInvalidResourceID, |
| 33 IDS_PAGE_INFO_BUTTON_TEXT_ALLOWED_BY_USER, | 60 IDS_PAGE_INFO_BUTTON_TEXT_ALLOWED_BY_USER, |
| 34 IDS_PAGE_INFO_BUTTON_TEXT_BLOCKED_BY_USER, | 61 IDS_PAGE_INFO_BUTTON_TEXT_BLOCKED_BY_USER, |
| 35 IDS_PAGE_INFO_BUTTON_TEXT_ASK_BY_USER, | 62 IDS_PAGE_INFO_BUTTON_TEXT_ASK_BY_USER, |
| 36 kInvalidResourceID, | 63 kInvalidResourceID, |
| 37 IDS_PAGE_INFO_BUTTON_TEXT_DETECT_IMPORTANT_CONTENT_BY_USER}; | 64 IDS_PAGE_INFO_BUTTON_TEXT_DETECT_IMPORTANT_CONTENT_BY_USER}; |
| 38 static_assert(arraysize(kPermissionButtonTextIDUserManaged) == | 65 static_assert(arraysize(kPermissionButtonTextIDUserManaged) == |
| 39 CONTENT_SETTING_NUM_SETTINGS, | 66 CONTENT_SETTING_NUM_SETTINGS, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 123 |
| 97 std::unique_ptr<PageInfoUI::SecurityDescription> CreateSecurityDescription( | 124 std::unique_ptr<PageInfoUI::SecurityDescription> CreateSecurityDescription( |
| 98 int summary_id, | 125 int summary_id, |
| 99 int details_id) { | 126 int details_id) { |
| 100 std::unique_ptr<PageInfoUI::SecurityDescription> security_description( | 127 std::unique_ptr<PageInfoUI::SecurityDescription> security_description( |
| 101 new PageInfoUI::SecurityDescription()); | 128 new PageInfoUI::SecurityDescription()); |
| 102 security_description->summary = l10n_util::GetStringUTF16(summary_id); | 129 security_description->summary = l10n_util::GetStringUTF16(summary_id); |
| 103 security_description->details = l10n_util::GetStringUTF16(details_id); | 130 security_description->details = l10n_util::GetStringUTF16(details_id); |
| 104 return security_description; | 131 return security_description; |
| 105 } | 132 } |
| 133 | |
| 134 // Gets the actual setting for a ContentSettingType, taking into account what | |
| 135 // the default setting value is and whether Html5ByDefault is enabled. | |
| 136 ContentSetting GetEffectiveSetting(Profile* profile, | |
| 137 ContentSettingsType type, | |
| 138 ContentSetting setting, | |
| 139 ContentSetting default_setting) { | |
| 140 ContentSetting effective_setting = setting; | |
| 141 if (effective_setting == CONTENT_SETTING_DEFAULT) | |
| 142 effective_setting = default_setting; | |
| 143 | |
| 144 #if BUILDFLAG(ENABLE_PLUGINS) | |
| 145 HostContentSettingsMap* host_content_settings_map = | |
| 146 HostContentSettingsMapFactory::GetForProfile(profile); | |
| 147 effective_setting = PluginsFieldTrial::EffectiveContentSetting( | |
| 148 host_content_settings_map, type, effective_setting); | |
| 149 | |
| 150 // Display the UI string for ASK instead of DETECT for HTML5 by Default. | |
| 151 // TODO(tommycli): Once HTML5 by Default is shipped and the feature flag | |
| 152 // is removed, just migrate the actual content setting to ASK. | |
| 153 if (PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map) && | |
| 154 effective_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) { | |
| 155 effective_setting = CONTENT_SETTING_ASK; | |
| 156 } | |
| 157 #endif | |
| 158 return effective_setting; | |
| 159 } | |
| 160 | |
| 106 } // namespace | 161 } // namespace |
| 107 | 162 |
| 108 PageInfoUI::CookieInfo::CookieInfo() : allowed(-1), blocked(-1) {} | 163 PageInfoUI::CookieInfo::CookieInfo() : allowed(-1), blocked(-1) {} |
| 109 | 164 |
| 110 PageInfoUI::PermissionInfo::PermissionInfo() | 165 PageInfoUI::PermissionInfo::PermissionInfo() |
| 111 : type(CONTENT_SETTINGS_TYPE_DEFAULT), | 166 : type(CONTENT_SETTINGS_TYPE_DEFAULT), |
| 112 setting(CONTENT_SETTING_DEFAULT), | 167 setting(CONTENT_SETTING_DEFAULT), |
| 113 default_setting(CONTENT_SETTING_DEFAULT), | 168 default_setting(CONTENT_SETTING_DEFAULT), |
| 114 source(content_settings::SETTING_SOURCE_NONE), | 169 source(content_settings::SETTING_SOURCE_NONE), |
| 115 is_incognito(false) {} | 170 is_incognito(false) {} |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 } | 256 } |
| 202 } | 257 } |
| 203 | 258 |
| 204 // static | 259 // static |
| 205 base::string16 PageInfoUI::PermissionActionToUIString( | 260 base::string16 PageInfoUI::PermissionActionToUIString( |
| 206 Profile* profile, | 261 Profile* profile, |
| 207 ContentSettingsType type, | 262 ContentSettingsType type, |
| 208 ContentSetting setting, | 263 ContentSetting setting, |
| 209 ContentSetting default_setting, | 264 ContentSetting default_setting, |
| 210 content_settings::SettingSource source) { | 265 content_settings::SettingSource source) { |
| 211 ContentSetting effective_setting = setting; | 266 ContentSetting effective_setting = |
| 212 if (effective_setting == CONTENT_SETTING_DEFAULT) | 267 GetEffectiveSetting(profile, type, setting, default_setting); |
| 213 effective_setting = default_setting; | |
| 214 | |
| 215 #if BUILDFLAG(ENABLE_PLUGINS) | |
| 216 HostContentSettingsMap* host_content_settings_map = | |
| 217 HostContentSettingsMapFactory::GetForProfile(profile); | |
| 218 effective_setting = PluginsFieldTrial::EffectiveContentSetting( | |
| 219 host_content_settings_map, type, effective_setting); | |
| 220 | |
| 221 // Display the UI string for ASK instead of DETECT for HTML5 by Default. | |
| 222 // TODO(tommycli): Once HTML5 by Default is shipped and the feature flag | |
| 223 // is removed, just migrate the actual content setting to ASK. | |
| 224 if (PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map) && | |
| 225 effective_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) { | |
| 226 effective_setting = CONTENT_SETTING_ASK; | |
| 227 } | |
| 228 #endif | |
| 229 | |
| 230 const int* button_text_ids = NULL; | 268 const int* button_text_ids = NULL; |
| 231 switch (source) { | 269 switch (source) { |
| 232 case content_settings::SETTING_SOURCE_USER: | 270 case content_settings::SETTING_SOURCE_USER: |
| 233 if (setting == CONTENT_SETTING_DEFAULT) { | 271 if (setting == CONTENT_SETTING_DEFAULT) { |
| 234 button_text_ids = kPermissionButtonTextIDDefaultSetting; | 272 button_text_ids = kPermissionButtonTextIDDefaultSetting; |
| 235 break; | 273 break; |
| 236 } | 274 } |
| 237 // Fallthrough. | 275 // Fallthrough. |
| 238 case content_settings::SETTING_SOURCE_POLICY: | 276 case content_settings::SETTING_SOURCE_POLICY: |
| 239 case content_settings::SETTING_SOURCE_EXTENSION: | 277 case content_settings::SETTING_SOURCE_EXTENSION: |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 260 } | 298 } |
| 261 NOTREACHED(); | 299 NOTREACHED(); |
| 262 return IDR_INFO; | 300 return IDR_INFO; |
| 263 } | 301 } |
| 264 | 302 |
| 265 // static | 303 // static |
| 266 base::string16 PageInfoUI::PermissionDecisionReasonToUIString( | 304 base::string16 PageInfoUI::PermissionDecisionReasonToUIString( |
| 267 Profile* profile, | 305 Profile* profile, |
| 268 const PageInfoUI::PermissionInfo& permission, | 306 const PageInfoUI::PermissionInfo& permission, |
| 269 const GURL& url) { | 307 const GURL& url) { |
| 308 ContentSetting effective_setting = GetEffectiveSetting( | |
| 309 profile, permission.type, permission.setting, permission.default_setting); | |
| 270 int message_id = kInvalidResourceID; | 310 int message_id = kInvalidResourceID; |
| 271 switch (permission.source) { | 311 switch (permission.source) { |
| 272 case content_settings::SettingSource::SETTING_SOURCE_POLICY: | 312 case content_settings::SettingSource::SETTING_SOURCE_POLICY: |
| 273 message_id = IDS_PAGE_INFO_PERMISSION_SET_BY_POLICY; | 313 message_id = kPermissionButtonTextIDPolicyManaged[effective_setting]; |
| 274 break; | 314 break; |
| 275 case content_settings::SettingSource::SETTING_SOURCE_EXTENSION: | 315 case content_settings::SettingSource::SETTING_SOURCE_EXTENSION: |
| 276 message_id = IDS_PAGE_INFO_PERMISSION_SET_BY_EXTENSION; | 316 message_id = kPermissionButtonTextIDExtensionManaged[effective_setting]; |
| 277 break; | 317 break; |
| 278 default: | 318 default: |
| 279 break; | 319 break; |
| 280 } | 320 } |
| 281 | 321 |
| 282 if (permission.setting == CONTENT_SETTING_BLOCK && | 322 if (permission.setting == CONTENT_SETTING_BLOCK && |
| 283 PermissionUtil::IsPermission(permission.type)) { | 323 PermissionUtil::IsPermission(permission.type)) { |
| 284 PermissionResult permission_result = | 324 PermissionResult permission_result = |
| 285 PermissionManager::Get(profile)->GetPermissionStatus(permission.type, | 325 PermissionManager::Get(profile)->GetPermissionStatus(permission.type, |
| 286 url, url); | 326 url, url); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 } | 434 } |
| 395 return resource_id; | 435 return resource_id; |
| 396 } | 436 } |
| 397 | 437 |
| 398 // static | 438 // static |
| 399 const gfx::Image& PageInfoUI::GetConnectionIcon( | 439 const gfx::Image& PageInfoUI::GetConnectionIcon( |
| 400 PageInfo::SiteConnectionStatus status) { | 440 PageInfo::SiteConnectionStatus status) { |
| 401 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 441 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 402 return rb.GetNativeImageNamed(GetConnectionIconID(status)); | 442 return rb.GetNativeImageNamed(GetConnectionIconID(status)); |
| 403 } | 443 } |
| OLD | NEW |