OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ | |
6 #define CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ | |
7 | |
8 #include <memory> | |
9 #include <vector> | |
10 | |
11 #include "base/gtest_prod_util.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/values.h" | |
15 #include "content/public/browser/navigation_throttle.h" | |
16 #include "content/public/browser/resource_request_info.h" | |
17 #include "content/public/common/console_message_level.h" | |
18 #include "url/gurl.h" | |
19 | |
20 namespace content { | |
21 | |
22 class NavigationHandle; | |
23 | |
24 // This throttle parses the Clear-Site-Data header and executes the clearing | |
25 // of browsing data. The navigation is delayed until the header is parsed and, | |
26 // if valid, until the browsing data are deleted. See the W3C working draft at | |
27 // https://www.w3.org/TR/clear-site-data/. | |
28 class CONTENT_EXPORT ClearSiteDataThrottle : public NavigationThrottle { | |
29 public: | |
30 struct ConsoleMessage { | |
31 GURL url; | |
32 std::string text; | |
33 ConsoleMessageLevel level; | |
34 }; | |
35 | |
36 static std::unique_ptr<NavigationThrottle> CreateThrottleForNavigation( | |
37 NavigationHandle* handle); | |
38 | |
39 ~ClearSiteDataThrottle() override; | |
40 | |
41 // NavigationThrottle implementation: | |
42 ThrottleCheckResult WillStartRequest() override; | |
43 ThrottleCheckResult WillRedirectRequest() override; | |
44 ThrottleCheckResult WillProcessResponse() override; | |
45 | |
46 private: | |
47 friend class ClearSiteDataThrottleTest; | |
48 FRIEND_TEST_ALL_PREFIXES(ClearSiteDataThrottleTest, ParseHeader); | |
49 FRIEND_TEST_ALL_PREFIXES(ClearSiteDataThrottleTest, InvalidHeader); | |
50 | |
51 explicit ClearSiteDataThrottle(NavigationHandle* navigation_handle); | |
52 | |
53 // Scans for 'Clear-Site-Data' headers, calls ParseHeader() to parse them, | |
54 // and requests the actual data clearing. This is the common logic | |
55 // of WillRedirectRequest() and WillProcessResponse(). | |
56 void HandleHeader(); | |
57 | |
58 // Parses the value of the 'Clear-Site-Data' header and outputs whether | |
59 // the header requests to |clear_cookies|, |clear_storage|, and |clear_cache|. | |
60 // The |messages| vector will be filled with messages to be output in the | |
61 // console. Returns true if parsing was successful. | |
62 bool ParseHeader(const std::string& header, | |
63 bool* clear_cookies, | |
64 bool* clear_storage, | |
65 bool* clear_cache, | |
66 std::vector<ConsoleMessage>* messages); | |
67 | |
68 // Signalizes that a parsing and deletion task was finished. | |
nasko
2016/08/11 20:07:22
nit: Signals?
msramek
2016/08/12 15:06:27
Done.
| |
69 void TaskFinished(); | |
70 | |
71 // Cached console messages to be output when the RenderFrameHost is ready. | |
72 std::vector<ConsoleMessage> messages_; | |
73 GURL current_url_; | |
74 | |
75 // The number of currently active parsing and deletion tasks. | |
76 int active_tasks_; | |
77 | |
78 // Needed for asynchronous parsing and deletion tasks. | |
79 base::WeakPtrFactory<ClearSiteDataThrottle> weak_ptr_factory_; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(ClearSiteDataThrottle); | |
82 }; | |
83 | |
84 } // namespace content | |
85 | |
86 #endif // CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ | |
OLD | NEW |