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_content_settings_client.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/content_settings_pattern.h" | 20 #include "chrome/common/content_settings_pattern.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", |
(...skipping 44 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 content_settings::ChromeContentSettingsClient client; |
| 84 return item_pattern.ToString(&client) |
83 + std::string(kPatternSeparator) | 85 + std::string(kPatternSeparator) |
84 + top_level_frame_pattern.ToString(); | 86 + top_level_frame_pattern.ToString(&client); |
85 } | 87 } |
86 | 88 |
87 PatternPair ParsePatternString(const std::string& pattern_str) { | 89 PatternPair ParsePatternString(const std::string& pattern_str) { |
88 std::vector<std::string> pattern_str_list; | 90 std::vector<std::string> pattern_str_list; |
89 base::SplitString(pattern_str, kPatternSeparator[0], &pattern_str_list); | 91 base::SplitString(pattern_str, kPatternSeparator[0], &pattern_str_list); |
90 | 92 |
91 // If the |pattern_str| is an empty string then the |pattern_string_list| | 93 // 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 | 94 // 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 | 95 // 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 | 96 // handle by the "if"-statment below. So the order of the if statements here |
95 // must be preserved. | 97 // must be preserved. |
96 if (pattern_str_list.size() == 1) { | 98 if (pattern_str_list.size() == 1) { |
97 if (pattern_str_list[0].empty()) { | 99 if (pattern_str_list[0].empty()) { |
98 pattern_str_list.pop_back(); | 100 pattern_str_list.pop_back(); |
99 } else { | 101 } else { |
100 pattern_str_list.push_back("*"); | 102 pattern_str_list.push_back("*"); |
101 } | 103 } |
102 } | 104 } |
103 | 105 |
104 if (pattern_str_list.size() > 2 || | 106 if (pattern_str_list.size() > 2 || |
105 pattern_str_list.size() == 0) { | 107 pattern_str_list.size() == 0) { |
106 return PatternPair(ContentSettingsPattern(), | 108 return PatternPair(ContentSettingsPattern(), |
107 ContentSettingsPattern()); | 109 ContentSettingsPattern()); |
108 } | 110 } |
109 | 111 |
| 112 content_settings::ChromeContentSettingsClient client; |
110 PatternPair pattern_pair; | 113 PatternPair pattern_pair; |
111 pattern_pair.first = | 114 pattern_pair.first = |
112 ContentSettingsPattern::FromString(pattern_str_list[0]); | 115 ContentSettingsPattern::FromString(&client, pattern_str_list[0]); |
113 pattern_pair.second = | 116 pattern_pair.second = |
114 ContentSettingsPattern::FromString(pattern_str_list[1]); | 117 ContentSettingsPattern::FromString(&client, 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 |