| 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..987492d9bedf14d3a0b02723b3e885c7d2dfcae1
|
| --- /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 <vector>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/time/time.h"
|
| +#include "content/public/browser/render_view_host.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +
|
| +namespace data_reduction_proxy {
|
| +
|
| +namespace {
|
| +
|
| +// Once the blocking page is shown, it is not displayed for another five
|
| +// minutes.
|
| +const int kBlockingPageDelayInMinutes = 5;
|
| +
|
| +}
|
| +
|
| +DataReductionProxyUIManager::BypassResource::BypassResource()
|
| + : is_subresource(false),
|
| + render_process_host_id(-1),
|
| + render_view_id(-1) {
|
| +}
|
| +
|
| +DataReductionProxyUIManager::BypassResource::~BypassResource() {
|
| +}
|
| +
|
| +DataReductionProxyUIManager::DataReductionProxyUIManager(
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
|
| + : ui_task_runner_(ui_task_runner),
|
| + io_task_runner_(io_task_runner) {
|
| +}
|
| +
|
| +DataReductionProxyUIManager::~DataReductionProxyUIManager() {
|
| +}
|
| +
|
| +bool DataReductionProxyUIManager::IsTabClosed(
|
| + const BypassResource& resource) const {
|
| + // The tab might have been closed.
|
| + content::RenderViewHost* render_view_host =
|
| + content::RenderViewHost::FromID(resource.render_process_host_id,
|
| + resource.render_view_id);
|
| + content::WebContents* web_contents = nullptr;
|
| + if (render_view_host)
|
| + web_contents = content::WebContents::FromRenderViewHost(render_view_host);
|
| +
|
| + if(web_contents)
|
| + return false;
|
| + return true;
|
| +}
|
| +
|
| +void DataReductionProxyUIManager::DisplayBlockingPage(
|
| + const BypassResource& resource) {
|
| + DCHECK(ui_task_runner_->BelongsToCurrentThread());
|
| + // Check if the user has already ignored the warning for this render_view
|
| + // and domain.
|
| + if (base::Time::Now() - blocking_page_last_shown_ <
|
| + base::TimeDelta::FromMinutes(kBlockingPageDelayInMinutes)) {
|
| + if (!resource.callback.is_null())
|
| + io_task_runner_->PostTask(FROM_HERE, base::Bind(resource.callback, true));
|
| + return;
|
| + }
|
| +
|
| + if (IsTabClosed(resource)) {
|
| + // The tab is gone and there was not a chance to show the interstitial.
|
| + // Just act as if "Don't Proceed" were chosen.
|
| + io_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone,
|
| + this, resource, false));
|
| + return;
|
| + }
|
| +
|
| + // TODO(megjablon): Show blocking page. For now, continue on to the page.
|
| + io_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone,
|
| + this, resource, true));
|
| +}
|
| +
|
| +void DataReductionProxyUIManager::OnBlockingPageDone(
|
| + const BypassResource& resource,
|
| + bool proceed) {
|
| + DCHECK(io_task_runner_->BelongsToCurrentThread());
|
| + if (!resource.callback.is_null())
|
| + resource.callback.Run(proceed);
|
| + if (proceed)
|
| + blocking_page_last_shown_ = base::Time::Now();
|
| +}
|
| +
|
| +} // namespace data_reduction_proxy
|
|
|