| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/safe_browsing/client_side_detection_service.h" | 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/task.h" | 15 #include "base/task.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 21 #include "chrome/common/net/http_return.h" | 21 #include "chrome/common/net/http_return.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/safe_browsing/client_model.pb.h" | 23 #include "chrome/common/safe_browsing/client_model.pb.h" |
| 24 #include "chrome/common/safe_browsing/csd.pb.h" | 24 #include "chrome/common/safe_browsing/csd.pb.h" |
| 25 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 25 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
| 26 #include "content/browser/browser_thread.h" | 26 #include "content/browser/browser_thread.h" |
| 27 #include "content/browser/renderer_host/render_process_host.h" | 27 #include "content/browser/renderer_host/render_process_host.h" |
| 28 #include "content/common/net/url_fetcher.h" |
| 28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 29 #include "content/public/browser/notification_types.h" | 30 #include "content/public/browser/notification_types.h" |
| 30 #include "crypto/sha2.h" | 31 #include "crypto/sha2.h" |
| 31 #include "googleurl/src/gurl.h" | 32 #include "googleurl/src/gurl.h" |
| 32 #include "net/base/load_flags.h" | 33 #include "net/base/load_flags.h" |
| 33 #include "net/http/http_response_headers.h" | 34 #include "net/http/http_response_headers.h" |
| 34 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
| 35 #include "net/url_request/url_request_status.h" | 36 #include "net/url_request/url_request_status.h" |
| 36 | 37 |
| 37 namespace safe_browsing { | 38 namespace safe_browsing { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 for (size_t i = 0; i < net::kIPv6AddressSize; ++i) { | 177 for (size_t i = 0; i < net::kIPv6AddressSize; ++i) { |
| 177 subnet[i] = ip_number[i] & mask[i]; | 178 subnet[i] = ip_number[i] & mask[i]; |
| 178 } | 179 } |
| 179 if (it->second.count(crypto::SHA256HashString(subnet)) > 0) { | 180 if (it->second.count(crypto::SHA256HashString(subnet)) > 0) { |
| 180 return true; | 181 return true; |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 return false; | 184 return false; |
| 184 } | 185 } |
| 185 | 186 |
| 186 void ClientSideDetectionService::OnURLFetchComplete( | 187 void ClientSideDetectionService::OnURLFetchComplete(const URLFetcher* source) { |
| 187 const URLFetcher* source, | 188 std::string data; |
| 188 const GURL& url, | 189 CHECK(source->GetResponseAsString(&data)); |
| 189 const net::URLRequestStatus& status, | |
| 190 int response_code, | |
| 191 const net::ResponseCookies& cookies, | |
| 192 const std::string& data) { | |
| 193 if (source == model_fetcher_.get()) { | 190 if (source == model_fetcher_.get()) { |
| 194 HandleModelResponse(source, url, status, response_code, cookies, data); | 191 HandleModelResponse( |
| 192 source, source->url(), source->status(), source->response_code(), |
| 193 source->cookies(), data); |
| 195 } else if (client_phishing_reports_.find(source) != | 194 } else if (client_phishing_reports_.find(source) != |
| 196 client_phishing_reports_.end()) { | 195 client_phishing_reports_.end()) { |
| 197 HandlePhishingVerdict(source, url, status, response_code, cookies, data); | 196 HandlePhishingVerdict( |
| 197 source, source->url(), source->status(), source->response_code(), |
| 198 source->cookies(), data); |
| 198 } else { | 199 } else { |
| 199 NOTREACHED(); | 200 NOTREACHED(); |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 | 203 |
| 203 void ClientSideDetectionService::Observe( | 204 void ClientSideDetectionService::Observe( |
| 204 int type, | 205 int type, |
| 205 const content::NotificationSource& source, | 206 const content::NotificationSource& source, |
| 206 const content::NotificationDetails& details) { | 207 const content::NotificationDetails& details) { |
| 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 &whitelist_patterns); | 574 &whitelist_patterns); |
| 574 for (size_t j = 0; j < whitelist_patterns.size(); ++j) { | 575 for (size_t j = 0; j < whitelist_patterns.size(); ++j) { |
| 575 if (whitelist_patterns[j] == canonical_url_as_pattern) { | 576 if (whitelist_patterns[j] == canonical_url_as_pattern) { |
| 576 return true; | 577 return true; |
| 577 } | 578 } |
| 578 } | 579 } |
| 579 } | 580 } |
| 580 return false; | 581 return false; |
| 581 } | 582 } |
| 582 } // namespace safe_browsing | 583 } // namespace safe_browsing |
| OLD | NEW |