Index: components/policy/core/browser/url_blacklist_manager.cc |
diff --git a/components/policy/core/browser/url_blacklist_manager.cc b/components/policy/core/browser/url_blacklist_manager.cc |
index 1ad8731fa8d2378b0a0394175ade24e45cc2ee30..fb0c50aea014fdc4b9b236fb11e2f7bef7b9a1ae 100644 |
--- a/components/policy/core/browser/url_blacklist_manager.cc |
+++ b/components/policy/core/browser/url_blacklist_manager.cc |
@@ -11,14 +11,17 @@ |
#include "base/bind.h" |
#include "base/files/file_path.h" |
#include "base/location.h" |
+#include "base/logging.h" |
#include "base/macros.h" |
#include "base/sequenced_task_runner.h" |
#include "base/single_thread_task_runner.h" |
#include "base/stl_util.h" |
#include "base/strings/string_number_conversions.h" |
+#include "base/strings/string_util.h" |
#include "base/task_runner_util.h" |
#include "base/threading/thread_task_runner_handle.h" |
#include "base/values.h" |
+#include "base/values.h" |
#include "components/policy/core/common/policy_pref_names.h" |
#include "components/pref_registry/pref_registry_syncable.h" |
#include "components/prefs/pref_service.h" |
@@ -26,6 +29,7 @@ |
#include "net/base/net_errors.h" |
#include "url/third_party/mozilla/url_parse.h" |
#include "url/url_constants.h" |
+#include "url/url_util.h" |
using url_matcher::URLMatcher; |
using url_matcher::URLMatcherCondition; |
@@ -204,10 +208,16 @@ void URLBlacklist::Allow(const base::ListValue* filters) { |
} |
bool URLBlacklist::IsURLBlocked(const GURL& url) const { |
+ return URLBlacklist::GetURLBlacklistState(url) == |
+ URLBlacklist::URLBlacklistState::URL_IN_BLACKLIST; |
+} |
+ |
+URLBlacklist::URLBlacklistState URLBlacklist::GetURLBlacklistState( |
+ const GURL& url) const { |
std::set<URLMatcherConditionSet::ID> matching_ids = |
url_matcher_->MatchURL(url); |
- const FilterComponents* max = NULL; |
+ const FilterComponents* max = nullptr; |
for (std::set<URLMatcherConditionSet::ID>::iterator id = matching_ids.begin(); |
id != matching_ids.end(); ++id) { |
std::map<int, FilterComponents>::const_iterator it = filters_.find(*id); |
@@ -217,17 +227,19 @@ bool URLBlacklist::IsURLBlocked(const GURL& url) const { |
max = &filter; |
} |
- // Default to allow. |
+ // Default neutral. |
if (!max) |
- return false; |
+ return URLBlacklist::URLBlacklistState::URL_NEUTRAL_STATE; |
// Some of the internal Chrome URLs are not affected by the "*" in the |
// blacklist. Note that the "*" is the lowest priority filter possible, so |
// any higher priority filter will be applied first. |
if (max->IsBlacklistWildcard() && BypassBlacklistWildcardForURL(url)) |
- return false; |
+ return URLBlacklist::URLBlacklistState::URL_IN_WHITELIST; |
- return !max->allow; |
+ return max->allow ? |
+ URLBlacklist::URLBlacklistState::URL_IN_WHITELIST : |
+ URLBlacklist::URLBlacklistState::URL_IN_BLACKLIST; |
} |
size_t URLBlacklist::Size() const { |
@@ -243,9 +255,17 @@ bool URLBlacklist::FilterToComponents(SegmentURLCallback segment_url, |
uint16_t* port, |
std::string* path, |
std::string* query) { |
+ DCHECK(scheme); |
+ DCHECK(host); |
+ DCHECK(match_subdomains); |
+ DCHECK(port); |
+ DCHECK(path); |
+ DCHECK(query); |
url::Parsed parsed; |
+ const std::string lc_filter = base::ToLowerASCII(filter); |
+ const std::string url_scheme = segment_url(filter, &parsed); |
- if (segment_url(filter, &parsed) == url::kFileScheme) { |
+ if (url_scheme == url::kFileScheme) { |
base::FilePath file_path; |
if (!net::FileURLToFilePath(GURL(filter), &file_path)) |
return false; |
@@ -254,8 +274,11 @@ bool URLBlacklist::FilterToComponents(SegmentURLCallback segment_url, |
host->clear(); |
*match_subdomains = true; |
*port = 0; |
- // Special path when the |filter| is 'file://*'. |
- *path = (filter == "file://*") ? "" : file_path.AsUTF8Unsafe(); |
+ // Special path when the |filter| is 'file://*' or 'file:*'. |
+ if (lc_filter == "file:*" || lc_filter == "file://*") { |
+ path->clear(); |
+ } else |
Andrew T Wilson (Slow)
2016/05/19 15:02:43
Since the if statement has {} you need it for the
igorcov
2016/05/19 15:25:13
Done.
|
+ *path = file_path.AsUTF8Unsafe(); |
#if defined(FILE_PATH_USES_WIN_SEPARATORS) |
// Separators have to be canonicalized on Windows. |
std::replace(path->begin(), path->end(), '\\', '/'); |
@@ -264,20 +287,35 @@ bool URLBlacklist::FilterToComponents(SegmentURLCallback segment_url, |
return true; |
} |
+ // Check if it's a scheme wildcard pattern. We support both versions |
+ // (scheme:* and scheme://*) the later being consistent with old filter |
+ // definitions. |
+ if (lc_filter == url_scheme + ":*" || lc_filter == url_scheme + "://*") { |
+ scheme->assign(url_scheme); |
+ host->clear(); |
+ *match_subdomains = true; |
+ *port = 0; |
+ path->clear(); |
+ query->clear(); |
+ return true; |
+ } |
+ |
+ // According to documentation host can't be empty. |
if (!parsed.host.is_nonempty()) |
return false; |
if (parsed.scheme.is_nonempty()) |
- scheme->assign(filter, parsed.scheme.begin, parsed.scheme.len); |
+ scheme->assign(url_scheme); |
else |
scheme->clear(); |
host->assign(filter, parsed.host.begin, parsed.host.len); |
+ *host = base::ToLowerASCII(*host); |
// Special '*' host, matches all hosts. |
if (*host == "*") { |
host->clear(); |
*match_subdomains = true; |
- } else if ((*host)[0] == '.') { |
+ } else if (host->at(0) == '.') { |
// A leading dot in the pattern syntax means that we don't want to match |
// subdomains. |
host->erase(0, 1); |
@@ -316,12 +354,10 @@ bool URLBlacklist::FilterToComponents(SegmentURLCallback segment_url, |
else |
path->clear(); |
- if (query) { |
- if (parsed.query.is_nonempty()) |
- query->assign(filter, parsed.query.begin, parsed.query.len); |
- else |
- query->clear(); |
- } |
+ if (parsed.query.is_nonempty()) |
+ query->assign(filter, parsed.query.begin, parsed.query.len); |
+ else |
+ query->clear(); |
return true; |
} |
@@ -492,6 +528,12 @@ bool URLBlacklistManager::IsURLBlocked(const GURL& url) const { |
return blacklist_->IsURLBlocked(url); |
} |
+URLBlacklist::URLBlacklistState URLBlacklistManager::GetURLBlacklistState( |
+ const GURL& url) const { |
+ DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
+ return blacklist_->GetURLBlacklistState(url); |
+} |
+ |
bool URLBlacklistManager::ShouldBlockRequestForFrame(const GURL& url, |
int* reason) const { |
DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |