Commit 36b96982 authored by Jason Lin's avatar Jason Lin Committed by Commit Bot

Display crostini WebUI installer in a system dialog

Bug: 929571
Test: Turn on flag crostini-webui-installer and install crostini from settings
Change-Id: I78895c2a84800d87d4e885e4bc35195d2329db74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1798072Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Jason Lin <lxj@google.com>
Cr-Commit-Position: refs/heads/master@{#697413}
parent b004998c
...@@ -1644,6 +1644,8 @@ jumbo_split_static_library("ui") { ...@@ -1644,6 +1644,8 @@ jumbo_split_static_library("ui") {
"webui/chromeos/cellular_setup/mobile_setup_ui.h", "webui/chromeos/cellular_setup/mobile_setup_ui.h",
"webui/chromeos/certificate_manager_dialog_ui.cc", "webui/chromeos/certificate_manager_dialog_ui.cc",
"webui/chromeos/certificate_manager_dialog_ui.h", "webui/chromeos/certificate_manager_dialog_ui.h",
"webui/chromeos/crostini_installer/crostini_installer_dialog.cc",
"webui/chromeos/crostini_installer/crostini_installer_dialog.h",
"webui/chromeos/crostini_installer/crostini_installer_page_handler.cc", "webui/chromeos/crostini_installer/crostini_installer_page_handler.cc",
"webui/chromeos/crostini_installer/crostini_installer_page_handler.h", "webui/chromeos/crostini_installer/crostini_installer_page_handler.h",
"webui/chromeos/crostini_installer/crostini_installer_ui.cc", "webui/chromeos/crostini_installer/crostini_installer_ui.cc",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "chrome/browser/chromeos/crostini/crostini_manager.h" #include "chrome/browser/chromeos/crostini/crostini_manager.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h" #include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.h"
#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/chrome_unscaled_resources.h" #include "chrome/grit/chrome_unscaled_resources.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -106,6 +108,8 @@ base::string16 GetErrorMessage(Error error) { ...@@ -106,6 +108,8 @@ base::string16 GetErrorMessage(Error error) {
} // namespace } // namespace
// TODO(lxj): |CrostiniInstallerView| will be removed at some point. We will
// wait until then to find a better place for this function.
void crostini::ShowCrostiniInstallerView( void crostini::ShowCrostiniInstallerView(
Profile* profile, Profile* profile,
crostini::CrostiniUISurface ui_surface) { crostini::CrostiniUISurface ui_surface) {
...@@ -116,8 +120,13 @@ void crostini::ShowCrostiniInstallerView( ...@@ -116,8 +120,13 @@ void crostini::ShowCrostiniInstallerView(
} }
base::UmaHistogramEnumeration(kCrostiniSetupSourceHistogram, ui_surface, base::UmaHistogramEnumeration(kCrostiniSetupSourceHistogram, ui_surface,
crostini::CrostiniUISurface::kCount); crostini::CrostiniUISurface::kCount);
if (chromeos::CrostiniInstallerUI::IsEnabled()) {
return chromeos::CrostiniInstallerDialog::Show(profile);
} else {
return CrostiniInstallerView::Show( return CrostiniInstallerView::Show(
profile, crostini::CrostiniInstaller::GetForProfile(profile)); profile, crostini::CrostiniInstaller::GetForProfile(profile));
}
} }
// static // static
...@@ -126,6 +135,8 @@ void CrostiniInstallerView::Show( ...@@ -126,6 +135,8 @@ void CrostiniInstallerView::Show(
crostini::CrostiniInstallerUIDelegate* delegate) { crostini::CrostiniInstallerUIDelegate* delegate) {
DCHECK(crostini::IsCrostiniUIAllowedForProfile(profile)); DCHECK(crostini::IsCrostiniUIAllowedForProfile(profile));
if (!g_crostini_installer_view) { if (!g_crostini_installer_view) {
DCHECK(!crostini::CrostiniManager::GetForProfile(profile)
->GetInstallerViewStatus());
g_crostini_installer_view = new CrostiniInstallerView(profile, delegate); g_crostini_installer_view = new CrostiniInstallerView(profile, delegate);
views::DialogDelegate::CreateDialogWidget(g_crostini_installer_view, views::DialogDelegate::CreateDialogWidget(g_crostini_installer_view,
nullptr, nullptr); nullptr, nullptr);
...@@ -141,7 +152,6 @@ void CrostiniInstallerView::Show( ...@@ -141,7 +152,6 @@ void CrostiniInstallerView::Show(
g_crostini_installer_view->big_message_label_->SetText( g_crostini_installer_view->big_message_label_->SetText(
l10n_util::GetStringFUTF16(IDS_CROSTINI_INSTALLER_TITLE, device_type)); l10n_util::GetStringFUTF16(IDS_CROSTINI_INSTALLER_TITLE, device_type));
// TODO(lxj): Move installer status tracking into the CrostiniInstaller.
crostini::CrostiniManager::GetForProfile(profile)->SetInstallerViewStatus( crostini::CrostiniManager::GetForProfile(profile)->SetInstallerViewStatus(
true); true);
} }
......
// 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
// 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_
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "content/public/browser/web_ui_data_source.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" #include "ui/webui/mojo_web_ui_controller.h"
namespace chromeos { namespace chromeos {
...@@ -23,7 +24,7 @@ bool CrostiniInstallerUI::IsEnabled() { ...@@ -23,7 +24,7 @@ bool CrostiniInstallerUI::IsEnabled() {
} }
CrostiniInstallerUI::CrostiniInstallerUI(content::WebUI* web_ui) CrostiniInstallerUI::CrostiniInstallerUI(content::WebUI* web_ui)
: ui::MojoWebUIController{web_ui} { : ui::MojoWebDialogUI{web_ui} {
// TODO(lxj): We might want to make sure there is only one instance of this // TODO(lxj): We might want to make sure there is only one instance of this
// class. // class.
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "ui/webui/mojo_web_ui_controller.h" #include "ui/web_dialogs/web_dialog_ui.h"
namespace chromeos { namespace chromeos {
...@@ -18,7 +18,7 @@ class CrostiniInstallerPageHandler; ...@@ -18,7 +18,7 @@ class CrostiniInstallerPageHandler;
// The WebUI for chrome://crostini-installer // The WebUI for chrome://crostini-installer
class CrostiniInstallerUI class CrostiniInstallerUI
: public ui::MojoWebUIController, : public ui::MojoWebDialogUI,
public chromeos::crostini_installer::mojom::PageHandlerFactory { public chromeos::crostini_installer::mojom::PageHandlerFactory {
public: public:
static bool IsEnabled(); static bool IsEnabled();
......
...@@ -214,6 +214,7 @@ const char kChromeUIConfirmPasswordChangeHost[] = "confirm-password-change"; ...@@ -214,6 +214,7 @@ const char kChromeUIConfirmPasswordChangeHost[] = "confirm-password-change";
const char kChromeUIConfirmPasswordChangeUrl[] = const char kChromeUIConfirmPasswordChangeUrl[] =
"chrome://confirm-password-change"; "chrome://confirm-password-change";
const char kChromeUICrostiniInstallerHost[] = "crostini-installer"; const char kChromeUICrostiniInstallerHost[] = "crostini-installer";
const char kChromeUICrostiniInstallerUrl[] = "chrome://crostini-installer";
const char kChromeUICryptohomeHost[] = "cryptohome"; const char kChromeUICryptohomeHost[] = "cryptohome";
const char kChromeUIDeviceEmulatorHost[] = "device-emulator"; const char kChromeUIDeviceEmulatorHost[] = "device-emulator";
const char kChromeUIDiscoverURL[] = "chrome://oobe/discover"; const char kChromeUIDiscoverURL[] = "chrome://oobe/discover";
......
...@@ -211,6 +211,7 @@ extern const char kChromeUICertificateManagerHost[]; ...@@ -211,6 +211,7 @@ extern const char kChromeUICertificateManagerHost[];
extern const char kChromeUIConfirmPasswordChangeHost[]; extern const char kChromeUIConfirmPasswordChangeHost[];
extern const char kChromeUIConfirmPasswordChangeUrl[]; extern const char kChromeUIConfirmPasswordChangeUrl[];
extern const char kChromeUICrostiniInstallerHost[]; extern const char kChromeUICrostiniInstallerHost[];
extern const char kChromeUICrostiniInstallerUrl[];
extern const char kChromeUICryptohomeHost[]; extern const char kChromeUICryptohomeHost[];
extern const char kChromeUIDeviceEmulatorHost[]; extern const char kChromeUIDeviceEmulatorHost[];
extern const char kChromeUIDiscoverURL[]; extern const char kChromeUIDiscoverURL[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment