1 // Copyright 2015 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 COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_INFO_H_
6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_INFO_H_
7 
8 #include <set>
9 #include <string>
10 #include <vector>
11 
12 #include "base/macros.h"
13 #include "components/content_settings/core/common/content_settings.h"
14 
15 namespace content_settings {
16 
17 class WebsiteSettingsInfo;
18 
19 class ContentSettingsInfo {
20  public:
21   enum IncognitoBehavior {
22     // Content setting will be inherited from regular to incognito profiles
23     // as usual. This should only be used for features that don't allow access
24     // to user data e.g. popup blocker or features that are allowed by default.
25     INHERIT_IN_INCOGNITO,
26 
27     // Content settings can be inherited if the setting is less permissive
28     // than the initial default value of the content setting. Example: A setting
29     // with an initial value of ASK will be inherited if it is set to BLOCK or
30     // ASK but ALLOW will become ASK in incognito mode. This should be used for
31     // all settings that allow access to user data, e.g. geolocation.
32     INHERIT_IF_LESS_PERMISSIVE
33   };
34 
35   enum StorageBehavior {
36     // The setting is stored and used in future sessions.
37     PERSISTENT,
38     // The setting is only valid throughout the current session.
39     EPHEMERAL,
40   };
41 
42   enum OriginRestriction {
43     // This flag indicates content types that only allow exceptions to be set
44     // on secure origins.
45     EXCEPTIONS_ON_SECURE_ORIGINS_ONLY,
46     // This flag indicates content types that allow exceptions to be set on
47     // secure and insecure origins.
48     EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS,
49   };
50 
51   // This object does not take ownership of |website_settings_info|.
52   ContentSettingsInfo(const WebsiteSettingsInfo* website_settings_info,
53                       const std::vector<std::string>& allowlisted_schemes,
54                       const std::set<ContentSetting>& valid_settings,
55                       IncognitoBehavior incognito_behavior,
56                       StorageBehavior storage_behavior,
57                       OriginRestriction origin_restriction);
58   ~ContentSettingsInfo();
59 
website_settings_info()60   const WebsiteSettingsInfo* website_settings_info() const {
61     return website_settings_info_;
62   }
allowlisted_schemes()63   const std::vector<std::string>& allowlisted_schemes() const {
64     return allowlisted_schemes_;
65   }
66 
67   // Gets the original default setting for a particular content type.
68   ContentSetting GetInitialDefaultSetting() const;
69 
70   bool IsSettingValid(ContentSetting setting) const;
71   bool IsDefaultSettingValid(ContentSetting setting) const;
72 
incognito_behavior()73   IncognitoBehavior incognito_behavior() const { return incognito_behavior_; }
storage_behavior()74   StorageBehavior storage_behavior() const { return storage_behavior_; }
origin_restriction()75   OriginRestriction origin_restriction() const { return origin_restriction_; }
76 
77  private:
78   const WebsiteSettingsInfo* website_settings_info_;
79   const std::vector<std::string> allowlisted_schemes_;
80   const std::set<ContentSetting> valid_settings_;
81   const IncognitoBehavior incognito_behavior_;
82   const StorageBehavior storage_behavior_;
83   const OriginRestriction origin_restriction_;
84 
85   DISALLOW_COPY_AND_ASSIGN(ContentSettingsInfo);
86 };
87 
88 }  // namespace content_settings
89 
90 #endif  // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_INFO_H_
91