| 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/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
| 20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "base/version.h" | 22 #include "base/version.h" |
| 23 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/chrome_version_info.h" | 25 #include "chrome/common/chrome_version_info.h" |
| 26 // TODO(rdevlin.cronin): Remove these once all references have been removed as | |
| 27 // part of crbug.com/159265. | |
| 28 #include "chrome/common/extensions/background_info.h" | |
| 29 #include "chrome/common/extensions/extension_manifest_constants.h" | 26 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 30 #include "chrome/common/extensions/incognito_handler.h" | |
| 31 #include "chrome/common/extensions/manifest.h" | 27 #include "chrome/common/extensions/manifest.h" |
| 32 #include "chrome/common/extensions/manifest_handler.h" | 28 #include "chrome/common/extensions/manifest_handler.h" |
| 33 #include "chrome/common/extensions/manifest_url_handler.h" | |
| 34 #include "chrome/common/extensions/permissions/api_permission_set.h" | 29 #include "chrome/common/extensions/permissions/api_permission_set.h" |
| 35 #include "chrome/common/extensions/permissions/permission_set.h" | 30 #include "chrome/common/extensions/permissions/permission_set.h" |
| 36 #include "chrome/common/extensions/permissions/permissions_data.h" | 31 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 37 #include "chrome/common/extensions/permissions/permissions_info.h" | 32 #include "chrome/common/extensions/permissions/permissions_info.h" |
| 38 #include "chrome/common/extensions/user_script.h" | |
| 39 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 40 #include "extensions/common/constants.h" | 34 #include "extensions/common/constants.h" |
| 41 #include "extensions/common/error_utils.h" | 35 #include "extensions/common/error_utils.h" |
| 42 #include "extensions/common/id_util.h" | 36 #include "extensions/common/id_util.h" |
| 43 #include "extensions/common/url_pattern_set.h" | 37 #include "extensions/common/url_pattern_set.h" |
| 44 #include "googleurl/src/url_util.h" | 38 #include "googleurl/src/url_util.h" |
| 45 #include "grit/chromium_strings.h" | 39 #include "grit/chromium_strings.h" |
| 46 #include "grit/theme_resources.h" | 40 #include "grit/theme_resources.h" |
| 47 #include "third_party/skia/include/core/SkBitmap.h" | 41 #include "third_party/skia/include/core/SkBitmap.h" |
| 48 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 161 } |
| 168 | 162 |
| 169 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass()); | 163 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass()); |
| 170 extension->install_warnings_.swap(install_warnings); | 164 extension->install_warnings_.swap(install_warnings); |
| 171 | 165 |
| 172 if (!extension->InitFromValue(flags, &error)) { | 166 if (!extension->InitFromValue(flags, &error)) { |
| 173 *utf8_error = UTF16ToUTF8(error); | 167 *utf8_error = UTF16ToUTF8(error); |
| 174 return NULL; | 168 return NULL; |
| 175 } | 169 } |
| 176 | 170 |
| 177 if (!extension->CheckPlatformAppFeatures(&error) || | |
| 178 !extension->CheckConflictingFeatures(&error)) { | |
| 179 *utf8_error = UTF16ToUTF8(error); | |
| 180 return NULL; | |
| 181 } | |
| 182 | |
| 183 return extension; | 171 return extension; |
| 184 } | 172 } |
| 185 | 173 |
| 186 // static | 174 // static |
| 187 bool Extension::IdIsValid(const std::string& id) { | 175 bool Extension::IdIsValid(const std::string& id) { |
| 188 // Verify that the id is legal. | 176 // Verify that the id is legal. |
| 189 if (id.size() != (id_util::kIdSize * 2)) | 177 if (id.size() != (id_util::kIdSize * 2)) |
| 190 return false; | 178 return false; |
| 191 | 179 |
| 192 // We only support lowercase IDs, because IDs can be used as URL components | 180 // We only support lowercase IDs, because IDs can be used as URL components |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 if (current_version.CompareTo(minimum_version) < 0) { | 805 if (current_version.CompareTo(minimum_version) < 0) { |
| 818 *error = ErrorUtils::FormatErrorMessageUTF16( | 806 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 819 errors::kChromeVersionTooLow, | 807 errors::kChromeVersionTooLow, |
| 820 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), | 808 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), |
| 821 minimum_version_string); | 809 minimum_version_string); |
| 822 return false; | 810 return false; |
| 823 } | 811 } |
| 824 return true; | 812 return true; |
| 825 } | 813 } |
| 826 | 814 |
| 827 bool Extension::CheckPlatformAppFeatures(string16* error) const { | |
| 828 if (!is_platform_app()) | |
| 829 return true; | |
| 830 | |
| 831 if (!BackgroundInfo::HasBackgroundPage(this)) { | |
| 832 *error = ASCIIToUTF16(errors::kBackgroundRequiredForPlatformApps); | |
| 833 return false; | |
| 834 } | |
| 835 | |
| 836 if (!IncognitoInfo::IsSplitMode(this)) { | |
| 837 *error = ASCIIToUTF16(errors::kInvalidIncognitoModeForPlatformApp); | |
| 838 return false; | |
| 839 } | |
| 840 | |
| 841 return true; | |
| 842 } | |
| 843 | |
| 844 bool Extension::CheckConflictingFeatures(string16* error) const { | |
| 845 if (BackgroundInfo::HasLazyBackgroundPage(this) && | |
| 846 HasAPIPermission(APIPermission::kWebRequest)) { | |
| 847 *error = ASCIIToUTF16(errors::kWebRequestConflictsWithLazyBackground); | |
| 848 return false; | |
| 849 } | |
| 850 | |
| 851 return true; | |
| 852 } | |
| 853 | |
| 854 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, | 815 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, |
| 855 const std::string& id, | 816 const std::string& id, |
| 856 const base::FilePath& path, | 817 const base::FilePath& path, |
| 857 Manifest::Location location) | 818 Manifest::Location location) |
| 858 : extension_id(id), | 819 : extension_id(id), |
| 859 extension_path(path), | 820 extension_path(path), |
| 860 extension_location(location) { | 821 extension_location(location) { |
| 861 if (manifest) | 822 if (manifest) |
| 862 extension_manifest.reset(manifest->DeepCopy()); | 823 extension_manifest.reset(manifest->DeepCopy()); |
| 863 } | 824 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 881 | 842 |
| 882 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 843 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 883 const Extension* extension, | 844 const Extension* extension, |
| 884 const PermissionSet* permissions, | 845 const PermissionSet* permissions, |
| 885 Reason reason) | 846 Reason reason) |
| 886 : reason(reason), | 847 : reason(reason), |
| 887 extension(extension), | 848 extension(extension), |
| 888 permissions(permissions) {} | 849 permissions(permissions) {} |
| 889 | 850 |
| 890 } // namespace extensions | 851 } // namespace extensions |
| OLD | NEW |