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/renderer_host/safe_browsing_resource_throttle.h" | 5 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/prerender/prerender_contents.h" | 9 #include "chrome/browser/prerender/prerender_contents.h" |
10 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 10 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
13 #include "content/public/browser/resource_controller.h" | 13 #include "content/public/browser/resource_controller.h" |
14 #include "content/public/browser/resource_request_info.h" | 14 #include "content/public/browser/resource_request_info.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
17 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
18 | 18 |
19 // Maximum time in milliseconds to wait for the safe browsing service to | 19 // Maximum time in milliseconds to wait for the safe browsing service to |
20 // verify a URL. After this amount of time the outstanding check will be | 20 // verify a URL. After this amount of time the outstanding check will be |
21 // aborted, and the URL will be treated as if it were safe. | 21 // aborted, and the URL will be treated as if it were safe. |
22 static const int kCheckUrlTimeoutMs = 5000; | 22 static const int kCheckUrlTimeoutMs = 5000; |
23 | 23 |
24 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more | 24 // TODO(eroman): Downgrade these CHECK()s to DCHECKs once there is more |
25 // unit test coverage. | 25 // unit test coverage. |
26 | 26 |
27 SafeBrowsingResourceThrottle::SafeBrowsingResourceThrottle( | 27 SafeBrowsingResourceThrottle::SafeBrowsingResourceThrottle( |
28 const net::URLRequest* request, | 28 const net::URLRequest* request, |
29 bool is_subresource, | 29 content::ResourceType resource_type, |
30 SafeBrowsingService* safe_browsing) | 30 SafeBrowsingService* safe_browsing) |
31 : state_(STATE_NONE), | 31 : state_(STATE_NONE), |
32 defer_state_(DEFERRED_NONE), | 32 defer_state_(DEFERRED_NONE), |
33 threat_type_(SB_THREAT_TYPE_SAFE), | 33 threat_type_(SB_THREAT_TYPE_SAFE), |
34 database_manager_(safe_browsing->database_manager()), | 34 database_manager_(safe_browsing->database_manager()), |
35 ui_manager_(safe_browsing->ui_manager()), | 35 ui_manager_(safe_browsing->ui_manager()), |
36 request_(request), | 36 request_(request), |
37 is_subresource_(is_subresource) { | 37 is_subresource_(resource_type != content::RESOURCE_TYPE_MAIN_FRAME), |
| 38 is_subframe_(resource_type == content::RESOURCE_TYPE_SUB_FRAME) { |
38 } | 39 } |
39 | 40 |
40 SafeBrowsingResourceThrottle::~SafeBrowsingResourceThrottle() { | 41 SafeBrowsingResourceThrottle::~SafeBrowsingResourceThrottle() { |
41 if (state_ == STATE_CHECKING_URL) | 42 if (state_ == STATE_CHECKING_URL) |
42 database_manager_->CancelCheck(this); | 43 database_manager_->CancelCheck(this); |
43 } | 44 } |
44 | 45 |
45 void SafeBrowsingResourceThrottle::WillStartRequest(bool* defer) { | 46 void SafeBrowsingResourceThrottle::WillStartRequest(bool* defer) { |
46 // We need to check the new URL before starting the request. | 47 // We need to check the new URL before starting the request. |
47 if (CheckUrl(request_->url())) | 48 if (CheckUrl(request_->url())) |
(...skipping 25 matching lines...) Expand all Loading... |
73 *defer = true; | 74 *defer = true; |
74 } | 75 } |
75 | 76 |
76 const char* SafeBrowsingResourceThrottle::GetNameForLogging() const { | 77 const char* SafeBrowsingResourceThrottle::GetNameForLogging() const { |
77 return "SafeBrowsingResourceThrottle"; | 78 return "SafeBrowsingResourceThrottle"; |
78 } | 79 } |
79 | 80 |
80 // SafeBrowsingService::Client implementation, called on the IO thread once | 81 // SafeBrowsingService::Client implementation, called on the IO thread once |
81 // the URL has been classified. | 82 // the URL has been classified. |
82 void SafeBrowsingResourceThrottle::OnCheckBrowseUrlResult( | 83 void SafeBrowsingResourceThrottle::OnCheckBrowseUrlResult( |
83 const GURL& url, SBThreatType threat_type) { | 84 const GURL& url, |
| 85 SBThreatType threat_type, |
| 86 const std::string& metadata) { |
84 CHECK(state_ == STATE_CHECKING_URL); | 87 CHECK(state_ == STATE_CHECKING_URL); |
85 CHECK(defer_state_ != DEFERRED_NONE); | 88 CHECK(defer_state_ != DEFERRED_NONE); |
86 CHECK(url == url_being_checked_) << "Was expecting: " << url_being_checked_ | 89 CHECK(url == url_being_checked_) << "Was expecting: " << url_being_checked_ |
87 << " but got: " << url; | 90 << " but got: " << url; |
88 | 91 |
89 #if defined(OS_ANDROID) | 92 #if defined(OS_ANDROID) |
90 // Temporarily disable SB interstitial during Finch experiment. | 93 // Temporarily disable SB interstitial during Finch experiment. |
91 // The database check is still exercised, but the interstitial never shown. | 94 // The database check is still exercised, but the interstitial never shown. |
92 threat_type = SB_THREAT_TYPE_SAFE; | 95 threat_type = SB_THREAT_TYPE_SAFE; |
93 #endif | 96 #endif |
(...skipping 19 matching lines...) Expand all Loading... |
113 } | 116 } |
114 | 117 |
115 const content::ResourceRequestInfo* info = | 118 const content::ResourceRequestInfo* info = |
116 content::ResourceRequestInfo::ForRequest(request_); | 119 content::ResourceRequestInfo::ForRequest(request_); |
117 | 120 |
118 SafeBrowsingUIManager::UnsafeResource resource; | 121 SafeBrowsingUIManager::UnsafeResource resource; |
119 resource.url = url; | 122 resource.url = url; |
120 resource.original_url = request_->original_url(); | 123 resource.original_url = request_->original_url(); |
121 resource.redirect_urls = redirect_urls_; | 124 resource.redirect_urls = redirect_urls_; |
122 resource.is_subresource = is_subresource_; | 125 resource.is_subresource = is_subresource_; |
| 126 resource.is_subframe = is_subframe_; |
123 resource.threat_type = threat_type; | 127 resource.threat_type = threat_type; |
| 128 resource.threat_metadata = metadata; |
124 resource.callback = base::Bind( | 129 resource.callback = base::Bind( |
125 &SafeBrowsingResourceThrottle::OnBlockingPageComplete, AsWeakPtr()); | 130 &SafeBrowsingResourceThrottle::OnBlockingPageComplete, AsWeakPtr()); |
126 resource.render_process_host_id = info->GetChildID(); | 131 resource.render_process_host_id = info->GetChildID(); |
127 resource.render_view_id = info->GetRouteID(); | 132 resource.render_view_id = info->GetRouteID(); |
128 | 133 |
129 state_ = STATE_DISPLAYING_BLOCKING_PAGE; | 134 state_ = STATE_DISPLAYING_BLOCKING_PAGE; |
130 | 135 |
131 content::BrowserThread::PostTask( | 136 content::BrowserThread::PostTask( |
132 content::BrowserThread::UI, | 137 content::BrowserThread::UI, |
133 FROM_HERE, | 138 FROM_HERE, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 this, &SafeBrowsingResourceThrottle::OnCheckUrlTimeout); | 211 this, &SafeBrowsingResourceThrottle::OnCheckUrlTimeout); |
207 | 212 |
208 return false; | 213 return false; |
209 } | 214 } |
210 | 215 |
211 void SafeBrowsingResourceThrottle::OnCheckUrlTimeout() { | 216 void SafeBrowsingResourceThrottle::OnCheckUrlTimeout() { |
212 CHECK(state_ == STATE_CHECKING_URL); | 217 CHECK(state_ == STATE_CHECKING_URL); |
213 CHECK(defer_state_ != DEFERRED_NONE); | 218 CHECK(defer_state_ != DEFERRED_NONE); |
214 | 219 |
215 database_manager_->CancelCheck(this); | 220 database_manager_->CancelCheck(this); |
216 OnCheckBrowseUrlResult(url_being_checked_, SB_THREAT_TYPE_SAFE); | 221 OnCheckBrowseUrlResult( |
| 222 url_being_checked_, SB_THREAT_TYPE_SAFE, std::string()); |
217 } | 223 } |
218 | 224 |
219 void SafeBrowsingResourceThrottle::ResumeRequest() { | 225 void SafeBrowsingResourceThrottle::ResumeRequest() { |
220 CHECK(state_ == STATE_NONE); | 226 CHECK(state_ == STATE_NONE); |
221 CHECK(defer_state_ != DEFERRED_NONE); | 227 CHECK(defer_state_ != DEFERRED_NONE); |
222 | 228 |
223 defer_state_ = DEFERRED_NONE; | 229 defer_state_ = DEFERRED_NONE; |
224 controller()->Resume(); | 230 controller()->Resume(); |
225 } | 231 } |
OLD | NEW |