Index: content/browser/browsing_data/clear_site_data_throttle.h |
diff --git a/content/browser/browsing_data/clear_site_data_throttle.h b/content/browser/browsing_data/clear_site_data_throttle.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..20f5e19b90cb7585cbfc3eb12e46a0fa6a0a4fe3 |
--- /dev/null |
+++ b/content/browser/browsing_data/clear_site_data_throttle.h |
@@ -0,0 +1,77 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ |
+#define CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ |
+ |
+#include <memory> |
+#include <vector> |
+ |
+#include "base/gtest_prod_util.h" |
+#include "base/macros.h" |
+#include "base/values.h" |
+#include "content/public/browser/navigation_throttle.h" |
+#include "content/public/browser/resource_request_info.h" |
+#include "content/public/common/console_message_level.h" |
+#include "url/gurl.h" |
+ |
+class Profile; |
+ |
+namespace content { |
+ |
+class NavigationHandle; |
+ |
+// This throttle asynchronously executes the clearing of browsing data. |
+// It does not block navigation. |
+class CONTENT_EXPORT ClearSiteDataThrottle : public NavigationThrottle { |
+ public: |
+ static std::unique_ptr<NavigationThrottle> |
+ CreateThrottleFor(NavigationHandle* handle); |
+ |
+ ~ClearSiteDataThrottle() override; |
+ |
+ // NavigationThrottle implementation: |
+ ThrottleCheckResult WillStartRequest() override; |
+ ThrottleCheckResult WillProcessResponse() override; |
+ ThrottleCheckResult WillRedirectRequest() override; |
+ |
+ private: |
+ struct ConsoleMessage { |
+ std::string text; |
+ ConsoleMessageLevel level; |
+ }; |
+ |
+ explicit ClearSiteDataThrottle(NavigationHandle* handle); |
+ |
+ // Scans for 'Clear-Site-Data' headers, calls ParseHeader() to parse them, |
+ // and requests the actual data clearing. This is the common logic |
+ // of WillProcessResponse() and WillRedirectRequest(). |
+ void HandleHeader(); |
+ |
+ // Parses the value of the 'Clear-Site-Data' header and outputs whether |
+ // the header requests to |clear_cookies|, |clear_storage|, and |clear_cache|. |
+ // The |messages| vector will be filled with messages to be output in the |
+ // console. Returns true if parsing was successful. |
+ bool ParseHeader(const std::string& header, |
+ bool* clear_cookies, bool* clear_storage, bool* clear_cache, |
+ std::vector<ConsoleMessage>* messages); |
+ |
+ // Console logging. Adds a |text| message with |level| to |messages|. |
+ void ConsoleLog( |
+ std::vector<ConsoleMessage>* messages, |
+ const std::string& text, ConsoleMessageLevel level); |
+ |
+ // Cached console messages to be output when the RenderFrameHost is ready. |
+ std::vector<ConsoleMessage> messages_; |
+ GURL current_url_; |
+ |
+ FRIEND_TEST_ALL_PREFIXES(ClearSiteDataThrottleTest, ParseHeader); |
+ FRIEND_TEST_ALL_PREFIXES(ClearSiteDataThrottleTest, InvalidHeader); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ClearSiteDataThrottle); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_THROTTLE_H_ |