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

Side by Side Diff: chrome/browser/content_settings/content_settings_pattern.h

Issue 5574001: Move ContentSettingsDetails and Pattern out of HostContentSettingsMap as separate classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/content_settings
Patch Set: rebase Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Patterns used in content setting rules.
6
7 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_
8 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_
9 #pragma once
10
11 #include <string>
12
13 class GURL;
14
15 // A hostname pattern. See |IsValid| for a description of possible patterns.
16 class ContentSettingsPattern {
markusheintz_ 2010/12/02 13:28:18 In order to prevent confusion or misunderstanding
jochen (gone - plz use gerrit) 2010/12/02 13:41:39 it doesn't describe content settings, but it also
markusheintz_ 2010/12/02 13:50:56 I see. Pls change the comment then. Hm... hard to
jochen (gone - plz use gerrit) 2010/12/02 13:55:40 Done.
17 public:
18 // Returns a pattern that matches the host of this URL and all subdomains.
19 static ContentSettingsPattern FromURL(const GURL& url);
20
21 // Returns a pattern that matches exactly this URL.
22 static ContentSettingsPattern FromURLNoWildcard(const GURL& url);
23
24 ContentSettingsPattern() {}
25
26 explicit ContentSettingsPattern(const std::string& pattern)
27 : pattern_(pattern) {}
28
29 // True if this is a valid pattern. Valid patterns are
30 // - [*.]domain.tld (matches domain.tld and all sub-domains)
31 // - host (matches an exact hostname)
32 // - a.b.c.d (matches an exact IPv4 ip)
33 // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip)
34 // TODO(jochen): should also return true for a complete URL without a host.
35 bool IsValid() const;
36
37 // True if |url| matches this pattern.
38 bool Matches(const GURL& url) const;
39
40 // Returns a std::string representation of this pattern.
41 const std::string& AsString() const { return pattern_; }
42
43 bool operator==(const ContentSettingsPattern& other) const {
44 return pattern_ == other.pattern_;
45 }
46
47 // Canonicalizes the pattern so that it's ASCII only, either
48 // in original or punycode form.
markusheintz_ 2010/12/02 13:28:18 In which case is it the original and in which case
jochen (gone - plz use gerrit) 2010/12/02 13:41:39 Done.
jochen (gone - plz use gerrit) 2010/12/02 13:41:39 Done.
49 std::string CanonicalizePattern() const;
50
51 // The version of the pattern format implemented.
52 static const int kContentSettingsPatternVersion;
53
54 // The format of a domain wildcard.
markusheintz_ 2010/12/02 13:28:18 Ignore this comment if the following twi constants
jochen (gone - plz use gerrit) 2010/12/02 13:41:39 it's still used in the host content settings map.
55 static const char *kDomainWildcard;
gfeher 2010/12/02 13:07:50 static const char* kDomainWildcard; ?
jochen (gone - plz use gerrit) 2010/12/02 13:18:43 Done.
56
57 // The length of kDomainWildcard (without the trailing '\0').
58 static const size_t kDomainWildcardLength;
59
60 private:
61 std::string pattern_;
62 };
63
64 // Stream operator so ContentSettingsPattern can be used in assertion
65 // statements.
66 inline std::ostream& operator<<(
67 std::ostream& out, const ContentSettingsPattern& pattern) {
68 return out << pattern.AsString();
69 }
70
71 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_PATTERN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698