Chromium Code Reviews| Index: components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.cc |
| diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.cc b/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cb585a7759d68c98c8a15b2d54975c0cd6358443 |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.cc |
| @@ -0,0 +1,97 @@ |
| +// Copyright (c) 2012 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_ui_manager.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/threading/thread.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "net/url_request/url_request_context.h" |
| +#include "net/url_request/url_request_context_getter.h" |
| + |
| +using content::BrowserThread; |
|
bengr
2014/12/17 00:30:20
I prefer to avoid using "using"
megjablon
2014/12/23 02:18:05
Done.
|
| +using content::RenderViewHost; |
| +using content::WebContents; |
| + |
| +namespace data_reduction_proxy { |
| + |
| +DataReductionProxyUIManager::BypassResource::BypassResource() |
| + : is_subresource(false), |
| + render_process_host_id(-1), |
| + render_view_id(-1) { |
| +} |
| + |
| +DataReductionProxyUIManager::BypassResource::~BypassResource() { |
| +} |
| + |
| +DataReductionProxyUIManager::DataReductionProxyUIManager() { |
| +} |
| + |
| +DataReductionProxyUIManager::~DataReductionProxyUIManager() { |
| +} |
| + |
| +void DataReductionProxyUIManager::OnBlockingPageDone( |
| + const std::vector<BypassResource>& resources, |
| + bool proceed) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + for (std::vector<BypassResource>::const_iterator iter = resources.begin(); |
| + iter != resources.end(); ++iter) { |
| + const BypassResource& resource = *iter; |
| + if (!resource.callback.is_null()) |
| + resource.callback.Run(proceed); |
| + |
| + if (proceed) |
| + proceed_blocking_page_ = base::Time::Now(); |
| + } |
| +} |
| + |
| +void DataReductionProxyUIManager::DisplayBlockingPage( |
| + const BypassResource& resource) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + // Check if the user has already ignored our warning for this render_view |
| + // and domain. |
| + if (base::Time::Now() - proceed_blocking_page_ < |
| + base::TimeDelta::FromMinutes(5)) { |
|
bengr
2014/12/17 00:30:20
indent 4
megjablon
2014/12/23 02:18:05
Done.
|
| + if (!resource.callback.is_null()) { |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, base::Bind(resource.callback, true)); |
| + } |
| + return; |
| + } |
| + |
| + // The tab might have been closed. |
| + RenderViewHost* render_view_host = |
| + RenderViewHost::FromID(resource.render_process_host_id, |
|
bengr
2014/12/17 00:30:20
Indent only 4
megjablon
2014/12/23 02:18:05
Done.
|
| + resource.render_view_id); |
| + WebContents* web_contents = NULL; |
| + if (render_view_host) |
| + web_contents = WebContents::FromRenderViewHost(render_view_host); |
| + |
| + if (!web_contents) { |
| + // The tab is gone and we did not have a chance at showing the interstitial. |
| + // Just act as if "Don't Proceed" were chosen. |
| + std::vector<BypassResource> resources; |
| + resources.push_back(resource); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone, |
| + this, resources, false)); |
| + return; |
| + } |
| + |
| + // TODO(megjablon): Show blocking page. For now, continue on to the page. |
| + LOG(WARNING) << "BLOCKING PAGE!"; |
| + std::vector<BypassResource> resources; |
| + resources.push_back(resource); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone, |
| + this, resources, true)); |
| +} |
| + |
| +} // namespace data_reduction_proxy |