2015-07-16 23:40:01 +02:00
|
|
|
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/extensions/component_extension_resource_manager.h"
|
|
|
|
|
2021-07-23 18:40:13 +02:00
|
|
|
#include "base/containers/contains.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/path_service.h"
|
2021-01-28 00:13:12 +01:00
|
|
|
#include "base/values.h"
|
|
|
|
#include "chrome/browser/pdf/pdf_extension_util.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2016-07-14 03:35:07 +02:00
|
|
|
#include "chrome/grit/component_extension_resources_map.h"
|
2021-01-28 00:13:12 +01:00
|
|
|
#include "chrome/grit/pdf_resources_map.h"
|
|
|
|
#include "extensions/common/constants.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
CefComponentExtensionResourceManager::CefComponentExtensionResourceManager() {
|
2017-05-17 11:29:28 +02:00
|
|
|
AddComponentResourceEntries(kComponentExtensionResources,
|
|
|
|
kComponentExtensionResourcesSize);
|
2021-01-28 00:13:12 +01:00
|
|
|
AddComponentResourceEntries(kPdfResources, kPdfResourcesSize);
|
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
base::Value::Dict dict;
|
2021-01-28 00:13:12 +01:00
|
|
|
pdf_extension_util::AddStrings(
|
|
|
|
pdf_extension_util::PdfViewerContext::kPdfViewer, &dict);
|
2023-01-30 18:43:54 +01:00
|
|
|
pdf_extension_util::AddAdditionalData(/*enable_printing=*/true,
|
|
|
|
/*enable_annotations=*/true, &dict);
|
2021-01-28 00:13:12 +01:00
|
|
|
|
|
|
|
ui::TemplateReplacements pdf_viewer_replacements;
|
2022-09-26 21:30:45 +02:00
|
|
|
ui::TemplateReplacementsFromDictionaryValue(dict, &pdf_viewer_replacements);
|
2021-01-28 00:13:12 +01:00
|
|
|
template_replacements_[extension_misc::kPdfExtensionId] =
|
|
|
|
std::move(pdf_viewer_replacements);
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefComponentExtensionResourceManager::~CefComponentExtensionResourceManager() {}
|
|
|
|
|
|
|
|
bool CefComponentExtensionResourceManager::IsComponentExtensionResource(
|
|
|
|
const base::FilePath& extension_path,
|
|
|
|
const base::FilePath& resource_path,
|
2019-07-16 19:59:21 +02:00
|
|
|
int* resource_id) const {
|
2015-07-16 23:40:01 +02:00
|
|
|
base::FilePath directory_path = extension_path;
|
|
|
|
base::FilePath resources_dir;
|
|
|
|
base::FilePath relative_path;
|
2018-05-14 13:24:05 +02:00
|
|
|
if (!base::PathService::Get(chrome::DIR_RESOURCES, &resources_dir) ||
|
2015-07-16 23:40:01 +02:00
|
|
|
!resources_dir.AppendRelativePath(directory_path, &relative_path)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
relative_path = relative_path.Append(resource_path);
|
|
|
|
relative_path = relative_path.NormalizePathSeparators();
|
|
|
|
|
2019-02-21 01:42:36 +01:00
|
|
|
auto entry = path_to_resource_info_.find(relative_path);
|
|
|
|
if (entry != path_to_resource_info_.end()) {
|
2019-07-16 19:59:21 +02:00
|
|
|
*resource_id = entry->second;
|
2019-02-21 01:42:36 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2019-02-21 01:42:36 +01:00
|
|
|
return false;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2019-02-01 20:40:18 +01:00
|
|
|
const ui::TemplateReplacements*
|
|
|
|
CefComponentExtensionResourceManager::GetTemplateReplacementsForExtension(
|
|
|
|
const std::string& extension_id) const {
|
2021-01-28 00:13:12 +01:00
|
|
|
auto it = template_replacements_.find(extension_id);
|
|
|
|
return it != template_replacements_.end() ? &it->second : nullptr;
|
2019-02-01 20:40:18 +01:00
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
void CefComponentExtensionResourceManager::AddComponentResourceEntries(
|
2021-03-04 23:36:57 +01:00
|
|
|
const webui::ResourcePath* entries,
|
2015-07-16 23:40:01 +02:00
|
|
|
size_t size) {
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
2017-05-17 11:29:28 +02:00
|
|
|
base::FilePath resource_path =
|
2021-03-04 23:36:57 +01:00
|
|
|
base::FilePath().AppendASCII(entries[i].path);
|
2015-07-16 23:40:01 +02:00
|
|
|
resource_path = resource_path.NormalizePathSeparators();
|
|
|
|
|
2021-01-28 00:13:12 +01:00
|
|
|
DCHECK(!base::Contains(path_to_resource_info_, resource_path));
|
2021-03-04 23:36:57 +01:00
|
|
|
path_to_resource_info_[resource_path] = entries[i].id;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace extensions
|