59dd17f2cf
* chore: bump chromium in DEPS to 102.0.4975.0 * chore: bump chromium in DEPS to 102.0.4977.0 * chore: update patches * Remove parameter of OnGpuProcessCrashed() https://chromium-review.googlesource.com/c/chromium/src/+/3543396 * hid: Add exclusionFilters option to requestDevice https://chromium-review.googlesource.com/c/chromium/src/+/3478175 * chore: bump chromium in DEPS to 102.0.4979.0 * chore: bump chromium in DEPS to 102.0.4981.0 * chore: update patches * Deny notification/push permission for documents in non-standard StoragePartitions https://chromium-review.googlesource.com/c/chromium/src/+/3257305 * Improve FrameTreeNode tracking in URLLoaderNetworkContext https://chromium-review.googlesource.com/c/chromium/src/+/3341866 * fixup! Remove parameter of OnGpuProcessCrashed() * chore: fix lint * Reland "Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome" https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * chore: bump chromium in DEPS to 102.0.4983.0 * Ensure EyeDropperView does not access a destroyed window https://chromium-review.googlesource.com/c/chromium/src/+/3561542 * ci: don't delete dawn .git directory 83901: Adds a generated file with the dawn git hash encoded at build time. | https://dawn-review.googlesource.com/c/dawn/+/83901 * ci: update Windows toolchain 3550827: New toolchain for Windows 10 20348 SDK | https://chromium-review.googlesource.com/c/chromium/src/+/3550827 * chore: bump chromium in DEPS to 102.0.4985.0 * chore: update patches * chore: bump chromium in DEPS to 102.0.4987.0 * chore: update patches * 3563432: codehealth: remove uses of DictionaryValue in cbui/webui https://chromium-review.googlesource.com/c/chromium/src/+/3563432 * chore: update patches after rebase * Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * 3565724: Preserve "proper method names" as-is in error.stack. https://chromium-review.googlesource.com/c/v8/v8/+/3565724 * chore: bump chromium in DEPS to 102.0.4989.0 * chore: update patches * fixup ci: don't delete dawn .git directory for Windows * 3560843: Remove multi-parameter version of gfx::Rect[F]::Inset() https://chromium-review.googlesource.com/c/chromium/src/+/3560843 * 3572711: Remove unused IDS_PDF_TOOLTIP_ROTATE_CW resource. https://chromium-review.googlesource.com/c/chromium/src/+/3572711 * 3572926: Reland "[Sysroot] Switch to Debian Bullseye stable" https://chromium-review.googlesource.com/c/chromium/src/+/3572926 * build: fixup sysroots with electron specific dependencies * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * fixup 3565724: Preserve "proper method names" as-is in error.stack. * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * test: add spec for navigator.hid.requestDevice({ exclusionFilters: [...] } * fixup 3565724: Preserve "proper method names" as-is in error.stack. * ci: use python3 to get the windows toolchain profile 3525960: Explicitly run everything with python3 | https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3525960 * chore: add diagnostic logging * fix: try calling process.crash() * chore: remove logging Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
113 lines
4.1 KiB
C++
113 lines
4.1 KiB
C++
// 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 "shell/browser/extensions/electron_component_extension_resource_manager.h"
|
|
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#include "base/containers/contains.h"
|
|
#include "base/logging.h"
|
|
#include "base/path_service.h"
|
|
#include "base/stl_util.h"
|
|
#include "base/values.h"
|
|
#include "build/build_config.h"
|
|
#include "chrome/common/chrome_paths.h"
|
|
#include "chrome/grit/component_extension_resources_map.h"
|
|
#include "electron/buildflags/buildflags.h"
|
|
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
|
#include "chrome/browser/pdf/pdf_extension_util.h" // nogncheck
|
|
#include "chrome/grit/pdf_resources_map.h"
|
|
#include "extensions/common/constants.h"
|
|
#endif
|
|
|
|
namespace extensions {
|
|
|
|
ElectronComponentExtensionResourceManager::
|
|
ElectronComponentExtensionResourceManager() {
|
|
AddComponentResourceEntries(kComponentExtensionResources,
|
|
kComponentExtensionResourcesSize);
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
|
AddComponentResourceEntries(kPdfResources, kPdfResourcesSize);
|
|
|
|
// Register strings for the PDF viewer, so that $i18n{} replacements work.
|
|
base::Value pdf_strings(base::Value::Type::DICTIONARY);
|
|
pdf_extension_util::AddStrings(
|
|
pdf_extension_util::PdfViewerContext::kPdfViewer, &pdf_strings);
|
|
pdf_extension_util::AddAdditionalData(true, &pdf_strings);
|
|
|
|
ui::TemplateReplacements pdf_viewer_replacements;
|
|
ui::TemplateReplacementsFromDictionaryValue(pdf_strings.GetDict(),
|
|
&pdf_viewer_replacements);
|
|
extension_template_replacements_[extension_misc::kPdfExtensionId] =
|
|
std::move(pdf_viewer_replacements);
|
|
#endif
|
|
}
|
|
|
|
ElectronComponentExtensionResourceManager::
|
|
~ElectronComponentExtensionResourceManager() = default;
|
|
|
|
bool ElectronComponentExtensionResourceManager::IsComponentExtensionResource(
|
|
const base::FilePath& extension_path,
|
|
const base::FilePath& resource_path,
|
|
int* resource_id) const {
|
|
base::FilePath directory_path = extension_path;
|
|
base::FilePath resources_dir;
|
|
base::FilePath relative_path;
|
|
if (!base::PathService::Get(chrome::DIR_RESOURCES, &resources_dir) ||
|
|
!resources_dir.AppendRelativePath(directory_path, &relative_path)) {
|
|
return false;
|
|
}
|
|
relative_path = relative_path.Append(resource_path);
|
|
relative_path = relative_path.NormalizePathSeparators();
|
|
|
|
auto entry = path_to_resource_id_.find(relative_path);
|
|
if (entry != path_to_resource_id_.end()) {
|
|
*resource_id = entry->second;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
const ui::TemplateReplacements*
|
|
ElectronComponentExtensionResourceManager::GetTemplateReplacementsForExtension(
|
|
const std::string& extension_id) const {
|
|
auto it = extension_template_replacements_.find(extension_id);
|
|
if (it == extension_template_replacements_.end()) {
|
|
return nullptr;
|
|
}
|
|
return &it->second;
|
|
}
|
|
|
|
void ElectronComponentExtensionResourceManager::AddComponentResourceEntries(
|
|
const webui::ResourcePath* entries,
|
|
size_t size) {
|
|
base::FilePath gen_folder_path = base::FilePath().AppendASCII(
|
|
"@out_folder@/gen/chrome/browser/resources/");
|
|
gen_folder_path = gen_folder_path.NormalizePathSeparators();
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
base::FilePath resource_path =
|
|
base::FilePath().AppendASCII(entries[i].path);
|
|
resource_path = resource_path.NormalizePathSeparators();
|
|
|
|
if (!gen_folder_path.IsParent(resource_path)) {
|
|
DCHECK(!base::Contains(path_to_resource_id_, resource_path));
|
|
path_to_resource_id_[resource_path] = entries[i].id;
|
|
} else {
|
|
// If the resource is a generated file, strip the generated folder's path,
|
|
// so that it can be served from a normal URL (as if it were not
|
|
// generated).
|
|
base::FilePath effective_path =
|
|
base::FilePath().AppendASCII(resource_path.AsUTF8Unsafe().substr(
|
|
gen_folder_path.value().length()));
|
|
DCHECK(!base::Contains(path_to_resource_id_, effective_path));
|
|
path_to_resource_id_[effective_path] = entries[i].id;
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace extensions
|