Chromium Code Reviews| 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 #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); | |
|
mmenke
2015/01/16 20:15:28
DCHECK_EQ(NOT_BYPASSED, state_)
megjablon
2015/01/17 02:21:48
Done.
| |
| 46 if (!params_->AreDataReductionProxiesBypassed( | |
| 47 *request_, ui_service_->data_reduction_proxy_config(), NULL)) | |
| 48 return; | |
|
mmenke
2015/01/16 20:15:28
nit: Use braces when the condition takes more tha
megjablon
2015/01/17 02:21:49
Done.
| |
| 49 if (request_->load_flags() & net::LOAD_PREFETCH) { | |
| 50 // Don't prefetch resources that bypass, disallow them. | |
| 51 controller()->Cancel(); | |
| 52 return; | |
| 53 } | |
| 54 // Do not display the interstitial if bypassed by 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 // Displays an intersitital when the Data Reduction Proxy explicitly returns a | |
| 64 // response that triggers a bypass. | |
| 65 void DataReductionProxyResourceThrottle::WillRedirectRequest( | |
| 66 const GURL& new_url, | |
| 67 bool* defer) { | |
| 68 // If the interstitial has already been shown, do not show it again. The | |
| 69 // LOAD_BYPASS_PROXY flag makes it so that proxies are not resolved. 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 const char* DataReductionProxyResourceThrottle::GetNameForLogging() const { | |
| 80 return kResouceThrottleLogName; | |
| 81 } | |
| 82 | |
| 83 // static | |
| 84 void DataReductionProxyResourceThrottle::StartDisplayingBlockingPage( | |
| 85 scoped_refptr<DataReductionProxyUIManager> ui_manager, | |
| 86 const DataReductionProxyUIManager::BypassResource& resource) { | |
| 87 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 88 ui_manager->DisplayBlockingPage(resource); | |
| 89 } | |
| 90 | |
| 91 void DataReductionProxyResourceThrottle::DisplayBlockingPage(bool* defer) { | |
| 92 const content::ResourceRequestInfo* info = | |
| 93 content::ResourceRequestInfo::ForRequest(request_); | |
| 94 DCHECK(info); | |
| 95 | |
| 96 state_ = REMOTE_BYPASS; | |
| 97 *defer = true; | |
| 98 | |
| 99 DataReductionProxyUIManager::BypassResource resource; | |
| 100 resource.url = request_->url(); | |
| 101 resource.is_subresource = is_subresource_; | |
| 102 resource.callback = base::Bind( | |
| 103 &DataReductionProxyResourceThrottle::OnBlockingPageComplete, AsWeakPtr()); | |
| 104 resource.render_process_host_id = info->GetChildID(); | |
| 105 resource.render_view_id = info->GetRouteID(); | |
| 106 | |
| 107 content::BrowserThread::PostTask( | |
| 108 content::BrowserThread::UI, FROM_HERE, | |
| 109 base::Bind( | |
| 110 &DataReductionProxyResourceThrottle::StartDisplayingBlockingPage, | |
| 111 ui_service_->ui_manager(), resource)); | |
| 112 } | |
| 113 | |
| 114 void DataReductionProxyResourceThrottle::OnBlockingPageComplete(bool proceed) { | |
| 115 state_ = NOT_BYPASSED; | |
| 116 if (proceed) | |
| 117 controller()->Resume(); | |
| 118 else | |
| 119 controller()->Cancel(); | |
| 120 } | |
| 121 | |
| 122 } // namespace data_reduction_proxy | |
| OLD | NEW |