summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/ui/webui/chromeos/crostini_installer
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/browser/ui/webui/chromeos/crostini_installer')
-rw-r--r--chromium/chrome/browser/ui/webui/chromeos/crostini_installer/BUILD.gn11
-rw-r--r--chromium/chrome/browser/ui/webui/chromeos/crostini_installer/OWNERS2
-rw-r--r--chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom34
-rw-r--r--chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.cc44
-rw-r--r--chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.h27
-rw-r--r--chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.cc64
-rw-r--r--chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h60
-rw-r--r--chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.cc78
-rw-r--r--chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h51
9 files changed, 371 insertions, 0 deletions
diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/BUILD.gn b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/BUILD.gn
new file mode 100644
index 00000000000..998e86183ac
--- /dev/null
+++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2019 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("//mojo/public/tools/bindings/mojom.gni")
+
+mojom("mojo_bindings") {
+ sources = [
+ "crostini_installer.mojom",
+ ]
+}
diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/OWNERS b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/OWNERS
new file mode 100644
index 00000000000..08850f42120
--- /dev/null
+++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/OWNERS
@@ -0,0 +1,2 @@
+per-file *.mojom=set noparent
+per-file *.mojom=file://ipc/SECURITY_OWNERS
diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom
new file mode 100644
index 00000000000..0091ecbc389
--- /dev/null
+++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom
@@ -0,0 +1,34 @@
+// Copyright 2019 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 chromeos.crostini_installer.mojom;
+
+// Lives in the browser process. A renderer uses this to create a page handler
+// for controlling Crostini installation.
+interface PageHandlerFactory {
+ // Create a page handler to control Crostini installation.
+ CreatePageHandler(pending_remote<Page> page,
+ pending_receiver<PageHandler> handler);
+};
+
+// Lives in the browser process. A renderer use this to control Crostini
+// installation.
+interface PageHandler {
+ // Start installation
+ Install();
+ // Cancel an on-going installation
+ Cancel();
+ // If a user cancels the installation without starting it at all, this should
+ // be called so that metrics can be recorded.
+ CancelBeforeStart();
+ // The page normally is displayed in a dialog. Call this to close the dialog.
+ // chrome.send('dialogClose') should not be used, which could kill the page
+ // handler before previous mojom calls have been run.
+ Close();
+};
+
+// Lives in the renderer process. The browser uses this to sends installation
+// updates to the web page in the render.
+interface Page {
+};
diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.cc b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.cc
new file mode 100644
index 00000000000..77020c743d1
--- /dev/null
+++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.cc
@@ -0,0 +1,44 @@
+// Copyright 2019 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/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.h"
+
+#include "chrome/browser/chromeos/crostini/crostini_manager.h"
+#include "chrome/common/webui_url_constants.h"
+
+namespace {
+GURL GetUrl() {
+ return GURL{chrome::kChromeUICrostiniInstallerUrl};
+}
+} // namespace
+
+namespace chromeos {
+
+void CrostiniInstallerDialog::Show(Profile* profile) {
+ DCHECK(crostini::IsCrostiniUIAllowedForProfile(profile));
+ auto* instance = SystemWebDialogDelegate::FindInstance(GetUrl().spec());
+ if (instance) {
+ instance->Focus();
+ return;
+ }
+
+ // TODO(lxj): Move installer status tracking into the CrostiniInstaller.
+ DCHECK(!crostini::CrostiniManager::GetForProfile(profile)
+ ->GetInstallerViewStatus());
+ crostini::CrostiniManager::GetForProfile(profile)->SetInstallerViewStatus(
+ true);
+
+ instance = new CrostiniInstallerDialog(profile);
+ instance->ShowSystemDialog();
+}
+
+CrostiniInstallerDialog::CrostiniInstallerDialog(Profile* profile)
+ : SystemWebDialogDelegate{GetUrl(), /*title=*/{}}, profile_{profile} {}
+
+CrostiniInstallerDialog::~CrostiniInstallerDialog() {
+ crostini::CrostiniManager::GetForProfile(profile_)->SetInstallerViewStatus(
+ false);
+}
+
+} // namespace chromeos
diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.h b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.h
new file mode 100644
index 00000000000..5c56ffaba34
--- /dev/null
+++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.h
@@ -0,0 +1,27 @@
+// Copyright 2019 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_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_DIALOG_H_
+#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_DIALOG_H_
+
+#include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h"
+
+class Profile;
+
+namespace chromeos {
+
+class CrostiniInstallerDialog : public SystemWebDialogDelegate {
+ public:
+ static void Show(Profile* profile);
+
+ private:
+ explicit CrostiniInstallerDialog(Profile* profile);
+ ~CrostiniInstallerDialog() override;
+
+ Profile* profile_;
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_DIALOG_H_
diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.cc
new file mode 100644
index 00000000000..8b971423ec4
--- /dev/null
+++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.cc
@@ -0,0 +1,64 @@
+// Copyright 2019 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/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h"
+
+#include <utility>
+
+#include "base/bind.h"
+#include "chrome/browser/chromeos/crostini/crostini_installer_ui_delegate.h"
+
+namespace chromeos {
+
+CrostiniInstallerPageHandler::CrostiniInstallerPageHandler(
+ crostini::CrostiniInstallerUIDelegate* installer_ui_delegate,
+ mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler>
+ pending_page_handler,
+ mojo::PendingRemote<chromeos::crostini_installer::mojom::Page> pending_page,
+ base::OnceClosure close_dialog_callback)
+ : installer_ui_delegate_{installer_ui_delegate},
+ receiver_{this, std::move(pending_page_handler)},
+ page_{std::move(pending_page)},
+ close_dialog_callback_{std::move(close_dialog_callback)} {}
+
+CrostiniInstallerPageHandler::~CrostiniInstallerPageHandler() = default;
+
+void CrostiniInstallerPageHandler::Install() {
+ installer_ui_delegate_->Install(
+ base::BindRepeating(&CrostiniInstallerPageHandler::OnProgressUpdate,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::BindOnce(&CrostiniInstallerPageHandler::OnInstallFinished,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void CrostiniInstallerPageHandler::Cancel() {
+ installer_ui_delegate_->Cancel(
+ base::BindOnce(&CrostiniInstallerPageHandler::OnCanceled,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void CrostiniInstallerPageHandler::CancelBeforeStart() {
+ installer_ui_delegate_->CancelBeforeStart();
+}
+
+void CrostiniInstallerPageHandler::Close() {
+ std::move(close_dialog_callback_).Run();
+}
+
+void CrostiniInstallerPageHandler::OnProgressUpdate(
+ crostini::mojom::InstallerState installer_state,
+ double progress_fraction) {
+ // TODO(lxj)
+}
+
+void CrostiniInstallerPageHandler::OnInstallFinished(
+ crostini::mojom::InstallerError error) {
+ // TODO(lxj)
+}
+
+void CrostiniInstallerPageHandler::OnCanceled() {
+ // TODO(lxj)
+}
+
+} // namespace chromeos
diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h
new file mode 100644
index 00000000000..9060a95057b
--- /dev/null
+++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h
@@ -0,0 +1,60 @@
+// Copyright 2019 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_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_PAGE_HANDLER_H_
+#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_PAGE_HANDLER_H_
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "chrome/browser/chromeos/crostini/crostini_installer_types.mojom-forward.h"
+#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom.h"
+#include "mojo/public/cpp/bindings/pending_receiver.h"
+#include "mojo/public/cpp/bindings/pending_remote.h"
+#include "mojo/public/cpp/bindings/receiver.h"
+#include "mojo/public/cpp/bindings/remote.h"
+
+namespace crostini {
+class CrostiniInstallerUIDelegate;
+} // namespace crostini
+
+namespace chromeos {
+
+class CrostiniInstallerPageHandler
+ : public chromeos::crostini_installer::mojom::PageHandler {
+ public:
+ CrostiniInstallerPageHandler(
+ crostini::CrostiniInstallerUIDelegate* installer_ui_delegate,
+ mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler>
+ pending_page_handler,
+ mojo::PendingRemote<chromeos::crostini_installer::mojom::Page>
+ pending_page,
+ base::OnceClosure close_dialog_callback);
+ ~CrostiniInstallerPageHandler() override;
+
+ // chromeos::crostini_installer::mojom::PageHandler:
+ void Install() override;
+ void Cancel() override;
+ void CancelBeforeStart() override;
+ void Close() override;
+
+ private:
+ void OnProgressUpdate(crostini::mojom::InstallerState installer_state,
+ double progress_fraction);
+ void OnInstallFinished(crostini::mojom::InstallerError error);
+ void OnCanceled();
+
+ crostini::CrostiniInstallerUIDelegate* installer_ui_delegate_;
+ mojo::Receiver<chromeos::crostini_installer::mojom::PageHandler> receiver_;
+ mojo::Remote<chromeos::crostini_installer::mojom::Page> page_;
+ base::OnceClosure close_dialog_callback_;
+
+ base::WeakPtrFactory<CrostiniInstallerPageHandler> weak_ptr_factory_{this};
+
+ DISALLOW_COPY_AND_ASSIGN(CrostiniInstallerPageHandler);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_PAGE_HANDLER_H_
diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.cc b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.cc
new file mode 100644
index 00000000000..02fe92c3d9a
--- /dev/null
+++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.cc
@@ -0,0 +1,78 @@
+// Copyright 2019 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/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h"
+
+#include <utility>
+
+#include "base/bind.h"
+#include "chrome/browser/chromeos/crostini/crostini_installer.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h"
+#include "chrome/common/webui_url_constants.h"
+#include "chrome/grit/browser_resources.h"
+#include "chromeos/constants/chromeos_features.h"
+#include "content/public/browser/web_ui_data_source.h"
+#include "ui/web_dialogs/web_dialog_ui.h"
+#include "ui/webui/mojo_web_ui_controller.h"
+
+namespace chromeos {
+
+bool CrostiniInstallerUI::IsEnabled() {
+ return base::FeatureList::IsEnabled(
+ chromeos::features::kCrostiniWebUIInstaller);
+}
+
+CrostiniInstallerUI::CrostiniInstallerUI(content::WebUI* web_ui)
+ : ui::MojoWebDialogUI{web_ui} {
+ // TODO(lxj): We might want to make sure there is only one instance of this
+ // class.
+
+ content::WebUIDataSource* source =
+ content::WebUIDataSource::Create(chrome::kChromeUICrostiniInstallerHost);
+
+ source->AddResourcePath("app.js", IDR_CROSTINI_INSTALLER_APP_JS);
+ source->AddResourcePath("browser_proxy.js",
+ IDR_CROSTINI_INSTALLER_BROWSER_PROXY_JS);
+ source->AddResourcePath("crostini_installer.mojom-lite.js",
+ IDR_CROSTINI_INSTALLER_MOJO_LITE_JS);
+ source->SetDefaultResource(IDR_CROSTINI_INSTALLER_INDEX_HTML);
+ content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
+
+ AddHandlerToRegistry(base::BindRepeating(
+ &CrostiniInstallerUI::BindPageHandlerFactory, base::Unretained(this)));
+}
+
+CrostiniInstallerUI::~CrostiniInstallerUI() = default;
+
+void CrostiniInstallerUI::BindPageHandlerFactory(
+ mojo::PendingReceiver<
+ chromeos::crostini_installer::mojom::PageHandlerFactory>
+ pending_receiver) {
+ if (page_factory_receiver_.is_bound()) {
+ page_factory_receiver_.reset();
+ }
+
+ page_factory_receiver_.Bind(std::move(pending_receiver));
+}
+
+void CrostiniInstallerUI::CreatePageHandler(
+ mojo::PendingRemote<chromeos::crostini_installer::mojom::Page> pending_page,
+ mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler>
+ pending_page_handler) {
+ DCHECK(pending_page.is_valid());
+
+ page_handler_ = std::make_unique<CrostiniInstallerPageHandler>(
+ crostini::CrostiniInstaller::GetForProfile(Profile::FromWebUI(web_ui())),
+ std::move(pending_page_handler), std::move(pending_page),
+ // Using Unretained(this) because |page_handler_| will not out-live
+ // |this|.
+ //
+ // CloseDialog() is a no-op if we are not in a dialog (e.g. user
+ // access the page using the URL directly, which is not supported).
+ base::BindOnce(&CrostiniInstallerUI::CloseDialog, base::Unretained(this),
+ nullptr));
+}
+
+} // namespace chromeos
diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h
new file mode 100644
index 00000000000..2e5d81d5dd9
--- /dev/null
+++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h
@@ -0,0 +1,51 @@
+// Copyright 2019 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_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_UI_H_
+#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_UI_H_
+
+#include "base/macros.h"
+#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom.h"
+#include "mojo/public/cpp/bindings/pending_receiver.h"
+#include "mojo/public/cpp/bindings/pending_remote.h"
+#include "mojo/public/cpp/bindings/receiver.h"
+#include "ui/web_dialogs/web_dialog_ui.h"
+
+namespace chromeos {
+
+class CrostiniInstallerPageHandler;
+
+// The WebUI for chrome://crostini-installer
+class CrostiniInstallerUI
+ : public ui::MojoWebDialogUI,
+ public chromeos::crostini_installer::mojom::PageHandlerFactory {
+ public:
+ static bool IsEnabled();
+
+ explicit CrostiniInstallerUI(content::WebUI* web_ui);
+ ~CrostiniInstallerUI() override;
+
+ private:
+ void BindPageHandlerFactory(
+ mojo::PendingReceiver<
+ chromeos::crostini_installer::mojom::PageHandlerFactory>
+ pending_receiver);
+
+ // chromeos::crostini_installer::mojom::PageHandlerFactory:
+ void CreatePageHandler(
+ mojo::PendingRemote<chromeos::crostini_installer::mojom::Page>
+ pending_page,
+ mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler>
+ pending_page_handler) override;
+
+ std::unique_ptr<CrostiniInstallerPageHandler> page_handler_;
+ mojo::Receiver<chromeos::crostini_installer::mojom::PageHandlerFactory>
+ page_factory_receiver_{this};
+
+ DISALLOW_COPY_AND_ASSIGN(CrostiniInstallerUI);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_UI_H_