| 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 #include "chrome/browser/privacy_blacklist/blacklist.h" | 5 #include "chrome/browser/privacy_blacklist/blacklist.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 return kDontSendReferrer; | 53 return kDontSendReferrer; |
| 54 else if (s == STRINGIZE(kDontSendUserAgent)) | 54 else if (s == STRINGIZE(kDontSendUserAgent)) |
| 55 return kDontSendUserAgent; | 55 return kDontSendUserAgent; |
| 56 else if (s == STRINGIZE(kBlockByType)) | 56 else if (s == STRINGIZE(kBlockByType)) |
| 57 return kBlockByType; | 57 return kBlockByType; |
| 58 else if (s == STRINGIZE(kBlockUnsecure)) | 58 else if (s == STRINGIZE(kBlockUnsecure)) |
| 59 return kBlockUnsecure; | 59 return kBlockUnsecure; |
| 60 return 0; | 60 return 0; |
| 61 } | 61 } |
| 62 | 62 |
| 63 // static |
| 63 bool Blacklist::Matches(const std::string& pattern, const std::string& url) { | 64 bool Blacklist::Matches(const std::string& pattern, const std::string& url) { |
| 64 if (pattern.size() > url.size()) | 65 if (pattern.size() > url.size()) |
| 65 return false; | 66 return false; |
| 66 | 67 |
| 67 std::string::size_type p = 0; | 68 std::string::size_type p = 0; |
| 68 std::string::size_type u = 0; | 69 std::string::size_type u = 0; |
| 69 | 70 |
| 70 while (pattern[p] != '\0' && url[u] != '\0') { | 71 while (pattern[p] != '\0' && url[u] != '\0') { |
| 71 if (pattern[p] == '@') { | 72 if (pattern[p] == '@') { |
| 72 while (pattern[++p] == '@'); // Consecutive @ are redundant. | 73 while (pattern[++p] == '@'); // Consecutive @ are redundant. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 blacklist_.push_back(linked_ptr<Entry>(entry)); | 168 blacklist_.push_back(linked_ptr<Entry>(entry)); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void Blacklist::AddProvider(Provider* provider) { | 171 void Blacklist::AddProvider(Provider* provider) { |
| 171 DCHECK(provider); | 172 DCHECK(provider); |
| 172 providers_.push_back(linked_ptr<Provider>(provider)); | 173 providers_.push_back(linked_ptr<Provider>(provider)); |
| 173 } | 174 } |
| 174 | 175 |
| 175 // Returns a pointer to the Blacklist-owned entry which matches the given | 176 // Returns a pointer to the Blacklist-owned entry which matches the given |
| 176 // URL. If no matching Entry is found, returns null. | 177 // URL. If no matching Entry is found, returns null. |
| 177 Blacklist::Match* Blacklist::findMatch(const GURL& url) const { | 178 Blacklist::Match* Blacklist::FindMatch(const GURL& url) const { |
| 178 // Never match something which is not http, https or ftp. | 179 // Never match something which is not http, https or ftp. |
| 179 // TODO(idanan): Investigate if this would be an inclusion test instead of an | 180 // TODO(idanan): Investigate if this would be an inclusion test instead of an |
| 180 // exclusion test and if there are other schemes to test for. | 181 // exclusion test and if there are other schemes to test for. |
| 181 if (!url.SchemeIs(chrome::kHttpScheme) && | 182 if (!url.SchemeIs(chrome::kHttpScheme) && |
| 182 !url.SchemeIs(chrome::kHttpsScheme) && | 183 !url.SchemeIs(chrome::kHttpsScheme) && |
| 183 !url.SchemeIs(chrome::kFtpScheme)) | 184 !url.SchemeIs(chrome::kFtpScheme)) |
| 184 return 0; | 185 return 0; |
| 186 std::string url_spec = GetURLAsString(url); |
| 185 Match* match = NULL; | 187 Match* match = NULL; |
| 186 for (EntryList::const_iterator i = blacklist_.begin(); | 188 for (EntryList::const_iterator i = blacklist_.begin(); |
| 187 i != blacklist_.end(); ++i) { | 189 i != blacklist_.end(); ++i) { |
| 188 if (Matches((*i)->pattern(), url.host() + url.path())) { | 190 if (Matches((*i)->pattern(), url_spec)) { |
| 189 if (!match) | 191 if (!match) |
| 190 match = new Match; | 192 match = new Match; |
| 191 match->AddEntry(i->get()); | 193 match->AddEntry(i->get()); |
| 192 } | 194 } |
| 193 } | 195 } |
| 194 return match; | 196 return match; |
| 195 } | 197 } |
| 196 | 198 |
| 199 // static |
| 200 std::string Blacklist::GetURLAsString(const GURL& url) { |
| 201 std::string url_spec = url.host() + url.path(); |
| 202 if (!url.query().empty()) |
| 203 url_spec = url_spec + "?" + url.query(); |
| 204 |
| 205 return url_spec; |
| 206 } |
| 207 |
| 197 std::string Blacklist::StripCookies(const std::string& header) { | 208 std::string Blacklist::StripCookies(const std::string& header) { |
| 198 return net::HttpUtil::StripHeaders(header, cookie_headers, 2); | 209 return net::HttpUtil::StripHeaders(header, cookie_headers, 2); |
| 199 } | 210 } |
| 200 | 211 |
| 201 std::string Blacklist::StripCookieExpiry(const std::string& cookie) { | 212 std::string Blacklist::StripCookieExpiry(const std::string& cookie) { |
| 202 std::string::size_type delim = cookie.find(';'); | 213 std::string::size_type delim = cookie.find(';'); |
| 203 std::string::size_type start = cookie.find("expires=", delim + 1); | 214 std::string::size_type start = cookie.find("expires=", delim + 1); |
| 204 if (start != std::string::npos) { | 215 if (start != std::string::npos) { |
| 205 std::string::size_type i = start; | 216 std::string::size_type i = start; |
| 206 // Make sure only whitespace precedes the expiry until a delimiter. | 217 // Make sure only whitespace precedes the expiry until a delimiter. |
| 207 while (cookie[--i] != ';') | 218 while (cookie[--i] != ';') |
| 208 if (!IsAsciiWhitespace(cookie[i])) | 219 if (!IsAsciiWhitespace(cookie[i])) |
| 209 return cookie; | 220 return cookie; |
| 210 | 221 |
| 211 std::string session_cookie(cookie, 0, i); | 222 std::string session_cookie(cookie, 0, i); |
| 212 std::string::size_type end = cookie.find(';', start + 1); | 223 std::string::size_type end = cookie.find(';', start + 1); |
| 213 if (end != std::string::npos) | 224 if (end != std::string::npos) |
| 214 session_cookie.append(cookie.substr(end)); | 225 session_cookie.append(cookie.substr(end)); |
| 215 return session_cookie; | 226 return session_cookie; |
| 216 } | 227 } |
| 217 return cookie; | 228 return cookie; |
| 218 } | 229 } |
| OLD | NEW |