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/content_settings/content_setting_bubble_model.h" | 5 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/api/infobars/infobar_service.h" | 8 #include "chrome/browser/api/infobars/infobar_service.h" |
9 #include "chrome/browser/content_settings/content_settings_utils.h" | 9 #include "chrome/browser/content_settings/content_settings_utils.h" |
10 #include "chrome/browser/content_settings/cookie_settings.h" | 10 #include "chrome/browser/content_settings/cookie_settings.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 84 } |
85 | 85 |
86 void ContentSettingTitleAndLinkModel::SetTitle() { | 86 void ContentSettingTitleAndLinkModel::SetTitle() { |
87 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { | 87 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { |
88 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, | 88 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, |
89 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, | 89 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, |
90 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, | 90 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, |
91 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE}, | 91 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE}, |
92 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE}, | 92 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE}, |
93 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, | 93 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, |
94 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, | 94 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, |
| 95 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, |
| 96 IDS_BLOCKED_PPAPI_BROKER_TITLE}, |
95 }; | 97 }; |
96 // Fields as for kBlockedTitleIDs, above. | 98 // Fields as for kBlockedTitleIDs, above. |
97 static const ContentSettingsTypeIdEntry | 99 static const ContentSettingsTypeIdEntry |
98 kResourceSpecificBlockedTitleIDs[] = { | 100 kResourceSpecificBlockedTitleIDs[] = { |
99 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE}, | 101 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE}, |
100 }; | 102 }; |
101 static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = { | 103 static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = { |
102 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE}, | 104 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE}, |
| 105 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_TITLE}, |
103 }; | 106 }; |
104 const ContentSettingsTypeIdEntry *title_ids = kBlockedTitleIDs; | 107 const ContentSettingsTypeIdEntry *title_ids = kBlockedTitleIDs; |
105 size_t num_title_ids = arraysize(kBlockedTitleIDs); | 108 size_t num_title_ids = arraysize(kBlockedTitleIDs); |
106 if (web_contents() && | 109 if (web_contents() && |
107 TabSpecificContentSettings::FromWebContents( | 110 TabSpecificContentSettings::FromWebContents( |
108 web_contents())->IsContentAccessed(content_type()) && | 111 web_contents())->IsContentAccessed(content_type()) && |
109 !TabSpecificContentSettings::FromWebContents( | 112 !TabSpecificContentSettings::FromWebContents( |
110 web_contents())->IsContentBlocked(content_type())) { | 113 web_contents())->IsContentBlocked(content_type())) { |
111 title_ids = kAccessedTitleIDs; | 114 title_ids = kAccessedTitleIDs; |
112 num_title_ids = arraysize(kAccessedTitleIDs); | 115 num_title_ids = arraysize(kAccessedTitleIDs); |
(...skipping 10 matching lines...) Expand all Loading... |
123 void ContentSettingTitleAndLinkModel::SetManageLink() { | 126 void ContentSettingTitleAndLinkModel::SetManageLink() { |
124 static const ContentSettingsTypeIdEntry kLinkIDs[] = { | 127 static const ContentSettingsTypeIdEntry kLinkIDs[] = { |
125 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, | 128 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, |
126 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, | 129 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, |
127 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, | 130 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, |
128 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, | 131 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, |
129 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, | 132 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, |
130 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, | 133 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, |
131 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, | 134 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, |
132 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK}, | 135 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK}, |
133 {CONTENT_SETTINGS_TYPE_MEDIASTREAM, IDS_MEDIASTREAM_BUBBLE_MANAGE_LINK} | 136 {CONTENT_SETTINGS_TYPE_MEDIASTREAM, IDS_MEDIASTREAM_BUBBLE_MANAGE_LINK}, |
| 137 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_PPAPI_BROKER_BUBBLE_MANAGE_LINK}, |
134 }; | 138 }; |
135 set_manage_link(l10n_util::GetStringUTF8( | 139 set_manage_link(l10n_util::GetStringUTF8( |
136 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); | 140 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); |
137 } | 141 } |
138 | 142 |
139 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() { | 143 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() { |
140 if (delegate_) | 144 if (delegate_) |
141 delegate_->ShowContentSettingsPage(content_type()); | 145 delegate_->ShowContentSettingsPage(content_type()); |
142 } | 146 } |
143 | 147 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 233 } |
230 | 234 |
231 bool ContentSettingSingleRadioGroup::settings_changed() const { | 235 bool ContentSettingSingleRadioGroup::settings_changed() const { |
232 return selected_item_ != bubble_content().radio_group.default_item; | 236 return selected_item_ != bubble_content().radio_group.default_item; |
233 } | 237 } |
234 | 238 |
235 // Initialize the radio group by setting the appropriate labels for the | 239 // Initialize the radio group by setting the appropriate labels for the |
236 // content type and setting the default value based on the content setting. | 240 // content type and setting the default value based on the content setting. |
237 void ContentSettingSingleRadioGroup::SetRadioGroup() { | 241 void ContentSettingSingleRadioGroup::SetRadioGroup() { |
238 GURL url = web_contents()->GetURL(); | 242 GURL url = web_contents()->GetURL(); |
239 string16 display_host_utf16; | 243 string16 display_host; |
240 net::AppendFormattedHost( | 244 net::AppendFormattedHost( |
241 url, | 245 url, |
242 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), | 246 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), |
243 &display_host_utf16); | 247 &display_host); |
244 std::string display_host(UTF16ToUTF8(display_host_utf16)); | |
245 | 248 |
246 if (display_host.empty()) | 249 if (display_host.empty()) |
247 display_host = url.spec(); | 250 display_host = ASCIIToUTF16(url.spec()); |
248 | 251 |
249 const std::set<std::string>& resources = | 252 const std::set<std::string>& resources = |
250 bubble_content().resource_identifiers; | 253 bubble_content().resource_identifiers; |
251 | 254 |
| 255 TabSpecificContentSettings* content_settings = |
| 256 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 257 bool allowed = |
| 258 !content_settings->IsContentBlocked(content_type()); |
| 259 DCHECK(!allowed || |
| 260 content_settings->IsContentAccessed(content_type())); |
| 261 |
252 RadioGroup radio_group; | 262 RadioGroup radio_group; |
253 radio_group.url = url; | 263 radio_group.url = url; |
254 | 264 |
255 static const ContentSettingsTypeIdEntry kAllowIDs[] = { | 265 static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = { |
256 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, | 266 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, |
257 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK}, | 267 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK}, |
258 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK}, | 268 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK}, |
259 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL}, | 269 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL}, |
260 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK}, | 270 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK}, |
| 271 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_UNBLOCK}, |
261 }; | 272 }; |
262 // Fields as for kAllowIDs, above. | 273 // Fields as for kBlockedAllowIDs, above. |
263 static const ContentSettingsTypeIdEntry kResourceSpecificAllowIDs[] = { | 274 static const ContentSettingsTypeIdEntry kResourceSpecificBlockedAllowIDs[] = { |
264 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK}, | 275 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK}, |
265 }; | 276 }; |
| 277 static const ContentSettingsTypeIdEntry kAllowedAllowIDs[] = { |
| 278 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_NO_ACTION}, |
| 279 }; |
| 280 |
266 std::string radio_allow_label; | 281 std::string radio_allow_label; |
267 const ContentSettingsTypeIdEntry* allow_ids = resources.empty() ? | 282 if (allowed) { |
268 kAllowIDs : kResourceSpecificAllowIDs; | 283 radio_allow_label = l10n_util::GetStringUTF8( |
269 size_t num_allow_ids = resources.empty() ? | 284 GetIdForContentType(kAllowedAllowIDs, arraysize(kAllowedAllowIDs), |
270 arraysize(kAllowIDs) : arraysize(kResourceSpecificAllowIDs); | 285 content_type())); |
271 radio_allow_label = l10n_util::GetStringFUTF8( | 286 } else if (resources.empty()) { |
272 GetIdForContentType(allow_ids, num_allow_ids, content_type()), | 287 radio_allow_label = l10n_util::GetStringFUTF8( |
273 UTF8ToUTF16(display_host)); | 288 GetIdForContentType(kBlockedAllowIDs, arraysize(kBlockedAllowIDs), |
| 289 content_type()), |
| 290 display_host); |
| 291 } else { |
| 292 radio_allow_label = l10n_util::GetStringFUTF8( |
| 293 GetIdForContentType(kResourceSpecificBlockedAllowIDs, |
| 294 arraysize(kResourceSpecificBlockedAllowIDs), |
| 295 content_type()), |
| 296 display_host); |
| 297 } |
274 | 298 |
275 static const ContentSettingsTypeIdEntry kBlockIDs[] = { | 299 static const ContentSettingsTypeIdEntry kBlockedBlockIDs[] = { |
276 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, | 300 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, |
277 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION}, | 301 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION}, |
278 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION}, | 302 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION}, |
279 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION}, | 303 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION}, |
280 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION}, | 304 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION}, |
| 305 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_NO_ACTION}, |
281 }; | 306 }; |
| 307 static const ContentSettingsTypeIdEntry kAllowedBlockIDs[] = { |
| 308 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_BLOCK}, |
| 309 }; |
| 310 |
282 std::string radio_block_label; | 311 std::string radio_block_label; |
283 radio_block_label = l10n_util::GetStringUTF8( | 312 if (allowed) { |
284 GetIdForContentType(kBlockIDs, arraysize(kBlockIDs), content_type())); | 313 radio_block_label = l10n_util::GetStringFUTF8( |
| 314 GetIdForContentType(kAllowedBlockIDs, arraysize(kAllowedBlockIDs), |
| 315 content_type()), |
| 316 display_host); |
| 317 } else { |
| 318 radio_block_label = l10n_util::GetStringUTF8( |
| 319 GetIdForContentType(kBlockedBlockIDs, arraysize(kBlockedBlockIDs), |
| 320 content_type())); |
| 321 } |
285 | 322 |
286 radio_group.radio_items.push_back(radio_allow_label); | 323 radio_group.radio_items.push_back(radio_allow_label); |
287 radio_group.radio_items.push_back(radio_block_label); | 324 radio_group.radio_items.push_back(radio_block_label); |
288 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | 325 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
289 CookieSettings* cookie_settings = | 326 CookieSettings* cookie_settings = |
290 CookieSettings::Factory::GetForProfile(profile()); | 327 CookieSettings::Factory::GetForProfile(profile()); |
291 ContentSetting most_restrictive_setting; | 328 ContentSetting most_restrictive_setting; |
292 SettingSource most_restrictive_setting_source = SETTING_SOURCE_NONE; | 329 SettingSource most_restrictive_setting_source = SETTING_SOURCE_NONE; |
293 | 330 |
294 if (resources.empty()) { | 331 if (resources.empty()) { |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 995 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
959 DCHECK_EQ(web_contents_, | 996 DCHECK_EQ(web_contents_, |
960 content::Source<WebContents>(source).ptr()); | 997 content::Source<WebContents>(source).ptr()); |
961 web_contents_ = NULL; | 998 web_contents_ = NULL; |
962 } else { | 999 } else { |
963 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 1000 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
964 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 1001 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
965 profile_ = NULL; | 1002 profile_ = NULL; |
966 } | 1003 } |
967 } | 1004 } |
OLD | NEW |