Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / content_settings / content_settings_utils.h
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.
4
5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_UTILS_H_
6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_UTILS_H_
7
8 #include <string>
9 #include <utility>
10
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"
14
15 namespace base {
16 class Value;
17 }
18
19 class GURL;
20 class HostContentSettingsMap;
21
22 namespace content_settings {
23
24 class ProviderInterface;
25 class RuleIterator;
26
27 typedef std::pair<ContentSettingsPattern, ContentSettingsPattern> PatternPair;
28
29 std::string GetTypeName(ContentSettingsType type);
30
31 bool GetTypeFromName(const std::string& name,
32                      ContentSettingsType* return_setting);
33
34 // Converts |Value| to |ContentSetting|.
35 ContentSetting ValueToContentSetting(const base::Value* value);
36
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);
42
43 PatternPair ParsePatternString(const std::string& pattern_str);
44
45 std::string CreatePatternString(
46     const ContentSettingsPattern& item_pattern,
47     const ContentSettingsPattern& top_level_frame_pattern);
48
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);
56
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);
66
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);
74
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);
82
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);
87
88 }  // namespace content_settings
89
90 #endif  // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_UTILS_H_