OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/content_settings/content_settings_utils.h" | 5 #include "chrome/browser/content_settings/content_settings_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 ContentSettingsType* return_setting) { | 69 ContentSettingsType* return_setting) { |
70 for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 70 for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
71 if (name.compare(kTypeNames[type]) == 0) { | 71 if (name.compare(kTypeNames[type]) == 0) { |
72 *return_setting = static_cast<ContentSettingsType>(type); | 72 *return_setting = static_cast<ContentSettingsType>(type); |
73 return true; | 73 return true; |
74 } | 74 } |
75 } | 75 } |
76 return false; | 76 return false; |
77 } | 77 } |
78 | 78 |
| 79 std::string ContentSettingToString(ContentSetting setting) { |
| 80 switch (setting) { |
| 81 case CONTENT_SETTING_ALLOW: |
| 82 return "allow"; |
| 83 case CONTENT_SETTING_ASK: |
| 84 return "ask"; |
| 85 case CONTENT_SETTING_BLOCK: |
| 86 return "block"; |
| 87 case CONTENT_SETTING_SESSION_ONLY: |
| 88 return "session"; |
| 89 case CONTENT_SETTING_DEFAULT: |
| 90 return "default"; |
| 91 case CONTENT_SETTING_NUM_SETTINGS: |
| 92 NOTREACHED(); |
| 93 } |
| 94 |
| 95 return std::string(); |
| 96 } |
| 97 |
| 98 ContentSetting ContentSettingFromString(const std::string& name) { |
| 99 if (name == "allow") |
| 100 return CONTENT_SETTING_ALLOW; |
| 101 if (name == "ask") |
| 102 return CONTENT_SETTING_ASK; |
| 103 if (name == "block") |
| 104 return CONTENT_SETTING_BLOCK; |
| 105 if (name == "session") |
| 106 return CONTENT_SETTING_SESSION_ONLY; |
| 107 |
| 108 NOTREACHED() << name << " is not a recognized content setting."; |
| 109 return CONTENT_SETTING_DEFAULT; |
| 110 } |
| 111 |
79 std::string CreatePatternString( | 112 std::string CreatePatternString( |
80 const ContentSettingsPattern& item_pattern, | 113 const ContentSettingsPattern& item_pattern, |
81 const ContentSettingsPattern& top_level_frame_pattern) { | 114 const ContentSettingsPattern& top_level_frame_pattern) { |
82 return item_pattern.ToString() | 115 return item_pattern.ToString() |
83 + std::string(kPatternSeparator) | 116 + std::string(kPatternSeparator) |
84 + top_level_frame_pattern.ToString(); | 117 + top_level_frame_pattern.ToString(); |
85 } | 118 } |
86 | 119 |
87 PatternPair ParsePatternString(const std::string& pattern_str) { | 120 PatternPair ParsePatternString(const std::string& pattern_str) { |
88 std::vector<std::string> pattern_str_list; | 121 std::vector<std::string> pattern_str_list; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 243 |
211 void GetRendererContentSettingRules(const HostContentSettingsMap* map, | 244 void GetRendererContentSettingRules(const HostContentSettingsMap* map, |
212 RendererContentSettingRules* rules) { | 245 RendererContentSettingRules* rules) { |
213 map->GetSettingsForOneType( | 246 map->GetSettingsForOneType( |
214 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &(rules->image_rules)); | 247 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &(rules->image_rules)); |
215 map->GetSettingsForOneType( | 248 map->GetSettingsForOneType( |
216 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &(rules->script_rules)); | 249 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &(rules->script_rules)); |
217 } | 250 } |
218 | 251 |
219 } // namespace content_settings | 252 } // namespace content_settings |
OLD | NEW |