Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(577)

Unified Diff: content/browser/browsing_data/clear_site_data_throttle.h

Issue 2025683003: First experimental implementation of the Clear-Site-Data header (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WebContentsObserver Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..222258c704e2f784a49768b811a890d9bcd5eb07
--- /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/browser/web_contents_observer.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,
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
+ public WebContentsObserver {
+ public:
+ struct ConsoleMessage {
+ std::string text;
+ ConsoleMessageLevel level;
+ };
+
+ static std::unique_ptr<NavigationThrottle>
+ CreateThrottleFor(NavigationHandle* handle);
+
+ ~ClearSiteDataThrottle() override;
+
+ // NavigationThrottle implementation:
+ ThrottleCheckResult WillStartRequest() override;
+ ThrottleCheckResult WillProcessResponse() override;
+ ThrottleCheckResult WillRedirectRequest() override;
+
+ // WebContentsObserver implementation:
+ void DidFinishNavigation(NavigationHandle* handle) override;
+
+ private:
+ 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);
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698