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

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

Issue 1312453005: Removed Profile::GetHostContentSettingsMap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
21 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" 22 #include "chrome/browser/content_settings/web_site_settings_uma_util.h"
22 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 23 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
23 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 24 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
24 #include "chrome/browser/extensions/extension_special_storage_policy.h" 25 #include "chrome/browser/extensions/extension_special_storage_policy.h"
25 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 26 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
26 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/ui/browser_list.h" 28 #include "chrome/browser/ui/browser_list.h"
28 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 30 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 signin_partition->GetHostZoomMap(); 558 signin_partition->GetHostZoomMap();
558 signin_host_zoom_map_subscription_ = 559 signin_host_zoom_map_subscription_ =
559 signin_host_zoom_map->AddZoomLevelChangedCallback( 560 signin_host_zoom_map->AddZoomLevelChangedCallback(
560 base::Bind(&ContentSettingsHandler::OnZoomLevelChanged, 561 base::Bind(&ContentSettingsHandler::OnZoomLevelChanged,
561 base::Unretained(this))); 562 base::Unretained(this)));
562 } 563 }
563 564
564 flash_settings_manager_.reset(new PepperFlashSettingsManager(this, context)); 565 flash_settings_manager_.reset(new PepperFlashSettingsManager(this, context));
565 566
566 Profile* profile = Profile::FromWebUI(web_ui()); 567 Profile* profile = Profile::FromWebUI(web_ui());
567 observer_.Add(profile->GetHostContentSettingsMap()); 568 observer_.Add(HostContentSettingsMapFactory::GetForProfile(profile));
568 if (profile->HasOffTheRecordProfile()) { 569 if (profile->HasOffTheRecordProfile()) {
569 auto map = profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); 570 auto map = HostContentSettingsMapFactory::GetForProfile(
571 profile->GetOffTheRecordProfile());
570 if (!observer_.IsObserving(map)) 572 if (!observer_.IsObserving(map))
571 observer_.Add(map); 573 observer_.Add(map);
572 } 574 }
573 } 575 }
574 576
575 void ContentSettingsHandler::InitializePage() { 577 void ContentSettingsHandler::InitializePage() {
576 media_settings_.reset(new MediaSettingsInfo()); 578 media_settings_.reset(new MediaSettingsInfo());
577 RefreshFlashMediaSettings(); 579 RefreshFlashMediaSettings();
578 580
579 UpdateHandlersEnabledRadios(); 581 UpdateHandlersEnabledRadios();
(...skipping 15 matching lines...) Expand all
595 UpdateExceptionsViewFromModel(details.type()); 597 UpdateExceptionsViewFromModel(details.type());
596 } 598 }
597 599
598 void ContentSettingsHandler::Observe( 600 void ContentSettingsHandler::Observe(
599 int type, 601 int type,
600 const content::NotificationSource& source, 602 const content::NotificationSource& source,
601 const content::NotificationDetails& details) { 603 const content::NotificationDetails& details) {
602 switch (type) { 604 switch (type) {
603 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 605 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
604 Profile* profile = content::Source<Profile>(source).ptr(); 606 Profile* profile = content::Source<Profile>(source).ptr();
607 HostContentSettingsMap* settings_map =
608 HostContentSettingsMapFactory::GetForProfile(profile);
605 if (profile->IsOffTheRecord() && 609 if (profile->IsOffTheRecord() &&
606 observer_.IsObserving(profile->GetHostContentSettingsMap())) { 610 observer_.IsObserving(settings_map)) {
607 web_ui()->CallJavascriptFunction( 611 web_ui()->CallJavascriptFunction(
608 "ContentSettingsExceptionsArea.OTRProfileDestroyed"); 612 "ContentSettingsExceptionsArea.OTRProfileDestroyed");
609 observer_.Remove(profile->GetHostContentSettingsMap()); 613 observer_.Remove(settings_map);
610 } 614 }
611 break; 615 break;
612 } 616 }
613 617
614 case chrome::NOTIFICATION_PROFILE_CREATED: { 618 case chrome::NOTIFICATION_PROFILE_CREATED: {
615 Profile* profile = content::Source<Profile>(source).ptr(); 619 Profile* profile = content::Source<Profile>(source).ptr();
616 if (profile->IsOffTheRecord()) { 620 if (profile->IsOffTheRecord()) {
617 UpdateAllOTRExceptionsViewsFromModel(); 621 UpdateAllOTRExceptionsViewsFromModel();
618 observer_.Add(profile->GetHostContentSettingsMap()); 622 observer_.Add(HostContentSettingsMapFactory::GetForProfile(profile));
619 } 623 }
620 break; 624 break;
621 } 625 }
622 626
623 case chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED: { 627 case chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED: {
624 UpdateHandlersEnabledRadios(); 628 UpdateHandlersEnabledRadios();
625 break; 629 break;
626 } 630 }
627 } 631 }
628 } 632 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 break; 808 break;
805 default: 809 default:
806 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); 810 UpdateExceptionsViewFromOTRHostContentSettingsMap(type);
807 break; 811 break;
808 } 812 }
809 } 813 }
810 814
811 // TODO(estade): merge with GetExceptionsFromHostContentSettingsMap. 815 // TODO(estade): merge with GetExceptionsFromHostContentSettingsMap.
812 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { 816 void ContentSettingsHandler::UpdateGeolocationExceptionsView() {
813 Profile* profile = Profile::FromWebUI(web_ui()); 817 Profile* profile = Profile::FromWebUI(web_ui());
814 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); 818 HostContentSettingsMap* map =
819 HostContentSettingsMapFactory::GetForProfile(profile);
815 820
816 ContentSettingsForOneType all_settings; 821 ContentSettingsForOneType all_settings;
817 map->GetSettingsForOneType( 822 map->GetSettingsForOneType(
818 CONTENT_SETTINGS_TYPE_GEOLOCATION, 823 CONTENT_SETTINGS_TYPE_GEOLOCATION,
819 std::string(), 824 std::string(),
820 &all_settings); 825 &all_settings);
821 826
822 // Group geolocation settings by primary_pattern. 827 // Group geolocation settings by primary_pattern.
823 AllPatternsSettings all_patterns_settings; 828 AllPatternsSettings all_patterns_settings;
824 for (ContentSettingsForOneType::iterator i = all_settings.begin(); 829 for (ContentSettingsForOneType::iterator i = all_settings.begin();
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); 1334 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group);
1330 Profile* profile = Profile::FromWebUI(web_ui()); 1335 Profile* profile = Profile::FromWebUI(web_ui());
1331 1336
1332 #if defined(OS_CHROMEOS) 1337 #if defined(OS_CHROMEOS)
1333 // ChromeOS special case : in Guest mode settings are opened in Incognito 1338 // ChromeOS special case : in Guest mode settings are opened in Incognito
1334 // mode, so we need original profile to actually modify settings. 1339 // mode, so we need original profile to actually modify settings.
1335 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) 1340 if (user_manager::UserManager::Get()->IsLoggedInAsGuest())
1336 profile = profile->GetOriginalProfile(); 1341 profile = profile->GetOriginalProfile();
1337 #endif 1342 #endif
1338 1343
1339 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); 1344 HostContentSettingsMap* map =
1345 HostContentSettingsMapFactory::GetForProfile(profile);
1340 1346
1341 // MEDIASTREAM is deprecated and the two separate settings MEDIASTREAM_CAMERA 1347 // MEDIASTREAM is deprecated and the two separate settings MEDIASTREAM_CAMERA
1342 // and MEDIASTREAM_MIC should be used instead. However, we still only have 1348 // and MEDIASTREAM_MIC should be used instead. However, we still only have
1343 // one pair of radio buttons that sets both settings. 1349 // one pair of radio buttons that sets both settings.
1344 // TODO(msramek): Clean this up once we have the new UI for media. 1350 // TODO(msramek): Clean this up once we have the new UI for media.
1345 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) { 1351 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
1346 map->SetDefaultContentSetting( 1352 map->SetDefaultContentSetting(
1347 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, default_setting); 1353 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, default_setting);
1348 map->SetDefaultContentSetting( 1354 map->SetDefaultContentSetting(
1349 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, default_setting); 1355 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, default_setting);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { 1490 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) {
1485 if (type == kContentSettingsTypeGroupNames[i].type) 1491 if (type == kContentSettingsTypeGroupNames[i].type)
1486 return kContentSettingsTypeGroupNames[i].name; 1492 return kContentSettingsTypeGroupNames[i].name;
1487 } 1493 }
1488 1494
1489 NOTREACHED(); 1495 NOTREACHED();
1490 return std::string(); 1496 return std::string();
1491 } 1497 }
1492 1498
1493 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { 1499 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() {
1494 return Profile::FromWebUI(web_ui())->GetHostContentSettingsMap(); 1500 return HostContentSettingsMapFactory::GetForProfile(
1501 Profile::FromWebUI(web_ui()));
1495 } 1502 }
1496 1503
1497 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { 1504 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() {
1498 return ProtocolHandlerRegistryFactory::GetForBrowserContext( 1505 return ProtocolHandlerRegistryFactory::GetForBrowserContext(
1499 GetBrowserContext(web_ui())); 1506 GetBrowserContext(web_ui()));
1500 } 1507 }
1501 1508
1502 HostContentSettingsMap* 1509 HostContentSettingsMap*
1503 ContentSettingsHandler::GetOTRContentSettingsMap() { 1510 ContentSettingsHandler::GetOTRContentSettingsMap() {
1504 Profile* profile = Profile::FromWebUI(web_ui()); 1511 Profile* profile = Profile::FromWebUI(web_ui());
1505 if (profile->HasOffTheRecordProfile()) 1512 if (profile->HasOffTheRecordProfile())
1506 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); 1513 return HostContentSettingsMapFactory::GetForProfile(
1514 profile->GetOffTheRecordProfile());
1507 return NULL; 1515 return NULL;
1508 } 1516 }
1509 1517
1510 void ContentSettingsHandler::RefreshFlashMediaSettings() { 1518 void ContentSettingsHandler::RefreshFlashMediaSettings() {
1511 MediaSettingsInfo::ForFlash& settings = media_settings_->forFlash(); 1519 MediaSettingsInfo::ForFlash& settings = media_settings_->forFlash();
1512 settings.initialized = false; 1520 settings.initialized = false;
1513 1521
1514 settings.last_refresh_request_id = 1522 settings.last_refresh_request_id =
1515 flash_settings_manager_->GetPermissionSettings( 1523 flash_settings_manager_->GetPermissionSettings(
1516 PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC); 1524 PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 1634
1627 // Exceptions apply only when the feature is enabled. 1635 // Exceptions apply only when the feature is enabled.
1628 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); 1636 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui()));
1629 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); 1637 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM);
1630 web_ui()->CallJavascriptFunction( 1638 web_ui()->CallJavascriptFunction(
1631 "ContentSettings.enableProtectedContentExceptions", 1639 "ContentSettings.enableProtectedContentExceptions",
1632 base::FundamentalValue(enable_exceptions)); 1640 base::FundamentalValue(enable_exceptions));
1633 } 1641 }
1634 1642
1635 } // namespace options 1643 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698