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

Unified Diff: content/browser/browsing_data/clear_site_data_header_observer.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: Addressed comments, git cl format 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_header_observer.h
diff --git a/content/browser/browsing_data/clear_site_data_header_observer.h b/content/browser/browsing_data/clear_site_data_header_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..6ce06268890ece6046ac838a1a17dcf2425b8842
--- /dev/null
+++ b/content/browser/browsing_data/clear_site_data_header_observer.h
@@ -0,0 +1,78 @@
+// 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_HEADER_OBSERVER_H_
+#define CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_HEADER_OBSERVER_H_
+
+#include <memory>
+#include <vector>
+
+#include "base/gtest_prod_util.h"
+#include "base/macros.h"
+#include "base/values.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"
+
+namespace content {
+
+class NavigationHandle;
+
+// This observer parses the Clear-Site-Data header and asynchronously executes
+// the clearing of browsing data. See the W3C working draft at
+// https://www.w3.org/TR/clear-site-data/.
+// TODO(msramek): It is currently not clear whether we should defer
+// the navigation until clearing is complete. If we decide that it should,
+// this class should be instead implemented as a NavigationThrottle.
+class CONTENT_EXPORT ClearSiteDataHeaderObserver : public WebContentsObserver {
+ public:
+ struct ConsoleMessage {
+ GURL url;
+ std::string text;
+ ConsoleMessageLevel level;
+ };
+
+ static std::unique_ptr<ClearSiteDataHeaderObserver> CreateFor(
+ NavigationHandle* handle);
+
+ ~ClearSiteDataHeaderObserver() override;
+
+ // WebContentsObserver implementation:
+ void DidStartNavigation(NavigationHandle* handle) override;
+ void DidRedirectNavigation(NavigationHandle* handle) override;
+ void DidFinishNavigation(NavigationHandle* handle) override;
+
+ private:
+ friend class ClearSiteDataHeaderObserverTest;
+ FRIEND_TEST_ALL_PREFIXES(ClearSiteDataHeaderObserverTest, ParseHeader);
+ FRIEND_TEST_ALL_PREFIXES(ClearSiteDataHeaderObserverTest, InvalidHeader);
+
+ explicit ClearSiteDataHeaderObserver(WebContents* web_contents);
+
+ // Scans for 'Clear-Site-Data' headers, calls ParseHeader() to parse them,
+ // and requests the actual data clearing. This is the common logic
+ // of DidFinishNavigation() and DidRedirectNavigation().
+ void HandleHeader(NavigationHandle* navigation_handle);
+
+ // 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_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClearSiteDataHeaderObserver);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_HEADER_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698