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

Side by Side Diff: chrome/common/extensions/manifest_handlers/content_scripts_handler.cc

Issue 1358513003: Use correct IntToString variants in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/manifest_handlers/content_scripts_handler.h" 5 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 errors::kInvalidGlobList, 50 errors::kInvalidGlobList,
51 base::IntToString(content_script_index), 51 base::IntToString(content_script_index),
52 globs_property_name); 52 globs_property_name);
53 return false; 53 return false;
54 } 54 }
55 55
56 for (size_t i = 0; i < list->GetSize(); ++i) { 56 for (size_t i = 0; i < list->GetSize(); ++i) {
57 std::string glob; 57 std::string glob;
58 if (!list->GetString(i, &glob)) { 58 if (!list->GetString(i, &glob)) {
59 *error = ErrorUtils::FormatErrorMessageUTF16( 59 *error = ErrorUtils::FormatErrorMessageUTF16(
60 errors::kInvalidGlob, 60 errors::kInvalidGlob, base::IntToString(content_script_index),
61 base::IntToString(content_script_index), 61 globs_property_name, base::SizeTToString(i));
62 globs_property_name,
63 base::IntToString(i));
64 return false; 62 return false;
65 } 63 }
66 64
67 (instance->*add_method)(glob); 65 (instance->*add_method)(glob);
68 } 66 }
69 67
70 return true; 68 return true;
71 } 69 }
72 70
73 // Helper method that loads a UserScript object from a dictionary in the 71 // Helper method that loads a UserScript object from a dictionary in the
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (matches->GetSize() == 0) { 134 if (matches->GetSize() == 0) {
137 *error = ErrorUtils::FormatErrorMessageUTF16( 135 *error = ErrorUtils::FormatErrorMessageUTF16(
138 errors::kInvalidMatchCount, 136 errors::kInvalidMatchCount,
139 base::IntToString(definition_index)); 137 base::IntToString(definition_index));
140 return false; 138 return false;
141 } 139 }
142 for (size_t j = 0; j < matches->GetSize(); ++j) { 140 for (size_t j = 0; j < matches->GetSize(); ++j) {
143 std::string match_str; 141 std::string match_str;
144 if (!matches->GetString(j, &match_str)) { 142 if (!matches->GetString(j, &match_str)) {
145 *error = ErrorUtils::FormatErrorMessageUTF16( 143 *error = ErrorUtils::FormatErrorMessageUTF16(
146 errors::kInvalidMatch, 144 errors::kInvalidMatch, base::IntToString(definition_index),
147 base::IntToString(definition_index), 145 base::SizeTToString(j), errors::kExpectString);
148 base::IntToString(j),
149 errors::kExpectString);
150 return false; 146 return false;
151 } 147 }
152 148
153 URLPattern pattern(UserScript::ValidUserScriptSchemes( 149 URLPattern pattern(UserScript::ValidUserScriptSchemes(
154 PermissionsData::CanExecuteScriptEverywhere(extension))); 150 PermissionsData::CanExecuteScriptEverywhere(extension)));
155 151
156 URLPattern::ParseResult parse_result = pattern.Parse(match_str); 152 URLPattern::ParseResult parse_result = pattern.Parse(match_str);
157 if (parse_result != URLPattern::PARSE_SUCCESS) { 153 if (parse_result != URLPattern::PARSE_SUCCESS) {
158 *error = ErrorUtils::FormatErrorMessageUTF16( 154 *error = ErrorUtils::FormatErrorMessageUTF16(
159 errors::kInvalidMatch, 155 errors::kInvalidMatch, base::IntToString(definition_index),
160 base::IntToString(definition_index), 156 base::SizeTToString(j),
161 base::IntToString(j),
162 URLPattern::GetParseResultString(parse_result)); 157 URLPattern::GetParseResultString(parse_result));
163 return false; 158 return false;
164 } 159 }
165 160
166 // TODO(aboxhall): check for webstore 161 // TODO(aboxhall): check for webstore
167 if (!PermissionsData::CanExecuteScriptEverywhere(extension) && 162 if (!PermissionsData::CanExecuteScriptEverywhere(extension) &&
168 pattern.scheme() != content::kChromeUIScheme) { 163 pattern.scheme() != content::kChromeUIScheme) {
169 // Exclude SCHEME_CHROMEUI unless it's been explicitly requested. 164 // Exclude SCHEME_CHROMEUI unless it's been explicitly requested.
170 // If the --extensions-on-chrome-urls flag has not been passed, requesting 165 // If the --extensions-on-chrome-urls flag has not been passed, requesting
171 // a chrome:// url will cause a parse failure above, so there's no need to 166 // a chrome:// url will cause a parse failure above, so there's no need to
(...skipping 21 matching lines...) Expand all
193 *error = ErrorUtils::FormatErrorMessageUTF16( 188 *error = ErrorUtils::FormatErrorMessageUTF16(
194 errors::kInvalidExcludeMatches, 189 errors::kInvalidExcludeMatches,
195 base::IntToString(definition_index)); 190 base::IntToString(definition_index));
196 return false; 191 return false;
197 } 192 }
198 193
199 for (size_t j = 0; j < exclude_matches->GetSize(); ++j) { 194 for (size_t j = 0; j < exclude_matches->GetSize(); ++j) {
200 std::string match_str; 195 std::string match_str;
201 if (!exclude_matches->GetString(j, &match_str)) { 196 if (!exclude_matches->GetString(j, &match_str)) {
202 *error = ErrorUtils::FormatErrorMessageUTF16( 197 *error = ErrorUtils::FormatErrorMessageUTF16(
203 errors::kInvalidExcludeMatch, 198 errors::kInvalidExcludeMatch, base::IntToString(definition_index),
204 base::IntToString(definition_index), 199 base::SizeTToString(j), errors::kExpectString);
205 base::IntToString(j),
206 errors::kExpectString);
207 return false; 200 return false;
208 } 201 }
209 202
210 int valid_schemes = UserScript::ValidUserScriptSchemes( 203 int valid_schemes = UserScript::ValidUserScriptSchemes(
211 PermissionsData::CanExecuteScriptEverywhere(extension)); 204 PermissionsData::CanExecuteScriptEverywhere(extension));
212 URLPattern pattern(valid_schemes); 205 URLPattern pattern(valid_schemes);
213 206
214 URLPattern::ParseResult parse_result = pattern.Parse(match_str); 207 URLPattern::ParseResult parse_result = pattern.Parse(match_str);
215 if (parse_result != URLPattern::PARSE_SUCCESS) { 208 if (parse_result != URLPattern::PARSE_SUCCESS) {
216 *error = ErrorUtils::FormatErrorMessageUTF16( 209 *error = ErrorUtils::FormatErrorMessageUTF16(
217 errors::kInvalidExcludeMatch, 210 errors::kInvalidExcludeMatch, base::IntToString(definition_index),
218 base::IntToString(definition_index), base::IntToString(j), 211 base::SizeTToString(j),
219 URLPattern::GetParseResultString(parse_result)); 212 URLPattern::GetParseResultString(parse_result));
220 return false; 213 return false;
221 } 214 }
222 215
223 result->add_exclude_url_pattern(pattern); 216 result->add_exclude_url_pattern(pattern);
224 } 217 }
225 } 218 }
226 219
227 // include/exclude globs (mostly for Greasemonkey compatibility) 220 // include/exclude globs (mostly for Greasemonkey compatibility)
228 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs, 221 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return false; 255 return false;
263 } 256 }
264 257
265 if (js) { 258 if (js) {
266 for (size_t script_index = 0; script_index < js->GetSize(); 259 for (size_t script_index = 0; script_index < js->GetSize();
267 ++script_index) { 260 ++script_index) {
268 const base::Value* value; 261 const base::Value* value;
269 std::string relative; 262 std::string relative;
270 if (!js->Get(script_index, &value) || !value->GetAsString(&relative)) { 263 if (!js->Get(script_index, &value) || !value->GetAsString(&relative)) {
271 *error = ErrorUtils::FormatErrorMessageUTF16( 264 *error = ErrorUtils::FormatErrorMessageUTF16(
272 errors::kInvalidJs, 265 errors::kInvalidJs, base::IntToString(definition_index),
273 base::IntToString(definition_index), 266 base::SizeTToString(script_index));
274 base::IntToString(script_index));
275 return false; 267 return false;
276 } 268 }
277 GURL url = extension->GetResourceURL(relative); 269 GURL url = extension->GetResourceURL(relative);
278 ExtensionResource resource = extension->GetResource(relative); 270 ExtensionResource resource = extension->GetResource(relative);
279 result->js_scripts().push_back(UserScript::File( 271 result->js_scripts().push_back(UserScript::File(
280 resource.extension_root(), resource.relative_path(), url)); 272 resource.extension_root(), resource.relative_path(), url));
281 } 273 }
282 } 274 }
283 275
284 if (css) { 276 if (css) {
285 for (size_t script_index = 0; script_index < css->GetSize(); 277 for (size_t script_index = 0; script_index < css->GetSize();
286 ++script_index) { 278 ++script_index) {
287 const base::Value* value; 279 const base::Value* value;
288 std::string relative; 280 std::string relative;
289 if (!css->Get(script_index, &value) || !value->GetAsString(&relative)) { 281 if (!css->Get(script_index, &value) || !value->GetAsString(&relative)) {
290 *error = ErrorUtils::FormatErrorMessageUTF16( 282 *error = ErrorUtils::FormatErrorMessageUTF16(
291 errors::kInvalidCss, 283 errors::kInvalidCss, base::IntToString(definition_index),
292 base::IntToString(definition_index), 284 base::SizeTToString(script_index));
293 base::IntToString(script_index));
294 return false; 285 return false;
295 } 286 }
296 GURL url = extension->GetResourceURL(relative); 287 GURL url = extension->GetResourceURL(relative);
297 ExtensionResource resource = extension->GetResource(relative); 288 ExtensionResource resource = extension->GetResource(relative);
298 result->css_scripts().push_back(UserScript::File( 289 result->css_scripts().push_back(UserScript::File(
299 resource.extension_root(), resource.relative_path(), url)); 290 resource.extension_root(), resource.relative_path(), url));
300 } 291 }
301 } 292 }
302 293
303 return true; 294 return true;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 const base::ListValue* scripts_list = NULL; 390 const base::ListValue* scripts_list = NULL;
400 if (!extension->manifest()->GetList(keys::kContentScripts, &scripts_list)) { 391 if (!extension->manifest()->GetList(keys::kContentScripts, &scripts_list)) {
401 *error = base::ASCIIToUTF16(errors::kInvalidContentScriptsList); 392 *error = base::ASCIIToUTF16(errors::kInvalidContentScriptsList);
402 return false; 393 return false;
403 } 394 }
404 395
405 for (size_t i = 0; i < scripts_list->GetSize(); ++i) { 396 for (size_t i = 0; i < scripts_list->GetSize(); ++i) {
406 const base::DictionaryValue* script_dict = NULL; 397 const base::DictionaryValue* script_dict = NULL;
407 if (!scripts_list->GetDictionary(i, &script_dict)) { 398 if (!scripts_list->GetDictionary(i, &script_dict)) {
408 *error = ErrorUtils::FormatErrorMessageUTF16( 399 *error = ErrorUtils::FormatErrorMessageUTF16(
409 errors::kInvalidContentScript, 400 errors::kInvalidContentScript, base::SizeTToString(i));
410 base::IntToString(i));
411 return false; 401 return false;
412 } 402 }
413 403
414 UserScript user_script; 404 UserScript user_script;
415 if (!LoadUserScriptFromDictionary(script_dict, 405 if (!LoadUserScriptFromDictionary(script_dict,
416 i, 406 i,
417 extension, 407 extension,
418 error, 408 error,
419 &user_script)) { 409 &user_script)) {
420 return false; // Failed to parse script context definition. 410 return false; // Failed to parse script context definition.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 if (!IsScriptValid(path, css_script.relative_path(), 463 if (!IsScriptValid(path, css_script.relative_path(),
474 IDS_EXTENSION_LOAD_CSS_FAILED, error)) 464 IDS_EXTENSION_LOAD_CSS_FAILED, error))
475 return false; 465 return false;
476 } 466 }
477 } 467 }
478 468
479 return true; 469 return true;
480 } 470 }
481 471
482 } // namespace extensions 472 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/plugins/plugins_handler.cc ('k') | chrome/common/net/x509_certificate_model_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698