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 "chrome/common/content_settings_types.h" 14 15namespace base { 16class Value; 17} 18 19class GURL; 20class HostContentSettingsMap; 21 22namespace content_settings { 23 24class ProviderInterface; 25class RuleIterator; 26 27typedef std::pair<ContentSettingsPattern, ContentSettingsPattern> PatternPair; 28 29std::string GetTypeName(ContentSettingsType type); 30 31// Converts |Value| to |ContentSetting|. 32ContentSetting ValueToContentSetting(const base::Value* value); 33 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. 37bool ParseContentSettingValue(const base::Value* value, 38 ContentSetting* setting); 39 40PatternPair ParsePatternString(const std::string& pattern_str); 41 42std::string CreatePatternString( 43 const ContentSettingsPattern& item_pattern, 44 const ContentSettingsPattern& top_level_frame_pattern); 45 46// Caller takes the ownership of the returned |base::Value*|. 47base::Value* GetContentSettingValueAndPatterns( 48 RuleIterator* rule_iterator, 49 const GURL& primary_url, 50 const GURL& secondary_url, 51 ContentSettingsPattern* primary_pattern, 52 ContentSettingsPattern* secondary_pattern); 53 54base::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); 63 64base::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); 71 72ContentSetting 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); 79 80// Populates |rules| with content setting rules for content types that are 81// handled by the renderer. 82void GetRendererContentSettingRules(const HostContentSettingsMap* map, 83 RendererContentSettingRules* rules); 84 85} // namespace content_settings 86 87#endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_UTILS_H_ 88