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 "chrome/common/content_settings.h"
12 #include "chrome/common/content_settings_pattern.h"
13 #include "chrome/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 // Converts |Value| to |ContentSetting|.
32 ContentSetting
ValueToContentSetting(const base::Value
* value
);
34 // Converts a |Value| to a |ContentSetting|. Returns true if |value| encodes
35 // a valid content setting, false otherwise. Note that |CONTENT_SETTING_DEFAULT|
36 // is encoded as a NULL value, so it is not allowed as an integer value.
37 bool ParseContentSettingValue(const base::Value
* value
,
38 ContentSetting
* setting
);
40 PatternPair
ParsePatternString(const std::string
& pattern_str
);
42 std::string
CreatePatternString(
43 const ContentSettingsPattern
& item_pattern
,
44 const ContentSettingsPattern
& top_level_frame_pattern
);
46 // Caller takes the ownership of the returned |base::Value*|.
47 base::Value
* GetContentSettingValueAndPatterns(
48 RuleIterator
* rule_iterator
,
49 const GURL
& primary_url
,
50 const GURL
& secondary_url
,
51 ContentSettingsPattern
* primary_pattern
,
52 ContentSettingsPattern
* secondary_pattern
);
54 base::Value
* GetContentSettingValueAndPatterns(
55 const ProviderInterface
* provider
,
56 const GURL
& primary_url
,
57 const GURL
& secondary_url
,
58 ContentSettingsType content_type
,
59 const std::string
& resource_identifier
,
60 bool include_incognito
,
61 ContentSettingsPattern
* primary_pattern
,
62 ContentSettingsPattern
* secondary_pattern
);
64 base::Value
* GetContentSettingValue(
65 const ProviderInterface
* provider
,
66 const GURL
& primary_url
,
67 const GURL
& secondary_url
,
68 ContentSettingsType content_type
,
69 const std::string
& resource_identifier
,
70 bool include_incognito
);
72 ContentSetting
GetContentSetting(
73 const ProviderInterface
* provider
,
74 const GURL
& primary_url
,
75 const GURL
& secondary_url
,
76 ContentSettingsType content_type
,
77 const std::string
& resource_identifier
,
78 bool include_incognito
);
80 // Populates |rules| with content setting rules for content types that are
81 // handled by the renderer.
82 void GetRendererContentSettingRules(const HostContentSettingsMap
* map
,
83 RendererContentSettingRules
* rules
);
85 } // namespace content_settings
87 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_UTILS_H_