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_notification_types.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/content_settings_helper.h" | 26 #include "chrome/common/content_settings_helper.h" |
27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 29 #include "content/browser/tab_contents/tab_contents.h" |
29 #include "content/common/content_notification_types.h" | 30 #include "content/common/content_notification_types.h" |
30 #include "content/common/notification_service.h" | 31 #include "content/common/notification_service.h" |
31 #include "content/common/notification_source.h" | 32 #include "content/common/notification_source.h" |
32 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
33 #include "grit/locale_settings.h" | 34 #include "grit/locale_settings.h" |
34 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 struct ContentSettingsTypeNameEntry { | 39 struct ContentSettingsTypeNameEntry { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 NotificationService::AllSources()); | 277 NotificationService::AllSources()); |
277 | 278 |
278 UpdateHandlersEnabledRadios(); | 279 UpdateHandlersEnabledRadios(); |
279 UpdateAllExceptionsViewsFromModel(); | 280 UpdateAllExceptionsViewsFromModel(); |
280 notification_registrar_.Add( | 281 notification_registrar_.Add( |
281 this, chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, | 282 this, chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, |
282 Source<HostContentSettingsMap>(settings_map)); | 283 Source<HostContentSettingsMap>(settings_map)); |
283 notification_registrar_.Add( | 284 notification_registrar_.Add( |
284 this, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 285 this, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
285 NotificationService::AllSources()); | 286 NotificationService::AllSources()); |
| 287 Profile* profile = Profile::FromWebUI(web_ui_); |
286 notification_registrar_.Add( | 288 notification_registrar_.Add( |
287 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, | 289 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, |
288 Source<Profile>(web_ui_->GetProfile())); | 290 Source<Profile>(profile)); |
289 | 291 |
290 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 292 PrefService* prefs = profile->GetPrefs(); |
291 pref_change_registrar_.Init(prefs); | 293 pref_change_registrar_.Init(prefs); |
292 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); | 294 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); |
293 } | 295 } |
294 | 296 |
295 void ContentSettingsHandler::Observe(int type, | 297 void ContentSettingsHandler::Observe(int type, |
296 const NotificationSource& source, | 298 const NotificationSource& source, |
297 const NotificationDetails& details) { | 299 const NotificationDetails& details) { |
298 switch (type) { | 300 switch (type) { |
299 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 301 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
300 if (Source<Profile>(source).ptr()->IsOffTheRecord()) { | 302 if (Source<Profile>(source).ptr()->IsOffTheRecord()) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 GetSettingDefaultFromModel(type)); | 353 GetSettingDefaultFromModel(type)); |
352 filter_settings.SetBoolean(ContentSettingsTypeToGroupName(type) + ".managed", | 354 filter_settings.SetBoolean(ContentSettingsTypeToGroupName(type) + ".managed", |
353 GetDefaultSettingManagedFromModel(type)); | 355 GetDefaultSettingManagedFromModel(type)); |
354 | 356 |
355 web_ui_->CallJavascriptFunction( | 357 web_ui_->CallJavascriptFunction( |
356 "ContentSettings.setContentFilterSettingsValue", filter_settings); | 358 "ContentSettings.setContentFilterSettingsValue", filter_settings); |
357 } | 359 } |
358 | 360 |
359 std::string ContentSettingsHandler::GetSettingDefaultFromModel( | 361 std::string ContentSettingsHandler::GetSettingDefaultFromModel( |
360 ContentSettingsType type) { | 362 ContentSettingsType type) { |
| 363 Profile* profile = Profile::FromWebUI(web_ui_); |
361 ContentSetting default_setting; | 364 ContentSetting default_setting; |
362 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 365 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
363 default_setting = DesktopNotificationServiceFactory::GetForProfile( | 366 default_setting = |
364 web_ui_->GetProfile())->GetDefaultContentSetting(); | 367 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
| 368 GetDefaultContentSetting(); |
365 } else { | 369 } else { |
366 default_setting = web_ui_->GetProfile()-> | 370 default_setting = |
367 GetHostContentSettingsMap()->GetDefaultContentSetting(type); | 371 profile->GetHostContentSettingsMap()->GetDefaultContentSetting(type); |
368 } | 372 } |
369 | 373 |
370 return ContentSettingToString(default_setting); | 374 return ContentSettingToString(default_setting); |
371 } | 375 } |
372 | 376 |
373 bool ContentSettingsHandler::GetDefaultSettingManagedFromModel( | 377 bool ContentSettingsHandler::GetDefaultSettingManagedFromModel( |
374 ContentSettingsType type) { | 378 ContentSettingsType type) { |
375 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 379 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
376 return DesktopNotificationServiceFactory::GetForProfile( | 380 Profile* profile = Profile::FromWebUI(web_ui_); |
377 web_ui_->GetProfile())->IsDefaultContentSettingManaged(); | 381 return DesktopNotificationServiceFactory::GetForProfile(profile)-> |
| 382 IsDefaultContentSettingManaged(); |
378 } else { | 383 } else { |
379 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); | 384 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); |
380 } | 385 } |
381 } | 386 } |
382 | 387 |
383 void ContentSettingsHandler::UpdateHandlersEnabledRadios() { | 388 void ContentSettingsHandler::UpdateHandlersEnabledRadios() { |
384 #if defined(ENABLE_REGISTER_PROTOCOL_HANDLER) | 389 #if defined(ENABLE_REGISTER_PROTOCOL_HANDLER) |
385 DCHECK(web_ui_); | 390 DCHECK(web_ui_); |
386 FundamentalValue handlers_enabled(GetProtocolHandlerRegistry()->enabled()); | 391 FundamentalValue handlers_enabled(GetProtocolHandlerRegistry()->enabled()); |
387 | 392 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 430 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
426 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 431 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
427 break; | 432 break; |
428 default: | 433 default: |
429 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); | 434 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); |
430 break; | 435 break; |
431 } | 436 } |
432 } | 437 } |
433 | 438 |
434 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { | 439 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { |
435 GeolocationContentSettingsMap* map = | 440 GeolocationContentSettingsMap* map = web_ui_->tab_contents()-> |
436 web_ui_->GetProfile()->GetGeolocationContentSettingsMap(); | 441 browser_context()->GetGeolocationContentSettingsMap(); |
437 GeolocationContentSettingsMap::AllOriginsSettings all_settings = | 442 GeolocationContentSettingsMap::AllOriginsSettings all_settings = |
438 map->GetAllOriginsSettings(); | 443 map->GetAllOriginsSettings(); |
439 GeolocationContentSettingsMap::AllOriginsSettings::const_iterator i; | 444 GeolocationContentSettingsMap::AllOriginsSettings::const_iterator i; |
440 | 445 |
441 ListValue exceptions; | 446 ListValue exceptions; |
442 for (i = all_settings.begin(); i != all_settings.end(); ++i) { | 447 for (i = all_settings.begin(); i != all_settings.end(); ++i) { |
443 const GURL& origin = i->first; | 448 const GURL& origin = i->first; |
444 const GeolocationContentSettingsMap::OneOriginSettings& one_settings = | 449 const GeolocationContentSettingsMap::OneOriginSettings& one_settings = |
445 i->second; | 450 i->second; |
446 | 451 |
(...skipping 22 matching lines...) Expand all Loading... |
469 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 474 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
470 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", | 475 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", |
471 type_string, exceptions); | 476 type_string, exceptions); |
472 | 477 |
473 // This is mainly here to keep this function ideologically parallel to | 478 // This is mainly here to keep this function ideologically parallel to |
474 // UpdateExceptionsViewFromHostContentSettingsMap(). | 479 // UpdateExceptionsViewFromHostContentSettingsMap(). |
475 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 480 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
476 } | 481 } |
477 | 482 |
478 void ContentSettingsHandler::UpdateNotificationExceptionsView() { | 483 void ContentSettingsHandler::UpdateNotificationExceptionsView() { |
| 484 Profile* profile = Profile::FromWebUI(web_ui_); |
479 DesktopNotificationService* service = | 485 DesktopNotificationService* service = |
480 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile()); | 486 DesktopNotificationServiceFactory::GetForProfile(profile); |
481 | 487 |
482 std::vector<GURL> allowed(service->GetAllowedOrigins()); | 488 std::vector<GURL> allowed(service->GetAllowedOrigins()); |
483 std::vector<GURL> blocked(service->GetBlockedOrigins()); | 489 std::vector<GURL> blocked(service->GetBlockedOrigins()); |
484 | 490 |
485 ListValue exceptions; | 491 ListValue exceptions; |
486 for (size_t i = 0; i < allowed.size(); ++i) { | 492 for (size_t i = 0; i < allowed.size(); ++i) { |
487 exceptions.Append( | 493 exceptions.Append( |
488 GetNotificationExceptionForPage(allowed[i], CONTENT_SETTING_ALLOW)); | 494 GetNotificationExceptionForPage(allowed[i], CONTENT_SETTING_ALLOW)); |
489 } | 495 } |
490 for (size_t i = 0; i < blocked.size(); ++i) { | 496 for (size_t i = 0; i < blocked.size(); ++i) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 std::string group, setting; | 571 std::string group, setting; |
566 if (!(args->GetString(0, &group) && | 572 if (!(args->GetString(0, &group) && |
567 args->GetString(1, &setting))) { | 573 args->GetString(1, &setting))) { |
568 NOTREACHED(); | 574 NOTREACHED(); |
569 return; | 575 return; |
570 } | 576 } |
571 | 577 |
572 ContentSetting default_setting = ContentSettingFromString(setting); | 578 ContentSetting default_setting = ContentSettingFromString(setting); |
573 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); | 579 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); |
574 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 580 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
575 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> | 581 Profile* profile = Profile::FromWebUI(web_ui_); |
| 582 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
576 SetDefaultContentSetting(default_setting); | 583 SetDefaultContentSetting(default_setting); |
577 } else { | 584 } else { |
578 GetContentSettingsMap()-> | 585 GetContentSettingsMap()-> |
579 SetDefaultContentSetting(content_type, default_setting); | 586 SetDefaultContentSetting(content_type, default_setting); |
580 } | 587 } |
581 } | 588 } |
582 | 589 |
583 void ContentSettingsHandler::RemoveException(const ListValue* args) { | 590 void ContentSettingsHandler::RemoveException(const ListValue* args) { |
584 size_t arg_i = 0; | 591 size_t arg_i = 0; |
585 std::string type_string; | 592 std::string type_string; |
586 CHECK(args->GetString(arg_i++, &type_string)); | 593 CHECK(args->GetString(arg_i++, &type_string)); |
587 | 594 |
| 595 Profile* profile = Profile::FromWebUI(web_ui_); |
588 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 596 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); |
589 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 597 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
590 std::string origin; | 598 std::string origin; |
591 std::string embedding_origin; | 599 std::string embedding_origin; |
592 bool rv = args->GetString(arg_i++, &origin); | 600 bool rv = args->GetString(arg_i++, &origin); |
593 DCHECK(rv); | 601 DCHECK(rv); |
594 rv = args->GetString(arg_i++, &embedding_origin); | 602 rv = args->GetString(arg_i++, &embedding_origin); |
595 DCHECK(rv); | 603 DCHECK(rv); |
596 | 604 |
597 web_ui_->GetProfile()->GetGeolocationContentSettingsMap()-> | 605 profile->GetGeolocationContentSettingsMap()-> |
598 SetContentSetting(GURL(origin), | 606 SetContentSetting(GURL(origin), |
599 GURL(embedding_origin), | 607 GURL(embedding_origin), |
600 CONTENT_SETTING_DEFAULT); | 608 CONTENT_SETTING_DEFAULT); |
601 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 609 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
602 std::string origin; | 610 std::string origin; |
603 std::string setting; | 611 std::string setting; |
604 bool rv = args->GetString(arg_i++, &origin); | 612 bool rv = args->GetString(arg_i++, &origin); |
605 DCHECK(rv); | 613 DCHECK(rv); |
606 rv = args->GetString(arg_i++, &setting); | 614 rv = args->GetString(arg_i++, &setting); |
607 DCHECK(rv); | 615 DCHECK(rv); |
608 ContentSetting content_setting = ContentSettingFromString(setting); | 616 ContentSetting content_setting = ContentSettingFromString(setting); |
609 if (content_setting == CONTENT_SETTING_ALLOW) { | 617 if (content_setting == CONTENT_SETTING_ALLOW) { |
610 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> | 618 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
611 ResetAllowedOrigin(GURL(origin)); | 619 ResetAllowedOrigin(GURL(origin)); |
612 } else { | 620 } else { |
613 DCHECK_EQ(content_setting, CONTENT_SETTING_BLOCK); | 621 DCHECK_EQ(content_setting, CONTENT_SETTING_BLOCK); |
614 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> | 622 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
615 ResetBlockedOrigin(GURL(origin)); | 623 ResetBlockedOrigin(GURL(origin)); |
616 } | 624 } |
617 } else { | 625 } else { |
618 std::string mode; | 626 std::string mode; |
619 bool rv = args->GetString(arg_i++, &mode); | 627 bool rv = args->GetString(arg_i++, &mode); |
620 DCHECK(rv); | 628 DCHECK(rv); |
621 | 629 |
622 std::string pattern; | 630 std::string pattern; |
623 rv = args->GetString(arg_i++, &pattern); | 631 rv = args->GetString(arg_i++, &pattern); |
624 DCHECK(rv); | 632 DCHECK(rv); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { | 711 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { |
704 if (type == kContentSettingsTypeGroupNames[i].type) | 712 if (type == kContentSettingsTypeGroupNames[i].type) |
705 return kContentSettingsTypeGroupNames[i].name; | 713 return kContentSettingsTypeGroupNames[i].name; |
706 } | 714 } |
707 | 715 |
708 NOTREACHED(); | 716 NOTREACHED(); |
709 return std::string(); | 717 return std::string(); |
710 } | 718 } |
711 | 719 |
712 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { | 720 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { |
713 return web_ui_->GetProfile()->GetHostContentSettingsMap(); | 721 return Profile::FromWebUI(web_ui_)->GetHostContentSettingsMap(); |
714 } | 722 } |
715 | 723 |
716 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { | 724 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { |
717 return web_ui_->GetProfile()->GetProtocolHandlerRegistry(); | 725 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); |
718 } | 726 } |
719 | 727 |
720 HostContentSettingsMap* | 728 HostContentSettingsMap* |
721 ContentSettingsHandler::GetOTRContentSettingsMap() { | 729 ContentSettingsHandler::GetOTRContentSettingsMap() { |
722 Profile* profile = web_ui_->GetProfile(); | 730 Profile* profile = Profile::FromWebUI(web_ui_); |
723 if (profile->HasOffTheRecordProfile()) | 731 if (profile->HasOffTheRecordProfile()) |
724 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 732 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
725 return NULL; | 733 return NULL; |
726 } | 734 } |
OLD | NEW |