Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / components / content_settings / core / browser / content_settings_utils.h
blob37d590e03b319eaf76885acc037385e4a91d1b66
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_
8 #include <string>
9 #include <utility>
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"
17 namespace base {
18 class Value;
21 class GURL;
22 class HostContentSettingsMap;
24 namespace content_settings {
26 class ProviderInterface;
27 class RuleIterator;
29 typedef std::pair<ContentSettingsPattern, ContentSettingsPattern> PatternPair;
31 // These constants are copied from extensions/common/extension_constants.h and
32 // content/public/common/url_constants.h to avoid complicated dependencies.
33 // TODO(vabr): Get these constants through the ContentSettingsClient.
34 const char kChromeDevToolsScheme[] = "chrome-devtools";
35 const char kChromeUIScheme[] = "chrome";
37 #if defined(ENABLE_EXTENSIONS)
38 const char kExtensionScheme[] = "chrome-extension";
39 #endif
41 std::string ContentSettingToString(ContentSetting setting);
43 ContentSetting ContentSettingFromString(const std::string& name);
45 // Converts |Value| to |ContentSetting|.
46 ContentSetting ValueToContentSetting(const base::Value* value);
48 // Converts a |Value| to a |ContentSetting|. Returns true if |value| encodes
49 // a valid content setting, false otherwise. Note that |CONTENT_SETTING_DEFAULT|
50 // is encoded as a NULL value, so it is not allowed as an integer value.
51 bool ParseContentSettingValue(const base::Value* value,
52 ContentSetting* setting);
54 PatternPair ParsePatternString(const std::string& pattern_str);
56 std::string CreatePatternString(
57 const ContentSettingsPattern& item_pattern,
58 const ContentSettingsPattern& top_level_frame_pattern);
60 // Caller takes the ownership of the returned |base::Value*|.
61 base::Value* GetContentSettingValueAndPatterns(
62 RuleIterator* rule_iterator,
63 const GURL& primary_url,
64 const GURL& secondary_url,
65 ContentSettingsPattern* primary_pattern,
66 ContentSettingsPattern* secondary_pattern);
68 // Returns a |base::Value*| representation of |setting| if |setting| is
69 // a valid content setting. Otherwise, returns a nullptr.
70 scoped_ptr<base::Value> ContentSettingToValue(ContentSetting setting);
72 base::Value* GetContentSettingValueAndPatterns(
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,
79 ContentSettingsPattern* primary_pattern,
80 ContentSettingsPattern* secondary_pattern);
82 // Populates |rules| with content setting rules for content types that are
83 // handled by the renderer.
84 void GetRendererContentSettingRules(const HostContentSettingsMap* map,
85 RendererContentSettingRules* rules);
87 } // namespace content_settings
89 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_UTILS_H_