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

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

Issue 7554008: Removal of Profile from content part 6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 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 | 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/content_settings_utils.h" 16 #include "chrome/browser/content_settings/content_settings_utils.h"
17 #include "chrome/browser/content_settings/host_content_settings_map.h" 17 #include "chrome/browser/content_settings/host_content_settings_map.h"
18 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 18 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
19 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" 19 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
20 #include "chrome/browser/notifications/desktop_notification_service.h" 20 #include "chrome/browser/notifications/desktop_notification_service.h"
21 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 21 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser_list.h" 23 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/content_settings_helper.h" 26 #include "chrome/common/content_settings_helper.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
29 #include "content/browser/tab_contents/tab_contents.h"
29 #include "content/common/content_notification_types.h" 30 #include "content/common/content_notification_types.h"
30 #include "content/common/notification_service.h" 31 #include "content/common/notification_service.h"
31 #include "content/common/notification_source.h" 32 #include "content/common/notification_source.h"
32 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
33 #include "grit/locale_settings.h" 34 #include "grit/locale_settings.h"
34 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
35 36
36 namespace { 37 namespace {
37 38
38 struct ContentSettingsTypeNameEntry { 39 struct ContentSettingsTypeNameEntry {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 NotificationService::AllSources()); 277 NotificationService::AllSources());
277 278
278 UpdateHandlersEnabledRadios(); 279 UpdateHandlersEnabledRadios();
279 UpdateAllExceptionsViewsFromModel(); 280 UpdateAllExceptionsViewsFromModel();
280 notification_registrar_.Add( 281 notification_registrar_.Add(
281 this, chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, 282 this, chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED,
282 Source<HostContentSettingsMap>(settings_map)); 283 Source<HostContentSettingsMap>(settings_map));
283 notification_registrar_.Add( 284 notification_registrar_.Add(
284 this, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, 285 this, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED,
285 NotificationService::AllSources()); 286 NotificationService::AllSources());
287 Profile* profile =
288 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
286 notification_registrar_.Add( 289 notification_registrar_.Add(
287 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, 290 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED,
288 Source<Profile>(web_ui_->GetProfile())); 291 Source<Profile>(profile));
289 292
290 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); 293 PrefService* prefs = profile->GetPrefs();
291 pref_change_registrar_.Init(prefs); 294 pref_change_registrar_.Init(prefs);
292 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); 295 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this);
293 } 296 }
294 297
295 void ContentSettingsHandler::Observe(int type, 298 void ContentSettingsHandler::Observe(int type,
296 const NotificationSource& source, 299 const NotificationSource& source,
297 const NotificationDetails& details) { 300 const NotificationDetails& details) {
298 switch (type) { 301 switch (type) {
299 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 302 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
300 if (Source<Profile>(source).ptr()->IsOffTheRecord()) { 303 if (Source<Profile>(source).ptr()->IsOffTheRecord()) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 GetSettingDefaultFromModel(type)); 354 GetSettingDefaultFromModel(type));
352 filter_settings.SetBoolean(ContentSettingsTypeToGroupName(type) + ".managed", 355 filter_settings.SetBoolean(ContentSettingsTypeToGroupName(type) + ".managed",
353 GetDefaultSettingManagedFromModel(type)); 356 GetDefaultSettingManagedFromModel(type));
354 357
355 web_ui_->CallJavascriptFunction( 358 web_ui_->CallJavascriptFunction(
356 "ContentSettings.setContentFilterSettingsValue", filter_settings); 359 "ContentSettings.setContentFilterSettingsValue", filter_settings);
357 } 360 }
358 361
359 std::string ContentSettingsHandler::GetSettingDefaultFromModel( 362 std::string ContentSettingsHandler::GetSettingDefaultFromModel(
360 ContentSettingsType type) { 363 ContentSettingsType type) {
364 Profile* profile =
365 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
361 ContentSetting default_setting; 366 ContentSetting default_setting;
362 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 367 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
363 default_setting = DesktopNotificationServiceFactory::GetForProfile( 368 default_setting =
364 web_ui_->GetProfile())->GetDefaultContentSetting(); 369 DesktopNotificationServiceFactory::GetForProfile(profile)->
370 GetDefaultContentSetting();
365 } else { 371 } else {
366 default_setting = web_ui_->GetProfile()-> 372 default_setting =
367 GetHostContentSettingsMap()->GetDefaultContentSetting(type); 373 profile-> GetHostContentSettingsMap()->GetDefaultContentSetting(type);
368 } 374 }
369 375
370 return ContentSettingToString(default_setting); 376 return ContentSettingToString(default_setting);
371 } 377 }
372 378
373 bool ContentSettingsHandler::GetDefaultSettingManagedFromModel( 379 bool ContentSettingsHandler::GetDefaultSettingManagedFromModel(
374 ContentSettingsType type) { 380 ContentSettingsType type) {
375 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 381 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
376 return DesktopNotificationServiceFactory::GetForProfile( 382 Profile* profile =
377 web_ui_->GetProfile())->IsDefaultContentSettingManaged(); 383 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
384 return DesktopNotificationServiceFactory::GetForProfile(profile)->
385 IsDefaultContentSettingManaged();
378 } else { 386 } else {
379 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); 387 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type);
380 } 388 }
381 } 389 }
382 390
383 void ContentSettingsHandler::UpdateHandlersEnabledRadios() { 391 void ContentSettingsHandler::UpdateHandlersEnabledRadios() {
384 #if defined(ENABLE_REGISTER_PROTOCOL_HANDLER) 392 #if defined(ENABLE_REGISTER_PROTOCOL_HANDLER)
385 DCHECK(web_ui_); 393 DCHECK(web_ui_);
386 FundamentalValue handlers_enabled(GetProtocolHandlerRegistry()->enabled()); 394 FundamentalValue handlers_enabled(GetProtocolHandlerRegistry()->enabled());
387 395
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 case CONTENT_SETTINGS_TYPE_GEOLOCATION: 433 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
426 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 434 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
427 break; 435 break;
428 default: 436 default:
429 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); 437 UpdateExceptionsViewFromOTRHostContentSettingsMap(type);
430 break; 438 break;
431 } 439 }
432 } 440 }
433 441
434 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { 442 void ContentSettingsHandler::UpdateGeolocationExceptionsView() {
435 GeolocationContentSettingsMap* map = 443 GeolocationContentSettingsMap* map = web_ui_->tab_contents()->
436 web_ui_->GetProfile()->GetGeolocationContentSettingsMap(); 444 browser_context()->GetGeolocationContentSettingsMap();
437 GeolocationContentSettingsMap::AllOriginsSettings all_settings = 445 GeolocationContentSettingsMap::AllOriginsSettings all_settings =
438 map->GetAllOriginsSettings(); 446 map->GetAllOriginsSettings();
439 GeolocationContentSettingsMap::AllOriginsSettings::const_iterator i; 447 GeolocationContentSettingsMap::AllOriginsSettings::const_iterator i;
440 448
441 ListValue exceptions; 449 ListValue exceptions;
442 for (i = all_settings.begin(); i != all_settings.end(); ++i) { 450 for (i = all_settings.begin(); i != all_settings.end(); ++i) {
443 const GURL& origin = i->first; 451 const GURL& origin = i->first;
444 const GeolocationContentSettingsMap::OneOriginSettings& one_settings = 452 const GeolocationContentSettingsMap::OneOriginSettings& one_settings =
445 i->second; 453 i->second;
446 454
(...skipping 22 matching lines...) Expand all
469 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_GEOLOCATION)); 477 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_GEOLOCATION));
470 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", 478 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions",
471 type_string, exceptions); 479 type_string, exceptions);
472 480
473 // This is mainly here to keep this function ideologically parallel to 481 // This is mainly here to keep this function ideologically parallel to
474 // UpdateExceptionsViewFromHostContentSettingsMap(). 482 // UpdateExceptionsViewFromHostContentSettingsMap().
475 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); 483 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION);
476 } 484 }
477 485
478 void ContentSettingsHandler::UpdateNotificationExceptionsView() { 486 void ContentSettingsHandler::UpdateNotificationExceptionsView() {
487 Profile* profile =
488 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
479 DesktopNotificationService* service = 489 DesktopNotificationService* service =
480 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile()); 490 DesktopNotificationServiceFactory::GetForProfile(profile);
481 491
482 std::vector<GURL> allowed(service->GetAllowedOrigins()); 492 std::vector<GURL> allowed(service->GetAllowedOrigins());
483 std::vector<GURL> blocked(service->GetBlockedOrigins()); 493 std::vector<GURL> blocked(service->GetBlockedOrigins());
484 494
485 ListValue exceptions; 495 ListValue exceptions;
486 for (size_t i = 0; i < allowed.size(); ++i) { 496 for (size_t i = 0; i < allowed.size(); ++i) {
487 exceptions.Append( 497 exceptions.Append(
488 GetNotificationExceptionForPage(allowed[i], CONTENT_SETTING_ALLOW)); 498 GetNotificationExceptionForPage(allowed[i], CONTENT_SETTING_ALLOW));
489 } 499 }
490 for (size_t i = 0; i < blocked.size(); ++i) { 500 for (size_t i = 0; i < blocked.size(); ++i) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 std::string group, setting; 575 std::string group, setting;
566 if (!(args->GetString(0, &group) && 576 if (!(args->GetString(0, &group) &&
567 args->GetString(1, &setting))) { 577 args->GetString(1, &setting))) {
568 NOTREACHED(); 578 NOTREACHED();
569 return; 579 return;
570 } 580 }
571 581
572 ContentSetting default_setting = ContentSettingFromString(setting); 582 ContentSetting default_setting = ContentSettingFromString(setting);
573 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); 583 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group);
574 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 584 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
575 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> 585 Profile* profile =
586 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
587 DesktopNotificationServiceFactory::GetForProfile(profile)->
576 SetDefaultContentSetting(default_setting); 588 SetDefaultContentSetting(default_setting);
577 } else { 589 } else {
578 GetContentSettingsMap()-> 590 GetContentSettingsMap()->
579 SetDefaultContentSetting(content_type, default_setting); 591 SetDefaultContentSetting(content_type, default_setting);
580 } 592 }
581 } 593 }
582 594
583 void ContentSettingsHandler::RemoveException(const ListValue* args) { 595 void ContentSettingsHandler::RemoveException(const ListValue* args) {
584 size_t arg_i = 0; 596 size_t arg_i = 0;
585 std::string type_string; 597 std::string type_string;
586 CHECK(args->GetString(arg_i++, &type_string)); 598 CHECK(args->GetString(arg_i++, &type_string));
587 599
600 Profile* profile =
601 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
588 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); 602 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string);
589 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 603 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
590 std::string origin; 604 std::string origin;
591 std::string embedding_origin; 605 std::string embedding_origin;
592 bool rv = args->GetString(arg_i++, &origin); 606 bool rv = args->GetString(arg_i++, &origin);
593 DCHECK(rv); 607 DCHECK(rv);
594 rv = args->GetString(arg_i++, &embedding_origin); 608 rv = args->GetString(arg_i++, &embedding_origin);
595 DCHECK(rv); 609 DCHECK(rv);
596 610
597 web_ui_->GetProfile()->GetGeolocationContentSettingsMap()-> 611 profile->GetGeolocationContentSettingsMap()->
598 SetContentSetting(GURL(origin), 612 SetContentSetting(GURL(origin),
599 GURL(embedding_origin), 613 GURL(embedding_origin),
600 CONTENT_SETTING_DEFAULT); 614 CONTENT_SETTING_DEFAULT);
601 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 615 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
602 std::string origin; 616 std::string origin;
603 std::string setting; 617 std::string setting;
604 bool rv = args->GetString(arg_i++, &origin); 618 bool rv = args->GetString(arg_i++, &origin);
605 DCHECK(rv); 619 DCHECK(rv);
606 rv = args->GetString(arg_i++, &setting); 620 rv = args->GetString(arg_i++, &setting);
607 DCHECK(rv); 621 DCHECK(rv);
608 ContentSetting content_setting = ContentSettingFromString(setting); 622 ContentSetting content_setting = ContentSettingFromString(setting);
609 if (content_setting == CONTENT_SETTING_ALLOW) { 623 if (content_setting == CONTENT_SETTING_ALLOW) {
610 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> 624 DesktopNotificationServiceFactory::GetForProfile(profile)->
611 ResetAllowedOrigin(GURL(origin)); 625 ResetAllowedOrigin(GURL(origin));
612 } else { 626 } else {
613 DCHECK_EQ(content_setting, CONTENT_SETTING_BLOCK); 627 DCHECK_EQ(content_setting, CONTENT_SETTING_BLOCK);
614 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> 628 DesktopNotificationServiceFactory::GetForProfile(profile)->
615 ResetBlockedOrigin(GURL(origin)); 629 ResetBlockedOrigin(GURL(origin));
616 } 630 }
617 } else { 631 } else {
618 std::string mode; 632 std::string mode;
619 bool rv = args->GetString(arg_i++, &mode); 633 bool rv = args->GetString(arg_i++, &mode);
620 DCHECK(rv); 634 DCHECK(rv);
621 635
622 std::string pattern; 636 std::string pattern;
623 rv = args->GetString(arg_i++, &pattern); 637 rv = args->GetString(arg_i++, &pattern);
624 DCHECK(rv); 638 DCHECK(rv);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { 717 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) {
704 if (type == kContentSettingsTypeGroupNames[i].type) 718 if (type == kContentSettingsTypeGroupNames[i].type)
705 return kContentSettingsTypeGroupNames[i].name; 719 return kContentSettingsTypeGroupNames[i].name;
706 } 720 }
707 721
708 NOTREACHED(); 722 NOTREACHED();
709 return std::string(); 723 return std::string();
710 } 724 }
711 725
712 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { 726 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() {
713 return web_ui_->GetProfile()->GetHostContentSettingsMap(); 727 Profile* profile =
728 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
729 return profile->GetHostContentSettingsMap();
714 } 730 }
715 731
716 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { 732 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() {
717 return web_ui_->GetProfile()->GetProtocolHandlerRegistry(); 733 Profile* profile =
734 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
735 return profile->GetProtocolHandlerRegistry();
718 } 736 }
719 737
720 HostContentSettingsMap* 738 HostContentSettingsMap*
721 ContentSettingsHandler::GetOTRContentSettingsMap() { 739 ContentSettingsHandler::GetOTRContentSettingsMap() {
722 Profile* profile = web_ui_->GetProfile(); 740 Profile* profile =
741 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
723 if (profile->HasOffTheRecordProfile()) 742 if (profile->HasOffTheRecordProfile())
724 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); 743 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap();
725 return NULL; 744 return NULL;
726 } 745 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698