diff options
-rw-r--r-- | chrome/app/DEPS | 1 | ||||
-rw-r--r-- | chrome/app/chrome_main_delegate.cc | 5 | ||||
-rw-r--r-- | chrome/browser/content_settings/content_settings_mock_observer.h | 3 | ||||
-rw-r--r-- | chrome/browser/content_settings/content_settings_policy_provider.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/api/content_settings/content_settings_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/notifications/desktop_notification_profile_util.h | 1 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 2 | ||||
-rw-r--r-- | chrome/common/content_settings_pattern.cc | 140 | ||||
-rw-r--r-- | chrome/common/content_settings_pattern.h | 88 | ||||
-rw-r--r-- | chrome/common/content_settings_pattern_parser.cc | 41 | ||||
-rw-r--r-- | chrome/common/content_settings_pattern_parser.h | 17 | ||||
-rw-r--r-- | chrome/common/content_settings_pattern_serializer.cc | 26 | ||||
-rw-r--r-- | chrome/common/content_settings_pattern_serializer.h | 30 | ||||
-rw-r--r-- | chrome/common/render_messages.cc | 6 | ||||
-rw-r--r-- | chrome/test/base/chrome_test_suite.cc | 5 | ||||
-rw-r--r-- | components/content_settings.gypi | 1 | ||||
-rw-r--r-- | components/content_settings/core/common/content_settings_types.h | 2 |
17 files changed, 192 insertions, 182 deletions
diff --git a/chrome/app/DEPS b/chrome/app/DEPS index c88daac..f2893c0 100644 --- a/chrome/app/DEPS +++ b/chrome/app/DEPS @@ -16,6 +16,7 @@ include_rules = [ "+components/startup_metric_utils", "+content/public/app", "+content/public/browser/browser_main_runner.h", + "+extensions/common/constants.h", "+grit", # For generated headers "+native_client/src/trusted/service_runtime/osx", "+policy", # For generated headers and source diff --git a/chrome/app/chrome_main_delegate.cc b/chrome/app/chrome_main_delegate.cc index 5de4cc5..8c965b0 100644 --- a/chrome/app/chrome_main_delegate.cc +++ b/chrome/app/chrome_main_delegate.cc @@ -26,6 +26,7 @@ #include "chrome/common/chrome_paths_internal.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_version_info.h" +#include "chrome/common/content_settings_pattern.h" #include "chrome/common/crash_keys.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/profiling.h" @@ -38,6 +39,7 @@ #include "components/startup_metric_utils/startup_metric_utils.h" #include "content/public/common/content_client.h" #include "content/public/common/content_paths.h" +#include "extensions/common/constants.h" #include "ui/base/ui_base_switches.h" #if defined(OS_WIN) @@ -426,6 +428,9 @@ bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) { nacl::RegisterPathProvider(); #endif + ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( + extensions::kExtensionScheme); + // No support for ANDROID yet as DiagnosticsController needs wchar support. // TODO(gspencer): That's not true anymore, or at least there are no w-string // references anymore. Not sure if that means this can be enabled on Android or diff --git a/chrome/browser/content_settings/content_settings_mock_observer.h b/chrome/browser/content_settings/content_settings_mock_observer.h index 419fcd7..3473888 100644 --- a/chrome/browser/content_settings/content_settings_mock_observer.h +++ b/chrome/browser/content_settings/content_settings_mock_observer.h @@ -7,6 +7,7 @@ #include <string> +#include "base/macros.h" #include "chrome/browser/content_settings/content_settings_observer.h" #include "testing/gmock/include/gmock/gmock.h" @@ -26,6 +27,6 @@ class MockObserver : public Observer { DISALLOW_COPY_AND_ASSIGN(MockObserver); }; -} // content_settings +} // namespace content_settings #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_MOCK_OBSERVER_H_ diff --git a/chrome/browser/content_settings/content_settings_policy_provider.cc b/chrome/browser/content_settings/content_settings_policy_provider.cc index f41669e..0b337d8 100644 --- a/chrome/browser/content_settings/content_settings_policy_provider.cc +++ b/chrome/browser/content_settings/content_settings_policy_provider.cc @@ -370,7 +370,7 @@ void PolicyProvider::GetAutoSelectCertificateSettingsFromPreferences( // Ignore invalid patterns. if (!pattern.IsValid()) { VLOG(1) << "Ignoring invalid certificate auto select setting:" - " Invalid content settings pattern: " << pattern; + " Invalid content settings pattern: " << pattern.ToString(); continue; } diff --git a/chrome/browser/extensions/api/content_settings/content_settings_unittest.cc b/chrome/browser/extensions/api/content_settings/content_settings_unittest.cc index a1c0237..c59604c 100644 --- a/chrome/browser/extensions/api/content_settings/content_settings_unittest.cc +++ b/chrome/browser/extensions/api/content_settings/content_settings_unittest.cc @@ -2,9 +2,9 @@ // 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 "base/macros.h" #include "chrome/browser/extensions/api/content_settings/content_settings_helpers.h" +#include "testing/gtest/include/gtest/gtest.h" namespace extensions { namespace helpers = content_settings_helpers; diff --git a/chrome/browser/notifications/desktop_notification_profile_util.h b/chrome/browser/notifications/desktop_notification_profile_util.h index 12d7cf2..97a72b7 100644 --- a/chrome/browser/notifications/desktop_notification_profile_util.h +++ b/chrome/browser/notifications/desktop_notification_profile_util.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_PROFILE_UTIL_H_ #define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_PROFILE_UTIL_H_ +#include "base/macros.h" #include "chrome/common/content_settings.h" class Profile; diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index dfb3308..2eb68fd 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -52,6 +52,8 @@ 'common/content_settings_pattern.h', 'common/content_settings_pattern_parser.cc', 'common/content_settings_pattern_parser.h', + 'common/content_settings_pattern_serializer.cc', + 'common/content_settings_pattern_serializer.h', 'common/crash_keys.cc', 'common/crash_keys.h', 'common/custom_handlers/protocol_handler.cc', diff --git a/chrome/common/content_settings_pattern.cc b/chrome/common/content_settings_pattern.cc index 03a746e..98ee8e1 100644 --- a/chrome/common/content_settings_pattern.cc +++ b/chrome/common/content_settings_pattern.cc @@ -10,17 +10,15 @@ #include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "chrome/common/content_settings_pattern_parser.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/url_constants.h" -#include "extensions/common/constants.h" -#include "ipc/ipc_message_utils.h" #include "net/base/dns_util.h" #include "net/base/net_util.h" #include "url/gurl.h" -#include "url/url_canon.h" namespace { +// The component supports only one scheme for simplicity. +const char* non_port_non_domain_wildcard_scheme = NULL; + std::string GetDefaultPort(const std::string& scheme) { if (scheme == url::kHttpScheme) return "80"; @@ -85,6 +83,44 @@ typedef ContentSettingsPattern::BuilderInterface BuilderInterface; // //////////////////////////////////////////////////////////////////////////// // ContentSettingsPattern::Builder // +class ContentSettingsPattern::Builder : + public ContentSettingsPattern::BuilderInterface { + public: + explicit Builder(bool use_legacy_validate); + virtual ~Builder(); + + // BuilderInterface: + virtual BuilderInterface* WithPort(const std::string& port) OVERRIDE; + virtual BuilderInterface* WithPortWildcard() OVERRIDE; + virtual BuilderInterface* WithHost(const std::string& host) OVERRIDE; + virtual BuilderInterface* WithDomainWildcard() OVERRIDE; + virtual BuilderInterface* WithScheme(const std::string& scheme) OVERRIDE; + virtual BuilderInterface* WithSchemeWildcard() OVERRIDE; + virtual BuilderInterface* WithPath(const std::string& path) OVERRIDE; + virtual BuilderInterface* WithPathWildcard() OVERRIDE; + virtual BuilderInterface* Invalid() OVERRIDE; + virtual ContentSettingsPattern Build() OVERRIDE; + + private: + // Canonicalizes the pattern parts so that they are ASCII only, either + // in original (if it was already ASCII) or punycode form. Returns true if + // the canonicalization was successful. + static bool Canonicalize(PatternParts* parts); + + // Returns true when the pattern |parts| represent a valid pattern. + static bool Validate(const PatternParts& parts); + + static bool LegacyValidate(const PatternParts& parts); + + bool is_valid_; + + bool use_legacy_validate_; + + PatternParts parts_; + + DISALLOW_COPY_AND_ASSIGN(Builder); +}; + ContentSettingsPattern::Builder::Builder(bool use_legacy_validate) : is_valid_(true), use_legacy_validate_(use_legacy_validate) {} @@ -224,7 +260,7 @@ bool ContentSettingsPattern::Builder::Validate(const PatternParts& parts) { } // If the pattern is for an extension URL test if it is valid. - if (parts.scheme == std::string(extensions::kExtensionScheme) && + if (IsNonWildcardDomainNonPortScheme(parts.scheme) && parts.port.empty() && !parts.is_port_wildcard) { return true; @@ -261,7 +297,7 @@ bool ContentSettingsPattern::Builder::LegacyValidate( return true; // If the pattern is for an extension URL test if it is valid. - if (parts.scheme == std::string(extensions::kExtensionScheme) && + if (IsNonWildcardDomainNonPortScheme(parts.scheme) && !parts.is_scheme_wildcard && !parts.host.empty() && !parts.has_domain_wildcard && @@ -311,11 +347,6 @@ ContentSettingsPattern::PatternParts::~PatternParts() {} // TODO(jochen): update once this feature is no longer behind a flag. const int ContentSettingsPattern::kContentSettingsPatternVersion = 1; -// TODO(markusheintz): These two constants were moved to the Pattern Parser. -// Remove once the dependency of the ContentSettingsBaseProvider is removed. -const char* ContentSettingsPattern::kDomainWildcard = "[*.]"; -const size_t ContentSettingsPattern::kDomainWildcardLength = 4; - // static BuilderInterface* ContentSettingsPattern::CreateBuilder( bool validate) { @@ -323,6 +354,15 @@ BuilderInterface* ContentSettingsPattern::CreateBuilder( } // static +ContentSettingsPattern ContentSettingsPattern::Wildcard() { + scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( + ContentSettingsPattern::CreateBuilder(true)); + builder->WithSchemeWildcard()->WithDomainWildcard()->WithPortWildcard()-> + WithPathWildcard(); + return builder->Build(); +} + +// static ContentSettingsPattern ContentSettingsPattern::FromURL( const GURL& url) { scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( @@ -388,26 +428,25 @@ ContentSettingsPattern ContentSettingsPattern::FromString( const std::string& pattern_spec) { scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( ContentSettingsPattern::CreateBuilder(false)); - content_settings::PatternParser::Parse(pattern_spec, builder.get()); + content_settings::PatternParser::Parse(pattern_spec, + builder.get()); return builder->Build(); } // static -ContentSettingsPattern ContentSettingsPattern::LegacyFromString( - const std::string& pattern_spec) { - scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( - ContentSettingsPattern::CreateBuilder(true)); - content_settings::PatternParser::Parse(pattern_spec, builder.get()); - return builder->Build(); +void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( + const char* scheme) { + DCHECK(scheme); + DCHECK(!non_port_non_domain_wildcard_scheme || + non_port_non_domain_wildcard_scheme == scheme); + non_port_non_domain_wildcard_scheme = scheme; } // static -ContentSettingsPattern ContentSettingsPattern::Wildcard() { - scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( - ContentSettingsPattern::CreateBuilder(true)); - builder->WithSchemeWildcard()->WithDomainWildcard()->WithPortWildcard()-> - WithPathWildcard(); - return builder->Build(); +bool ContentSettingsPattern::IsNonWildcardDomainNonPortScheme( + const std::string& scheme) { + DCHECK(non_port_non_domain_wildcard_scheme); + return scheme == non_port_non_domain_wildcard_scheme; } ContentSettingsPattern::ContentSettingsPattern() @@ -421,17 +460,6 @@ ContentSettingsPattern::ContentSettingsPattern( is_valid_(valid) { } -void ContentSettingsPattern::WriteToMessage(IPC::Message* m) const { - IPC::WriteParam(m, is_valid_); - IPC::WriteParam(m, parts_); -} - -bool ContentSettingsPattern::ReadFromMessage(const IPC::Message* m, - PickleIterator* iter) { - return IPC::ReadParam(m, iter, &is_valid_) && - IPC::ReadParam(m, iter, &parts_); -} - bool ContentSettingsPattern::Matches( const GURL& url) const { // An invalid pattern matches nothing. @@ -471,8 +499,8 @@ bool ContentSettingsPattern::Matches( return false; } - // For chrome extensions URLs ignore the port. - if (parts_.scheme == std::string(extensions::kExtensionScheme)) + // Ignore the port if the scheme doesn't support it. + if (IsNonWildcardDomainNonPortScheme(parts_.scheme)) return true; // Match the port part. @@ -497,7 +525,7 @@ bool ContentSettingsPattern::MatchesAllHosts() const { return parts_.has_domain_wildcard && parts_.host.empty(); } -const std::string ContentSettingsPattern::ToString() const { +std::string ContentSettingsPattern::ToString() const { if (IsValid()) return content_settings::PatternParser::ToString(parts_); else @@ -562,6 +590,23 @@ bool ContentSettingsPattern::operator>( } // static +ContentSettingsPattern::Relation ContentSettingsPattern::CompareScheme( + const ContentSettingsPattern::PatternParts& parts, + const ContentSettingsPattern::PatternParts& other_parts) { + if (parts.is_scheme_wildcard && !other_parts.is_scheme_wildcard) + return ContentSettingsPattern::SUCCESSOR; + if (!parts.is_scheme_wildcard && other_parts.is_scheme_wildcard) + return ContentSettingsPattern::PREDECESSOR; + + int result = parts.scheme.compare(other_parts.scheme); + if (result == 0) + return ContentSettingsPattern::IDENTITY; + if (result > 0) + return ContentSettingsPattern::DISJOINT_ORDER_PRE; + return ContentSettingsPattern::DISJOINT_ORDER_POST; +} + +// static ContentSettingsPattern::Relation ContentSettingsPattern::CompareHost( const ContentSettingsPattern::PatternParts& parts, const ContentSettingsPattern::PatternParts& other_parts) { @@ -649,23 +694,6 @@ ContentSettingsPattern::Relation ContentSettingsPattern::CompareHost( } // static -ContentSettingsPattern::Relation ContentSettingsPattern::CompareScheme( - const ContentSettingsPattern::PatternParts& parts, - const ContentSettingsPattern::PatternParts& other_parts) { - if (parts.is_scheme_wildcard && !other_parts.is_scheme_wildcard) - return ContentSettingsPattern::SUCCESSOR; - if (!parts.is_scheme_wildcard && other_parts.is_scheme_wildcard) - return ContentSettingsPattern::PREDECESSOR; - - int result = parts.scheme.compare(other_parts.scheme); - if (result == 0) - return ContentSettingsPattern::IDENTITY; - if (result > 0) - return ContentSettingsPattern::DISJOINT_ORDER_PRE; - return ContentSettingsPattern::DISJOINT_ORDER_POST; -} - -// static ContentSettingsPattern::Relation ContentSettingsPattern::ComparePort( const ContentSettingsPattern::PatternParts& parts, const ContentSettingsPattern::PatternParts& other_parts) { diff --git a/chrome/common/content_settings_pattern.h b/chrome/common/content_settings_pattern.h index a7b4861..0673014 100644 --- a/chrome/common/content_settings_pattern.h +++ b/chrome/common/content_settings_pattern.h @@ -7,25 +7,16 @@ #ifndef CHROME_COMMON_CONTENT_SETTINGS_PATTERN_H_ #define CHROME_COMMON_CONTENT_SETTINGS_PATTERN_H_ -#include <ostream> #include <string> -#include "base/basictypes.h" -#include "base/compiler_specific.h" #include "base/gtest_prod_util.h" class GURL; -class Pickle; -class PickleIterator; namespace content_settings { class PatternParser; } -namespace IPC { -class Message; -} - // A pattern used in content setting rules. See |IsValid| for a description of // possible patterns. class ContentSettingsPattern { @@ -131,12 +122,6 @@ class ContentSettingsPattern { // 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; - // Returns a wildcard content settings pattern that matches all possible valid // origins. static ContentSettingsPattern Wildcard(); @@ -159,17 +144,19 @@ class ContentSettingsPattern { // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip) static ContentSettingsPattern FromString(const std::string& pattern_spec); - static ContentSettingsPattern LegacyFromString( - const std::string& pattern_spec); + // Sets the scheme that doesn't support domain wildcard and port. + // Needs to be called by the embedder before using ContentSettingsPattern. + // |scheme| can't be NULL, and the pointed string must remain alive until the + // app terminates. + static void SetNonWildcardDomainNonPortScheme(const char* scheme); + + // Compares |scheme| against the scheme set by the embedder. + static bool IsNonWildcardDomainNonPortScheme(const std::string& scheme); // Constructs an empty pattern. Empty patterns are invalid patterns. Invalid // patterns match nothing. ContentSettingsPattern(); - // Serializes the pattern to an IPC message or deserializes it. - void WriteToMessage(IPC::Message* m) const; - bool ReadFromMessage(const IPC::Message* m, PickleIterator* iter); - // True if this is a valid pattern. bool IsValid() const { return is_valid_; } @@ -180,7 +167,7 @@ class ContentSettingsPattern { bool MatchesAllHosts() const; // Returns a std::string representation of this pattern. - const std::string ToString() const; + std::string ToString() const; // Compares the pattern with a given |other| pattern and returns the // |Relation| of the two patterns. @@ -200,54 +187,10 @@ class ContentSettingsPattern { private: friend class content_settings::PatternParser; - friend class Builder; + friend class ContentSettingsPatternSerializer; FRIEND_TEST_ALL_PREFIXES(ContentSettingsPatternParserTest, SerializePatterns); - class Builder : public BuilderInterface { - public: - explicit Builder(bool use_legacy_validate); - virtual ~Builder(); - - // Overrides BuilderInterface - virtual BuilderInterface* WithPort(const std::string& port) OVERRIDE; - - virtual BuilderInterface* WithPortWildcard() OVERRIDE; - - virtual BuilderInterface* WithHost(const std::string& host) OVERRIDE; - - virtual BuilderInterface* WithDomainWildcard() OVERRIDE; - - virtual BuilderInterface* WithScheme(const std::string& scheme) OVERRIDE; - - virtual BuilderInterface* WithSchemeWildcard() OVERRIDE; - - virtual BuilderInterface* WithPath(const std::string& path) OVERRIDE; - - virtual BuilderInterface* WithPathWildcard() OVERRIDE; - - virtual BuilderInterface* Invalid() OVERRIDE; - - virtual ContentSettingsPattern Build() OVERRIDE; - - private: - // Canonicalizes the pattern parts so that they are ASCII only, either - // in original (if it was already ASCII) or punycode form. Returns true if - // the canonicalization was successful. - static bool Canonicalize(PatternParts* parts); - - // Returns true when the pattern |parts| represent a valid pattern. - static bool Validate(const PatternParts& parts); - - static bool LegacyValidate(const PatternParts& parts); - - bool is_valid_; - - bool use_legacy_validate_; - - PatternParts parts_; - - DISALLOW_COPY_AND_ASSIGN(Builder); - }; + class Builder; static Relation CompareScheme( const ContentSettingsPattern::PatternParts& parts, @@ -261,8 +204,6 @@ class ContentSettingsPattern { const ContentSettingsPattern::PatternParts& parts, const ContentSettingsPattern::PatternParts& other_parts); - static bool Validate(const PatternParts& parts); - ContentSettingsPattern(const PatternParts& parts, bool valid); PatternParts parts_; @@ -270,11 +211,4 @@ class ContentSettingsPattern { bool is_valid_; }; -// Stream operator so ContentSettingsPattern can be used in assertion -// statements. -inline std::ostream& operator<<( - std::ostream& out, const ContentSettingsPattern& pattern) { - return out << pattern.ToString(); -} - #endif // CHROME_COMMON_CONTENT_SETTINGS_PATTERN_H_ diff --git a/chrome/common/content_settings_pattern_parser.cc b/chrome/common/content_settings_pattern_parser.cc index 6cfb4bb..1a90da4 100644 --- a/chrome/common/content_settings_pattern_parser.cc +++ b/chrome/common/content_settings_pattern_parser.cc @@ -5,16 +5,18 @@ #include "chrome/common/content_settings_pattern_parser.h" #include "base/strings/string_util.h" -#include "chrome/common/url_constants.h" -#include "extensions/common/constants.h" -#include "net/base/net_util.h" -#include "url/gurl.h" -#include "url/url_canon.h" +#include "url/url_constants.h" namespace { -const char* kUrlPathSeparator = "/"; -const char* kUrlPortSeparator = ":"; +const char kDomainWildcard[] = "[*.]"; +const size_t kDomainWildcardLength = 4; +const char kHostWildcard[] = "*"; +const char kPathWildcard[] = "*"; +const char kPortWildcard[] = "*"; +const char kSchemeWildcard[] = "*"; +const char kUrlPathSeparator[] = "/"; +const char kUrlPortSeparator[] = ":"; class Component { public: @@ -33,19 +35,6 @@ class Component { namespace content_settings { -const char* PatternParser::kDomainWildcard = "[*.]"; - -const size_t PatternParser::kDomainWildcardLength = 4; - -const char* PatternParser::kSchemeWildcard = "*"; - -const char* PatternParser::kHostWildcard = "*"; - -const char* PatternParser::kPortWildcard = "*"; - -const char* PatternParser::kPathWildcard = "*"; - -// static void PatternParser::Parse(const std::string& pattern_spec, ContentSettingsPattern::BuilderInterface* builder) { if (pattern_spec == "*") { @@ -69,11 +58,11 @@ void PatternParser::Parse(const std::string& pattern_spec, return; // Test if a scheme pattern is in the spec. - current_pos = pattern_spec.find( - std::string(url::kStandardSchemeSeparator), start); + const std::string standard_scheme_separator(url::kStandardSchemeSeparator); + current_pos = pattern_spec.find(standard_scheme_separator, start); if (current_pos != std::string::npos) { scheme_component = Component(start, current_pos); - start = current_pos + strlen(url::kStandardSchemeSeparator); + start = current_pos + standard_scheme_separator.size(); current_pos = start; } else { current_pos = start; @@ -172,8 +161,8 @@ void PatternParser::Parse(const std::string& pattern_spec, builder->WithPort(port); } } else { - if (scheme != std::string(extensions::kExtensionScheme) && - scheme != std::string(url::kFileScheme)) + if (!ContentSettingsPattern::IsNonWildcardDomainNonPortScheme(scheme) && + scheme != url::kFileScheme) builder->WithPortWildcard(); } @@ -217,7 +206,7 @@ std::string PatternParser::ToString( } str += parts.host; - if (parts.scheme == std::string(extensions::kExtensionScheme)) { + if (ContentSettingsPattern::IsNonWildcardDomainNonPortScheme(parts.scheme)) { str += parts.path.empty() ? std::string(kUrlPathSeparator) : parts.path; return str; } diff --git a/chrome/common/content_settings_pattern_parser.h b/chrome/common/content_settings_pattern_parser.h index 19f8d27..fbd8ccc 100644 --- a/chrome/common/content_settings_pattern_parser.h +++ b/chrome/common/content_settings_pattern_parser.h @@ -12,8 +12,6 @@ namespace content_settings { -struct PatternParts; - class PatternParser { public: static void Parse(const std::string& pattern_spec, @@ -21,21 +19,6 @@ class PatternParser { static std::string ToString( const ContentSettingsPattern::PatternParts& parts); - - private: - static const char* kDomainWildcard; - - static const size_t kDomainWildcardLength; - - static const char* kSchemeWildcard; - - static const char* kHostWildcard; - - static const char* kPortWildcard; - - static const char* kPathWildcard; - - DISALLOW_COPY_AND_ASSIGN(PatternParser); }; } // namespace content_settings diff --git a/chrome/common/content_settings_pattern_serializer.cc b/chrome/common/content_settings_pattern_serializer.cc new file mode 100644 index 0000000..7bf2c2f --- /dev/null +++ b/chrome/common/content_settings_pattern_serializer.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2014 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/common/content_settings_pattern_serializer.h" + +#include "chrome/common/content_settings_pattern.h" +#include "chrome/common/render_messages.h" + +// static +void ContentSettingsPatternSerializer::WriteToMessage( + const ContentSettingsPattern& pattern, + IPC::Message* m) { + IPC::WriteParam(m, pattern.is_valid_); + IPC::WriteParam(m, pattern.parts_); +} + +// static +bool ContentSettingsPatternSerializer::ReadFromMessage( + const IPC::Message* m, + PickleIterator* iter, + ContentSettingsPattern* pattern) { + DCHECK(pattern); + return IPC::ReadParam(m, iter, &pattern->is_valid_) && + IPC::ReadParam(m, iter, &pattern->parts_); +} diff --git a/chrome/common/content_settings_pattern_serializer.h b/chrome/common/content_settings_pattern_serializer.h new file mode 100644 index 0000000..9d1d184 --- /dev/null +++ b/chrome/common/content_settings_pattern_serializer.h @@ -0,0 +1,30 @@ +// Copyright (c) 2014 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_COMMON_CONTENT_SETTINGS_PATTERN_SERIALIZER_H_ +#define CHROME_COMMON_CONTENT_SETTINGS_PATTERN_SERIALIZER_H_ + +#include "base/macros.h" + +namespace IPC { +class Message; +} + +class ContentSettingsPattern; +class PickleIterator; + +class ContentSettingsPatternSerializer { + public: + // Serializes the pattern to an IPC message. + static void WriteToMessage(const ContentSettingsPattern& pattern, + IPC::Message* m); + // Deserializes the pattern from the IPC message. + static bool ReadFromMessage(const IPC::Message* m, PickleIterator* iter, + ContentSettingsPattern* pattern); + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(ContentSettingsPatternSerializer); +}; + +#endif // CHROME_COMMON_CONTENT_SETTINGS_PATTERN_SERIALIZER_H_ diff --git a/chrome/common/render_messages.cc b/chrome/common/render_messages.cc index ce17fa3..dd81496 100644 --- a/chrome/common/render_messages.cc +++ b/chrome/common/render_messages.cc @@ -4,16 +4,18 @@ #include "chrome/common/render_messages.h" +#include "chrome/common/content_settings_pattern_serializer.h" + namespace IPC { void ParamTraits<ContentSettingsPattern>::Write( Message* m, const ContentSettingsPattern& pattern) { - pattern.WriteToMessage(m); + ContentSettingsPatternSerializer::WriteToMessage(pattern, m); } bool ParamTraits<ContentSettingsPattern>::Read( const Message* m, PickleIterator* iter, ContentSettingsPattern* pattern) { - return pattern->ReadFromMessage(m, iter); + return ContentSettingsPatternSerializer::ReadFromMessage(m, iter, pattern); } void ParamTraits<ContentSettingsPattern>::Log( diff --git a/chrome/test/base/chrome_test_suite.cc b/chrome/test/base/chrome_test_suite.cc index 6292b85..45c0d5c 100644 --- a/chrome/test/base/chrome_test_suite.cc +++ b/chrome/test/base/chrome_test_suite.cc @@ -16,8 +16,10 @@ #include "chrome/browser/browser_process.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/content_settings_pattern.h" #include "chrome/common/url_constants.h" #include "content/public/test/test_launcher.h" +#include "extensions/common/constants.h" #include "testing/gtest/include/gtest/gtest.h" #if defined(OS_ANDROID) @@ -106,6 +108,9 @@ void ChromeTestSuite::Initialize() { // values for DIR_EXE and DIR_MODULE. content::ContentTestSuiteBase::Initialize(); + ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( + extensions::kExtensionScheme); + #if defined(OS_MACOSX) && !defined(OS_IOS) // Look in the framework bundle for resources. base::FilePath path; diff --git a/components/content_settings.gypi b/components/content_settings.gypi index 478aa866f..5816e78 100644 --- a/components/content_settings.gypi +++ b/components/content_settings.gypi @@ -8,6 +8,7 @@ # GN version: //components/content_settings/core/common 'target_name': 'content_settings_core_common', 'type': 'none', + 'variables': { 'enable_wexit_time_destructors': 1, }, 'include_dirs': [ '..', ], diff --git a/components/content_settings/core/common/content_settings_types.h b/components/content_settings/core/common/content_settings_types.h index ea60346..cce4a77 100644 --- a/components/content_settings/core/common/content_settings_types.h +++ b/components/content_settings/core/common/content_settings_types.h @@ -5,6 +5,8 @@ #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_TYPES_H_ #define COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_TYPES_H_ +#include "build/build_config.h" + // A particular type of content to care about. We give the user various types // of controls over each of these. enum ContentSettingsType { |