File: data_reduction_proxy_resource_throttle_android.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (108 lines) | stat: -rw-r--r-- 4,062 bytes parent folder | download
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2015 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_LOADER_DATA_REDUCTION_PROXY_RESOURCE_THROTTLE_ANDROID_H_
#define CHROME_BROWSER_LOADER_DATA_REDUCTION_PROXY_RESOURCE_THROTTLE_ANDROID_H_

#include <string>
#include <vector>

#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/safe_browsing/ui_manager.h"
#include "content/public/browser/resource_throttle.h"
#include "content/public/common/resource_type.h"

namespace content {
class ResourceContext;
}  // namespace content

namespace net {
struct RedirectInfo;
class URLRequest;
}  // namepsace net

// DataReductionProxyResourceThrottle checks that URLs are "safe" before
// navigating to them. To be considered "safe", a URL must not be tagged as a
// phishing or malware URL by the SPDY proxy.
//
// If the URL is tagged as unsafe, a warning page is shown and the request
// remains suspended. If the user decides to cancel, the request is cancelled.
// If on the other hand the user decides the URL is safe, the request is
// resumed.
//
// The SPDY proxy and the browser make use of extra headers to communicate.
// When a proxy detects a malware or a phishing page, it injects a special
// header and returns a 307 redirect to the same location. If the user decides
// to proceed, the client injects a special header.
//
// Header              Sent From     Description
// X-Phishing-Url        Proxy      Identified as phishing url.
// X-Malware-Url         Proxy      Identified as malware url
// X-Unsafe-Url-Proceed  Browser    User requests proceed.
//
class DataReductionProxyResourceThrottle
    : public content::ResourceThrottle,
      public base::SupportsWeakPtr<DataReductionProxyResourceThrottle> {
 public:
  // Create a DataReductionProxyResourceThrottle.  If it's not enabled
  // or we can't process this request, will return NULL.
  static DataReductionProxyResourceThrottle* MaybeCreate(
      net::URLRequest* request,
      content::ResourceContext* resource_context,
      content::ResourceType resource_type,
      safe_browsing::SafeBrowsingService* sb_service);

  DataReductionProxyResourceThrottle(net::URLRequest* request,
                            content::ResourceType resource_type,
                            safe_browsing::SafeBrowsingService* safe_browsing);

  // content::ResourceThrottle implementation (called on IO thread).
  void WillRedirectRequest(const net::RedirectInfo& redirect_info,
                           bool* defer) override;
  const char* GetNameForLogging() const override;

 private:
  // Describes what phase of the check a throttle is in.
  enum State {
    STATE_NONE,
    STATE_DISPLAYING_BLOCKING_PAGE,
  };

  static const char* kUnsafeUrlProceedHeader;

  ~DataReductionProxyResourceThrottle() override;

  // SafeBrowsingService::UrlCheckCallback implementation.
  void OnBlockingPageComplete(bool proceed);

  // Returns the threat type.
  safe_browsing::SBThreatType CheckUrl();

  // Starts displaying the safe browsing interstitial page if it is not
  // prerendering. Called on the UI thread.
  static void StartDisplayingBlockingPage(
      const base::WeakPtr<DataReductionProxyResourceThrottle>& throttle,
      scoped_refptr<safe_browsing::SafeBrowsingUIManager> ui_manager,
      const security_interstitials::UnsafeResource& resource);

  // Resumes the request, by continuing the deferred action (either starting the
  // request, or following a redirect).
  void ResumeRequest();

  State state_;

  // The redirect chain for this resource.
  std::vector<GURL> redirect_urls_;

  scoped_refptr<safe_browsing::SafeBrowsingService> safe_browsing_;
  net::URLRequest* request_;
  const bool is_subresource_;
  const bool is_subframe_;

  DISALLOW_COPY_AND_ASSIGN(DataReductionProxyResourceThrottle);
};

#endif  // CHROME_BROWSER_LOADER_DATA_REDUCTION_PROXY_RESOURCE_THROTTLE_ANDROID_H_