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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/content_settings/content_settings_provider.h" | 15 #include "chrome/browser/content_settings/content_settings_provider.h" |
16 #include "chrome/browser/content_settings/content_settings_rule.h" | 16 #include "chrome/browser/content_settings/content_settings_rule.h" |
17 #include "chrome/browser/content_settings/host_content_settings_map.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/content_settings_pattern.h" | 19 #include "chrome/common/content_settings_pattern.h" |
| 20 #include "extensions/common/constants.h" |
20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // The names of the ContentSettingsType values, for use with dictionary prefs. | 25 // The names of the ContentSettingsType values, for use with dictionary prefs. |
25 const char* kTypeNames[] = { | 26 const char* kTypeNames[] = { |
26 "cookies", | 27 "cookies", |
27 "images", | 28 "images", |
28 "javascript", | 29 "javascript", |
29 "plugins", | 30 "plugins", |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 *return_setting = static_cast<ContentSettingsType>(type); | 73 *return_setting = static_cast<ContentSettingsType>(type); |
73 return true; | 74 return true; |
74 } | 75 } |
75 } | 76 } |
76 return false; | 77 return false; |
77 } | 78 } |
78 | 79 |
79 std::string CreatePatternString( | 80 std::string CreatePatternString( |
80 const ContentSettingsPattern& item_pattern, | 81 const ContentSettingsPattern& item_pattern, |
81 const ContentSettingsPattern& top_level_frame_pattern) { | 82 const ContentSettingsPattern& top_level_frame_pattern) { |
82 return item_pattern.ToString() | 83 return item_pattern.ToString(extensions::kExtensionScheme) |
83 + std::string(kPatternSeparator) | 84 + std::string(kPatternSeparator) |
84 + top_level_frame_pattern.ToString(); | 85 + top_level_frame_pattern.ToString(extensions::kExtensionScheme); |
85 } | 86 } |
86 | 87 |
87 PatternPair ParsePatternString(const std::string& pattern_str) { | 88 PatternPair ParsePatternString(const std::string& pattern_str) { |
88 std::vector<std::string> pattern_str_list; | 89 std::vector<std::string> pattern_str_list; |
89 base::SplitString(pattern_str, kPatternSeparator[0], &pattern_str_list); | 90 base::SplitString(pattern_str, kPatternSeparator[0], &pattern_str_list); |
90 | 91 |
91 // If the |pattern_str| is an empty string then the |pattern_string_list| | 92 // If the |pattern_str| is an empty string then the |pattern_string_list| |
92 // contains a single empty string. In this case the empty string will be | 93 // contains a single empty string. In this case the empty string will be |
93 // removed to signal an invalid |pattern_str|. Invalid pattern strings are | 94 // removed to signal an invalid |pattern_str|. Invalid pattern strings are |
94 // handle by the "if"-statment below. So the order of the if statements here | 95 // handle by the "if"-statment below. So the order of the if statements here |
95 // must be preserved. | 96 // must be preserved. |
96 if (pattern_str_list.size() == 1) { | 97 if (pattern_str_list.size() == 1) { |
97 if (pattern_str_list[0].empty()) { | 98 if (pattern_str_list[0].empty()) { |
98 pattern_str_list.pop_back(); | 99 pattern_str_list.pop_back(); |
99 } else { | 100 } else { |
100 pattern_str_list.push_back("*"); | 101 pattern_str_list.push_back("*"); |
101 } | 102 } |
102 } | 103 } |
103 | 104 |
104 if (pattern_str_list.size() > 2 || | 105 if (pattern_str_list.size() > 2 || |
105 pattern_str_list.size() == 0) { | 106 pattern_str_list.size() == 0) { |
106 return PatternPair(ContentSettingsPattern(), | 107 return PatternPair(ContentSettingsPattern(), |
107 ContentSettingsPattern()); | 108 ContentSettingsPattern()); |
108 } | 109 } |
109 | 110 |
110 PatternPair pattern_pair; | 111 PatternPair pattern_pair; |
111 pattern_pair.first = | 112 pattern_pair.first = |
112 ContentSettingsPattern::FromString(pattern_str_list[0]); | 113 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 114 pattern_str_list[0]); |
113 pattern_pair.second = | 115 pattern_pair.second = |
114 ContentSettingsPattern::FromString(pattern_str_list[1]); | 116 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 117 pattern_str_list[1]); |
115 return pattern_pair; | 118 return pattern_pair; |
116 } | 119 } |
117 | 120 |
118 ContentSetting ValueToContentSetting(const base::Value* value) { | 121 ContentSetting ValueToContentSetting(const base::Value* value) { |
119 ContentSetting setting = CONTENT_SETTING_DEFAULT; | 122 ContentSetting setting = CONTENT_SETTING_DEFAULT; |
120 bool valid = ParseContentSettingValue(value, &setting); | 123 bool valid = ParseContentSettingValue(value, &setting); |
121 DCHECK(valid); | 124 DCHECK(valid); |
122 return setting; | 125 return setting; |
123 } | 126 } |
124 | 127 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 213 |
211 void GetRendererContentSettingRules(const HostContentSettingsMap* map, | 214 void GetRendererContentSettingRules(const HostContentSettingsMap* map, |
212 RendererContentSettingRules* rules) { | 215 RendererContentSettingRules* rules) { |
213 map->GetSettingsForOneType( | 216 map->GetSettingsForOneType( |
214 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &(rules->image_rules)); | 217 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &(rules->image_rules)); |
215 map->GetSettingsForOneType( | 218 map->GetSettingsForOneType( |
216 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &(rules->script_rules)); | 219 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &(rules->script_rules)); |
217 } | 220 } |
218 | 221 |
219 } // namespace content_settings | 222 } // namespace content_settings |
OLD | NEW |