| OLD | NEW |
| 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/file_util.h" | 7 #include "base/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/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 #include "chrome/common/extensions/extension_manifest_constants.h" | 15 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 16 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 16 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
| 17 #include "extensions/common/error_utils.h" | 18 #include "extensions/common/error_utils.h" |
| 18 #include "extensions/common/extension_resource.h" | 19 #include "extensions/common/extension_resource.h" |
| 19 #include "extensions/common/url_pattern.h" | 20 #include "extensions/common/url_pattern.h" |
| 20 #include "extensions/common/url_pattern_set.h" | 21 #include "extensions/common/url_pattern_set.h" |
| 21 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 | 25 |
| 25 namespace extensions { | 26 namespace extensions { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 if (!matches->GetString(j, &match_str)) { | 130 if (!matches->GetString(j, &match_str)) { |
| 130 *error = ErrorUtils::FormatErrorMessageUTF16( | 131 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 131 errors::kInvalidMatch, | 132 errors::kInvalidMatch, |
| 132 base::IntToString(definition_index), | 133 base::IntToString(definition_index), |
| 133 base::IntToString(j), | 134 base::IntToString(j), |
| 134 errors::kExpectString); | 135 errors::kExpectString); |
| 135 return false; | 136 return false; |
| 136 } | 137 } |
| 137 | 138 |
| 138 URLPattern pattern(UserScript::ValidUserScriptSchemes( | 139 URLPattern pattern(UserScript::ValidUserScriptSchemes( |
| 139 extension->CanExecuteScriptEverywhere())); | 140 PermissionsData::CanExecuteScriptEverywhere(extension))); |
| 140 | 141 |
| 141 URLPattern::ParseResult parse_result = pattern.Parse(match_str); | 142 URLPattern::ParseResult parse_result = pattern.Parse(match_str); |
| 142 if (parse_result != URLPattern::PARSE_SUCCESS) { | 143 if (parse_result != URLPattern::PARSE_SUCCESS) { |
| 143 *error = ErrorUtils::FormatErrorMessageUTF16( | 144 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 144 errors::kInvalidMatch, | 145 errors::kInvalidMatch, |
| 145 base::IntToString(definition_index), | 146 base::IntToString(definition_index), |
| 146 base::IntToString(j), | 147 base::IntToString(j), |
| 147 URLPattern::GetParseResultString(parse_result)); | 148 URLPattern::GetParseResultString(parse_result)); |
| 148 return false; | 149 return false; |
| 149 } | 150 } |
| 150 | 151 |
| 151 // TODO(aboxhall): check for webstore | 152 // TODO(aboxhall): check for webstore |
| 152 if (!extension->CanExecuteScriptEverywhere() && | 153 if (!PermissionsData::CanExecuteScriptEverywhere(extension) && |
| 153 pattern.scheme() != chrome::kChromeUIScheme) { | 154 pattern.scheme() != chrome::kChromeUIScheme) { |
| 154 // Exclude SCHEME_CHROMEUI unless it's been explicitly requested. | 155 // Exclude SCHEME_CHROMEUI unless it's been explicitly requested. |
| 155 // If the --extensions-on-chrome-urls flag has not been passed, requesting | 156 // If the --extensions-on-chrome-urls flag has not been passed, requesting |
| 156 // a chrome:// url will cause a parse failure above, so there's no need to | 157 // a chrome:// url will cause a parse failure above, so there's no need to |
| 157 // check the flag here. | 158 // check the flag here. |
| 158 pattern.SetValidSchemes( | 159 pattern.SetValidSchemes( |
| 159 pattern.valid_schemes() & ~URLPattern::SCHEME_CHROMEUI); | 160 pattern.valid_schemes() & ~URLPattern::SCHEME_CHROMEUI); |
| 160 } | 161 } |
| 161 | 162 |
| 162 if (pattern.MatchesScheme(chrome::kFileScheme) && | 163 if (pattern.MatchesScheme(chrome::kFileScheme) && |
| 163 !extension->CanExecuteScriptEverywhere()) { | 164 !PermissionsData::CanExecuteScriptEverywhere(extension)) { |
| 164 extension->set_wants_file_access(true); | 165 extension->set_wants_file_access(true); |
| 165 if (!(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS)) { | 166 if (!(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS)) { |
| 166 pattern.SetValidSchemes( | 167 pattern.SetValidSchemes( |
| 167 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | 168 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
| 168 } | 169 } |
| 169 } | 170 } |
| 170 | 171 |
| 171 result->add_url_pattern(pattern); | 172 result->add_url_pattern(pattern); |
| 172 } | 173 } |
| 173 | 174 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 186 if (!exclude_matches->GetString(j, &match_str)) { | 187 if (!exclude_matches->GetString(j, &match_str)) { |
| 187 *error = ErrorUtils::FormatErrorMessageUTF16( | 188 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 188 errors::kInvalidExcludeMatch, | 189 errors::kInvalidExcludeMatch, |
| 189 base::IntToString(definition_index), | 190 base::IntToString(definition_index), |
| 190 base::IntToString(j), | 191 base::IntToString(j), |
| 191 errors::kExpectString); | 192 errors::kExpectString); |
| 192 return false; | 193 return false; |
| 193 } | 194 } |
| 194 | 195 |
| 195 int valid_schemes = UserScript::ValidUserScriptSchemes( | 196 int valid_schemes = UserScript::ValidUserScriptSchemes( |
| 196 extension->CanExecuteScriptEverywhere()); | 197 PermissionsData::CanExecuteScriptEverywhere(extension)); |
| 197 URLPattern pattern(valid_schemes); | 198 URLPattern pattern(valid_schemes); |
| 198 | 199 |
| 199 URLPattern::ParseResult parse_result = pattern.Parse(match_str); | 200 URLPattern::ParseResult parse_result = pattern.Parse(match_str); |
| 200 if (parse_result != URLPattern::PARSE_SUCCESS) { | 201 if (parse_result != URLPattern::PARSE_SUCCESS) { |
| 201 *error = ErrorUtils::FormatErrorMessageUTF16( | 202 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 202 errors::kInvalidExcludeMatch, | 203 errors::kInvalidExcludeMatch, |
| 203 base::IntToString(definition_index), base::IntToString(j), | 204 base::IntToString(definition_index), base::IntToString(j), |
| 204 URLPattern::GetParseResultString(parse_result)); | 205 URLPattern::GetParseResultString(parse_result)); |
| 205 return false; | 206 return false; |
| 206 } | 207 } |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 if (!IsScriptValid(path, css_script.relative_path(), | 456 if (!IsScriptValid(path, css_script.relative_path(), |
| 456 IDS_EXTENSION_LOAD_CSS_FAILED, error)) | 457 IDS_EXTENSION_LOAD_CSS_FAILED, error)) |
| 457 return false; | 458 return false; |
| 458 } | 459 } |
| 459 } | 460 } |
| 460 | 461 |
| 461 return true; | 462 return true; |
| 462 } | 463 } |
| 463 | 464 |
| 464 } // namespace extensions | 465 } // namespace extensions |
| OLD | NEW |