Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Nasko Oskov | 3e19fbd | 2018-06-13 00:13:29 | [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 | |
Nasko Oskov | ee48dfb4 | 2024-06-08 05:13:06 | [diff] [blame] | 5 | |
Nasko Oskov | 3e19fbd | 2018-06-13 00:13:29 | [diff] [blame] | 6 | #include "content/browser/process_internals/process_internals_ui.h" |
| 7 | |
| 8 | #include <memory> |
Henrique Ferreiro | 8feb71f0 | 2019-09-17 00:05:48 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <utility> |
Nasko Oskov | 3e19fbd | 2018-06-13 00:13:29 | [diff] [blame] | 11 | |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 12 | #include "base/functional/bind.h" |
Henrique Ferreiro | 8feb71f0 | 2019-09-17 00:05:48 | [diff] [blame] | 13 | #include "content/browser/process_internals/process_internals.mojom.h" |
| 14 | #include "content/browser/process_internals/process_internals_handler_impl.h" |
dpapad | 5c8201b1 | 2023-04-25 23:05:39 | [diff] [blame] | 15 | #include "content/grit/process_resources.h" |
| 16 | #include "content/grit/process_resources_map.h" |
Nasko Oskov | 3e19fbd | 2018-06-13 00:13:29 | [diff] [blame] | 17 | #include "content/public/browser/render_process_host.h" |
| 18 | #include "content/public/browser/web_contents.h" |
| 19 | #include "content/public/browser/web_ui.h" |
| 20 | #include "content/public/browser/web_ui_data_source.h" |
| 21 | #include "content/public/browser/web_ui_message_handler.h" |
| 22 | #include "content/public/common/bindings_policy.h" |
| 23 | #include "content/public/common/url_constants.h" |
Jun Kokatsu | 2e4a490 | 2020-08-05 20:52:16 | [diff] [blame] | 24 | #include "services/network/public/mojom/content_security_policy.mojom.h" |
Nasko Oskov | 3e19fbd | 2018-06-13 00:13:29 | [diff] [blame] | 25 | |
| 26 | namespace content { |
| 27 | |
| 28 | ProcessInternalsUI::ProcessInternalsUI(WebUI* web_ui) |
Daniel Cheng | 0d360f55 | 2020-12-01 23:11:42 | [diff] [blame] | 29 | : WebUIController(web_ui) { |
Nasko Oskov | 8a73f7d | 2019-09-27 22:29:32 | [diff] [blame] | 30 | // This WebUI does not require any process bindings, so disable it early in |
| 31 | // initialization time. |
Avi Drissman | 78865bbb | 2024-08-22 20:57:19 | [diff] [blame] | 32 | web_ui->SetBindings(BindingsPolicySet()); |
Nasko Oskov | 3e19fbd | 2018-06-13 00:13:29 | [diff] [blame] | 33 | |
| 34 | // Create a WebUIDataSource to serve the HTML/JS files to the WebUI. |
Juyoung Kim | aa699c8 | 2022-02-08 01:55:29 | [diff] [blame] | 35 | WebUIDataSource* source = WebUIDataSource::CreateAndAdd( |
| 36 | web_ui->GetWebContents()->GetBrowserContext(), |
| 37 | kChromeUIProcessInternalsHost); |
Nasko Oskov | 3e19fbd | 2018-06-13 00:13:29 | [diff] [blame] | 38 | |
Peter Kasting | 5f6928c | 2024-11-29 21:25:11 | [diff] [blame] | 39 | source->AddResourcePaths(kProcessResources); |
dpapad | 5c8201b1 | 2023-04-25 23:05:39 | [diff] [blame] | 40 | source->SetDefaultResource(IDR_PROCESS_PROCESS_INTERNALS_HTML); |
Jun Kokatsu | 2e4a490 | 2020-08-05 20:52:16 | [diff] [blame] | 41 | source->OverrideContentSecurityPolicy( |
| 42 | network::mojom::CSPDirectiveName::TrustedTypes, |
Jun Kokatsu | 935468e | 2021-08-19 05:07:49 | [diff] [blame] | 43 | "trusted-types static-types;"); |
Nasko Oskov | 3e19fbd | 2018-06-13 00:13:29 | [diff] [blame] | 44 | } |
| 45 | |
Mario Sanchez Prada | 5509ddb | 2019-12-17 08:49:11 | [diff] [blame] | 46 | WEB_UI_CONTROLLER_TYPE_IMPL(ProcessInternalsUI) |
| 47 | |
Nasko Oskov | 3e19fbd | 2018-06-13 00:13:29 | [diff] [blame] | 48 | ProcessInternalsUI::~ProcessInternalsUI() = default; |
| 49 | |
Sharon Yang | e7371a1 | 2021-07-01 20:32:31 | [diff] [blame] | 50 | void ProcessInternalsUI::WebUIRenderFrameCreated(RenderFrameHost* rfh) { |
Nasko Oskov | 8a73f7d | 2019-09-27 22:29:32 | [diff] [blame] | 51 | // Enable the JavaScript Mojo bindings in the renderer process, so the JS |
| 52 | // code can call the Mojo APIs exposed by this WebUI. |
Jiewei Qian | cc639a66 | 2022-04-01 02:43:34 | [diff] [blame] | 53 | rfh->EnableMojoJsBindings(nullptr); |
Nasko Oskov | 8a73f7d | 2019-09-27 22:29:32 | [diff] [blame] | 54 | } |
| 55 | |
Robert Sesek | 976c70cf | 2022-08-12 19:17:57 | [diff] [blame] | 56 | void ProcessInternalsUI::BindInterface( |
| 57 | RenderFrameHost* render_frame_host, |
| 58 | mojo::PendingReceiver<::mojom::ProcessInternalsHandler> receiver) { |
Nasko Oskov | 2498284 | 2018-10-06 02:02:05 | [diff] [blame] | 59 | ui_handler_ = std::make_unique<ProcessInternalsHandlerImpl>( |
| 60 | render_frame_host->GetSiteInstance()->GetBrowserContext(), |
Henrique Ferreiro | 8feb71f0 | 2019-09-17 00:05:48 | [diff] [blame] | 61 | std::move(receiver)); |
Nasko Oskov | 3e19fbd | 2018-06-13 00:13:29 | [diff] [blame] | 62 | } |
| 63 | |
Nasko Oskov | 3e19fbd | 2018-06-13 00:13:29 | [diff] [blame] | 64 | } // namespace content |