1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_H_
#define COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_H_
#include <stddef.h>
#include <map>
#include <string>
#include <vector>
#include "base/time/time.h"
#include "base/values.h"
#include "components/content_settings/core/common/content_settings_constraints.h"
#include "components/content_settings/core/common/content_settings_metadata.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/content_settings_rules.h"
#include "components/content_settings/core/common/content_settings_types.h"
// Different settings that can be assigned for a particular content type. We
// give the user the ability to set these on a global and per-origin basis.
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.content_settings
// GENERATED_JAVA_CLASS_NAME_OVERRIDE: ContentSettingValues
//
// TODO(nigeltao): migrate the Java users of this enum to the mojom-generated
// enum.
enum ContentSetting {
CONTENT_SETTING_DEFAULT = 0,
CONTENT_SETTING_ALLOW,
CONTENT_SETTING_BLOCK,
CONTENT_SETTING_ASK,
CONTENT_SETTING_SESSION_ONLY,
CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
CONTENT_SETTING_NUM_SETTINGS
};
// Range-checked conversion of an int to a ContentSetting, for use when reading
// prefs off disk.
ContentSetting IntToContentSetting(int content_setting);
struct ContentSettingPatternSource {
ContentSettingPatternSource(const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_patttern,
base::Value setting_value,
content_settings::mojom::ProviderType provider,
bool incognito,
content_settings::RuleMetaData metadata =
content_settings::RuleMetaData());
ContentSettingPatternSource(const ContentSettingPatternSource& other);
ContentSettingPatternSource();
ContentSettingPatternSource& operator=(
const ContentSettingPatternSource& other);
~ContentSettingPatternSource();
ContentSetting GetContentSetting() const;
bool IsExpired() const;
bool operator==(const ContentSettingPatternSource& other) const;
ContentSettingsPattern primary_pattern;
ContentSettingsPattern secondary_pattern;
base::Value setting_value;
content_settings::RuleMetaData metadata;
content_settings::mojom::ProviderType source =
content_settings::mojom::ProviderType::kNone;
bool incognito;
};
// Formatter method for Google Test.
std::ostream& operator<<(std::ostream& os,
const ContentSettingPatternSource& source);
typedef std::vector<ContentSettingPatternSource> ContentSettingsForOneType;
struct RendererContentSettingRules {
// Returns true if |content_type| is a type that is contained in this class.
// Any new type added below must also update this method.
static bool IsRendererContentSetting(ContentSettingsType content_type);
// Filters all the rules by matching the primary pattern with
// |outermost_main_frame_url|. Any new type added below that needs to match
// the primary pattern with the outermost main frame's url should also update
// this method.
void FilterRulesByOutermostMainFrameURL(const GURL& outermost_main_frame_url);
RendererContentSettingRules();
~RendererContentSettingRules();
RendererContentSettingRules(const RendererContentSettingRules& rules);
RendererContentSettingRules(RendererContentSettingRules&& rules);
RendererContentSettingRules& operator=(
const RendererContentSettingRules& rules);
RendererContentSettingRules& operator=(RendererContentSettingRules&& rules);
bool operator==(const RendererContentSettingRules& other) const;
ContentSettingsForOneType mixed_content_rules;
};
namespace content_settings {
using ProviderType = mojom::ProviderType;
// Enum containing the various source for content settings. Settings can be
// set by policy, extension, the user or by the custodian of a supervised user.
// Certain (internal) origins are allowlisted. For these origins the source is
// |SettingSource::kAllowList|.
//
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.content_settings
// GENERATED_JAVA_CLASS_NAME_OVERRIDE: ContentSettingSource
enum class SettingSource {
kNone,
kPolicy,
kExtension,
kUser,
kAllowList,
kSupervised,
kInstalledWebApp,
kTpcdGrant,
kOsJavascriptOptimizer,
kTest,
};
// |SettingInfo| provides meta data for content setting values. |source|
// contains the source of a value. |primary_pattern| and |secondary_pattern|
// contains the patterns of the appling rule.
struct SettingInfo {
SettingInfo();
SettingInfo(SettingInfo&& other);
SettingInfo(SettingInfo& other) = delete;
SettingInfo& operator=(SettingInfo&& other);
SettingInfo& operator=(const SettingInfo& other) = delete;
SettingInfo Clone() const;
SettingSource source = SettingSource::kNone;
ContentSettingsPattern primary_pattern;
ContentSettingsPattern secondary_pattern;
RuleMetaData metadata;
void SetAttributes(const content_settings::RuleEntry& rule_entry) {
primary_pattern = rule_entry.first.primary_pattern;
secondary_pattern = rule_entry.first.secondary_pattern;
metadata = rule_entry.second.metadata.Clone();
}
void SetAttributes(const ContentSettingPatternSource& content_setting) {
primary_pattern = content_setting.primary_pattern;
secondary_pattern = content_setting.secondary_pattern;
metadata = content_setting.metadata.Clone();
}
};
// Returns the SettingSource associated with the given ProviderType.
constexpr SettingSource GetSettingSourceFromProviderType(
ProviderType provider_type) {
switch (provider_type) {
case ProviderType::kWebuiAllowlistProvider:
case ProviderType::kComponentExtensionProvider:
return SettingSource::kAllowList;
case ProviderType::kPolicyProvider:
return SettingSource::kPolicy;
case ProviderType::kSupervisedProvider:
return SettingSource::kSupervised;
case ProviderType::kCustomExtensionProvider:
return SettingSource::kExtension;
case ProviderType::kInstalledWebappProvider:
return SettingSource::kInstalledWebApp;
case ProviderType::kJavascriptOptimizerAndroidProvider:
return SettingSource::kOsJavascriptOptimizer;
case ProviderType::kNotificationAndroidProvider:
case ProviderType::kOneTimePermissionProvider:
case ProviderType::kPrefProvider:
case ProviderType::kDefaultProvider:
return SettingSource::kUser;
case ProviderType::kProviderForTests:
case ProviderType::kOtherProviderForTests:
return SettingSource::kTest;
case content_settings::ProviderType::kNone:
return SettingSource::kNone;
}
}
} // namespace content_settings
#endif // COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_H_
|