| 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 "extensions/common/extension.h" | 5 #include "extensions/common/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/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/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 "components/crx_file/id_util.h" |
| 23 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
| 24 #include "extensions/common/constants.h" | 25 #include "extensions/common/constants.h" |
| 25 #include "extensions/common/error_utils.h" | 26 #include "extensions/common/error_utils.h" |
| 26 #include "extensions/common/id_util.h" | |
| 27 #include "extensions/common/manifest.h" | 27 #include "extensions/common/manifest.h" |
| 28 #include "extensions/common/manifest_constants.h" | 28 #include "extensions/common/manifest_constants.h" |
| 29 #include "extensions/common/manifest_handler.h" | 29 #include "extensions/common/manifest_handler.h" |
| 30 #include "extensions/common/manifest_handlers/permissions_parser.h" | 30 #include "extensions/common/manifest_handlers/permissions_parser.h" |
| 31 #include "extensions/common/permissions/permission_set.h" | 31 #include "extensions/common/permissions/permission_set.h" |
| 32 #include "extensions/common/permissions/permissions_data.h" | 32 #include "extensions/common/permissions/permissions_data.h" |
| 33 #include "extensions/common/permissions/permissions_info.h" | 33 #include "extensions/common/permissions/permissions_info.h" |
| 34 #include "extensions/common/switches.h" | 34 #include "extensions/common/switches.h" |
| 35 #include "extensions/common/url_pattern.h" | 35 #include "extensions/common/url_pattern.h" |
| 36 #include "net/base/filename_util.h" | 36 #include "net/base/filename_util.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 extension->install_warnings_.swap(install_warnings); | 126 extension->install_warnings_.swap(install_warnings); |
| 127 | 127 |
| 128 if (!extension->InitFromValue(flags, &error)) { | 128 if (!extension->InitFromValue(flags, &error)) { |
| 129 *utf8_error = base::UTF16ToUTF8(error); | 129 *utf8_error = base::UTF16ToUTF8(error); |
| 130 return NULL; | 130 return NULL; |
| 131 } | 131 } |
| 132 | 132 |
| 133 return extension; | 133 return extension; |
| 134 } | 134 } |
| 135 | 135 |
| 136 // static | |
| 137 bool Extension::IdIsValid(const std::string& id) { | |
| 138 // Verify that the id is legal. | |
| 139 if (id.size() != (id_util::kIdSize * 2)) | |
| 140 return false; | |
| 141 | |
| 142 // We only support lowercase IDs, because IDs can be used as URL components | |
| 143 // (where GURL will lowercase it). | |
| 144 std::string temp = base::StringToLowerASCII(id); | |
| 145 for (size_t i = 0; i < temp.size(); i++) | |
| 146 if (temp[i] < 'a' || temp[i] > 'p') | |
| 147 return false; | |
| 148 | |
| 149 return true; | |
| 150 } | |
| 151 | |
| 152 Manifest::Type Extension::GetType() const { | 136 Manifest::Type Extension::GetType() const { |
| 153 return converted_from_user_script() ? | 137 return converted_from_user_script() ? |
| 154 Manifest::TYPE_USER_SCRIPT : manifest_->type(); | 138 Manifest::TYPE_USER_SCRIPT : manifest_->type(); |
| 155 } | 139 } |
| 156 | 140 |
| 157 // static | 141 // static |
| 158 GURL Extension::GetResourceURL(const GURL& extension_url, | 142 GURL Extension::GetResourceURL(const GURL& extension_url, |
| 159 const std::string& relative_path) { | 143 const std::string& relative_path) { |
| 160 DCHECK(extension_url.SchemeIs(extensions::kExtensionScheme)); | 144 DCHECK(extension_url.SchemeIs(extensions::kExtensionScheme)); |
| 161 DCHECK_EQ("/", extension_url.path()); | 145 DCHECK_EQ("/", extension_url.path()); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 } | 447 } |
| 464 | 448 |
| 465 if (manifest->HasKey(keys::kPublicKey)) { | 449 if (manifest->HasKey(keys::kPublicKey)) { |
| 466 std::string public_key; | 450 std::string public_key; |
| 467 std::string public_key_bytes; | 451 std::string public_key_bytes; |
| 468 if (!manifest->GetString(keys::kPublicKey, &public_key) || | 452 if (!manifest->GetString(keys::kPublicKey, &public_key) || |
| 469 !ParsePEMKeyBytes(public_key, &public_key_bytes)) { | 453 !ParsePEMKeyBytes(public_key, &public_key_bytes)) { |
| 470 *error = base::ASCIIToUTF16(errors::kInvalidKey); | 454 *error = base::ASCIIToUTF16(errors::kInvalidKey); |
| 471 return false; | 455 return false; |
| 472 } | 456 } |
| 473 std::string extension_id = id_util::GenerateId(public_key_bytes); | 457 std::string extension_id = crx_file::id_util::GenerateId(public_key_bytes); |
| 474 manifest->set_extension_id(extension_id); | 458 manifest->set_extension_id(extension_id); |
| 475 return true; | 459 return true; |
| 476 } | 460 } |
| 477 | 461 |
| 478 if (creation_flags & REQUIRE_KEY) { | 462 if (creation_flags & REQUIRE_KEY) { |
| 479 *error = base::ASCIIToUTF16(errors::kInvalidKey); | 463 *error = base::ASCIIToUTF16(errors::kInvalidKey); |
| 480 return false; | 464 return false; |
| 481 } else { | 465 } else { |
| 482 // If there is a path, we generate the ID from it. This is useful for | 466 // If there is a path, we generate the ID from it. This is useful for |
| 483 // development mode, because it keeps the ID stable across restarts and | 467 // development mode, because it keeps the ID stable across restarts and |
| 484 // reloading the extension. | 468 // reloading the extension. |
| 485 std::string extension_id = id_util::GenerateIdForPath(path); | 469 std::string extension_id = crx_file::id_util::GenerateIdForPath(path); |
| 486 if (extension_id.empty()) { | 470 if (extension_id.empty()) { |
| 487 NOTREACHED() << "Could not create ID from path."; | 471 NOTREACHED() << "Could not create ID from path."; |
| 488 return false; | 472 return false; |
| 489 } | 473 } |
| 490 manifest->set_extension_id(extension_id); | 474 manifest->set_extension_id(extension_id); |
| 491 return true; | 475 return true; |
| 492 } | 476 } |
| 493 } | 477 } |
| 494 | 478 |
| 495 Extension::Extension(const base::FilePath& path, | 479 Extension::Extension(const base::FilePath& path, |
| 496 scoped_ptr<extensions::Manifest> manifest) | 480 scoped_ptr<extensions::Manifest> manifest) |
| 497 : manifest_version_(0), | 481 : manifest_version_(0), |
| 498 converted_from_user_script_(false), | 482 converted_from_user_script_(false), |
| 499 manifest_(manifest.release()), | 483 manifest_(manifest.release()), |
| 500 finished_parsing_manifest_(false), | 484 finished_parsing_manifest_(false), |
| 501 display_in_launcher_(true), | 485 display_in_launcher_(true), |
| 502 display_in_new_tab_page_(true), | 486 display_in_new_tab_page_(true), |
| 503 wants_file_access_(false), | 487 wants_file_access_(false), |
| 504 creation_flags_(0) { | 488 creation_flags_(0) { |
| 505 DCHECK(path.empty() || path.IsAbsolute()); | 489 DCHECK(path.empty() || path.IsAbsolute()); |
| 506 path_ = id_util::MaybeNormalizePath(path); | 490 path_ = crx_file::id_util::MaybeNormalizePath(path); |
| 507 } | 491 } |
| 508 | 492 |
| 509 Extension::~Extension() { | 493 Extension::~Extension() { |
| 510 } | 494 } |
| 511 | 495 |
| 512 bool Extension::InitFromValue(int flags, base::string16* error) { | 496 bool Extension::InitFromValue(int flags, base::string16* error) { |
| 513 DCHECK(error); | 497 DCHECK(error); |
| 514 | 498 |
| 515 creation_flags_ = flags; | 499 creation_flags_ = flags; |
| 516 | 500 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 | 763 |
| 780 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 764 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 781 const Extension* extension, | 765 const Extension* extension, |
| 782 const PermissionSet* permissions, | 766 const PermissionSet* permissions, |
| 783 Reason reason) | 767 Reason reason) |
| 784 : reason(reason), | 768 : reason(reason), |
| 785 extension(extension), | 769 extension(extension), |
| 786 permissions(permissions) {} | 770 permissions(permissions) {} |
| 787 | 771 |
| 788 } // namespace extensions | 772 } // namespace extensions |
| OLD | NEW |