| 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/l10n_util.h" |
| 7 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 8 #include "base/base64.h" | 9 #include "base/base64.h" |
| 9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/file_version_info.h" |
| 13 #include "base/logging.h" | 15 #include "base/logging.h" |
| 14 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 15 #include "base/stl_util-inl.h" | 17 #include "base/stl_util-inl.h" |
| 16 #include "base/third_party/nss/blapi.h" | 18 #include "base/third_party/nss/blapi.h" |
| 17 #include "base/third_party/nss/sha256.h" | 19 #include "base/third_party/nss/sha256.h" |
| 18 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
| 19 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/common/extensions/extension_error_reporter.h" | 23 #include "chrome/common/extensions/extension_error_reporter.h" |
| 22 #include "chrome/common/extensions/extension_error_utils.h" | 24 #include "chrome/common/extensions/extension_error_utils.h" |
| 23 #include "chrome/common/extensions/extension_l10n_util.h" | 25 #include "chrome/common/extensions/extension_l10n_util.h" |
| 24 #include "chrome/common/extensions/user_script.h" | 26 #include "chrome/common/extensions/user_script.h" |
| 25 #include "chrome/common/notification_service.h" | 27 #include "chrome/common/notification_service.h" |
| 26 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 29 #include "grit/chromium_strings.h" |
| 27 #include "webkit/glue/image_decoder.h" | 30 #include "webkit/glue/image_decoder.h" |
| 28 | 31 |
| 29 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
| 30 #include "base/registry.h" | 33 #include "base/registry.h" |
| 31 #endif | 34 #endif |
| 32 | 35 |
| 33 namespace keys = extension_manifest_keys; | 36 namespace keys = extension_manifest_keys; |
| 34 namespace values = extension_manifest_values; | 37 namespace values = extension_manifest_values; |
| 35 namespace errors = extension_manifest_errors; | 38 namespace errors = extension_manifest_errors; |
| 36 | 39 |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 return false; | 753 return false; |
| 751 } | 754 } |
| 752 update_url_ = GURL(tmp); | 755 update_url_ = GURL(tmp); |
| 753 if (!update_url_.is_valid() || update_url_.has_ref()) { | 756 if (!update_url_.is_valid() || update_url_.has_ref()) { |
| 754 *error = ExtensionErrorUtils::FormatErrorMessage( | 757 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 755 errors::kInvalidUpdateURL, tmp); | 758 errors::kInvalidUpdateURL, tmp); |
| 756 return false; | 759 return false; |
| 757 } | 760 } |
| 758 } | 761 } |
| 759 | 762 |
| 763 // Validate minimum Chrome version (if present). We don't need to store this, |
| 764 // since the extension is not valid if it is incorrect. |
| 765 if (source.HasKey(keys::kMinimumChromeVersion)) { |
| 766 std::string minimum_version_string; |
| 767 if (!source.GetString(keys::kMinimumChromeVersion, |
| 768 &minimum_version_string)) { |
| 769 *error = errors::kInvalidMinimumChromeVersion; |
| 770 return false; |
| 771 } |
| 772 |
| 773 scoped_ptr<Version> minimum_version( |
| 774 Version::GetVersionFromString(minimum_version_string)); |
| 775 if (!minimum_version.get()) { |
| 776 *error = errors::kInvalidMinimumChromeVersion; |
| 777 return false; |
| 778 } |
| 779 |
| 780 scoped_ptr<FileVersionInfo> current_version_info( |
| 781 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
| 782 if (!current_version_info.get()) { |
| 783 DCHECK(false); |
| 784 return false; |
| 785 } |
| 786 |
| 787 scoped_ptr<Version> current_version( |
| 788 Version::GetVersionFromString(current_version_info->file_version())); |
| 789 if (!current_version.get()) { |
| 790 DCHECK(false); |
| 791 return false; |
| 792 } |
| 793 |
| 794 if (current_version->CompareTo(*minimum_version) < 0) { |
| 795 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 796 errors::kChromeVersionTooLow, |
| 797 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), |
| 798 minimum_version_string); |
| 799 return false; |
| 800 } |
| 801 } |
| 802 |
| 760 // Initialize converted_from_user_script (if present) | 803 // Initialize converted_from_user_script (if present) |
| 761 source.GetBoolean(keys::kConvertedFromUserScript, | 804 source.GetBoolean(keys::kConvertedFromUserScript, |
| 762 &converted_from_user_script_); | 805 &converted_from_user_script_); |
| 763 | 806 |
| 764 // Initialize icons (if present). | 807 // Initialize icons (if present). |
| 765 if (source.HasKey(keys::kIcons)) { | 808 if (source.HasKey(keys::kIcons)) { |
| 766 DictionaryValue* icons_value = NULL; | 809 DictionaryValue* icons_value = NULL; |
| 767 if (!source.GetDictionary(keys::kIcons, &icons_value)) { | 810 if (!source.GetDictionary(keys::kIcons, &icons_value)) { |
| 768 *error = errors::kInvalidIcons; | 811 *error = errors::kInvalidIcons; |
| 769 return false; | 812 return false; |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1283 UserScript::PatternList::const_iterator pattern = | 1326 UserScript::PatternList::const_iterator pattern = |
| 1284 content_script->url_patterns().begin(); | 1327 content_script->url_patterns().begin(); |
| 1285 for (; pattern != content_script->url_patterns().end(); ++pattern) { | 1328 for (; pattern != content_script->url_patterns().end(); ++pattern) { |
| 1286 if (pattern->match_subdomains() && pattern->host().empty()) | 1329 if (pattern->match_subdomains() && pattern->host().empty()) |
| 1287 return true; | 1330 return true; |
| 1288 } | 1331 } |
| 1289 } | 1332 } |
| 1290 | 1333 |
| 1291 return false; | 1334 return false; |
| 1292 } | 1335 } |
| OLD | NEW |