summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-20 14:30:40 +0000
committermarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-20 14:30:40 +0000
commit026d4fdde11afb8107b6a092cc2d6dbae6f230c5 (patch)
treea62cab017ae6fade2159586b3bfb5699af7df33e
parentcca1200a6e6ddae53a089bdac7bed22bbda4ca94 (diff)
downloadchromium_src-026d4fdde11afb8107b6a092cc2d6dbae6f230c5.zip
chromium_src-026d4fdde11afb8107b6a092cc2d6dbae6f230c5.tar.gz
chromium_src-026d4fdde11afb8107b6a092cc2d6dbae6f230c5.tar.bz2
Allow default desktop content settings and default geolocation settings to be managed via policy. (Support for the Cocoa UI will be added via a separate CL)
BUG=63190,63187, 63180 TEST=none Review URL: http://codereview.chromium.org/5398001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69707 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/policy/policy_templates.grd106
-rw-r--r--chrome/app/policy/policy_templates.json99
-rw-r--r--chrome/browser/dom_ui/options/content_settings_handler.cc19
-rw-r--r--chrome/browser/dom_ui/options/content_settings_handler.h4
-rw-r--r--chrome/browser/geolocation/geolocation_content_settings_map.cc70
-rw-r--r--chrome/browser/geolocation/geolocation_content_settings_map.h26
-rw-r--r--chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc66
-rw-r--r--chrome/browser/gtk/options/content_filter_page_gtk.cc26
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc5
-rw-r--r--chrome/browser/notifications/desktop_notification_service.h1
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store.cc31
-rw-r--r--chrome/browser/policy/configuration_policy_store_interface.h2
-rw-r--r--chrome/browser/resources/options/content_settings.js9
-rw-r--r--chrome/browser/ui/views/options/content_filter_page_view.cc17
-rw-r--r--chrome/common/notification_type.h5
-rw-r--r--chrome/common/policy_constants.cc2
-rw-r--r--chrome/common/policy_constants.h2
17 files changed, 467 insertions, 23 deletions
diff --git a/chrome/app/policy/policy_templates.grd b/chrome/app/policy/policy_templates.grd
index f9bfbe3..39d0545 100644
--- a/chrome/app/policy/policy_templates.grd
+++ b/chrome/app/policy/policy_templates.grd
@@ -350,6 +350,112 @@ templates and will be translated for each locale. -->
For detailed examples, visit:
<ph name="PROXY_HELP_URL">$2<ex>http://www.chromium.org/developers/design-documents/network-settings#TOC-Command-line-options-for-proxy-sett</ex></ph>
</message>
+ <!-- Content Settings messages -->
+ <message name="IDS_POLICY_CONTENTSETTINGS_CAPTION" desc="Caption of the 'content settings' policy group.">
+ Content Settings
+ </message>
+ <message name="IDS_POLICY_CONTENTSETTINGS_DESC" desc="Description of the 'content settings' policy group.">
+ Content Settings allow you to specify how contents of a specific type (for example Cookies, Images or JavaScript) is handled.
+ </message>
+
+ <message name="IDS_POLICY_DEFAULTCOOKIESSETTING_CAPTION" desc="Text describing the dropdown menu for selecting the default notification setting.">
+ Default cookies setting
+ </message>
+ <message name="IDS_POLICY_DEFAULTCOOKIESSETTING_DESC" desc="Description of the 'default cookies setting' policy.">
+ Allows you to set whether websites are allowed to set local data. Setting local data can be either allowed for all websites or denied for all websites.
+ </message>
+ <message name="IDS_POLICY_ENUM_ALLOWCOOKIES_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'ALLOW'.">
+ Allow all sites to set local data.
+ </message>
+ <message name="IDS_POLICY_ENUM_BLOCKCOOKIES_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'BLOCK'.">
+ Do not allow any site to set local data
+ </message>
+
+ <message name="IDS_POLICY_DEFAULTIMAGESSETTING_CAPTION" desc="Text describing the dropdown menu for selecting the default notification setting.">
+ Default images setting
+ </message>
+ <message name="IDS_POLICY_DEFAULTIMAGESSETTING_DESC" desc="Description of the 'default images setting' policy.">
+ Allows you to set whether websites are allowed to display images. Displaying images can be either allowed for all websites or denied for all websites.
+ </message>
+ <message name="IDS_POLICY_ENUM_ALLOWIMAGES_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'ALLOW'.">
+ Allow all sites to show all images
+ </message>
+ <message name="IDS_POLICY_ENUM_BLOCKIMAGES_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'BLOCK'.">
+ Do not allow any site to show images
+ </message>
+
+ <message name="IDS_POLICY_DEFAULTJAVASCRIPTSETTING_CAPTION" desc="Text describing the dropdown menu for selecting the default notification setting.">
+ Default JavaScript setting
+ </message>
+ <message name="IDS_POLICY_DEFAULTJAVASCRIPTSETTING_DESC" desc="Description of the 'default JavaScript setting' policy.">
+ Allows you to set whether websites are allowed to run JavaScript. Running JavaScript can be either allowed for all websites or denied for all websites.
+ </message>
+ <message name="IDS_POLICY_ENUM_ALLOWJAVASCRIPT_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'ALLOW'.">
+ Allow all sites to run JavaScript
+ </message>
+ <message name="IDS_POLICY_ENUM_BLOCKJAVASCRIPT_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'BLOCK'.">
+ Do not allow any site to run JavaScript
+ </message>
+
+ <message name="IDS_POLICY_DEFAULTPLUGINSSETTING_CAPTION" desc="Text describing the dropdown menu for selecting the default notification setting.">
+ Default plugins setting
+ </message>
+ <message name="IDS_POLICY_DEFAULTPLUGINSSETTING_DESC" desc="Description of the 'default plug-ins setting' policy.">
+ Allows you to set whether websites are allowed to automatically run plugins. Automatically running plugins can be either allowed for all websites or denied for all websites.
+ </message>
+ <message name="IDS_POLICY_ENUM_ALLOWPLUGINS_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'ALLOW'.">
+ Allow all sites to automatically run plugins
+ </message>
+ <message name="IDS_POLICY_ENUM_BLOCKPLUGINS_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'BLOCK'.">
+ Block all plugins
+ </message>
+
+ <message name="IDS_POLICY_DEFAULTPOPUPSSETTING_CAPTION" desc="Text describing the dropdown menu for selecting the default notification setting.">
+ Default popups setting
+ </message>
+ <message name="IDS_POLICY_DEFAULTPOPUPSSETTING_DESC" desc="Description of the 'default popups setting' policy.">
+ Allows you to set whether websites are allowed to show pop-ups. Showing popups can be either allowed for all websites or denied for all websites.
+ </message>
+ <message name="IDS_POLICY_ENUM_ALLOWPOPUPS_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'ALLOW'.">
+ Allow all sites to show pop-ups
+ </message>
+ <message name="IDS_POLICY_ENUM_BLOCKPOPUPS_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'BLOCK'.">
+ Do not allow any site to show popups
+ </message>
+
+ <message name="IDS_POLICY_DEFAULTNOTIFICATIONSETTING_CAPTION" desc="Text describing the dropdown menu for selecting the default notification setting.">
+ Default notification setting
+ </message>
+ <message name="IDS_POLICY_DEFAULTNOTIFICATIONSETTING_DESC" desc="Description of the 'default notification setting' policy.">
+ Allows you to set whether websites are allowed to display desktop notifications. Displaying desktop notifications can be allowed by default, denied by default or the user can be asked everytime a website wants to show desktop notifications.
+ </message>
+ <message name="IDS_POLICY_ENUM_ALLOWNOTIFICATIONS_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'ALLOW'.">
+ Allow sites to show desktop notifications
+ </message>
+ <message name="IDS_POLICY_ENUM_BLOCKNOTIFICATIONS_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'BLOCK'.">
+ Do not allow any site to show desktop notifications
+ </message>
+ <message name="IDS_POLICY_ENUM_ASKNOTIFICATIONS_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'ASK'.">
+ Ask every time a site wants to show desktop notifications
+ </message>
+
+ <message name="IDS_POLICY_DEFAULTGEOLOCATIONSETTING_CAPTION" desc="Text describing the dropdown menu for selecting the default notification setting.">
+ Default geolocation setting
+ </message>
+ <message name="IDS_POLICY_DEFAULTGEOLOCATIONSETTING_DESC" desc="Description of the 'default geolocation setting' policy.">
+ Allows you to set whether websites are allowed to track the users' physical location. Tracking the users' physical location can be allowed by default, denied by default or the user can be asked everytime a website requests the pysical location.
+ </message>
+
+ <message name="IDS_POLICY_ENUM_ALLOWGEOLOCATION_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'ALLOW'.">
+ Allow sites to track the users' physical location
+ </message>
+ <message name="IDS_POLICY_ENUM_BLOCKGEOLOCATION_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'BLOCK'.">
+ Do not allow any site to track the users' physical location
+ </message>
+ <message name="IDS_POLICY_ENUM_ASKGEOLOCATION_CAPTION" desc="Label in a 'default content settings' dropdown menu for selecting the default content settings 'ASK'.">
+ Ask whenever a site wants to track the users' physical location
+ </message>
+ <!-- End HTTP Policy messages -->
<!-- HTTP Authentication Policy messages -->
<message name="IDS_POLICY_HTTPAUTHENTICATION_CAPTION" desc="Caption of the 'HTTPAuthentication' policy group">
diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json
index 04e195c..59a4e15 100644
--- a/chrome/app/policy/policy_templates.json
+++ b/chrome/app/policy/policy_templates.json
@@ -506,6 +506,105 @@
]
},
{
+ 'name': 'ContentSettings',
+ 'type': 'group',
+ 'policies': [
+ {
+ 'name': 'DefaultCookiesSetting',
+ 'type': 'enum',
+ 'items': [
+ {'name': 'AllowCookies', 'value': '0'},
+ {'name': 'BlockCookies', 'value': '1'},
+ ],
+ 'supported_on': ['chrome.*:10-'],
+ 'annotations': {
+ 'features': {'dynamic_refresh': 1},
+ 'example_value': 0,
+ }
+ },
+ {
+ 'name': 'DefaultImagesSetting',
+ 'type': 'enum',
+ 'items': [
+ {'name': 'AllowImages', 'value': '0'},
+ {'name': 'BlockImages', 'value': '1'},
+ ],
+ 'supported_on': ['chrome.*:10-'],
+ 'annotations': {
+ 'features': {'dynamic_refresh': 1},
+ 'example_value': 0,
+ }
+ },
+ {
+ 'name': 'DefaultJavaScriptSetting',
+ 'type': 'enum',
+ 'items': [
+ {'name': 'AllowJavaScript', 'value': '0'},
+ {'name': 'BlockJavaScript', 'value': '1'},
+ ],
+ 'supported_on': ['chrome.*:10-'],
+ 'annotations': {
+ 'features': {'dynamic_refresh': 1},
+ 'example_value': 0,
+ }
+ },
+ {
+ 'name': 'DefaultPluginsSetting',
+ 'type': 'enum',
+ 'items': [
+ {'name': 'AllowPlugins', 'value': '0'},
+ {'name': 'BlockPlugins', 'value': '1'},
+ ],
+ 'supported_on': ['chrome.*:10-'],
+ 'annotations': {
+ 'features': {'dynamic_refresh': 1},
+ 'example_value': 0,
+ }
+ },
+ {
+ 'name': 'DefaultPopupsSetting',
+ 'type': 'enum',
+ 'items': [
+ {'name': 'AllowPopups', 'value': '0'},
+ {'name': 'BlockPopups', 'value': '1'},
+ ],
+ 'supported_on': ['chrome.*:10-'],
+ 'annotations': {
+ 'features': {'dynamic_refresh': 1},
+ 'example_value': 1,
+ }
+ },
+ {
+ 'name': 'DefaultNotificationSetting',
+ 'type': 'enum',
+ 'items': [
+ {'name': 'AllowNotifications', 'value': '0'},
+ {'name': 'BlockNotifications', 'value': '1'},
+ {'name': 'AskNotifications', 'value': '2'},
+ ],
+ 'supported_on': ['chrome.*:10-'],
+ 'annotations': {
+ 'features': {'dynamic_refresh': 1},
+ 'example_value': 2,
+ }
+ },
+ {
+ 'name': 'DefaultGeolocationSetting',
+ 'type': 'enum',
+ 'items': [
+ {'name': 'AllowGeolocation', 'value': '0'},
+ {'name': 'BlockGeolocation', 'value': '1'},
+ {'name': 'AskGeolocation', 'value': '2'},
+ ],
+ 'supported_on': ['chrome.*:10-'],
+ 'annotations': {
+ 'features': {'dynamic_refresh': 1},
+ 'example_value': 0,
+ }
+ },
+ ]
+ },
+ {
'name': 'ChromeFrameRendererSettings',
'type': 'group',
'policies': [{
diff --git a/chrome/browser/dom_ui/options/content_settings_handler.cc b/chrome/browser/dom_ui/options/content_settings_handler.cc
index 3e5f8d3..af1b063 100644
--- a/chrome/browser/dom_ui/options/content_settings_handler.cc
+++ b/chrome/browser/dom_ui/options/content_settings_handler.cc
@@ -368,8 +368,10 @@ void ContentSettingsHandler::Observe(NotificationType type,
void ContentSettingsHandler::UpdateSettingDefaultFromModel(
ContentSettingsType type) {
DictionaryValue filter_settings;
- filter_settings.SetString(ContentSettingsTypeToGroupName(type),
- GetSettingDefaultFromModel(type));
+ filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value",
+ GetSettingDefaultFromModel(type));
+ filter_settings.SetBoolean(ContentSettingsTypeToGroupName(type) + ".managed",
+ GetDefaultSettingManagedFromModel(type));
dom_ui_->CallJavascriptFunction(
L"ContentSettings.setContentFilterSettingsValue", filter_settings);
@@ -391,6 +393,19 @@ std::string ContentSettingsHandler::GetSettingDefaultFromModel(
return ContentSettingToString(default_setting);
}
+bool ContentSettingsHandler::GetDefaultSettingManagedFromModel(
+ ContentSettingsType type) {
+ if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
+ return dom_ui_->GetProfile()->
+ GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged();
+ } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
+ return dom_ui_->GetProfile()->
+ GetDesktopNotificationService()->IsDefaultContentSettingManaged();
+ } else {
+ return GetContentSettingsMap()->IsDefaultContentSettingManaged(type);
+ }
+}
+
void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() {
for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1;
type < CONTENT_SETTINGS_NUM_TYPES; ++type) {
diff --git a/chrome/browser/dom_ui/options/content_settings_handler.h b/chrome/browser/dom_ui/options/content_settings_handler.h
index e18de26..a67f89e 100644
--- a/chrome/browser/dom_ui/options/content_settings_handler.h
+++ b/chrome/browser/dom_ui/options/content_settings_handler.h
@@ -96,6 +96,10 @@ class ContentSettingsHandler : public OptionsPageUIHandler {
// Gets the default setting in string form.
std::string GetSettingDefaultFromModel(ContentSettingsType type);
+ // Returns true if the default setting for the given content settings type
+ // |type| is managed.
+ bool GetDefaultSettingManagedFromModel(ContentSettingsType type);
+
// Member variables ---------------------------------------------------------
NotificationRegistrar notification_registrar_;
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map.cc b/chrome/browser/geolocation/geolocation_content_settings_map.cc
index 40b1462..5c67523 100644
--- a/chrome/browser/geolocation/geolocation_content_settings_map.cc
+++ b/chrome/browser/geolocation/geolocation_content_settings_map.cc
@@ -20,9 +20,13 @@
#include "base/string_piece.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/content_settings/content_settings_details.h"
+#include "chrome/browser/content_settings/content_settings_pattern.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_pref_update.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
@@ -36,6 +40,11 @@ const ContentSetting
GeolocationContentSettingsMap::GeolocationContentSettingsMap(Profile* profile)
: profile_(profile) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ prefs_registrar_.Init(profile_->GetPrefs());
+ prefs_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this);
+ prefs_registrar_.Add(prefs::kGeolocationContentSettings, this);
+ notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
+ Source<Profile>(profile_));
}
// static
@@ -47,6 +56,9 @@ void GeolocationContentSettingsMap::RegisterUserPrefs(PrefService* prefs) {
ContentSetting GeolocationContentSettingsMap::GetDefaultContentSetting() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ // If the profile is destroyed (and set to NULL) return CONTENT_SETTING_BLOCK.
+ if (!profile_)
+ return CONTENT_SETTING_BLOCK;
const PrefService* prefs = profile_->GetPrefs();
const ContentSetting default_content_setting = IntToContentSetting(
prefs->GetInteger(prefs::kGeolocationDefaultContentSetting));
@@ -54,6 +66,15 @@ ContentSetting GeolocationContentSettingsMap::GetDefaultContentSetting() const {
kDefaultSetting : default_content_setting;
}
+bool GeolocationContentSettingsMap::IsDefaultContentSettingManaged() const {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ // If the profile is destroyed (and set to NULL) return true.
+ if (!profile_)
+ return true;
+ return profile_->GetPrefs()->IsManagedPreference(
+ prefs::kGeolocationDefaultContentSetting);
+}
+
ContentSetting GeolocationContentSettingsMap::GetContentSetting(
const GURL& requesting_url,
const GURL& embedding_url) const {
@@ -62,7 +83,9 @@ ContentSetting GeolocationContentSettingsMap::GetContentSetting(
GURL requesting_origin(requesting_url.GetOrigin());
GURL embedding_origin(embedding_url.GetOrigin());
DCHECK(requesting_origin.is_valid() && embedding_origin.is_valid());
-
+ // If the profile is destroyed (and set to NULL) return CONTENT_SETTING_BLOCK.
+ if (!profile_)
+ return CONTENT_SETTING_BLOCK;
const DictionaryValue* all_settings_dictionary =
profile_->GetPrefs()->GetDictionary(prefs::kGeolocationContentSettings);
// Careful: The returned value could be NULL if the pref has never been set.
@@ -115,6 +138,8 @@ GeolocationContentSettingsMap::AllOriginsSettings
void GeolocationContentSettingsMap::SetDefaultContentSetting(
ContentSetting setting) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!profile_)
+ return;
profile_->GetPrefs()->SetInteger(prefs::kGeolocationDefaultContentSetting,
setting == CONTENT_SETTING_DEFAULT ?
kDefaultSetting : setting);
@@ -131,6 +156,8 @@ void GeolocationContentSettingsMap::SetContentSetting(
GURL embedding_origin(embedding_url.GetOrigin());
DCHECK(requesting_origin.is_valid());
DCHECK(embedding_origin.is_valid() || embedding_url.is_empty());
+ if (!profile_)
+ return;
PrefService* prefs = profile_->GetPrefs();
DictionaryValue* all_settings_dictionary = prefs->GetMutableDictionary(
prefs::kGeolocationContentSettings);
@@ -162,13 +189,52 @@ void GeolocationContentSettingsMap::SetContentSetting(
void GeolocationContentSettingsMap::ResetToDefault() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
+ if (!profile_)
+ return;
PrefService* prefs = profile_->GetPrefs();
prefs->ClearPref(prefs::kGeolocationDefaultContentSetting);
prefs->ClearPref(prefs::kGeolocationContentSettings);
}
+void GeolocationContentSettingsMap::NotifyObservers(
+ const ContentSettingsDetails& details) {
+ NotificationService::current()->Notify(
+ NotificationType::GEOLOCATION_SETTINGS_CHANGED,
+ Source<GeolocationContentSettingsMap>(this),
+ Details<const ContentSettingsDetails>(&details));
+}
+
+void GeolocationContentSettingsMap::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::PREF_CHANGED) {
+ const std::string& name = *Details<std::string>(details).ptr();
+ if (name == prefs::kGeolocationDefaultContentSetting) {
+ NotifyObservers(ContentSettingsDetails(
+ ContentSettingsPattern(),
+ CONTENT_SETTINGS_TYPE_DEFAULT,
+ ""));
+ }
+ } else if (NotificationType::PROFILE_DESTROYED == type) {
+ UnregisterObservers();
+ } else {
+ NOTREACHED();
+ }
+}
+
+void GeolocationContentSettingsMap::UnregisterObservers() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!profile_)
+ return;
+ prefs_registrar_.RemoveAll();
+ notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED,
+ Source<Profile>(profile_));
+ profile_ = NULL;
+}
+
GeolocationContentSettingsMap::~GeolocationContentSettingsMap() {
+ UnregisterObservers();
}
// static
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map.h b/chrome/browser/geolocation/geolocation_content_settings_map.h
index ae56044..74a74fa 100644
--- a/chrome/browser/geolocation/geolocation_content_settings_map.h
+++ b/chrome/browser/geolocation/geolocation_content_settings_map.h
@@ -17,21 +17,28 @@
#include "base/basictypes.h"
#include "base/ref_counted.h"
+#include "chrome/browser/prefs/pref_change_registrar.h"
#include "chrome/common/content_settings.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
#include "googleurl/src/gurl.h"
+class ContentSettingsDetails;
class DictionaryValue;
class PrefService;
class Profile;
class GeolocationContentSettingsMap
- : public base::RefCountedThreadSafe<GeolocationContentSettingsMap> {
+ : public base::RefCountedThreadSafe<GeolocationContentSettingsMap>,
+ public NotificationObserver {
public:
typedef std::map<GURL, ContentSetting> OneOriginSettings;
typedef std::map<GURL, OneOriginSettings> AllOriginsSettings;
explicit GeolocationContentSettingsMap(Profile* profile);
+ virtual ~GeolocationContentSettingsMap();
+
static void RegisterUserPrefs(PrefService* prefs);
// Returns the default setting.
@@ -39,6 +46,9 @@ class GeolocationContentSettingsMap
// This should only be called on the UI thread.
ContentSetting GetDefaultContentSetting() const;
+ // Returns true if the content setting is managed (set by a policy).
+ bool IsDefaultContentSettingManaged() const;
+
// Returns a single ContentSetting which applies to the given |requesting_url|
// when embedded in a top-level page from |embedding_url|. To determine the
// setting for a top-level page, as opposed to a frame embedded in a page,
@@ -80,13 +90,21 @@ class GeolocationContentSettingsMap
// This should only be called on the UI thread.
void ResetToDefault();
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
private:
friend class base::RefCountedThreadSafe<GeolocationContentSettingsMap>;
// The default setting.
static const ContentSetting kDefaultSetting;
- ~GeolocationContentSettingsMap();
+ // Sends a CONTENT_SETTINGS_CHANGED notification.
+ void NotifyObservers(const ContentSettingsDetails& details);
+
+ void UnregisterObservers();
// Sets the fields of |one_origin_settings| based on the values in
// |dictionary|.
@@ -97,6 +115,10 @@ class GeolocationContentSettingsMap
// The profile we're associated with.
Profile* profile_;
+ // Registrar to register for PREF_CHANGED notifications.
+ PrefChangeRegistrar prefs_registrar_;
+ NotificationRegistrar notification_registrar_;
+
DISALLOW_COPY_AND_ASSIGN(GeolocationContentSettingsMap);
};
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc b/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc
index 2ed941d..0177f0f 100644
--- a/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc
+++ b/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc
@@ -6,7 +6,10 @@
#include "base/message_loop.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/content_settings/content_settings_details.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/common/notification_registrar.h"
+#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -14,6 +17,41 @@
namespace {
+class StubSettingsObserver : public NotificationObserver {
+ public:
+ StubSettingsObserver() : last_notifier(NULL), counter(0) {
+ registrar_.Add(this, NotificationType::GEOLOCATION_SETTINGS_CHANGED,
+ NotificationService::AllSources());
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ ++counter;
+ Source<GeolocationContentSettingsMap> content_settings(source);
+ Details<ContentSettingsDetails> settings_details(details);
+ last_notifier = content_settings.ptr();
+ last_pattern = settings_details.ptr()->pattern();
+ last_update_all = settings_details.ptr()->update_all();
+ last_update_all_types = settings_details.ptr()->update_all_types();
+ last_type = settings_details.ptr()->type();
+ // This checks that calling a Get function from an observer doesn't
+ // deadlock.
+ last_notifier->GetContentSetting(GURL("http://random-hostname.com/"),
+ GURL("http://foo.random-hostname.com/"));
+ }
+
+ GeolocationContentSettingsMap* last_notifier;
+ ContentSettingsPattern last_pattern;
+ bool last_update_all;
+ bool last_update_all_types;
+ int counter;
+ ContentSettingsType last_type;
+
+ private:
+ NotificationRegistrar registrar_;
+};
+
class GeolocationContentSettingsMapTests : public testing::Test {
public:
GeolocationContentSettingsMapTests()
@@ -241,4 +279,32 @@ TEST_F(GeolocationContentSettingsMapTests, IgnoreInvalidURLsInPrefs) {
GURL("http://b/")));
}
+TEST_F(GeolocationContentSettingsMapTests, Observe) {
+ TestingProfile profile;
+ GeolocationContentSettingsMap* map =
+ profile.GetGeolocationContentSettingsMap();
+ StubSettingsObserver observer;
+
+ EXPECT_EQ(CONTENT_SETTING_ASK, map->GetDefaultContentSetting());
+
+ // Test if a CONTENT_SETTING_CHANGE notification is sent after the geolocation
+ // default content setting was changed through calling the
+ // SetDefaultContentSetting method.
+ map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(map, observer.last_notifier);
+ EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
+ EXPECT_EQ(1, observer.counter);
+
+
+ // Test if a CONTENT_SETTING_CHANGE notification is sent after the preference
+ // GeolocationDefaultContentSetting was changed.
+ PrefService* prefs = profile.GetPrefs();
+ prefs->SetInteger(prefs::kGeolocationDefaultContentSetting,
+ CONTENT_SETTING_ALLOW);
+ EXPECT_EQ(2, observer.counter);
+ EXPECT_EQ(map, observer.last_notifier);
+ EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetDefaultContentSetting());
+}
+
} // namespace
diff --git a/chrome/browser/gtk/options/content_filter_page_gtk.cc b/chrome/browser/gtk/options/content_filter_page_gtk.cc
index 547f3d1..13aeb05 100644
--- a/chrome/browser/gtk/options/content_filter_page_gtk.cc
+++ b/chrome/browser/gtk/options/content_filter_page_gtk.cc
@@ -7,6 +7,7 @@
#include "app/l10n_util.h"
#include "base/command_line.h"
#include "chrome/browser/content_settings/content_settings_details.h"
+#include "chrome/browser/content_settings/content_settings_pattern.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/geolocation/geolocation_exceptions_table_model.h"
#include "chrome/browser/plugin_exceptions_table_model.h"
@@ -157,6 +158,10 @@ GtkWidget* ContentFilterPageGtk::InitGroup() {
// aften content settings change.
registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED,
+ NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::GEOLOCATION_SETTINGS_CHANGED,
+ NotificationService::AllSources());
return vbox;
}
@@ -164,15 +169,24 @@ GtkWidget* ContentFilterPageGtk::InitGroup() {
void ContentFilterPageGtk::UpdateButtonsState() {
// Get default_setting.
ContentSetting default_setting;
+ // If the content setting is managed, sensitive is set to false and the radio
+ // buttons will be disabled.
+ bool sensitive = true;
if (content_type_ == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
default_setting = profile()->GetGeolocationContentSettingsMap()->
GetDefaultContentSetting();
+ sensitive = !profile()->GetGeolocationContentSettingsMap()->
+ IsDefaultContentSettingManaged();
} else if (content_type_ == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
default_setting = profile()->GetDesktopNotificationService()->
GetDefaultContentSetting();
+ sensitive = !profile()->GetDesktopNotificationService()->
+ IsDefaultContentSettingManaged();
} else {
default_setting = profile()->GetHostContentSettingsMap()->
GetDefaultContentSetting(content_type_);
+ sensitive = !profile()->GetHostContentSettingsMap()->
+ IsDefaultContentSettingManaged(content_type_);
}
// Set UI state.
if (default_setting == CONTENT_SETTING_ALLOW) {
@@ -186,8 +200,6 @@ void ContentFilterPageGtk::UpdateButtonsState() {
}
// Disable the UI if the default content setting is managed.
- bool sensitive = !profile()->GetHostContentSettingsMap()->
- IsDefaultContentSettingManaged(content_type_);
gtk_widget_set_sensitive(allow_radio_, sensitive);
gtk_widget_set_sensitive(block_radio_, sensitive);
if (ask_radio_)
@@ -276,10 +288,18 @@ void ContentFilterPageGtk::OnPluginsPageLinkClicked(GtkWidget* button) {
void ContentFilterPageGtk::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
-
if (type == NotificationType::CONTENT_SETTINGS_CHANGED) {
NotifyContentSettingsChanged(
Details<const ContentSettingsDetails>(details).ptr());
+ } else if (type == NotificationType::GEOLOCATION_SETTINGS_CHANGED) {
+ NotifyContentSettingsChanged(
+ Details<const ContentSettingsDetails>(details).ptr());
+ } else if (type == NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED) {
+ ContentSettingsDetails content_settings_details(
+ ContentSettingsPattern(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ "");
+ NotifyContentSettingsChanged(&content_settings_details);
} else {
OptionsPageBase::Observe(type, source, details);
}
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index 494d86f..2badc86 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -452,6 +452,11 @@ void DesktopNotificationService::SetDefaultContentSetting(
// The cache is updated through the notification observer.
}
+bool DesktopNotificationService::IsDefaultContentSettingManaged() const {
+ return profile_->GetPrefs()->IsManagedPreference(
+ prefs::kDesktopNotificationDefaultContentSetting);
+}
+
void DesktopNotificationService::ResetToDefaultContentSetting() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h
index a7a4ce2..bb6691b 100644
--- a/chrome/browser/notifications/desktop_notification_service.h
+++ b/chrome/browser/notifications/desktop_notification_service.h
@@ -93,6 +93,7 @@ class DesktopNotificationService : public NotificationObserver {
// been allowed or denied yet.
ContentSetting GetDefaultContentSetting();
void SetDefaultContentSetting(ContentSetting setting);
+ bool IsDefaultContentSettingManaged() const;
// NOTE: This should only be called on the UI thread.
void ResetToDefaultContentSetting();
diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc
index c777e35..813eecc 100644
--- a/chrome/browser/policy/configuration_policy_pref_store.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store.cc
@@ -163,17 +163,21 @@ const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry
{ Value::TYPE_BOOLEAN, kPolicyDeveloperToolsDisabled,
prefs::kDevToolsDisabled },
{ Value::TYPE_BOOLEAN, kPolicyBlockThirdPartyCookies,
- prefs::kBlockThirdPartyCookies},
+ prefs::kBlockThirdPartyCookies },
{ Value::TYPE_INTEGER, kPolicyDefaultCookiesSetting,
- prefs::kManagedDefaultCookiesSetting},
+ prefs::kManagedDefaultCookiesSetting },
{ Value::TYPE_INTEGER, kPolicyDefaultImagesSetting,
- prefs::kManagedDefaultImagesSetting},
+ prefs::kManagedDefaultImagesSetting },
{ Value::TYPE_INTEGER, kPolicyDefaultJavaScriptSetting,
- prefs::kManagedDefaultJavaScriptSetting},
+ prefs::kManagedDefaultJavaScriptSetting },
{ Value::TYPE_INTEGER, kPolicyDefaultPluginsSetting,
- prefs::kManagedDefaultPluginsSetting},
+ prefs::kManagedDefaultPluginsSetting },
{ Value::TYPE_INTEGER, kPolicyDefaultPopupsSetting,
- prefs::kManagedDefaultPopupsSetting},
+ prefs::kManagedDefaultPopupsSetting },
+ { Value::TYPE_INTEGER, kPolicyDefaultNotificationSetting,
+ prefs::kDesktopNotificationDefaultContentSetting },
+ { Value::TYPE_INTEGER, kPolicyDefaultGeolocationSetting,
+ prefs::kGeolocationDefaultContentSetting },
{ Value::TYPE_STRING, kPolicyAuthSchemes,
prefs::kAuthSchemes },
{ Value::TYPE_BOOLEAN, kPolicyDisableAuthNegotiateCnameLookup,
@@ -282,15 +286,19 @@ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() {
{ kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN,
key::kBlockThirdPartyCookies },
{ kPolicyDefaultCookiesSetting, Value::TYPE_INTEGER,
- key::kDefaultCookiesSetting},
+ key::kDefaultCookiesSetting },
{ kPolicyDefaultImagesSetting, Value::TYPE_INTEGER,
- key::kDefaultImagesSetting},
+ key::kDefaultImagesSetting },
{ kPolicyDefaultJavaScriptSetting, Value::TYPE_INTEGER,
- key::kDefaultJavaScriptSetting},
+ key::kDefaultJavaScriptSetting },
{ kPolicyDefaultPluginsSetting, Value::TYPE_INTEGER,
- key::kDefaultPluginsSetting},
+ key::kDefaultPluginsSetting },
{ kPolicyDefaultPopupsSetting, Value::TYPE_INTEGER,
- key::kDefaultPopupsSetting},
+ key::kDefaultPopupsSetting },
+ { kPolicyDefaultNotificationSetting, Value::TYPE_INTEGER,
+ key::kDefaultNotificationSetting },
+ { kPolicyDefaultGeolocationSetting, Value::TYPE_INTEGER,
+ key::kDefaultGeolocationSetting },
{ kPolicyAuthSchemes, Value::TYPE_STRING, key::kAuthSchemes },
{ kPolicyDisableAuthNegotiateCnameLookup, Value::TYPE_BOOLEAN,
key::kDisableAuthNegotiateCnameLookup },
@@ -303,7 +311,6 @@ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() {
{ kPolicyGSSAPILibraryName, Value::TYPE_STRING,
key::kGSSAPILibraryName },
-
#if defined(OS_CHROMEOS)
{ kPolicyChromeOsLockOnIdleSuspend, Value::TYPE_BOOLEAN,
key::kChromeOsLockOnIdleSuspend },
diff --git a/chrome/browser/policy/configuration_policy_store_interface.h b/chrome/browser/policy/configuration_policy_store_interface.h
index cfb943e..860f3a4 100644
--- a/chrome/browser/policy/configuration_policy_store_interface.h
+++ b/chrome/browser/policy/configuration_policy_store_interface.h
@@ -56,6 +56,8 @@ enum ConfigurationPolicyType {
kPolicyDefaultJavaScriptSetting,
kPolicyDefaultPluginsSetting,
kPolicyDefaultPopupsSetting,
+ kPolicyDefaultNotificationSetting,
+ kPolicyDefaultGeolocationSetting,
kPolicyExtensionInstallForceList,
kPolicyChromeOsLockOnIdleSuspend,
kPolicyAuthSchemes,
diff --git a/chrome/browser/resources/options/content_settings.js b/chrome/browser/resources/options/content_settings.js
index efc85e8..4f48190 100644
--- a/chrome/browser/resources/options/content_settings.js
+++ b/chrome/browser/resources/options/content_settings.js
@@ -78,8 +78,13 @@ cr.define('options', function() {
*/
ContentSettings.setContentFilterSettingsValue = function(dict) {
for (var group in dict) {
- document.querySelector('input[type=radio][name=' + group +
- '][value=' + dict[group] + ']').checked = true;
+ document.querySelector('input[type=radio][name=' + group + '][value=' +
+ dict[group]['value'] + ']').checked = true;
+ var radios = document.querySelectorAll('input[type=radio][name=' +
+ group + ']');
+ for (var i = 0, len = radios.length; i < len; i++) {
+ radios[i].disabled = dict[group]['managed'];
+ }
}
};
diff --git a/chrome/browser/ui/views/options/content_filter_page_view.cc b/chrome/browser/ui/views/options/content_filter_page_view.cc
index d331540..3e4ba8d 100644
--- a/chrome/browser/ui/views/options/content_filter_page_view.cc
+++ b/chrome/browser/ui/views/options/content_filter_page_view.cc
@@ -153,6 +153,10 @@ void ContentFilterPageView::InitControlLayout() {
registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED,
+ NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::GEOLOCATION_SETTINGS_CHANGED,
+ NotificationService::AllSources());
}
///////////////////////////////////////////////////////////////////////////////
@@ -163,9 +167,13 @@ void ContentFilterPageView::UpdateView() {
if (content_type_ == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
default_setting = profile()->GetGeolocationContentSettingsMap()->
GetDefaultContentSetting();
+ is_content_type_managed = profile()->GetGeolocationContentSettingsMap()->
+ IsDefaultContentSettingManaged();
} else if (content_type_ == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
default_setting = profile()->GetDesktopNotificationService()->
GetDefaultContentSetting();
+ is_content_type_managed = profile()->GetDesktopNotificationService()->
+ IsDefaultContentSettingManaged();
} else {
default_setting = profile()->GetHostContentSettingsMap()->
GetDefaultContentSetting(content_type_);
@@ -267,6 +275,15 @@ void ContentFilterPageView::Observe(NotificationType type,
if (type == NotificationType::CONTENT_SETTINGS_CHANGED) {
NotifyContentSettingsChanged(
Details<ContentSettingsDetails>(details).ptr());
+ } else if (type == NotificationType::GEOLOCATION_SETTINGS_CHANGED) {
+ NotifyContentSettingsChanged(
+ Details<ContentSettingsDetails>(details).ptr());
+ } else if (type == NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED) {
+ ContentSettingsDetails content_settings_details(
+ ContentSettingsPattern(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ "");
+ NotifyContentSettingsChanged(&content_settings_details);
} else {
OptionsPageBase::Observe(type, source, details);
}
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index 7f01898..8564063 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -1116,6 +1116,11 @@ class NotificationType {
// details are None.
DESKTOP_NOTIFICATION_SETTINGS_CHANGED,
+ // Sent when the geolocation settings change. The source is the
+ // GeolocationContentSettingsMap object, the details are
+ // ContentSettingsNotificationsDetails.
+ GEOLOCATION_SETTINGS_CHANGED,
+
// Sync --------------------------------------------------------------------
// Sent when the sync backend has been paused.
diff --git a/chrome/common/policy_constants.cc b/chrome/common/policy_constants.cc
index 36e6874..8fcad63 100644
--- a/chrome/common/policy_constants.cc
+++ b/chrome/common/policy_constants.cc
@@ -62,6 +62,8 @@ const char kDefaultImagesSetting[] = "DefaultImagesSetting";
const char kDefaultJavaScriptSetting[] = "DefaultJavaScriptSetting";
const char kDefaultPluginsSetting[] = "DefaultPluginsSetting";
const char kDefaultPopupsSetting[] = "DefaultPopupsSetting";
+const char kDefaultNotificationSetting[] = "DefaultNotificationSetting";
+const char kDefaultGeolocationSetting[] = "DefaultGeolocationSetting";
const char kAuthSchemes[] = "AuthSchemes";
const char kDisableAuthNegotiateCnameLookup[] =
"DisableAuthNegotiateCnameLookup";
diff --git a/chrome/common/policy_constants.h b/chrome/common/policy_constants.h
index 623cc17..318e27c 100644
--- a/chrome/common/policy_constants.h
+++ b/chrome/common/policy_constants.h
@@ -59,6 +59,8 @@ extern const char kDefaultImagesSetting[];
extern const char kDefaultJavaScriptSetting[];
extern const char kDefaultPluginsSetting[];
extern const char kDefaultPopupsSetting[];
+extern const char kDefaultNotificationSetting[];
+extern const char kDefaultGeolocationSetting[];
extern const char kAuthSchemes[];
extern const char kDisableAuthNegotiateCnameLookup[];
extern const char kEnableAuthNegotiatePort[];