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

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

Issue 418051: Merge 32271 - Don't allow content scripts to execute on file:// urls.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/249/src/
Patch Set: Created 11 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 IntToString(definition_index), IntToString(j)); 237 IntToString(definition_index), IntToString(j));
238 return false; 238 return false;
239 } 239 }
240 240
241 URLPattern pattern; 241 URLPattern pattern;
242 if (!pattern.Parse(match_str)) { 242 if (!pattern.Parse(match_str)) {
243 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatch, 243 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatch,
244 IntToString(definition_index), IntToString(j)); 244 IntToString(definition_index), IntToString(j));
245 return false; 245 return false;
246 } 246 }
247 std::string scheme = pattern.scheme();
248 if (scheme == "file") {
249 // No content scripts are allowed unless the command line override switch
250 // was provided.
251 if (!CommandLine::ForCurrentProcess()->HasSwitch(
252 switches::kEnableJsOnFileUrls)) {
253 *error = errors::kInvalidJsMatches;
254 return false;
255 }
256 }
247 257
248 result->add_url_pattern(pattern); 258 result->add_url_pattern(pattern);
249 } 259 }
250 260
251 // include/exclude globs (mostly for Greasemonkey compat) 261 // Include/exclude globs (mostly for Greasemonkey compatibility).
252 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs, 262 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs,
253 error, &UserScript::add_glob, result)) { 263 error, &UserScript::add_glob, result)) {
254 return false; 264 return false;
255 } 265 }
256 266
257 if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs, 267 if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs,
258 error, &UserScript::add_exclude_glob, result)) { 268 error, &UserScript::add_exclude_glob, result)) {
259 return false; 269 return false;
260 } 270 }
261 271
262 // js and css keys 272 // js and css keys.
263 ListValue* js = NULL; 273 ListValue* js = NULL;
264 if (content_script->HasKey(keys::kJs) && 274 if (content_script->HasKey(keys::kJs) &&
265 !content_script->GetList(keys::kJs, &js)) { 275 !content_script->GetList(keys::kJs, &js)) {
266 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidJsList, 276 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidJsList,
267 IntToString(definition_index)); 277 IntToString(definition_index));
268 return false; 278 return false;
269 } 279 }
270 280
271 ListValue* css = NULL; 281 ListValue* css = NULL;
272 if (content_script->HasKey(keys::kCss) && 282 if (content_script->HasKey(keys::kCss) &&
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 UserScript::PatternList::const_iterator pattern = 1252 UserScript::PatternList::const_iterator pattern =
1243 content_script->url_patterns().begin(); 1253 content_script->url_patterns().begin();
1244 for (; pattern != content_script->url_patterns().end(); ++pattern) { 1254 for (; pattern != content_script->url_patterns().end(); ++pattern) {
1245 if (pattern->match_subdomains() && pattern->host().empty()) 1255 if (pattern->match_subdomains() && pattern->host().empty())
1246 return true; 1256 return true;
1247 } 1257 }
1248 } 1258 }
1249 1259
1250 return false; 1260 return false;
1251 } 1261 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/static/content_scripts.html ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698