Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/content_settings/content_settings_details.h" | 15 #include "chrome/browser/content_settings/content_settings_details.h" |
| 16 #include "chrome/browser/content_settings/host_content_settings_map.h" | 16 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 17 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | |
| 17 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 18 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 18 #include "chrome/browser/notifications/desktop_notification_service.h" | 19 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 19 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 20 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/content_settings_helper.h" | 24 #include "chrome/common/content_settings_helper.h" |
| 24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "content/common/notification_service.h" | 27 #include "content/common/notification_service.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 { "blockException", IDS_EXCEPTIONS_BLOCK_BUTTON }, | 196 { "blockException", IDS_EXCEPTIONS_BLOCK_BUTTON }, |
| 196 { "sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON }, | 197 { "sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON }, |
| 197 { "askException", IDS_EXCEPTIONS_ASK_BUTTON }, | 198 { "askException", IDS_EXCEPTIONS_ASK_BUTTON }, |
| 198 { "addExceptionRow", IDS_EXCEPTIONS_ADD_BUTTON }, | 199 { "addExceptionRow", IDS_EXCEPTIONS_ADD_BUTTON }, |
| 199 { "removeExceptionRow", IDS_EXCEPTIONS_REMOVE_BUTTON }, | 200 { "removeExceptionRow", IDS_EXCEPTIONS_REMOVE_BUTTON }, |
| 200 { "editExceptionRow", IDS_EXCEPTIONS_EDIT_BUTTON }, | 201 { "editExceptionRow", IDS_EXCEPTIONS_EDIT_BUTTON }, |
| 201 { "otr_exceptions_explanation", IDS_EXCEPTIONS_OTR_LABEL }, | 202 { "otr_exceptions_explanation", IDS_EXCEPTIONS_OTR_LABEL }, |
| 202 { "examplePattern", IDS_EXCEPTIONS_PATTERN_EXAMPLE }, | 203 { "examplePattern", IDS_EXCEPTIONS_PATTERN_EXAMPLE }, |
| 203 { "addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS }, | 204 { "addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS }, |
| 204 { "manage_exceptions", IDS_EXCEPTIONS_MANAGE }, | 205 { "manage_exceptions", IDS_EXCEPTIONS_MANAGE }, |
| 206 { "manage_handlers", IDS_HANDLERS_MANAGE }, | |
| 205 { "exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER }, | 207 { "exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER }, |
| 206 { "exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER }, | 208 { "exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER }, |
| 207 // Cookies filter. | 209 // Cookies filter. |
| 208 { "cookies_tab_label", IDS_COOKIES_TAB_LABEL }, | 210 { "cookies_tab_label", IDS_COOKIES_TAB_LABEL }, |
| 209 { "cookies_header", IDS_COOKIES_HEADER }, | 211 { "cookies_header", IDS_COOKIES_HEADER }, |
| 210 { "cookies_allow", IDS_COOKIES_ALLOW_RADIO }, | 212 { "cookies_allow", IDS_COOKIES_ALLOW_RADIO }, |
| 211 { "cookies_block", IDS_COOKIES_BLOCK_RADIO }, | 213 { "cookies_block", IDS_COOKIES_BLOCK_RADIO }, |
| 212 { "cookies_session_only", IDS_COOKIES_SESSION_ONLY_RADIO }, | 214 { "cookies_session_only", IDS_COOKIES_SESSION_ONLY_RADIO }, |
| 213 { "cookies_block_3rd_party", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX }, | 215 { "cookies_block_3rd_party", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX }, |
| 214 { "cookies_clear_when_close", IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX }, | 216 { "cookies_clear_when_close", IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX }, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 web_ui_->CallJavascriptFunction("ContentSettings.setBlockThirdPartyCookies", | 269 web_ui_->CallJavascriptFunction("ContentSettings.setBlockThirdPartyCookies", |
| 268 *block_3rd_party.get()); | 270 *block_3rd_party.get()); |
| 269 | 271 |
| 270 notification_registrar_.Add( | 272 notification_registrar_.Add( |
| 271 this, NotificationType::OTR_PROFILE_CREATED, | 273 this, NotificationType::OTR_PROFILE_CREATED, |
| 272 NotificationService::AllSources()); | 274 NotificationService::AllSources()); |
| 273 notification_registrar_.Add( | 275 notification_registrar_.Add( |
| 274 this, NotificationType::PROFILE_DESTROYED, | 276 this, NotificationType::PROFILE_DESTROYED, |
| 275 NotificationService::AllSources()); | 277 NotificationService::AllSources()); |
| 276 | 278 |
| 279 UpdateHandlersEnabledRadios(); | |
|
tony
2011/05/23 21:42:00
Should this be part of UpdateAllExceptionsViewsFro
koz (OOO until 15th September)
2011/05/24 08:47:49
I think not, because it's not an exceptions view.
| |
| 277 UpdateAllExceptionsViewsFromModel(); | 280 UpdateAllExceptionsViewsFromModel(); |
| 278 notification_registrar_.Add( | 281 notification_registrar_.Add( |
| 279 this, NotificationType::CONTENT_SETTINGS_CHANGED, | 282 this, NotificationType::CONTENT_SETTINGS_CHANGED, |
| 280 NotificationService::AllSources()); | 283 NotificationService::AllSources()); |
| 281 notification_registrar_.Add( | 284 notification_registrar_.Add( |
| 282 this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, | 285 this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, |
| 283 NotificationService::AllSources()); | 286 NotificationService::AllSources()); |
| 284 notification_registrar_.Add( | 287 notification_registrar_.Add( |
| 285 this, NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 288 this, NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
| 286 NotificationService::AllSources()); | 289 NotificationService::AllSources()); |
| 290 notification_registrar_.Add( | |
| 291 this, NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED, | |
| 292 NotificationService::AllSources()); | |
| 287 | 293 |
| 288 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 294 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); |
| 289 pref_change_registrar_.Init(prefs); | 295 pref_change_registrar_.Init(prefs); |
| 290 pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this); | 296 pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this); |
| 291 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); | 297 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); |
| 292 } | 298 } |
| 293 | 299 |
| 294 void ContentSettingsHandler::Observe(NotificationType type, | 300 void ContentSettingsHandler::Observe(NotificationType type, |
| 295 const NotificationSource& source, | 301 const NotificationSource& source, |
| 296 const NotificationDetails& details) { | 302 const NotificationDetails& details) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 case NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED: { | 339 case NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED: { |
| 334 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 340 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 335 break; | 341 break; |
| 336 } | 342 } |
| 337 | 343 |
| 338 case NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { | 344 case NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { |
| 339 UpdateNotificationExceptionsView(); | 345 UpdateNotificationExceptionsView(); |
| 340 break; | 346 break; |
| 341 } | 347 } |
| 342 | 348 |
| 349 case NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED: { | |
| 350 UpdateHandlersEnabledRadios(); | |
| 351 break; | |
| 352 } | |
| 353 | |
| 343 default: | 354 default: |
| 344 OptionsPageUIHandler::Observe(type, source, details); | 355 OptionsPageUIHandler::Observe(type, source, details); |
| 345 } | 356 } |
| 346 } | 357 } |
| 347 | 358 |
| 348 void ContentSettingsHandler::UpdateSettingDefaultFromModel( | 359 void ContentSettingsHandler::UpdateSettingDefaultFromModel( |
| 349 ContentSettingsType type) { | 360 ContentSettingsType type) { |
| 350 DictionaryValue filter_settings; | 361 DictionaryValue filter_settings; |
| 351 filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value", | 362 filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value", |
| 352 GetSettingDefaultFromModel(type)); | 363 GetSettingDefaultFromModel(type)); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 379 return web_ui_->GetProfile()-> | 390 return web_ui_->GetProfile()-> |
| 380 GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged(); | 391 GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged(); |
| 381 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 392 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
| 382 return DesktopNotificationServiceFactory::GetForProfile( | 393 return DesktopNotificationServiceFactory::GetForProfile( |
| 383 web_ui_->GetProfile())->IsDefaultContentSettingManaged(); | 394 web_ui_->GetProfile())->IsDefaultContentSettingManaged(); |
| 384 } else { | 395 } else { |
| 385 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); | 396 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); |
| 386 } | 397 } |
| 387 } | 398 } |
| 388 | 399 |
| 400 void ContentSettingsHandler::UpdateHandlersEnabledRadios() { | |
| 401 DCHECK(web_ui_); | |
| 402 FundamentalValue* handlers_enabled = Value::CreateBooleanValue( | |
| 403 GetProtocolHandlerRegistry()->enabled()); | |
|
tony
2011/05/23 21:42:00
It looks like this is leaked. Can you just stack
koz (OOO until 15th September)
2011/05/24 08:47:49
Done.
| |
| 404 web_ui_->CallJavascriptFunction("ContentSettings.updateHandlersEnabledRadios", | |
| 405 *handlers_enabled); | |
| 406 } | |
| 407 | |
| 389 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { | 408 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { |
| 390 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; | 409 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
| 391 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 410 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
| 392 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); | 411 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); |
| 393 } | 412 } |
| 394 } | 413 } |
| 395 | 414 |
| 396 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { | 415 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { |
| 397 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; | 416 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
| 398 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 417 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 NOTREACHED(); | 737 NOTREACHED(); |
| 719 return ""; | 738 return ""; |
| 720 } | 739 } |
| 721 return kContentSettingsTypeGroupNames[type]; | 740 return kContentSettingsTypeGroupNames[type]; |
| 722 } | 741 } |
| 723 | 742 |
| 724 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { | 743 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { |
| 725 return web_ui_->GetProfile()->GetHostContentSettingsMap(); | 744 return web_ui_->GetProfile()->GetHostContentSettingsMap(); |
| 726 } | 745 } |
| 727 | 746 |
| 747 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { | |
| 748 return web_ui_->GetProfile()->GetProtocolHandlerRegistry(); | |
| 749 } | |
| 750 | |
| 728 HostContentSettingsMap* | 751 HostContentSettingsMap* |
| 729 ContentSettingsHandler::GetOTRContentSettingsMap() { | 752 ContentSettingsHandler::GetOTRContentSettingsMap() { |
| 730 Profile* profile = web_ui_->GetProfile(); | 753 Profile* profile = web_ui_->GetProfile(); |
| 731 if (profile->HasOffTheRecordProfile()) | 754 if (profile->HasOffTheRecordProfile()) |
| 732 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 755 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
| 733 return NULL; | 756 return NULL; |
| 734 } | 757 } |
| OLD | NEW |