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

Side by Side Diff: chrome/common/extensions/matcher/url_matcher_factory.cc

Issue 11312228: Move extension_error_utils.* and url_pattern_set.* into (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hate Created 8 years, 1 month 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 | Annotate | Revision Log
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/matcher/url_matcher_factory.h" 5 #include "chrome/common/extensions/matcher/url_matcher_factory.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/common/extensions/extension_error_utils.h"
12 #include "chrome/common/extensions/matcher/url_matcher_constants.h" 11 #include "chrome/common/extensions/matcher/url_matcher_constants.h"
13 #include "chrome/common/extensions/matcher/url_matcher_helpers.h" 12 #include "chrome/common/extensions/matcher/url_matcher_helpers.h"
13 #include "extensions/common/error_utils.h"
14 #include "third_party/re2/re2/re2.h" 14 #include "third_party/re2/re2/re2.h"
15 15
16 namespace helpers = extensions::url_matcher_helpers; 16 namespace helpers = extensions::url_matcher_helpers;
17 namespace keys = extensions::url_matcher_constants; 17 namespace keys = extensions::url_matcher_constants;
18 18
19 namespace { 19 namespace {
20 // Error messages: 20 // Error messages:
21 const char kInvalidPortRanges[] = "Invalid port ranges in UrlFilter."; 21 const char kInvalidPortRanges[] = "Invalid port ranges in UrlFilter.";
22 const char kVectorOfStringsExpected[] = 22 const char kVectorOfStringsExpected[] =
23 "UrlFilter attribute '*' expected a vector of strings as parameter."; 23 "UrlFilter attribute '*' expected a vector of strings as parameter.";
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 if (!error->empty()) 127 if (!error->empty())
128 return scoped_refptr<URLMatcherConditionSet>(NULL); 128 return scoped_refptr<URLMatcherConditionSet>(NULL);
129 } else if (condition_attribute_name == keys::kPortsKey) { 129 } else if (condition_attribute_name == keys::kPortsKey) {
130 // Handle ports. 130 // Handle ports.
131 url_matcher_port_filter = CreateURLMatcherPorts( 131 url_matcher_port_filter = CreateURLMatcherPorts(
132 &condition_attribute_value, error); 132 &condition_attribute_value, error);
133 if (!error->empty()) 133 if (!error->empty())
134 return scoped_refptr<URLMatcherConditionSet>(NULL); 134 return scoped_refptr<URLMatcherConditionSet>(NULL);
135 } else { 135 } else {
136 // Handle unknown attributes. 136 // Handle unknown attributes.
137 *error = ExtensionErrorUtils::FormatErrorMessage( 137 *error = ErrorUtils::FormatErrorMessage(
138 kUnknownURLFilterAttribute, 138 kUnknownURLFilterAttribute,
139 condition_attribute_name); 139 condition_attribute_name);
140 return scoped_refptr<URLMatcherConditionSet>(NULL); 140 return scoped_refptr<URLMatcherConditionSet>(NULL);
141 } 141 }
142 } 142 }
143 143
144 // As the URL is the preliminary matching criterion that triggers the tests 144 // As the URL is the preliminary matching criterion that triggers the tests
145 // for the remaining condition attributes, we insert an empty URL match if 145 // for the remaining condition attributes, we insert an empty URL match if
146 // no other url match conditions were specified. Such an empty URL is always 146 // no other url match conditions were specified. Such an empty URL is always
147 // matched. 147 // matched.
(...skipping 16 matching lines...) Expand all
164 } 164 }
165 165
166 // static 166 // static
167 URLMatcherCondition URLMatcherFactory::CreateURLMatcherCondition( 167 URLMatcherCondition URLMatcherFactory::CreateURLMatcherCondition(
168 URLMatcherConditionFactory* url_matcher_condition_factory, 168 URLMatcherConditionFactory* url_matcher_condition_factory,
169 const std::string& condition_attribute_name, 169 const std::string& condition_attribute_name,
170 const base::Value* value, 170 const base::Value* value,
171 std::string* error) { 171 std::string* error) {
172 std::string str_value; 172 std::string str_value;
173 if (!value->GetAsString(&str_value)) { 173 if (!value->GetAsString(&str_value)) {
174 *error = ExtensionErrorUtils::FormatErrorMessage(kAttributeExpectedString, 174 *error = ErrorUtils::FormatErrorMessage(kAttributeExpectedString,
175 condition_attribute_name); 175 condition_attribute_name);
176 return URLMatcherCondition(); 176 return URLMatcherCondition();
177 } 177 }
178 // Test regular expressions for validity. 178 // Test regular expressions for validity.
179 if (condition_attribute_name == keys::kURLMatchesKey) { 179 if (condition_attribute_name == keys::kURLMatchesKey) {
180 re2::RE2 regex(str_value); 180 re2::RE2 regex(str_value);
181 if (!regex.ok()) { 181 if (!regex.ok()) {
182 *error = ExtensionErrorUtils::FormatErrorMessage(kUnparseableRegexString, 182 *error = ErrorUtils::FormatErrorMessage(kUnparseableRegexString,
183 str_value, 183 str_value,
184 regex.error()); 184 regex.error());
185 return URLMatcherCondition(); 185 return URLMatcherCondition();
186 } 186 }
187 } 187 }
188 return g_url_matcher_condition_factory_methods.Get().Call( 188 return g_url_matcher_condition_factory_methods.Get().Call(
189 url_matcher_condition_factory, condition_attribute_name, str_value); 189 url_matcher_condition_factory, condition_attribute_name, str_value);
190 } 190 }
191 191
192 // static 192 // static
193 scoped_ptr<URLMatcherSchemeFilter> URLMatcherFactory::CreateURLMatcherScheme( 193 scoped_ptr<URLMatcherSchemeFilter> URLMatcherFactory::CreateURLMatcherScheme(
194 const base::Value* value, 194 const base::Value* value,
195 std::string* error) { 195 std::string* error) {
196 std::vector<std::string> schemas; 196 std::vector<std::string> schemas;
197 if (!helpers::GetAsStringVector(value, &schemas)) { 197 if (!helpers::GetAsStringVector(value, &schemas)) {
198 *error = ExtensionErrorUtils::FormatErrorMessage(kVectorOfStringsExpected, 198 *error = ErrorUtils::FormatErrorMessage(kVectorOfStringsExpected,
199 keys::kSchemesKey); 199 keys::kSchemesKey);
200 return scoped_ptr<URLMatcherSchemeFilter>(NULL); 200 return scoped_ptr<URLMatcherSchemeFilter>(NULL);
201 } 201 }
202 return scoped_ptr<URLMatcherSchemeFilter>( 202 return scoped_ptr<URLMatcherSchemeFilter>(
203 new URLMatcherSchemeFilter(schemas)); 203 new URLMatcherSchemeFilter(schemas));
204 } 204 }
205 205
206 // static 206 // static
207 scoped_ptr<URLMatcherPortFilter> URLMatcherFactory::CreateURLMatcherPorts( 207 scoped_ptr<URLMatcherPortFilter> URLMatcherFactory::CreateURLMatcherPorts(
208 const base::Value* value, 208 const base::Value* value,
(...skipping 24 matching lines...) Expand all
233 } else { 233 } else {
234 *error = kInvalidPortRanges; 234 *error = kInvalidPortRanges;
235 return scoped_ptr<URLMatcherPortFilter>(NULL); 235 return scoped_ptr<URLMatcherPortFilter>(NULL);
236 } 236 }
237 } 237 }
238 238
239 return scoped_ptr<URLMatcherPortFilter>(new URLMatcherPortFilter(ranges)); 239 return scoped_ptr<URLMatcherPortFilter>(new URLMatcherPortFilter(ranges));
240 } 240 }
241 241
242 } // namespace extensions 242 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest_unittest.cc ('k') | chrome/common/extensions/message_bundle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698