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