1 // Copyright (c) 2012 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.
5 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_UTILS_H_
6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_UTILS_H_
11 #include "base/compiler_specific.h"
12 #include "components/content_settings/core/common/content_settings.h"
13 #include "components/content_settings/core/common/content_settings_pattern.h"
14 #include "components/content_settings/core/common/content_settings_types.h"
21 class HostContentSettingsMap
;
23 namespace content_settings
{
25 class ProviderInterface
;
28 typedef std::pair
<ContentSettingsPattern
, ContentSettingsPattern
> PatternPair
;
30 std::string
GetTypeName(ContentSettingsType type
);
32 bool GetTypeFromName(const std::string
& name
,
33 ContentSettingsType
* return_setting
) WARN_UNUSED_RESULT
;
35 std::string
ContentSettingToString(ContentSetting setting
);
37 ContentSetting
ContentSettingFromString(const std::string
& name
);
39 // Converts |Value| to |ContentSetting|.
40 ContentSetting
ValueToContentSetting(const base::Value
* value
);
42 // Converts a |Value| to a |ContentSetting|. Returns true if |value| encodes
43 // a valid content setting, false otherwise. Note that |CONTENT_SETTING_DEFAULT|
44 // is encoded as a NULL value, so it is not allowed as an integer value.
45 bool ParseContentSettingValue(const base::Value
* value
,
46 ContentSetting
* setting
);
48 PatternPair
ParsePatternString(const std::string
& pattern_str
);
50 std::string
CreatePatternString(
51 const ContentSettingsPattern
& item_pattern
,
52 const ContentSettingsPattern
& top_level_frame_pattern
);
54 // Caller takes the ownership of the returned |base::Value*|.
55 base::Value
* GetContentSettingValueAndPatterns(
56 RuleIterator
* rule_iterator
,
57 const GURL
& primary_url
,
58 const GURL
& secondary_url
,
59 ContentSettingsPattern
* primary_pattern
,
60 ContentSettingsPattern
* secondary_pattern
);
62 base::Value
* GetContentSettingValueAndPatterns(
63 const ProviderInterface
* provider
,
64 const GURL
& primary_url
,
65 const GURL
& secondary_url
,
66 ContentSettingsType content_type
,
67 const std::string
& resource_identifier
,
68 bool include_incognito
,
69 ContentSettingsPattern
* primary_pattern
,
70 ContentSettingsPattern
* secondary_pattern
);
72 // Populates |rules| with content setting rules for content types that are
73 // handled by the renderer.
74 void GetRendererContentSettingRules(const HostContentSettingsMap
* map
,
75 RendererContentSettingRules
* rules
);
77 } // namespace content_settings
79 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_UTILS_H_