1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
// Copyright 2019 The Chromium Authors
// 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_ASH_CROSTINI_UPGRADER_CROSTINI_UPGRADER_UI_H_
#define CHROME_BROWSER_UI_WEBUI_ASH_CROSTINI_UPGRADER_CROSTINI_UPGRADER_UI_H_
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/webui/ash/crostini_upgrader/crostini_upgrader.mojom.h"
#include "chrome/common/webui_url_constants.h"
#include "content/public/browser/webui_config.h"
#include "content/public/common/url_constants.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 ash {
class CrostiniUpgraderPageHandler;
class CrostiniUpgraderUI;
// WebUIConfig for chrome://crostini-upgrader
class CrostiniUpgraderUIConfig
: public content::DefaultWebUIConfig<CrostiniUpgraderUI> {
public:
CrostiniUpgraderUIConfig()
: DefaultWebUIConfig(content::kChromeUIScheme,
chrome::kChromeUICrostiniUpgraderHost) {}
};
// The WebUI for chrome://crostini-upgrader
class CrostiniUpgraderUI : public ui::MojoWebDialogUI,
public crostini_upgrader::mojom::PageHandlerFactory {
public:
explicit CrostiniUpgraderUI(content::WebUI* web_ui);
CrostiniUpgraderUI(const CrostiniUpgraderUI&) = delete;
CrostiniUpgraderUI& operator=(const CrostiniUpgraderUI&) = delete;
~CrostiniUpgraderUI() override;
// Send a close request to the web page. Return true if the page is already
// closed.
bool RequestClosePage();
void set_launch_callback(base::OnceCallback<void(bool)>(launch_callback)) {
launch_callback_ = std::move(launch_callback);
}
// Instantiates implementor of the
// crostini_upgrader::mojom::PageHandlerFactory mojo interface
// passing the pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<crostini_upgrader::mojom::PageHandlerFactory>
pending_receiver);
base::WeakPtr<CrostiniUpgraderUI> GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
private:
// crostini_upgrader::mojom::PageHandlerFactory:
void CreatePageHandler(
mojo::PendingRemote<crostini_upgrader::mojom::Page> pending_page,
mojo::PendingReceiver<crostini_upgrader::mojom::PageHandler>
pending_page_handler) override;
void OnPageClosed();
std::unique_ptr<CrostiniUpgraderPageHandler> page_handler_;
mojo::Receiver<crostini_upgrader::mojom::PageHandlerFactory>
page_factory_receiver_{this};
// Not owned. Passed to |page_handler_|
base::OnceCallback<void(bool)> launch_callback_;
bool page_closed_ = false;
base::WeakPtrFactory<CrostiniUpgraderUI> weak_ptr_factory_{this};
WEB_UI_CONTROLLER_TYPE_DECL();
};
} // namespace ash
#endif // CHROME_BROWSER_UI_WEBUI_ASH_CROSTINI_UPGRADER_CROSTINI_UPGRADER_UI_H_
|