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/common/console_message_level.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 class Profile; |
| 20 |
| 21 namespace content { |
| 22 |
| 23 class NavigationHandle; |
| 24 |
| 25 // This throttle asynchronously executes the clearing of browsing data. |
| 26 // It does not block navigation. |
| 27 class CONTENT_EXPORT ClearSiteDataThrottle : public NavigationThrottle { |
| 28 public: |
| 29 static std::unique_ptr<NavigationThrottle> |
| 30 CreateThrottleFor(NavigationHandle* handle); |
| 31 |
| 32 ~ClearSiteDataThrottle() override; |
| 33 |
| 34 // NavigationThrottle implementation: |
| 35 ThrottleCheckResult WillStartRequest() override; |
| 36 ThrottleCheckResult WillProcessResponse() override; |
| 37 ThrottleCheckResult WillRedirectRequest() override; |
| 38 |
| 39 private: |
| 40 struct ConsoleMessage { |
| 41 std::string text; |
| 42 ConsoleMessageLevel level; |
| 43 }; |
| 44 |
| 45 explicit ClearSiteDataThrottle(NavigationHandle* handle); |
| 46 |
| 47 // Scans for 'Clear-Site-Data' headers, calls ParseHeader() to parse them, |
| 48 // and requests the actual data clearing. This is the common logic |
| 49 // of WillProcessResponse() and WillRedirectRequest(). |
| 50 void HandleHeader(); |
| 51 |
| 52 // Parses the value of the 'Clear-Site-Data' header and outputs whether |
| 53 // the header requests to |clear_cookies|, |clear_storage|, and |clear_cache|. |
| 54 // The |messages| vector will be filled with messages to be output in the |
| 55 // console. Returns true if parsing was successful. |
| 56 bool ParseHeader(const std::string& header, |
| 57 bool* clear_cookies, bool* clear_storage, bool* clear_cache, |
| 58 std::vector<ConsoleMessage>* messages); |
| 59 |
| 60 // Console logging. Adds a |text| message with |level| to |messages|. |
| 61 void ConsoleLog( |
| 62 std::vector<ConsoleMessage>* messages, |
| 63 const std::string& text, ConsoleMessageLevel level); |
| 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 |