Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Unified Diff: components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.cc

Issue 684223003: Data Reduction Proxy Interstitials (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing bengr comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a9a450feb9df498ca4e456bbe55c4fa3b30c4011
--- /dev/null
+++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.cc
@@ -0,0 +1,136 @@
+// 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"
+
+namespace data_reduction_proxy {
+
+namespace {
+
+const char kResouceThrottleLogName[] = "DataReductionProxyResourceThrottle";
+
+} // namespace
+
+DataReductionProxyResourceThrottle::DataReductionProxyResourceThrottle(
+ const net::URLRequest* request,
+ content::ResourceType resource_type,
+ const 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) {
+ DCHECK(request);
+ DCHECK(ui_service);
+ DCHECK(params);
+}
+
+DataReductionProxyResourceThrottle::~DataReductionProxyResourceThrottle() {
+}
+
+// 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.
+// isn't configured.
+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;
+ }
+ // 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.
+ // local rules.
+ if (params_->IsBypassedByDataReductionProxyLocalRules(
+ *request_, ui_service_->data_reduction_proxy_config())) {
+ state_ = LOCAL_BYPASS;
+ return;
+ }
+ DisplayBlockingPage(defer);
+}
+
+// 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.
+// that triggers a bypass.
+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);
+}
+
+// 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.
+// reduction proxy sent an explicit bypass. If the response isn't from the data
+// reduction proxy and the scheme type can be proxied by the data reduction
+// proxy we have a connection error, display the blocking page.
+void DataReductionProxyResourceThrottle::WillProcessResponse(bool* defer) {
+ if (state_ != NOT_BYPASSED)
+ return;
+ if (params_->IsDataReductionProxy(request_->proxy_server(), NULL) ||
+ !DataReductionProxyParams::CanProxyURLScheme(request_->url())) {
+ return;
+ }
+ DisplayBlockingPage(defer);
+}
+
+const char* DataReductionProxyResourceThrottle::GetNameForLogging() const {
+ return kResouceThrottleLogName;
bengr 2014/12/31 01:10:21 indent -2.
megjablon 2014/12/31 02:12:28 Done.
+}
+
+// static
+void DataReductionProxyResourceThrottle::StartDisplayingBlockingPage(
+ scoped_refptr<DataReductionProxyUIManager> ui_manager,
+ const DataReductionProxyUIManager::BypassResource& resource) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ ui_manager->DisplayBlockingPage(resource);
+}
+
+void DataReductionProxyResourceThrottle::DisplayBlockingPage(bool* defer) {
+ const content::ResourceRequestInfo* info =
+ content::ResourceRequestInfo::ForRequest(request_);
+ DCHECK(info);
+
+ state_ = REMOTE_BYPASS;
+ *defer = true;
+
+ 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();
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(
+ &DataReductionProxyResourceThrottle::StartDisplayingBlockingPage,
+ ui_service_->ui_manager(), resource));
+}
+
+void DataReductionProxyResourceThrottle::OnBlockingPageComplete(bool proceed) {
+ state_ = NOT_BYPASSED;
+ if (proceed)
+ controller()->Resume();
+ else
+ controller()->Cancel();
+}
+
+} // namespace data_reduction_proxy

Powered by Google App Engine
This is Rietveld 408576698