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

Side by Side Diff: components/data_reduction_proxy/content/browser/data_reduction_proxy_blocking_page.h

Issue 830503004: Data Reduction Proxy blocking page and resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@interstitalStep1
Patch Set: Rebase and crash fixes Created 5 years, 11 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_DATA_REDUCTION_PROXY_BLOCKING_PA GE_H_
6 #define COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_DATA_REDUCTION_PROXY_BLOCKING_PA GE_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_u i_manager.h"
13 #include "content/public/browser/interstitial_page_delegate.h"
14 #include "url/gurl.h"
15
16 namespace base {
17 class SingleThreadTaskRunner;
18 }
19
20 namespace content {
21 class InterstitialPage;
22 class WebContents;
23 }
24
25 namespace data_reduction_proxy {
26
27 class DataReductionProxyBlockingPageFactory;
28 class DataReductionProxyUIManager;
29
30 // When a user is about to visit a page and the the Data Reduction Proxy
31 // bypasses this class show an interstitial page with some options (go back,
32 // continue) to alert the user of the bypass.
33 //
34 // The DataReductionProxyBlockingPage is created by the
35 // DataReductionProxyUIManager on the UI thread when it has been determined that
36 // a page will be bypassed. The operation of the blocking page occurs on the UI
37 // thread, where it waits for the user to make a decision about what to do:
38 // either go back or continue on.
39 //
40 // The blocking page forwards the result of the user's choice back to the
41 // DataReductionProxyUIManager so that the request can be canceled for the new
42 // page, or allowed to continue.
43 //
44 // A web page may contain several resources flagged as blacklisted. This
45 // only results in one interstitial being shown. If the user decides to proceed
46 // in the first interstitial, we will not display another intersitial for a
47 // predetermined amount of time.
48 class DataReductionProxyBlockingPage
49 : public content::InterstitialPageDelegate {
50 public:
51 typedef DataReductionProxyUIManager::BypassResource BypassResource;
52 typedef std::vector<BypassResource> BypassResourceList;
53 typedef std::map<content::WebContents*, BypassResourceList> BypassResourceMap;
54
55 virtual ~DataReductionProxyBlockingPage();
56
57 // Creates a blocking page. Use ShowBlockingPage when access to the blocking
58 // page directly isn't needed.
59 static DataReductionProxyBlockingPage* CreateBlockingPage(
60 DataReductionProxyUIManager* ui_manager,
61 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
62 content::WebContents* web_contents,
63 const BypassResource& bypass_resource);
64
65 // Shows a blocking page warning about a Data Reduction Proxy bypass for a
66 // specific resource. You can call this method several times, if an
67 // interstitial is already showing, the new one will be queued and displayed
68 // if the user decides to proceed on the currently showing interstitial.
69 static void ShowBlockingPage(
70 DataReductionProxyUIManager* ui_manager,
71 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
72 const BypassResource& bypass_resource);
73
74 content::InterstitialPage* interstitial_page() const;
75
76 // Makes the passed |factory| the factory used to instantiate
77 // DataReductionProxyBlockingPage objects. Useful for tests.
78 static void RegisterFactory(DataReductionProxyBlockingPageFactory* factory) {
79 factory_ = factory;
80 }
81
82 // InterstitialPageDelegate methods:
83 virtual std::string GetHTMLContents() override;
84 virtual void OnProceed() override;
85 virtual void OnDontProceed() override;
86 virtual void CommandReceived(const std::string& command) override;
87
88 protected:
89 friend class DataReductionProxyBlockingPageFactoryImpl;
90
91 enum BlockingPageEvent {
92 SHOW,
93 PROCEED,
94 DONT_PROCEED,
95 };
96
97 // Don't instantiate this class directly, use ShowBlockingPage instead.
98 DataReductionProxyBlockingPage(
99 DataReductionProxyUIManager* ui_manager,
100 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
101 content::WebContents* web_contents,
102 const BypassResourceList& resource_list);
103
104 // Creates the InterstitialPage and shows it.
105 void Show();
106
107 // A list of DataReductionProxyUIManager::BypassResource for a tab that the
108 // user should be warned about. They are queued when displaying more than one
109 // interstitial at a time.
110 static BypassResourceMap* GetBypassResourcesMap();
111
112 // Prevents creating the actual interstitial view for testing.
113 void DontCreateViewForTesting();
114
115 // Notifies the DataReductionProxyUIManager on the IO thread whether to
116 // proceed or not for the |resources|.
117 static void NotifyDataReductionProxyUIManager(
118 DataReductionProxyUIManager* ui_manager,
119 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
120 const BypassResourceList& resource_list, bool proceed);
121
122 // Returns true if the passed |bypass_resources| is blocking the load of
123 // the main page.
124 static bool IsMainPageLoadBlocked(const BypassResourceList& resource_list);
125
126 // For reporting back user actions.
127 DataReductionProxyUIManager* ui_manager_;
128 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
129
130 // True if the interstitial is blocking the main page because it is on one
131 // of our lists. False if a subresource is being blocked, or in the case of
132 // client-side detection where the interstitial is shown after page load
133 // finishes.
134 bool is_main_frame_load_blocked_;
135
136 // The index of a navigation entry that should be removed when DontProceed()
137 // is invoked, -1 if not entry should be removed.
138 int navigation_entry_index_to_remove_;
139
140 // The list of bypassed resources this page is warning about.
141 BypassResourceList resource_list_;
142
143 bool proceeded_;
144
145 content::WebContents* web_contents_;
146 GURL url_;
147 content::InterstitialPage* interstitial_page_; // Owns us
148
149 // The factory used to instantiate DataReductionProxyBlockingPage objects.
150 // Useful for tests, so they can provide their own implementation of
151 // DataReductionProxyBlockingPage.
152 static DataReductionProxyBlockingPageFactory* factory_;
153
154 private:
155 // Whether the interstitial should create a view.
156 bool create_view_;
157
158 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyBlockingPage);
159 };
160
161 // Factory for creating DataReductionProxyBlockingPage. Useful for tests.
162 class DataReductionProxyBlockingPageFactory {
163 public:
164 virtual ~DataReductionProxyBlockingPageFactory() { }
165
166 virtual DataReductionProxyBlockingPage* CreateDataReductionProxyPage(
167 DataReductionProxyUIManager* ui_manager,
168 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
169 content::WebContents* web_contents,
170 const DataReductionProxyBlockingPage::BypassResourceList&
171 resource_list) = 0;
172 };
173
174 } // namespace data_reduction_proxy
175
176 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_DATA_REDUCTION_PROXY_BLOCKING _PAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698