summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-30 12:48:44 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-30 12:48:44 +0000
commit2dd6bca0a1040075b094b73a100dbca424f4b2f8 (patch)
tree4f38c5eb4b0fa3b09480fce6b16429677a67e90e
parent9d01a6a5884920abb57f71b8fb9a1101bf15cca0 (diff)
downloadchromium_src-2dd6bca0a1040075b094b73a100dbca424f4b2f8.zip
chromium_src-2dd6bca0a1040075b094b73a100dbca424f4b2f8.tar.gz
chromium_src-2dd6bca0a1040075b094b73a100dbca424f4b2f8.tar.bz2
Introduce a content settings provider interface.
BUG=64753 TEST=ContentSettingsProviderTest.* Review URL: http://codereview.chromium.org/5269007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67707 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/content_settings/content_settings_provider.h38
-rw-r--r--chrome/browser/content_settings/content_settings_provider_unittest.cc26
-rw-r--r--chrome/browser/content_settings/mock_content_settings_provider.cc41
-rw-r--r--chrome/browser/content_settings/mock_content_settings_provider.h39
-rw-r--r--chrome/chrome_browser.gypi1
-rw-r--r--chrome/chrome_tests.gypi3
6 files changed, 148 insertions, 0 deletions
diff --git a/chrome/browser/content_settings/content_settings_provider.h b/chrome/browser/content_settings/content_settings_provider.h
new file mode 100644
index 0000000..3229779a
--- /dev/null
+++ b/chrome/browser/content_settings/content_settings_provider.h
@@ -0,0 +1,38 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Interface for objects providing content setting rules.
+
+#ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_
+#define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_
+#pragma once
+
+#include "chrome/common/content_settings.h"
+
+class ContentSettingsProviderInterface {
+ public:
+ // True if this provider can provide a default setting for the |content_type|.
+ virtual bool CanProvideDefaultSetting(ContentSettingsType content_type) = 0;
+
+ // Returns the default content setting this provider has for the given
+ // |content_type|, or CONTENT_SETTING_DEFAULT if nothing be provided for this
+ // type.
+ virtual ContentSetting ProvideDefaultSetting(
+ ContentSettingsType content_type) = 0;
+
+ // Notifies the provider that the host content settings map would like to
+ // update the default setting for the given |content_type|. The provider may
+ // ignore this.
+ virtual void UpdateDefaultSetting(ContentSettingsType content_type,
+ ContentSetting setting) = 0;
+
+ // True if the default setting for the |content_type| is policy managed, i.e.,
+ // there shouldn't be any UI shown to modify this setting.
+ virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) = 0;
+
+ protected:
+ virtual ~ContentSettingsProviderInterface() {};
+};
+
+#endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_
diff --git a/chrome/browser/content_settings/content_settings_provider_unittest.cc b/chrome/browser/content_settings/content_settings_provider_unittest.cc
new file mode 100644
index 0000000..bb625ef
--- /dev/null
+++ b/chrome/browser/content_settings/content_settings_provider_unittest.cc
@@ -0,0 +1,26 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "chrome/browser/content_settings/mock_content_settings_provider.h"
+
+TEST(ContentSettingsProviderTest, Mock) {
+ MockContentSettingsProvider provider(CONTENT_SETTINGS_TYPE_COOKIES,
+ CONTENT_SETTING_ALLOW,
+ false,
+ true);
+ EXPECT_TRUE(provider.CanProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
+ EXPECT_FALSE(provider.CanProvideDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS));
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
+ EXPECT_EQ(CONTENT_SETTING_DEFAULT,
+ provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS));
+ EXPECT_FALSE(provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES));
+ EXPECT_FALSE(provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_POPUPS));
+ provider.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES,
+ CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
+}
diff --git a/chrome/browser/content_settings/mock_content_settings_provider.cc b/chrome/browser/content_settings/mock_content_settings_provider.cc
new file mode 100644
index 0000000..f93f7ce
--- /dev/null
+++ b/chrome/browser/content_settings/mock_content_settings_provider.cc
@@ -0,0 +1,41 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/content_settings/mock_content_settings_provider.h"
+
+MockContentSettingsProvider::MockContentSettingsProvider(
+ ContentSettingsType content_type,
+ ContentSetting setting,
+ bool is_managed,
+ bool can_override)
+ : content_type_(content_type),
+ setting_(setting),
+ is_managed_(is_managed),
+ can_override_(can_override) {
+}
+
+MockContentSettingsProvider::~MockContentSettingsProvider() {
+}
+
+bool MockContentSettingsProvider::CanProvideDefaultSetting(
+ ContentSettingsType content_type) {
+ return content_type == content_type_;
+}
+
+ContentSetting MockContentSettingsProvider::ProvideDefaultSetting(
+ ContentSettingsType content_type) {
+ return content_type == content_type_ ? setting_ : CONTENT_SETTING_DEFAULT;
+}
+
+void MockContentSettingsProvider::UpdateDefaultSetting(
+ ContentSettingsType content_type,
+ ContentSetting setting) {
+ if (can_override_ && content_type == content_type_)
+ setting_ = setting;
+}
+
+bool MockContentSettingsProvider::DefaultSettingIsManaged(
+ ContentSettingsType content_type) {
+ return content_type == content_type_ && is_managed_;
+}
diff --git a/chrome/browser/content_settings/mock_content_settings_provider.h b/chrome/browser/content_settings/mock_content_settings_provider.h
new file mode 100644
index 0000000..e716909
--- /dev/null
+++ b/chrome/browser/content_settings/mock_content_settings_provider.h
@@ -0,0 +1,39 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CONTENT_SETTINGS_MOCK_CONTENT_SETTINGS_PROVIDER_H_
+#define CHROME_BROWSER_CONTENT_SETTINGS_MOCK_CONTENT_SETTINGS_PROVIDER_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "chrome/browser/content_settings/content_settings_provider.h"
+
+class MockContentSettingsProvider : public ContentSettingsProviderInterface {
+ public:
+ // Create a content settings provider that provides a given setting for a
+ // given type.
+ MockContentSettingsProvider(ContentSettingsType content_type,
+ ContentSetting setting,
+ bool is_managed,
+ bool can_override);
+ virtual ~MockContentSettingsProvider();
+
+ // ContentSettingsProviderInterface implementation.
+ virtual bool CanProvideDefaultSetting(ContentSettingsType content_type);
+ virtual ContentSetting ProvideDefaultSetting(
+ ContentSettingsType content_type);
+ virtual void UpdateDefaultSetting(ContentSettingsType content_type,
+ ContentSetting setting);
+ virtual bool DefaultSettingIsManaged(ContentSettingsType content_type);
+
+ private:
+ ContentSettingsType content_type_;
+ ContentSetting setting_;
+ bool is_managed_;
+ bool can_override_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockContentSettingsProvider);
+};
+
+#endif // CHROME_BROWSER_CONTENT_SETTINGS_MOCK_CONTENT_SETTINGS_PROVIDER_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index b73259c..a5f6f16 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1239,6 +1239,7 @@
'browser/content_setting_combo_model.h',
'browser/content_setting_image_model.cc',
'browser/content_setting_image_model.h',
+ 'browser/content_settings/content_settings_provider.h',
'browser/content_settings/host_content_settings_map.cc',
'browser/content_settings/host_content_settings_map.h',
'browser/cookies_tree_model.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 9814273..289ab1a 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1265,7 +1265,10 @@
'browser/cocoa/wrench_menu_controller_unittest.mm',
'browser/command_updater_unittest.cc',
'browser/content_exceptions_table_model_unittest.cc',
+ 'browser/content_settings/content_settings_provider_unittest.cc',
'browser/content_settings/host_content_settings_map_unittest.cc',
+ 'browser/content_settings/mock_content_settings_provider.cc',
+ 'browser/content_settings/mock_content_settings_provider.h',
'browser/cookies_tree_model_unittest.cc',
'browser/debugger/devtools_manager_unittest.cc',
'browser/device_orientation/provider_unittest.cc',