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 CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_UTILS_H_
6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_UTILS_H_
11 #include "components/content_settings/core/common/content_settings.h"
12 #include "components/content_settings/core/common/content_settings_pattern.h"
13 #include "components/content_settings/core/common/content_settings_types.h"
20 class HostContentSettingsMap
;
22 namespace content_settings
{
24 class ProviderInterface
;
27 typedef std::pair
<ContentSettingsPattern
, ContentSettingsPattern
> PatternPair
;
29 std::string
GetTypeName(ContentSettingsType type
);
31 bool GetTypeFromName(const std::string
& name
,
32 ContentSettingsType
* return_setting
);
34 std::string
ContentSettingToString(ContentSetting setting
);
36 ContentSetting
ContentSettingFromString(const std::string
& name
);
38 // Converts |Value| to |ContentSetting|.
39 ContentSetting
ValueToContentSetting(const base::Value
* value
);
41 // Converts a |Value| to a |ContentSetting|. Returns true if |value| encodes
42 // a valid content setting, false otherwise. Note that |CONTENT_SETTING_DEFAULT|
43 // is encoded as a NULL value, so it is not allowed as an integer value.
44 bool ParseContentSettingValue(const base::Value
* value
,
45 ContentSetting
* setting
);
47 PatternPair
ParsePatternString(const std::string
& pattern_str
);
49 std::string
CreatePatternString(
50 const ContentSettingsPattern
& item_pattern
,
51 const ContentSettingsPattern
& top_level_frame_pattern
);
53 // Caller takes the ownership of the returned |base::Value*|.
54 base::Value
* GetContentSettingValueAndPatterns(
55 RuleIterator
* rule_iterator
,
56 const GURL
& primary_url
,
57 const GURL
& secondary_url
,
58 ContentSettingsPattern
* primary_pattern
,
59 ContentSettingsPattern
* secondary_pattern
);
61 base::Value
* GetContentSettingValueAndPatterns(
62 const ProviderInterface
* provider
,
63 const GURL
& primary_url
,
64 const GURL
& secondary_url
,
65 ContentSettingsType content_type
,
66 const std::string
& resource_identifier
,
67 bool include_incognito
,
68 ContentSettingsPattern
* primary_pattern
,
69 ContentSettingsPattern
* secondary_pattern
);
71 base::Value
* GetContentSettingValue(
72 const ProviderInterface
* provider
,
73 const GURL
& primary_url
,
74 const GURL
& secondary_url
,
75 ContentSettingsType content_type
,
76 const std::string
& resource_identifier
,
77 bool include_incognito
);
79 ContentSetting
GetContentSetting(
80 const ProviderInterface
* provider
,
81 const GURL
& primary_url
,
82 const GURL
& secondary_url
,
83 ContentSettingsType content_type
,
84 const std::string
& resource_identifier
,
85 bool include_incognito
);
87 // Populates |rules| with content setting rules for content types that are
88 // handled by the renderer.
89 void GetRendererContentSettingRules(const HostContentSettingsMap
* map
,
90 RendererContentSettingRules
* rules
);
92 } // namespace content_settings
94 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_UTILS_H_