Index: components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.cc |
diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.cc b/components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e586678035d9dda1156827872d1d6b0163581627 |
--- /dev/null |
+++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.cc |
@@ -0,0 +1,138 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.h" |
+ |
+#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_service.h" |
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/resource_controller.h" |
+#include "content/public/browser/resource_request_info.h" |
+#include "net/base/load_flags.h" |
+#include "net/http/http_response_headers.h" |
+#include "net/url_request/url_request.h" |
+ |
+using content::BrowserThread; |
+using content::ResourceThrottle; |
+ |
+namespace data_reduction_proxy { |
+ |
+namespace { |
+ |
+const char* kResouceThrottleLogName = "DataReductionProxyResourceThrottle"; |
bengr
2014/12/17 00:30:19
const char kResouceThrottleLogName[] = "DataReduct
megjablon
2014/12/23 02:18:04
Done.
|
+ |
+} // namespace |
+ |
+DataReductionProxyResourceThrottle::DataReductionProxyResourceThrottle( |
+ net::URLRequest* request, |
+ content::ResourceType resource_type, |
+ DataReductionProxyUIService* ui_service, |
+ const DataReductionProxyParams* params) |
+ : state_(NOT_BYPASSED), |
+ request_(request), |
+ ui_service_(ui_service), |
+ params_(params), |
+ is_subresource_(resource_type != content::RESOURCE_TYPE_MAIN_FRAME) { |
bengr
2014/12/17 00:30:19
DCHECK(request)
DCHECK(params)
and anything else
megjablon
2014/12/23 02:18:04
Done.
|
+} |
+ |
+DataReductionProxyResourceThrottle::~DataReductionProxyResourceThrottle() { } |
bengr
2014/12/17 00:30:20
Move closing brace to new line.
megjablon
2014/12/23 02:18:04
Done.
|
+ |
+void DataReductionProxyResourceThrottle::WillStartUsingNetwork(bool* defer) { |
+ DCHECK(state_ == NOT_BYPASSED); |
+ |
+ if (!params_->AreDataReductionProxiesBypassed(*request_, NULL)) |
+ return; |
+ |
+ if (request_->load_flags() & net::LOAD_PREFETCH) { |
+ // Don't prefetch resources that bypass, disallow them. |
+ controller()->Cancel(); |
+ return; |
+ } |
+ |
+ if (params_->IsBypassedByDataReductionProxyLocalRules( |
+ *request_, ui_service_->data_reduction_proxy_config())) { |
+ state_ = LOCAL_BYPASS; |
+ return; |
+ } |
+ |
+ DisplayBlockingPage(defer); |
+} |
+ |
+void DataReductionProxyResourceThrottle::WillRedirectRequest( |
+ const GURL& new_url, |
+ bool* defer) { |
+ // If we have already shown the interstitial, do not show it again. The |
+ // LOAD_BYPASS_PROXY flag makes it so that we do not resolve proxies. This |
+ // override is used when downloading PAC files. If the request does not have |
+ // the LOAD_BYPASS_PROXY flag, do not show the interstitial. |
+ if (state_ != NOT_BYPASSED || |
+ !(request_->load_flags() & net::LOAD_BYPASS_PROXY)) { |
+ return; |
+ } |
+ |
+ DisplayBlockingPage(defer); |
+} |
+ |
+void DataReductionProxyResourceThrottle::WillProcessResponse(bool* defer) { |
+ if(state_ != NOT_BYPASSED) |
bengr
2014/12/17 00:30:20
Fix the space after "if" and the indent of "return
megjablon
2014/12/23 02:18:04
Done.
|
+ return; |
+ |
+ if (params_->IsDataReductionProxy(request_->proxy_server(), NULL) || |
+ request_->url().SchemeIs("chrome") || |
+ request_->url().SchemeIs("about") || |
+ request_->url().SchemeIs("file")) { |
bengr
2014/12/17 00:30:19
Where did this list of schemes come from? what abo
megjablon
2014/12/23 02:18:04
I wanted to skip any local requests. We can skip w
|
+ return; |
+ } |
+ |
+ DisplayBlockingPage(defer); |
+} |
+ |
+void DataReductionProxyResourceThrottle::DisplayBlockingPage(bool* defer) { |
+ const content::ResourceRequestInfo* info = |
+ content::ResourceRequestInfo::ForRequest(request_); |
+ DCHECK(info); |
+ |
+ state_ = REMOTE_BYPASS; |
+ DataReductionProxyUIManager::BypassResource resource; |
+ resource.url = request_->url(); |
+ resource.is_subresource = is_subresource_; |
+ resource.callback = base::Bind( |
+ &DataReductionProxyResourceThrottle::OnBlockingPageComplete, AsWeakPtr()); |
+ resource.render_process_host_id = info->GetChildID(); |
+ resource.render_view_id = info->GetRouteID(); |
+ |
+ *defer = true; |
+ |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, |
+ FROM_HERE, |
bengr
2014/12/17 00:30:20
Move up with previous line.
megjablon
2014/12/23 02:18:04
Done.
|
+ base::Bind( |
+ &DataReductionProxyResourceThrottle::StartDisplayingBlockingPage, |
+ AsWeakPtr(), |
+ ui_service_->ui_manager(), |
+ resource)); |
bengr
2014/12/17 00:30:20
Move these up onto same like as "AsWeakPtr()"
megjablon
2014/12/23 02:18:04
Done.
|
+} |
+ |
+const char* DataReductionProxyResourceThrottle::GetNameForLogging() const { |
+ return kResouceThrottleLogName; |
+} |
+ |
+// static |
+void DataReductionProxyResourceThrottle::StartDisplayingBlockingPage( |
+ const base::WeakPtr<DataReductionProxyResourceThrottle>& throttle, |
+ scoped_refptr<DataReductionProxyUIManager> ui_manager, |
+ const DataReductionProxyUIManager::BypassResource& resource) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ ui_manager->DisplayBlockingPage(resource); |
+} |
+ |
+void DataReductionProxyResourceThrottle::OnBlockingPageComplete(bool proceed) { |
+ state_ = NOT_BYPASSED; |
+ if (proceed) |
+ controller()->Resume(); |
+ else |
+ controller()->Cancel(); |
+} |
+ |
+} // namespace data_reduction_proxy |