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