Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: chrome/browser/ui/webui/options/content_settings_handler.cc

Issue 7713034: HostContentSettingsMap refactoring. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Code review comments. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
20 #include "chrome/browser/content_settings/cookie_settings_factory.h"
19 #include "chrome/browser/content_settings/host_content_settings_map.h" 21 #include "chrome/browser/content_settings/host_content_settings_map.h"
20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 22 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
21 #include "chrome/browser/notifications/desktop_notification_service.h" 23 #include "chrome/browser/notifications/desktop_notification_service.h"
22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 24 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
23 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/browser_list.h" 26 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
(...skipping 25 matching lines...) Expand all
54 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { 56 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = {
55 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, 57 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"},
56 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, 58 {CONTENT_SETTINGS_TYPE_IMAGES, "images"},
57 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, 59 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"},
58 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, 60 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"},
59 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, 61 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"},
60 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, 62 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"},
61 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, 63 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"},
62 {CONTENT_SETTINGS_TYPE_INTENTS, "intents"}, 64 {CONTENT_SETTINGS_TYPE_INTENTS, "intents"},
63 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, 65 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"},
66 {CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY, "cookies-session-only"},
64 }; 67 };
65 COMPILE_ASSERT(arraysize(kContentSettingsTypeGroupNames) == 68 COMPILE_ASSERT(arraysize(kContentSettingsTypeGroupNames) ==
66 CONTENT_SETTINGS_NUM_TYPES, 69 CONTENT_SETTINGS_NUM_TYPES,
67 MISSING_CONTENT_SETTINGS_TYPE); 70 MISSING_CONTENT_SETTINGS_TYPE);
68 71
69 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { 72 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) {
70 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { 73 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) {
71 if (name == kContentSettingsTypeGroupNames[i].name) 74 if (name == kContentSettingsTypeGroupNames[i].name)
72 return kContentSettingsTypeGroupNames[i].type; 75 return kContentSettingsTypeGroupNames[i].type;
73 } 76 }
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 NOTREACHED(); 610 NOTREACHED();
608 return; 611 return;
609 } 612 }
610 613
611 ContentSetting default_setting = ContentSettingFromString(setting); 614 ContentSetting default_setting = ContentSettingFromString(setting);
612 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); 615 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group);
613 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 616 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
614 Profile* profile = Profile::FromWebUI(web_ui_); 617 Profile* profile = Profile::FromWebUI(web_ui_);
615 DesktopNotificationServiceFactory::GetForProfile(profile)-> 618 DesktopNotificationServiceFactory::GetForProfile(profile)->
616 SetDefaultContentSetting(default_setting); 619 SetDefaultContentSetting(default_setting);
620 } else if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
621 GetCookieSettings()->SetDefaultSetting(default_setting);
617 } else { 622 } else {
618 GetContentSettingsMap()-> 623 GetContentSettingsMap()->
619 SetDefaultContentSetting(content_type, default_setting); 624 SetDefaultContentSetting(content_type, default_setting);
620 } 625 }
621 } 626 }
622 627
623 void ContentSettingsHandler::RemoveException(const ListValue* args) { 628 void ContentSettingsHandler::RemoveException(const ListValue* args) {
624 size_t arg_i = 0; 629 size_t arg_i = 0;
625 std::string type_string; 630 std::string type_string;
626 CHECK(args->GetString(arg_i++, &type_string)); 631 CHECK(args->GetString(arg_i++, &type_string));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 bool rv = args->GetString(arg_i++, &mode); 664 bool rv = args->GetString(arg_i++, &mode);
660 DCHECK(rv); 665 DCHECK(rv);
661 666
662 std::string pattern; 667 std::string pattern;
663 rv = args->GetString(arg_i++, &pattern); 668 rv = args->GetString(arg_i++, &pattern);
664 DCHECK(rv); 669 DCHECK(rv);
665 670
666 HostContentSettingsMap* settings_map = 671 HostContentSettingsMap* settings_map =
667 mode == "normal" ? GetContentSettingsMap() : 672 mode == "normal" ? GetContentSettingsMap() :
668 GetOTRContentSettingsMap(); 673 GetOTRContentSettingsMap();
674
669 // The settings map could be null if the mode was OTR but the OTR profile 675 // The settings map could be null if the mode was OTR but the OTR profile
670 // got destroyed before we received this message. 676 // got destroyed before we received this message.
671 if (settings_map) { 677 if (settings_map) {
672 settings_map->SetContentSetting( 678 if (type == CONTENT_SETTINGS_TYPE_COOKIES) {
673 ContentSettingsPattern::FromString(pattern), 679 CookieSettings* cookie_settings =
674 ContentSettingsPattern::Wildcard(), 680 mode == "normal" ? GetCookieSettings() : GetOTRCookieSettings();
675 ContentSettingsTypeFromGroupName(type_string), 681 DCHECK(cookie_settings != NULL);
Bernhard Bauer 2011/09/01 11:41:54 I think we should be a bit more defensive here, as
marja 2011/09/01 13:34:48 Crash here would mean that GetContentSettingsMap r
676 "", 682 cookie_settings->ResetCookieSetting(
677 CONTENT_SETTING_DEFAULT); 683 ContentSettingsPattern::FromString(pattern));
684 } else {
685 settings_map->SetContentSetting(
686 ContentSettingsPattern::FromString(pattern),
687 ContentSettingsPattern::Wildcard(),
688 ContentSettingsTypeFromGroupName(type_string),
689 "",
690 CONTENT_SETTING_DEFAULT);
691 }
678 } 692 }
679 } 693 }
680 } 694 }
681 695
682 void ContentSettingsHandler::SetException(const ListValue* args) { 696 void ContentSettingsHandler::SetException(const ListValue* args) {
683 size_t arg_i = 0; 697 size_t arg_i = 0;
684 std::string type_string; 698 std::string type_string;
685 CHECK(args->GetString(arg_i++, &type_string)); 699 CHECK(args->GetString(arg_i++, &type_string));
686 std::string mode; 700 std::string mode;
687 CHECK(args->GetString(arg_i++, &mode)); 701 CHECK(args->GetString(arg_i++, &mode));
688 std::string pattern; 702 std::string pattern;
689 CHECK(args->GetString(arg_i++, &pattern)); 703 CHECK(args->GetString(arg_i++, &pattern));
690 std::string setting; 704 std::string setting;
691 CHECK(args->GetString(arg_i++, &setting)); 705 CHECK(args->GetString(arg_i++, &setting));
692 706
693 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); 707 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string);
694 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || 708 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION ||
695 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 709 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
696 NOTREACHED(); 710 NOTREACHED();
697 return; 711 return;
698 } 712 }
699 713
700 HostContentSettingsMap* settings_map = 714 HostContentSettingsMap* settings_map =
701 mode == "normal" ? GetContentSettingsMap() : 715 mode == "normal" ? GetContentSettingsMap() :
702 GetOTRContentSettingsMap(); 716 GetOTRContentSettingsMap();
703
704 // The settings map could be null if the mode was OTR but the OTR profile 717 // The settings map could be null if the mode was OTR but the OTR profile
705 // got destroyed before we received this message. 718 // got destroyed before we received this message.
706 if (!settings_map) 719 if (!settings_map)
707 return; 720 return;
708 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), 721 if (type == CONTENT_SETTINGS_TYPE_COOKIES) {
709 ContentSettingsPattern::Wildcard(), 722 CookieSettings* cookie_settings =
710 type, 723 mode == "normal" ? GetCookieSettings() : GetOTRCookieSettings();
711 "", 724 DCHECK(cookie_settings != NULL);
712 ContentSettingFromString(setting)); 725 cookie_settings->SetCookieSetting(
726 ContentSettingsPattern::FromString(pattern),
727 ContentSettingFromString(setting));
728 } else {
729 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern),
730 ContentSettingsPattern::Wildcard(),
731 type,
732 "",
733 ContentSettingFromString(setting));
734 }
713 } 735 }
714 736
715 void ContentSettingsHandler::CheckExceptionPatternValidity( 737 void ContentSettingsHandler::CheckExceptionPatternValidity(
716 const ListValue* args) { 738 const ListValue* args) {
717 size_t arg_i = 0; 739 size_t arg_i = 0;
718 Value* type; 740 Value* type;
719 CHECK(args->Get(arg_i++, &type)); 741 CHECK(args->Get(arg_i++, &type));
720 std::string mode_string; 742 std::string mode_string;
721 CHECK(args->GetString(arg_i++, &mode_string)); 743 CHECK(args->GetString(arg_i++, &mode_string));
722 std::string pattern_string; 744 std::string pattern_string;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); 779 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry();
758 } 780 }
759 781
760 HostContentSettingsMap* 782 HostContentSettingsMap*
761 ContentSettingsHandler::GetOTRContentSettingsMap() { 783 ContentSettingsHandler::GetOTRContentSettingsMap() {
762 Profile* profile = Profile::FromWebUI(web_ui_); 784 Profile* profile = Profile::FromWebUI(web_ui_);
763 if (profile->HasOffTheRecordProfile()) 785 if (profile->HasOffTheRecordProfile())
764 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); 786 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap();
765 return NULL; 787 return NULL;
766 } 788 }
789
790 CookieSettings* ContentSettingsHandler::GetCookieSettings() {
791 return CookieSettingsFactory::GetForProfile(Profile::FromWebUI(web_ui_));
792 }
793
794 CookieSettings* ContentSettingsHandler::GetOTRCookieSettings() {
795 Profile* profile = Profile::FromWebUI(web_ui_);
796 if (profile->HasOffTheRecordProfile())
797 return CookieSettingsFactory::GetForProfile(
798 profile->GetOffTheRecordProfile());
799 return NULL;
800 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698