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