| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/browser/extensions/extension.h" | 5 #include "chrome/browser/extensions/extension.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 "Required value 'name' is missing or invalid."; | 62 "Required value 'name' is missing or invalid."; |
| 63 const char* Extension::kInvalidRunAtError = | 63 const char* Extension::kInvalidRunAtError = |
| 64 "Invalid value for 'content_scripts[*].run_at'."; | 64 "Invalid value for 'content_scripts[*].run_at'."; |
| 65 const char* Extension::kInvalidVersionError = | 65 const char* Extension::kInvalidVersionError = |
| 66 "Required value 'version' is missing or invalid."; | 66 "Required value 'version' is missing or invalid."; |
| 67 const char* Extension::kInvalidZipHashError = | 67 const char* Extension::kInvalidZipHashError = |
| 68 "Required key 'zip_hash' is missing or invalid."; | 68 "Required key 'zip_hash' is missing or invalid."; |
| 69 const char* Extension::kInvalidPluginsDirError = | 69 const char* Extension::kInvalidPluginsDirError = |
| 70 "Invalid value for 'plugins_dir'."; | 70 "Invalid value for 'plugins_dir'."; |
| 71 | 71 |
| 72 const int Extension::kIdSize = 20; // SHA1 (160 bits) == 20 bytes |
| 73 |
| 72 const std::string Extension::VersionString() const { | 74 const std::string Extension::VersionString() const { |
| 73 return version_->GetString(); | 75 return version_->GetString(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 // static | 78 // static |
| 77 GURL Extension::GetResourceURL(const GURL& extension_url, | 79 GURL Extension::GetResourceURL(const GURL& extension_url, |
| 78 const std::string& relative_path) { | 80 const std::string& relative_path) { |
| 79 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme)); | 81 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme)); |
| 80 DCHECK(extension_url.path() == "/"); | 82 DCHECK(extension_url.path() == "/"); |
| 81 | 83 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 static_cast<uint32>(format_version) != kExpectedFormatVersion) { | 167 static_cast<uint32>(format_version) != kExpectedFormatVersion) { |
| 166 *error = kInvalidFormatVersionError; | 168 *error = kInvalidFormatVersionError; |
| 167 return false; | 169 return false; |
| 168 } | 170 } |
| 169 | 171 |
| 170 // Initialize id. | 172 // Initialize id. |
| 171 if (!source.GetString(kIdKey, &id_)) { | 173 if (!source.GetString(kIdKey, &id_)) { |
| 172 *error = kInvalidIdError; | 174 *error = kInvalidIdError; |
| 173 return false; | 175 return false; |
| 174 } | 176 } |
| 175 // Verify that the id is legal. This test is basically verifying that it | 177 |
| 176 // is ASCII and doesn't have any path components in it. | 178 // Verify that the id is legal. The id is a hex string of the SHA-1 hash of |
| 177 // TODO(erikkay): verify the actual id format - it will be more restrictive | 179 // the public key. |
| 178 // than this. Perhaps just a hex string? | 180 std::vector<uint8> id_bytes; |
| 179 if (!IsStringASCII(id_)) { | 181 if (!HexStringToBytes(id_, &id_bytes) || id_bytes.size() != kIdSize) { |
| 180 *error = kInvalidIdError; | |
| 181 return false; | |
| 182 } | |
| 183 FilePath id_path; | |
| 184 id_path = id_path.AppendASCII(id_); | |
| 185 if ((id_path.value() == FilePath::kCurrentDirectory) || | |
| 186 (id_path.value() == FilePath::kParentDirectory) || | |
| 187 !(id_path.BaseName() == id_path)) { | |
| 188 *error = kInvalidIdError; | 182 *error = kInvalidIdError; |
| 189 return false; | 183 return false; |
| 190 } | 184 } |
| 191 | 185 |
| 192 // Initialize URL. | 186 // Initialize URL. |
| 193 extension_url_ = GURL(std::string(chrome::kExtensionScheme) + | 187 extension_url_ = GURL(std::string(chrome::kExtensionScheme) + |
| 194 chrome::kStandardSchemeSeparator + id_ + "/"); | 188 chrome::kStandardSchemeSeparator + id_ + "/"); |
| 195 | 189 |
| 196 // Initialize version. | 190 // Initialize version. |
| 197 std::string version_str; | 191 std::string version_str; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 script.set_path(Extension::GetResourcePath(path(), file)); | 318 script.set_path(Extension::GetResourcePath(path(), file)); |
| 325 script.set_url(Extension::GetResourceURL(url(), file)); | 319 script.set_url(Extension::GetResourceURL(url(), file)); |
| 326 | 320 |
| 327 content_scripts_.push_back(script); | 321 content_scripts_.push_back(script); |
| 328 } | 322 } |
| 329 } | 323 } |
| 330 | 324 |
| 331 return true; | 325 return true; |
| 332 } | 326 } |
| 333 | 327 |
| OLD | NEW |