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

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

Issue 3068005: Flesh out the content settings exceptions lists a bit more. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: reduce instance vars Created 10 years, 4 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
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/notification_service.h"
14 #include "chrome/common/notification_source.h"
15 #include "chrome/common/notification_type.h"
13 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
14 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
15 #include "grit/locale_settings.h" 18 #include "grit/locale_settings.h"
16 19
20 typedef HostContentSettingsMap::ContentSettingsDetails ContentSettingsDetails;
21
17 namespace { 22 namespace {
18 23
19 std::wstring ContentSettingsTypeToGroupName(ContentSettingsType type) { 24 std::wstring ContentSettingsTypeToGroupName(ContentSettingsType type) {
20 switch (type) { 25 switch (type) {
21 case CONTENT_SETTINGS_TYPE_COOKIES: 26 case CONTENT_SETTINGS_TYPE_COOKIES:
22 return L"cookies"; 27 return L"cookies";
23 case CONTENT_SETTINGS_TYPE_IMAGES: 28 case CONTENT_SETTINGS_TYPE_IMAGES:
24 return L"images"; 29 return L"images";
25 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: 30 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
26 return L"javascript"; 31 return L"javascript";
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 DCHECK(localized_strings); 104 DCHECK(localized_strings);
100 105
101 localized_strings->SetString(L"content_exceptions", 106 localized_strings->SetString(L"content_exceptions",
102 l10n_util::GetString(IDS_COOKIES_EXCEPTIONS_BUTTON)); 107 l10n_util::GetString(IDS_COOKIES_EXCEPTIONS_BUTTON));
103 localized_strings->SetString(L"contentSettingsPage", 108 localized_strings->SetString(L"contentSettingsPage",
104 l10n_util::GetString(IDS_CONTENT_SETTINGS_TITLE)); 109 l10n_util::GetString(IDS_CONTENT_SETTINGS_TITLE));
105 localized_strings->SetString(L"allowException", 110 localized_strings->SetString(L"allowException",
106 l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON)); 111 l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON));
107 localized_strings->SetString(L"blockException", 112 localized_strings->SetString(L"blockException",
108 l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON)); 113 l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON));
114 localized_strings->SetString(L"addExceptionRow",
115 l10n_util::GetString(IDS_EXCEPTIONS_ADD_BUTTON));
116 localized_strings->SetString(L"removeExceptionRow",
117 l10n_util::GetString(IDS_EXCEPTIONS_REMOVE_BUTTON));
109 118
110 // Cookies filter. 119 // Cookies filter.
111 localized_strings->SetString(L"cookies_tab_label", 120 localized_strings->SetString(L"cookies_tab_label",
112 l10n_util::GetString(IDS_COOKIES_TAB_LABEL)); 121 l10n_util::GetString(IDS_COOKIES_TAB_LABEL));
113 localized_strings->SetString(L"cookies_modify", 122 localized_strings->SetString(L"cookies_modify",
114 l10n_util::GetString(IDS_MODIFY_COOKIE_STORING_LABEL)); 123 l10n_util::GetString(IDS_MODIFY_COOKIE_STORING_LABEL));
115 localized_strings->SetString(L"cookies_allow", 124 localized_strings->SetString(L"cookies_allow",
116 l10n_util::GetString(IDS_COOKIES_ALLOW_RADIO)); 125 l10n_util::GetString(IDS_COOKIES_ALLOW_RADIO));
117 localized_strings->SetString(L"cookies_block", 126 localized_strings->SetString(L"cookies_block",
118 l10n_util::GetString(IDS_COOKIES_BLOCK_RADIO)); 127 l10n_util::GetString(IDS_COOKIES_BLOCK_RADIO));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 223
215 dom_ui_->CallJavascriptFunction( 224 dom_ui_->CallJavascriptFunction(
216 L"ContentSettings.setInitialContentFilterSettingsValue", filter_settings); 225 L"ContentSettings.setInitialContentFilterSettingsValue", filter_settings);
217 226
218 scoped_ptr<Value> bool_value(Value::CreateBooleanValue( 227 scoped_ptr<Value> bool_value(Value::CreateBooleanValue(
219 settings_map->BlockThirdPartyCookies())); 228 settings_map->BlockThirdPartyCookies()));
220 dom_ui_->CallJavascriptFunction( 229 dom_ui_->CallJavascriptFunction(
221 L"ContentSettings.setBlockThirdPartyCookies", *bool_value.get()); 230 L"ContentSettings.setBlockThirdPartyCookies", *bool_value.get());
222 231
223 UpdateImagesExceptionsViewFromModel(); 232 UpdateImagesExceptionsViewFromModel();
233 notification_registrar_.Add(
234 this, NotificationType::CONTENT_SETTINGS_CHANGED,
235 Source<const HostContentSettingsMap>(settings_map));
224 } 236 }
225 237
226 // TODO(estade): generalize this function to work on all content settings types 238 // TODO(estade): generalize this function to work on all content settings types
227 // rather than just images. 239 // rather than just images.
228 // TODO(estade): call this in response to content exceptions change 240 void ContentSettingsHandler::Observe(NotificationType type,
229 // notifications. 241 const NotificationSource& source,
242 const NotificationDetails& details) {
243 if (type != NotificationType::CONTENT_SETTINGS_CHANGED)
244 return OptionsPageUIHandler::Observe(type, source, details);
245
246 const ContentSettingsDetails* settings_details =
247 static_cast<Details<const ContentSettingsDetails> >(details).ptr();
248
249 if (settings_details->type() == CONTENT_SETTINGS_TYPE_IMAGES ||
250 settings_details->update_all_types()) {
251 // TODO(estade): we pretend update_all() is always true.
252 UpdateImagesExceptionsViewFromModel();
253 }
254 }
255
256 // TODO(estade): generalize this function to work on all content settings types
257 // rather than just images.
230 void ContentSettingsHandler::UpdateImagesExceptionsViewFromModel() { 258 void ContentSettingsHandler::UpdateImagesExceptionsViewFromModel() {
231 HostContentSettingsMap::SettingsForOneType entries; 259 HostContentSettingsMap::SettingsForOneType entries;
232 const HostContentSettingsMap* settings_map = 260 const HostContentSettingsMap* settings_map =
233 dom_ui_->GetProfile()->GetHostContentSettingsMap(); 261 dom_ui_->GetProfile()->GetHostContentSettingsMap();
234 settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, &entries); 262 settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, &entries);
235 263
236 ListValue exceptions; 264 ListValue exceptions;
237 for (size_t i = 0; i < entries.size(); ++i) { 265 for (size_t i = 0; i < entries.size(); ++i) {
238 ListValue* exception = new ListValue(); 266 ListValue* exception = new ListValue();
239 exception->Append(new StringValue(entries[i].first.AsString())); 267 exception->Append(new StringValue(entries[i].first.AsString()));
240 exception->Append( 268 exception->Append(
241 new StringValue(ContentSettingToString(entries[i].second))); 269 new StringValue(ContentSettingToString(entries[i].second)));
242 exceptions.Append(exception); 270 exceptions.Append(exception);
243 } 271 }
244 272
245 dom_ui_->CallJavascriptFunction( 273 dom_ui_->CallJavascriptFunction(
246 L"ContentSettings.setImagesExceptions", exceptions); 274 L"ContentSettings.setImagesExceptions", exceptions);
247 } 275 }
248 276
249 void ContentSettingsHandler::RegisterMessages() { 277 void ContentSettingsHandler::RegisterMessages() {
250 dom_ui_->RegisterMessageCallback("setContentFilter", 278 dom_ui_->RegisterMessageCallback("setContentFilter",
251 NewCallback(this, 279 NewCallback(this,
252 &ContentSettingsHandler::SetContentFilter)); 280 &ContentSettingsHandler::SetContentFilter));
253 dom_ui_->RegisterMessageCallback("setAllowThirdPartyCookies", 281 dom_ui_->RegisterMessageCallback("setAllowThirdPartyCookies",
254 NewCallback(this, 282 NewCallback(this,
255 &ContentSettingsHandler::SetAllowThirdPartyCookies)); 283 &ContentSettingsHandler::SetAllowThirdPartyCookies));
284 dom_ui_->RegisterMessageCallback("removeImageExceptions",
285 NewCallback(this,
286 &ContentSettingsHandler::RemoveExceptions));
256 } 287 }
257 288
258 void ContentSettingsHandler::SetContentFilter(const Value* value) { 289 void ContentSettingsHandler::SetContentFilter(const Value* value) {
259 const ListValue* list_value = static_cast<const ListValue*>(value); 290 const ListValue* list_value = static_cast<const ListValue*>(value);
260 DCHECK_EQ(2U, list_value->GetSize()); 291 DCHECK_EQ(2U, list_value->GetSize());
261 std::string group, setting; 292 std::string group, setting;
262 if (!(list_value->GetString(0, &group) && 293 if (!(list_value->GetString(0, &group) &&
263 list_value->GetString(1, &setting))) { 294 list_value->GetString(1, &setting))) {
264 NOTREACHED(); 295 NOTREACHED();
265 return; 296 return;
266 } 297 }
267 298
268 dom_ui_->GetProfile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 299 dom_ui_->GetProfile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
269 ContentSettingsTypeFromGroupName(group), 300 ContentSettingsTypeFromGroupName(group),
270 ContentSettingFromString(setting)); 301 ContentSettingFromString(setting));
271 } 302 }
272 303
273 void ContentSettingsHandler::SetAllowThirdPartyCookies(const Value* value) { 304 void ContentSettingsHandler::SetAllowThirdPartyCookies(const Value* value) {
274 std::wstring allow = ExtractStringValue(value); 305 std::wstring allow = ExtractStringValue(value);
275 306
276 dom_ui_->GetProfile()->GetHostContentSettingsMap()->SetBlockThirdPartyCookies( 307 dom_ui_->GetProfile()->GetHostContentSettingsMap()->SetBlockThirdPartyCookies(
277 allow == L"true"); 308 allow == L"true");
278 } 309 }
310
311 // TODO(estade): generalize this function to work on all content settings types
312 // rather than just images.
313 void ContentSettingsHandler::RemoveExceptions(const Value* value) {
314 const ListValue* list_value = static_cast<const ListValue*>(value);
315
316 HostContentSettingsMap* settings_map =
317 dom_ui_->GetProfile()->GetHostContentSettingsMap();
318 for (size_t i = 0; i < list_value->GetSize(); ++i) {
319 std::string pattern;
320 bool rv = list_value->GetString(i, &pattern);
321 DCHECK(rv);
322 settings_map->SetContentSetting(HostContentSettingsMap::Pattern(pattern),
323 CONTENT_SETTINGS_TYPE_IMAGES,
324 CONTENT_SETTING_DEFAULT);
325 }
326 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/content_settings_handler.h ('k') | chrome/browser/host_content_settings_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698