| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_PRIVACY_BLACKLIST_BLACKLIST_H_ | 5 #ifndef CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_H_ |
| 6 #define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_H_ | 6 #define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 std::vector<std::string> types_; | 112 std::vector<std::string> types_; |
| 113 | 113 |
| 114 // Points to the provider of this entry, the providers are all | 114 // Points to the provider of this entry, the providers are all |
| 115 // owned by the blacklist. | 115 // owned by the blacklist. |
| 116 const Provider* provider_; | 116 const Provider* provider_; |
| 117 | 117 |
| 118 friend class Blacklist; | 118 friend class Blacklist; |
| 119 friend class BlacklistIO; | 119 friend class BlacklistIO; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 // When a request matches a Blacklist rule but the rule must be applied | 122 // A request may match one or more Blacklist rules. The Match class packages |
| 123 // after the request has started, we tag it with this user data to | 123 // all the matching entries behind a single interface with access to the |
| 124 // avoid doing lookups more than once per request. The Entry is owned | 124 // underlying set of entries so that we can display provider information. |
| 125 // be the blacklist, so this indirection makes sure that it does not | 125 // Often a match must be applied after a URLRequest has started, so it gets |
| 126 // get destroyed by the Blacklist. | 126 // tagged with the Match object to avoid doing lookups more than once per |
| 127 class RequestData : public URLRequest::UserData { | 127 // request. |
| 128 class Match : public URLRequest::UserData { |
| 128 public: | 129 public: |
| 129 explicit RequestData(const Entry* entry) : entry_(entry) {} | 130 // Functions that return combined results from all entries. |
| 130 const Entry* entry() const { return entry_; } | 131 unsigned int attributes() const { return attributes_; } |
| 132 bool MatchType(const std::string&) const; |
| 133 bool IsBlocked(const GURL&) const; |
| 134 |
| 135 // Access to individual entries, mostly for display/logging purposes. |
| 136 const std::vector<const Entry*>& entries() const { return entries_; } |
| 137 |
| 131 private: | 138 private: |
| 132 const Entry* const entry_; | 139 Match(); |
| 140 void AddEntry(const Entry* entry); |
| 141 std::vector<const Entry*> entries_; |
| 142 unsigned int attributes_; // Precomputed ORed attributes of entries. |
| 143 |
| 144 friend class Blacklist; // Only blacklist constructs and sets these. |
| 133 }; | 145 }; |
| 134 | 146 |
| 135 // Constructs a Blacklist given the filename of the persistent version. | 147 // Constructs a Blacklist given the filename of the persistent version. |
| 136 // | 148 // |
| 137 // For startup efficiency, and because the blacklist must be available | 149 // For startup efficiency, and because the blacklist must be available |
| 138 // before any http request is made (including the homepage, if one is | 150 // before any http request is made (including the homepage, if one is |
| 139 // set to be loaded at startup), it is important to load the blacklist | 151 // set to be loaded at startup), it is important to load the blacklist |
| 140 // from a local source as efficiently as possible. For this reason, the | 152 // from a local source as efficiently as possible. For this reason, the |
| 141 // combined rules from all active blacklists are stored in one local file. | 153 // combined rules from all active blacklists are stored in one local file. |
| 142 explicit Blacklist(const FilePath& path); | 154 explicit Blacklist(const FilePath& path); |
| 143 | 155 |
| 144 // Destructor. | 156 // Destructor. |
| 145 ~Blacklist(); | 157 ~Blacklist(); |
| 146 | 158 |
| 147 // Returns a pointer to the Blacklist-owned entry which matches the given | 159 // Returns a pointer to a Match structure holding all matching entries. |
| 148 // URL. If no matching Entry is found, returns null. | 160 // If no matching Entry is found, returns null. Ownership belongs to the |
| 149 const Entry* findMatch(const GURL&) const; | 161 // caller. |
| 162 Match* findMatch(const GURL&) const; |
| 150 | 163 |
| 151 // Helper to remove cookies from a header. | 164 // Helper to remove cookies from a header. |
| 152 static std::string StripCookies(const std::string&); | 165 static std::string StripCookies(const std::string&); |
| 153 | 166 |
| 154 // Helper to remove cookie expiration from a header. | 167 // Helper to remove cookie expiration from a header. |
| 155 static std::string StripCookieExpiry(const std::string&); | 168 static std::string StripCookieExpiry(const std::string&); |
| 156 | 169 |
| 157 private: | 170 private: |
| 171 // Matches a pattern to a core URL which is host/path with all the other |
| 172 // optional parts (scheme, user, password, port) stripped away. Used only |
| 173 // internally but made static so that access can be given to tests. |
| 174 static bool Matches(const std::string& pattern, const std::string& url); |
| 175 |
| 158 std::vector<Entry*> blacklist_; | 176 std::vector<Entry*> blacklist_; |
| 159 std::vector<Provider*> providers_; | 177 std::vector<Provider*> providers_; |
| 160 | 178 |
| 161 FRIEND_TEST(BlacklistTest, Generic); | 179 FRIEND_TEST(BlacklistTest, Generic); |
| 180 FRIEND_TEST(BlacklistTest, PatternMatch); |
| 162 DISALLOW_COPY_AND_ASSIGN(Blacklist); | 181 DISALLOW_COPY_AND_ASSIGN(Blacklist); |
| 163 }; | 182 }; |
| 164 | 183 |
| 165 #endif | 184 #endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_H_ |
| OLD | NEW |