summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host/safe_browsing_resource_handler.h
blob: a8492335fc89aa408c6dc1eb0b6393fca0ef062b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_HANDLER_H_
#define CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_HANDLER_H_

#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"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/common/notification_registrar.h"

// Checks that a url is safe.
class SafeBrowsingResourceHandler : public ResourceHandler,
                                    public SafeBrowsingService::Client,
                                    public NotificationObserver {
 public:
  SafeBrowsingResourceHandler(ResourceHandler* handler,
                              int render_process_host_id,
                              int render_view_id,
                              const GURL& url,
                              ResourceType::Type resource_type,
                              SafeBrowsingService* safe_browsing,
                              ResourceDispatcherHost* resource_dispatcher_host,
                              ResourceDispatcherHost::Receiver* receiver);
  ~SafeBrowsingResourceHandler();

  // ResourceHandler implementation:
  bool OnUploadProgress(int request_id, uint64 position, uint64 size);
  bool OnRequestRedirected(int request_id, const GURL& new_url,
                           ResourceResponse* response, bool* defer);
  bool OnResponseStarted(int request_id, ResourceResponse* response);
  void OnGetHashTimeout();
  bool OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size,
                  int min_size);
  bool OnReadCompleted(int request_id, int* bytes_read);
  bool OnResponseCompleted(int request_id,
                           const URLRequestStatus& status,
                           const std::string& security_info);

  // SafeBrowsingService::Client implementation, called on the IO thread once
  // the URL has been classified.
  void OnUrlCheckResult(const GURL& url,
                        SafeBrowsingService::UrlCheckResult result);

  // SafeBrowsingService::Client implementation, called on the IO thread when
  // the user has decided to proceed with the current request, or go back.
  void OnBlockingPageComplete(bool proceed);

  // NotificationObserver interface.
  void Observe(NotificationType type,
               const NotificationSource& source,
               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_;
  int render_view_id_;
  int paused_request_id_;  // -1 if not paused
  bool in_safe_browsing_check_;
  bool displaying_blocking_page_;
  SafeBrowsingService::UrlCheckResult safe_browsing_result_;
  scoped_refptr<SafeBrowsingService> safe_browsing_;
  scoped_ptr<URLRequestStatus> queued_error_;
  std::string queued_security_info_;
  int queued_error_request_id_;
  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);
};


#endif  // CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_HANDLER_H_