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/values.h" | |
14 #include "content/public/browser/navigation_throttle.h" | |
15 #include "content/public/browser/resource_request_info.h" | |
16 #include "content/public/browser/web_contents_observer.h" | |
17 #include "content/public/common/console_message_level.h" | |
18 #include "url/gurl.h" | |
19 | |
20 class Profile; | |
21 | |
22 namespace content { | |
23 | |
24 class NavigationHandle; | |
25 | |
26 // This throttle asynchronously executes the clearing of browsing data. | |
27 // It does not block navigation. | |
28 class CONTENT_EXPORT ClearSiteDataThrottle : public NavigationThrottle, | |
clamy
2016/07/26 16:48:13
It seems very weird to me to have a class that is
msramek
2016/07/27 15:02:53
Done. Renamed to ClearSiteDataHeaderObserver, and
| |
29 public WebContentsObserver { | |
30 public: | |
31 struct ConsoleMessage { | |
32 std::string text; | |
33 ConsoleMessageLevel level; | |
34 }; | |
35 | |
36 static std::unique_ptr<NavigationThrottle> | |
37 CreateThrottleFor(NavigationHandle* handle); | |
38 | |
39 ~ClearSiteDataThrottle() override; | |
40 | |
41 // NavigationThrottle implementation: | |
42 ThrottleCheckResult WillStartRequest() override; | |
43 ThrottleCheckResult WillProcessResponse() override; | |
44 ThrottleCheckResult WillRedirectRequest() override; | |
45 | |
46 // WebContentsObserver implementation: | |
47 void DidFinishNavigation(NavigationHandle* handle) override; | |
48 | |
49 private: | |
50 explicit ClearSiteDataThrottle(NavigationHandle* handle); | |
51 | |
52 // Scans for 'Clear-Site-Data' headers, calls ParseHeader() to parse them, | |
53 // and requests the actual data clearing. This is the common logic | |
54 // of WillProcessResponse() and WillRedirectRequest(). | |
55 void HandleHeader(); | |
56 | |
57 // Parses the value of the 'Clear-Site-Data' header and outputs whether | |
58 // the header requests to |clear_cookies|, |clear_storage|, and |clear_cache|. | |
59 // The |messages| vector will be filled with messages to be output in the | |
60 // console. Returns true if parsing was successful. | |
61 bool ParseHeader(const std::string& header, | |
62 bool* clear_cookies, bool* clear_storage, bool* clear_cache, | |
63 std::vector<ConsoleMessage>* messages); | |
64 | |
65 // Cached console messages to be output when the RenderFrameHost is ready. | |
66 std::vector<ConsoleMessage> messages_; | |
67 GURL current_url_; | |
68 | |
69 FRIEND_TEST_ALL_PREFIXES(ClearSiteDataThrottleTest, ParseHeader); | |
70 FRIEND_TEST_ALL_PREFIXES(ClearSiteDataThrottleTest, InvalidHeader); | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(ClearSiteDataThrottle); | |
73 }; | |
74 | |
75 } // namespace content | |
76 | |
77 #endif // CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ | |
OLD | NEW |