Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 755e1b73 | 2010-06-24 23:28:53 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 33c1c26a | 2013-01-24 21:56:26 | [diff] [blame] | 5 | #include "content/browser/webui/shared_resources_data_source.h" |
[email protected] | 755e1b73 | 2010-06-24 23:28:53 | [diff] [blame] | 6 | |
dpapad | ba11d6dc4 | 2021-02-24 18:26:57 | [diff] [blame] | 7 | #include <set> |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 8 | |
Tom Sepez | ccfe003 | 2025-03-14 19:56:55 | [diff] [blame] | 9 | #include "base/containers/contains.h" |
Lei Zhang | 4fcf840 | 2023-03-17 22:58:51 | [diff] [blame] | 10 | #include "content/public/browser/web_ui_data_source.h" |
Becca Hughes | 88a4afe | 2020-06-23 01:30:46 | [diff] [blame] | 11 | #include "services/network/public/mojom/content_security_policy.mojom.h" |
dbeam | 41c9c72 | 2014-11-26 03:59:06 | [diff] [blame] | 12 | #include "ui/base/webui/web_ui_util.h" |
dpapad | aaac8a06 | 2024-12-20 19:10:37 | [diff] [blame] | 13 | #include "ui/webui/resources/grit/webui_resources.h" |
14 | #include "ui/webui/resources/grit/webui_resources_map.h" | ||||
[email protected] | 755e1b73 | 2010-06-24 23:28:53 | [diff] [blame] | 15 | |
Georg Neis | 35ff854b | 2024-12-17 02:02:08 | [diff] [blame] | 16 | #if BUILDFLAG(IS_CHROMEOS) |
dpapad | 1be7371b | 2023-02-23 23:59:48 | [diff] [blame] | 17 | #include "ash/webui/grit/ash_webui_common_resources_map.h" |
Rebekah Potter | aca4b4e7 | 2023-02-24 16:58:00 | [diff] [blame] | 18 | #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 Horimoto | 93a81e47 | 2018-09-21 23:30:50 | [diff] [blame] | 22 | #endif |
23 | |||||
dbeam | 41c9c72 | 2014-11-26 03:59:06 | [diff] [blame] | 24 | namespace content { |
25 | |||||
[email protected] | 755e1b73 | 2010-06-24 23:28:53 | [diff] [blame] | 26 | namespace { |
27 | |||||
Georg Neis | 35ff854b | 2024-12-17 02:02:08 | [diff] [blame] | 28 | #if BUILDFLAG(IS_CHROMEOS) |
Rebekah Potter | aca4b4e7 | 2023-02-24 16:58:00 | [diff] [blame] | 29 | const std::set<int> GetContentResourceIds() { |
30 | return std::set<int>{ | ||||
Rebekah Potter | aca4b4e7 | 2023-02-24 16:58:00 | [diff] [blame] | 31 | IDR_UNGUESSABLE_TOKEN_MOJO_JS, |
32 | IDR_URL_MOJO_JS, | ||||
Kyle Horimoto | 261faa0 | 2020-06-19 21:17:50 | [diff] [blame] | 33 | }; |
34 | } | ||||
35 | |||||
dpapad | 757b2ac4 | 2021-02-18 10:05:06 | [diff] [blame] | 36 | // Adds all resources with IDs in |resource_ids| to |resources_map|. |
37 | void AddResources(const std::set<int>& resource_ids, | ||||
Tom Sepez | ccfe003 | 2025-03-14 19:56:55 | [diff] [blame] | 38 | base::span<const webui::ResourcePath> resources, |
dpapad | ba11d6dc4 | 2021-02-24 18:26:57 | [diff] [blame] | 39 | WebUIDataSource* source) { |
Tom Sepez | ccfe003 | 2025-03-14 19:56:55 | [diff] [blame] | 40 | for (const auto& resource : resources) { |
41 | if (base::Contains(resource_ids, resource.id)) { | ||||
42 | source->AddResourcePath(resource.path, resource.id); | ||||
43 | } | ||||
[email protected] | 755e1b73 | 2010-06-24 23:28:53 | [diff] [blame] | 44 | } |
Kyle Horimoto | 93a81e47 | 2018-09-21 23:30:50 | [diff] [blame] | 45 | } |
Georg Neis | 35ff854b | 2024-12-17 02:02:08 | [diff] [blame] | 46 | #endif // BUILDFLAG(IS_CHROMEOS) |
Kyle Horimoto | 93a81e47 | 2018-09-21 23:30:50 | [diff] [blame] | 47 | |
Lei Zhang | 4fcf840 | 2023-03-17 22:58:51 | [diff] [blame] | 48 | } // namespace |
49 | |||||
dpapad | c67e08d0 | 2022-01-11 08:05:39 | [diff] [blame] | 50 | void PopulateSharedResourcesDataSource(WebUIDataSource* source) { |
dpapad | ba11d6dc4 | 2021-02-24 18:26:57 | [diff] [blame] | 51 | source->OverrideContentSecurityPolicy( |
52 | network::mojom::CSPDirectiveName::WorkerSrc, "worker-src blob: 'self';"); | ||||
Tommy Steimel | 1e9e4fd3 | 2020-05-21 21:24:55 | [diff] [blame] | 53 | |
Rebekah Potter | aca4b4e7 | 2023-02-24 16:58:00 | [diff] [blame] | 54 | // 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 Potter | 8762852 | 2023-02-24 21:14:24 | [diff] [blame] | 56 | // they are only used by one UI) or in //ui/webui/resources/mojo:build_ts |
Rebekah Potter | aca4b4e7 | 2023-02-24 16:58:00 | [diff] [blame] | 57 | // (if used by multiple UIs). |
Peter Kasting | 5f6928c | 2024-11-29 21:25:11 | [diff] [blame] | 58 | source->AddResourcePaths(kWebuiResources); |
Georg Neis | 35ff854b | 2024-12-17 02:02:08 | [diff] [blame] | 59 | #if BUILDFLAG(IS_CHROMEOS) |
Peter Kasting | 5f6928c | 2024-11-29 21:25:11 | [diff] [blame] | 60 | source->AddResourcePaths(kAshWebuiCommonResources); |
Rebekah Potter | aca4b4e7 | 2023-02-24 16:58:00 | [diff] [blame] | 61 | // Deprecated -lite style mojo bindings. |
Peter Kasting | 5f6928c | 2024-11-29 21:25:11 | [diff] [blame] | 62 | source->AddResourcePaths(kMojoBindingsResources); |
Tom Sepez | ccfe003 | 2025-03-14 19:56:55 | [diff] [blame] | 63 | AddResources(GetContentResourceIds(), kContentResources, source); |
Georg Neis | 35ff854b | 2024-12-17 02:02:08 | [diff] [blame] | 64 | #endif // BUILDFLAG(IS_CHROMEOS) |
dpapad | c67e08d0 | 2022-01-11 08:05:39 | [diff] [blame] | 65 | } |
[email protected] | 9225362 | 2013-01-14 20:40:50 | [diff] [blame] | 66 | |
dbeam | 41c9c72 | 2014-11-26 03:59:06 | [diff] [blame] | 67 | } // namespace content |