Commit 6e4ece71 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Prepare webrunner for ViewsV2 migration.

The old fuchsia.ui.viewsv1 API is being replaced with views support
in Scenic. This CL prepares chromium for that migration:
1. Adds implementation of fuchsia.app.ViewFactory in WebComponent.
   fuchsia.viewsv1.ViewFactory will be removed in the future after
   it's removed and all consumers are updated.
2. Added CreateView2() method in the chromium.web.Frame interface.
   It is compatible with ViewsV2 and will replace the old
   CreateView().
3. Updated content_shell and ozone_demo to use Presenter::Present2(),
   which is compatible with ViewsV2.

Bug: 899348
Change-Id: I82d066cdd60dc06cf598f336a40cca4584d1e3bb
Reviewed-on: https://chromium-review.googlesource.com/c/1311123
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605203}
parent f176a641
......@@ -24,7 +24,9 @@
#if defined(OS_FUCHSIA)
#include <fuchsia/ui/policy/cpp/fidl.h>
#include <lib/zx/eventpair.h>
#include "base/fuchsia/component_context.h"
#include "base/fuchsia/fuchsia_logging.h"
#endif
#if defined(USE_OZONE)
......@@ -108,19 +110,22 @@ ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) {
properties.bounds = gfx::Rect(initial_size);
#if defined(OS_FUCHSIA)
// When using Scenic Ozone platform we need to supply a ViewOwner request to
// the window. This is not necessary when using the headless ozone platform.
// When using Scenic Ozone platform we need to supply a view_token to the
// window. This is not necessary when using the headless ozone platform.
if (ui::OzonePlatform::GetInstance()
->GetPlatformProperties()
.needs_view_owner_request) {
// Initialize view_owner_request for the new instance.
fidl::InterfaceHandle<fuchsia::ui::viewsv1token::ViewOwner> view_owner;
properties.view_owner_request = view_owner.NewRequest();
.needs_view_token) {
// Create view_token and view_holder_token.
zx::eventpair view_holder_token;
zx_status_t status = zx::eventpair::create(
/*options=*/0, &properties.view_token, &view_holder_token);
ZX_CHECK(status == ZX_OK, status) << "zx_eventpair_create";
// Request Presenter to show the view full-screen.
auto presenter = base::fuchsia::ComponentContext::GetDefault()
->ConnectToService<fuchsia::ui::policy::Presenter>();
presenter->Present(std::move(view_owner), nullptr);
presenter->Present2(std::move(view_holder_token), nullptr);
}
#endif
......
......@@ -16,7 +16,9 @@
#if defined(OS_FUCHSIA)
#include <fuchsia/ui/policy/cpp/fidl.h>
#include <lib/zx/eventpair.h>
#include "base/fuchsia/component_context.h"
#include "base/fuchsia/fuchsia_logging.h"
#endif
namespace ui {
......@@ -31,19 +33,22 @@ DemoWindow::DemoWindow(WindowManager* window_manager,
properties.bounds = bounds;
#if defined(OS_FUCHSIA)
// When using Scenic Ozone platform we need to supply a ViewOwner request to
// the window. This is not necessary when using the headless ozone platform.
// When using Scenic Ozone platform we need to supply a view_token to the
// window. This is not necessary when using the headless ozone platform.
if (ui::OzonePlatform::GetInstance()
->GetPlatformProperties()
.needs_view_owner_request) {
// Initialize view_owner_request for the new instance.
fidl::InterfaceHandle<fuchsia::ui::viewsv1token::ViewOwner> view_owner;
properties.view_owner_request = view_owner.NewRequest();
.needs_view_token) {
// Create view_token and view_holder_token.
zx::eventpair view_holder_token;
zx_status_t status = zx::eventpair::create(
/*options=*/0, &properties.view_token, &view_holder_token);
ZX_CHECK(status == ZX_OK, status) << "zx_eventpair_create";
// Request Presenter to show the view full-screen.
auto presenter = base::fuchsia::ComponentContext::GetDefault()
->ConnectToService<fuchsia::ui::policy::Presenter>();
presenter->Present(std::move(view_owner), nullptr);
presenter->Present2(std::move(view_holder_token), nullptr);
}
#endif
......
......@@ -89,13 +89,12 @@ class OzonePlatformScenic
std::unique_ptr<PlatformWindow> CreatePlatformWindow(
PlatformWindowDelegate* delegate,
PlatformWindowInitProperties properties) override {
if (!properties.view_owner_request) {
if (!properties.view_token) {
NOTREACHED();
return nullptr;
}
return std::make_unique<ScenicWindow>(
window_manager_.get(), delegate,
std::move(properties.view_owner_request));
return std::make_unique<ScenicWindow>(window_manager_.get(), delegate,
std::move(properties.view_token));
}
const PlatformProperties& GetPlatformProperties() override {
......
......@@ -22,11 +22,9 @@
namespace ui {
ScenicWindow::ScenicWindow(
ScenicWindowManager* window_manager,
PlatformWindowDelegate* delegate,
fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner>
view_owner_request)
ScenicWindow::ScenicWindow(ScenicWindowManager* window_manager,
PlatformWindowDelegate* delegate,
zx::eventpair view_token)
: manager_(window_manager),
delegate_(delegate),
window_id_(manager_->AddWindow(this)),
......@@ -57,8 +55,8 @@ ScenicWindow::ScenicWindow(
parent_node_.SetEventMask(fuchsia::ui::gfx::kMetricsEventMask);
// Create the view.
manager_->GetViewManager()->CreateView(
view_.NewRequest(), std::move(view_owner_request),
manager_->GetViewManager()->CreateView2(
view_.NewRequest(), std::move(view_token),
view_listener_binding_.NewBinding(), std::move(parent_export_token),
"Chromium");
view_.set_error_handler(fit::bind_member(this, &ScenicWindow::OnViewError));
......
......@@ -33,13 +33,10 @@ class OZONE_EXPORT ScenicWindow : public PlatformWindow,
public InputEventDispatcherDelegate {
public:
// Both |window_manager| and |delegate| must outlive the ScenicWindow.
// |view_owner_request| is passed to the view managed when creating the
// underlying view. In order for the View to be displayed the ViewOwner must
// be used to add the view to a ViewContainer.
// |view_token| is passed to Scenic to attach the view to the view tree.
ScenicWindow(ScenicWindowManager* window_manager,
PlatformWindowDelegate* delegate,
fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner>
view_owner_request);
zx::eventpair view_token);
~ScenicWindow() override;
scenic::Session* scenic_session() { return &scenic_session_; }
......
......@@ -33,7 +33,8 @@ fuchsia::ui::viewsv1::ViewManager* ScenicWindowManager::GetViewManager() {
fuchsia::ui::scenic::Scenic* ScenicWindowManager::GetScenic() {
if (!scenic_) {
GetViewManager()->GetScenic(scenic_.NewRequest());
scenic_ = base::fuchsia::ComponentContext::GetDefault()
->ConnectToService<fuchsia::ui::scenic::Scenic>();
scenic_.set_error_handler([]() {
LOG(ERROR) << "The Scenic channel was unexpectedly terminated.";
});
......
......@@ -38,12 +38,12 @@ base::Lock& GetOzoneInstanceLock() {
OzonePlatform::PlatformProperties::PlatformProperties() = default;
OzonePlatform::PlatformProperties::PlatformProperties(
bool needs_request,
bool needs_view_token,
bool custom_frame_default,
bool can_use_system_title_bar,
bool requires_mojo_for_ipc,
std::vector<gfx::BufferFormat> buffer_formats)
: needs_view_owner_request(needs_request),
: needs_view_token(needs_view_token),
custom_frame_pref_default(custom_frame_default),
use_system_title_bar(can_use_system_title_bar),
requires_mojo(requires_mojo_for_ipc),
......
......@@ -96,10 +96,9 @@ class OZONE_EXPORT OzonePlatform {
~PlatformProperties();
PlatformProperties(const PlatformProperties& other);
// Fuchsia only: set to true when the platforms requires
// |view_owner_request| field in PlatformWindowInitProperties when creating
// a window.
bool needs_view_owner_request = false;
// Fuchsia only: set to true when the platforms requires |view_token| field
// in PlatformWindowInitProperties when creating a window.
bool needs_view_token = false;
// Determine whether we should default to native decorations or the custom
// frame based on the currently-running window manager.
......
......@@ -24,7 +24,7 @@ source_set("platform_window") {
if (is_fuchsia) {
public_deps = [
"//third_party/fuchsia-sdk/sdk:viewsv1token",
"//third_party/fuchsia-sdk/sdk:zx",
]
}
}
......
......@@ -12,7 +12,7 @@
#include "ui/gfx/native_widget_types.h"
#if defined(OS_FUCHSIA)
#include <fuchsia/ui/viewsv1token/cpp/fidl.h>
#include <lib/zx/eventpair.h>
#endif
namespace ui {
......@@ -45,8 +45,7 @@ struct PlatformWindowInitProperties {
gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget;
#if defined(OS_FUCHSIA)
fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner>
view_owner_request;
zx::eventpair view_token;
#endif
};
......
......@@ -71,6 +71,8 @@ source_set("webrunner_common") {
deps = [
":web_fidl",
"//base",
"//third_party/fuchsia-sdk/sdk:app",
"//third_party/fuchsia-sdk/sdk:viewsv1",
"//url",
]
}
......@@ -284,7 +286,7 @@ fidl_library("web_fidl") {
public_deps = [
"//third_party/fuchsia-sdk/sdk:gfx",
"//third_party/fuchsia-sdk/sdk:sys",
"//third_party/fuchsia-sdk/sdk:viewsv1",
"//third_party/fuchsia-sdk/sdk:viewsv1token",
]
}
......
......@@ -81,15 +81,28 @@ void WebComponent::Detach() {
}
void WebComponent::CreateView(
fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner> view_owner,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services) {
zx::eventpair view_token,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> incoming_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> outgoing_services) {
DCHECK(frame_);
DCHECK(!view_is_bound_);
frame_->CreateView(std::move(view_owner), std::move(services));
frame_->CreateView2(std::move(view_token), std::move(incoming_services),
std::move(outgoing_services));
view_is_bound_ = true;
}
void WebComponent::CreateView(
fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner> view_owner,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services) {
// Cast the ViewOwner request to view_token. This is temporary hack for
// ViewsV2 transition. This version of CreateView() will be removed in the
// future.
CreateView(zx::eventpair(view_owner.TakeChannel().release()),
std::move(services), nullptr);
}
void WebComponent::DestroyComponent(int termination_exit_code,
fuchsia::sys::TerminationReason reason) {
termination_reason_ = reason;
......
......@@ -6,6 +6,7 @@
#define WEBRUNNER_APP_COMMON_WEB_COMPONENT_H_
#include <fuchsia/sys/cpp/fidl.h>
#include <fuchsia/ui/app/cpp/fidl.h>
#include <fuchsia/ui/viewsv1/cpp/fidl.h>
#include <lib/fidl/cpp/binding.h>
#include <lib/fidl/cpp/binding_set.h>
......@@ -28,7 +29,9 @@ class WebContentRunner;
// resources and service bindings. Runners for specialized web-based content
// (e.g. Cast applications) can extend this class to configure the Frame to
// their needs, publish additional APIs, etc.
// TODO(crbug.com/899348): Remove fuchsia::ui::viewsv1::ViewProvider.
class WebComponent : public fuchsia::sys::ComponentController,
public fuchsia::ui::app::ViewProvider,
public fuchsia::ui::viewsv1::ViewProvider {
public:
~WebComponent() override;
......@@ -56,12 +59,18 @@ class WebComponent : public fuchsia::sys::ComponentController,
void Kill() override;
void Detach() override;
// fuchsia::ui::viewsv1::ViewProvider implementation.
// fuchsia::ui::app::ViewProvider implementation.
void CreateView(
fidl::InterfaceRequest<::fuchsia::ui::viewsv1token::ViewOwner> view_owner,
fidl::InterfaceRequest<::fuchsia::sys::ServiceProvider> services)
zx::eventpair view_token,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> incoming_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> outgoing_services)
override;
// fuchsia::ui::viewsv1::ViewProvider implementation.
void CreateView(
fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner> view_owner,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services) override;
// Reports the supplied exit-code and reason to the |controller_binding_| and
// requests that the |runner_| delete this component.
void DestroyComponent(int termination_exit_code,
......
......@@ -208,8 +208,17 @@ bool FrameImpl::ShouldCreateWebContents(
void FrameImpl::CreateView(
fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner> view_owner,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services) {
// Cast |view_owner| request to a eventpair.
CreateView2(zx::eventpair(view_owner.TakeChannel().release()),
std::move(services), nullptr);
}
void FrameImpl::CreateView2(
zx::eventpair view_token,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> incoming_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> outgoing_services) {
ui::PlatformWindowInitProperties properties;
properties.view_owner_request = std::move(view_owner);
properties.view_token = std::move(view_token);
window_tree_host_ =
std::make_unique<aura::WindowTreeHostPlatform>(std::move(properties));
......
......@@ -54,6 +54,11 @@ class FrameImpl : public chromium::web::Frame,
void CreateView(
fidl::InterfaceRequest<fuchsia::ui::viewsv1token::ViewOwner> view_owner,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services) override;
void CreateView2(
zx::eventpair view_token,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> incoming_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> outgoing_services)
override;
void GetNavigationController(
fidl::InterfaceRequest<chromium::web::NavigationController> controller)
override;
......
......@@ -14,12 +14,18 @@ enum ExecuteMode {
};
interface Frame {
// Creates and registers a view with the view manager and returns its
// view owner which may subsequently be passed to |View.AddChild()|
// to attach the view to a view hierarchy.
// Creates a new view using the specified |view_token|. Caller should pass the
// other end of the token to CreateViewHolderCmd() to attach the new view to a
// the view tree.
//
// |view_owner|: Request for the Frame's ViewOwner.
// |services|: Request for the Frame's View-related services.
// |view_token|: Token for the new view.
4: CreateView2(handle<eventpair> view_token,
request<fuchsia.sys.ServiceProvider>? incoming_services,
fuchsia.sys.ServiceProvider? outgoing_services);
// Deprecated.
// TODO(crbug.com/899348): Update all code to use CreateView2()
// and remove CreateView().
1: CreateView(request<fuchsia.ui.viewsv1token.ViewOwner> view_owner,
request<fuchsia.sys.ServiceProvider>? services);
......
......@@ -68,6 +68,12 @@ class FakeFrame : public chromium::web::Frame {
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> services) override {
}
void CreateView2(
zx::eventpair view_token,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> incoming_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> outgoing_services)
override {}
void GetNavigationController(
fidl::InterfaceRequest<chromium::web::NavigationController> controller)
override {}
......
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