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 ffc8dacb602d8646f41a87fda11a62db2fe038d9..ab9ccc3aad50d44caa01f7cdd51d415b4083b519 100644 |
--- a/components/policy/core/browser/url_blacklist_manager.cc |
+++ b/components/policy/core/browser/url_blacklist_manager.cc |
@@ -26,6 +26,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 +205,16 @@ void URLBlacklist::Allow(const base::ListValue* filters) { |
} |
bool URLBlacklist::IsURLBlocked(const GURL& url) const { |
+ return URLBlacklist::GetURLBlacklistState(url) == |
+ net::NetworkDelegate::URLBlacklistState::URL_IN_BLACKLIST; |
bartfab (slow)
2016/03/10 13:49:41
Nit: Indent.
|
+} |
+ |
+net::NetworkDelegate::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 +224,19 @@ bool URLBlacklist::IsURLBlocked(const GURL& url) const { |
max = &filter; |
} |
- // Default to allow. |
+ // Default neutral. |
if (!max) |
- return false; |
+ return net::NetworkDelegate::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 net::NetworkDelegate::URLBlacklistState::URL_IN_WHITELIST; |
- return !max->allow; |
+ return max->allow ? |
+ net::NetworkDelegate::URLBlacklistState::URL_IN_WHITELIST : |
+ net::NetworkDelegate::URLBlacklistState::URL_IN_BLACKLIST; |
} |
size_t URLBlacklist::Size() const { |
@@ -245,7 +254,8 @@ bool URLBlacklist::FilterToComponents(SegmentURLCallback segment_url, |
std::string* query) { |
url::Parsed parsed; |
- if (segment_url(filter, &parsed) == url::kFileScheme) { |
+ std::string url_scheme = segment_url(filter, &parsed); |
bartfab (slow)
2016/03/10 13:49:41
Nit: const.
|
+ if (url_scheme == url::kFileScheme) { |
base::FilePath file_path; |
if (!net::FileURLToFilePath(GURL(filter), &file_path)) |
return false; |
@@ -264,8 +274,18 @@ bool URLBlacklist::FilterToComponents(SegmentURLCallback segment_url, |
return true; |
} |
- if (!parsed.host.is_nonempty()) |
+ if (!parsed.host.is_nonempty()) { |
+ // Check if a custom scheme pattern is defined. |
+ if (!url::IsStandard(url_scheme.c_str(), |
+ url::Component(0, |
+ static_cast<int>(url_scheme.length()))) && |
+ filter == url_scheme + "://*") { |
+ scheme->assign(url_scheme); |
+ return true; |
+ } |
+ |
return false; |
+ } |
if (parsed.scheme.is_nonempty()) |
scheme->assign(filter, parsed.scheme.begin, parsed.scheme.len); |
@@ -491,6 +511,12 @@ bool URLBlacklistManager::IsURLBlocked(const GURL& url) const { |
return blacklist_->IsURLBlocked(url); |
} |
+net::NetworkDelegate::URLBlacklistState |
+URLBlacklistManager::GetURLBlacklistState(const GURL& url) const { |
+ DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
bartfab (slow)
2016/03/10 13:49:41
Nit: #include "base/logging.h"
|
+ return blacklist_->GetURLBlacklistState(url); |
+} |
+ |
bool URLBlacklistManager::ShouldBlockRequestForFrame(const GURL& url, |
int* reason) const { |
DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |