1 // Copyright (c) 2011 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 #include "chrome/browser/content_settings/content_settings_mock_provider.h" 6 7 namespace content_settings { 8 9 MockDefaultProvider::MockDefaultProvider( 10 ContentSettingsType content_type, 11 ContentSetting setting, 12 bool is_managed, 13 bool can_override) 14 : content_type_(content_type), 15 setting_(setting), 16 is_managed_(is_managed), 17 can_override_(can_override) { 18 } 19 20 MockDefaultProvider::~MockDefaultProvider() { 21 } 22 23 ContentSetting MockDefaultProvider::ProvideDefaultSetting( 24 ContentSettingsType content_type) const { 25 return content_type == content_type_ ? setting_ : CONTENT_SETTING_DEFAULT; 26 } 27 28 void MockDefaultProvider::UpdateDefaultSetting( 29 ContentSettingsType content_type, 30 ContentSetting setting) { 31 if (can_override_ && content_type == content_type_) 32 setting_ = setting; 33 } 34 35 bool MockDefaultProvider::DefaultSettingIsManaged( 36 ContentSettingsType content_type) const { 37 return content_type == content_type_ && is_managed_; 38 } 39 40 void MockDefaultProvider::ResetToDefaults() { 41 } 42 43 MockProvider::MockProvider() 44 : requesting_url_pattern_(ContentSettingsPattern()), 45 embedding_url_pattern_(ContentSettingsPattern()), 46 content_type_(CONTENT_SETTINGS_TYPE_COOKIES), 47 resource_identifier_(""), 48 setting_(CONTENT_SETTING_DEFAULT), 49 read_only_(false), 50 is_managed_(false) {} 51 52 MockProvider::MockProvider(ContentSettingsPattern requesting_url_pattern, 53 ContentSettingsPattern embedding_url_pattern, 54 ContentSettingsType content_type, 55 ResourceIdentifier resource_identifier, 56 ContentSetting setting, 57 bool read_only, 58 bool is_managed) 59 : requesting_url_pattern_(requesting_url_pattern), 60 embedding_url_pattern_(embedding_url_pattern), 61 content_type_(content_type), 62 resource_identifier_(resource_identifier), 63 setting_(setting), 64 read_only_(read_only), 65 is_managed_(is_managed) {} 66 67 MockProvider::~MockProvider() {} 68 69 ContentSetting MockProvider::GetContentSetting( 70 const GURL& requesting_url, 71 const GURL& embedding_url, 72 ContentSettingsType content_type, 73 const ResourceIdentifier& resource_identifier) const { 74 if (requesting_url_pattern_.Matches(requesting_url) && 75 content_type_ == content_type && 76 resource_identifier_ == resource_identifier) { 77 return setting_; 78 } 79 return CONTENT_SETTING_DEFAULT; 80 } 81 82 void MockProvider::SetContentSetting( 83 const ContentSettingsPattern& requesting_url_pattern, 84 const ContentSettingsPattern& embedding_url_pattern, 85 ContentSettingsType content_type, 86 const ResourceIdentifier& resource_identifier, 87 ContentSetting content_setting) { 88 if (read_only_) 89 return; 90 requesting_url_pattern_ = ContentSettingsPattern(requesting_url_pattern); 91 embedding_url_pattern_ = ContentSettingsPattern(embedding_url_pattern); 92 content_type_ = content_type; 93 resource_identifier_ = resource_identifier; 94 setting_ = content_setting; 95 } 96 97 bool MockProvider::ContentSettingsTypeIsManaged(ContentSettingsType type) { 98 if (type == content_type_) { 99 return is_managed_; 100 } 101 return false; 102 } 103 104 } // namespace content_settings 105