OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_r esource_throttle.h" | |
6 | |
7 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_u i_service.h" | |
8 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | |
9 #include "content/public/browser/browser_thread.h" | |
10 #include "content/public/browser/resource_controller.h" | |
11 #include "content/public/browser/resource_request_info.h" | |
12 #include "net/base/load_flags.h" | |
13 #include "net/http/http_response_headers.h" | |
14 #include "net/url_request/url_request.h" | |
15 | |
16 namespace data_reduction_proxy { | |
17 | |
18 namespace { | |
19 | |
20 const char kResouceThrottleLogName[] = "DataReductionProxyResourceThrottle"; | |
21 | |
22 } // namespace | |
23 | |
24 DataReductionProxyResourceThrottle::DataReductionProxyResourceThrottle( | |
25 const net::URLRequest* request, | |
26 content::ResourceType resource_type, | |
27 const DataReductionProxyUIService* ui_service, | |
28 const DataReductionProxyParams* params) | |
29 : state_(NOT_BYPASSED), | |
30 request_(request), | |
31 ui_service_(ui_service), | |
32 params_(params), | |
33 is_subresource_(resource_type != content::RESOURCE_TYPE_MAIN_FRAME) { | |
34 DCHECK(request); | |
35 DCHECK(ui_service); | |
36 DCHECK(params); | |
37 } | |
38 | |
39 DataReductionProxyResourceThrottle::~DataReductionProxyResourceThrottle() { | |
40 } | |
41 | |
42 // Enforces warning when the proxy will not be used for a request because it | |
bengr
2014/12/31 01:10:21
What does "Enforces warning" mean? Please reword.
megjablon
2014/12/31 02:12:28
Done.
| |
43 // isn't configured. | |
44 void DataReductionProxyResourceThrottle::WillStartUsingNetwork(bool* defer) { | |
45 DCHECK(state_ == NOT_BYPASSED); | |
46 if (!params_->AreDataReductionProxiesBypassed(*request_, NULL)) | |
47 return; | |
48 if (request_->load_flags() & net::LOAD_PREFETCH) { | |
49 // Don't prefetch resources that bypass, disallow them. | |
50 controller()->Cancel(); | |
51 return; | |
52 } | |
53 // Do not display a blocking page if the data reduction proxy is bypassed by | |
bengr
2014/12/31 01:10:21
"a blocking page" -> "the interstitial"
"if the da
megjablon
2014/12/31 02:12:28
Done.
| |
54 // local rules. | |
55 if (params_->IsBypassedByDataReductionProxyLocalRules( | |
56 *request_, ui_service_->data_reduction_proxy_config())) { | |
57 state_ = LOCAL_BYPASS; | |
58 return; | |
59 } | |
60 DisplayBlockingPage(defer); | |
61 } | |
62 | |
63 // Enforces warning when the data reduction proxy explicitly returns a response | |
bengr
2014/12/31 01:10:21
Reword "enforces warning" here too.
megjablon
2014/12/31 02:12:28
Done.
| |
64 // that triggers a bypass. | |
65 void DataReductionProxyResourceThrottle::WillRedirectRequest( | |
66 const GURL& new_url, | |
67 bool* defer) { | |
68 // If we have already shown the interstitial, do not show it again. The | |
69 // LOAD_BYPASS_PROXY flag makes it so that we do not resolve proxies. This | |
70 // override is used when downloading PAC files. If the request does not have | |
71 // the LOAD_BYPASS_PROXY flag, do not show the interstitial. | |
72 if (state_ != NOT_BYPASSED || | |
73 !(request_->load_flags() & net::LOAD_BYPASS_PROXY)) { | |
74 return; | |
75 } | |
76 DisplayBlockingPage(defer); | |
77 } | |
78 | |
79 // We already checked if the proxy is bypassed by local rules and if the data | |
bengr
2014/12/31 01:10:21
Rewrite to remove all instances of "we".
Capitaliz
megjablon
2014/12/31 02:12:28
Done.
| |
80 // reduction proxy sent an explicit bypass. If the response isn't from the data | |
81 // reduction proxy and the scheme type can be proxied by the data reduction | |
82 // proxy we have a connection error, display the blocking page. | |
83 void DataReductionProxyResourceThrottle::WillProcessResponse(bool* defer) { | |
84 if (state_ != NOT_BYPASSED) | |
85 return; | |
86 if (params_->IsDataReductionProxy(request_->proxy_server(), NULL) || | |
87 !DataReductionProxyParams::CanProxyURLScheme(request_->url())) { | |
88 return; | |
89 } | |
90 DisplayBlockingPage(defer); | |
91 } | |
92 | |
93 const char* DataReductionProxyResourceThrottle::GetNameForLogging() const { | |
94 return kResouceThrottleLogName; | |
bengr
2014/12/31 01:10:21
indent -2.
megjablon
2014/12/31 02:12:28
Done.
| |
95 } | |
96 | |
97 // static | |
98 void DataReductionProxyResourceThrottle::StartDisplayingBlockingPage( | |
99 scoped_refptr<DataReductionProxyUIManager> ui_manager, | |
100 const DataReductionProxyUIManager::BypassResource& resource) { | |
101 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
102 ui_manager->DisplayBlockingPage(resource); | |
103 } | |
104 | |
105 void DataReductionProxyResourceThrottle::DisplayBlockingPage(bool* defer) { | |
106 const content::ResourceRequestInfo* info = | |
107 content::ResourceRequestInfo::ForRequest(request_); | |
108 DCHECK(info); | |
109 | |
110 state_ = REMOTE_BYPASS; | |
111 *defer = true; | |
112 | |
113 DataReductionProxyUIManager::BypassResource resource; | |
114 resource.url = request_->url(); | |
115 resource.is_subresource = is_subresource_; | |
116 resource.callback = base::Bind( | |
117 &DataReductionProxyResourceThrottle::OnBlockingPageComplete, AsWeakPtr()); | |
118 resource.render_process_host_id = info->GetChildID(); | |
119 resource.render_view_id = info->GetRouteID(); | |
120 | |
121 content::BrowserThread::PostTask( | |
122 content::BrowserThread::UI, FROM_HERE, | |
123 base::Bind( | |
124 &DataReductionProxyResourceThrottle::StartDisplayingBlockingPage, | |
125 ui_service_->ui_manager(), resource)); | |
126 } | |
127 | |
128 void DataReductionProxyResourceThrottle::OnBlockingPageComplete(bool proceed) { | |
129 state_ = NOT_BYPASSED; | |
130 if (proceed) | |
131 controller()->Resume(); | |
132 else | |
133 controller()->Cancel(); | |
134 } | |
135 | |
136 } // namespace data_reduction_proxy | |
OLD | NEW |