summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-18 22:36:42 +0000
committerpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-18 22:36:42 +0000
commit6f004f1b37d04d790bd8d15575705bc4840ed74e (patch)
tree0d256c2e234289e9f30040957e746c1adfcb95f4 /chrome/browser
parentdb1df0f4ac4c9897992e3674574d229845f94b25 (diff)
downloadchromium_src-6f004f1b37d04d790bd8d15575705bc4840ed74e.zip
chromium_src-6f004f1b37d04d790bd8d15575705bc4840ed74e.tar.gz
chromium_src-6f004f1b37d04d790bd8d15575705bc4840ed74e.tar.bz2
Wait for the SafeBrowsing check to complete before following
a redirect. BUG=6442 TEST=None Review URL: http://codereview.chromium.org/165508 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23670 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/renderer_host/safe_browsing_resource_handler.cc41
-rw-r--r--chrome/browser/renderer_host/safe_browsing_resource_handler.h8
2 files changed, 45 insertions, 4 deletions
diff --git a/chrome/browser/renderer_host/safe_browsing_resource_handler.cc b/chrome/browser/renderer_host/safe_browsing_resource_handler.cc
index c215262..63cd46d 100644
--- a/chrome/browser/renderer_host/safe_browsing_resource_handler.cc
+++ b/chrome/browser/renderer_host/safe_browsing_resource_handler.cc
@@ -32,7 +32,8 @@ SafeBrowsingResourceHandler::SafeBrowsingResourceHandler(
safe_browsing_(safe_browsing),
queued_error_request_id_(-1),
rdh_(resource_dispatcher_host),
- resource_type_(resource_type) {
+ resource_type_(resource_type),
+ redirect_id_(-1) {
if (safe_browsing_->CheckUrl(url, this)) {
safe_browsing_result_ = SafeBrowsingService::URL_SAFE;
safe_browsing_->LogPauseDelay(base::TimeDelta()); // No delay.
@@ -62,9 +63,14 @@ bool SafeBrowsingResourceHandler::OnRequestRedirected(
ResourceResponse* response,
bool* defer) {
if (in_safe_browsing_check_) {
- Release();
- in_safe_browsing_check_ = false;
- safe_browsing_->CancelCheck(this);
+ // Defer following the redirect until the SafeBrowsing check is complete.
+ // Store the redirect context so we can pass it on to other handlers once we
+ // have completed our check.
+ redirect_response_ = response;
+ redirect_url_ = new_url;
+ redirect_id_ = request_id;
+ *defer = true;
+ return true;
}
if (safe_browsing_->CheckUrl(new_url, this)) {
@@ -151,6 +157,12 @@ void SafeBrowsingResourceHandler::OnUrlCheckResult(
in_safe_browsing_check_ = false;
if (result == SafeBrowsingService::URL_SAFE) {
+ // Resume following any redirect response we've deferred.
+ if (redirect_id_ != -1) {
+ ResumeRedirect();
+ return;
+ }
+
if (paused_request_id_ != -1) {
rdh_->PauseRequest(render_process_host_id_, paused_request_id_, false);
paused_request_id_ = -1;
@@ -185,6 +197,12 @@ void SafeBrowsingResourceHandler::OnBlockingPageComplete(bool proceed) {
displaying_blocking_page_ = false;
if (proceed) {
+ // Resume following any deferred redirect.
+ if (redirect_id_ != -1) {
+ ResumeRedirect();
+ return;
+ }
+
safe_browsing_result_ = SafeBrowsingService::URL_SAFE;
if (paused_request_id_ != -1) {
rdh_->PauseRequest(render_process_host_id_, paused_request_id_, false);
@@ -215,3 +233,18 @@ void SafeBrowsingResourceHandler::Observe(NotificationType type,
Release();
}
}
+
+void SafeBrowsingResourceHandler::ResumeRedirect() {
+ DCHECK(redirect_id_ != -1);
+
+ // Give the other resource handlers a chance to handle the redirect.
+ bool defer = false;
+ next_handler_->OnRequestRedirected(redirect_id_, redirect_url_,
+ redirect_response_, &defer);
+ if (!defer)
+ rdh_->FollowDeferredRedirect(render_process_host_id_, redirect_id_);
+
+ redirect_response_ = NULL;
+ redirect_id_ = -1;
+ Release();
+}
diff --git a/chrome/browser/renderer_host/safe_browsing_resource_handler.h b/chrome/browser/renderer_host/safe_browsing_resource_handler.h
index e2901e8..a849233 100644
--- a/chrome/browser/renderer_host/safe_browsing_resource_handler.h
+++ b/chrome/browser/renderer_host/safe_browsing_resource_handler.h
@@ -7,6 +7,7 @@
#include <string>
+#include "base/ref_counted.h"
#include "base/time.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/renderer_host/resource_handler.h"
@@ -56,6 +57,9 @@ class SafeBrowsingResourceHandler : public ResourceHandler,
const NotificationDetails& details);
private:
+ // Helper function for resuming the following of a redirect response.
+ void ResumeRedirect();
+
NotificationRegistrar registrar_;
scoped_refptr<ResourceHandler> next_handler_;
int render_process_host_id_;
@@ -71,6 +75,10 @@ class SafeBrowsingResourceHandler : public ResourceHandler,
ResourceDispatcherHost* rdh_;
base::Time pause_time_;
ResourceType::Type resource_type_;
+ // Context for handling deferred redirects.
+ scoped_refptr<ResourceResponse> redirect_response_;
+ GURL redirect_url_;
+ int redirect_id_;
DISALLOW_COPY_AND_ASSIGN(SafeBrowsingResourceHandler);
};