extension_resource_path_normalizer.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "extensions/common/extension_resource_path_normalizer.h"
  5. #include <utility>
  6. #include <vector>
  7. #include "base/check.h"
  8. bool NormalizeExtensionResourcePath(const base::FilePath& path,
  9. base::FilePath* result) {
  10. DCHECK(result);
  11. if (path.ReferencesParent())
  12. return false;
  13. base::FilePath rv;
  14. for (const auto& path_component : path.GetComponents()) {
  15. if (path_component != base::FilePath::kCurrentDirectory)
  16. rv = rv.Append(path_component);
  17. }
  18. if (rv.empty())
  19. return false;
  20. *result = std::move(rv);
  21. return true;
  22. }
  23. std::set<base::FilePath> NormalizeExtensionResourcePaths(
  24. const std::set<base::FilePath>& icons_paths) {
  25. std::set<base::FilePath> rv;
  26. for (const auto& icon_path : icons_paths) {
  27. base::FilePath normalized_path;
  28. if (NormalizeExtensionResourcePath(icon_path, &normalized_path))
  29. rv.emplace(std::move(normalized_path));
  30. }
  31. return rv;
  32. }