| 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/content_settings_utils.h" | 16 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 17 #include "chrome/browser/content_settings/host_content_settings_map.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 18 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 18 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 19 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 19 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 20 #include "chrome/browser/notifications/desktop_notification_service.h" | 20 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 21 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 21 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
| 24 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/content_settings_helper.h" | 26 #include "chrome/common/content_settings_helper.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 29 #include "content/common/content_notification_types.h" |
| 28 #include "content/common/notification_service.h" | 30 #include "content/common/notification_service.h" |
| 29 #include "content/common/notification_source.h" | 31 #include "content/common/notification_source.h" |
| 30 #include "content/common/notification_type.h" | |
| 31 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 32 #include "grit/locale_settings.h" | 33 #include "grit/locale_settings.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 struct ContentSettingsTypeNameEntry { | 38 struct ContentSettingsTypeNameEntry { |
| 38 ContentSettingsType type; | 39 ContentSettingsType type; |
| 39 const char* name; | 40 const char* name; |
| 40 }; | 41 }; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 RegisterTitle(localized_strings, "contentSettingsPage", | 262 RegisterTitle(localized_strings, "contentSettingsPage", |
| 262 IDS_CONTENT_SETTINGS_TITLE); | 263 IDS_CONTENT_SETTINGS_TITLE); |
| 263 localized_strings->SetBoolean("enable_click_to_play", | 264 localized_strings->SetBoolean("enable_click_to_play", |
| 264 CommandLine::ForCurrentProcess()->HasSwitch( | 265 CommandLine::ForCurrentProcess()->HasSwitch( |
| 265 switches::kEnableClickToPlay)); | 266 switches::kEnableClickToPlay)); |
| 266 } | 267 } |
| 267 | 268 |
| 268 void ContentSettingsHandler::Initialize() { | 269 void ContentSettingsHandler::Initialize() { |
| 269 const HostContentSettingsMap* settings_map = GetContentSettingsMap(); | 270 const HostContentSettingsMap* settings_map = GetContentSettingsMap(); |
| 270 notification_registrar_.Add( | 271 notification_registrar_.Add( |
| 271 this, NotificationType::OTR_PROFILE_CREATED, | 272 this, chrome::NOTIFICATION_OTR_PROFILE_CREATED, |
| 272 NotificationService::AllSources()); | 273 NotificationService::AllSources()); |
| 273 notification_registrar_.Add( | 274 notification_registrar_.Add( |
| 274 this, NotificationType::PROFILE_DESTROYED, | 275 this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 275 NotificationService::AllSources()); | 276 NotificationService::AllSources()); |
| 276 | 277 |
| 277 UpdateHandlersEnabledRadios(); | 278 UpdateHandlersEnabledRadios(); |
| 278 UpdateAllExceptionsViewsFromModel(); | 279 UpdateAllExceptionsViewsFromModel(); |
| 279 notification_registrar_.Add( | 280 notification_registrar_.Add( |
| 280 this, NotificationType::CONTENT_SETTINGS_CHANGED, | 281 this, chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, |
| 281 Source<HostContentSettingsMap>(settings_map)); | 282 Source<HostContentSettingsMap>(settings_map)); |
| 282 notification_registrar_.Add( | 283 notification_registrar_.Add( |
| 283 this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, | 284 this, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_DEFAULT_CHANGED, |
| 284 NotificationService::AllSources()); | 285 NotificationService::AllSources()); |
| 285 notification_registrar_.Add( | 286 notification_registrar_.Add( |
| 286 this, NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 287 this, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
| 287 NotificationService::AllSources()); | 288 NotificationService::AllSources()); |
| 288 notification_registrar_.Add( | 289 notification_registrar_.Add( |
| 289 this, NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED, | 290 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, |
| 290 NotificationService::AllSources()); | 291 NotificationService::AllSources()); |
| 291 | 292 |
| 292 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 293 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); |
| 293 pref_change_registrar_.Init(prefs); | 294 pref_change_registrar_.Init(prefs); |
| 294 pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this); | 295 pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this); |
| 295 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); | 296 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); |
| 296 } | 297 } |
| 297 | 298 |
| 298 void ContentSettingsHandler::Observe(NotificationType type, | 299 void ContentSettingsHandler::Observe(int type, |
| 299 const NotificationSource& source, | 300 const NotificationSource& source, |
| 300 const NotificationDetails& details) { | 301 const NotificationDetails& details) { |
| 301 switch (type.value) { | 302 switch (type) { |
| 302 case NotificationType::PROFILE_DESTROYED: { | 303 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
| 303 Profile* profile = static_cast<Source<Profile> >(source).ptr(); | 304 Profile* profile = static_cast<Source<Profile> >(source).ptr(); |
| 304 if (profile->IsOffTheRecord()) { | 305 if (profile->IsOffTheRecord()) { |
| 305 web_ui_->CallJavascriptFunction( | 306 web_ui_->CallJavascriptFunction( |
| 306 "ContentSettingsExceptionsArea.OTRProfileDestroyed"); | 307 "ContentSettingsExceptionsArea.OTRProfileDestroyed"); |
| 307 } | 308 } |
| 308 break; | 309 break; |
| 309 } | 310 } |
| 310 | 311 |
| 311 case NotificationType::OTR_PROFILE_CREATED: { | 312 case chrome::NOTIFICATION_OTR_PROFILE_CREATED: { |
| 312 UpdateAllOTRExceptionsViewsFromModel(); | 313 UpdateAllOTRExceptionsViewsFromModel(); |
| 313 break; | 314 break; |
| 314 } | 315 } |
| 315 | 316 |
| 316 case NotificationType::CONTENT_SETTINGS_CHANGED: { | 317 case chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED: { |
| 317 const ContentSettingsDetails* settings_details = | 318 const ContentSettingsDetails* settings_details = |
| 318 Details<const ContentSettingsDetails>(details).ptr(); | 319 Details<const ContentSettingsDetails>(details).ptr(); |
| 319 | 320 |
| 320 // TODO(estade): we pretend update_all() is always true. | 321 // TODO(estade): we pretend update_all() is always true. |
| 321 if (settings_details->update_all_types()) | 322 if (settings_details->update_all_types()) |
| 322 UpdateAllExceptionsViewsFromModel(); | 323 UpdateAllExceptionsViewsFromModel(); |
| 323 else | 324 else |
| 324 UpdateExceptionsViewFromModel(settings_details->type()); | 325 UpdateExceptionsViewFromModel(settings_details->type()); |
| 325 break; | 326 break; |
| 326 } | 327 } |
| 327 | 328 |
| 328 case NotificationType::PREF_CHANGED: { | 329 case chrome::NOTIFICATION_PREF_CHANGED: { |
| 329 const std::string& pref_name = *Details<std::string>(details).ptr(); | 330 const std::string& pref_name = *Details<std::string>(details).ptr(); |
| 330 if (pref_name == prefs::kGeolocationDefaultContentSetting) | 331 if (pref_name == prefs::kGeolocationDefaultContentSetting) |
| 331 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 332 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 332 else if (pref_name == prefs::kGeolocationContentSettings) | 333 else if (pref_name == prefs::kGeolocationContentSettings) |
| 333 UpdateGeolocationExceptionsView(); | 334 UpdateGeolocationExceptionsView(); |
| 334 break; | 335 break; |
| 335 } | 336 } |
| 336 | 337 |
| 337 case NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED: { | 338 case chrome::NOTIFICATION_DESKTOP_NOTIFICATION_DEFAULT_CHANGED: { |
| 338 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 339 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 339 break; | 340 break; |
| 340 } | 341 } |
| 341 | 342 |
| 342 case NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { | 343 case chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { |
| 343 UpdateNotificationExceptionsView(); | 344 UpdateNotificationExceptionsView(); |
| 344 break; | 345 break; |
| 345 } | 346 } |
| 346 | 347 |
| 347 case NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED: { | 348 case chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED: { |
| 348 UpdateHandlersEnabledRadios(); | 349 UpdateHandlersEnabledRadios(); |
| 349 break; | 350 break; |
| 350 } | 351 } |
| 351 | 352 |
| 352 default: | 353 default: |
| 353 OptionsPageUIHandler::Observe(type, source, details); | 354 OptionsPageUIHandler::Observe(type, source, details); |
| 354 } | 355 } |
| 355 } | 356 } |
| 356 | 357 |
| 357 void ContentSettingsHandler::UpdateSettingDefaultFromModel( | 358 void ContentSettingsHandler::UpdateSettingDefaultFromModel( |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 return web_ui_->GetProfile()->GetProtocolHandlerRegistry(); | 736 return web_ui_->GetProfile()->GetProtocolHandlerRegistry(); |
| 736 } | 737 } |
| 737 | 738 |
| 738 HostContentSettingsMap* | 739 HostContentSettingsMap* |
| 739 ContentSettingsHandler::GetOTRContentSettingsMap() { | 740 ContentSettingsHandler::GetOTRContentSettingsMap() { |
| 740 Profile* profile = web_ui_->GetProfile(); | 741 Profile* profile = web_ui_->GetProfile(); |
| 741 if (profile->HasOffTheRecordProfile()) | 742 if (profile->HasOffTheRecordProfile()) |
| 742 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 743 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
| 743 return NULL; | 744 return NULL; |
| 744 } | 745 } |
| OLD | NEW |