OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ | 5 #ifndef CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ |
6 #define CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ | 6 #define CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
mmenke
2016/10/21 15:16:21
Not used.
msramek
2016/10/31 19:23:36
This is here because of std::unique_ptr<>.
| |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
mmenke
2016/10/21 15:16:21
Nont needed.
msramek
2016/10/31 19:23:35
Done. Removed.
| |
15 #include "content/public/browser/navigation_throttle.h" | |
16 #include "content/public/browser/resource_request_info.h" | 15 #include "content/public/browser/resource_request_info.h" |
mmenke
2016/10/21 15:16:21
Not needed.
msramek
2016/10/31 19:23:36
True, but after last changes it's needed again bec
| |
16 #include "content/public/browser/resource_throttle.h" | |
17 #include "content/public/common/console_message_level.h" | 17 #include "content/public/common/console_message_level.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 | 19 |
20 namespace net { | |
21 struct RedirectInfo; | |
22 class URLRequest; | |
23 } | |
24 | |
25 namespace url { | |
26 class Origin; | |
27 } | |
mmenke
2016/10/21 15:16:20
Not needed.
msramek
2016/10/31 19:23:35
True, but after last changes it's needed again now
| |
28 | |
20 namespace content { | 29 namespace content { |
21 | 30 |
22 class NavigationHandle; | |
23 | |
24 // This throttle parses the Clear-Site-Data header and executes the clearing | 31 // 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, | 32 // of browsing data. The resource load is delayed until the header is parsed |
26 // if valid, until the browsing data are deleted. See the W3C working draft at | 33 // and, if valid, until the browsing data are deleted. See the W3C working draft |
27 // https://www.w3.org/TR/clear-site-data/. | 34 // at https://www.w3.org/TR/clear-site-data/. |
28 class CONTENT_EXPORT ClearSiteDataThrottle : public NavigationThrottle { | 35 class CONTENT_EXPORT ClearSiteDataThrottle : public ResourceThrottle { |
29 public: | 36 public: |
30 struct ConsoleMessage { | 37 struct ConsoleMessage { |
31 GURL url; | 38 GURL url; |
32 std::string text; | 39 std::string text; |
33 ConsoleMessageLevel level; | 40 ConsoleMessageLevel level; |
34 }; | 41 }; |
35 | 42 |
36 static std::unique_ptr<NavigationThrottle> CreateThrottleForNavigation( | 43 // Instantiates a throttle for the given |request|. The caller must |
37 NavigationHandle* handle); | 44 // guarantee that |request| outlives the throttle. |
45 static std::unique_ptr<ResourceThrottle> CreateThrottleForRequest( | |
46 net::URLRequest* request); | |
38 | 47 |
39 ~ClearSiteDataThrottle() override; | 48 ~ClearSiteDataThrottle() override; |
40 | 49 |
41 // NavigationThrottle implementation: | 50 // ResourceThrottle implementation: |
42 ThrottleCheckResult WillStartRequest() override; | 51 const char* GetNameForLogging() const override; |
43 ThrottleCheckResult WillRedirectRequest() override; | 52 void WillStartRequest(bool* defer) override; |
44 ThrottleCheckResult WillProcessResponse() override; | 53 void WillRedirectRequest(const net::RedirectInfo& redirect_info, |
54 bool* defer) override; | |
55 void WillProcessResponse(bool* defer) override; | |
45 | 56 |
46 private: | 57 private: |
47 friend class ClearSiteDataFuzzerTest; | 58 friend class ClearSiteDataFuzzerTest; |
48 friend class ClearSiteDataThrottleTest; | 59 friend class ClearSiteDataThrottleTest; |
49 FRIEND_TEST_ALL_PREFIXES(ClearSiteDataThrottleTest, ParseHeader); | 60 FRIEND_TEST_ALL_PREFIXES(ClearSiteDataThrottleTest, ParseHeader); |
50 FRIEND_TEST_ALL_PREFIXES(ClearSiteDataThrottleTest, InvalidHeader); | 61 FRIEND_TEST_ALL_PREFIXES(ClearSiteDataThrottleTest, InvalidHeader); |
mmenke
2016/10/21 15:16:21
Do we really need to friend the test fixture? Thi
msramek
2016/10/31 19:23:35
I made ParseHeader "public static". I don't think
| |
51 | 62 |
52 explicit ClearSiteDataThrottle(NavigationHandle* navigation_handle); | 63 explicit ClearSiteDataThrottle(net::URLRequest* request); |
53 | 64 |
54 // Scans for the first occurrence of the 'Clear-Site-Data' header, calls | 65 // Scans for the first occurrence of the 'Clear-Site-Data' header, calls |
55 // ParseHeader() to parse it, and requests the actual data clearing. This is | 66 // ParseHeader() to parse it, and requests the actual data clearing. This is |
56 // the common logic of WillRedirectRequest() and WillProcessResponse(). | 67 // the common logic of WillRedirectRequest() and WillProcessResponse(). |
57 void HandleHeader(); | 68 // Returns true if a valid header was found and the clearing was executed. |
69 bool HandleHeader(); | |
58 | 70 |
59 // Parses the value of the 'Clear-Site-Data' header and outputs whether | 71 // Parses the value of the 'Clear-Site-Data' header and outputs whether |
60 // the header requests to |clear_cookies|, |clear_storage|, and |clear_cache|. | 72 // the header requests to |clear_cookies|, |clear_storage|, and |clear_cache|. |
61 // The |messages| vector will be filled with messages to be output in the | 73 // The |messages| vector will be filled with messages to be output in the |
62 // console. Returns true if parsing was successful. | 74 // console. Returns true if parsing was successful. |
63 bool ParseHeader(const std::string& header, | 75 bool ParseHeader(const std::string& header, |
mmenke
2016/10/21 15:16:20
include <string>
msramek
2016/10/31 19:23:35
Done.
| |
64 bool* clear_cookies, | 76 bool* clear_cookies, |
65 bool* clear_storage, | 77 bool* clear_storage, |
66 bool* clear_cache, | 78 bool* clear_cache, |
67 std::vector<ConsoleMessage>* messages); | 79 std::vector<ConsoleMessage>* messages); |
68 | 80 |
69 // Signals that a parsing and deletion task was finished. | 81 // Signals that a parsing and deletion task was finished. |
70 void TaskFinished(); | 82 void TaskFinished(); |
71 | 83 |
72 // Cached console messages to be output when the RenderFrameHost is ready. | 84 // The request this throttle is observing. |
85 net::URLRequest* request_; | |
86 | |
87 // Cached console messages to be output when the resource is loaded. | |
73 std::vector<ConsoleMessage> messages_; | 88 std::vector<ConsoleMessage> messages_; |
74 GURL current_url_; | 89 GURL current_url_; |
mmenke
2016/10/21 15:16:21
Don't think we need this variable - can just grab
msramek
2016/10/31 19:23:35
Done. Yes, this is a remnant of the NavigationThro
| |
75 | 90 |
76 // Whether we are currently waiting for a callback that data clearing has | |
77 // been completed; | |
78 bool clearing_in_progress_; | |
79 | |
80 // The time when the last clearing operation started. Used when clearing | 91 // The time when the last clearing operation started. Used when clearing |
81 // finishes to compute the duration. | 92 // finishes to compute the duration. |
82 base::TimeTicks clearing_started_; | 93 base::TimeTicks clearing_started_; |
mmenke
2016/10/21 15:16:21
While you're here, should include base/time.h
msramek
2016/10/31 19:23:35
Done.
| |
83 | 94 |
84 // Needed for asynchronous parsing and deletion tasks. | 95 // Needed for asynchronous parsing and deletion tasks. |
85 base::WeakPtrFactory<ClearSiteDataThrottle> weak_ptr_factory_; | 96 base::WeakPtrFactory<ClearSiteDataThrottle> weak_ptr_factory_; |
86 | 97 |
87 DISALLOW_COPY_AND_ASSIGN(ClearSiteDataThrottle); | 98 DISALLOW_COPY_AND_ASSIGN(ClearSiteDataThrottle); |
88 }; | 99 }; |
89 | 100 |
90 } // namespace content | 101 } // namespace content |
91 | 102 |
92 #endif // CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ | 103 #endif // CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ |
OLD | NEW |