| 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 // Displays an interstitial when the proxy will not be used for a request |
| 43 // because it 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 the interstitial if bypassed by local rules. |
| 54 if (params_->IsBypassedByDataReductionProxyLocalRules( |
| 55 *request_, ui_service_->data_reduction_proxy_config())) { |
| 56 state_ = LOCAL_BYPASS; |
| 57 return; |
| 58 } |
| 59 DisplayBlockingPage(defer); |
| 60 } |
| 61 |
| 62 // Displays an intersitital when the Data Reduction Proxy explicitly returns a |
| 63 // response that triggers a bypass. |
| 64 void DataReductionProxyResourceThrottle::WillRedirectRequest( |
| 65 const GURL& new_url, |
| 66 bool* defer) { |
| 67 // If the interstitial has already been shown, do not show it again. The |
| 68 // LOAD_BYPASS_PROXY flag makes it so that proxiesare not resolved. This |
| 69 // override is used when downloading PAC files. If the request does not have |
| 70 // the LOAD_BYPASS_PROXY flag, do not show the interstitial. |
| 71 if (state_ != NOT_BYPASSED || |
| 72 !(request_->load_flags() & net::LOAD_BYPASS_PROXY)) { |
| 73 return; |
| 74 } |
| 75 DisplayBlockingPage(defer); |
| 76 } |
| 77 |
| 78 // Already checked if the proxy is bypassed by local rules and if the Data |
| 79 // Reduction Proxy sent an explicit bypass. If the response isn't from the Data |
| 80 // Reduction Proxy and the scheme type can be proxied by the Data Reduction |
| 81 // Proxy there is connection error, display the interstitial. |
| 82 void DataReductionProxyResourceThrottle::WillProcessResponse(bool* defer) { |
| 83 if (state_ != NOT_BYPASSED) |
| 84 return; |
| 85 if (params_->IsDataReductionProxy(request_->proxy_server(), NULL) || |
| 86 !DataReductionProxyParams::CanProxyURLScheme(request_->url())) { |
| 87 return; |
| 88 } |
| 89 DisplayBlockingPage(defer); |
| 90 } |
| 91 |
| 92 const char* DataReductionProxyResourceThrottle::GetNameForLogging() const { |
| 93 return kResouceThrottleLogName; |
| 94 } |
| 95 |
| 96 // static |
| 97 void DataReductionProxyResourceThrottle::StartDisplayingBlockingPage( |
| 98 scoped_refptr<DataReductionProxyUIManager> ui_manager, |
| 99 const DataReductionProxyUIManager::BypassResource& resource) { |
| 100 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 101 ui_manager->DisplayBlockingPage(resource); |
| 102 } |
| 103 |
| 104 void DataReductionProxyResourceThrottle::DisplayBlockingPage(bool* defer) { |
| 105 const content::ResourceRequestInfo* info = |
| 106 content::ResourceRequestInfo::ForRequest(request_); |
| 107 DCHECK(info); |
| 108 |
| 109 state_ = REMOTE_BYPASS; |
| 110 *defer = true; |
| 111 |
| 112 DataReductionProxyUIManager::BypassResource resource; |
| 113 resource.url = request_->url(); |
| 114 resource.is_subresource = is_subresource_; |
| 115 resource.callback = base::Bind( |
| 116 &DataReductionProxyResourceThrottle::OnBlockingPageComplete, AsWeakPtr()); |
| 117 resource.render_process_host_id = info->GetChildID(); |
| 118 resource.render_view_id = info->GetRouteID(); |
| 119 |
| 120 content::BrowserThread::PostTask( |
| 121 content::BrowserThread::UI, FROM_HERE, |
| 122 base::Bind( |
| 123 &DataReductionProxyResourceThrottle::StartDisplayingBlockingPage, |
| 124 ui_service_->ui_manager(), resource)); |
| 125 } |
| 126 |
| 127 void DataReductionProxyResourceThrottle::OnBlockingPageComplete(bool proceed) { |
| 128 state_ = NOT_BYPASSED; |
| 129 if (proceed) |
| 130 controller()->Resume(); |
| 131 else |
| 132 controller()->Cancel(); |
| 133 } |
| 134 |
| 135 } // namespace data_reduction_proxy |
| OLD | NEW |