| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_POLICY_URL_BLACKLIST_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_URL_BLACKLIST_MANAGER_H_ |
| 6 #define CHROME_BROWSER_POLICY_URL_BLACKLIST_MANAGER_H_ | 6 #define CHROME_BROWSER_POLICY_URL_BLACKLIST_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 SCHEME_HTTP = 1 << 0, | 32 SCHEME_HTTP = 1 << 0, |
| 33 SCHEME_HTTPS = 1 << 1, | 33 SCHEME_HTTPS = 1 << 1, |
| 34 SCHEME_FTP = 1 << 2, | 34 SCHEME_FTP = 1 << 2, |
| 35 | 35 |
| 36 SCHEME_ALL = (1 << 3) - 1, | 36 SCHEME_ALL = (1 << 3) - 1, |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 URLBlacklist(); | 39 URLBlacklist(); |
| 40 virtual ~URLBlacklist(); | 40 virtual ~URLBlacklist(); |
| 41 | 41 |
| 42 // URLs matching |filter| will be blocked. | 42 // URLs matching |filter| will be blocked. The filter format is documented |
| 43 // at http://www.chromium.org/administrators/url-blacklist-filter-format |
| 43 void Block(const std::string& filter); | 44 void Block(const std::string& filter); |
| 44 | 45 |
| 45 // URLs matching |filter| will be allowed. If |filter| is both Blocked and | 46 // URLs matching |filter| will be allowed. If |filter| is both Blocked and |
| 46 // Allowed, Allow takes precedence. | 47 // Allowed, Allow takes precedence. |
| 47 void Allow(const std::string& filter); | 48 void Allow(const std::string& filter); |
| 48 | 49 |
| 49 // Returns true if the URL is blocked. | 50 // Returns true if the URL is blocked. |
| 50 bool IsURLBlocked(const GURL& url) const; | 51 bool IsURLBlocked(const GURL& url) const; |
| 51 | 52 |
| 52 // Returns true if |scheme| is a scheme that can be filtered. Returns true | 53 // Returns true if |scheme| is a scheme that can be filtered. Returns true |
| 53 // and sets |flag| to SCHEME_ALL if |scheme| is empty. | 54 // and sets |flag| to SCHEME_ALL if |scheme| is empty. |
| 54 static bool SchemeToFlag(const std::string& scheme, SchemeFlag* flag); | 55 static bool SchemeToFlag(const std::string& scheme, SchemeFlag* flag); |
| 55 | 56 |
| 56 // Splits a URL filter into its components. A GURL isn't used because these | 57 // Splits a URL filter into its components. A GURL isn't used because these |
| 57 // can be invalid URLs e.g. "google.com". | 58 // can be invalid URLs e.g. "google.com". |
| 58 // Returns false if the URL couldn't be parsed. | 59 // Returns false if the URL couldn't be parsed. |
| 59 // The optional username and password are ignored. | 60 // The optional username and password are ignored. |
| 60 // |port| is 0 if none is explicitly defined. | 61 // |port| is 0 if none is explicitly defined. |
| 61 // |path| does not include query parameters. | 62 // |path| does not include query parameters. |
| 62 static bool FilterToComponents(const std::string& filter, | 63 static bool FilterToComponents(const std::string& filter, |
| 63 std::string* scheme, | 64 std::string* scheme, |
| 64 std::string* host, | 65 std::string* host, |
| 65 uint16* port, | 66 uint16* port, |
| 66 std::string* path); | 67 std::string* path); |
| 67 private: | 68 private: |
| 68 struct PathFilter { | 69 struct PathFilter; |
| 69 explicit PathFilter(const std::string& path, uint16 port, bool match) | |
| 70 : path_prefix(path), | |
| 71 port(port), | |
| 72 blocked_schemes(0), | |
| 73 allowed_schemes(0), | |
| 74 match_subdomains(match) {} | |
| 75 | |
| 76 std::string path_prefix; | |
| 77 uint16 port; | |
| 78 uint8 blocked_schemes; | |
| 79 uint8 allowed_schemes; | |
| 80 bool match_subdomains; | |
| 81 }; | |
| 82 | 70 |
| 83 typedef std::vector<PathFilter> PathFilterList; | 71 typedef std::vector<PathFilter> PathFilterList; |
| 84 typedef base::hash_map<std::string, PathFilterList*> HostFilterTable; | 72 typedef base::hash_map<std::string, PathFilterList*> HostFilterTable; |
| 85 | 73 |
| 86 void AddFilter(const std::string& filter, bool block); | 74 void AddFilter(const std::string& filter, bool block); |
| 87 | 75 |
| 88 HostFilterTable host_filters_; | 76 HostFilterTable host_filters_; |
| 89 | 77 |
| 90 DISALLOW_COPY_AND_ASSIGN(URLBlacklist); | 78 DISALLOW_COPY_AND_ASSIGN(URLBlacklist); |
| 91 }; | 79 }; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 154 |
| 167 // The current blacklist. | 155 // The current blacklist. |
| 168 scoped_ptr<URLBlacklist> blacklist_; | 156 scoped_ptr<URLBlacklist> blacklist_; |
| 169 | 157 |
| 170 DISALLOW_COPY_AND_ASSIGN(URLBlacklistManager); | 158 DISALLOW_COPY_AND_ASSIGN(URLBlacklistManager); |
| 171 }; | 159 }; |
| 172 | 160 |
| 173 } // namespace policy | 161 } // namespace policy |
| 174 | 162 |
| 175 #endif // CHROME_BROWSER_POLICY_URL_BLACKLIST_MANAGER_H_ | 163 #endif // CHROME_BROWSER_POLICY_URL_BLACKLIST_MANAGER_H_ |
| OLD | NEW |