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/intranet_redirect_detector.h" | 5 #include "chrome/browser/intranet_redirect_detector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "content/public/common/content_url_request_user_data.h" |
16 #include "content/public/common/url_fetcher.h" | 17 #include "content/public/common/url_fetcher.h" |
17 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
19 #include "net/base/registry_controlled_domain.h" | 20 #include "net/base/registry_controlled_domain.h" |
20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
21 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
22 | 23 |
23 const size_t IntranetRedirectDetector::kNumCharsInHostnames = 10; | 24 const size_t IntranetRedirectDetector::kNumCharsInHostnames = 10; |
24 | 25 |
25 IntranetRedirectDetector::IntranetRedirectDetector() | 26 IntranetRedirectDetector::IntranetRedirectDetector() |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 std::string url_string("http://"); | 81 std::string url_string("http://"); |
81 for (size_t j = 0; j < kNumCharsInHostnames; ++j) | 82 for (size_t j = 0; j < kNumCharsInHostnames; ++j) |
82 url_string += ('a' + base::RandInt(0, 'z' - 'a')); | 83 url_string += ('a' + base::RandInt(0, 'z' - 'a')); |
83 GURL random_url(url_string + '/'); | 84 GURL random_url(url_string + '/'); |
84 content::URLFetcher* fetcher = content::URLFetcher::Create( | 85 content::URLFetcher* fetcher = content::URLFetcher::Create( |
85 random_url, content::URLFetcher::HEAD, this); | 86 random_url, content::URLFetcher::HEAD, this); |
86 // We don't want these fetches to affect existing state in the profile. | 87 // We don't want these fetches to affect existing state in the profile. |
87 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | | 88 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | |
88 net::LOAD_DO_NOT_SAVE_COOKIES); | 89 net::LOAD_DO_NOT_SAVE_COOKIES); |
89 fetcher->SetRequestContext(g_browser_process->system_request_context()); | 90 fetcher->SetRequestContext(g_browser_process->system_request_context()); |
| 91 // TODO(jochen): Do cookie audit. |
| 92 fetcher->SetContentURLRequestUserData( |
| 93 new content::ContentURLRequestUserData()); |
90 fetcher->Start(); | 94 fetcher->Start(); |
91 fetchers_.insert(fetcher); | 95 fetchers_.insert(fetcher); |
92 } | 96 } |
93 } | 97 } |
94 | 98 |
95 void IntranetRedirectDetector::OnURLFetchComplete( | 99 void IntranetRedirectDetector::OnURLFetchComplete( |
96 const content::URLFetcher* source) { | 100 const content::URLFetcher* source) { |
97 // Delete the fetcher on this function's exit. | 101 // Delete the fetcher on this function's exit. |
98 Fetchers::iterator fetcher = fetchers_.find( | 102 Fetchers::iterator fetcher = fetchers_.find( |
99 const_cast<content::URLFetcher*>(source)); | 103 const_cast<content::URLFetcher*>(source)); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // the same thread. So just use the heuristic that any all-lowercase a-z | 176 // the same thread. So just use the heuristic that any all-lowercase a-z |
173 // hostname with the right number of characters is likely from the detector | 177 // hostname with the right number of characters is likely from the detector |
174 // (and thus should be blocked). | 178 // (and thus should be blocked). |
175 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && | 179 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && |
176 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == | 180 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == |
177 std::string::npos)) ? | 181 std::string::npos)) ? |
178 net::ERR_NAME_NOT_RESOLVED : | 182 net::ERR_NAME_NOT_RESOLVED : |
179 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, | 183 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, |
180 os_error); | 184 os_error); |
181 } | 185 } |
OLD | NEW |