| OLD | NEW |
| 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 Loading... |
| 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 continue; | |
| 254 } | |
| 255 } | |
| 256 | 247 |
| 257 result->add_url_pattern(pattern); | 248 result->add_url_pattern(pattern); |
| 258 } | 249 } |
| 259 | 250 |
| 260 // Include/exclude globs (mostly for Greasemonkey compatibility). | 251 // include/exclude globs (mostly for Greasemonkey compat) |
| 261 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs, | 252 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs, |
| 262 error, &UserScript::add_glob, result)) { | 253 error, &UserScript::add_glob, result)) { |
| 263 return false; | 254 return false; |
| 264 } | 255 } |
| 265 | 256 |
| 266 if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs, | 257 if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs, |
| 267 error, &UserScript::add_exclude_glob, result)) { | 258 error, &UserScript::add_exclude_glob, result)) { |
| 268 return false; | 259 return false; |
| 269 } | 260 } |
| 270 | 261 |
| 271 // js and css keys. | 262 // js and css keys |
| 272 ListValue* js = NULL; | 263 ListValue* js = NULL; |
| 273 if (content_script->HasKey(keys::kJs) && | 264 if (content_script->HasKey(keys::kJs) && |
| 274 !content_script->GetList(keys::kJs, &js)) { | 265 !content_script->GetList(keys::kJs, &js)) { |
| 275 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidJsList, | 266 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidJsList, |
| 276 IntToString(definition_index)); | 267 IntToString(definition_index)); |
| 277 return false; | 268 return false; |
| 278 } | 269 } |
| 279 | 270 |
| 280 ListValue* css = NULL; | 271 ListValue* css = NULL; |
| 281 if (content_script->HasKey(keys::kCss) && | 272 if (content_script->HasKey(keys::kCss) && |
| (...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 UserScript::PatternList::const_iterator pattern = | 1242 UserScript::PatternList::const_iterator pattern = |
| 1252 content_script->url_patterns().begin(); | 1243 content_script->url_patterns().begin(); |
| 1253 for (; pattern != content_script->url_patterns().end(); ++pattern) { | 1244 for (; pattern != content_script->url_patterns().end(); ++pattern) { |
| 1254 if (pattern->match_subdomains() && pattern->host().empty()) | 1245 if (pattern->match_subdomains() && pattern->host().empty()) |
| 1255 return true; | 1246 return true; |
| 1256 } | 1247 } |
| 1257 } | 1248 } |
| 1258 | 1249 |
| 1259 return false; | 1250 return false; |
| 1260 } | 1251 } |
| OLD | NEW |