Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/task.h" | 17 #include "base/task.h" |
| 18 #include "chrome/browser/prefs/pref_change_registrar.h" | 18 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 19 #include "content/common/notification_observer.h" | 19 #include "content/common/notification_observer.h" |
| 20 | 20 |
| 21 class GURL; | 21 class GURL; |
| 22 class NotificationDetails; | 22 class NotificationDetails; |
| 23 class NotificationSource; | 23 class NotificationSource; |
| 24 class PrefService; | 24 class PrefService; |
| 25 | 25 |
| 26 namespace base { | |
| 27 class ListValue; | |
| 28 } | |
| 29 | |
| 30 namespace policy { | 26 namespace policy { |
| 31 | 27 |
| 32 // Contains a set of filters to block and allow certain URLs, and matches GURLs | 28 // Contains a set of filters to block and allow certain URLs, and matches GURLs |
| 33 // against this set. The filters are currently kept in memory. | 29 // against this set. The filters are currently kept in memory. |
| 34 class URLBlacklist { | 30 class URLBlacklist { |
| 35 public: | 31 public: |
| 32 // A constant mapped to a scheme that can be filtered. | |
| 33 enum SchemeFlag { | |
| 34 SCHEME_HTTP = 1 << 0, | |
| 35 SCHEME_HTTPS = 1 << 1, | |
| 36 SCHEME_FTP = 1 << 2, | |
| 37 | |
| 38 SCHEME_ALL = (1 << 3) - 1, | |
| 39 }; | |
| 40 | |
| 36 URLBlacklist(); | 41 URLBlacklist(); |
| 37 virtual ~URLBlacklist(); | 42 virtual ~URLBlacklist(); |
| 38 | 43 |
| 39 // URLs matching |filter| will be blocked. | 44 // URLs matching |filter| will be blocked. |
| 40 void Block(const std::string& filter); | 45 void Block(const std::string& filter); |
| 41 | 46 |
| 42 // URLs matching |filter| will be allowed. If |filter| is both Blocked and | 47 // URLs matching |filter| will be allowed. If |filter| is both Blocked and |
| 43 // Allowed, Allow takes precedence. | 48 // Allowed, Allow takes precedence. |
| 44 void Allow(const std::string& filter); | 49 void Allow(const std::string& filter); |
| 45 | 50 |
| 46 // Returns true if the URL is blocked. | 51 // Returns true if the URL is blocked. |
| 47 bool IsURLBlocked(const GURL& url) const; | 52 bool IsURLBlocked(const GURL& url) const; |
| 48 | 53 |
| 49 // A constant mapped to a scheme that can be filtered. | |
| 50 enum SchemeFlag { | |
| 51 SCHEME_HTTP = 1 << 0, | |
| 52 SCHEME_HTTPS = 1 << 1, | |
| 53 SCHEME_FTP = 1 << 2, | |
| 54 | |
| 55 SCHEME_ALL = (1 << 3) - 1, | |
| 56 }; | |
| 57 | |
| 58 // Returns true if |scheme| is a scheme that can be filtered. Returns true | 54 // Returns true if |scheme| is a scheme that can be filtered. Returns true |
| 59 // and sets |flag| to SCHEME_ALL if |scheme| is empty. | 55 // and sets |flag| to SCHEME_ALL if |scheme| is empty. |
| 60 static bool SchemeToFlag(const std::string& scheme, SchemeFlag* flag); | 56 static bool SchemeToFlag(const std::string& scheme, SchemeFlag* flag); |
| 61 | 57 |
| 62 // Splits a URL filter into its components. A GURL isn't used because these | 58 // Splits a URL filter into its components. A GURL isn't used because these |
| 63 // can be invalid URLs e.g. "google.com". | 59 // can be invalid URLs e.g. "google.com". |
| 64 // Returns false if the URL couldn't be parsed. | 60 // Returns false if the URL couldn't be parsed. |
| 65 // The optional username and password are ignored. | 61 // The optional username and password are ignored. |
| 66 // |port| is 0 if none is explicitly defined. | 62 // |port| is 0 if none is explicitly defined. |
| 67 // |path| does not include query parameters. | 63 // |path| does not include query parameters. |
| 68 static bool FilterToComponents(const std::string& filter, | 64 static bool FilterToComponents(const std::string& filter, |
| 69 std::string* scheme, | 65 std::string* scheme, |
| 70 std::string* host, | 66 std::string* host, |
| 71 uint16* port, | 67 uint16* port, |
| 72 std::string* path); | 68 std::string* path); |
| 73 private: | 69 private: |
| 74 void AddFilter(const std::string& filter, bool block); | |
| 75 | |
| 76 struct PathFilter { | 70 struct PathFilter { |
| 77 explicit PathFilter(const std::string& path, uint16 port, bool match) | 71 explicit PathFilter(const std::string& path, uint16 port, bool match) |
| 78 : path_prefix(path), | 72 : path_prefix(path), |
| 79 port(port), | 73 port(port), |
| 80 blocked_schemes(0), | 74 blocked_schemes(0), |
| 81 allowed_schemes(0), | 75 allowed_schemes(0), |
| 82 match_subdomains(match) {} | 76 match_subdomains(match) {} |
| 83 | 77 |
| 84 std::string path_prefix; | 78 std::string path_prefix; |
| 85 uint16 port; | 79 uint16 port; |
| 86 uint8 blocked_schemes; | 80 uint8 blocked_schemes; |
| 87 uint8 allowed_schemes; | 81 uint8 allowed_schemes; |
| 88 bool match_subdomains; | 82 bool match_subdomains; |
| 89 }; | 83 }; |
| 90 | 84 |
| 91 typedef std::vector<PathFilter> PathFilterList; | 85 typedef std::vector<PathFilter> PathFilterList; |
| 92 typedef base::hash_map<std::string, PathFilterList*> HostFilterTable; | 86 typedef base::hash_map<std::string, PathFilterList*> HostFilterTable; |
| 93 | 87 |
| 88 void AddFilter(const std::string& filter, bool block); | |
|
pastarmovj
2011/09/20 13:14:08
I hope rearranging the functions here was followed
Joao da Silva
2011/09/20 18:51:17
Done.
| |
| 89 | |
| 94 HostFilterTable host_filters_; | 90 HostFilterTable host_filters_; |
| 95 | 91 |
| 96 DISALLOW_COPY_AND_ASSIGN(URLBlacklist); | 92 DISALLOW_COPY_AND_ASSIGN(URLBlacklist); |
| 97 }; | 93 }; |
| 98 | 94 |
| 99 // Tracks the blacklist policies for a given profile, and updates it on changes. | 95 // Tracks the blacklist policies for a given profile, and updates it on changes. |
| 100 // | 96 // |
| 101 // This class interacts with both the UI thread, where notifications of pref | 97 // This class interacts with both the UI thread, where notifications of pref |
| 102 // changes are received from, and the IO thread, which owns it (in the | 98 // changes are received from, and the IO thread, which owns it (in the |
| 103 // ProfileIOData) and checks for blacklisted URLs (from ChromeNetworkDelegate). | 99 // ProfileIOData) and checks for blacklisted URLs (from ChromeNetworkDelegate). |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 | 166 |
| 171 // The current blacklist. | 167 // The current blacklist. |
| 172 scoped_ptr<URLBlacklist> blacklist_; | 168 scoped_ptr<URLBlacklist> blacklist_; |
| 173 | 169 |
| 174 DISALLOW_COPY_AND_ASSIGN(URLBlacklistManager); | 170 DISALLOW_COPY_AND_ASSIGN(URLBlacklistManager); |
| 175 }; | 171 }; |
| 176 | 172 |
| 177 } // namespace policy | 173 } // namespace policy |
| 178 | 174 |
| 179 #endif // CHROME_BROWSER_POLICY_URL_BLACKLIST_MANAGER_H_ | 175 #endif // CHROME_BROWSER_POLICY_URL_BLACKLIST_MANAGER_H_ |
| OLD | NEW |