| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/manifest_handlers/shared_module_info.h" | 5 #include "extensions/common/manifest_handlers/shared_module_info.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/version.h" | 12 #include "base/version.h" |
| 13 #include "components/crx_file/id_util.h" |
| 13 #include "extensions/common/constants.h" | 14 #include "extensions/common/constants.h" |
| 14 #include "extensions/common/error_utils.h" | 15 #include "extensions/common/error_utils.h" |
| 15 #include "extensions/common/manifest_constants.h" | 16 #include "extensions/common/manifest_constants.h" |
| 16 #include "extensions/common/permissions/permission_set.h" | 17 #include "extensions/common/permissions/permission_set.h" |
| 17 #include "extensions/common/permissions/permissions_data.h" | 18 #include "extensions/common/permissions/permissions_data.h" |
| 18 | 19 |
| 19 namespace extensions { | 20 namespace extensions { |
| 20 | 21 |
| 21 namespace keys = manifest_keys; | 22 namespace keys = manifest_keys; |
| 22 namespace values = manifest_values; | 23 namespace values = manifest_values; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 45 SharedModuleInfo::~SharedModuleInfo() { | 46 SharedModuleInfo::~SharedModuleInfo() { |
| 46 } | 47 } |
| 47 | 48 |
| 48 // static | 49 // static |
| 49 void SharedModuleInfo::ParseImportedPath(const std::string& path, | 50 void SharedModuleInfo::ParseImportedPath(const std::string& path, |
| 50 std::string* import_id, | 51 std::string* import_id, |
| 51 std::string* import_relative_path) { | 52 std::string* import_relative_path) { |
| 52 std::vector<std::string> tokens; | 53 std::vector<std::string> tokens; |
| 53 Tokenize(path, std::string("/"), &tokens); | 54 Tokenize(path, std::string("/"), &tokens); |
| 54 if (tokens.size() > 2 && tokens[0] == kModulesDir && | 55 if (tokens.size() > 2 && tokens[0] == kModulesDir && |
| 55 Extension::IdIsValid(tokens[1])) { | 56 crx_file::id_util::IdIsValid(tokens[1])) { |
| 56 *import_id = tokens[1]; | 57 *import_id = tokens[1]; |
| 57 *import_relative_path = tokens[2]; | 58 *import_relative_path = tokens[2]; |
| 58 for (size_t i = 3; i < tokens.size(); ++i) | 59 for (size_t i = 3; i < tokens.size(); ++i) |
| 59 *import_relative_path += "/" + tokens[i]; | 60 *import_relative_path += "/" + tokens[i]; |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 // static | 64 // static |
| 64 bool SharedModuleInfo::IsImportedPath(const std::string& path) { | 65 bool SharedModuleInfo::IsImportedPath(const std::string& path) { |
| 65 std::vector<std::string> tokens; | 66 std::vector<std::string> tokens; |
| 66 Tokenize(path, std::string("/"), &tokens); | 67 Tokenize(path, std::string("/"), &tokens); |
| 67 if (tokens.size() > 2 && tokens[0] == kModulesDir && | 68 if (tokens.size() > 2 && tokens[0] == kModulesDir && |
| 68 Extension::IdIsValid(tokens[1])) { | 69 crx_file::id_util::IdIsValid(tokens[1])) { |
| 69 return true; | 70 return true; |
| 70 } | 71 } |
| 71 return false; | 72 return false; |
| 72 } | 73 } |
| 73 | 74 |
| 74 // static | 75 // static |
| 75 bool SharedModuleInfo::IsSharedModule(const Extension* extension) { | 76 bool SharedModuleInfo::IsSharedModule(const Extension* extension) { |
| 76 CHECK(extension); | 77 CHECK(extension); |
| 77 return extension->manifest()->is_shared_module(); | 78 return extension->manifest()->is_shared_module(); |
| 78 } | 79 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 148 } |
| 148 if (export_value->HasKey(keys::kWhitelist)) { | 149 if (export_value->HasKey(keys::kWhitelist)) { |
| 149 const base::ListValue* whitelist = NULL; | 150 const base::ListValue* whitelist = NULL; |
| 150 if (!export_value->GetList(keys::kWhitelist, &whitelist)) { | 151 if (!export_value->GetList(keys::kWhitelist, &whitelist)) { |
| 151 *error = base::ASCIIToUTF16(errors::kInvalidExportWhitelist); | 152 *error = base::ASCIIToUTF16(errors::kInvalidExportWhitelist); |
| 152 return false; | 153 return false; |
| 153 } | 154 } |
| 154 for (size_t i = 0; i < whitelist->GetSize(); ++i) { | 155 for (size_t i = 0; i < whitelist->GetSize(); ++i) { |
| 155 std::string extension_id; | 156 std::string extension_id; |
| 156 if (!whitelist->GetString(i, &extension_id) || | 157 if (!whitelist->GetString(i, &extension_id) || |
| 157 !Extension::IdIsValid(extension_id)) { | 158 !crx_file::id_util::IdIsValid(extension_id)) { |
| 158 *error = ErrorUtils::FormatErrorMessageUTF16( | 159 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 159 errors::kInvalidExportWhitelistString, base::IntToString(i)); | 160 errors::kInvalidExportWhitelistString, base::IntToString(i)); |
| 160 return false; | 161 return false; |
| 161 } | 162 } |
| 162 export_whitelist_.insert(extension_id); | 163 export_whitelist_.insert(extension_id); |
| 163 } | 164 } |
| 164 } | 165 } |
| 165 for (size_t i = 0; i < resources_list->GetSize(); ++i) { | 166 for (size_t i = 0; i < resources_list->GetSize(); ++i) { |
| 166 std::string resource_path; | 167 std::string resource_path; |
| 167 if (!resources_list->GetString(i, &resource_path)) { | 168 if (!resources_list->GetString(i, &resource_path)) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 188 } | 189 } |
| 189 for (size_t i = 0; i < import_list->GetSize(); ++i) { | 190 for (size_t i = 0; i < import_list->GetSize(); ++i) { |
| 190 const base::DictionaryValue* import_entry = NULL; | 191 const base::DictionaryValue* import_entry = NULL; |
| 191 if (!import_list->GetDictionary(i, &import_entry)) { | 192 if (!import_list->GetDictionary(i, &import_entry)) { |
| 192 *error = base::ASCIIToUTF16(errors::kInvalidImport); | 193 *error = base::ASCIIToUTF16(errors::kInvalidImport); |
| 193 return false; | 194 return false; |
| 194 } | 195 } |
| 195 std::string extension_id; | 196 std::string extension_id; |
| 196 imports_.push_back(ImportInfo()); | 197 imports_.push_back(ImportInfo()); |
| 197 if (!import_entry->GetString(keys::kId, &extension_id) || | 198 if (!import_entry->GetString(keys::kId, &extension_id) || |
| 198 !Extension::IdIsValid(extension_id)) { | 199 !crx_file::id_util::IdIsValid(extension_id)) { |
| 199 *error = ErrorUtils::FormatErrorMessageUTF16( | 200 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 200 errors::kInvalidImportId, base::IntToString(i)); | 201 errors::kInvalidImportId, base::IntToString(i)); |
| 201 return false; | 202 return false; |
| 202 } | 203 } |
| 203 imports_.back().extension_id = extension_id; | 204 imports_.back().extension_id = extension_id; |
| 204 if (import_entry->HasKey(keys::kMinimumVersion)) { | 205 if (import_entry->HasKey(keys::kMinimumVersion)) { |
| 205 std::string min_version; | 206 std::string min_version; |
| 206 if (!import_entry->GetString(keys::kMinimumVersion, &min_version)) { | 207 if (!import_entry->GetString(keys::kMinimumVersion, &min_version)) { |
| 207 *error = ErrorUtils::FormatErrorMessageUTF16( | 208 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 208 errors::kInvalidImportVersion, base::IntToString(i)); | 209 errors::kInvalidImportVersion, base::IntToString(i)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 254 |
| 254 const std::vector<std::string> SharedModuleHandler::Keys() const { | 255 const std::vector<std::string> SharedModuleHandler::Keys() const { |
| 255 static const char* keys[] = { | 256 static const char* keys[] = { |
| 256 keys::kExport, | 257 keys::kExport, |
| 257 keys::kImport | 258 keys::kImport |
| 258 }; | 259 }; |
| 259 return std::vector<std::string>(keys, keys + arraysize(keys)); | 260 return std::vector<std::string>(keys, keys + arraysize(keys)); |
| 260 } | 261 } |
| 261 | 262 |
| 262 } // namespace extensions | 263 } // namespace extensions |
| OLD | NEW |