Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / renderer_host / data_reduction_proxy_resource_throttle_android.h
blobda8adeabdc010283e2b9ad032f475bb669ae858f
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_RENDERER_HOST_DATA_REDUCTION_PROXY_RESOURCE_THROTTLE_ANDROID_H_
6 #define CHROME_BROWSER_RENDERER_HOST_DATA_REDUCTION_PROXY_RESOURCE_THROTTLE_ANDROID_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/ref_counted.h"
12 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
13 #include "chrome/browser/safe_browsing/ui_manager.h"
14 #include "content/public/browser/resource_throttle.h"
15 #include "content/public/common/resource_type.h"
17 namespace content {
18 class ResourceContext;
19 } // namespace content
21 namespace net {
22 struct RedirectInfo;
23 class URLRequest;
24 } // namepsace net
26 // DataReductionProxyResourceThrottle checks that URLs are "safe" before
27 // navigating to them. To be considered "safe", a URL must not be tagged as a
28 // phishing or malware URL by the SPDY proxy.
30 // If the URL is tagged as unsafe, a warning page is shown and the request
31 // remains suspended. If the user decides to cancel, the request is cancelled.
32 // If on the other hand the user decides the URL is safe, the request is
33 // resumed.
35 // The SPDY proxy and the browser make use of extra headers to communicate.
36 // When a proxy detects a malware or a phishing page, it injects a special
37 // header and returns a 307 redirect to the same location. If the user decides
38 // to proceed, the client injects a special header.
40 // Header Sent From Description
41 // X-Phishing-Url Proxy Identified as phishing url.
42 // X-Malware-Url Proxy Identified as malware url
43 // X-Unsafe-Url-Proceed Browser User requests proceed.
45 class DataReductionProxyResourceThrottle
46 : public content::ResourceThrottle,
47 public base::SupportsWeakPtr<DataReductionProxyResourceThrottle> {
48 public:
49 // Create a DataReductionProxyResourceThrottle. If it's not enabled
50 // or we can't process this request, will return NULL.
51 static DataReductionProxyResourceThrottle* MaybeCreate(
52 net::URLRequest* request,
53 content::ResourceContext* resource_context,
54 content::ResourceType resource_type,
55 SafeBrowsingService* sb_service);
57 DataReductionProxyResourceThrottle(net::URLRequest* request,
58 content::ResourceType resource_type,
59 SafeBrowsingService* safe_browsing);
61 // content::ResourceThrottle implementation (called on IO thread).
62 void WillRedirectRequest(const net::RedirectInfo& redirect_info,
63 bool* defer) override;
64 const char* GetNameForLogging() const override;
66 private:
67 // Describes what phase of the check a throttle is in.
68 enum State {
69 STATE_NONE,
70 STATE_DISPLAYING_BLOCKING_PAGE,
73 static const char* kUnsafeUrlProceedHeader;
75 ~DataReductionProxyResourceThrottle() override;
77 // SafeBrowsingService::UrlCheckCallback implementation.
78 void OnBlockingPageComplete(bool proceed);
80 // Returns the threat type.
81 SBThreatType CheckUrl();
83 // Starts displaying the safe browsing interstitial page if it is not
84 // prerendering. Called on the UI thread.
85 static void StartDisplayingBlockingPage(
86 const base::WeakPtr<DataReductionProxyResourceThrottle>& throttle,
87 scoped_refptr<SafeBrowsingUIManager> ui_manager,
88 const SafeBrowsingUIManager::UnsafeResource& resource);
90 // Resumes the request, by continuing the deferred action (either starting the
91 // request, or following a redirect).
92 void ResumeRequest();
94 State state_;
96 // The redirect chain for this resource.
97 std::vector<GURL> redirect_urls_;
99 scoped_refptr<SafeBrowsingService> safe_browsing_;
100 net::URLRequest* request_;
101 const bool is_subresource_;
102 const bool is_subframe_;
104 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyResourceThrottle);
107 #endif // CHROME_BROWSER_RENDERER_HOST_DATA_REDUCTION_PROXY_RESOURCE_THROTTLE_ANDROID_H_