OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_BROWSING_DATA_ORIGIN_FILTER_BUILDER_H_ | 5 #ifndef CHROME_BROWSER_BROWSING_DATA_ORIGIN_FILTER_BUILDER_H_ |
6 #define CHROME_BROWSER_BROWSING_DATA_ORIGIN_FILTER_BUILDER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_ORIGIN_FILTER_BUILDER_H_ |
7 | 7 |
8 #include <ostream> | 8 #include <ostream> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "net/cookies/canonical_cookie.h" | |
13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
14 #include "url/origin.h" | 15 #include "url/origin.h" |
15 | 16 |
17 class ContentSettingsPattern; | |
18 | |
16 // A class that constructs URL deletion filters (represented as GURL->bool | 19 // A class that constructs URL deletion filters (represented as GURL->bool |
17 // predicates) that match certain origins. | 20 // predicates) that match certain origins. |
18 class OriginFilterBuilder { | 21 class OriginFilterBuilder { |
19 public: | 22 public: |
20 enum Mode { | 23 enum Mode { |
24 // This means that only the origins given will be deleted. | |
21 WHITELIST, | 25 WHITELIST, |
26 // This means that the origins given will NOT be deleted. | |
Mike West
2016/03/11 08:36:10
Nit: "This means that everything EXCEPT the origin
dmurph
2016/03/30 22:21:26
Done.
| |
22 BLACKLIST | 27 BLACKLIST |
23 }; | 28 }; |
24 | 29 |
25 // Constructs a filter with the given |mode| - whitelist or blacklist. | 30 // Constructs a filter with the given |mode| - whitelist or blacklist. |
26 explicit OriginFilterBuilder(Mode mode); | 31 explicit OriginFilterBuilder(Mode mode); |
27 | 32 |
28 ~OriginFilterBuilder(); | 33 ~OriginFilterBuilder(); |
29 | 34 |
30 // Adds the |origin| to the (white- or black-) list. | 35 // Adds the |origin| to the (white- or black-) list. |
31 void AddOrigin(const url::Origin& origin); | 36 void AddOrigin(const url::Origin& origin); |
32 | 37 |
33 // Sets the |mode| of the filter. | 38 // Sets the |mode| of the filter. |
34 void SetMode(Mode mode); | 39 void SetMode(Mode mode); |
35 | 40 |
41 // Returns if we're an empty blacklist, where we delete everything. | |
Mike West
2016/03/11 08:36:10
Nit: Returns true
dmurph
2016/03/30 22:21:26
Done.
| |
42 bool IsEmptyBlacklist() const; | |
43 | |
36 // Builds a filter that matches URLs whose origins are in the whitelist, | 44 // Builds a filter that matches URLs whose origins are in the whitelist, |
37 // or aren't in the blacklist. | 45 // or aren't in the blacklist. |
38 base::Callback<bool(const GURL&)> BuildSameOriginFilter() const; | 46 base::Callback<bool(const GURL&)> BuildSameOriginFilter() const; |
39 | 47 |
48 // Builds a filter that calls ContentSettingsPattern::Matches on the origins | |
49 // in this filter. | |
50 base::Callback<bool(const ContentSettingsPattern& pattern)> | |
51 BuildWebsiteSettingsPatternMatchesFilter() const; | |
52 | |
53 // We compare the tld+1 of the origins and the cookie. This makes sure that | |
54 // websites don't have a partial cookie state. | |
55 // * If we're a blacklist, we will return true (to delete) if NONE of the | |
56 // origins can see the cookie. | |
57 // * If we're a whitelist, we will return true (to delete) if ANY of the | |
58 // origins can see the cookie. | |
59 // This means that origins not in the list can see the effects of this filter, | |
60 // as they will either be cleared as well, or have their cookies still around. | |
61 // Examples of tld+1s: | |
62 // * google.com | |
63 // * website.misawa.aomori.jp (the last three are the tld) | |
64 // * 192.168.1.1 | |
Mike West
2016/03/11 08:36:10
I'd rephrase this a bit for clarity, perhaps somet
dmurph
2016/03/30 22:21:26
Done, thanks.
| |
65 base::Callback<bool(const net::CanonicalCookie& pattern)> | |
66 BuildDomainCookieFilter() const; | |
67 | |
40 // Build a filter that matches URLs whose origins, or origins obtained by | 68 // Build a filter that matches URLs whose origins, or origins obtained by |
41 // replacing the host with any superdomain, are listed in the whitelist, | 69 // replacing the host with any superdomain, are listed in the whitelist, |
42 // or are not listed in the blacklist. | 70 // or are not listed in the blacklist. |
43 base::Callback<bool(const GURL&)> BuildDomainFilter() const; | 71 base::Callback<bool(const GURL&)> BuildDomainFilter() const; |
44 | 72 |
45 // A convenience method to produce an empty blacklist, a filter that matches | 73 // A convenience method to produce an empty blacklist, a filter that matches |
46 // everything. | 74 // everything. |
47 static base::Callback<bool(const GURL&)> BuildNoopFilter(); | 75 static base::Callback<bool(const GURL&)> BuildNoopFilter(); |
48 | 76 |
49 private: | 77 private: |
50 // True if the origin of |url| is in the whitelist, or isn't in the blacklist. | 78 // True if the origin of |url| is in the whitelist, or isn't in the blacklist. |
51 // The whitelist or blacklist is represented as |origins| and |mode|. | 79 // The whitelist or blacklist is represented as |origins| and |mode|. |
52 static bool MatchesURL( | 80 static bool MatchesURL( |
53 std::set<url::Origin>* origins, Mode mode, const GURL& url); | 81 std::set<url::Origin>* origins, Mode mode, const GURL& url); |
54 | 82 |
83 // True if the pattern something in the whitelist, or doesn't match something | |
84 // in the blacklist. | |
85 // The whitelist or blacklist is represented as |origins| and |mode|. | |
86 static bool MatchesWebsiteSettingsPattern( | |
87 std::set<url::Origin>* origins, | |
88 Mode mode, | |
89 const ContentSettingsPattern& pattern); | |
90 | |
91 // True if no origins can see the given cookie and we're a blacklist, or any | |
92 // origins can see the cookie and we're a whitelist. | |
93 // The whitelist or blacklist is represented as |origins| and |mode|. | |
94 static bool MatchesCookieForTLDPlusOne(std::set<url::Origin>* origins, | |
95 Mode mode, | |
96 const net::CanonicalCookie& cookie); | |
97 | |
55 // True if any origin [scheme, host, port], such that |url| has the same | 98 // True if any origin [scheme, host, port], such that |url| has the same |
56 // scheme and port, and |url|'s host is the same or a subdomain of that host, | 99 // scheme and port, and |url|'s host is the same or a subdomain of that host, |
57 // is in the whitelist, or isn't in the blacklist. The whitelist or blacklist | 100 // is in the whitelist, or isn't in the blacklist. The whitelist or blacklist |
58 // is represented as |origins| and |mode|. | 101 // is represented as |origins| and |mode|. |
59 static bool MatchesURLWithSubdomains( | 102 static bool MatchesURLWithSubdomains( |
60 std::set<url::Origin>* origins, Mode mode, const GURL& url); | 103 std::set<url::Origin>* origins, Mode mode, const GURL& url); |
61 | 104 |
62 // The list of origins and whether they should be interpreted as a whitelist | 105 // The list of origins and whether they should be interpreted as a whitelist |
63 // or blacklist. | 106 // or blacklist. |
64 std::set<url::Origin> origin_list_; | 107 std::set<url::Origin> origin_list_; |
65 Mode mode_; | 108 Mode mode_; |
66 | 109 |
67 DISALLOW_COPY_AND_ASSIGN(OriginFilterBuilder); | 110 DISALLOW_COPY_AND_ASSIGN(OriginFilterBuilder); |
68 }; | 111 }; |
69 | 112 |
70 #endif // CHROME_BROWSER_BROWSING_DATA_ORIGIN_FILTER_BUILDER_H_ | 113 #endif // CHROME_BROWSER_BROWSING_DATA_ORIGIN_FILTER_BUILDER_H_ |
OLD | NEW |