blob: ca59f199f64fc896a01dbf8651f9c1c3b7d883b0 [file] [log] [blame]
Sergey Ulanovd283ff92023-03-03 20:59:471// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/shell/browser/fuchsia_view_presenter.h"
6
7#include <lib/sys/cpp/component_context.h>
8
Sergey Ulanovb4b24052023-03-06 23:58:429#include "base/fuchsia/fuchsia_logging.h"
Sergey Ulanovd283ff92023-03-03 20:59:4710#include "base/fuchsia/process_context.h"
11#include "base/functional/bind.h"
12#include "base/functional/callback_helpers.h"
Sergey Ulanovb4b24052023-03-06 23:58:4213#include "base/location.h"
Sergey Ulanovd283ff92023-03-03 20:59:4714#include "ui/platform_window/fuchsia/initialize_presenter_api_view.h"
15
16namespace content {
17
18FuchsiaViewPresenter::FuchsiaViewPresenter() {
19 // The presenter callbacks may be already set when running tests. In that case
20 // they don't need to be set again.
21 if (ui::fuchsia::GetFlatlandViewPresenter()) {
22 return;
23 }
24
25 base::ComponentContextForProcess()->svc()->Connect(
26 graphical_presenter_.NewRequest());
Sergey Ulanovb4b24052023-03-06 23:58:4227 graphical_presenter_.set_error_handler(base::LogFidlErrorAndExitProcess(
28 FROM_HERE, "fuchsia.element.GraphicalPresenter"));
Sergey Ulanovd283ff92023-03-03 20:59:4729
Sergey Ulanovd283ff92023-03-03 20:59:4730 ui::fuchsia::SetFlatlandViewPresenter(base::BindRepeating(
31 &FuchsiaViewPresenter::PresentFlatlandView, base::Unretained(this)));
32 callbacks_were_set_ = true;
33}
34
35FuchsiaViewPresenter::~FuchsiaViewPresenter() {
36 if (callbacks_were_set_) {
Sergey Ulanovd283ff92023-03-03 20:59:4737 ui::fuchsia::SetFlatlandViewPresenter(base::NullCallback());
38 }
39}
40
Sergey Ulanovd283ff92023-03-03 20:59:4741fuchsia::element::ViewControllerPtr FuchsiaViewPresenter::PresentFlatlandView(
42 fuchsia::ui::views::ViewportCreationToken viewport_creation_token) {
43 fuchsia::element::ViewControllerPtr view_controller;
44 fuchsia::element::ViewSpec view_spec;
45 view_spec.set_viewport_creation_token(std::move(viewport_creation_token));
46 graphical_presenter_->PresentView(std::move(view_spec), nullptr,
47 view_controller.NewRequest(),
48 [](auto result) {});
49 return view_controller;
50}
51
52} // namespace content