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

Side by Side Diff: chrome/browser/dom_ui/content_settings_handler.cc

Issue 2901008: Add the rest of the content settings tabs. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: git try -b mac Created 10 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/resources/options.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/content_settings_handler.h" 5 #include "chrome/browser/dom_ui/content_settings_handler.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/host_content_settings_map.h" 11 #include "chrome/browser/host_content_settings_map.h"
12 #include "chrome/browser/profile.h" 12 #include "chrome/browser/profile.h"
13 #include "chrome/common/url_constants.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 #include "grit/locale_settings.h" 15 #include "grit/locale_settings.h"
15 16
16 namespace { 17 namespace {
17 18
18 // The list of content settings types that we display in the tabbed options
19 // under the Content Settings page. This should be filled in as more pages
20 // are added.
21 ContentSettingsType kContentSettingsTypes[] = {
22 CONTENT_SETTINGS_TYPE_COOKIES,
23 CONTENT_SETTINGS_TYPE_IMAGES,
24 };
25
26 std::wstring ContentSettingsTypeToGroupName(ContentSettingsType type) { 19 std::wstring ContentSettingsTypeToGroupName(ContentSettingsType type) {
27 switch (type) { 20 switch (type) {
28 case CONTENT_SETTINGS_TYPE_COOKIES: 21 case CONTENT_SETTINGS_TYPE_COOKIES:
29 return L"cookies"; 22 return L"cookies";
30 case CONTENT_SETTINGS_TYPE_IMAGES: 23 case CONTENT_SETTINGS_TYPE_IMAGES:
31 return L"images"; 24 return L"images";
25 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
26 return L"javascript";
27 case CONTENT_SETTINGS_TYPE_PLUGINS:
28 return L"plugins";
29 case CONTENT_SETTINGS_TYPE_POPUPS:
30 return L"popups";
31 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
32 return L"location";
33 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
34 return L"notifications";
32 35
33 default: 36 default:
34 NOTREACHED(); 37 NOTREACHED();
35 return L""; 38 return L"";
36 } 39 }
37 } 40 }
38 41
39 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { 42 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) {
40 if (name == "cookies") 43 if (name == "cookies")
41 return CONTENT_SETTINGS_TYPE_COOKIES; 44 return CONTENT_SETTINGS_TYPE_COOKIES;
42 if (name == "images") 45 if (name == "images")
43 return CONTENT_SETTINGS_TYPE_IMAGES; 46 return CONTENT_SETTINGS_TYPE_IMAGES;
47 if (name == "javascript")
48 return CONTENT_SETTINGS_TYPE_JAVASCRIPT;
49 if (name == "plugins")
50 return CONTENT_SETTINGS_TYPE_PLUGINS;
51 if (name == "popups")
52 return CONTENT_SETTINGS_TYPE_POPUPS;
53 if (name == "location")
54 return CONTENT_SETTINGS_TYPE_GEOLOCATION;
55 if (name == "notifications")
56 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
44 57
45 NOTREACHED(); 58 NOTREACHED();
46 return CONTENT_SETTINGS_TYPE_DEFAULT; 59 return CONTENT_SETTINGS_TYPE_DEFAULT;
47 } 60 }
48 61
49 std::string ContentSettingToString(ContentSetting setting) { 62 std::string ContentSettingToString(ContentSetting setting) {
50 switch (setting) { 63 switch (setting) {
51 case CONTENT_SETTING_ALLOW: 64 case CONTENT_SETTING_ALLOW:
52 return "allow"; 65 return "allow";
53 case CONTENT_SETTING_ASK: 66 case CONTENT_SETTING_ASK:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 127
115 // Image filter. 128 // Image filter.
116 localized_strings->SetString(L"images_tab_label", 129 localized_strings->SetString(L"images_tab_label",
117 l10n_util::GetString(IDS_IMAGES_TAB_LABEL)); 130 l10n_util::GetString(IDS_IMAGES_TAB_LABEL));
118 localized_strings->SetString(L"images_setting", 131 localized_strings->SetString(L"images_setting",
119 l10n_util::GetString(IDS_IMAGES_SETTING_LABEL)); 132 l10n_util::GetString(IDS_IMAGES_SETTING_LABEL));
120 localized_strings->SetString(L"images_allow", 133 localized_strings->SetString(L"images_allow",
121 l10n_util::GetString(IDS_IMAGES_LOAD_RADIO)); 134 l10n_util::GetString(IDS_IMAGES_LOAD_RADIO));
122 localized_strings->SetString(L"images_block", 135 localized_strings->SetString(L"images_block",
123 l10n_util::GetString(IDS_IMAGES_NOLOAD_RADIO)); 136 l10n_util::GetString(IDS_IMAGES_NOLOAD_RADIO));
137
138 // JavaScript filter.
139 localized_strings->SetString(L"javascript_tab_label",
140 l10n_util::GetString(IDS_JAVASCRIPT_TAB_LABEL));
141 localized_strings->SetString(L"javascript_setting",
142 l10n_util::GetString(IDS_JS_SETTING_LABEL));
143 localized_strings->SetString(L"javascript_allow",
144 l10n_util::GetString(IDS_JS_ALLOW_RADIO));
145 localized_strings->SetString(L"javascript_block",
146 l10n_util::GetString(IDS_JS_DONOTALLOW_RADIO));
147
148 // Plug-ins filter.
149 localized_strings->SetString(L"plugins_tab_label",
150 l10n_util::GetString(IDS_PLUGIN_TAB_LABEL));
151 localized_strings->SetString(L"plugins_setting",
152 l10n_util::GetString(IDS_PLUGIN_SETTING_LABEL));
153 localized_strings->SetString(L"plugins_allow",
154 l10n_util::GetString(IDS_PLUGIN_LOAD_RADIO));
155 localized_strings->SetString(L"plugins_block",
156 l10n_util::GetString(IDS_PLUGIN_NOLOAD_RADIO));
157 localized_strings->SetString(L"disable_individual_plugins",
158 l10n_util::GetString(IDS_PLUGIN_SELECTIVE_DISABLE));
159 localized_strings->SetString(L"chrome_plugin_url",
160 chrome::kChromeUIPluginsURL);
161
162 // Pop-ups filter.
163 localized_strings->SetString(L"popups_tab_label",
164 l10n_util::GetString(IDS_POPUP_TAB_LABEL));
165 localized_strings->SetString(L"popups_setting",
166 l10n_util::GetString(IDS_POPUP_SETTING_LABEL));
167 localized_strings->SetString(L"popups_allow",
168 l10n_util::GetString(IDS_POPUP_ALLOW_RADIO));
169 localized_strings->SetString(L"popups_block",
170 l10n_util::GetString(IDS_POPUP_BLOCK_RADIO));
171
172 // Location filter.
173 localized_strings->SetString(L"location_tab_label",
174 l10n_util::GetString(IDS_GEOLOCATION_TAB_LABEL));
175 localized_strings->SetString(L"location_setting",
176 l10n_util::GetString(IDS_GEOLOCATION_SETTING_LABEL));
177 localized_strings->SetString(L"location_allow",
178 l10n_util::GetString(IDS_GEOLOCATION_ALLOW_RADIO));
179 localized_strings->SetString(L"location_ask",
180 l10n_util::GetString(IDS_GEOLOCATION_ASK_RADIO));
181 localized_strings->SetString(L"location_block",
182 l10n_util::GetString(IDS_GEOLOCATION_BLOCK_RADIO));
183
184 // Notifications filter.
185 localized_strings->SetString(L"notifications_tab_label",
186 l10n_util::GetString(IDS_NOTIFICATIONS_TAB_LABEL));
187 localized_strings->SetString(L"notifications_setting",
188 l10n_util::GetString(IDS_NOTIFICATIONS_SETTING_LABEL));
189 localized_strings->SetString(L"notifications_allow",
190 l10n_util::GetString(IDS_NOTIFICATIONS_ALLOW_RADIO));
191 localized_strings->SetString(L"notifications_ask",
192 l10n_util::GetString(IDS_NOTIFICATIONS_ASK_RADIO));
193 localized_strings->SetString(L"notifications_block",
194 l10n_util::GetString(IDS_NOTIFICATIONS_BLOCK_RADIO));
124 } 195 }
125 196
126 void ContentSettingsHandler::RegisterMessages() { 197 void ContentSettingsHandler::RegisterMessages() {
127 dom_ui_->RegisterMessageCallback("getContentFilterSettings", 198 dom_ui_->RegisterMessageCallback("getContentFilterSettings",
128 NewCallback(this, 199 NewCallback(this,
129 &ContentSettingsHandler::GetContentFilterSettings)); 200 &ContentSettingsHandler::GetContentFilterSettings));
130 dom_ui_->RegisterMessageCallback("setContentFilter", 201 dom_ui_->RegisterMessageCallback("setContentFilter",
131 NewCallback(this, 202 NewCallback(this,
132 &ContentSettingsHandler::SetContentFilter)); 203 &ContentSettingsHandler::SetContentFilter));
133 dom_ui_->RegisterMessageCallback("setAllowThirdPartyCookies", 204 dom_ui_->RegisterMessageCallback("setAllowThirdPartyCookies",
134 NewCallback(this, 205 NewCallback(this,
135 &ContentSettingsHandler::SetAllowThirdPartyCookies)); 206 &ContentSettingsHandler::SetAllowThirdPartyCookies));
136 } 207 }
137 208
138 void ContentSettingsHandler::GetContentFilterSettings(const Value* value) { 209 void ContentSettingsHandler::GetContentFilterSettings(const Value* value) {
139 // We send a list of the <input> IDs that should be checked. 210 // We send a list of the <input> IDs that should be checked.
140 DictionaryValue dict_value; 211 DictionaryValue dict_value;
141 212
142 const HostContentSettingsMap* settings_map = 213 const HostContentSettingsMap* settings_map =
143 dom_ui_->GetProfile()->GetHostContentSettingsMap(); 214 dom_ui_->GetProfile()->GetHostContentSettingsMap();
144 for (size_t i = 0; i < arraysize(kContentSettingsTypes); ++i) { 215 for (int i = CONTENT_SETTINGS_TYPE_DEFAULT + 1;
145 ContentSettingsType type = kContentSettingsTypes[i]; 216 i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
217 ContentSettingsType type = static_cast<ContentSettingsType>(i);
146 ContentSetting default_setting = settings_map-> 218 ContentSetting default_setting = settings_map->
147 GetDefaultContentSetting(type); 219 GetDefaultContentSetting(type);
148 220
149 dict_value.SetString(ContentSettingsTypeToGroupName(type), 221 dict_value.SetString(ContentSettingsTypeToGroupName(type),
150 ContentSettingToString(default_setting)); 222 ContentSettingToString(default_setting));
151 } 223 }
152 224
153 dom_ui_->CallJavascriptFunction( 225 dom_ui_->CallJavascriptFunction(
154 L"ContentSettings.setInitialContentFilterSettingsValue", dict_value); 226 L"ContentSettings.setInitialContentFilterSettingsValue", dict_value);
155 227
(...skipping 17 matching lines...) Expand all
173 ContentSettingsTypeFromGroupName(group), 245 ContentSettingsTypeFromGroupName(group),
174 ContentSettingFromString(setting)); 246 ContentSettingFromString(setting));
175 } 247 }
176 248
177 void ContentSettingsHandler::SetAllowThirdPartyCookies(const Value* value) { 249 void ContentSettingsHandler::SetAllowThirdPartyCookies(const Value* value) {
178 std::wstring allow = ExtractStringValue(value); 250 std::wstring allow = ExtractStringValue(value);
179 251
180 dom_ui_->GetProfile()->GetHostContentSettingsMap()->SetBlockThirdPartyCookies( 252 dom_ui_->GetProfile()->GetHostContentSettingsMap()->SetBlockThirdPartyCookies(
181 allow == L"true"); 253 allow == L"true");
182 } 254 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698