| 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_
|
|
|