summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-02 14:47:45 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-02 14:47:45 +0000
commit5f24f215c60528bd329930bf98373a52dfe08555 (patch)
treef26f29fd3404cacb55f55a038c094d14e2076a73 /chrome
parentc139f9bf6f6f5ce2e550c59952ff5bebb1430458 (diff)
downloadchromium_src-5f24f215c60528bd329930bf98373a52dfe08555.zip
chromium_src-5f24f215c60528bd329930bf98373a52dfe08555.tar.gz
chromium_src-5f24f215c60528bd329930bf98373a52dfe08555.tar.bz2
Move ContentSettingsDetails and Pattern out of HostContentSettingsMap as separate classes.
BUG=64753 TEST=compiles Review URL: http://codereview.chromium.org/5574001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc2
-rw-r--r--chrome/browser/content_exceptions_table_model.cc8
-rw-r--r--chrome/browser/content_exceptions_table_model.h4
-rw-r--r--chrome/browser/content_exceptions_table_model_unittest.cc2
-rw-r--r--chrome/browser/content_settings/content_settings_details.h56
-rw-r--r--chrome/browser/content_settings/content_settings_pattern.cc87
-rw-r--r--chrome/browser/content_settings/content_settings_pattern.h72
-rw-r--r--chrome/browser/content_settings/content_settings_pattern_unittest.cc69
-rw-r--r--chrome/browser/content_settings/host_content_settings_map.cc143
-rw-r--r--chrome/browser/content_settings/host_content_settings_map.h92
-rw-r--r--chrome/browser/content_settings/host_content_settings_map_unittest.cc105
-rw-r--r--chrome/browser/cookies_tree_model_unittest.cc8
-rw-r--r--chrome/browser/dom_ui/options/content_settings_handler.cc20
-rw-r--r--chrome/browser/gtk/options/content_exception_editor.cc10
-rw-r--r--chrome/browser/gtk/options/content_exception_editor.h8
-rw-r--r--chrome/browser/gtk/options/content_exceptions_window_gtk.cc4
-rw-r--r--chrome/browser/gtk/options/content_exceptions_window_gtk.h2
-rw-r--r--chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc2
-rw-r--r--chrome/browser/gtk/options/content_filter_page_gtk.cc5
-rw-r--r--chrome/browser/gtk/options/content_filter_page_gtk.h4
-rw-r--r--chrome/browser/plugin_exceptions_table_model.h2
-rw-r--r--chrome/browser/plugin_exceptions_table_model_unittest.cc6
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc4
-rw-r--r--chrome/browser/ui/cocoa/content_exceptions_window_controller.mm7
-rw-r--r--chrome/browser/ui/cocoa/content_exceptions_window_controller_unittest.mm6
-rw-r--r--chrome/browser/ui/cocoa/content_settings_dialog_controller.mm11
-rw-r--r--chrome/browser/ui/cocoa/table_model_array_controller_unittest.mm6
-rw-r--r--chrome/browser/ui/views/options/content_filter_page_view.cc6
-rw-r--r--chrome/browser/ui/views/options/content_filter_page_view.h2
-rw-r--r--chrome/browser/ui/views/options/exception_editor_view.cc12
-rw-r--r--chrome/browser/ui/views/options/exception_editor_view.h8
-rw-r--r--chrome/browser/ui/views/options/exceptions_view.cc4
-rw-r--r--chrome/browser/ui/views/options/exceptions_view.h2
-rw-r--r--chrome/chrome_browser.gypi3
-rw-r--r--chrome/chrome_tests.gypi1
35 files changed, 431 insertions, 352 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 2c4e503..d180970 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -4497,7 +4497,7 @@ void TestingAutomationProvider::SetContentSetting(
if (host.empty()) {
map->SetDefaultContentSetting(content_type, setting);
} else {
- map->SetContentSetting(HostContentSettingsMap::Pattern(host),
+ map->SetContentSetting(ContentSettingsPattern(host),
content_type, "", setting);
}
*success = true;
diff --git a/chrome/browser/content_exceptions_table_model.cc b/chrome/browser/content_exceptions_table_model.cc
index c45177c..ee92157 100644
--- a/chrome/browser/content_exceptions_table_model.cc
+++ b/chrome/browser/content_exceptions_table_model.cc
@@ -30,7 +30,7 @@ ContentExceptionsTableModel::ContentExceptionsTableModel(
ContentExceptionsTableModel::~ContentExceptionsTableModel() {}
void ContentExceptionsTableModel::AddException(
- const HostContentSettingsMap::Pattern& original_pattern,
+ const ContentSettingsPattern& original_pattern,
ContentSetting setting,
bool is_off_the_record) {
DCHECK(!is_off_the_record || off_the_record_map_);
@@ -38,7 +38,7 @@ void ContentExceptionsTableModel::AddException(
int insert_position =
is_off_the_record ? RowCount() : static_cast<int>(entries_.size());
- const HostContentSettingsMap::Pattern pattern(
+ const ContentSettingsPattern pattern(
original_pattern.CanonicalizePattern());
entries(is_off_the_record).push_back(
@@ -77,14 +77,14 @@ void ContentExceptionsTableModel::RemoveAll() {
}
int ContentExceptionsTableModel::IndexOfExceptionByPattern(
- const HostContentSettingsMap::Pattern& original_pattern,
+ const ContentSettingsPattern& original_pattern,
bool is_off_the_record) {
DCHECK(!is_off_the_record || off_the_record_map_);
int offset =
is_off_the_record ? static_cast<int>(entries_.size()) : 0;
- const HostContentSettingsMap::Pattern pattern(
+ const ContentSettingsPattern pattern(
original_pattern.CanonicalizePattern());
// This is called on every key type in the editor. Move to a map if we end up
diff --git a/chrome/browser/content_exceptions_table_model.h b/chrome/browser/content_exceptions_table_model.h
index 17986f7..e01250b7 100644
--- a/chrome/browser/content_exceptions_table_model.h
+++ b/chrome/browser/content_exceptions_table_model.h
@@ -37,7 +37,7 @@ class ContentExceptionsTableModel : public TableModel {
}
// Adds a new exception on the map and table model.
- void AddException(const HostContentSettingsMap::Pattern& pattern,
+ void AddException(const ContentSettingsPattern& pattern,
ContentSetting setting,
bool is_off_the_record);
@@ -49,7 +49,7 @@ class ContentExceptionsTableModel : public TableModel {
// Returns the index of the specified exception given a host, or -1 if there
// is no exception for the specified host.
- int IndexOfExceptionByPattern(const HostContentSettingsMap::Pattern& pattern,
+ int IndexOfExceptionByPattern(const ContentSettingsPattern& pattern,
bool is_off_the_record);
// TableModel overrides:
diff --git a/chrome/browser/content_exceptions_table_model_unittest.cc b/chrome/browser/content_exceptions_table_model_unittest.cc
index f467d07..3c3d26d 100644
--- a/chrome/browser/content_exceptions_table_model_unittest.cc
+++ b/chrome/browser/content_exceptions_table_model_unittest.cc
@@ -27,7 +27,7 @@ TEST_F(ContentExceptionsTableModelTest, Incognito) {
otr_profile->GetHostContentSettingsMap(),
CONTENT_SETTINGS_TYPE_COOKIES);
delete otr_profile;
- model.AddException(HostContentSettingsMap::Pattern("example.com"),
+ model.AddException(ContentSettingsPattern("example.com"),
CONTENT_SETTING_BLOCK, true);
}
diff --git a/chrome/browser/content_settings/content_settings_details.h b/chrome/browser/content_settings/content_settings_details.h
new file mode 100644
index 0000000..51c54314c
--- /dev/null
+++ b/chrome/browser/content_settings/content_settings_details.h
@@ -0,0 +1,56 @@
+// 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.
+
+// The details send with notifications about content setting changes.
+
+#ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DETAILS_H_
+#define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DETAILS_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "chrome/browser/content_settings/content_settings_pattern.h"
+#include "chrome/common/content_settings.h"
+
+// Details for the CONTENT_SETTINGS_CHANGED notification. This is sent when
+// content settings change for at least one host. If settings change for more
+// than one pattern in one user interaction, this will usually send a single
+// notification with update_all() returning true instead of one notification
+// for each pattern.
+class ContentSettingsDetails {
+ public:
+ // Update the setting that matches this pattern/content type/resource.
+ ContentSettingsDetails(const ContentSettingsPattern& pattern,
+ ContentSettingsType type,
+ const std::string& resource_identifier)
+ : pattern_(pattern),
+ type_(type),
+ resource_identifier_(resource_identifier) {}
+
+ // The pattern whose settings have changed.
+ const ContentSettingsPattern& pattern() const { return pattern_; }
+
+ // True if all settings should be updated for the given type.
+ bool update_all() const { return pattern_.AsString().empty(); }
+
+ // The type of the pattern whose settings have changed.
+ ContentSettingsType type() const { return type_; }
+
+ // The resource identifier for the settings type that has changed.
+ const std::string& resource_identifier() const {
+ return resource_identifier_;
+ }
+
+ // True if all types should be updated. If update_all() is false, this will
+ // be false as well (although the reverse does not hold true).
+ bool update_all_types() const {
+ return CONTENT_SETTINGS_TYPE_DEFAULT == type_;
+ }
+
+ private:
+ ContentSettingsPattern pattern_;
+ ContentSettingsType type_;
+ std::string resource_identifier_;
+};
+
+#endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DETAILS_H_
diff --git a/chrome/browser/content_settings/content_settings_pattern.cc b/chrome/browser/content_settings/content_settings_pattern.cc
new file mode 100644
index 0000000..ba93ff4b
--- /dev/null
+++ b/chrome/browser/content_settings/content_settings_pattern.cc
@@ -0,0 +1,87 @@
+// 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/content_settings_pattern.h"
+
+#include "base/string_util.h"
+#include "net/base/net_util.h"
+#include "googleurl/src/gurl.h"
+#include "googleurl/src/url_canon.h"
+
+// The version of the pattern format implemented. Version 1 includes the
+// following patterns:
+// - [*.]domain.tld (matches domain.tld and all sub-domains)
+// - host (matches an exact hostname)
+// - a.b.c.d (matches an exact IPv4 ip)
+// - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip)
+// - file:///tmp/test.html (a complete URL without a host)
+// Version 2 adds a resource identifier for plugins.
+// TODO(jochen): update once this feature is no longer behind a flag.
+const int ContentSettingsPattern::kContentSettingsPatternVersion = 1;
+const char* ContentSettingsPattern::kDomainWildcard = "[*.]";
+const size_t ContentSettingsPattern::kDomainWildcardLength = 4;
+
+// static
+ContentSettingsPattern ContentSettingsPattern::FromURL(
+ const GURL& url) {
+ return ContentSettingsPattern(!url.has_host() || url.HostIsIPAddress() ?
+ net::GetHostOrSpecFromURL(url) :
+ std::string(kDomainWildcard) + url.host());
+}
+
+// static
+ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard(
+ const GURL& url) {
+ return ContentSettingsPattern(net::GetHostOrSpecFromURL(url));
+}
+
+bool ContentSettingsPattern::IsValid() const {
+ if (pattern_.empty())
+ return false;
+
+ const std::string host(pattern_.length() > kDomainWildcardLength &&
+ StartsWithASCII(pattern_, kDomainWildcard, false) ?
+ pattern_.substr(kDomainWildcardLength) :
+ pattern_);
+ url_canon::CanonHostInfo host_info;
+ return host.find('*') == std::string::npos &&
+ !net::CanonicalizeHost(host, &host_info).empty();
+}
+
+bool ContentSettingsPattern::Matches(const GURL& url) const {
+ if (!IsValid())
+ return false;
+
+ const std::string host(net::GetHostOrSpecFromURL(url));
+ if (pattern_.length() < kDomainWildcardLength ||
+ !StartsWithASCII(pattern_, kDomainWildcard, false))
+ return pattern_ == host;
+
+ const size_t match =
+ host.rfind(pattern_.substr(kDomainWildcardLength));
+
+ return (match != std::string::npos) &&
+ (match == 0 || host[match - 1] == '.') &&
+ (match + pattern_.length() - kDomainWildcardLength == host.length());
+}
+
+std::string ContentSettingsPattern::CanonicalizePattern() const {
+ if (!IsValid()) {
+ return "";
+ }
+
+ bool starts_with_wildcard = pattern_.length() > kDomainWildcardLength &&
+ StartsWithASCII(pattern_, kDomainWildcard, false);
+
+ const std::string host(starts_with_wildcard ?
+ pattern_.substr(kDomainWildcardLength) : pattern_);
+
+ std::string canonicalized_pattern =
+ starts_with_wildcard ? kDomainWildcard : "";
+
+ url_canon::CanonHostInfo host_info;
+ canonicalized_pattern += net::CanonicalizeHost(host, &host_info);
+
+ return canonicalized_pattern;
+}
diff --git a/chrome/browser/content_settings/content_settings_pattern.h b/chrome/browser/content_settings/content_settings_pattern.h
new file mode 100644
index 0000000..330042f
--- /dev/null
+++ b/chrome/browser/content_settings/content_settings_pattern.h
@@ -0,0 +1,72 @@
+// 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.
+
+// Patterns used in content setting rules.
+
+#ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_
+#define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_
+#pragma once
+
+#include <string>
+
+class GURL;
+
+// A pattern used in content setting rules. See |IsValid| for a description of
+// possible patterns.
+class ContentSettingsPattern {
+ public:
+ // Returns a pattern that matches the host of this URL and all subdomains.
+ static ContentSettingsPattern FromURL(const GURL& url);
+
+ // Returns a pattern that matches exactly this URL.
+ static ContentSettingsPattern FromURLNoWildcard(const GURL& url);
+
+ ContentSettingsPattern() {}
+
+ explicit ContentSettingsPattern(const std::string& pattern)
+ : pattern_(pattern) {}
+
+ // True if this is a valid pattern. Valid patterns are
+ // - [*.]domain.tld (matches domain.tld and all sub-domains)
+ // - host (matches an exact hostname)
+ // - a.b.c.d (matches an exact IPv4 ip)
+ // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip)
+ // TODO(jochen): should also return true for a complete URL without a host.
+ bool IsValid() const;
+
+ // True if |url| matches this pattern.
+ bool Matches(const GURL& url) const;
+
+ // Returns a std::string representation of this pattern.
+ const std::string& AsString() const { return pattern_; }
+
+ bool operator==(const ContentSettingsPattern& other) const {
+ return pattern_ == other.pattern_;
+ }
+
+ // Canonicalizes the pattern so that it's ASCII only, either
+ // in original (if it was already ASCII) or punycode form.
+ std::string CanonicalizePattern() const;
+
+ // The version of the pattern format implemented.
+ static const int kContentSettingsPatternVersion;
+
+ // The format of a domain wildcard.
+ static const char* kDomainWildcard;
+
+ // The length of kDomainWildcard (without the trailing '\0').
+ static const size_t kDomainWildcardLength;
+
+ private:
+ std::string pattern_;
+};
+
+// Stream operator so ContentSettingsPattern can be used in assertion
+// statements.
+inline std::ostream& operator<<(
+ std::ostream& out, const ContentSettingsPattern& pattern) {
+ return out << pattern.AsString();
+}
+
+#endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_
diff --git a/chrome/browser/content_settings/content_settings_pattern_unittest.cc b/chrome/browser/content_settings/content_settings_pattern_unittest.cc
new file mode 100644
index 0000000..88b42dc
--- /dev/null
+++ b/chrome/browser/content_settings/content_settings_pattern_unittest.cc
@@ -0,0 +1,69 @@
+// 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/content_settings_pattern.h"
+
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+TEST(ContentSettingsPatternTest, PatternSupport) {
+ EXPECT_TRUE(ContentSettingsPattern("[*.]example.com").IsValid());
+ EXPECT_TRUE(ContentSettingsPattern("example.com").IsValid());
+ EXPECT_TRUE(ContentSettingsPattern("192.168.0.1").IsValid());
+ EXPECT_TRUE(ContentSettingsPattern("[::1]").IsValid());
+ EXPECT_FALSE(ContentSettingsPattern("*example.com").IsValid());
+ EXPECT_FALSE(ContentSettingsPattern("example.*").IsValid());
+ EXPECT_FALSE(ContentSettingsPattern("http://example.com").IsValid());
+
+ EXPECT_TRUE(ContentSettingsPattern("[*.]example.com").Matches(
+ GURL("http://example.com/")));
+ EXPECT_TRUE(ContentSettingsPattern("[*.]example.com").Matches(
+ GURL("http://www.example.com/")));
+ EXPECT_TRUE(ContentSettingsPattern("www.example.com").Matches(
+ GURL("http://www.example.com/")));
+ EXPECT_FALSE(ContentSettingsPattern("").Matches(
+ GURL("http://www.example.com/")));
+ EXPECT_FALSE(ContentSettingsPattern("[*.]example.com").Matches(
+ GURL("http://example.org/")));
+ EXPECT_FALSE(ContentSettingsPattern("example.com").Matches(
+ GURL("http://example.org/")));
+}
+
+TEST(ContentSettingsPatternTest, CanonicalizePattern) {
+ // Basic patterns.
+ EXPECT_STREQ("[*.]ikea.com", ContentSettingsPattern("[*.]ikea.com")
+ .CanonicalizePattern().c_str());
+ EXPECT_STREQ("example.com", ContentSettingsPattern("example.com")
+ .CanonicalizePattern().c_str());
+ EXPECT_STREQ("192.168.1.1", ContentSettingsPattern("192.168.1.1")
+ .CanonicalizePattern().c_str());
+ EXPECT_STREQ("[::1]", ContentSettingsPattern("[::1]")
+ .CanonicalizePattern().c_str());
+ // IsValid returns false for file:/// patterns.
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "file:///temp/file.html").CanonicalizePattern().c_str());
+
+ // UTF-8 patterns.
+ EXPECT_STREQ("[*.]xn--ira-ppa.com", ContentSettingsPattern(
+ "[*.]\xC4\x87ira.com").CanonicalizePattern().c_str());
+ EXPECT_STREQ("xn--ira-ppa.com", ContentSettingsPattern(
+ "\xC4\x87ira.com").CanonicalizePattern().c_str());
+ // IsValid returns false for file:/// patterns.
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "file:///\xC4\x87ira.html").CanonicalizePattern().c_str());
+
+ // Invalid patterns.
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "*example.com").CanonicalizePattern().c_str());
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "example.*").CanonicalizePattern().c_str());
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "*\xC4\x87ira.com").CanonicalizePattern().c_str());
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "\xC4\x87ira.*").CanonicalizePattern().c_str());
+}
+
+} // namespace
diff --git a/chrome/browser/content_settings/host_content_settings_map.cc b/chrome/browser/content_settings/host_content_settings_map.cc
index 5e167a7..fb2e6e9 100644
--- a/chrome/browser/content_settings/host_content_settings_map.cc
+++ b/chrome/browser/content_settings/host_content_settings_map.cc
@@ -8,6 +8,7 @@
#include "base/string_util.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/metrics/user_metrics.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profile.h"
@@ -26,22 +27,6 @@
#include "net/base/static_cookie_policy.h"
namespace {
-// The version of the pattern format implemented. Version 1 includes the
-// following patterns:
-// - [*.]domain.tld (matches domain.tld and all sub-domains)
-// - host (matches an exact hostname)
-// - a.b.c.d (matches an exact IPv4 ip)
-// - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip)
-// - file:///tmp/test.html (a complete URL without a host)
-// Version 2 adds a resource identifier for plugins.
-// TODO(jochen): update once this feature is no longer behind a flag.
-const int kContentSettingsPatternVersion = 1;
-
-// The format of a domain wildcard.
-const char kDomainWildcard[] = "[*.]";
-
-// The length of kDomainWildcard (without the trailing '\0')
-const size_t kDomainWildcardLength = arraysize(kDomainWildcard) - 1;
// Base pref path of the prefs that contain the managed default content
// settings values.
@@ -138,70 +123,6 @@ struct HostContentSettingsMap::ExtendedContentSettings {
ResourceContentSettings content_settings_for_resources;
};
-// static
-HostContentSettingsMap::Pattern HostContentSettingsMap::Pattern::FromURL(
- const GURL& url) {
- return Pattern(!url.has_host() || url.HostIsIPAddress() ?
- net::GetHostOrSpecFromURL(url) :
- std::string(kDomainWildcard) + url.host());
-}
-
-// static
-HostContentSettingsMap::Pattern
- HostContentSettingsMap::Pattern::FromURLNoWildcard(const GURL& url) {
- return Pattern(net::GetHostOrSpecFromURL(url));
-}
-
-bool HostContentSettingsMap::Pattern::IsValid() const {
- if (pattern_.empty())
- return false;
-
- const std::string host(pattern_.length() > kDomainWildcardLength &&
- StartsWithASCII(pattern_, kDomainWildcard, false) ?
- pattern_.substr(kDomainWildcardLength) :
- pattern_);
- url_canon::CanonHostInfo host_info;
- return host.find('*') == std::string::npos &&
- !net::CanonicalizeHost(host, &host_info).empty();
-}
-
-bool HostContentSettingsMap::Pattern::Matches(const GURL& url) const {
- if (!IsValid())
- return false;
-
- const std::string host(net::GetHostOrSpecFromURL(url));
- if (pattern_.length() < kDomainWildcardLength ||
- !StartsWithASCII(pattern_, kDomainWildcard, false))
- return pattern_ == host;
-
- const size_t match =
- host.rfind(pattern_.substr(kDomainWildcardLength));
-
- return (match != std::string::npos) &&
- (match == 0 || host[match - 1] == '.') &&
- (match + pattern_.length() - kDomainWildcardLength == host.length());
-}
-
-std::string HostContentSettingsMap::Pattern::CanonicalizePattern() const {
- if (!IsValid()) {
- return "";
- }
-
- bool starts_with_wildcard = pattern_.length() > kDomainWildcardLength &&
- StartsWithASCII(pattern_, kDomainWildcard, false);
-
- const std::string host(starts_with_wildcard ?
- pattern_.substr(kDomainWildcardLength) : pattern_);
-
- std::string canonicalized_pattern =
- starts_with_wildcard ? kDomainWildcard : "";
-
- url_canon::CanonHostInfo host_info;
- canonicalized_pattern += net::CanonicalizeHost(host, &host_info);
-
- return canonicalized_pattern;
-}
-
HostContentSettingsMap::HostContentSettingsMap(Profile* profile)
: profile_(profile),
block_third_party_cookies_(false),
@@ -232,10 +153,10 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile)
// Verify preferences version.
if (!prefs->HasPrefPath(prefs::kContentSettingsVersion)) {
prefs->SetInteger(prefs::kContentSettingsVersion,
- kContentSettingsPatternVersion);
+ ContentSettingsPattern::kContentSettingsPatternVersion);
}
if (prefs->GetInteger(prefs::kContentSettingsVersion) >
- kContentSettingsPatternVersion) {
+ ContentSettingsPattern::kContentSettingsPatternVersion) {
LOG(ERROR) << "Unknown content settings version in preferences.";
return;
}
@@ -268,7 +189,7 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile)
void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterDictionaryPref(prefs::kDefaultContentSettings);
prefs->RegisterIntegerPref(prefs::kContentSettingsVersion,
- kContentSettingsPatternVersion);
+ ContentSettingsPattern::kContentSettingsPatternVersion);
prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns);
prefs->RegisterBooleanPref(prefs::kBlockThirdPartyCookies, false);
prefs->RegisterBooleanPref(prefs::kBlockNonsandboxedPlugins, false);
@@ -364,7 +285,8 @@ ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting(
}
// Match patterns starting with the most concrete pattern match.
- for (std::string key = std::string(kDomainWildcard) + host; ; ) {
+ for (std::string key =
+ std::string(ContentSettingsPattern::kDomainWildcard) + host; ; ) {
HostContentSettings::const_iterator i(off_the_record_settings_.find(key));
if (i != off_the_record_settings_.end() &&
i->second.content_settings_for_resources.find(requested_setting) !=
@@ -381,10 +303,12 @@ ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting(
requested_setting)->second;
}
- const size_t next_dot = key.find('.', kDomainWildcardLength);
+ const size_t next_dot =
+ key.find('.', ContentSettingsPattern::kDomainWildcardLength);
if (next_dot == std::string::npos)
break;
- key.erase(kDomainWildcardLength, next_dot - kDomainWildcardLength + 1);
+ key.erase(ContentSettingsPattern::kDomainWildcardLength,
+ next_dot - ContentSettingsPattern::kDomainWildcardLength + 1);
}
return CONTENT_SETTING_DEFAULT;
@@ -444,7 +368,8 @@ ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings(
}
// Match patterns starting with the most concrete pattern match.
- for (std::string key = std::string(kDomainWildcard) + host; ; ) {
+ for (std::string key =
+ std::string(ContentSettingsPattern::kDomainWildcard) + host; ; ) {
HostContentSettings::const_iterator i(off_the_record_settings_.find(key));
if (i != off_the_record_settings_.end()) {
for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) {
@@ -459,10 +384,12 @@ ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings(
output.settings[j] = i->second.content_settings.settings[j];
}
}
- const size_t next_dot = key.find('.', kDomainWildcardLength);
+ const size_t next_dot =
+ key.find('.', ContentSettingsPattern::kDomainWildcardLength);
if (next_dot == std::string::npos)
break;
- key.erase(kDomainWildcardLength, next_dot - kDomainWildcardLength + 1);
+ key.erase(ContentSettingsPattern::kDomainWildcardLength,
+ next_dot - ContentSettingsPattern::kDomainWildcardLength + 1);
}
return output;
@@ -499,7 +426,8 @@ void HostContentSettingsMap::GetSettingsForOneType(
if (setting != CONTENT_SETTING_DEFAULT) {
// Use of push_back() relies on the map iterator traversing in order of
// ascending keys.
- settings->push_back(std::make_pair(Pattern(i->first), setting));
+ settings->push_back(
+ std::make_pair(ContentSettingsPattern(i->first), setting));
}
}
}
@@ -543,11 +471,12 @@ void HostContentSettingsMap::SetDefaultContentSetting(
}
updating_preferences_ = false;
- NotifyObservers(ContentSettingsDetails(Pattern(), content_type, ""));
+ NotifyObservers(
+ ContentSettingsDetails(ContentSettingsPattern(), content_type, ""));
}
void HostContentSettingsMap::SetContentSetting(
- const Pattern& original_pattern,
+ const ContentSettingsPattern& original_pattern,
ContentSettingsType content_type,
const std::string& resource_identifier,
ContentSetting setting) {
@@ -560,7 +489,7 @@ void HostContentSettingsMap::SetContentSetting(
CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableClickToPlay));
- const Pattern pattern(original_pattern.CanonicalizePattern());
+ const ContentSettingsPattern pattern(original_pattern.CanonicalizePattern());
bool early_exit = false;
std::string pattern_str(pattern.AsString());
@@ -659,11 +588,11 @@ void HostContentSettingsMap::AddExceptionForURL(
ContentSetting setting) {
// Make sure there is no entry that would override the pattern we are about
// to insert for exactly this URL.
- SetContentSetting(Pattern::FromURLNoWildcard(url),
+ SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(url),
content_type,
resource_identifier,
CONTENT_SETTING_DEFAULT);
- SetContentSetting(Pattern::FromURL(url),
+ SetContentSetting(ContentSettingsPattern::FromURL(url),
content_type,
resource_identifier,
setting);
@@ -722,7 +651,8 @@ void HostContentSettingsMap::ClearSettingsForOneType(
ScopedPrefUpdate update(prefs, prefs::kContentSettingsPatterns);
updating_preferences_ = false;
- NotifyObservers(ContentSettingsDetails(Pattern(), content_type, ""));
+ NotifyObservers(
+ ContentSettingsDetails(ContentSettingsPattern(), content_type, ""));
}
bool HostContentSettingsMap::RequiresResourceIdentifier(
@@ -820,8 +750,9 @@ void HostContentSettingsMap::ResetToDefaults() {
prefs->ClearPref(prefs::kBlockThirdPartyCookies);
prefs->ClearPref(prefs::kBlockNonsandboxedPlugins);
updating_preferences_ = false;
- NotifyObservers(
- ContentSettingsDetails(Pattern(), CONTENT_SETTINGS_TYPE_DEFAULT, ""));
+ NotifyObservers(ContentSettingsDetails(ContentSettingsPattern(),
+ CONTENT_SETTINGS_TYPE_DEFAULT,
+ ""));
}
}
@@ -876,8 +807,9 @@ void HostContentSettingsMap::Observe(NotificationType type,
}
if (!is_off_the_record_) {
- NotifyObservers(
- ContentSettingsDetails(Pattern(), CONTENT_SETTINGS_TYPE_DEFAULT, ""));
+ NotifyObservers(ContentSettingsDetails(ContentSettingsPattern(),
+ CONTENT_SETTINGS_TYPE_DEFAULT,
+ ""));
}
} else if (NotificationType::PROFILE_DESTROYED == type) {
UnregisterObservers();
@@ -1041,7 +973,7 @@ void HostContentSettingsMap::ReadExceptions(bool overwrite) {
for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys());
i != all_settings_dictionary->end_keys(); ++i) {
const std::string& pattern(*i);
- if (!Pattern(pattern).IsValid())
+ if (!ContentSettingsPattern(pattern).IsValid())
LOG(WARNING) << "Invalid pattern stored in content settings";
DictionaryValue* pattern_settings_dictionary = NULL;
bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion(
@@ -1099,7 +1031,9 @@ void HostContentSettingsMap::MigrateObsoletePopupsPref(PrefService* prefs) {
i != whitelist_pref->end(); ++i) {
std::string host;
(*i)->GetAsString(&host);
- SetContentSetting(Pattern(host), CONTENT_SETTINGS_TYPE_POPUPS, "",
+ SetContentSetting(ContentSettingsPattern(host),
+ CONTENT_SETTINGS_TYPE_POPUPS,
+ "",
CONTENT_SETTING_ALLOW);
}
prefs->ClearPref(prefs::kPopupWhitelistedHosts);
@@ -1113,7 +1047,8 @@ void HostContentSettingsMap::MigrateObsoletePerhostPref(PrefService* prefs) {
for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys());
i != all_settings_dictionary->end_keys(); ++i) {
const std::string& host(*i);
- Pattern pattern(std::string(kDomainWildcard) + host);
+ ContentSettingsPattern pattern(
+ std::string(ContentSettingsPattern::kDomainWildcard) + host);
DictionaryValue* host_settings_dictionary = NULL;
bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion(
host, &host_settings_dictionary);
@@ -1141,7 +1076,7 @@ void HostContentSettingsMap::CanonicalizeContentSettingsExceptions(
i != all_settings_dictionary->end_keys(); ++i) {
const std::string& pattern(*i);
const std::string canonicalized_pattern =
- Pattern(pattern).CanonicalizePattern();
+ ContentSettingsPattern(pattern).CanonicalizePattern();
if (canonicalized_pattern.empty() || canonicalized_pattern == pattern)
continue;
diff --git a/chrome/browser/content_settings/host_content_settings_map.h b/chrome/browser/content_settings/host_content_settings_map.h
index 9f52582..e19c125 100644
--- a/chrome/browser/content_settings/host_content_settings_map.h
+++ b/chrome/browser/content_settings/host_content_settings_map.h
@@ -18,11 +18,13 @@
#include "base/lock.h"
#include "base/ref_counted.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/content_settings/content_settings_pattern.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"
+class ContentSettingsDetails;
class DictionaryValue;
class GURL;
class PrefService;
@@ -33,86 +35,7 @@ class HostContentSettingsMap
public base::RefCountedThreadSafe<HostContentSettingsMap,
BrowserThread::DeleteOnUIThread> {
public:
- // A hostname pattern. See |IsValid| for a description of possible patterns.
- class Pattern {
- public:
- // Returns a pattern that matches the host of this URL and all subdomains.
- static Pattern FromURL(const GURL& url);
-
- // Returns a pattern that matches exactly this URL.
- static Pattern FromURLNoWildcard(const GURL& url);
-
- Pattern() {}
-
- explicit Pattern(const std::string& pattern) : pattern_(pattern) {}
-
- // True if this is a valid pattern. Valid patterns are
- // - [*.]domain.tld (matches domain.tld and all sub-domains)
- // - host (matches an exact hostname)
- // - a.b.c.d (matches an exact IPv4 ip)
- // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip)
- bool IsValid() const;
-
- // True if |url| matches this pattern.
- bool Matches(const GURL& url) const;
-
- // Returns a std::string representation of this pattern.
- const std::string& AsString() const { return pattern_; }
-
- bool operator==(const Pattern& other) const {
- return pattern_ == other.pattern_;
- }
-
- // Canonicalizes the pattern so that it's ASCII only, either
- // in original or punycode form.
- std::string CanonicalizePattern() const;
-
- private:
- std::string pattern_;
- };
-
- // Details for the CONTENT_SETTINGS_CHANGED notification. This is sent when
- // content settings change for at least one host. If settings change for more
- // than one pattern in one user interaction, this will usually send a single
- // notification with update_all() returning true instead of one notification
- // for each pattern.
- class ContentSettingsDetails {
- public:
- // Update the setting that matches this pattern/content type/resource.
- ContentSettingsDetails(const Pattern& pattern,
- ContentSettingsType type,
- const std::string& resource_identifier)
- : pattern_(pattern),
- type_(type),
- resource_identifier_(resource_identifier) {}
-
- // The pattern whose settings have changed.
- const Pattern& pattern() const { return pattern_; }
-
- // True if all settings should be updated for the given type.
- bool update_all() const { return pattern_.AsString().empty(); }
-
- // The type of the pattern whose settings have changed.
- ContentSettingsType type() const { return type_; }
-
- // The resource identifier for the settings type that has changed.
- const std::string& resource_identifier() const {
- return resource_identifier_;
- }
-
- // True if all types should be updated. If update_all() is false, this will
- // be false as well (although the reverse does not hold true).
- bool update_all_types() const {
- return CONTENT_SETTINGS_TYPE_DEFAULT == type_;
- }
-
- private:
- Pattern pattern_;
- ContentSettingsType type_;
- std::string resource_identifier_;
- };
-
- typedef std::pair<Pattern, ContentSetting> PatternSettingPair;
+ typedef std::pair<ContentSettingsPattern, ContentSetting> PatternSettingPair;
typedef std::vector<PatternSettingPair> SettingsForOneType;
explicit HostContentSettingsMap(Profile* profile);
@@ -189,7 +112,7 @@ class HostContentSettingsMap
// the |resource_identifier| must be non-empty.
//
// This should only be called on the UI thread.
- void SetContentSetting(const Pattern& pattern,
+ void SetContentSetting(const ContentSettingsPattern& pattern,
ContentSettingsType content_type,
const std::string& resource_identifier,
ContentSetting setting);
@@ -344,11 +267,4 @@ class HostContentSettingsMap
DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap);
};
-// Stream operator so HostContentSettingsMap::Pattern can be used in
-// assertion statements.
-inline std::ostream& operator<<(
- std::ostream& out, const HostContentSettingsMap::Pattern& pattern) {
- return out << pattern.AsString();
-}
-
#endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_
diff --git a/chrome/browser/content_settings/host_content_settings_map_unittest.cc b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
index 5f6bf5c..280799b 100644
--- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc
+++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
+#include "chrome/browser/content_settings/content_settings_details.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_registrar.h"
@@ -44,8 +45,7 @@ class StubSettingsObserver : public NotificationObserver {
const NotificationDetails& details) {
++counter;
Source<HostContentSettingsMap> content_settings(source);
- Details<HostContentSettingsMap::ContentSettingsDetails>
- settings_details(details);
+ Details<ContentSettingsDetails> settings_details(details);
last_notifier = content_settings.ptr();
last_pattern = settings_details.ptr()->pattern();
last_update_all = settings_details.ptr()->update_all();
@@ -57,7 +57,7 @@ class StubSettingsObserver : public NotificationObserver {
}
HostContentSettingsMap* last_notifier;
- HostContentSettingsMap::Pattern last_pattern;
+ ContentSettingsPattern last_pattern;
bool last_update_all;
bool last_update_all_types;
int counter;
@@ -118,7 +118,7 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) {
// Check returning individual settings.
GURL host("http://example.com/");
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
@@ -163,7 +163,7 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) {
EXPECT_TRUE(SettingsEqual(desired_settings, settings));
// Check returning all hosts for a setting.
- HostContentSettingsMap::Pattern pattern2("[*.]example.org");
+ ContentSettingsPattern pattern2("[*.]example.org");
host_content_settings_map->SetContentSetting(pattern2,
CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK);
host_content_settings_map->SetContentSetting(pattern2,
@@ -186,7 +186,7 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) {
EXPECT_EQ(0U, host_settings.size());
// Check clearing one type.
- HostContentSettingsMap::Pattern pattern3("[*.]example.net");
+ ContentSettingsPattern pattern3("[*.]example.net");
host_content_settings_map->SetContentSetting(pattern,
CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK);
host_content_settings_map->SetContentSetting(pattern2,
@@ -214,8 +214,8 @@ TEST_F(HostContentSettingsMapTest, Patterns) {
GURL host1("http://example.com/");
GURL host2("http://www.example.com/");
GURL host3("http://example.org/");
- HostContentSettingsMap::Pattern pattern1("[*.]example.com");
- HostContentSettingsMap::Pattern pattern2("example.org");
+ ContentSettingsPattern pattern1("[*.]example.com");
+ ContentSettingsPattern pattern2("example.org");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host1, CONTENT_SETTINGS_TYPE_IMAGES, ""));
@@ -237,70 +237,13 @@ TEST_F(HostContentSettingsMapTest, Patterns) {
host3, CONTENT_SETTINGS_TYPE_IMAGES, ""));
}
-TEST_F(HostContentSettingsMapTest, PatternSupport) {
- EXPECT_TRUE(HostContentSettingsMap::Pattern("[*.]example.com").IsValid());
- EXPECT_TRUE(HostContentSettingsMap::Pattern("example.com").IsValid());
- EXPECT_TRUE(HostContentSettingsMap::Pattern("192.168.0.1").IsValid());
- EXPECT_TRUE(HostContentSettingsMap::Pattern("[::1]").IsValid());
- EXPECT_FALSE(HostContentSettingsMap::Pattern("*example.com").IsValid());
- EXPECT_FALSE(HostContentSettingsMap::Pattern("example.*").IsValid());
- EXPECT_FALSE(HostContentSettingsMap::Pattern("http://example.com").IsValid());
-
- EXPECT_TRUE(HostContentSettingsMap::Pattern("[*.]example.com").Matches(
- GURL("http://example.com/")));
- EXPECT_TRUE(HostContentSettingsMap::Pattern("[*.]example.com").Matches(
- GURL("http://www.example.com/")));
- EXPECT_TRUE(HostContentSettingsMap::Pattern("www.example.com").Matches(
- GURL("http://www.example.com/")));
- EXPECT_FALSE(HostContentSettingsMap::Pattern("").Matches(
- GURL("http://www.example.com/")));
- EXPECT_FALSE(HostContentSettingsMap::Pattern("[*.]example.com").Matches(
- GURL("http://example.org/")));
- EXPECT_FALSE(HostContentSettingsMap::Pattern("example.com").Matches(
- GURL("http://example.org/")));
-}
-
-TEST_F(HostContentSettingsMapTest, CanonicalizePattern) {
- // Basic patterns.
- EXPECT_STREQ("[*.]ikea.com", HostContentSettingsMap::Pattern("[*.]ikea.com")
- .CanonicalizePattern().c_str());
- EXPECT_STREQ("example.com", HostContentSettingsMap::Pattern("example.com")
- .CanonicalizePattern().c_str());
- EXPECT_STREQ("192.168.1.1", HostContentSettingsMap::Pattern("192.168.1.1")
- .CanonicalizePattern().c_str());
- EXPECT_STREQ("[::1]", HostContentSettingsMap::Pattern("[::1]")
- .CanonicalizePattern().c_str());
- // IsValid returns false for file:/// patterns.
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "file:///temp/file.html").CanonicalizePattern().c_str());
-
- // UTF-8 patterns.
- EXPECT_STREQ("[*.]xn--ira-ppa.com", HostContentSettingsMap::Pattern(
- "[*.]\xC4\x87ira.com").CanonicalizePattern().c_str());
- EXPECT_STREQ("xn--ira-ppa.com", HostContentSettingsMap::Pattern(
- "\xC4\x87ira.com").CanonicalizePattern().c_str());
- // IsValid returns false for file:/// patterns.
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "file:///\xC4\x87ira.html").CanonicalizePattern().c_str());
-
- // Invalid patterns.
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "*example.com").CanonicalizePattern().c_str());
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "example.*").CanonicalizePattern().c_str());
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "*\xC4\x87ira.com").CanonicalizePattern().c_str());
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "\xC4\x87ira.*").CanonicalizePattern().c_str());
-}
-
TEST_F(HostContentSettingsMapTest, Observer) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
StubSettingsObserver observer;
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
host_content_settings_map->SetContentSetting(pattern,
CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_ALLOW);
EXPECT_EQ(host_content_settings_map, observer.last_notifier);
@@ -377,7 +320,7 @@ TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
scoped_ptr<Value> default_value(prefs->FindPreference(
prefs::kContentSettingsPatterns)->GetValue()->DeepCopy());
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
GURL host("http://example.com");
host_content_settings_map->SetContentSetting(pattern,
@@ -408,7 +351,7 @@ TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
GURL host_ending_with_dot("http://example.com./");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
@@ -488,9 +431,9 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) {
profile.GetHostContentSettingsMap();
GURL host("http://a.b.example.com/");
- HostContentSettingsMap::Pattern pattern1("[*.]example.com");
- HostContentSettingsMap::Pattern pattern2("[*.]b.example.com");
- HostContentSettingsMap::Pattern pattern3("a.b.example.com");
+ ContentSettingsPattern pattern1("[*.]example.com");
+ ContentSettingsPattern pattern2("[*.]b.example.com");
+ ContentSettingsPattern pattern3("a.b.example.com");
host_content_settings_map->SetContentSetting(pattern1,
CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK);
@@ -543,7 +486,7 @@ TEST_F(HostContentSettingsMapTest, OffTheRecord) {
profile.set_off_the_record(false);
GURL host("http://example.com/");
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
@@ -666,7 +609,7 @@ TEST_F(HostContentSettingsMapTest, NonDefaultSettings) {
profile.GetHostContentSettingsMap();
GURL host("http://example.com/");
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
ContentSettings desired_settings(CONTENT_SETTING_DEFAULT);
ContentSettings settings =
@@ -693,7 +636,7 @@ TEST_F(HostContentSettingsMapTest, ResourceIdentifier) {
profile.GetHostContentSettingsMap();
GURL host("http://example.com/");
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
std::string resource1("someplugin");
std::string resource2("otherplugin");
@@ -724,7 +667,7 @@ TEST_F(HostContentSettingsMapTest, ResourceIdentifierPrefs) {
profile.GetHostContentSettingsMap();
GURL host("http://example.com/");
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
std::string resource1("someplugin");
std::string resource2("otherplugin");
@@ -798,7 +741,7 @@ TEST_F(HostContentSettingsMapTest,
TestingPrefService* prefs = profile.GetTestingPrefService();
// Set pattern for JavaScript setting.
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
host_content_settings_map->SetContentSetting(pattern,
CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_BLOCK);
@@ -833,7 +776,7 @@ TEST_F(HostContentSettingsMapTest,
CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
// Set an exception to allow "[*.]example.com"
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
host_content_settings_map->SetContentSetting(pattern,
CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_ALLOW);
@@ -905,7 +848,7 @@ TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsChange) {
prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting,
Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(host_content_settings_map, observer.last_notifier);
- EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern);
EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
EXPECT_TRUE(observer.last_update_all);
EXPECT_TRUE(observer.last_update_all_types);
@@ -915,7 +858,7 @@ TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsChange) {
prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting);
EXPECT_EQ(host_content_settings_map, observer.last_notifier);
EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
- EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern);
EXPECT_TRUE(observer.last_update_all);
EXPECT_TRUE(observer.last_update_all_types);
EXPECT_EQ(2, observer.counter);
@@ -941,7 +884,7 @@ TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsNoChange) {
prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting,
Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
EXPECT_EQ(host_content_settings_map, observer.last_notifier);
- EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern);
EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
EXPECT_TRUE(observer.last_update_all);
EXPECT_TRUE(observer.last_update_all_types);
@@ -951,7 +894,7 @@ TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsNoChange) {
prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting);
EXPECT_EQ(host_content_settings_map, observer.last_notifier);
EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
- EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern);
EXPECT_TRUE(observer.last_update_all);
EXPECT_TRUE(observer.last_update_all_types);
EXPECT_EQ(2, observer.counter);
diff --git a/chrome/browser/cookies_tree_model_unittest.cc b/chrome/browser/cookies_tree_model_unittest.cc
index b20329b..12c3e1a 100644
--- a/chrome/browser/cookies_tree_model_unittest.cc
+++ b/chrome/browser/cookies_tree_model_unittest.cc
@@ -6,6 +6,7 @@
#include <string>
+#include "chrome/browser/content_settings/content_settings_details.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/mock_browsing_data_appcache_helper.h"
#include "chrome/browser/mock_browsing_data_database_helper.h"
@@ -33,12 +34,11 @@ class StubSettingsObserver : public NotificationObserver {
const NotificationSource& source,
const NotificationDetails& details) {
++counter;
- Details<HostContentSettingsMap::ContentSettingsDetails>
- settings_details(details);
+ Details<ContentSettingsDetails> settings_details(details);
last_pattern = settings_details.ptr()->pattern();
}
- HostContentSettingsMap::Pattern last_pattern;
+ ContentSettingsPattern last_pattern;
int counter;
private:
@@ -670,7 +670,7 @@ TEST_F(CookiesTreeModelTest, OriginOrdering) {
TEST_F(CookiesTreeModelTest, ContentSettings) {
GURL host("http://example.com/");
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
net::CookieMonster* monster = profile_->GetCookieMonster();
monster->SetCookie(host, "A=1");
diff --git a/chrome/browser/dom_ui/options/content_settings_handler.cc b/chrome/browser/dom_ui/options/content_settings_handler.cc
index d640869..fa53ab7 100644
--- a/chrome/browser/dom_ui/options/content_settings_handler.cc
+++ b/chrome/browser/dom_ui/options/content_settings_handler.cc
@@ -10,6 +10,7 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_list.h"
+#include "chrome/browser/content_settings/content_settings_details.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
@@ -24,8 +25,6 @@
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
-typedef HostContentSettingsMap::ContentSettingsDetails ContentSettingsDetails;
-
namespace {
const char* kDisplayPattern = "displayPattern";
@@ -112,7 +111,7 @@ std::string GeolocationExceptionToString(const GURL& origin,
// in a HostContentSettingsMap-controlled exceptions table (e.g., cookies).
// Ownership of the pointer is passed to the caller.
DictionaryValue* GetExceptionForPage(
- const HostContentSettingsMap::Pattern pattern,
+ const ContentSettingsPattern pattern,
ContentSetting setting) {
DictionaryValue* exception = new DictionaryValue();
exception->Set(
@@ -330,7 +329,7 @@ void ContentSettingsHandler::Observe(NotificationType type,
case NotificationType::CONTENT_SETTINGS_CHANGED: {
const ContentSettingsDetails* settings_details =
- static_cast<Details<const ContentSettingsDetails> >(details).ptr();
+ Details<const ContentSettingsDetails>(details).ptr();
// TODO(estade): we pretend update_all() is always true.
if (settings_details->update_all_types())
@@ -633,7 +632,7 @@ void ContentSettingsHandler::RemoveExceptions(const ListValue* args) {
// got destroyed before we received this message.
if (settings_map) {
settings_map->SetContentSetting(
- HostContentSettingsMap::Pattern(pattern),
+ ContentSettingsPattern(pattern),
ContentSettingsTypeFromGroupName(type_string),
"",
CONTENT_SETTING_DEFAULT);
@@ -669,11 +668,10 @@ void ContentSettingsHandler::SetException(const ListValue* args) {
if (!settings_map)
return;
- settings_map->
- SetContentSetting(HostContentSettingsMap::Pattern(pattern),
- type,
- "",
- ContentSettingFromString(setting));
+ settings_map->SetContentSetting(ContentSettingsPattern(pattern),
+ type,
+ "",
+ ContentSettingFromString(setting));
}
void ContentSettingsHandler::CheckExceptionPatternValidity(
@@ -686,7 +684,7 @@ void ContentSettingsHandler::CheckExceptionPatternValidity(
std::string pattern_string;
CHECK(args->GetString(arg_i++, &pattern_string));
- HostContentSettingsMap::Pattern pattern(pattern_string);
+ ContentSettingsPattern pattern(pattern_string);
scoped_ptr<Value> mode_value(Value::CreateStringValue(mode_string));
scoped_ptr<Value> pattern_value(Value::CreateStringValue(pattern_string));
diff --git a/chrome/browser/gtk/options/content_exception_editor.cc b/chrome/browser/gtk/options/content_exception_editor.cc
index 144bf84..5f8aa69 100644
--- a/chrome/browser/gtk/options/content_exception_editor.cc
+++ b/chrome/browser/gtk/options/content_exception_editor.cc
@@ -21,7 +21,7 @@ ContentExceptionEditor::ContentExceptionEditor(
ContentExceptionsTableModel* model,
bool allow_off_the_record,
int index,
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
ContentSetting setting,
bool is_off_the_record)
: delegate_(delegate),
@@ -91,7 +91,7 @@ ContentExceptionEditor::ContentExceptionEditor(
}
bool ContentExceptionEditor::IsPatternValid(
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
bool is_off_the_record) const {
bool is_valid_pattern = pattern.IsValid() &&
(model_->IndexOfExceptionByPattern(pattern, is_off_the_record) == -1);
@@ -107,8 +107,7 @@ void ContentExceptionEditor::UpdateImage(GtkWidget* image, bool is_valid) {
}
void ContentExceptionEditor::OnEntryChanged(GtkWidget* entry) {
- HostContentSettingsMap::Pattern new_pattern(
- gtk_entry_get_text(GTK_ENTRY(entry)));
+ ContentSettingsPattern new_pattern(gtk_entry_get_text(GTK_ENTRY(entry)));
bool is_off_the_record =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(otr_checkbox_));
bool is_valid = IsPatternValid(new_pattern, is_off_the_record);
@@ -120,8 +119,7 @@ void ContentExceptionEditor::OnEntryChanged(GtkWidget* entry) {
void ContentExceptionEditor::OnResponse(GtkWidget* sender, int response_id) {
if (response_id == GTK_RESPONSE_OK) {
// Notify our delegate to update everything.
- HostContentSettingsMap::Pattern new_pattern(
- gtk_entry_get_text(GTK_ENTRY(entry_)));
+ ContentSettingsPattern new_pattern(gtk_entry_get_text(GTK_ENTRY(entry_)));
ContentSetting setting = cb_model_.SettingForIndex(
gtk_combo_box_get_active(GTK_COMBO_BOX(action_combo_)));
bool is_off_the_record =
diff --git a/chrome/browser/gtk/options/content_exception_editor.h b/chrome/browser/gtk/options/content_exception_editor.h
index fed69c0..4ed5ad3 100644
--- a/chrome/browser/gtk/options/content_exception_editor.h
+++ b/chrome/browser/gtk/options/content_exception_editor.h
@@ -23,7 +23,7 @@ class ContentExceptionEditor {
public:
// Invoked when the user accepts the edit.
virtual void AcceptExceptionEdit(
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
ContentSetting setting,
bool is_off_the_record,
int index,
@@ -38,7 +38,7 @@ class ContentExceptionEditor {
ContentExceptionsTableModel* model,
bool allow_off_the_record,
int index,
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
ContentSetting setting,
bool is_off_the_record);
virtual ~ContentExceptionEditor() {}
@@ -47,7 +47,7 @@ class ContentExceptionEditor {
// Returns true if we're adding a new item.
bool is_new() const { return index_ == -1; }
- bool IsPatternValid(const HostContentSettingsMap::Pattern& pattern,
+ bool IsPatternValid(const ContentSettingsPattern& pattern,
bool is_off_the_record) const;
void UpdateImage(GtkWidget* image, bool is_valid);
@@ -65,7 +65,7 @@ class ContentExceptionEditor {
// Index of the item being edited. If -1, indicates this is a new entry.
const int index_;
- const HostContentSettingsMap::Pattern pattern_;
+ const ContentSettingsPattern pattern_;
const ContentSetting setting_;
// UI widgets.
diff --git a/chrome/browser/gtk/options/content_exceptions_window_gtk.cc b/chrome/browser/gtk/options/content_exceptions_window_gtk.cc
index 5c8cdfd..6a1fc88 100644
--- a/chrome/browser/gtk/options/content_exceptions_window_gtk.cc
+++ b/chrome/browser/gtk/options/content_exceptions_window_gtk.cc
@@ -199,7 +199,7 @@ void ContentExceptionsWindowGtk::SetColumnValues(int row, GtkTreeIter* iter) {
}
void ContentExceptionsWindowGtk::AcceptExceptionEdit(
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
ContentSetting setting,
bool is_off_the_record,
int index,
@@ -235,7 +235,7 @@ void ContentExceptionsWindowGtk::UpdateButtonState() {
void ContentExceptionsWindowGtk::Add(GtkWidget* widget) {
new ContentExceptionEditor(GTK_WINDOW(dialog_),
this, model_.get(), allow_off_the_record_, -1,
- HostContentSettingsMap::Pattern(),
+ ContentSettingsPattern(),
CONTENT_SETTING_BLOCK, false);
}
diff --git a/chrome/browser/gtk/options/content_exceptions_window_gtk.h b/chrome/browser/gtk/options/content_exceptions_window_gtk.h
index 4779833..0f70c90 100644
--- a/chrome/browser/gtk/options/content_exceptions_window_gtk.h
+++ b/chrome/browser/gtk/options/content_exceptions_window_gtk.h
@@ -37,7 +37,7 @@ class ContentExceptionsWindowGtk : public gtk_tree::TableAdapter::Delegate,
// ContentExceptionEditor::Delegate implementation:
virtual void AcceptExceptionEdit(
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
ContentSetting setting,
bool is_off_the_record,
int index,
diff --git a/chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc b/chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc
index 764e991..8af7c55 100644
--- a/chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc
+++ b/chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc
@@ -26,7 +26,7 @@ class ContentExceptionsWindowGtkUnittest : public testing::Test {
void AddException(const std::string& pattern, ContentSetting value) {
host_content_settings_map_->SetContentSetting(
- HostContentSettingsMap::Pattern(pattern),
+ ContentSettingsPattern(pattern),
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
"",
value);
diff --git a/chrome/browser/gtk/options/content_filter_page_gtk.cc b/chrome/browser/gtk/options/content_filter_page_gtk.cc
index 21387a5..d9b06a9 100644
--- a/chrome/browser/gtk/options/content_filter_page_gtk.cc
+++ b/chrome/browser/gtk/options/content_filter_page_gtk.cc
@@ -6,6 +6,7 @@
#include "app/l10n_util.h"
#include "base/command_line.h"
+#include "chrome/browser/content_settings/content_settings_details.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"
@@ -278,14 +279,14 @@ void ContentFilterPageGtk::Observe(NotificationType type,
if (type == NotificationType::CONTENT_SETTINGS_CHANGED) {
NotifyContentSettingsChanged(
- Details<HostContentSettingsMap::ContentSettingsDetails>(details).ptr());
+ Details<const ContentSettingsDetails>(details).ptr());
} else {
OptionsPageBase::Observe(type, source, details);
}
}
void ContentFilterPageGtk::NotifyContentSettingsChanged(
- const HostContentSettingsMap::ContentSettingsDetails *details) {
+ const ContentSettingsDetails *details) {
if (details->type() == CONTENT_SETTINGS_TYPE_DEFAULT ||
details->type() == content_type_) {
ignore_toggle_ = true;
diff --git a/chrome/browser/gtk/options/content_filter_page_gtk.h b/chrome/browser/gtk/options/content_filter_page_gtk.h
index 6150226..3b7bdec 100644
--- a/chrome/browser/gtk/options/content_filter_page_gtk.h
+++ b/chrome/browser/gtk/options/content_filter_page_gtk.h
@@ -15,6 +15,8 @@
#include "chrome/common/content_settings_types.h"
#include "chrome/common/notification_registrar.h"
+class ContentSettingsDetails;
+
// A page in the content settings window. Used for everything but the Cookies
// page (which has a much more complex dialog). A |content_type| is passed into
// the constructor and the correct strings and settings are used.
@@ -38,7 +40,7 @@ class ContentFilterPageGtk : public OptionsPageBase {
virtual void UpdateButtonsState();
virtual void NotifyContentSettingsChanged(
- const HostContentSettingsMap::ContentSettingsDetails *details);
+ const ContentSettingsDetails* details);
// Builds the content of the dialog.
GtkWidget* InitGroup();
diff --git a/chrome/browser/plugin_exceptions_table_model.h b/chrome/browser/plugin_exceptions_table_model.h
index 37009a2..3a7c69a 100644
--- a/chrome/browser/plugin_exceptions_table_model.h
+++ b/chrome/browser/plugin_exceptions_table_model.h
@@ -55,7 +55,7 @@ class PluginExceptionsTableModel : public RemoveRowsTableModel,
friend class plugin_test_internal::PluginExceptionsTableModelTest;
struct SettingsEntry {
- HostContentSettingsMap::Pattern pattern;
+ ContentSettingsPattern pattern;
int plugin_id;
ContentSetting setting;
bool is_otr;
diff --git a/chrome/browser/plugin_exceptions_table_model_unittest.cc b/chrome/browser/plugin_exceptions_table_model_unittest.cc
index 813083c..61ffdad 100644
--- a/chrome/browser/plugin_exceptions_table_model_unittest.cc
+++ b/chrome/browser/plugin_exceptions_table_model_unittest.cc
@@ -65,8 +65,8 @@ class PluginExceptionsTableModelTest : public testing::Test {
HostContentSettingsMap* map = profile_->GetHostContentSettingsMap();
- HostContentSettingsMap::Pattern example_com("[*.]example.com");
- HostContentSettingsMap::Pattern moose_org("[*.]moose.org");
+ ContentSettingsPattern example_com("[*.]example.com");
+ ContentSettingsPattern moose_org("[*.]moose.org");
map->SetContentSetting(example_com,
CONTENT_SETTINGS_TYPE_PLUGINS,
"a-foo",
@@ -179,7 +179,7 @@ TEST_F(PluginExceptionsTableModelTest, RemoveLastRowInGroup) {
HostContentSettingsMap* map = profile_->GetHostContentSettingsMap();
EXPECT_CALL(observer, OnModelChanged());
- map->SetContentSetting(HostContentSettingsMap::Pattern("[*.]blurp.net"),
+ map->SetContentSetting(ContentSettingsPattern("[*.]blurp.net"),
CONTENT_SETTINGS_TYPE_PLUGINS,
"b-bar",
CONTENT_SETTING_BLOCK);
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 0c26578..fd60bb55 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -29,6 +29,7 @@
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/cert_store.h"
#include "chrome/browser/character_encoding.h"
+#include "chrome/browser/content_settings/content_settings_details.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/debugger/devtools_manager.h"
#include "chrome/browser/defaults.h"
@@ -3138,8 +3139,7 @@ void TabContents::Observe(NotificationType type,
break;
case NotificationType::CONTENT_SETTINGS_CHANGED: {
- Details<const HostContentSettingsMap::ContentSettingsDetails>
- settings_details(details);
+ Details<const ContentSettingsDetails> settings_details(details);
NavigationEntry* entry = controller_.GetActiveEntry();
GURL entry_url;
if (entry)
diff --git a/chrome/browser/ui/cocoa/content_exceptions_window_controller.mm b/chrome/browser/ui/cocoa/content_exceptions_window_controller.mm
index 1a6aa74..e9a426f6 100644
--- a/chrome/browser/ui/cocoa/content_exceptions_window_controller.mm
+++ b/chrome/browser/ui/cocoa/content_exceptions_window_controller.mm
@@ -49,7 +49,7 @@
forString:(NSString*)string
errorDescription:(NSString**)error {
if ([string length]) {
- if (HostContentSettingsMap::Pattern(
+ if (ContentSettingsPattern(
base::SysNSStringToUTF8(string)).IsValid()) {
*object = string;
return YES;
@@ -295,7 +295,7 @@ static ContentExceptionsWindowController*
return;
}
newException_.reset(new HostContentSettingsMap::PatternSettingPair);
- newException_->first = HostContentSettingsMap::Pattern(
+ newException_->first = ContentSettingsPattern(
l10n_util::GetStringUTF8(IDS_EXCEPTIONS_SAMPLE_PATTERN));
newException_->second = CONTENT_SETTING_BLOCK;
[tableView_ reloadData];
@@ -418,8 +418,7 @@ static ContentExceptionsWindowController*
// Modify it.
NSString* identifier = [tableColumn identifier];
if ([identifier isEqualToString:@"pattern"]) {
- entry.first = HostContentSettingsMap::Pattern(
- base::SysNSStringToUTF8(object));
+ entry.first = ContentSettingsPattern(base::SysNSStringToUTF8(object));
}
if ([identifier isEqualToString:@"action"]) {
int index = [object intValue];
diff --git a/chrome/browser/ui/cocoa/content_exceptions_window_controller_unittest.mm b/chrome/browser/ui/cocoa/content_exceptions_window_controller_unittest.mm
index 99dfb9d..d42e171 100644
--- a/chrome/browser/ui/cocoa/content_exceptions_window_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/content_exceptions_window_controller_unittest.mm
@@ -160,7 +160,7 @@ TEST_F(ContentExceptionsWindowControllerTest, Add) {
"",
&settings);
EXPECT_EQ(1u, settings.size());
- EXPECT_EQ(HostContentSettingsMap::Pattern("addedhost"), settings[0].first);
+ EXPECT_EQ(ContentSettingsPattern("addedhost"), settings[0].first);
}
TEST_F(ContentExceptionsWindowControllerTest, AddEscDoesNotAdd) {
@@ -202,7 +202,7 @@ TEST_F(ContentExceptionsWindowControllerTest, AddEditAddAdd) {
}
TEST_F(ContentExceptionsWindowControllerTest, AddExistingEditAdd) {
- settingsMap_->SetContentSetting(HostContentSettingsMap::Pattern("myhost"),
+ settingsMap_->SetContentSetting(ContentSettingsPattern("myhost"),
CONTENT_SETTINGS_TYPE_PLUGINS,
"",
CONTENT_SETTING_BLOCK);
@@ -226,7 +226,7 @@ TEST_F(ContentExceptionsWindowControllerTest, AddExistingEditAdd) {
}
TEST_F(ContentExceptionsWindowControllerTest, AddExistingDoesNotOverwrite) {
- settingsMap_->SetContentSetting(HostContentSettingsMap::Pattern("myhost"),
+ settingsMap_->SetContentSetting(ContentSettingsPattern("myhost"),
CONTENT_SETTINGS_TYPE_COOKIES,
"",
CONTENT_SETTING_SESSION_ONLY);
diff --git a/chrome/browser/ui/cocoa/content_settings_dialog_controller.mm b/chrome/browser/ui/cocoa/content_settings_dialog_controller.mm
index 7a574d0..855dc3a 100644
--- a/chrome/browser/ui/cocoa/content_settings_dialog_controller.mm
+++ b/chrome/browser/ui/cocoa/content_settings_dialog_controller.mm
@@ -9,6 +9,7 @@
#include "app/l10n_util.h"
#include "base/command_line.h"
#include "base/mac_util.h"
+#import "chrome/browser/content_settings/content_settings_details.h"
#import "chrome/browser/content_settings/host_content_settings_map.h"
#import "chrome/browser/geolocation/geolocation_content_settings_map.h"
#import "chrome/browser/geolocation/geolocation_exceptions_table_model.h"
@@ -49,8 +50,7 @@ ContentSettingsDialogController* g_instance = nil;
- (void)prefChanged:(const std::string&)prefName;
// Callback when content settings are changed.
-- (void)contentSettingsChanged:
- (HostContentSettingsMap::ContentSettingsDetails*)details;
+- (void)contentSettingsChanged:(ContentSettingsDetails*)details;
@end
@@ -80,8 +80,8 @@ class PrefObserverBridge : public NotificationObserver {
// This is sent when the "is managed" state changes.
// TODO(markusheintz): Move all content settings to this notification.
if (type == NotificationType::CONTENT_SETTINGS_CHANGED) {
- HostContentSettingsMap::ContentSettingsDetails* settings_details =
- Details<HostContentSettingsMap::ContentSettingsDetails>(details).ptr();
+ ContentSettingsDetails* settings_details =
+ Details<ContentSettingsDetails>(details).ptr();
[controller_ contentSettingsChanged:settings_details];
}
}
@@ -638,8 +638,7 @@ class PrefObserverDisabler {
}
}
-- (void)contentSettingsChanged:
- (HostContentSettingsMap::ContentSettingsDetails*)details {
+- (void)contentSettingsChanged:(ContentSettingsDetails*)details {
[self prefChanged:prefs::kBlockNonsandboxedPlugins];
[self prefChanged:prefs::kDefaultContentSettings];
}
diff --git a/chrome/browser/ui/cocoa/table_model_array_controller_unittest.mm b/chrome/browser/ui/cocoa/table_model_array_controller_unittest.mm
index c60c4cf..65b901f 100644
--- a/chrome/browser/ui/cocoa/table_model_array_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/table_model_array_controller_unittest.mm
@@ -35,8 +35,8 @@ class TableModelArrayControllerTest : public CocoaTest {
TestingProfile* profile = browser_helper_.profile();
HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
- HostContentSettingsMap::Pattern example_com("[*.]example.com");
- HostContentSettingsMap::Pattern moose_org("[*.]moose.org");
+ ContentSettingsPattern example_com("[*.]example.com");
+ ContentSettingsPattern moose_org("[*.]moose.org");
map->SetContentSetting(example_com,
CONTENT_SETTINGS_TYPE_PLUGINS,
"a-foo",
@@ -138,7 +138,7 @@ TEST_F(TableModelArrayControllerTest, RemoveAll) {
TEST_F(TableModelArrayControllerTest, AddException) {
TestingProfile* profile = browser_helper_.profile();
HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
- HostContentSettingsMap::Pattern example_com("[*.]example.com");
+ ContentSettingsPattern example_com("[*.]example.com");
map->SetContentSetting(example_com,
CONTENT_SETTINGS_TYPE_PLUGINS,
"c-blurp",
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 320611d..ebceafa 100644
--- a/chrome/browser/ui/views/options/content_filter_page_view.cc
+++ b/chrome/browser/ui/views/options/content_filter_page_view.cc
@@ -6,6 +6,7 @@
#include "app/l10n_util.h"
#include "base/command_line.h"
+#include "chrome/browser/content_settings/content_settings_details.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/geolocation/geolocation_exceptions_table_model.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
@@ -253,7 +254,7 @@ void ContentFilterPageView::ButtonPressed(views::Button* sender,
}
void ContentFilterPageView::NotifyContentSettingsChanged(
- const HostContentSettingsMap::ContentSettingsDetails *details) {
+ const ContentSettingsDetails* details) {
if (details->type() == CONTENT_SETTINGS_TYPE_DEFAULT ||
details->type() == content_type_) {
UpdateView();
@@ -265,8 +266,7 @@ void ContentFilterPageView::Observe(NotificationType type,
const NotificationDetails& details) {
if (type == NotificationType::CONTENT_SETTINGS_CHANGED) {
NotifyContentSettingsChanged(
- Details<HostContentSettingsMap::ContentSettingsDetails>
- (details).ptr());
+ Details<ContentSettingsDetails>(details).ptr());
} else {
OptionsPageBase::Observe(type, source, details);
}
diff --git a/chrome/browser/ui/views/options/content_filter_page_view.h b/chrome/browser/ui/views/options/content_filter_page_view.h
index a9f09e1..5f23583 100644
--- a/chrome/browser/ui/views/options/content_filter_page_view.h
+++ b/chrome/browser/ui/views/options/content_filter_page_view.h
@@ -39,7 +39,7 @@ class ContentFilterPageView : public OptionsPageView,
virtual void UpdateView();
virtual void NotifyContentSettingsChanged(
- const HostContentSettingsMap::ContentSettingsDetails *details);
+ const ContentSettingsDetails* details);
// OptionsPageView implementation:
virtual void InitControlLayout();
diff --git a/chrome/browser/ui/views/options/exception_editor_view.cc b/chrome/browser/ui/views/options/exception_editor_view.cc
index 93ca859..7b111d8 100644
--- a/chrome/browser/ui/views/options/exception_editor_view.cc
+++ b/chrome/browser/ui/views/options/exception_editor_view.cc
@@ -24,7 +24,7 @@ ExceptionEditorView::ExceptionEditorView(
ContentExceptionsTableModel* model,
bool allow_off_the_record,
int index,
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
ContentSetting setting,
bool is_off_the_record)
: delegate_(delegate),
@@ -63,7 +63,7 @@ std::wstring ExceptionEditorView::GetWindowTitle() const {
bool ExceptionEditorView::IsDialogButtonEnabled(
MessageBoxFlags::DialogButton button) const {
if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
- return IsPatternValid(HostContentSettingsMap::Pattern(
+ return IsPatternValid(ContentSettingsPattern(
UTF16ToUTF8(pattern_tf_->text())),
incognito_cb_->checked());
}
@@ -75,7 +75,7 @@ bool ExceptionEditorView::Cancel() {
}
bool ExceptionEditorView::Accept() {
- HostContentSettingsMap::Pattern new_pattern(UTF16ToUTF8(pattern_tf_->text()));
+ ContentSettingsPattern new_pattern(UTF16ToUTF8(pattern_tf_->text()));
ContentSetting setting =
cb_model_.SettingForIndex(action_cb_->selected_item());
bool is_off_the_record = incognito_cb_->checked();
@@ -91,7 +91,7 @@ views::View* ExceptionEditorView::GetContentsView() {
void ExceptionEditorView::ContentsChanged(views::Textfield* sender,
const std::wstring& new_contents) {
GetDialogClientView()->UpdateDialogButtons();
- UpdateImageView(pattern_iv_, IsPatternValid(HostContentSettingsMap::Pattern(
+ UpdateImageView(pattern_iv_, IsPatternValid(ContentSettingsPattern(
UTF16ToUTF8(pattern_tf_->text())), incognito_cb_->checked()));
}
@@ -110,7 +110,7 @@ void ExceptionEditorView::Init() {
pattern_iv_ = new views::ImageView;
- UpdateImageView(pattern_iv_, IsPatternValid(HostContentSettingsMap::Pattern(
+ UpdateImageView(pattern_iv_, IsPatternValid(ContentSettingsPattern(
UTF16ToUTF8(pattern_tf_->text())), is_off_the_record_));
action_cb_ = new views::Combobox(&cb_model_);
@@ -158,7 +158,7 @@ views::Label* ExceptionEditorView::CreateLabel(int message_id) {
}
bool ExceptionEditorView::IsPatternValid(
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
bool is_off_the_record) const {
bool is_valid_pattern = pattern.IsValid() &&
(model_->IndexOfExceptionByPattern(pattern, is_off_the_record) == -1);
diff --git a/chrome/browser/ui/views/options/exception_editor_view.h b/chrome/browser/ui/views/options/exception_editor_view.h
index d880360..db8ddf6 100644
--- a/chrome/browser/ui/views/options/exception_editor_view.h
+++ b/chrome/browser/ui/views/options/exception_editor_view.h
@@ -38,7 +38,7 @@ class ExceptionEditorView : public views::View,
public:
// Invoked when the user accepts the edit.
virtual void AcceptExceptionEdit(
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
ContentSetting setting,
bool is_off_the_record,
int index,
@@ -55,7 +55,7 @@ class ExceptionEditorView : public views::View,
ContentExceptionsTableModel* model,
bool allow_off_the_record,
int index,
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
ContentSetting setting,
bool is_off_the_record);
virtual ~ExceptionEditorView() {}
@@ -87,7 +87,7 @@ class ExceptionEditorView : public views::View,
// Returns true if we're adding a new item.
bool is_new() const { return index_ == -1; }
- bool IsPatternValid(const HostContentSettingsMap::Pattern& pattern,
+ bool IsPatternValid(const ContentSettingsPattern& pattern,
bool is_off_the_record) const;
void UpdateImageView(views::ImageView* image_view, bool is_valid);
@@ -99,7 +99,7 @@ class ExceptionEditorView : public views::View,
// Index of the item being edited. If -1, indices this is a new entry.
const bool allow_off_the_record_;
const int index_;
- const HostContentSettingsMap::Pattern pattern_;
+ const ContentSettingsPattern pattern_;
const ContentSetting setting_;
const bool is_off_the_record_;
diff --git a/chrome/browser/ui/views/options/exceptions_view.cc b/chrome/browser/ui/views/options/exceptions_view.cc
index eadaf75..0a622a1 100644
--- a/chrome/browser/ui/views/options/exceptions_view.cc
+++ b/chrome/browser/ui/views/options/exceptions_view.cc
@@ -128,7 +128,7 @@ std::wstring ExceptionsView::GetWindowTitle() const {
}
void ExceptionsView::AcceptExceptionEdit(
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
ContentSetting setting,
bool is_off_the_record,
int index,
@@ -234,7 +234,7 @@ void ExceptionsView::UpdateButtonState() {
void ExceptionsView::Add() {
ExceptionEditorView* view =
new ExceptionEditorView(this, &model_, allow_off_the_record_, -1,
- HostContentSettingsMap::Pattern(),
+ ContentSettingsPattern(),
CONTENT_SETTING_BLOCK, false);
view->Show(window()->GetNativeWindow());
diff --git a/chrome/browser/ui/views/options/exceptions_view.h b/chrome/browser/ui/views/options/exceptions_view.h
index 3624816..a0747be 100644
--- a/chrome/browser/ui/views/options/exceptions_view.h
+++ b/chrome/browser/ui/views/options/exceptions_view.h
@@ -69,7 +69,7 @@ class ExceptionsView : public ExceptionEditorView::Delegate,
// ExceptionEditorView::Delegate implementation.
virtual void AcceptExceptionEdit(
- const HostContentSettingsMap::Pattern& pattern,
+ const ContentSettingsPattern& pattern,
ContentSetting setting,
bool is_off_the_record,
int index,
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index b685ee4..a8ea3b9 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -783,6 +783,9 @@
'browser/content_setting_combo_model.h',
'browser/content_setting_image_model.cc',
'browser/content_setting_image_model.h',
+ 'browser/content_settings/content_settings_details.h',
+ 'browser/content_settings/content_settings_pattern.cc',
+ 'browser/content_settings/content_settings_pattern.h',
'browser/content_settings/content_settings_provider.h',
'browser/content_settings/host_content_settings_map.cc',
'browser/content_settings/host_content_settings_map.h',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 2904701..b50e5e5a 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1107,6 +1107,7 @@
'browser/diagnostics/diagnostics_model_unittest.cc',
'browser/command_updater_unittest.cc',
'browser/content_exceptions_table_model_unittest.cc',
+ 'browser/content_settings/content_settings_pattern_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',