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