Index: chrome/common/extensions/extension.cc |
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc |
index c4c1d9a2914762c2dfff9c6ff2a10224d6c1403f..ca3432484ac7d44a50df81c8062b4fba72189fed 100644 |
--- a/chrome/common/extensions/extension.cc |
+++ b/chrome/common/extensions/extension.cc |
@@ -318,6 +318,7 @@ ExtensionResource Extension::GetResource( |
base::FilePath relative_file_path(UTF8ToWide(new_path)); |
#endif |
ExtensionResource r(id(), path(), relative_file_path); |
+ |
if ((creation_flags() & Extension::FOLLOW_SYMLINKS_ANYWHERE)) { |
r.set_follow_symlinks_anywhere(); |
} |
@@ -1172,6 +1173,9 @@ bool Extension::InitFromValue(int flags, string16* error) { |
if (!LoadSharedFeatures(error)) |
return false; |
+ if (!LoadSharedModuleFeatures(error)) |
+ return false; |
+ |
if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
manifest_->GetBoolean(keys::kConvertedFromUserScript, |
&converted_from_user_script_); |
@@ -1193,6 +1197,16 @@ bool Extension::InitFromValue(int flags, string16* error) { |
optional_api_permissions, optional_host_permissions, URLPatternSet()); |
initial_api_permissions_.reset(); |
+ // Extensions that export resources should not have any permissions of their |
+ // own, instead they rely on the permissions of the extensions which import |
+ // them. |
+ if (exported_set_.size() > 0 && |
+ (!required_permission_set_->IsEmpty() || |
+ !optional_permission_set_->IsEmpty())) { |
+ *error = ASCIIToUTF16(errors::kInvalidExportPermissions); |
+ return false; |
+ } |
+ |
return true; |
} |
@@ -1494,6 +1508,127 @@ bool Extension::LoadSharedFeatures(string16* error) { |
return true; |
} |
+// static |
+void Extension::ParseImportedPath(const std::string& path, |
+ std::string* import_id, |
+ std::string* import_relative_path) { |
+ std::vector<std::string> tokens; |
+ Tokenize(path, std::string("/"), &tokens); |
+ if (tokens.size() > 2 && tokens[0] == extension_filenames::kModulesDir && |
+ IdIsValid(tokens[1])) { |
+ *import_id = tokens[1]; |
+ *import_relative_path = tokens[2]; |
+ for (size_t i = 3; i < tokens.size(); ++i) |
+ *import_relative_path += "/" + tokens[i]; |
+ } |
+} |
+ |
+// static |
+bool Extension::IsImportedPath(const std::string& path) { |
+ std::vector<std::string> tokens; |
+ Tokenize(path, std::string("/"), &tokens); |
+ if (tokens.size() > 2 && tokens[0] == extension_filenames::kModulesDir && |
+ IdIsValid(tokens[1])) { |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+bool Extension::Imports(const std::string& other_id) const { |
+ for (size_t i = 0; i < imports_.size(); i++) { |
+ if (imports_[i].extension_id == other_id) |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+bool Extension::IsExportAllowed(const std::string& relative_path) const { |
+ return exported_set_.MatchesURL(extension_url_.Resolve(relative_path)); |
+} |
+ |
+bool Extension::LoadSharedModuleFeatures(string16* error) { |
+ bool has_import = manifest_->HasKey(keys::kImport); |
+ bool has_export = manifest_->HasKey(keys::kExport); |
+ if (!has_import && !has_export) |
+ return true; |
+ |
+ if (has_import && has_export) { |
+ *error = ASCIIToUTF16(errors::kInvalidImportAndExport); |
+ return false; |
+ } |
+ |
+ if (has_export) { |
+ const DictionaryValue* export_value = NULL; |
+ if (!manifest_->GetDictionary(keys::kExport, &export_value)) { |
+ *error = ASCIIToUTF16(errors::kInvalidExport); |
+ return false; |
+ } |
+ const ListValue* resources_list = NULL; |
+ if (!export_value->GetList(keys::kResources, &resources_list)) { |
+ *error = ASCIIToUTF16(errors::kInvalidExportResources); |
+ return false; |
+ } |
+ for (size_t i = 0; i < resources_list->GetSize(); ++i) { |
+ std::string resource_path; |
+ if (!resources_list->GetString(i, &resource_path)) { |
+ *error = ErrorUtils::FormatErrorMessageUTF16( |
+ errors::kInvalidExportResourcesString, base::IntToString(i)); |
+ return false; |
+ } |
+ const GURL& resolved_path = extension_url_.Resolve(resource_path); |
+ if (!resolved_path.is_valid()) { |
+ *error = ErrorUtils::FormatErrorMessageUTF16( |
+ errors::kInvalidExportResourcesString, base::IntToString(i)); |
+ return false; |
+ } |
+ exported_set_.AddPattern( |
+ URLPattern(URLPattern::SCHEME_EXTENSION, resolved_path.spec())); |
+ } |
+ } |
+ |
+ if (has_import) { |
+ const ListValue* import_list = NULL; |
+ if (!manifest_->GetList(keys::kImport, &import_list)) { |
+ *error = ASCIIToUTF16(errors::kInvalidImport); |
+ return false; |
+ } |
+ for (size_t i = 0; i < import_list->GetSize(); ++i) { |
+ const DictionaryValue* import_entry = NULL; |
+ if (!import_list->GetDictionary(i, &import_entry)) { |
+ *error = ASCIIToUTF16(errors::kInvalidImport); |
+ return false; |
+ } |
+ std::string extension_id; |
+ imports_.push_back(ImportInfo()); |
+ if (!import_entry->GetString(keys::kId, &extension_id) || |
+ !IdIsValid(extension_id)) { |
+ *error = ErrorUtils::FormatErrorMessageUTF16( |
+ errors::kInvalidImportId, base::IntToString(i)); |
+ return false; |
+ } |
+ imports_.back().extension_id = extension_id; |
+ if (import_entry->HasKey(keys::kMinimumVersion)) { |
+ std::string min_version; |
+ if (!import_entry->GetString(keys::kMinimumVersion, &min_version)) { |
+ *error = ErrorUtils::FormatErrorMessageUTF16( |
+ errors::kInvalidImportVersion, base::IntToString(i)); |
+ return false; |
+ } |
+ imports_.back().min_version = min_version; |
+ Version v(min_version); |
+ /*imports_.back().min_version.reset(new Version(min_version)); |
+ if (!imports_.back().min_version->IsValid()) {*/ |
Matt Perry
2013/04/24 21:22:11
rm this dead code
|
+ if (!v.IsValid()) { |
+ *error = ErrorUtils::FormatErrorMessageUTF16( |
+ errors::kInvalidImportVersion, base::IntToString(i)); |
+ return false; |
+ } |
+ } |
+ } |
+ } |
+ return true; |
+} |
+ |
bool Extension::LoadDescription(string16* error) { |
if (manifest_->HasKey(keys::kDescription) && |
!manifest_->GetString(keys::kDescription, &description_)) { |