c05e04c797d0441442858a73bedd96c0bc260d8a - chromium/src

1,406 views
Skip to first unread message

ort...@chromium.org

unread,
Mar 1, 2022, 7:43:46 PM3/1/22
to chromium...@chromium.org
commit c05e04c797d0441442858a73bedd96c0bc260d8a
Author: Giovanni Ortuño Urquidi <ort...@chromium.org>
AuthorDate: Wed Mar 02 00:43:17 2022
Commit: Chromium LUCI CQ <chromiu...@luci-project-accounts.iam.gserviceaccount.com>
CommitDate: Wed Mar 02 00:43:17 2022

system-extensions: Implement functionality of system-extensions-internals

Adds a Mojo Interface that installs a System Extension from a directory
in the Downloads/ directory.

Calls this Mojo Interface from chrome://system-extensions-internals/.

Bug: 1192426
Change-Id: Idd04f3ea6c245aa5ae46d6d43721aa59555e8558
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3308234
Reviewed-by: Jiewei Qian <q...@chromium.org>
Commit-Queue: Giovanni Ortuno Urquidi <ort...@chromium.org>
Reviewed-by: Dominick Ng <domi...@chromium.org>
Cr-Commit-Position: refs/heads/main@{#976488}

diff --git a/ash/webui/system_extensions_internals_ui/BUILD.gn b/ash/webui/system_extensions_internals_ui/BUILD.gn
index d260625a..7b0a72a 100644
--- a/ash/webui/system_extensions_internals_ui/BUILD.gn
+++ b/ash/webui/system_extensions_internals_ui/BUILD.gn
@@ -19,6 +19,7 @@

deps = [
"//ash/webui/resources:system_extensions_internals_resources",
+ "//ash/webui/system_extensions_internals_ui/mojom",
"//content/public/browser",
"//ui/webui",
]
@@ -30,7 +31,13 @@
}

js_library("system_extensions_internals") {
- sources = [ "resources/index.js" ]
+ sources = [
+ "resources/index.js",
+ "resources/page_handler.js",
+ ]
+ externs_list =
+ [ "//ash/webui/web_applications/externs/file_handling.externs.js" ]
+ deps = [ "//ash/webui/system_extensions_internals_ui/mojom:mojom_webui_js" ]
}

js2gtest("browser_tests_js") {
@@ -43,13 +50,32 @@

grd_prefix = "ash_system_extensions_internals"

+mojo_grdp = "$target_gen_dir/system_extensions_internals_mojo_resources.grdp"
+
+generate_grd("build_mojo_grdp") {
+ grd_prefix = grd_prefix
+ out_grd = mojo_grdp
+
+ deps = [ "//ash/webui/system_extensions_internals_ui/mojom:mojom_webui_js" ]
+
+ # Flatten out the dependency tree of your mojom and add generated bindings
+ # file here.
+ input_files = [ "ash/webui/system_extensions_internals_ui/mojom/system_extensions_internals_ui.mojom-webui.js" ]
+
+ input_files_base_dir =
+ rebase_path("$root_gen_dir/mojom-webui", "$root_build_dir")
+}
+
generate_grd("build_grd") {
input_files_base_dir = rebase_path("resources", "//")
input_files = [
"index.html",
"index.js",
+ "page_handler.js",
]

grd_prefix = grd_prefix
out_grd = "$target_gen_dir/${grd_prefix}_resources.grd"
+ deps = [ ":build_mojo_grdp" ]
+ grdp_files = [ mojo_grdp ]
}
diff --git a/ash/webui/system_extensions_internals_ui/mojom/BUILD.gn b/ash/webui/system_extensions_internals_ui/mojom/BUILD.gn
new file mode 100644
index 0000000..0755d379
--- /dev/null
+++ b/ash/webui/system_extensions_internals_ui/mojom/BUILD.gn
@@ -0,0 +1,15 @@
+# Copyright 2021 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.
+
+import("//build/config/chromeos/ui_mode.gni")
+import("//mojo/public/tools/bindings/mojom.gni")
+
+assert(is_chromeos_ash, "System Extensions Internals is ash-chrome only")
+
+mojom("mojom") {
+ sources = [ "system_extensions_internals_ui.mojom" ]
+
+ public_deps = [ "//mojo/public/mojom/base" ]
+ webui_module_path = "/ash/webui/system_extensions_internals_ui/mojom/"
+}
diff --git a/ash/webui/system_extensions_internals_ui/mojom/OWNERS b/ash/webui/system_extensions_internals_ui/mojom/OWNERS
new file mode 100644
index 0000000..08850f4
--- /dev/null
+++ b/ash/webui/system_extensions_internals_ui/mojom/OWNERS
@@ -0,0 +1,2 @@
+per-file *.mojom=set noparent
+per-file *.mojom=file://ipc/SECURITY_OWNERS
diff --git a/ash/webui/system_extensions_internals_ui/mojom/system_extensions_internals_ui.mojom b/ash/webui/system_extensions_internals_ui/mojom/system_extensions_internals_ui.mojom
new file mode 100644
index 0000000..5af2055
--- /dev/null
+++ b/ash/webui/system_extensions_internals_ui/mojom/system_extensions_internals_ui.mojom
@@ -0,0 +1,15 @@
+// Copyright 2021 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.
+
+module ash.mojom.system_extensions_internals;
+
+import "mojo/public/mojom/base/safe_base_name.mojom";
+
+// Interface for installing an unpacked System Extension.
+interface PageHandler {
+ // Installs a system extension from `system_extension_dir_name`, which must be
+ // a folder located at the top level of the default Downloads directory.
+ InstallSystemExtensionFromDownloadsDir(
+ mojo_base.mojom.SafeBaseName system_extension_dir_name) => (bool success);
+};
diff --git a/ash/webui/system_extensions_internals_ui/resources/index.js b/ash/webui/system_extensions_internals_ui/resources/index.js
index 1441a844..b1dc57b 100644
--- a/ash/webui/system_extensions_internals_ui/resources/index.js
+++ b/ash/webui/system_extensions_internals_ui/resources/index.js
@@ -2,9 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

+import {pageHandler} from './page_handler.js';
+
const chooseDirButton = document.querySelector('#choose-directory');
const resultDialog = document.querySelector('#result-dialog');

chooseDirButton.addEventListener('click', async event => {
+ const directory = await window.showDirectoryPicker({startIn: 'downloads'});
+ const {success} = await pageHandler.installSystemExtensionFromDownloadsDir(
+ {path: {path: directory.name}});
+ if (success) {
+ resultDialog.textContent =
+ `System Extension in '${directory.name}' was successfully installed.`;
+ } else {
+ resultDialog.textContent =
+ `System Extension in '${directory.name}' failed to be installed.`;
+ }
resultDialog.showModal();
});
diff --git a/ash/webui/system_extensions_internals_ui/resources/page_handler.js b/ash/webui/system_extensions_internals_ui/resources/page_handler.js
new file mode 100644
index 0000000..74fd29d
--- /dev/null
+++ b/ash/webui/system_extensions_internals_ui/resources/page_handler.js
@@ -0,0 +1,11 @@
+// Copyright 2021 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.
+
+/**
+ * @fileoverview Convenience module to bind to initialize a PageHandler
+ * remote i.e. a PageHandler that we can use to talk to the browser.
+ */
+import {PageHandler, PageHandlerRemote} from '/ash/webui/system_extensions_internals_ui/mojom/system_extensions_internals_ui.mojom-webui.js';
+
+export const pageHandler = PageHandler.getRemote();
diff --git a/ash/webui/system_extensions_internals_ui/system_extensions_internals_ui.h b/ash/webui/system_extensions_internals_ui/system_extensions_internals_ui.h
index c1dcb1c..5a757713 100644
--- a/ash/webui/system_extensions_internals_ui/system_extensions_internals_ui.h
+++ b/ash/webui/system_extensions_internals_ui/system_extensions_internals_ui.h
@@ -5,6 +5,7 @@
#ifndef ASH_WEBUI_SYSTEM_EXTENSIONS_INTERNALS_UI_SYSTEM_EXTENSIONS_INTERNALS_UI_H_
#define ASH_WEBUI_SYSTEM_EXTENSIONS_INTERNALS_UI_SYSTEM_EXTENSIONS_INTERNALS_UI_H_

+#include "ash/webui/system_extensions_internals_ui/mojom/system_extensions_internals_ui.mojom.h"
#include "ui/webui/mojo_web_ui_controller.h"

namespace ash {
@@ -18,6 +19,12 @@
delete;
~SystemExtensionsInternalsUI() override;

+ // Implemented in //chrome/browser/chrome_browser_interface_binders.cc
+ // because PageHandler is implemented in //chrome/browser.
+ void BindInterface(
+ mojo::PendingReceiver<mojom::system_extensions_internals::PageHandler>
+ page_handler);
+
private:
WEB_UI_CONTROLLER_TYPE_DECL();
};
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 14d1bbf..a4e30d7 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -2440,6 +2440,8 @@
"//ash/webui/shimless_rma",
"//ash/webui/shimless_rma/mojom",
"//ash/webui/shortcut_customization_ui",
+ "//ash/webui/system_extensions_internals_ui",
+ "//ash/webui/system_extensions_internals_ui/mojom",
"//chrome/app/theme:chrome_unscaled_resources_grit",
"//chrome/browser/ash/system_extensions",
"//chrome/browser/ash/system_extensions/api/hid",
diff --git a/chrome/browser/ash/system_extensions/BUILD.gn b/chrome/browser/ash/system_extensions/BUILD.gn
index 27f8bf9..5c23430 100644
--- a/chrome/browser/ash/system_extensions/BUILD.gn
+++ b/chrome/browser/ash/system_extensions/BUILD.gn
@@ -23,6 +23,8 @@
"system_extensions_install_manager.cc",
"system_extensions_install_manager.h",
"system_extensions_install_status.h",
+ "system_extensions_internals_page_handler.cc",
+ "system_extensions_internals_page_handler.h",
"system_extensions_profile_utils.cc",
"system_extensions_profile_utils.h",
"system_extensions_provider.cc",
@@ -40,6 +42,7 @@
deps = [
":system_extensions_group",
"//ash/constants",
+ "//ash/webui/system_extensions_internals_ui/mojom",
"//base",
"//chrome/browser/chromeos",
"//chrome/browser/profiles",
diff --git a/chrome/browser/ash/system_extensions/system_extensions_internals_page_handler.cc b/chrome/browser/ash/system_extensions/system_extensions_internals_page_handler.cc
new file mode 100644
index 0000000..a704db82
--- /dev/null
+++ b/chrome/browser/ash/system_extensions/system_extensions_internals_page_handler.cc
@@ -0,0 +1,45 @@
+// Copyright 2021 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 "chrome/browser/ash/system_extensions/system_extensions_internals_page_handler.h"
+
+#include "base/debug/stack_trace.h"
+
+SystemExtensionsInternalsPageHandler::SystemExtensionsInternalsPageHandler(
+ Profile* profile)
+ : profile_(profile) {}
+
+SystemExtensionsInternalsPageHandler::~SystemExtensionsInternalsPageHandler() =
+ default;
+
+void SystemExtensionsInternalsPageHandler::
+ InstallSystemExtensionFromDownloadsDir(
+ const base::SafeBaseName& system_extension_dir_name,
+ InstallSystemExtensionFromDownloadsDirCallback callback) {
+ base::FilePath downloads_path;
+ if (!base::PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &downloads_path)) {
+ std::move(callback).Run(false);
+ return;
+ }
+
+ auto& install_manager =
+ SystemExtensionsProvider::Get(profile_)->install_manager();
+ base::FilePath system_extension_dir =
+ downloads_path.Append(system_extension_dir_name);
+
+ install_manager.InstallUnpackedExtensionFromDir(
+ system_extension_dir,
+ base::BindOnce(&SystemExtensionsInternalsPageHandler::OnInstallFinished,
+ weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
+}
+
+void SystemExtensionsInternalsPageHandler::OnInstallFinished(
+ InstallSystemExtensionFromDownloadsDirCallback callback,
+ InstallStatusOrSystemExtensionId result) {
+ if (!result.ok()) {
+ LOG(ERROR) << "failed with: " << static_cast<int32_t>(result.status());
+ }
+
+ std::move(callback).Run(result.ok());
+}
diff --git a/chrome/browser/ash/system_extensions/system_extensions_internals_page_handler.h b/chrome/browser/ash/system_extensions/system_extensions_internals_page_handler.h
new file mode 100644
index 0000000..b286c5b
--- /dev/null
+++ b/chrome/browser/ash/system_extensions/system_extensions_internals_page_handler.h
@@ -0,0 +1,40 @@
+// Copyright 2021 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.
+
+#ifndef CHROME_BROWSER_ASH_SYSTEM_EXTENSIONS_SYSTEM_EXTENSIONS_INTERNALS_PAGE_HANDLER_H_
+#define CHROME_BROWSER_ASH_SYSTEM_EXTENSIONS_SYSTEM_EXTENSIONS_INTERNALS_PAGE_HANDLER_H_
+
+#include "ash/webui/system_extensions_internals_ui/mojom/system_extensions_internals_ui.mojom.h"
+#include "base/files/file_path.h"
+#include "base/files/safe_base_name.h"
+#include "base/memory/weak_ptr.h"
+#include "base/path_service.h"
+#include "chrome/browser/ash/system_extensions/system_extensions_install_status.h"
+#include "chrome/browser/ash/system_extensions/system_extensions_provider.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_paths.h"
+
+class SystemExtensionsInternalsPageHandler
+ : public ash::mojom::system_extensions_internals::PageHandler {
+ public:
+ explicit SystemExtensionsInternalsPageHandler(Profile* profile);
+ ~SystemExtensionsInternalsPageHandler() override;
+
+ // mojom::system_extensions_internals::PageHandler
+ void InstallSystemExtensionFromDownloadsDir(
+ const base::SafeBaseName& system_extension_dir_name,
+ InstallSystemExtensionFromDownloadsDirCallback callback) override;
+
+ private:
+ void OnInstallFinished(
+ InstallSystemExtensionFromDownloadsDirCallback callback,
+ InstallStatusOrSystemExtensionId result);
+
+ raw_ptr<Profile> profile_;
+
+ base::WeakPtrFactory<SystemExtensionsInternalsPageHandler> weak_ptr_factory_{
+ this};
+};
+
+#endif // CHROME_BROWSER_ASH_SYSTEM_EXTENSIONS_SYSTEM_EXTENSIONS_INTERNALS_PAGE_HANDLER_H_
diff --git a/chrome/browser/chrome_browser_interface_binders.cc b/chrome/browser/chrome_browser_interface_binders.cc
index 315507e..04bbe20 100644
--- a/chrome/browser/chrome_browser_interface_binders.cc
+++ b/chrome/browser/chrome_browser_interface_binders.cc
@@ -74,6 +74,7 @@
#include "content/public/common/url_constants.h"
#include "extensions/buildflags/buildflags.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
+#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "services/image_annotation/public/mojom/image_annotation.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/credentialmanager/credential_manager.mojom.h"
@@ -219,7 +220,10 @@
#include "ash/webui/scanning/mojom/scanning.mojom.h"
#include "ash/webui/scanning/scanning_ui.h"
#include "ash/webui/shimless_rma/shimless_rma.h"
+#include "ash/webui/system_extensions_internals_ui/mojom/system_extensions_internals_ui.mojom.h"
+#include "ash/webui/system_extensions_internals_ui/system_extensions_internals_ui.h"
#include "chrome/browser/apps/digital_goods/digital_goods_factory_impl.h"
+#include "chrome/browser/ash/system_extensions/system_extensions_internals_page_handler.h"
#include "chrome/browser/nearby_sharing/common/nearby_share_features.h"
#include "chrome/browser/speech/cros_speech_recognition_service_factory.h"
#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision.mojom.h"
@@ -304,6 +308,16 @@
#include "components/history_clusters/history_clusters_internals/webui/history_clusters_internals_ui.h"
#endif

+#if BUILDFLAG(IS_CHROMEOS_ASH)
+void ash::SystemExtensionsInternalsUI::BindInterface(
+ mojo::PendingReceiver<ash::mojom::system_extensions_internals::PageHandler>
+ receiver) {
+ auto page_handler = std::make_unique<SystemExtensionsInternalsPageHandler>(
+ Profile::FromWebUI(web_ui()));
+ mojo::MakeSelfOwnedReceiver(std::move(page_handler), std::move(receiver));
+}
+#endif
+
namespace chrome {
namespace internal {

@@ -1139,6 +1153,13 @@
.Add<ash::mojom::sample_swa::PageHandlerFactory>();
#endif // BUILDFLAG(IS_CHROMEOS_ASH) && !defined(OFFICIAL_BUILD)

+#if BUILDFLAG(IS_CHROMEOS_ASH)
+ if (base::FeatureList::IsEnabled(ash::features::kSystemExtensions)) {
+ registry.ForWebUI<ash::SystemExtensionsInternalsUI>()
+ .Add<ash::mojom::system_extensions_internals::PageHandler>();
+ }
+#endif // BUILDFLAG(IS_CHROMEOS_ASH)
+
// --- Section 2: chrome-untrusted:// WebUIs:

#if BUILDFLAG(IS_CHROMEOS_ASH) && !defined(OFFICIAL_BUILD)
Reply all
Reply to author
Forward
0 new messages