| 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/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 for (size_t i = 0; i < Extension::kNumPermissions; ++i) { | 57 for (size_t i = 0; i < Extension::kNumPermissions; ++i) { |
| 58 if (str == Extension::kPermissionNames[i]) | 58 if (str == Extension::kPermissionNames[i]) |
| 59 return true; | 59 return true; |
| 60 } | 60 } |
| 61 | 61 |
| 62 return false; | 62 return false; |
| 63 } | 63 } |
| 64 | 64 |
| 65 } // namespace | 65 } // namespace |
| 66 | 66 |
| 67 // static | |
| 68 int Extension::id_counter_ = 0; | |
| 69 | |
| 70 const char Extension::kManifestFilename[] = "manifest.json"; | 67 const char Extension::kManifestFilename[] = "manifest.json"; |
| 71 const char Extension::kLocaleFolder[] = "_locales"; | 68 const char Extension::kLocaleFolder[] = "_locales"; |
| 72 const char Extension::kMessagesFilename[] = "messages.json"; | 69 const char Extension::kMessagesFilename[] = "messages.json"; |
| 73 | 70 |
| 74 // A list of all the keys allowed by themes. | 71 // A list of all the keys allowed by themes. |
| 75 static const wchar_t* kValidThemeKeys[] = { | 72 static const wchar_t* kValidThemeKeys[] = { |
| 76 keys::kDescription, | 73 keys::kDescription, |
| 77 keys::kName, | 74 keys::kName, |
| 78 keys::kPublicKey, | 75 keys::kPublicKey, |
| 79 keys::kSignature, | 76 keys::kSignature, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 HKEY reg_root = HKEY_LOCAL_MACHINE; | 166 HKEY reg_root = HKEY_LOCAL_MACHINE; |
| 170 RegKey key; | 167 RegKey key; |
| 171 registry_path.append("\\"); | 168 registry_path.append("\\"); |
| 172 registry_path.append(id_); | 169 registry_path.append(id_); |
| 173 if (key.Open(reg_root, ASCIIToWide(registry_path).c_str())) | 170 if (key.Open(reg_root, ASCIIToWide(registry_path).c_str())) |
| 174 return Extension::EXTERNAL_REGISTRY; | 171 return Extension::EXTERNAL_REGISTRY; |
| 175 #endif | 172 #endif |
| 176 return Extension::EXTERNAL_PREF; | 173 return Extension::EXTERNAL_PREF; |
| 177 } | 174 } |
| 178 | 175 |
| 179 bool Extension::GenerateIdFromPublicKey(const std::string& input, | 176 bool Extension::GenerateId(const std::string& input, std::string* output) { |
| 180 std::string* output) { | |
| 181 CHECK(output); | 177 CHECK(output); |
| 182 if (input.length() == 0) | 178 if (input.length() == 0) |
| 183 return false; | 179 return false; |
| 184 | 180 |
| 185 const uint8* ubuf = reinterpret_cast<const unsigned char*>(input.data()); | 181 const uint8* ubuf = reinterpret_cast<const unsigned char*>(input.data()); |
| 186 SHA256Context ctx; | 182 SHA256Context ctx; |
| 187 SHA256_Begin(&ctx); | 183 SHA256_Begin(&ctx); |
| 188 SHA256_Update(&ctx, ubuf, input.length()); | 184 SHA256_Update(&ctx, ubuf, input.length()); |
| 189 uint8 hash[Extension::kIdSize]; | 185 uint8 hash[Extension::kIdSize]; |
| 190 SHA256_End(&ctx, hash, NULL, sizeof(hash)); | 186 SHA256_End(&ctx, hash, NULL, sizeof(hash)); |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 // Nothing much has changed. | 596 // Nothing much has changed. |
| 601 return false; | 597 return false; |
| 602 } | 598 } |
| 603 | 599 |
| 604 bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, | 600 bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, |
| 605 std::string* error) { | 601 std::string* error) { |
| 606 if (source.HasKey(keys::kPublicKey)) { | 602 if (source.HasKey(keys::kPublicKey)) { |
| 607 std::string public_key_bytes; | 603 std::string public_key_bytes; |
| 608 if (!source.GetString(keys::kPublicKey, &public_key_) || | 604 if (!source.GetString(keys::kPublicKey, &public_key_) || |
| 609 !ParsePEMKeyBytes(public_key_, &public_key_bytes) || | 605 !ParsePEMKeyBytes(public_key_, &public_key_bytes) || |
| 610 !GenerateIdFromPublicKey(public_key_bytes, &id_)) { | 606 !GenerateId(public_key_bytes, &id_)) { |
| 611 *error = errors::kInvalidKey; | 607 *error = errors::kInvalidKey; |
| 612 return false; | 608 return false; |
| 613 } | 609 } |
| 614 } else if (require_id) { | 610 } else if (require_id) { |
| 615 *error = errors::kInvalidKey; | 611 *error = errors::kInvalidKey; |
| 616 return false; | 612 return false; |
| 617 } else { | 613 } else { |
| 618 // Generate a random ID | 614 // If there is a path, we generate the ID from it. This is useful for |
| 619 id_ = StringPrintf("%x", NextGeneratedId()); | 615 // development mode, because it keeps the ID stable across restarts and |
| 620 | 616 // reloading the extension. |
| 621 // pad the string out to kIdSize*2 chars with zeroes. | 617 if (!GenerateId(WideToUTF8(path_.ToWStringHack()), &id_)) { |
| 622 id_.insert(0, Extension::kIdSize*2 - id_.length(), '0'); | 618 NOTREACHED() << "Could not create ID from path."; |
| 623 | 619 return false; |
| 624 // Convert to our mp-decimal. | 620 } |
| 625 ConvertHexadecimalToIDAlphabet(&id_); | |
| 626 } | 621 } |
| 627 | 622 |
| 628 // Make a copy of the manifest so we can store it in prefs. | 623 // Make a copy of the manifest so we can store it in prefs. |
| 629 manifest_value_.reset(static_cast<DictionaryValue*>(source.DeepCopy())); | 624 manifest_value_.reset(static_cast<DictionaryValue*>(source.DeepCopy())); |
| 630 | 625 |
| 631 // Initialize the URL. | 626 // Initialize the URL. |
| 632 extension_url_ = GURL(std::string(chrome::kExtensionScheme) + | 627 extension_url_ = GURL(std::string(chrome::kExtensionScheme) + |
| 633 chrome::kStandardSchemeSeparator + id_ + "/"); | 628 chrome::kStandardSchemeSeparator + id_ + "/"); |
| 634 | 629 |
| 635 // Initialize version. | 630 // Initialize version. |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 UserScript::PatternList::const_iterator pattern = | 1167 UserScript::PatternList::const_iterator pattern = |
| 1173 content_script->url_patterns().begin(); | 1168 content_script->url_patterns().begin(); |
| 1174 for (; pattern != content_script->url_patterns().end(); ++pattern) { | 1169 for (; pattern != content_script->url_patterns().end(); ++pattern) { |
| 1175 if (pattern->match_subdomains() && pattern->host().empty()) | 1170 if (pattern->match_subdomains() && pattern->host().empty()) |
| 1176 return true; | 1171 return true; |
| 1177 } | 1172 } |
| 1178 } | 1173 } |
| 1179 | 1174 |
| 1180 return false; | 1175 return false; |
| 1181 } | 1176 } |
| OLD | NEW |