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

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

Issue 7033018: Handler settings page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove in_unit_test_ Created 9 years, 7 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 <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/host_content_settings_map.h" 16 #include "chrome/browser/content_settings/host_content_settings_map.h"
17 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
17 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" 18 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
18 #include "chrome/browser/notifications/desktop_notification_service.h" 19 #include "chrome/browser/notifications/desktop_notification_service.h"
19 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 20 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser_list.h" 22 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/content_settings_helper.h" 24 #include "chrome/common/content_settings_helper.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
25 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
26 #include "content/common/notification_service.h" 27 #include "content/common/notification_service.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 { "blockException", IDS_EXCEPTIONS_BLOCK_BUTTON }, 196 { "blockException", IDS_EXCEPTIONS_BLOCK_BUTTON },
196 { "sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON }, 197 { "sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON },
197 { "askException", IDS_EXCEPTIONS_ASK_BUTTON }, 198 { "askException", IDS_EXCEPTIONS_ASK_BUTTON },
198 { "addExceptionRow", IDS_EXCEPTIONS_ADD_BUTTON }, 199 { "addExceptionRow", IDS_EXCEPTIONS_ADD_BUTTON },
199 { "removeExceptionRow", IDS_EXCEPTIONS_REMOVE_BUTTON }, 200 { "removeExceptionRow", IDS_EXCEPTIONS_REMOVE_BUTTON },
200 { "editExceptionRow", IDS_EXCEPTIONS_EDIT_BUTTON }, 201 { "editExceptionRow", IDS_EXCEPTIONS_EDIT_BUTTON },
201 { "otr_exceptions_explanation", IDS_EXCEPTIONS_OTR_LABEL }, 202 { "otr_exceptions_explanation", IDS_EXCEPTIONS_OTR_LABEL },
202 { "examplePattern", IDS_EXCEPTIONS_PATTERN_EXAMPLE }, 203 { "examplePattern", IDS_EXCEPTIONS_PATTERN_EXAMPLE },
203 { "addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS }, 204 { "addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS },
204 { "manage_exceptions", IDS_EXCEPTIONS_MANAGE }, 205 { "manage_exceptions", IDS_EXCEPTIONS_MANAGE },
206 { "manage_handlers", IDS_HANDLERS_MANAGE },
205 { "exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER }, 207 { "exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER },
206 { "exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER }, 208 { "exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER },
207 // Cookies filter. 209 // Cookies filter.
208 { "cookies_tab_label", IDS_COOKIES_TAB_LABEL }, 210 { "cookies_tab_label", IDS_COOKIES_TAB_LABEL },
209 { "cookies_header", IDS_COOKIES_HEADER }, 211 { "cookies_header", IDS_COOKIES_HEADER },
210 { "cookies_allow", IDS_COOKIES_ALLOW_RADIO }, 212 { "cookies_allow", IDS_COOKIES_ALLOW_RADIO },
211 { "cookies_block", IDS_COOKIES_BLOCK_RADIO }, 213 { "cookies_block", IDS_COOKIES_BLOCK_RADIO },
212 { "cookies_session_only", IDS_COOKIES_SESSION_ONLY_RADIO }, 214 { "cookies_session_only", IDS_COOKIES_SESSION_ONLY_RADIO },
213 { "cookies_block_3rd_party", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX }, 215 { "cookies_block_3rd_party", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX },
214 { "cookies_clear_when_close", IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX }, 216 { "cookies_clear_when_close", IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX },
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 web_ui_->CallJavascriptFunction("ContentSettings.setBlockThirdPartyCookies", 269 web_ui_->CallJavascriptFunction("ContentSettings.setBlockThirdPartyCookies",
268 *block_3rd_party.get()); 270 *block_3rd_party.get());
269 271
270 notification_registrar_.Add( 272 notification_registrar_.Add(
271 this, NotificationType::OTR_PROFILE_CREATED, 273 this, NotificationType::OTR_PROFILE_CREATED,
272 NotificationService::AllSources()); 274 NotificationService::AllSources());
273 notification_registrar_.Add( 275 notification_registrar_.Add(
274 this, NotificationType::PROFILE_DESTROYED, 276 this, NotificationType::PROFILE_DESTROYED,
275 NotificationService::AllSources()); 277 NotificationService::AllSources());
276 278
279 UpdateHandlersEnabledRadios();
277 UpdateAllExceptionsViewsFromModel(); 280 UpdateAllExceptionsViewsFromModel();
278 notification_registrar_.Add( 281 notification_registrar_.Add(
279 this, NotificationType::CONTENT_SETTINGS_CHANGED, 282 this, NotificationType::CONTENT_SETTINGS_CHANGED,
280 NotificationService::AllSources()); 283 NotificationService::AllSources());
281 notification_registrar_.Add( 284 notification_registrar_.Add(
282 this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, 285 this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED,
283 NotificationService::AllSources()); 286 NotificationService::AllSources());
284 notification_registrar_.Add( 287 notification_registrar_.Add(
285 this, NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, 288 this, NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED,
286 NotificationService::AllSources()); 289 NotificationService::AllSources());
290 notification_registrar_.Add(
291 this, NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED,
292 NotificationService::AllSources());
287 293
288 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); 294 PrefService* prefs = web_ui_->GetProfile()->GetPrefs();
289 pref_change_registrar_.Init(prefs); 295 pref_change_registrar_.Init(prefs);
290 pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this); 296 pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this);
291 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); 297 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this);
292 } 298 }
293 299
294 void ContentSettingsHandler::Observe(NotificationType type, 300 void ContentSettingsHandler::Observe(NotificationType type,
295 const NotificationSource& source, 301 const NotificationSource& source,
296 const NotificationDetails& details) { 302 const NotificationDetails& details) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 case NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED: { 339 case NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED: {
334 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 340 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
335 break; 341 break;
336 } 342 }
337 343
338 case NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { 344 case NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED: {
339 UpdateNotificationExceptionsView(); 345 UpdateNotificationExceptionsView();
340 break; 346 break;
341 } 347 }
342 348
349 case NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED: {
350 UpdateHandlersEnabledRadios();
351 break;
352 }
353
343 default: 354 default:
344 OptionsPageUIHandler::Observe(type, source, details); 355 OptionsPageUIHandler::Observe(type, source, details);
345 } 356 }
346 } 357 }
347 358
348 void ContentSettingsHandler::UpdateSettingDefaultFromModel( 359 void ContentSettingsHandler::UpdateSettingDefaultFromModel(
349 ContentSettingsType type) { 360 ContentSettingsType type) {
350 DictionaryValue filter_settings; 361 DictionaryValue filter_settings;
351 filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value", 362 filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value",
352 GetSettingDefaultFromModel(type)); 363 GetSettingDefaultFromModel(type));
(...skipping 26 matching lines...) Expand all
379 return web_ui_->GetProfile()-> 390 return web_ui_->GetProfile()->
380 GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged(); 391 GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged();
381 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 392 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
382 return DesktopNotificationServiceFactory::GetForProfile( 393 return DesktopNotificationServiceFactory::GetForProfile(
383 web_ui_->GetProfile())->IsDefaultContentSettingManaged(); 394 web_ui_->GetProfile())->IsDefaultContentSettingManaged();
384 } else { 395 } else {
385 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); 396 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type);
386 } 397 }
387 } 398 }
388 399
400 void ContentSettingsHandler::UpdateHandlersEnabledRadios() {
401 #if defined(ENABLE_REGISTER_PROTOCOL_HANDLER)
402 DCHECK(web_ui_);
403 FundamentalValue handlers_enabled(GetProtocolHandlerRegistry()->enabled());
404
405 web_ui_->CallJavascriptFunction("ContentSettings.updateHandlersEnabledRadios",
406 handlers_enabled);
407 #endif // defined(ENABLE_REGISTER_PROTOCOL_HANDLER)
408 }
409
389 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { 410 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() {
390 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; 411 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1;
391 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { 412 type < CONTENT_SETTINGS_NUM_TYPES; ++type) {
392 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); 413 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type));
393 } 414 }
394 } 415 }
395 416
396 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { 417 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() {
397 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; 418 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1;
398 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { 419 type < CONTENT_SETTINGS_NUM_TYPES; ++type) {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 NOTREACHED(); 739 NOTREACHED();
719 return ""; 740 return "";
720 } 741 }
721 return kContentSettingsTypeGroupNames[type]; 742 return kContentSettingsTypeGroupNames[type];
722 } 743 }
723 744
724 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { 745 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() {
725 return web_ui_->GetProfile()->GetHostContentSettingsMap(); 746 return web_ui_->GetProfile()->GetHostContentSettingsMap();
726 } 747 }
727 748
749 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() {
750 return web_ui_->GetProfile()->GetProtocolHandlerRegistry();
751 }
752
728 HostContentSettingsMap* 753 HostContentSettingsMap*
729 ContentSettingsHandler::GetOTRContentSettingsMap() { 754 ContentSettingsHandler::GetOTRContentSettingsMap() {
730 Profile* profile = web_ui_->GetProfile(); 755 Profile* profile = web_ui_->GetProfile();
731 if (profile->HasOffTheRecordProfile()) 756 if (profile->HasOffTheRecordProfile())
732 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); 757 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap();
733 return NULL; 758 return NULL;
734 } 759 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/content_settings_handler.h ('k') | chrome/browser/ui/webui/options/handler_options_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698