OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS_MA
NAGER_H_ | 5 #ifndef CHROME_BROWSER_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS_MA
NAGER_H_ |
6 #define CHROME_BROWSER_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS_MA
NAGER_H_ | 6 #define CHROME_BROWSER_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS_MA
NAGER_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 #include <set> |
8 #include <string> | 10 #include <string> |
| 11 #include <utility> |
9 | 12 |
10 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/scoped_observer.h" |
| 15 #include "base/time/clock.h" |
| 16 #include "base/time/time.h" |
11 #include "components/content_settings/core/browser/content_settings_observer.h" | 17 #include "components/content_settings/core/browser/content_settings_observer.h" |
| 18 #include "components/content_settings/core/common/content_settings.h" |
12 #include "components/content_settings/core/common/content_settings_types.h" | 19 #include "components/content_settings/core/common/content_settings_types.h" |
| 20 #include "components/history/core/browser/history_service_observer.h" |
13 | 21 |
14 class ContentSettingsPattern; | 22 class ContentSettingsPattern; |
| 23 class GURL; |
15 class HostContentSettingsMap; | 24 class HostContentSettingsMap; |
16 class Profile; | 25 class Profile; |
17 | 26 |
18 // This class observes subresource filter content settings changes for metrics | 27 namespace base { |
19 // collection. | 28 class DictionaryValue; |
| 29 } // namespace base |
| 30 |
| 31 namespace history { |
| 32 class HistoryService; |
| 33 } // namespace history |
| 34 |
| 35 // This class contains helpers to get/set content and website settings related |
| 36 // to subresource filtering. It also observes content setting changes for |
| 37 // metrics collection. |
20 class SubresourceFilterContentSettingsManager | 38 class SubresourceFilterContentSettingsManager |
21 : public content_settings::Observer { | 39 : public content_settings::Observer, |
| 40 public history::HistoryServiceObserver { |
22 public: | 41 public: |
23 explicit SubresourceFilterContentSettingsManager(Profile* profile); | 42 explicit SubresourceFilterContentSettingsManager(Profile* profile); |
24 ~SubresourceFilterContentSettingsManager() override; | 43 ~SubresourceFilterContentSettingsManager() override; |
25 | 44 |
| 45 ContentSetting GetSitePermission(const GURL& url) const; |
| 46 |
| 47 // Only called via direct user action on via the subresource filter UI. Sets |
| 48 // the content setting to turn off the subresource filter. |
| 49 void WhitelistSite(const GURL& url); |
| 50 |
| 51 // Specific logic for more intelligent UI. |
| 52 void OnDidShowUI(const GURL& url); |
| 53 bool ShouldShowUIForSite(const GURL& url) const; |
| 54 bool should_use_smart_ui() const { return should_use_smart_ui_; } |
| 55 |
| 56 void set_clock_for_testing(std::unique_ptr<base::Clock> tick_clock) { |
| 57 clock_ = std::move(tick_clock); |
| 58 } |
| 59 |
| 60 // Time before showing the UI again on a domain. |
| 61 // TODO(csharrison): Consider setting this via a finch param. |
| 62 static constexpr base::TimeDelta kDelayBeforeShowingInfobarAgain = |
| 63 base::TimeDelta::FromMinutes(30); |
| 64 |
26 private: | 65 private: |
27 // content_settings::Observer: | 66 // content_settings::Observer: |
28 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | 67 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
29 const ContentSettingsPattern& secondary_pattern, | 68 const ContentSettingsPattern& secondary_pattern, |
30 ContentSettingsType content_type, | 69 ContentSettingsType content_type, |
31 std::string resource_identifier) override; | 70 std::string resource_identifier) override; |
32 | 71 |
| 72 // history::HistoryServiceObserver: |
| 73 void OnURLsDeleted(history::HistoryService* history_service, |
| 74 bool all_history, |
| 75 bool expired, |
| 76 const history::URLRows& deleted_rows, |
| 77 const std::set<GURL>& favicon_urls) override; |
| 78 |
| 79 std::unique_ptr<base::DictionaryValue> GetSiteMetadata(const GURL& url) const; |
| 80 void SetSiteMetadata(const GURL& url, |
| 81 std::unique_ptr<base::DictionaryValue> dict); |
| 82 |
| 83 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
| 84 history_observer_; |
| 85 |
33 HostContentSettingsMap* settings_map_; | 86 HostContentSettingsMap* settings_map_; |
34 | 87 |
| 88 // A clock is injected into this class so tests can set arbitrary timestamps |
| 89 // in website settings. |
| 90 std::unique_ptr<base::Clock> clock_; |
| 91 |
| 92 // Used internally so the class ignores changes to the settings that are not |
| 93 // user initiated through the settings UI. |
| 94 bool ignore_settings_changes_ = false; |
| 95 |
| 96 const bool should_use_smart_ui_ = false; |
| 97 |
35 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterContentSettingsManager); | 98 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterContentSettingsManager); |
36 }; | 99 }; |
37 | 100 |
38 #endif // CHROME_BROWSER_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS
_MANAGER_H_ | 101 #endif // CHROME_BROWSER_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS
_MANAGER_H_ |
OLD | NEW |