OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/managed_mode/managed_mode_url_filter.h" | 5 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/hash_tables.h" | 8 #include "base/hash_tables.h" |
9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 replacements.ClearPassword(); | 186 replacements.ClearPassword(); |
187 replacements.ClearQuery(); | 187 replacements.ClearQuery(); |
188 replacements.ClearRef(); | 188 replacements.ClearRef(); |
189 return url.ReplaceComponents(replacements); | 189 return url.ReplaceComponents(replacements); |
190 } | 190 } |
191 | 191 |
192 ManagedModeURLFilter::FilteringBehavior | 192 ManagedModeURLFilter::FilteringBehavior |
193 ManagedModeURLFilter::GetFilteringBehaviorForURL(const GURL& url) const { | 193 ManagedModeURLFilter::GetFilteringBehaviorForURL(const GURL& url) const { |
194 DCHECK(CalledOnValidThread()); | 194 DCHECK(CalledOnValidThread()); |
195 | 195 |
196 // If the default behavior is to allow, we don't need to check anything else. | |
197 if (default_behavior_ == ALLOW) | |
198 return ALLOW; | |
199 | |
200 #if defined(ENABLE_CONFIGURATION_POLICY) | 196 #if defined(ENABLE_CONFIGURATION_POLICY) |
201 // URLs with a non-standard scheme (e.g. chrome://) are always allowed. | 197 // URLs with a non-standard scheme (e.g. chrome://) are always allowed. |
202 if (!policy::URLBlacklist::HasStandardScheme(url)) | 198 if (!policy::URLBlacklist::HasStandardScheme(url)) |
203 return ALLOW; | 199 return ALLOW; |
204 #endif | 200 #endif |
205 | 201 |
206 // Check manual overrides for the exact URL. | 202 // Check manual overrides for the exact URL. |
207 std::map<GURL, bool>::const_iterator url_it = url_map_.find(Normalize(url)); | 203 std::map<GURL, bool>::const_iterator url_it = url_map_.find(Normalize(url)); |
208 if (url_it != url_map_.end()) | 204 if (url_it != url_map_.end()) |
209 return url_it->second ? ALLOW : BLOCK; | 205 return url_it->second ? ALLOW : BLOCK; |
210 | 206 |
211 // Check manual overrides for the hostname. | 207 // Check manual overrides for the hostname. |
212 std::map<std::string, bool>::const_iterator host_it = | 208 std::map<std::string, bool>::const_iterator host_it = |
213 host_map_.find(url.host()); | 209 host_map_.find(url.host()); |
214 if (host_it != host_map_.end()) | 210 if (host_it != host_map_.end()) |
215 return host_it->second ? ALLOW : BLOCK; | 211 return host_it->second ? ALLOW : BLOCK; |
216 | 212 |
| 213 // If the default behavior is to allow, we don't need to check anything else. |
| 214 if (default_behavior_ == ALLOW) |
| 215 return ALLOW; |
| 216 |
217 // Check the list of URL patterns. | 217 // Check the list of URL patterns. |
218 std::set<URLMatcherConditionSet::ID> matching_ids = | 218 std::set<URLMatcherConditionSet::ID> matching_ids = |
219 contents_->url_matcher.MatchURL(url); | 219 contents_->url_matcher.MatchURL(url); |
220 if (!matching_ids.empty()) | 220 if (!matching_ids.empty()) |
221 return ALLOW; | 221 return ALLOW; |
222 | 222 |
223 // Check the list of hostname hashes. | 223 // Check the list of hostname hashes. |
224 std::string hash = base::SHA1HashString(url.host()); | 224 std::string hash = base::SHA1HashString(url.host()); |
225 std::string hash_hex = base::HexEncode(hash.data(), hash.length()); | 225 std::string hash_hex = base::HexEncode(hash.data(), hash.length()); |
226 if (contents_->hash_site_map.count(hash_hex)) | 226 if (contents_->hash_site_map.count(hash_hex)) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 307 |
308 void ManagedModeURLFilter::RemoveObserver(Observer* observer) { | 308 void ManagedModeURLFilter::RemoveObserver(Observer* observer) { |
309 observers_.RemoveObserver(observer); | 309 observers_.RemoveObserver(observer); |
310 } | 310 } |
311 | 311 |
312 void ManagedModeURLFilter::SetContents(scoped_ptr<Contents> contents) { | 312 void ManagedModeURLFilter::SetContents(scoped_ptr<Contents> contents) { |
313 DCHECK(CalledOnValidThread()); | 313 DCHECK(CalledOnValidThread()); |
314 contents_ = contents.Pass(); | 314 contents_ = contents.Pass(); |
315 FOR_EACH_OBSERVER(Observer, observers_, OnSiteListUpdated()); | 315 FOR_EACH_OBSERVER(Observer, observers_, OnSiteListUpdated()); |
316 } | 316 } |
OLD | NEW |