| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/policy/core/browser/url_blacklist_manager.h" | 5 #include "components/policy/core/browser/url_blacklist_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 9 #include <limits> |
| 10 |
| 7 #include "base/bind.h" | 11 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 9 #include "base/location.h" | 13 #include "base/location.h" |
| 10 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 11 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
| 12 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 13 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/task_runner_util.h" | 19 #include "base/task_runner_util.h" |
| 16 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 134 |
| 131 // Returns true if |this| represents the "*" filter in the blacklist. | 135 // Returns true if |this| represents the "*" filter in the blacklist. |
| 132 bool IsBlacklistWildcard() const { | 136 bool IsBlacklistWildcard() const { |
| 133 return !allow && host.empty() && scheme.empty() && path.empty() && | 137 return !allow && host.empty() && scheme.empty() && path.empty() && |
| 134 query.empty() && port == 0 && number_of_key_value_pairs == 0 && | 138 query.empty() && port == 0 && number_of_key_value_pairs == 0 && |
| 135 match_subdomains; | 139 match_subdomains; |
| 136 } | 140 } |
| 137 | 141 |
| 138 std::string scheme; | 142 std::string scheme; |
| 139 std::string host; | 143 std::string host; |
| 140 uint16 port; | 144 uint16_t port; |
| 141 std::string path; | 145 std::string path; |
| 142 std::string query; | 146 std::string query; |
| 143 int number_of_key_value_pairs; | 147 int number_of_key_value_pairs; |
| 144 bool match_subdomains; | 148 bool match_subdomains; |
| 145 bool allow; | 149 bool allow; |
| 146 }; | 150 }; |
| 147 | 151 |
| 148 URLBlacklist::URLBlacklist(SegmentURLCallback segment_url) | 152 URLBlacklist::URLBlacklist(SegmentURLCallback segment_url) |
| 149 : segment_url_(segment_url), id_(0), url_matcher_(new URLMatcher) {} | 153 : segment_url_(segment_url), id_(0), url_matcher_(new URLMatcher) {} |
| 150 | 154 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 size_t URLBlacklist::Size() const { | 232 size_t URLBlacklist::Size() const { |
| 229 return filters_.size(); | 233 return filters_.size(); |
| 230 } | 234 } |
| 231 | 235 |
| 232 // static | 236 // static |
| 233 bool URLBlacklist::FilterToComponents(SegmentURLCallback segment_url, | 237 bool URLBlacklist::FilterToComponents(SegmentURLCallback segment_url, |
| 234 const std::string& filter, | 238 const std::string& filter, |
| 235 std::string* scheme, | 239 std::string* scheme, |
| 236 std::string* host, | 240 std::string* host, |
| 237 bool* match_subdomains, | 241 bool* match_subdomains, |
| 238 uint16* port, | 242 uint16_t* port, |
| 239 std::string* path, | 243 std::string* path, |
| 240 std::string* query) { | 244 std::string* query) { |
| 241 url::Parsed parsed; | 245 url::Parsed parsed; |
| 242 | 246 |
| 243 if (segment_url(filter, &parsed) == url::kFileScheme) { | 247 if (segment_url(filter, &parsed) == url::kFileScheme) { |
| 244 base::FilePath file_path; | 248 base::FilePath file_path; |
| 245 if (!net::FileURLToFilePath(GURL(filter), &file_path)) | 249 if (!net::FileURLToFilePath(GURL(filter), &file_path)) |
| 246 return false; | 250 return false; |
| 247 | 251 |
| 248 *scheme = url::kFileScheme; | 252 *scheme = url::kFileScheme; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 *match_subdomains = false; | 295 *match_subdomains = false; |
| 292 } | 296 } |
| 293 } | 297 } |
| 294 | 298 |
| 295 if (parsed.port.is_nonempty()) { | 299 if (parsed.port.is_nonempty()) { |
| 296 int int_port; | 300 int int_port; |
| 297 if (!base::StringToInt(filter.substr(parsed.port.begin, parsed.port.len), | 301 if (!base::StringToInt(filter.substr(parsed.port.begin, parsed.port.len), |
| 298 &int_port)) { | 302 &int_port)) { |
| 299 return false; | 303 return false; |
| 300 } | 304 } |
| 301 if (int_port <= 0 || int_port > kuint16max) | 305 if (int_port <= 0 || int_port > std::numeric_limits<uint16_t>::max()) |
| 302 return false; | 306 return false; |
| 303 *port = int_port; | 307 *port = int_port; |
| 304 } else { | 308 } else { |
| 305 // Match any port. | 309 // Match any port. |
| 306 *port = 0; | 310 *port = 0; |
| 307 } | 311 } |
| 308 | 312 |
| 309 if (parsed.path.is_nonempty()) | 313 if (parsed.path.is_nonempty()) |
| 310 path->assign(filter, parsed.path.begin, parsed.path.len); | 314 path->assign(filter, parsed.path.begin, parsed.path.len); |
| 311 else | 315 else |
| 312 path->clear(); | 316 path->clear(); |
| 313 | 317 |
| 314 if (query) { | 318 if (query) { |
| 315 if (parsed.query.is_nonempty()) | 319 if (parsed.query.is_nonempty()) |
| 316 query->assign(filter, parsed.query.begin, parsed.query.len); | 320 query->assign(filter, parsed.query.begin, parsed.query.len); |
| 317 else | 321 else |
| 318 query->clear(); | 322 query->clear(); |
| 319 } | 323 } |
| 320 | 324 |
| 321 return true; | 325 return true; |
| 322 } | 326 } |
| 323 | 327 |
| 324 // static | 328 // static |
| 325 scoped_refptr<URLMatcherConditionSet> URLBlacklist::CreateConditionSet( | 329 scoped_refptr<URLMatcherConditionSet> URLBlacklist::CreateConditionSet( |
| 326 URLMatcher* url_matcher, | 330 URLMatcher* url_matcher, |
| 327 int id, | 331 int id, |
| 328 const std::string& scheme, | 332 const std::string& scheme, |
| 329 const std::string& host, | 333 const std::string& host, |
| 330 bool match_subdomains, | 334 bool match_subdomains, |
| 331 uint16 port, | 335 uint16_t port, |
| 332 const std::string& path, | 336 const std::string& path, |
| 333 const std::string& query, | 337 const std::string& query, |
| 334 bool allow) { | 338 bool allow) { |
| 335 URLMatcherConditionFactory* condition_factory = | 339 URLMatcherConditionFactory* condition_factory = |
| 336 url_matcher->condition_factory(); | 340 url_matcher->condition_factory(); |
| 337 std::set<URLMatcherCondition> conditions; | 341 std::set<URLMatcherCondition> conditions; |
| 338 conditions.insert(match_subdomains ? | 342 conditions.insert(match_subdomains ? |
| 339 condition_factory->CreateHostSuffixPathPrefixCondition(host, path) : | 343 condition_factory->CreateHostSuffixPathPrefixCondition(host, path) : |
| 340 condition_factory->CreateHostEqualsPathPrefixCondition(host, path)); | 344 condition_factory->CreateHostEqualsPathPrefixCondition(host, path)); |
| 341 | 345 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 } | 505 } |
| 502 | 506 |
| 503 // static | 507 // static |
| 504 void URLBlacklistManager::RegisterProfilePrefs( | 508 void URLBlacklistManager::RegisterProfilePrefs( |
| 505 user_prefs::PrefRegistrySyncable* registry) { | 509 user_prefs::PrefRegistrySyncable* registry) { |
| 506 registry->RegisterListPref(policy_prefs::kUrlBlacklist); | 510 registry->RegisterListPref(policy_prefs::kUrlBlacklist); |
| 507 registry->RegisterListPref(policy_prefs::kUrlWhitelist); | 511 registry->RegisterListPref(policy_prefs::kUrlWhitelist); |
| 508 } | 512 } |
| 509 | 513 |
| 510 } // namespace policy | 514 } // namespace policy |
| OLD | NEW |