Index: components/data_reduction_proxy/content/data_reduction_proxy_ui_manager.cc |
diff --git a/components/data_reduction_proxy/content/data_reduction_proxy_ui_manager.cc b/components/data_reduction_proxy/content/data_reduction_proxy_ui_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f2791c9100db282abe24a2b5382b51e52ec4c5ae |
--- /dev/null |
+++ b/components/data_reduction_proxy/content/data_reduction_proxy_ui_manager.cc |
@@ -0,0 +1,98 @@ |
+// 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/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/navigation_entry.h" |
+#include "content/public/browser/notification_service.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; |
+using content::NavigationEntry; |
+using content::RenderViewHost; |
+using content::WebContents; |
+ |
+namespace data_reduction_proxy { |
+ |
+DataReductionProxyUIManager::BypassResource::BypassResource() |
+ : is_subresource(false), |
+ blocking_page_type(DRP_NO_PAGE), |
+ render_process_host_id(-1), |
+ render_view_id(-1) { |
+} |
+ |
+DataReductionProxyUIManager::BypassResource::~BypassResource() { } |
bengr
2014/10/31 17:06:48
style nit: I always put the closing brace on a new
megjablon
2014/12/11 23:32:06
Done.
|
+ |
+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) { |
bengr
2014/10/31 17:06:48
curly braces not needed.
megjablon
2014/12/11 23:32:06
Done.
|
+ 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)) { |
+ 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, |
+ 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. |
bengr
2014/10/31 17:06:48
What's left to do?
megjablon
2014/12/11 23:32:06
This doesn't display anything. I need to add the b
|
+ 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 |