OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/webui/options/content_settings_handler.h" | 5 #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/content_settings/content_settings_details.h" | 12 #include "chrome/browser/content_settings/content_settings_details.h" |
13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
14 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 15 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
15 #include "chrome/browser/notifications/desktop_notification_service.h" | 16 #include "chrome/browser/notifications/desktop_notification_service.h" |
16 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 17 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/content_settings_helper.h" | 21 #include "chrome/common/content_settings_helper.h" |
21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
23 #include "content/common/notification_service.h" | 24 #include "content/common/notification_service.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 { "blockException", IDS_EXCEPTIONS_BLOCK_BUTTON }, | 193 { "blockException", IDS_EXCEPTIONS_BLOCK_BUTTON }, |
193 { "sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON }, | 194 { "sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON }, |
194 { "askException", IDS_EXCEPTIONS_ASK_BUTTON }, | 195 { "askException", IDS_EXCEPTIONS_ASK_BUTTON }, |
195 { "addExceptionRow", IDS_EXCEPTIONS_ADD_BUTTON }, | 196 { "addExceptionRow", IDS_EXCEPTIONS_ADD_BUTTON }, |
196 { "removeExceptionRow", IDS_EXCEPTIONS_REMOVE_BUTTON }, | 197 { "removeExceptionRow", IDS_EXCEPTIONS_REMOVE_BUTTON }, |
197 { "editExceptionRow", IDS_EXCEPTIONS_EDIT_BUTTON }, | 198 { "editExceptionRow", IDS_EXCEPTIONS_EDIT_BUTTON }, |
198 { "otr_exceptions_explanation", IDS_EXCEPTIONS_OTR_LABEL }, | 199 { "otr_exceptions_explanation", IDS_EXCEPTIONS_OTR_LABEL }, |
199 { "examplePattern", IDS_EXCEPTIONS_PATTERN_EXAMPLE }, | 200 { "examplePattern", IDS_EXCEPTIONS_PATTERN_EXAMPLE }, |
200 { "addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS }, | 201 { "addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS }, |
201 { "manage_exceptions", IDS_EXCEPTIONS_MANAGE }, | 202 { "manage_exceptions", IDS_EXCEPTIONS_MANAGE }, |
| 203 { "manage_handlers", IDS_HANDLERS_MANAGE }, |
202 { "exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER }, | 204 { "exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER }, |
203 { "exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER }, | 205 { "exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER }, |
204 // Cookies filter. | 206 // Cookies filter. |
205 { "cookies_tab_label", IDS_COOKIES_TAB_LABEL }, | 207 { "cookies_tab_label", IDS_COOKIES_TAB_LABEL }, |
206 { "cookies_header", IDS_COOKIES_HEADER }, | 208 { "cookies_header", IDS_COOKIES_HEADER }, |
207 { "cookies_allow", IDS_COOKIES_ALLOW_RADIO }, | 209 { "cookies_allow", IDS_COOKIES_ALLOW_RADIO }, |
208 { "cookies_block", IDS_COOKIES_BLOCK_RADIO }, | 210 { "cookies_block", IDS_COOKIES_BLOCK_RADIO }, |
209 { "cookies_session_only", IDS_COOKIES_SESSION_ONLY_RADIO }, | 211 { "cookies_session_only", IDS_COOKIES_SESSION_ONLY_RADIO }, |
210 { "cookies_block_3rd_party", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX }, | 212 { "cookies_block_3rd_party", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX }, |
211 { "cookies_clear_when_close", IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX }, | 213 { "cookies_clear_when_close", IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX }, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 web_ui_->CallJavascriptFunction("ContentSettings.setBlockThirdPartyCookies", | 266 web_ui_->CallJavascriptFunction("ContentSettings.setBlockThirdPartyCookies", |
265 *block_3rd_party.get()); | 267 *block_3rd_party.get()); |
266 | 268 |
267 notification_registrar_.Add( | 269 notification_registrar_.Add( |
268 this, NotificationType::OTR_PROFILE_CREATED, | 270 this, NotificationType::OTR_PROFILE_CREATED, |
269 NotificationService::AllSources()); | 271 NotificationService::AllSources()); |
270 notification_registrar_.Add( | 272 notification_registrar_.Add( |
271 this, NotificationType::PROFILE_DESTROYED, | 273 this, NotificationType::PROFILE_DESTROYED, |
272 NotificationService::AllSources()); | 274 NotificationService::AllSources()); |
273 | 275 |
| 276 UpdateHandlersEnabledRadios(); |
274 UpdateAllExceptionsViewsFromModel(); | 277 UpdateAllExceptionsViewsFromModel(); |
275 notification_registrar_.Add( | 278 notification_registrar_.Add( |
276 this, NotificationType::CONTENT_SETTINGS_CHANGED, | 279 this, NotificationType::CONTENT_SETTINGS_CHANGED, |
277 NotificationService::AllSources()); | 280 NotificationService::AllSources()); |
278 notification_registrar_.Add( | 281 notification_registrar_.Add( |
279 this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, | 282 this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, |
280 NotificationService::AllSources()); | 283 NotificationService::AllSources()); |
281 notification_registrar_.Add( | 284 notification_registrar_.Add( |
282 this, NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 285 this, NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
283 NotificationService::AllSources()); | 286 NotificationService::AllSources()); |
| 287 notification_registrar_.Add( |
| 288 this, NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED, |
| 289 NotificationService::AllSources()); |
284 | 290 |
285 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 291 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); |
286 pref_change_registrar_.Init(prefs); | 292 pref_change_registrar_.Init(prefs); |
287 pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this); | 293 pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this); |
288 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); | 294 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); |
289 } | 295 } |
290 | 296 |
291 void ContentSettingsHandler::Observe(NotificationType type, | 297 void ContentSettingsHandler::Observe(NotificationType type, |
292 const NotificationSource& source, | 298 const NotificationSource& source, |
293 const NotificationDetails& details) { | 299 const NotificationDetails& details) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 case NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED: { | 336 case NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED: { |
331 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 337 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
332 break; | 338 break; |
333 } | 339 } |
334 | 340 |
335 case NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { | 341 case NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { |
336 UpdateNotificationExceptionsView(); | 342 UpdateNotificationExceptionsView(); |
337 break; | 343 break; |
338 } | 344 } |
339 | 345 |
| 346 case NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED: { |
| 347 UpdateHandlersEnabledRadios(); |
| 348 break; |
| 349 } |
| 350 |
340 default: | 351 default: |
341 OptionsPageUIHandler::Observe(type, source, details); | 352 OptionsPageUIHandler::Observe(type, source, details); |
342 } | 353 } |
343 } | 354 } |
344 | 355 |
345 void ContentSettingsHandler::UpdateSettingDefaultFromModel( | 356 void ContentSettingsHandler::UpdateSettingDefaultFromModel( |
346 ContentSettingsType type) { | 357 ContentSettingsType type) { |
347 DictionaryValue filter_settings; | 358 DictionaryValue filter_settings; |
348 filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value", | 359 filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value", |
349 GetSettingDefaultFromModel(type)); | 360 GetSettingDefaultFromModel(type)); |
(...skipping 26 matching lines...) Expand all Loading... |
376 return web_ui_->GetProfile()-> | 387 return web_ui_->GetProfile()-> |
377 GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged(); | 388 GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged(); |
378 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 389 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
379 return DesktopNotificationServiceFactory::GetForProfile( | 390 return DesktopNotificationServiceFactory::GetForProfile( |
380 web_ui_->GetProfile())->IsDefaultContentSettingManaged(); | 391 web_ui_->GetProfile())->IsDefaultContentSettingManaged(); |
381 } else { | 392 } else { |
382 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); | 393 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); |
383 } | 394 } |
384 } | 395 } |
385 | 396 |
| 397 void ContentSettingsHandler::UpdateHandlersEnabledRadios() { |
| 398 DCHECK(web_ui_); |
| 399 FundamentalValue* handlers_enabled = Value::CreateBooleanValue( |
| 400 GetProtocolHandlerRegistry()->enabled()); |
| 401 web_ui_->CallJavascriptFunction("ContentSettings.updateHandlersEnabledRadios", |
| 402 *handlers_enabled); |
| 403 } |
| 404 |
386 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { | 405 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { |
387 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; | 406 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
388 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 407 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
389 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); | 408 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); |
390 } | 409 } |
391 } | 410 } |
392 | 411 |
393 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { | 412 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { |
394 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; | 413 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
395 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 414 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 NOTREACHED(); | 733 NOTREACHED(); |
715 return ""; | 734 return ""; |
716 } | 735 } |
717 return kContentSettingsTypeGroupNames[type]; | 736 return kContentSettingsTypeGroupNames[type]; |
718 } | 737 } |
719 | 738 |
720 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { | 739 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { |
721 return web_ui_->GetProfile()->GetHostContentSettingsMap(); | 740 return web_ui_->GetProfile()->GetHostContentSettingsMap(); |
722 } | 741 } |
723 | 742 |
| 743 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { |
| 744 return web_ui_->GetProfile()->GetProtocolHandlerRegistry(); |
| 745 } |
| 746 |
724 HostContentSettingsMap* | 747 HostContentSettingsMap* |
725 ContentSettingsHandler::GetOTRContentSettingsMap() { | 748 ContentSettingsHandler::GetOTRContentSettingsMap() { |
726 Profile* profile = web_ui_->GetProfile(); | 749 Profile* profile = web_ui_->GetProfile(); |
727 if (profile->HasOffTheRecordProfile()) | 750 if (profile->HasOffTheRecordProfile()) |
728 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 751 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
729 return NULL; | 752 return NULL; |
730 } | 753 } |
OLD | NEW |