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_HEADER_OBSERVER_H_ |
| 6 #define CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_HEADER_OBSERVER_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/resource_request_info.h" |
| 15 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "content/public/common/console_message_level.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 namespace content { |
| 20 |
| 21 class NavigationHandle; |
| 22 |
| 23 // This observer parses the Clear-Site-Data header and asynchronously executes |
| 24 // the clearing of browsing data. See the W3C working draft at |
| 25 // https://www.w3.org/TR/clear-site-data/. |
| 26 // TODO(msramek): It is currently not clear whether we should defer |
| 27 // the navigation until clearing is complete. If we decide that it should, |
| 28 // this class should be instead implemented as a NavigationThrottle. |
| 29 class CONTENT_EXPORT ClearSiteDataHeaderObserver : public WebContentsObserver { |
| 30 public: |
| 31 struct ConsoleMessage { |
| 32 GURL url; |
| 33 std::string text; |
| 34 ConsoleMessageLevel level; |
| 35 }; |
| 36 |
| 37 static std::unique_ptr<ClearSiteDataHeaderObserver> CreateFor( |
| 38 NavigationHandle* handle); |
| 39 |
| 40 ~ClearSiteDataHeaderObserver() override; |
| 41 |
| 42 // WebContentsObserver implementation: |
| 43 void DidStartNavigation(NavigationHandle* handle) override; |
| 44 void DidRedirectNavigation(NavigationHandle* handle) override; |
| 45 void DidFinishNavigation(NavigationHandle* handle) override; |
| 46 |
| 47 private: |
| 48 friend class ClearSiteDataHeaderObserverTest; |
| 49 FRIEND_TEST_ALL_PREFIXES(ClearSiteDataHeaderObserverTest, ParseHeader); |
| 50 FRIEND_TEST_ALL_PREFIXES(ClearSiteDataHeaderObserverTest, InvalidHeader); |
| 51 |
| 52 explicit ClearSiteDataHeaderObserver(WebContents* web_contents); |
| 53 |
| 54 // Scans for 'Clear-Site-Data' headers, calls ParseHeader() to parse them, |
| 55 // and requests the actual data clearing. This is the common logic |
| 56 // of DidFinishNavigation() and DidRedirectNavigation(). |
| 57 void HandleHeader(NavigationHandle* navigation_handle); |
| 58 |
| 59 // Parses the value of the 'Clear-Site-Data' header and outputs whether |
| 60 // the header requests to |clear_cookies|, |clear_storage|, and |clear_cache|. |
| 61 // The |messages| vector will be filled with messages to be output in the |
| 62 // console. Returns true if parsing was successful. |
| 63 bool ParseHeader(const std::string& header, |
| 64 bool* clear_cookies, |
| 65 bool* clear_storage, |
| 66 bool* clear_cache, |
| 67 std::vector<ConsoleMessage>* messages); |
| 68 |
| 69 // Cached console messages to be output when the RenderFrameHost is ready. |
| 70 std::vector<ConsoleMessage> messages_; |
| 71 GURL current_url_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(ClearSiteDataHeaderObserver); |
| 74 }; |
| 75 |
| 76 } // namespace content |
| 77 |
| 78 #endif // CONTENT_BROWSER_BROWSING_DATA_CLEAR_SITE_DATA_HEADER_OBSERVER_H_ |
OLD | NEW |