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/renderer_host/safe_browsing_resource_handler.h" | 5 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.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_final_status.h" | 9 #include "chrome/browser/prerender/prerender_final_status.h" |
10 #include "chrome/browser/prerender/prerender_tracker.h" | 10 #include "chrome/browser/prerender/prerender_tracker.h" |
11 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" | 11 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" |
12 #include "content/browser/renderer_host/global_request_id.h" | 12 #include "content/browser/renderer_host/global_request_id.h" |
13 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 13 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
14 #include "content/browser/renderer_host/resource_message_filter.h" | 14 #include "content/browser/renderer_host/resource_message_filter.h" |
15 #include "content/common/resource_response.h" | 15 #include "content/public/common/resource_response.h" |
16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
17 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
20 | 20 |
21 // Maximum time in milliseconds to wait for the safe browsing service to | 21 // Maximum time in milliseconds to wait for the safe browsing service to |
22 // verify a URL. After this amount of time the outstanding check will be | 22 // verify a URL. After this amount of time the outstanding check will be |
23 // aborted, and the URL will be treated as if it were safe. | 23 // aborted, and the URL will be treated as if it were safe. |
24 static const int kCheckUrlTimeoutMs = 5000; | 24 static const int kCheckUrlTimeoutMs = 5000; |
25 | 25 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 bool SafeBrowsingResourceHandler::OnUploadProgress(int request_id, | 64 bool SafeBrowsingResourceHandler::OnUploadProgress(int request_id, |
65 uint64 position, | 65 uint64 position, |
66 uint64 size) { | 66 uint64 size) { |
67 return next_handler_->OnUploadProgress(request_id, position, size); | 67 return next_handler_->OnUploadProgress(request_id, position, size); |
68 } | 68 } |
69 | 69 |
70 bool SafeBrowsingResourceHandler::OnRequestRedirected( | 70 bool SafeBrowsingResourceHandler::OnRequestRedirected( |
71 int request_id, | 71 int request_id, |
72 const GURL& new_url, | 72 const GURL& new_url, |
73 ResourceResponse* response, | 73 content::ResourceResponse* response, |
74 bool* defer) { | 74 bool* defer) { |
75 CHECK(state_ == STATE_NONE); | 75 CHECK(state_ == STATE_NONE); |
76 CHECK(defer_state_ == DEFERRED_NONE); | 76 CHECK(defer_state_ == DEFERRED_NONE); |
77 | 77 |
78 // Save the redirect urls for possible malware detail reporting later. | 78 // Save the redirect urls for possible malware detail reporting later. |
79 redirect_urls_.push_back(new_url); | 79 redirect_urls_.push_back(new_url); |
80 | 80 |
81 // We need to check the new URL before following the redirect. | 81 // We need to check the new URL before following the redirect. |
82 if (CheckUrl(new_url)) { | 82 if (CheckUrl(new_url)) { |
83 return next_handler_->OnRequestRedirected( | 83 return next_handler_->OnRequestRedirected( |
84 request_id, new_url, response, defer); | 84 request_id, new_url, response, defer); |
85 } | 85 } |
86 | 86 |
87 // If the URL couldn't be verified synchronously, defer following the | 87 // If the URL couldn't be verified synchronously, defer following the |
88 // redirect until the SafeBrowsing check is complete. Store the redirect | 88 // redirect until the SafeBrowsing check is complete. Store the redirect |
89 // context so we can pass it on to other handlers once we have completed | 89 // context so we can pass it on to other handlers once we have completed |
90 // our check. | 90 // our check. |
91 defer_state_ = DEFERRED_REDIRECT; | 91 defer_state_ = DEFERRED_REDIRECT; |
92 deferred_request_id_ = request_id; | 92 deferred_request_id_ = request_id; |
93 deferred_url_ = new_url; | 93 deferred_url_ = new_url; |
94 deferred_redirect_response_ = response; | 94 deferred_redirect_response_ = response; |
95 *defer = true; | 95 *defer = true; |
96 | 96 |
97 return true; | 97 return true; |
98 } | 98 } |
99 | 99 |
100 bool SafeBrowsingResourceHandler::OnResponseStarted( | 100 bool SafeBrowsingResourceHandler::OnResponseStarted( |
101 int request_id, ResourceResponse* response) { | 101 int request_id, content::ResourceResponse* response) { |
102 CHECK(state_ == STATE_NONE); | 102 CHECK(state_ == STATE_NONE); |
103 CHECK(defer_state_ == DEFERRED_NONE); | 103 CHECK(defer_state_ == DEFERRED_NONE); |
104 return next_handler_->OnResponseStarted(request_id, response); | 104 return next_handler_->OnResponseStarted(request_id, response); |
105 } | 105 } |
106 | 106 |
107 void SafeBrowsingResourceHandler::OnCheckUrlTimeout() { | 107 void SafeBrowsingResourceHandler::OnCheckUrlTimeout() { |
108 CHECK(state_ == STATE_CHECKING_URL); | 108 CHECK(state_ == STATE_CHECKING_URL); |
109 CHECK(defer_state_ != DEFERRED_NONE); | 109 CHECK(defer_state_ != DEFERRED_NONE); |
110 safe_browsing_->CancelCheck(this); | 110 safe_browsing_->CancelCheck(this); |
111 OnBrowseUrlCheckResult(deferred_url_, SafeBrowsingService::SAFE); | 111 OnBrowseUrlCheckResult(deferred_url_, SafeBrowsingService::SAFE); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 rdh_->StartDeferredRequest(render_process_host_id_, request_id); | 327 rdh_->StartDeferredRequest(render_process_host_id_, request_id); |
328 } | 328 } |
329 | 329 |
330 void SafeBrowsingResourceHandler::ResumeRedirect() { | 330 void SafeBrowsingResourceHandler::ResumeRedirect() { |
331 CHECK(defer_state_ == DEFERRED_REDIRECT); | 331 CHECK(defer_state_ == DEFERRED_REDIRECT); |
332 defer_state_ = DEFERRED_NONE; | 332 defer_state_ = DEFERRED_NONE; |
333 | 333 |
334 // Retrieve the details for the paused OnReceivedRedirect(). | 334 // Retrieve the details for the paused OnReceivedRedirect(). |
335 int request_id = deferred_request_id_; | 335 int request_id = deferred_request_id_; |
336 GURL redirect_url = deferred_url_; | 336 GURL redirect_url = deferred_url_; |
337 scoped_refptr<ResourceResponse> redirect_response = | 337 scoped_refptr<content::ResourceResponse> redirect_response = |
338 deferred_redirect_response_; | 338 deferred_redirect_response_; |
339 | 339 |
340 ClearDeferredRequestInfo(); | 340 ClearDeferredRequestInfo(); |
341 | 341 |
342 // Give the other resource handlers a chance to handle the redirect. | 342 // Give the other resource handlers a chance to handle the redirect. |
343 bool defer = false; | 343 bool defer = false; |
344 // TODO(eroman): the return value is being lost here. Should | 344 // TODO(eroman): the return value is being lost here. Should |
345 // use it to cancel the request. | 345 // use it to cancel the request. |
346 next_handler_->OnRequestRedirected(request_id, redirect_url, | 346 next_handler_->OnRequestRedirected(request_id, redirect_url, |
347 redirect_response, &defer); | 347 redirect_response, &defer); |
348 if (!defer) { | 348 if (!defer) { |
349 rdh_->FollowDeferredRedirect(render_process_host_id_, request_id, | 349 rdh_->FollowDeferredRedirect(render_process_host_id_, request_id, |
350 false, GURL()); | 350 false, GURL()); |
351 } | 351 } |
352 } | 352 } |
353 | 353 |
354 void SafeBrowsingResourceHandler::ClearDeferredRequestInfo() { | 354 void SafeBrowsingResourceHandler::ClearDeferredRequestInfo() { |
355 deferred_request_id_ = -1; | 355 deferred_request_id_ = -1; |
356 deferred_url_ = GURL(); | 356 deferred_url_ = GURL(); |
357 deferred_redirect_response_ = NULL; | 357 deferred_redirect_response_ = NULL; |
358 } | 358 } |
OLD | NEW |