Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: chrome/common/extensions/url_pattern_set.cc

Issue 10809094: Context Menus now uses the JSON Schema Compiler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@json_functions_as_properties
Patch Set: switchy switch switch switch switch switch. switchy switch. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/extensions/url_pattern_set.h" 5 #include "chrome/common/extensions/url_pattern_set.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 168 }
169 169
170 scoped_ptr<base::ListValue> URLPatternSet::ToValue() const { 170 scoped_ptr<base::ListValue> URLPatternSet::ToValue() const {
171 scoped_ptr<ListValue> value(new ListValue); 171 scoped_ptr<ListValue> value(new ListValue);
172 for (URLPatternSet::const_iterator i = patterns_.begin(); 172 for (URLPatternSet::const_iterator i = patterns_.begin();
173 i != patterns_.end(); ++i) 173 i != patterns_.end(); ++i)
174 value->AppendIfNotPresent(Value::CreateStringValue(i->GetAsString())); 174 value->AppendIfNotPresent(Value::CreateStringValue(i->GetAsString()));
175 return value.Pass(); 175 return value.Pass();
176 } 176 }
177 177
178 bool URLPatternSet::Populate(const std::vector<std::string>& patterns,
179 int valid_schemes,
180 bool allow_file_access,
181 std::string* error) {
182 ClearPatterns();
183 for (size_t i = 0; i < patterns.size(); ++i) {
184 URLPattern pattern(valid_schemes);
185 if (pattern.Parse(patterns[i]) != URLPattern::PARSE_SUCCESS) {
186 if (error) {
187 *error = ExtensionErrorUtils::FormatErrorMessage(
188 kInvalidURLPatternError, patterns[i]);
189 } else {
190 LOG(ERROR) << "Invalid url pattern: " << patterns[i];
191 }
192 return false;
193 }
194 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) {
195 pattern.SetValidSchemes(
196 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE);
197 }
198 AddPattern(pattern);
199 }
200 return true;
201 }
202
178 bool URLPatternSet::Populate(const base::ListValue& value, 203 bool URLPatternSet::Populate(const base::ListValue& value,
179 int valid_schemes, 204 int valid_schemes,
180 bool allow_file_access, 205 bool allow_file_access,
181 std::string* error) { 206 std::string* error) {
182 ClearPatterns(); 207 ClearPatterns();
183 for (size_t i = 0; i < value.GetSize(); ++i) { 208 for (size_t i = 0; i < value.GetSize(); ++i) {
184 std::string item; 209 std::string item;
185 if (!value.GetString(i, &item)) 210 if (!value.GetString(i, &item))
186 return false; 211 return false;
187 URLPattern pattern(valid_schemes); 212 URLPattern pattern(valid_schemes);
188 if (pattern.Parse(item) != URLPattern::PARSE_SUCCESS) { 213 if (pattern.Parse(item) != URLPattern::PARSE_SUCCESS) {
189 if (error) { 214 if (error) {
190 *error = ExtensionErrorUtils::FormatErrorMessage( 215 *error = ExtensionErrorUtils::FormatErrorMessage(
191 kInvalidURLPatternError, item); 216 kInvalidURLPatternError, item);
192 } else { 217 } else {
193 LOG(ERROR) << "Invalid url pattern: " << item; 218 LOG(ERROR) << "Invalid url pattern: " << item;
194 } 219 }
195 return false; 220 return false;
196 } 221 }
197 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { 222 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) {
198 pattern.SetValidSchemes( 223 pattern.SetValidSchemes(
199 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); 224 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE);
200 } 225 }
201 AddPattern(pattern); 226 AddPattern(pattern);
202 } 227 }
not at google - send to devlin 2012/07/30 15:36:53 ditto. If we do, there is a lot of chance to shar
chebert 2012/07/30 22:45:19 Done.
203 return true; 228 return true;
204 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698