blob: a6b5360469d8f33cce60908e582a784f53d2c64e [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[email protected]755e1b732010-06-24 23:28:532// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]33c1c26a2013-01-24 21:56:265#include "content/browser/webui/shared_resources_data_source.h"
[email protected]755e1b732010-06-24 23:28:536
dpapadba11d6dc42021-02-24 18:26:577#include <set>
avib7348942015-12-25 20:57:108
Tom Sepezccfe0032025-03-14 19:56:559#include "base/containers/contains.h"
Lei Zhang4fcf8402023-03-17 22:58:5110#include "content/public/browser/web_ui_data_source.h"
Becca Hughes88a4afe2020-06-23 01:30:4611#include "services/network/public/mojom/content_security_policy.mojom.h"
dbeam41c9c722014-11-26 03:59:0612#include "ui/base/webui/web_ui_util.h"
dpapadaaac8a062024-12-20 19:10:3713#include "ui/webui/resources/grit/webui_resources.h"
14#include "ui/webui/resources/grit/webui_resources_map.h"
[email protected]755e1b732010-06-24 23:28:5315
Georg Neis35ff854b2024-12-17 02:02:0816#if BUILDFLAG(IS_CHROMEOS)
dpapad1be7371b2023-02-23 23:59:4817#include "ash/webui/grit/ash_webui_common_resources_map.h"
Rebekah Potteraca4b4e72023-02-24 16:58:0018#include "content/grit/content_resources.h"
19#include "content/grit/content_resources_map.h"
20#include "mojo/public/js/grit/mojo_bindings_resources.h"
21#include "mojo/public/js/grit/mojo_bindings_resources_map.h"
Kyle Horimoto93a81e472018-09-21 23:30:5022#endif
23
dbeam41c9c722014-11-26 03:59:0624namespace content {
25
[email protected]755e1b732010-06-24 23:28:5326namespace {
27
Georg Neis35ff854b2024-12-17 02:02:0828#if BUILDFLAG(IS_CHROMEOS)
Rebekah Potteraca4b4e72023-02-24 16:58:0029const std::set<int> GetContentResourceIds() {
30 return std::set<int>{
Rebekah Potteraca4b4e72023-02-24 16:58:0031 IDR_UNGUESSABLE_TOKEN_MOJO_JS,
32 IDR_URL_MOJO_JS,
Kyle Horimoto261faa02020-06-19 21:17:5033 };
34}
35
dpapad757b2ac42021-02-18 10:05:0636// Adds all resources with IDs in |resource_ids| to |resources_map|.
37void AddResources(const std::set<int>& resource_ids,
Tom Sepezccfe0032025-03-14 19:56:5538 base::span<const webui::ResourcePath> resources,
dpapadba11d6dc42021-02-24 18:26:5739 WebUIDataSource* source) {
Tom Sepezccfe0032025-03-14 19:56:5540 for (const auto& resource : resources) {
41 if (base::Contains(resource_ids, resource.id)) {
42 source->AddResourcePath(resource.path, resource.id);
43 }
[email protected]755e1b732010-06-24 23:28:5344 }
Kyle Horimoto93a81e472018-09-21 23:30:5045}
Georg Neis35ff854b2024-12-17 02:02:0846#endif // BUILDFLAG(IS_CHROMEOS)
Kyle Horimoto93a81e472018-09-21 23:30:5047
Lei Zhang4fcf8402023-03-17 22:58:5148} // namespace
49
dpapadc67e08d02022-01-11 08:05:3950void PopulateSharedResourcesDataSource(WebUIDataSource* source) {
dpapadba11d6dc42021-02-24 18:26:5751 source->OverrideContentSecurityPolicy(
52 network::mojom::CSPDirectiveName::WorkerSrc, "worker-src blob: 'self';");
Tommy Steimel1e9e4fd32020-05-21 21:24:5553
Rebekah Potteraca4b4e72023-02-24 16:58:0054 // Note: Don't put generated Mojo bindings here. Mojo bindings should be
55 // included in the either the ts_library() target for the UI using them (if
Rebekah Potter87628522023-02-24 21:14:2456 // they are only used by one UI) or in //ui/webui/resources/mojo:build_ts
Rebekah Potteraca4b4e72023-02-24 16:58:0057 // (if used by multiple UIs).
Peter Kasting5f6928c2024-11-29 21:25:1158 source->AddResourcePaths(kWebuiResources);
Georg Neis35ff854b2024-12-17 02:02:0859#if BUILDFLAG(IS_CHROMEOS)
Peter Kasting5f6928c2024-11-29 21:25:1160 source->AddResourcePaths(kAshWebuiCommonResources);
Rebekah Potteraca4b4e72023-02-24 16:58:0061 // Deprecated -lite style mojo bindings.
Peter Kasting5f6928c2024-11-29 21:25:1162 source->AddResourcePaths(kMojoBindingsResources);
Tom Sepezccfe0032025-03-14 19:56:5563 AddResources(GetContentResourceIds(), kContentResources, source);
Georg Neis35ff854b2024-12-17 02:02:0864#endif // BUILDFLAG(IS_CHROMEOS)
dpapadc67e08d02022-01-11 08:05:3965}
[email protected]92253622013-01-14 20:40:5066
dbeam41c9c722014-11-26 03:59:0667} // namespace content