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/policy/url_blacklist_manager.h" | 5 #include "chrome/browser/policy/url_blacklist_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/net/url_fixer_upper.h" | 13 #include "chrome/browser/net/url_fixer_upper.h" |
14 #include "chrome/browser/signin/signin_manager.h" | |
15 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
17 #include "components/user_prefs/pref_registry_syncable.h" | 16 #include "components/user_prefs/pref_registry_syncable.h" |
18 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
20 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
21 #include "google_apis/gaia/gaia_urls.h" | 20 #include "google_apis/gaia/gaia_urls.h" |
22 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
23 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
24 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
25 | 24 |
| 25 #if !defined(OS_CHROMEOS) |
| 26 #include "chrome/browser/signin/signin_manager.h" |
| 27 #endif |
| 28 |
26 using content::BrowserThread; | 29 using content::BrowserThread; |
27 using extensions::URLMatcher; | 30 using extensions::URLMatcher; |
28 using extensions::URLMatcherCondition; | 31 using extensions::URLMatcherCondition; |
29 using extensions::URLMatcherConditionFactory; | 32 using extensions::URLMatcherConditionFactory; |
30 using extensions::URLMatcherConditionSet; | 33 using extensions::URLMatcherConditionSet; |
31 using extensions::URLMatcherPortFilter; | 34 using extensions::URLMatcherPortFilter; |
32 using extensions::URLMatcherSchemeFilter; | 35 using extensions::URLMatcherSchemeFilter; |
33 | 36 |
34 namespace policy { | 37 namespace policy { |
35 | 38 |
(...skipping 15 matching lines...) Expand all Loading... |
51 const char kServiceLoginAuth[] = "/ServiceLoginAuth"; | 54 const char kServiceLoginAuth[] = "/ServiceLoginAuth"; |
52 | 55 |
53 bool IsStandardScheme(const std::string& scheme) { | 56 bool IsStandardScheme(const std::string& scheme) { |
54 for (size_t i = 0; i < arraysize(kStandardSchemes); ++i) { | 57 for (size_t i = 0; i < arraysize(kStandardSchemes); ++i) { |
55 if (scheme == kStandardSchemes[i]) | 58 if (scheme == kStandardSchemes[i]) |
56 return true; | 59 return true; |
57 } | 60 } |
58 return false; | 61 return false; |
59 } | 62 } |
60 | 63 |
| 64 #if !defined(OS_CHROMEOS) |
| 65 |
61 bool IsSigninFlowURL(const GURL& url) { | 66 bool IsSigninFlowURL(const GURL& url) { |
62 // Whitelist all the signin flow URLs flagged by the SigninManager. | 67 // Whitelist all the signin flow URLs flagged by the SigninManager. |
63 if (SigninManager::IsWebBasedSigninFlowURL(url)) | 68 if (SigninManager::IsWebBasedSigninFlowURL(url)) |
64 return true; | 69 return true; |
65 | 70 |
66 // Additionally whitelist /ServiceLoginAuth. | 71 // Additionally whitelist /ServiceLoginAuth. |
67 if (url.GetOrigin() != GURL(GaiaUrls::GetInstance()->gaia_origin_url())) | 72 if (url.GetOrigin() != GURL(GaiaUrls::GetInstance()->gaia_origin_url())) |
68 return false; | 73 return false; |
69 return url.path() == kServiceLoginAuth; | 74 return url.path() == kServiceLoginAuth; |
70 } | 75 } |
71 | 76 |
| 77 #endif // !defined(OS_CHROMEOS) |
| 78 |
72 // A task that builds the blacklist on the FILE thread. | 79 // A task that builds the blacklist on the FILE thread. |
73 scoped_ptr<URLBlacklist> BuildBlacklist(scoped_ptr<base::ListValue> block, | 80 scoped_ptr<URLBlacklist> BuildBlacklist(scoped_ptr<base::ListValue> block, |
74 scoped_ptr<base::ListValue> allow) { | 81 scoped_ptr<base::ListValue> allow) { |
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
76 | 83 |
77 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist); | 84 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist); |
78 blacklist->Block(block.get()); | 85 blacklist->Block(block.get()); |
79 blacklist->Allow(allow.get()); | 86 blacklist->Allow(allow.get()); |
80 return blacklist.Pass(); | 87 return blacklist.Pass(); |
81 } | 88 } |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
376 return blacklist_->IsURLBlocked(url); | 383 return blacklist_->IsURLBlocked(url); |
377 } | 384 } |
378 | 385 |
379 bool URLBlacklistManager::IsRequestBlocked( | 386 bool URLBlacklistManager::IsRequestBlocked( |
380 const net::URLRequest& request) const { | 387 const net::URLRequest& request) const { |
381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
382 int filter_flags = net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME; | 389 int filter_flags = net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME; |
383 if ((request.load_flags() & filter_flags) == 0) | 390 if ((request.load_flags() & filter_flags) == 0) |
384 return false; | 391 return false; |
| 392 |
| 393 #if !defined(OS_CHROMEOS) |
385 if (IsSigninFlowURL(request.url())) | 394 if (IsSigninFlowURL(request.url())) |
386 return false; | 395 return false; |
| 396 #endif |
| 397 |
387 return IsURLBlocked(request.url()); | 398 return IsURLBlocked(request.url()); |
388 } | 399 } |
389 | 400 |
390 // static | 401 // static |
391 void URLBlacklistManager::RegisterUserPrefs(PrefRegistrySyncable* registry) { | 402 void URLBlacklistManager::RegisterUserPrefs(PrefRegistrySyncable* registry) { |
392 registry->RegisterListPref(prefs::kUrlBlacklist, | 403 registry->RegisterListPref(prefs::kUrlBlacklist, |
393 PrefRegistrySyncable::UNSYNCABLE_PREF); | 404 PrefRegistrySyncable::UNSYNCABLE_PREF); |
394 registry->RegisterListPref(prefs::kUrlWhitelist, | 405 registry->RegisterListPref(prefs::kUrlWhitelist, |
395 PrefRegistrySyncable::UNSYNCABLE_PREF); | 406 PrefRegistrySyncable::UNSYNCABLE_PREF); |
396 } | 407 } |
397 | 408 |
398 } // namespace policy | 409 } // namespace policy |
OLD | NEW |