| 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" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 | 107 |
| 108 bool SharedModuleInfo::Parse(const Extension* extension, | 108 bool SharedModuleInfo::Parse(const Extension* extension, |
| 109 base::string16* error) { | 109 base::string16* error) { |
| 110 bool has_import = extension->manifest()->HasKey(keys::kImport); | 110 bool has_import = extension->manifest()->HasKey(keys::kImport); |
| 111 bool has_export = extension->manifest()->HasKey(keys::kExport); | 111 bool has_export = extension->manifest()->HasKey(keys::kExport); |
| 112 if (!has_import && !has_export) | 112 if (!has_import && !has_export) |
| 113 return true; | 113 return true; |
| 114 | 114 |
| 115 if (has_import && has_export) { | 115 if (has_import && has_export) { |
| 116 *error = ASCIIToUTF16(errors::kInvalidImportAndExport); | 116 *error = base::ASCIIToUTF16(errors::kInvalidImportAndExport); |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 | 119 |
| 120 if (has_export) { | 120 if (has_export) { |
| 121 const base::DictionaryValue* export_value = NULL; | 121 const base::DictionaryValue* export_value = NULL; |
| 122 if (!extension->manifest()->GetDictionary(keys::kExport, &export_value)) { | 122 if (!extension->manifest()->GetDictionary(keys::kExport, &export_value)) { |
| 123 *error = ASCIIToUTF16(errors::kInvalidExport); | 123 *error = base::ASCIIToUTF16(errors::kInvalidExport); |
| 124 return false; | 124 return false; |
| 125 } | 125 } |
| 126 const base::ListValue* resources_list = NULL; | 126 const base::ListValue* resources_list = NULL; |
| 127 if (!export_value->GetList(keys::kResources, &resources_list)) { | 127 if (!export_value->GetList(keys::kResources, &resources_list)) { |
| 128 *error = ASCIIToUTF16(errors::kInvalidExportResources); | 128 *error = base::ASCIIToUTF16(errors::kInvalidExportResources); |
| 129 return false; | 129 return false; |
| 130 } | 130 } |
| 131 for (size_t i = 0; i < resources_list->GetSize(); ++i) { | 131 for (size_t i = 0; i < resources_list->GetSize(); ++i) { |
| 132 std::string resource_path; | 132 std::string resource_path; |
| 133 if (!resources_list->GetString(i, &resource_path)) { | 133 if (!resources_list->GetString(i, &resource_path)) { |
| 134 *error = ErrorUtils::FormatErrorMessageUTF16( | 134 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 135 errors::kInvalidExportResourcesString, base::IntToString(i)); | 135 errors::kInvalidExportResourcesString, base::IntToString(i)); |
| 136 return false; | 136 return false; |
| 137 } | 137 } |
| 138 const GURL& resolved_path = extension->url().Resolve(resource_path); | 138 const GURL& resolved_path = extension->url().Resolve(resource_path); |
| 139 if (!resolved_path.is_valid()) { | 139 if (!resolved_path.is_valid()) { |
| 140 *error = ErrorUtils::FormatErrorMessageUTF16( | 140 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 141 errors::kInvalidExportResourcesString, base::IntToString(i)); | 141 errors::kInvalidExportResourcesString, base::IntToString(i)); |
| 142 return false; | 142 return false; |
| 143 } | 143 } |
| 144 exported_set_.AddPattern( | 144 exported_set_.AddPattern( |
| 145 URLPattern(URLPattern::SCHEME_EXTENSION, resolved_path.spec())); | 145 URLPattern(URLPattern::SCHEME_EXTENSION, resolved_path.spec())); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 if (has_import) { | 149 if (has_import) { |
| 150 const base::ListValue* import_list = NULL; | 150 const base::ListValue* import_list = NULL; |
| 151 if (!extension->manifest()->GetList(keys::kImport, &import_list)) { | 151 if (!extension->manifest()->GetList(keys::kImport, &import_list)) { |
| 152 *error = ASCIIToUTF16(errors::kInvalidImport); | 152 *error = base::ASCIIToUTF16(errors::kInvalidImport); |
| 153 return false; | 153 return false; |
| 154 } | 154 } |
| 155 for (size_t i = 0; i < import_list->GetSize(); ++i) { | 155 for (size_t i = 0; i < import_list->GetSize(); ++i) { |
| 156 const base::DictionaryValue* import_entry = NULL; | 156 const base::DictionaryValue* import_entry = NULL; |
| 157 if (!import_list->GetDictionary(i, &import_entry)) { | 157 if (!import_list->GetDictionary(i, &import_entry)) { |
| 158 *error = ASCIIToUTF16(errors::kInvalidImport); | 158 *error = base::ASCIIToUTF16(errors::kInvalidImport); |
| 159 return false; | 159 return false; |
| 160 } | 160 } |
| 161 std::string extension_id; | 161 std::string extension_id; |
| 162 imports_.push_back(ImportInfo()); | 162 imports_.push_back(ImportInfo()); |
| 163 if (!import_entry->GetString(keys::kId, &extension_id) || | 163 if (!import_entry->GetString(keys::kId, &extension_id) || |
| 164 !Extension::IdIsValid(extension_id)) { | 164 !Extension::IdIsValid(extension_id)) { |
| 165 *error = ErrorUtils::FormatErrorMessageUTF16( | 165 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 166 errors::kInvalidImportId, base::IntToString(i)); | 166 errors::kInvalidImportId, base::IntToString(i)); |
| 167 return false; | 167 return false; |
| 168 } | 168 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 219 |
| 220 const std::vector<std::string> SharedModuleHandler::Keys() const { | 220 const std::vector<std::string> SharedModuleHandler::Keys() const { |
| 221 static const char* keys[] = { | 221 static const char* keys[] = { |
| 222 keys::kExport, | 222 keys::kExport, |
| 223 keys::kImport | 223 keys::kImport |
| 224 }; | 224 }; |
| 225 return std::vector<std::string>(keys, keys + arraysize(keys)); | 225 return std::vector<std::string>(keys, keys + arraysize(keys)); |
| 226 } | 226 } |
| 227 | 227 |
| 228 } // namespace extensions | 228 } // namespace extensions |
| OLD | NEW |