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" |
28 #include "content/common/notification_service.h" | 29 #include "content/common/notification_service.h" |
29 #include "content/common/notification_source.h" | 30 #include "content/common/notification_source.h" |
30 #include "content/common/notification_type.h" | 31 #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" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 scoped_ptr<Value> block_3rd_party(Value::CreateBooleanValue( | 271 scoped_ptr<Value> block_3rd_party(Value::CreateBooleanValue( |
271 settings_map->BlockThirdPartyCookies())); | 272 settings_map->BlockThirdPartyCookies())); |
272 web_ui_->CallJavascriptFunction("ContentSettings.setBlockThirdPartyCookies", | 273 web_ui_->CallJavascriptFunction("ContentSettings.setBlockThirdPartyCookies", |
273 *block_3rd_party.get()); | 274 *block_3rd_party.get()); |
274 | 275 |
275 notification_registrar_.Add( | 276 notification_registrar_.Add( |
276 this, NotificationType::OTR_PROFILE_CREATED, | 277 this, chrome::OTR_PROFILE_CREATED, |
277 NotificationService::AllSources()); | 278 NotificationService::AllSources()); |
278 notification_registrar_.Add( | 279 notification_registrar_.Add( |
279 this, NotificationType::PROFILE_DESTROYED, | 280 this, chrome::PROFILE_DESTROYED, |
280 NotificationService::AllSources()); | 281 NotificationService::AllSources()); |
281 | 282 |
282 UpdateHandlersEnabledRadios(); | 283 UpdateHandlersEnabledRadios(); |
283 UpdateAllExceptionsViewsFromModel(); | 284 UpdateAllExceptionsViewsFromModel(); |
284 notification_registrar_.Add( | 285 notification_registrar_.Add( |
285 this, NotificationType::CONTENT_SETTINGS_CHANGED, | 286 this, chrome::CONTENT_SETTINGS_CHANGED, |
286 Source<HostContentSettingsMap>(settings_map)); | 287 Source<HostContentSettingsMap>(settings_map)); |
287 notification_registrar_.Add( | 288 notification_registrar_.Add( |
288 this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, | 289 this, chrome::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, |
289 NotificationService::AllSources()); | 290 NotificationService::AllSources()); |
290 notification_registrar_.Add( | 291 notification_registrar_.Add( |
291 this, NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 292 this, chrome::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
292 NotificationService::AllSources()); | 293 NotificationService::AllSources()); |
293 notification_registrar_.Add( | 294 notification_registrar_.Add( |
294 this, NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED, | 295 this, chrome::PROTOCOL_HANDLER_REGISTRY_CHANGED, |
295 NotificationService::AllSources()); | 296 NotificationService::AllSources()); |
296 | 297 |
297 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 298 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); |
298 pref_change_registrar_.Init(prefs); | 299 pref_change_registrar_.Init(prefs); |
299 pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this); | 300 pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this); |
300 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); | 301 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); |
301 } | 302 } |
302 | 303 |
303 void ContentSettingsHandler::Observe(NotificationType type, | 304 void ContentSettingsHandler::Observe(NotificationType type, |
304 const NotificationSource& source, | 305 const NotificationSource& source, |
305 const NotificationDetails& details) { | 306 const NotificationDetails& details) { |
306 switch (type.value) { | 307 switch (type.value) { |
307 case NotificationType::PROFILE_DESTROYED: { | 308 case chrome::PROFILE_DESTROYED: { |
308 Profile* profile = static_cast<Source<Profile> >(source).ptr(); | 309 Profile* profile = static_cast<Source<Profile> >(source).ptr(); |
309 if (profile->IsOffTheRecord()) { | 310 if (profile->IsOffTheRecord()) { |
310 web_ui_->CallJavascriptFunction( | 311 web_ui_->CallJavascriptFunction( |
311 "ContentSettingsExceptionsArea.OTRProfileDestroyed"); | 312 "ContentSettingsExceptionsArea.OTRProfileDestroyed"); |
312 } | 313 } |
313 break; | 314 break; |
314 } | 315 } |
315 | 316 |
316 case NotificationType::OTR_PROFILE_CREATED: { | 317 case chrome::OTR_PROFILE_CREATED: { |
317 UpdateAllOTRExceptionsViewsFromModel(); | 318 UpdateAllOTRExceptionsViewsFromModel(); |
318 break; | 319 break; |
319 } | 320 } |
320 | 321 |
321 case NotificationType::CONTENT_SETTINGS_CHANGED: { | 322 case chrome::CONTENT_SETTINGS_CHANGED: { |
322 const ContentSettingsDetails* settings_details = | 323 const ContentSettingsDetails* settings_details = |
323 Details<const ContentSettingsDetails>(details).ptr(); | 324 Details<const ContentSettingsDetails>(details).ptr(); |
324 | 325 |
325 // TODO(estade): we pretend update_all() is always true. | 326 // TODO(estade): we pretend update_all() is always true. |
326 if (settings_details->update_all_types()) | 327 if (settings_details->update_all_types()) |
327 UpdateAllExceptionsViewsFromModel(); | 328 UpdateAllExceptionsViewsFromModel(); |
328 else | 329 else |
329 UpdateExceptionsViewFromModel(settings_details->type()); | 330 UpdateExceptionsViewFromModel(settings_details->type()); |
330 break; | 331 break; |
331 } | 332 } |
332 | 333 |
333 case NotificationType::PREF_CHANGED: { | 334 case chrome::PREF_CHANGED: { |
334 const std::string& pref_name = *Details<std::string>(details).ptr(); | 335 const std::string& pref_name = *Details<std::string>(details).ptr(); |
335 if (pref_name == prefs::kGeolocationDefaultContentSetting) | 336 if (pref_name == prefs::kGeolocationDefaultContentSetting) |
336 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 337 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
337 else if (pref_name == prefs::kGeolocationContentSettings) | 338 else if (pref_name == prefs::kGeolocationContentSettings) |
338 UpdateGeolocationExceptionsView(); | 339 UpdateGeolocationExceptionsView(); |
339 break; | 340 break; |
340 } | 341 } |
341 | 342 |
342 case NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED: { | 343 case chrome::DESKTOP_NOTIFICATION_DEFAULT_CHANGED: { |
343 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 344 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
344 break; | 345 break; |
345 } | 346 } |
346 | 347 |
347 case NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { | 348 case chrome::DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { |
348 UpdateNotificationExceptionsView(); | 349 UpdateNotificationExceptionsView(); |
349 break; | 350 break; |
350 } | 351 } |
351 | 352 |
352 case NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED: { | 353 case chrome::PROTOCOL_HANDLER_REGISTRY_CHANGED: { |
353 UpdateHandlersEnabledRadios(); | 354 UpdateHandlersEnabledRadios(); |
354 break; | 355 break; |
355 } | 356 } |
356 | 357 |
357 default: | 358 default: |
358 OptionsPageUIHandler::Observe(type, source, details); | 359 OptionsPageUIHandler::Observe(type, source, details); |
359 } | 360 } |
360 } | 361 } |
361 | 362 |
362 void ContentSettingsHandler::UpdateSettingDefaultFromModel( | 363 void ContentSettingsHandler::UpdateSettingDefaultFromModel( |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 return web_ui_->GetProfile()->GetProtocolHandlerRegistry(); | 751 return web_ui_->GetProfile()->GetProtocolHandlerRegistry(); |
751 } | 752 } |
752 | 753 |
753 HostContentSettingsMap* | 754 HostContentSettingsMap* |
754 ContentSettingsHandler::GetOTRContentSettingsMap() { | 755 ContentSettingsHandler::GetOTRContentSettingsMap() { |
755 Profile* profile = web_ui_->GetProfile(); | 756 Profile* profile = web_ui_->GetProfile(); |
756 if (profile->HasOffTheRecordProfile()) | 757 if (profile->HasOffTheRecordProfile()) |
757 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 758 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
758 return NULL; | 759 return NULL; |
759 } | 760 } |
OLD | NEW |