OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_RES
OURCE_THROTTLE_H_ |
| 6 #define COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_RES
OURCE_THROTTLE_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_u
i_manager.h" |
| 11 #include "content/public/browser/resource_throttle.h" |
| 12 #include "content/public/common/resource_type.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 namespace net { |
| 16 class URLRequest; |
| 17 } |
| 18 |
| 19 namespace data_reduction_proxy { |
| 20 |
| 21 class DataReductionProxyParams; |
| 22 class DataReductionProxyUIManager; |
| 23 class DataReductionProxyUIService; |
| 24 |
| 25 // Gets notified at various points during the process of loading a resource. |
| 26 // Defers the resource load when the Data Reduction Proxy is not going to be |
| 27 // used. Resumes or cancels a deferred resource load via the ResourceController. |
| 28 // |
| 29 // Displays a warning when the proxy will not be used for a request because it |
| 30 // isn't configured (a previous bypass) and when the proxy is supposed to be |
| 31 // used, but there is a connection error. Will not warn when the Data Reduction |
| 32 // Proxy is bypassed by local rules, or when the url scheme is not proxied by |
| 33 // the Data Reduction Proxy. |
| 34 // |
| 35 // This class is useful, e.g., for users that wish to be warned when |
| 36 // configurations that are able to go through the Data Reduction Proxy are |
| 37 // bypassed. |
| 38 // |
| 39 // TODO(megjablon): An interstitial cannot be displayed at the time of |
| 40 // WillProcessResponse. This prevents warning at the time when the Data |
| 41 // Reduction Proxy returns a response that triggers a bypass. Therefore this |
| 42 // interstitial is not shown for block=once bypasses. For other bypasses, the |
| 43 // interstitial is not not shown on the initial bypassed request, but on the |
| 44 // subsequent request. |
| 45 class DataReductionProxyResourceThrottle |
| 46 : public content::ResourceThrottle, |
| 47 public base::SupportsWeakPtr<DataReductionProxyResourceThrottle> { |
| 48 public: |
| 49 // Constructs a DataReductionProxyResourceThrottle object with the given |
| 50 // request, resource type, ui service, and params. |
| 51 DataReductionProxyResourceThrottle( |
| 52 const net::URLRequest* request, |
| 53 content::ResourceType resource_type, |
| 54 const DataReductionProxyUIService* ui_service, |
| 55 const DataReductionProxyParams* params); |
| 56 |
| 57 virtual ~DataReductionProxyResourceThrottle(); |
| 58 |
| 59 // Overrides content::ResourceThrottle. |
| 60 void WillStartUsingNetwork(bool* defer) override; |
| 61 void WillRedirectRequest(const GURL& new_url, bool* defer) override; |
| 62 const char* GetNameForLogging() const override; |
| 63 |
| 64 private: |
| 65 enum State { |
| 66 NOT_BYPASSED, // A warning has not been shown yet for this request. |
| 67 LOCAL_BYPASS, // The request was bypassed by local bypass rules. |
| 68 REMOTE_BYPASS, // The request was bypassed by the Data Reduction Proxy. |
| 69 }; |
| 70 |
| 71 // Starts displaying the Data Reduction Proxy blocking page if it is not |
| 72 // prerendering. Must only be called on the UI thread. Takes a bypass |
| 73 // resource, which is a structure used to pass parameters between the IO and |
| 74 // UI thread, and shows a DataReductionBlockingPage for the resource using |
| 75 // the given ui_manager. |
| 76 static void StartDisplayingBlockingPage( |
| 77 scoped_refptr<DataReductionProxyUIManager> ui_manager, |
| 78 const DataReductionProxyUIManager::BypassResource& resource); |
| 79 |
| 80 // Creates a bypass resource and calls StartDisplayingBlockingPage on the UI |
| 81 // thread. Sets defer to true. A bypass resource is a structure used to pass |
| 82 // parameters between the IO and UI thread when interacting with the |
| 83 // interstitial. Virtual for testing. |
| 84 virtual void DisplayBlockingPage(bool* defer); |
| 85 |
| 86 // Called on the IO thread when the user has decided to proceed with the |
| 87 // current request, or go back. |
| 88 void OnBlockingPageComplete(bool proceed); |
| 89 |
| 90 // The bypass state of this. |
| 91 State state_; |
| 92 |
| 93 // Must outlive |this|. |
| 94 const net::URLRequest* request_; |
| 95 |
| 96 // Holds the UI manager that shows interstitials. Must outlive |this|. |
| 97 const DataReductionProxyUIService* ui_service_; |
| 98 |
| 99 // Must outlive |this|. |
| 100 const DataReductionProxyParams* params_; |
| 101 |
| 102 const bool is_subresource_; |
| 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyResourceThrottle); |
| 105 }; |
| 106 |
| 107 } // namespace data_reduction_proxy |
| 108 |
| 109 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_
RESOURCE_THROTTLE_H_ |
OLD | NEW |