Sergey Ulanov | d283ff9 | 2023-03-03 20:59:47 | [diff] [blame] | 1 | // 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 Ulanov | b4b2405 | 2023-03-06 23:58:42 | [diff] [blame] | 9 | #include "base/fuchsia/fuchsia_logging.h" |
Sergey Ulanov | d283ff9 | 2023-03-03 20:59:47 | [diff] [blame] | 10 | #include "base/fuchsia/process_context.h" |
| 11 | #include "base/functional/bind.h" |
| 12 | #include "base/functional/callback_helpers.h" |
Sergey Ulanov | b4b2405 | 2023-03-06 23:58:42 | [diff] [blame] | 13 | #include "base/location.h" |
Sergey Ulanov | d283ff9 | 2023-03-03 20:59:47 | [diff] [blame] | 14 | #include "ui/platform_window/fuchsia/initialize_presenter_api_view.h" |
| 15 | |
| 16 | namespace content { |
| 17 | |
| 18 | FuchsiaViewPresenter::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 Ulanov | b4b2405 | 2023-03-06 23:58:42 | [diff] [blame] | 27 | graphical_presenter_.set_error_handler(base::LogFidlErrorAndExitProcess( |
| 28 | FROM_HERE, "fuchsia.element.GraphicalPresenter")); |
Sergey Ulanov | d283ff9 | 2023-03-03 20:59:47 | [diff] [blame] | 29 | |
Sergey Ulanov | d283ff9 | 2023-03-03 20:59:47 | [diff] [blame] | 30 | ui::fuchsia::SetFlatlandViewPresenter(base::BindRepeating( |
| 31 | &FuchsiaViewPresenter::PresentFlatlandView, base::Unretained(this))); |
| 32 | callbacks_were_set_ = true; |
| 33 | } |
| 34 | |
| 35 | FuchsiaViewPresenter::~FuchsiaViewPresenter() { |
| 36 | if (callbacks_were_set_) { |
Sergey Ulanov | d283ff9 | 2023-03-03 20:59:47 | [diff] [blame] | 37 | ui::fuchsia::SetFlatlandViewPresenter(base::NullCallback()); |
| 38 | } |
| 39 | } |
| 40 | |
Sergey Ulanov | d283ff9 | 2023-03-03 20:59:47 | [diff] [blame] | 41 | fuchsia::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 |