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 "base/memory/scoped_ptr.h"
13 #include "components/content_settings/core/common/content_settings.h"
14 #include "components/content_settings/core/common/content_settings_pattern.h"
15 #include "components/content_settings/core/common/content_settings_types.h"
22 class HostContentSettingsMap
;
24 namespace content_settings
{
26 class ProviderInterface
;
29 typedef std::pair
<ContentSettingsPattern
, ContentSettingsPattern
> PatternPair
;
31 std::string
ContentSettingToString(ContentSetting setting
);
33 ContentSetting
ContentSettingFromString(const std::string
& name
);
35 // Converts |Value| to |ContentSetting|.
36 ContentSetting
ValueToContentSetting(const base::Value
* value
);
38 // Converts a |Value| to a |ContentSetting|. Returns true if |value| encodes
39 // a valid content setting, false otherwise. Note that |CONTENT_SETTING_DEFAULT|
40 // is encoded as a NULL value, so it is not allowed as an integer value.
41 bool ParseContentSettingValue(const base::Value
* value
,
42 ContentSetting
* setting
);
44 PatternPair
ParsePatternString(const std::string
& pattern_str
);
46 std::string
CreatePatternString(
47 const ContentSettingsPattern
& item_pattern
,
48 const ContentSettingsPattern
& top_level_frame_pattern
);
50 // Caller takes the ownership of the returned |base::Value*|.
51 base::Value
* GetContentSettingValueAndPatterns(
52 RuleIterator
* rule_iterator
,
53 const GURL
& primary_url
,
54 const GURL
& secondary_url
,
55 ContentSettingsPattern
* primary_pattern
,
56 ContentSettingsPattern
* secondary_pattern
);
58 // Returns a |base::Value*| representation of |setting| if |setting| is
59 // a valid content setting. Otherwise, returns a nullptr.
60 scoped_ptr
<base::Value
> ContentSettingToValue(ContentSetting setting
);
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_