OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/data_reduction_proxy/content/data_reduction_proxy_ui_manage r.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
9 #include "base/threading/thread.h" | |
10 #include "content/public/browser/browser_thread.h" | |
11 #include "content/public/browser/navigation_entry.h" | |
12 #include "content/public/browser/notification_service.h" | |
13 #include "content/public/browser/render_view_host.h" | |
14 #include "content/public/browser/web_contents.h" | |
15 #include "net/url_request/url_request_context.h" | |
16 #include "net/url_request/url_request_context_getter.h" | |
17 | |
18 using content::BrowserThread; | |
19 using content::NavigationEntry; | |
20 using content::RenderViewHost; | |
21 using content::WebContents; | |
22 | |
23 namespace data_reduction_proxy { | |
24 | |
25 DataReductionProxyUIManager::BypassResource::BypassResource() | |
26 : is_subresource(false), | |
27 blocking_page_type(DRP_NO_PAGE), | |
28 render_process_host_id(-1), | |
29 render_view_id(-1) { | |
30 } | |
31 | |
32 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.
| |
33 | |
34 DataReductionProxyUIManager::DataReductionProxyUIManager() { } | |
35 | |
36 DataReductionProxyUIManager::~DataReductionProxyUIManager() { } | |
37 | |
38 void DataReductionProxyUIManager::OnBlockingPageDone( | |
39 const std::vector<BypassResource>& resources, | |
40 bool proceed) { | |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
42 for (std::vector<BypassResource>::const_iterator iter = resources.begin(); | |
43 iter != resources.end(); ++iter) { | |
44 const BypassResource& resource = *iter; | |
45 if (!resource.callback.is_null()) | |
46 resource.callback.Run(proceed); | |
47 | |
48 if (proceed) { | |
bengr
2014/10/31 17:06:48
curly braces not needed.
megjablon
2014/12/11 23:32:06
Done.
| |
49 proceed_blocking_page_ = base::Time::Now(); | |
50 } | |
51 } | |
52 } | |
53 | |
54 void DataReductionProxyUIManager::DisplayBlockingPage( | |
55 const BypassResource& resource) { | |
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
57 | |
58 // Check if the user has already ignored our warning for this render_view | |
59 // and domain. | |
60 if (base::Time::Now() - proceed_blocking_page_ < | |
61 base::TimeDelta::FromMinutes(5)) { | |
62 if (!resource.callback.is_null()) { | |
63 BrowserThread::PostTask( | |
64 BrowserThread::IO, FROM_HERE, base::Bind(resource.callback, true)); | |
65 } | |
66 return; | |
67 } | |
68 | |
69 // The tab might have been closed. | |
70 RenderViewHost* render_view_host = | |
71 RenderViewHost::FromID(resource.render_process_host_id, | |
72 resource.render_view_id); | |
73 WebContents* web_contents = NULL; | |
74 if (render_view_host) | |
75 web_contents = WebContents::FromRenderViewHost(render_view_host); | |
76 | |
77 if (!web_contents) { | |
78 // The tab is gone and we did not have a chance at showing the interstitial. | |
79 // Just act as if "Don't Proceed" were chosen. | |
80 std::vector<BypassResource> resources; | |
81 resources.push_back(resource); | |
82 BrowserThread::PostTask( | |
83 BrowserThread::IO, FROM_HERE, | |
84 base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone, | |
85 this, resources, false)); | |
86 return; | |
87 } | |
88 | |
89 // 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
| |
90 std::vector<BypassResource> resources; | |
91 resources.push_back(resource); | |
92 BrowserThread::PostTask( | |
93 BrowserThread::IO, FROM_HERE, | |
94 base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone, | |
95 this, resources, true)); | |
96 } | |
97 | |
98 } // namespace data_reduction_proxy | |
OLD | NEW |