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/website_settings/website_settings_ui.h" | 5 #include "chrome/browser/ui/website_settings/website_settings_ui.h" |
6 | 6 |
7 #include "grit/generated_resources.h" | 7 #include "grit/generated_resources.h" |
8 #include "grit/theme_resources.h" | 8 #include "grit/theme_resources.h" |
9 #include "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/gfx/image/image.h" | 12 #include "ui/gfx/image/image.h" |
13 | 13 |
14 namespace { | 14 namespace { |
| 15 |
15 const int kInvalidResourceID = -1; | 16 const int kInvalidResourceID = -1; |
16 } | 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 |
17 | 71 |
18 WebsiteSettingsUI::CookieInfo::CookieInfo() | 72 WebsiteSettingsUI::CookieInfo::CookieInfo() |
19 : allowed(-1), blocked(-1) { | 73 : allowed(-1), blocked(-1) { |
20 } | 74 } |
21 | 75 |
22 WebsiteSettingsUI::PermissionInfo::PermissionInfo() | 76 WebsiteSettingsUI::PermissionInfo::PermissionInfo() |
23 : type(CONTENT_SETTINGS_TYPE_DEFAULT), | 77 : type(CONTENT_SETTINGS_TYPE_DEFAULT), |
24 setting(CONTENT_SETTING_DEFAULT), | 78 setting(CONTENT_SETTING_DEFAULT), |
25 default_setting(CONTENT_SETTING_DEFAULT) { | 79 default_setting(CONTENT_SETTING_DEFAULT), |
| 80 source(content_settings::SETTING_SOURCE_NONE) { |
26 } | 81 } |
27 | 82 |
28 WebsiteSettingsUI::IdentityInfo::IdentityInfo() | 83 WebsiteSettingsUI::IdentityInfo::IdentityInfo() |
29 : identity_status(WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN), | 84 : identity_status(WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN), |
30 cert_id(0), | 85 cert_id(0), |
31 connection_status(WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN) { | 86 connection_status(WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN) { |
32 } | 87 } |
33 | 88 |
34 string16 WebsiteSettingsUI::IdentityInfo::GetIdentityStatusText() const { | 89 string16 WebsiteSettingsUI::IdentityInfo::GetIdentityStatusText() const { |
35 if (identity_status == WebsiteSettings::SITE_IDENTITY_STATUS_CERT || | 90 if (identity_status == WebsiteSettings::SITE_IDENTITY_STATUS_CERT || |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 case CONTENT_SETTING_ASK: | 137 case CONTENT_SETTING_ASK: |
83 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_ASK); | 138 return l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_ASK); |
84 default: | 139 default: |
85 NOTREACHED(); | 140 NOTREACHED(); |
86 return string16(); | 141 return string16(); |
87 } | 142 } |
88 } | 143 } |
89 | 144 |
90 // static | 145 // static |
91 string16 WebsiteSettingsUI::PermissionActionToUIString( | 146 string16 WebsiteSettingsUI::PermissionActionToUIString( |
92 ContentSetting setting, ContentSetting default_setting) { | 147 ContentSetting setting, |
93 ContentSetting setting_value; | 148 ContentSetting default_setting, |
94 int setting_description_id = kInvalidResourceID; | 149 content_settings::SettingSource source) { |
95 int action_description_id = kInvalidResourceID; | 150 ContentSetting effective_setting = setting; |
| 151 if (effective_setting == CONTENT_SETTING_DEFAULT) |
| 152 effective_setting = default_setting; |
96 | 153 |
97 // Check whether or not the default setting was used. | 154 const int* button_text_ids = NULL; |
98 if (setting == CONTENT_SETTING_DEFAULT) { | 155 switch (source) { |
99 setting_value = default_setting; | 156 case content_settings::SETTING_SOURCE_USER: |
100 setting_description_id = IDS_WEBSITE_SETTINGS_DEFAULT_SETTING; | 157 if (setting == CONTENT_SETTING_DEFAULT) |
101 } else { | 158 button_text_ids = kPermissionButtonTextIDDefaultSetting; |
102 setting_value = setting; | 159 else |
103 setting_description_id = IDS_WEBSITE_SETTINGS_USER_SETTING; | 160 button_text_ids = kPermissionButtonTextIDUserManaged; |
104 } | |
105 | |
106 // Determine the string to use to describe the action that was taken, e.g. | |
107 // "Allowed", "Blocked", "Ask". | |
108 switch (setting_value) { | |
109 case CONTENT_SETTING_ALLOW: | |
110 action_description_id = IDS_WEBSITE_SETTINGS_PERMISSION_ACTION_ALLOWED; | |
111 break; | 161 break; |
112 case CONTENT_SETTING_BLOCK: | 162 case content_settings::SETTING_SOURCE_POLICY: |
113 action_description_id = IDS_WEBSITE_SETTINGS_PERMISSION_ACTION_BLOCKED; | 163 button_text_ids = kPermissionButtonTextIDPolicyManaged; |
114 break; | 164 break; |
115 case CONTENT_SETTING_ASK: | 165 case content_settings::SETTING_SOURCE_EXTENSION: |
116 action_description_id = IDS_WEBSITE_SETTINGS_PERMISSION_ACTION_ASK; | 166 button_text_ids = kPermissionButtonTextIDExtensionManaged; |
117 break; | 167 break; |
| 168 case content_settings::SETTING_SOURCE_WHITELIST: |
| 169 case content_settings::SETTING_SOURCE_NONE: |
118 default: | 170 default: |
119 NOTREACHED(); | 171 NOTREACHED(); |
| 172 return string16(); |
120 } | 173 } |
121 return l10n_util::GetStringFUTF16(setting_description_id, | 174 int button_text_id = button_text_ids[effective_setting]; |
122 l10n_util::GetStringUTF16(action_description_id)); | 175 DCHECK_NE(button_text_id, kInvalidResourceID); |
| 176 return l10n_util::GetStringUTF16(button_text_id); |
123 } | 177 } |
124 | 178 |
125 // static | 179 // static |
126 const gfx::Image& WebsiteSettingsUI::GetPermissionIcon( | 180 const gfx::Image& WebsiteSettingsUI::GetPermissionIcon( |
127 ContentSettingsType type, | 181 ContentSettingsType type, |
128 ContentSetting setting) { | 182 ContentSetting setting) { |
129 bool use_blocked = (setting == CONTENT_SETTING_BLOCK); | 183 bool use_blocked = (setting == CONTENT_SETTING_BLOCK); |
130 int resource_id = IDR_INFO; | 184 int resource_id = IDR_INFO; |
131 switch (type) { | 185 switch (type) { |
132 case CONTENT_SETTINGS_TYPE_IMAGES: | 186 case CONTENT_SETTINGS_TYPE_IMAGES: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 287 } |
234 | 288 |
235 // static | 289 // static |
236 const gfx::Image& WebsiteSettingsUI::GetFirstVisitIcon( | 290 const gfx::Image& WebsiteSettingsUI::GetFirstVisitIcon( |
237 const string16& first_visit) { | 291 const string16& first_visit) { |
238 // FIXME(markusheintz): Display a minor warning icon if the page is visited | 292 // FIXME(markusheintz): Display a minor warning icon if the page is visited |
239 // the first time. | 293 // the first time. |
240 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 294 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
241 return rb.GetNativeImageNamed(IDR_PAGEINFO_INFO); | 295 return rb.GetNativeImageNamed(IDR_PAGEINFO_INFO); |
242 } | 296 } |
OLD | NEW |