#include "ash/webui/file_manager/resource_loader.h"
#include "base/files/file_path.h"
#include "base/strings/string_util.h"
#include "chromeos/constants/chromeos_features.h"
namespace ash {
namespace file_manager {
void AddFilesAppResources(content::WebUIDataSource* source,
const webui::ResourcePath* entries,
size_t size) {
std::map<std::string, int> resource_map;
if (chromeos::features::IsJellyEnabled()) {
for (size_t i = 0; i < size; ++i) {
const base::FilePath file_path(entries[i].path);
if (file_path.Extension() == ".css") {
resource_map[std::string(entries[i].path)] = entries[i].id;
}
}
}
for (size_t i = 0; i < size; ++i) {
std::string path(entries[i].path);
if (base::StartsWith(path, "file_manager/") &&
path.find("untrusted_resources/") == std::string::npos) {
base::ReplaceFirstSubstringAfterOffset(&path, 0, "file_manager/", "");
if (chromeos::features::IsJellyEnabled()) {
const base::FilePath file_path(entries[i].path);
if (file_path.Extension() == ".css") {
const std::string gm3_counterpart(
file_path.RemoveExtension().value() + "_gm3" +
file_path.Extension());
auto gm3_resource = resource_map.find(gm3_counterpart);
if (gm3_resource != resource_map.end()) {
source->AddResourcePath(path, gm3_resource->second);
continue;
}
}
}
source->AddResourcePath(path, entries[i].id);
}
}
}
}
}