blob: 6da08be6dfe81c9edfe281fa949a6e6573d602e7 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2018 The Chromium Authors
Nasko Oskov3e19fbd2018-06-13 00:13:292// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Nasko Oskovee48dfb42024-06-08 05:13:065
Nasko Oskov3e19fbd2018-06-13 00:13:296#include "content/browser/process_internals/process_internals_ui.h"
7
8#include <memory>
Henrique Ferreiro8feb71f02019-09-17 00:05:489#include <string>
10#include <utility>
Nasko Oskov3e19fbd2018-06-13 00:13:2911
Avi Drissmanadac21992023-01-11 23:46:3912#include "base/functional/bind.h"
Henrique Ferreiro8feb71f02019-09-17 00:05:4813#include "content/browser/process_internals/process_internals.mojom.h"
14#include "content/browser/process_internals/process_internals_handler_impl.h"
dpapad5c8201b12023-04-25 23:05:3915#include "content/grit/process_resources.h"
16#include "content/grit/process_resources_map.h"
Nasko Oskov3e19fbd2018-06-13 00:13:2917#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 Kokatsu2e4a4902020-08-05 20:52:1624#include "services/network/public/mojom/content_security_policy.mojom.h"
Nasko Oskov3e19fbd2018-06-13 00:13:2925
26namespace content {
27
28ProcessInternalsUI::ProcessInternalsUI(WebUI* web_ui)
Daniel Cheng0d360f552020-12-01 23:11:4229 : WebUIController(web_ui) {
Nasko Oskov8a73f7d2019-09-27 22:29:3230 // This WebUI does not require any process bindings, so disable it early in
31 // initialization time.
Avi Drissman78865bbb2024-08-22 20:57:1932 web_ui->SetBindings(BindingsPolicySet());
Nasko Oskov3e19fbd2018-06-13 00:13:2933
34 // Create a WebUIDataSource to serve the HTML/JS files to the WebUI.
Juyoung Kimaa699c82022-02-08 01:55:2935 WebUIDataSource* source = WebUIDataSource::CreateAndAdd(
36 web_ui->GetWebContents()->GetBrowserContext(),
37 kChromeUIProcessInternalsHost);
Nasko Oskov3e19fbd2018-06-13 00:13:2938
Peter Kasting5f6928c2024-11-29 21:25:1139 source->AddResourcePaths(kProcessResources);
dpapad5c8201b12023-04-25 23:05:3940 source->SetDefaultResource(IDR_PROCESS_PROCESS_INTERNALS_HTML);
Jun Kokatsu2e4a4902020-08-05 20:52:1641 source->OverrideContentSecurityPolicy(
42 network::mojom::CSPDirectiveName::TrustedTypes,
Jun Kokatsu935468e2021-08-19 05:07:4943 "trusted-types static-types;");
Nasko Oskov3e19fbd2018-06-13 00:13:2944}
45
Mario Sanchez Prada5509ddb2019-12-17 08:49:1146WEB_UI_CONTROLLER_TYPE_IMPL(ProcessInternalsUI)
47
Nasko Oskov3e19fbd2018-06-13 00:13:2948ProcessInternalsUI::~ProcessInternalsUI() = default;
49
Sharon Yange7371a12021-07-01 20:32:3150void ProcessInternalsUI::WebUIRenderFrameCreated(RenderFrameHost* rfh) {
Nasko Oskov8a73f7d2019-09-27 22:29:3251 // Enable the JavaScript Mojo bindings in the renderer process, so the JS
52 // code can call the Mojo APIs exposed by this WebUI.
Jiewei Qiancc639a662022-04-01 02:43:3453 rfh->EnableMojoJsBindings(nullptr);
Nasko Oskov8a73f7d2019-09-27 22:29:3254}
55
Robert Sesek976c70cf2022-08-12 19:17:5756void ProcessInternalsUI::BindInterface(
57 RenderFrameHost* render_frame_host,
58 mojo::PendingReceiver<::mojom::ProcessInternalsHandler> receiver) {
Nasko Oskov24982842018-10-06 02:02:0559 ui_handler_ = std::make_unique<ProcessInternalsHandlerImpl>(
60 render_frame_host->GetSiteInstance()->GetBrowserContext(),
Henrique Ferreiro8feb71f02019-09-17 00:05:4861 std::move(receiver));
Nasko Oskov3e19fbd2018-06-13 00:13:2962}
63
Nasko Oskov3e19fbd2018-06-13 00:13:2964} // namespace content