Chromium Code Reviews| Index: chrome/browser/managed_mode/managed_mode_url_filter.cc |
| diff --git a/chrome/browser/managed_mode/managed_mode_url_filter.cc b/chrome/browser/managed_mode/managed_mode_url_filter.cc |
| index a77e180d4b47ca9797b226bc147ddb66d0d9f0b6..1dad2b74254bed81a3602b6412125fc8319ada6d 100644 |
| --- a/chrome/browser/managed_mode/managed_mode_url_filter.cc |
| +++ b/chrome/browser/managed_mode/managed_mode_url_filter.cc |
| @@ -159,7 +159,14 @@ scoped_ptr<ManagedModeURLFilter::Contents> LoadWhitelistsOnBlockingPoolThread( |
| ManagedModeURLFilter::ManagedModeURLFilter() |
| : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| default_behavior_(ALLOW), |
| - contents_(new Contents()) { |
| + contents_(new Contents()), |
| + url_manual_list_allow_(new policy::URLBlacklist()), |
| + url_manual_list_block_(new policy::URLBlacklist()) { |
| + // Initialize the manual whitelist to block everything, otherwise all the |
|
Pam (message me for reviews)
2013/01/09 12:00:41
Wait, what? Shouldn't the whitelist only ever allo
Sergiu
2013/01/09 13:04:23
Done.
|
| + // websites are allowed until SetManualLists is called. |
|
Bernhard Bauer
2013/01/09 12:01:36
I think this comment creates more confusion than i
Sergiu
2013/01/09 13:04:23
Done.
|
| + ListValue all_sites; |
| + all_sites.Append(new base::StringValue("*")); |
| + url_manual_list_allow_->Block(&all_sites); |
| // Detach from the current thread so we can be constructed on a different |
| // thread than the one where we're used. |
| DetachFromThread(); |
| @@ -191,6 +198,14 @@ ManagedModeURLFilter::GetFilteringBehaviorForURL(const GURL& url) const { |
| return ALLOW; |
| #endif |
| + // TODO(sergiu): Find a less confusing way to do this. Options include |
| + // renaming the functions in policy::URLBlacklist or adding a function that |
| + // checks if the URL is allowed instead of blocked. |
| + if (!url_manual_list_allow_->IsURLBlocked(url)) |
| + return ALLOW; |
| + if (url_manual_list_block_->IsURLBlocked(url)) |
| + return BLOCK; |
| + |
| // Check the list of URL patterns. |
| std::set<URLMatcherConditionSet::ID> matching_ids = |
| contents_->url_matcher.MatchURL(url); |
| @@ -266,6 +281,46 @@ void ManagedModeURLFilter::SetFromPatterns( |
| weak_ptr_factory_.GetWeakPtr(), continuation)); |
| } |
| +void ManagedModeURLFilter::SetManualLists(scoped_ptr<ListValue> whitelist, |
| + scoped_ptr<ListValue> blacklist){ |
| + DCHECK(CalledOnValidThread()); |
| + url_manual_list_block_.reset(new policy::URLBlacklist); |
| + url_manual_list_allow_.reset(new policy::URLBlacklist); |
| + url_manual_list_block_->Block(blacklist.get()); |
| + ListValue all_sites; |
| + all_sites.Append(new base::StringValue("*")); |
| + url_manual_list_allow_->Allow(whitelist.get()); |
| + url_manual_list_allow_->Block(&all_sites); |
| + |
| + // Debug |
| + DVLOG(1) << "Loaded whitelist: "; |
| + for (ListValue::iterator it = whitelist->begin(); |
| + it != whitelist->end(); ++it){ |
| + std::string item; |
| + (*it)->GetAsString(&item); |
| + DVLOG(1) << item; |
| + } |
| + DVLOG(1) << "Loaded blacklist: "; |
| + for (ListValue::iterator it = blacklist->begin(); |
| + it != blacklist->end(); ++it){ |
| + std::string item; |
| + (*it)->GetAsString(&item); |
| + DVLOG(1) << item; |
| + } |
| +} |
| + |
| +void ManagedModeURLFilter::AddURLPatternToManualList( |
| + const bool is_whitelist, |
| + const std::string& url) { |
| + DCHECK(CalledOnValidThread()); |
| + ListValue list; |
| + list.AppendString(url); |
| + if (is_whitelist) |
| + url_manual_list_allow_->Allow(&list); |
| + else |
| + url_manual_list_block_->Block(&list); |
| +} |
| + |
| void ManagedModeURLFilter::SetContents(const base::Closure& continuation, |
| scoped_ptr<Contents> contents) { |
| DCHECK(CalledOnValidThread()); |