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 <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/content_settings/content_settings_details.h" | 16 #include "chrome/browser/content_settings/content_settings_details.h" |
17 #include "chrome/browser/content_settings/content_settings_pattern.h" | 17 #include "chrome/browser/content_settings/content_settings_pattern.h" |
18 #include "chrome/browser/content_settings/content_settings_utils.h" | 18 #include "chrome/browser/content_settings/content_settings_utils.h" |
19 #include "chrome/browser/content_settings/cookie_settings.h" | |
19 #include "chrome/browser/content_settings/host_content_settings_map.h" | 20 #include "chrome/browser/content_settings/host_content_settings_map.h" |
20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 21 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
21 #include "chrome/browser/notifications/desktop_notification_service.h" | 22 #include "chrome/browser/notifications/desktop_notification_service.h" |
22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 23 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
25 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
54 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { | 55 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { |
55 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, | 56 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, |
56 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, | 57 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, |
57 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, | 58 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, |
58 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, | 59 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, |
59 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, | 60 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, |
60 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, | 61 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, |
61 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, | 62 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, |
62 {CONTENT_SETTINGS_TYPE_INTENTS, "intents"}, | 63 {CONTENT_SETTINGS_TYPE_INTENTS, "intents"}, |
63 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, | 64 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, |
65 {CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY, "cookies-session-only"}, | |
64 }; | 66 }; |
65 COMPILE_ASSERT(arraysize(kContentSettingsTypeGroupNames) == | 67 COMPILE_ASSERT(arraysize(kContentSettingsTypeGroupNames) == |
66 CONTENT_SETTINGS_NUM_TYPES, | 68 CONTENT_SETTINGS_NUM_TYPES, |
67 MISSING_CONTENT_SETTINGS_TYPE); | 69 MISSING_CONTENT_SETTINGS_TYPE); |
68 | 70 |
69 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { | 71 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { |
70 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { | 72 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { |
71 if (name == kContentSettingsTypeGroupNames[i].name) | 73 if (name == kContentSettingsTypeGroupNames[i].name) |
72 return kContentSettingsTypeGroupNames[i].type; | 74 return kContentSettingsTypeGroupNames[i].type; |
73 } | 75 } |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 ContentSettingsType type) { | 366 ContentSettingsType type) { |
365 Profile* profile = Profile::FromWebUI(web_ui_); | 367 Profile* profile = Profile::FromWebUI(web_ui_); |
366 ContentSetting default_setting; | 368 ContentSetting default_setting; |
367 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 369 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
368 default_setting = | 370 default_setting = |
369 DesktopNotificationServiceFactory::GetForProfile(profile)-> | 371 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
370 GetDefaultContentSetting(); | 372 GetDefaultContentSetting(); |
371 } else { | 373 } else { |
372 default_setting = | 374 default_setting = |
373 profile->GetHostContentSettingsMap()->GetDefaultContentSetting(type); | 375 profile->GetHostContentSettingsMap()->GetDefaultContentSetting(type); |
374 } | 376 } |
Bernhard Bauer
2011/09/05 11:05:38
You're probably going to need to add a case for CO
marja
2011/09/06 08:30:15
Done.
| |
375 | 377 |
376 return ContentSettingToString(default_setting); | 378 return ContentSettingToString(default_setting); |
377 } | 379 } |
378 | 380 |
379 bool ContentSettingsHandler::GetDefaultSettingManagedFromModel( | 381 bool ContentSettingsHandler::GetDefaultSettingManagedFromModel( |
380 ContentSettingsType type) { | 382 ContentSettingsType type) { |
381 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 383 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
382 Profile* profile = Profile::FromWebUI(web_ui_); | 384 Profile* profile = Profile::FromWebUI(web_ui_); |
383 return DesktopNotificationServiceFactory::GetForProfile(profile)-> | 385 return DesktopNotificationServiceFactory::GetForProfile(profile)-> |
384 IsDefaultContentSettingManaged(); | 386 IsDefaultContentSettingManaged(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 void ContentSettingsHandler::UpdateExceptionsViewFromModel( | 422 void ContentSettingsHandler::UpdateExceptionsViewFromModel( |
421 ContentSettingsType type) { | 423 ContentSettingsType type) { |
422 switch (type) { | 424 switch (type) { |
423 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 425 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
424 UpdateGeolocationExceptionsView(); | 426 UpdateGeolocationExceptionsView(); |
425 break; | 427 break; |
426 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 428 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
427 UpdateNotificationExceptionsView(); | 429 UpdateNotificationExceptionsView(); |
428 break; | 430 break; |
429 default: | 431 default: |
430 UpdateExceptionsViewFromHostContentSettingsMap(type); | 432 UpdateExceptionsViewFromHostContentSettingsMap(type); |
Bernhard Bauer
2011/09/05 11:05:38
Same here.
marja
2011/09/06 08:30:15
Done; for this I added CookieSettings::GetCookieSe
| |
431 break; | 433 break; |
432 } | 434 } |
433 } | 435 } |
434 | 436 |
435 void ContentSettingsHandler::UpdateOTRExceptionsViewFromModel( | 437 void ContentSettingsHandler::UpdateOTRExceptionsViewFromModel( |
436 ContentSettingsType type) { | 438 ContentSettingsType type) { |
437 switch (type) { | 439 switch (type) { |
438 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 440 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
439 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 441 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
440 break; | 442 break; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 NOTREACHED(); | 609 NOTREACHED(); |
608 return; | 610 return; |
609 } | 611 } |
610 | 612 |
611 ContentSetting default_setting = ContentSettingFromString(setting); | 613 ContentSetting default_setting = ContentSettingFromString(setting); |
612 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); | 614 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); |
613 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 615 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
614 Profile* profile = Profile::FromWebUI(web_ui_); | 616 Profile* profile = Profile::FromWebUI(web_ui_); |
615 DesktopNotificationServiceFactory::GetForProfile(profile)-> | 617 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
616 SetDefaultContentSetting(default_setting); | 618 SetDefaultContentSetting(default_setting); |
619 } else if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { | |
620 GetCookieSettings()->SetDefaultSetting(default_setting); | |
617 } else { | 621 } else { |
618 GetContentSettingsMap()-> | 622 GetContentSettingsMap()-> |
619 SetDefaultContentSetting(content_type, default_setting); | 623 SetDefaultContentSetting(content_type, default_setting); |
620 } | 624 } |
621 } | 625 } |
622 | 626 |
623 void ContentSettingsHandler::RemoveException(const ListValue* args) { | 627 void ContentSettingsHandler::RemoveException(const ListValue* args) { |
624 size_t arg_i = 0; | 628 size_t arg_i = 0; |
625 std::string type_string; | 629 std::string type_string; |
626 CHECK(args->GetString(arg_i++, &type_string)); | 630 CHECK(args->GetString(arg_i++, &type_string)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
662 std::string pattern; | 666 std::string pattern; |
663 rv = args->GetString(arg_i++, &pattern); | 667 rv = args->GetString(arg_i++, &pattern); |
664 DCHECK(rv); | 668 DCHECK(rv); |
665 | 669 |
666 HostContentSettingsMap* settings_map = | 670 HostContentSettingsMap* settings_map = |
667 mode == "normal" ? GetContentSettingsMap() : | 671 mode == "normal" ? GetContentSettingsMap() : |
668 GetOTRContentSettingsMap(); | 672 GetOTRContentSettingsMap(); |
669 // The settings map could be null if the mode was OTR but the OTR profile | 673 // The settings map could be null if the mode was OTR but the OTR profile |
670 // got destroyed before we received this message. | 674 // got destroyed before we received this message. |
671 if (settings_map) { | 675 if (settings_map) { |
672 settings_map->SetContentSetting( | 676 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
673 ContentSettingsPattern::FromString(pattern), | 677 CookieSettings* cookie_settings = |
674 ContentSettingsPattern::Wildcard(), | 678 mode == "normal" ? GetCookieSettings() : GetOTRCookieSettings(); |
675 ContentSettingsTypeFromGroupName(type_string), | 679 if (cookie_settings == NULL) { |
676 "", | 680 NOTREACHED(); |
677 CONTENT_SETTING_DEFAULT); | 681 return; |
682 } | |
683 cookie_settings->ResetCookieSetting( | |
684 ContentSettingsPattern::FromString(pattern)); | |
685 } else { | |
686 settings_map->SetContentSetting( | |
687 ContentSettingsPattern::FromString(pattern), | |
688 ContentSettingsPattern::Wildcard(), | |
689 ContentSettingsTypeFromGroupName(type_string), | |
690 "", | |
691 CONTENT_SETTING_DEFAULT); | |
692 } | |
678 } | 693 } |
679 } | 694 } |
680 } | 695 } |
681 | 696 |
682 void ContentSettingsHandler::SetException(const ListValue* args) { | 697 void ContentSettingsHandler::SetException(const ListValue* args) { |
683 size_t arg_i = 0; | 698 size_t arg_i = 0; |
684 std::string type_string; | 699 std::string type_string; |
685 CHECK(args->GetString(arg_i++, &type_string)); | 700 CHECK(args->GetString(arg_i++, &type_string)); |
686 std::string mode; | 701 std::string mode; |
687 CHECK(args->GetString(arg_i++, &mode)); | 702 CHECK(args->GetString(arg_i++, &mode)); |
688 std::string pattern; | 703 std::string pattern; |
689 CHECK(args->GetString(arg_i++, &pattern)); | 704 CHECK(args->GetString(arg_i++, &pattern)); |
690 std::string setting; | 705 std::string setting; |
691 CHECK(args->GetString(arg_i++, &setting)); | 706 CHECK(args->GetString(arg_i++, &setting)); |
692 | 707 |
693 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 708 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); |
694 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || | 709 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || |
695 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 710 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
696 NOTREACHED(); | 711 NOTREACHED(); |
697 return; | 712 return; |
698 } | 713 } |
699 | 714 |
700 HostContentSettingsMap* settings_map = | 715 HostContentSettingsMap* settings_map = |
701 mode == "normal" ? GetContentSettingsMap() : | 716 mode == "normal" ? GetContentSettingsMap() : |
702 GetOTRContentSettingsMap(); | 717 GetOTRContentSettingsMap(); |
703 | |
704 // The settings map could be null if the mode was OTR but the OTR profile | 718 // The settings map could be null if the mode was OTR but the OTR profile |
705 // got destroyed before we received this message. | 719 // got destroyed before we received this message. |
706 if (!settings_map) | 720 if (!settings_map) |
707 return; | 721 return; |
708 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), | 722 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { |
709 ContentSettingsPattern::Wildcard(), | 723 CookieSettings* cookie_settings = |
710 type, | 724 mode == "normal" ? GetCookieSettings() : GetOTRCookieSettings(); |
711 "", | 725 DCHECK(cookie_settings != NULL); |
712 ContentSettingFromString(setting)); | 726 cookie_settings->SetCookieSetting( |
727 ContentSettingsPattern::FromString(pattern), | |
728 ContentSettingFromString(setting)); | |
729 } else { | |
730 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), | |
731 ContentSettingsPattern::Wildcard(), | |
732 type, | |
733 "", | |
734 ContentSettingFromString(setting)); | |
735 } | |
713 } | 736 } |
714 | 737 |
715 void ContentSettingsHandler::CheckExceptionPatternValidity( | 738 void ContentSettingsHandler::CheckExceptionPatternValidity( |
716 const ListValue* args) { | 739 const ListValue* args) { |
717 size_t arg_i = 0; | 740 size_t arg_i = 0; |
718 Value* type; | 741 Value* type; |
719 CHECK(args->Get(arg_i++, &type)); | 742 CHECK(args->Get(arg_i++, &type)); |
720 std::string mode_string; | 743 std::string mode_string; |
721 CHECK(args->GetString(arg_i++, &mode_string)); | 744 CHECK(args->GetString(arg_i++, &mode_string)); |
722 std::string pattern_string; | 745 std::string pattern_string; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
757 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); | 780 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); |
758 } | 781 } |
759 | 782 |
760 HostContentSettingsMap* | 783 HostContentSettingsMap* |
761 ContentSettingsHandler::GetOTRContentSettingsMap() { | 784 ContentSettingsHandler::GetOTRContentSettingsMap() { |
762 Profile* profile = Profile::FromWebUI(web_ui_); | 785 Profile* profile = Profile::FromWebUI(web_ui_); |
763 if (profile->HasOffTheRecordProfile()) | 786 if (profile->HasOffTheRecordProfile()) |
764 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 787 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
765 return NULL; | 788 return NULL; |
766 } | 789 } |
790 | |
791 CookieSettings* ContentSettingsHandler::GetCookieSettings() { | |
792 return CookieSettings::GetForProfile(Profile::FromWebUI(web_ui_)); | |
793 } | |
794 | |
795 CookieSettings* ContentSettingsHandler::GetOTRCookieSettings() { | |
796 Profile* profile = Profile::FromWebUI(web_ui_); | |
797 if (profile->HasOffTheRecordProfile()) | |
798 return CookieSettings::GetForProfile( | |
799 profile->GetOffTheRecordProfile()); | |
800 return NULL; | |
801 } | |
OLD | NEW |