From 77f873c1a4335aeadeec65ee30cd87b64fe8790d Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 16 Nov 2015 12:56:08 -0800 Subject: [PATCH] Wire in Mojo services to sky_shell.mojo After this patch, code running in sky_shell.mojo has access to Mojo services. --- sky/shell/platform/mojo/platform_view_mojo.cc | 13 ++++++--- sky/shell/platform/mojo/platform_view_mojo.h | 5 ++-- .../platform/mojo/sky_application_impl.cc | 27 ++++++++++++------- .../platform/mojo/sky_application_impl.h | 21 +++++++++------ sky/shell/ui/internals.cc | 7 ++++- sky/shell/ui/internals.h | 1 + 6 files changed, 50 insertions(+), 24 deletions(-) diff --git a/sky/shell/platform/mojo/platform_view_mojo.cc b/sky/shell/platform/mojo/platform_view_mojo.cc index 6c91db58706..5c23f3ab6a3 100644 --- a/sky/shell/platform/mojo/platform_view_mojo.cc +++ b/sky/shell/platform/mojo/platform_view_mojo.cc @@ -7,6 +7,7 @@ #include "base/bind.h" #include "base/location.h" #include "base/single_thread_task_runner.h" +#include "mojo/public/cpp/application/connect.h" #include "sky/shell/gpu/mojo/rasterizer_mojo.h" namespace sky { @@ -23,8 +24,9 @@ PlatformViewMojo::PlatformViewMojo(const Config& config) PlatformViewMojo::~PlatformViewMojo() { } -void PlatformViewMojo::Init(mojo::ApplicationImpl* app) { - app->ConnectToService("mojo:native_viewport_service", &viewport_); +void PlatformViewMojo::Init(mojo::ShellPtr shell) { + mojo::ConnectToService( + shell.get(), "mojo:native_viewport_service", &viewport_); mojo::NativeViewportEventDispatcherPtr ptr; dispatcher_binding_.Bind(GetProxy(&ptr)); @@ -53,11 +55,16 @@ void PlatformViewMojo::Init(mojo::ApplicationImpl* app) { config_.ui_delegate, base::Bind(&RasterizerMojo::OnContextProviderAvailable, rasterizer->GetWeakPtr(), base::Passed(&context_provider_info)))); + + ConnectToEngine(mojo::GetProxy(&sky_engine_)); + + ServicesDataPtr services = ServicesData::New(); + services->shell = shell.Pass(); + sky_engine_->SetServices(services.Pass()); } void PlatformViewMojo::Run(const mojo::String& url, mojo::asset_bundle::AssetBundlePtr bundle) { - ConnectToEngine(mojo::GetProxy(&sky_engine_)); sky_engine_->RunFromAssetBundle(url, bundle.Pass()); } diff --git a/sky/shell/platform/mojo/platform_view_mojo.h b/sky/shell/platform/mojo/platform_view_mojo.h index 9f4920fe76f..15d09956274 100644 --- a/sky/shell/platform/mojo/platform_view_mojo.h +++ b/sky/shell/platform/mojo/platform_view_mojo.h @@ -5,8 +5,9 @@ #ifndef SKY_SHELL_PLATFORM_MOJO_PLATFORM_VIEW_MOJO_H_ #define SKY_SHELL_PLATFORM_MOJO_PLATFORM_VIEW_MOJO_H_ -#include "mojo/public/cpp/application/application_impl.h" +#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/interfaces/application/service_provider.mojom.h" +#include "mojo/public/interfaces/application/shell.mojom.h" #include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h" #include "mojo/services/native_viewport/interfaces/native_viewport.mojom.h" #include "sky/shell/platform_view.h" @@ -20,7 +21,7 @@ class PlatformViewMojo : public PlatformView, explicit PlatformViewMojo(const Config& config); ~PlatformViewMojo() override; - void Init(mojo::ApplicationImpl* app); + void Init(mojo::ShellPtr shell); void Run(const mojo::String& url, mojo::asset_bundle::AssetBundlePtr bundle); diff --git a/sky/shell/platform/mojo/sky_application_impl.cc b/sky/shell/platform/mojo/sky_application_impl.cc index 676e29e0235..7fb49ba54d5 100644 --- a/sky/shell/platform/mojo/sky_application_impl.cc +++ b/sky/shell/platform/mojo/sky_application_impl.cc @@ -14,32 +14,39 @@ namespace shell { SkyApplicationImpl::SkyApplicationImpl( mojo::InterfaceRequest application, mojo::URLResponsePtr response) - : app_(this, application.Pass()), + : binding_(this, application.Pass()), initial_response_(response.Pass()) { } SkyApplicationImpl::~SkyApplicationImpl() { } -void SkyApplicationImpl::Initialize(mojo::ApplicationImpl* app) { +void SkyApplicationImpl::Initialize(mojo::ShellPtr shell, + mojo::Array args, + const mojo::String& url) { DCHECK(initial_response_); - UnpackInitialResponse(); + UnpackInitialResponse(shell.get()); shell_view_.reset(new ShellView(Shell::Shared())); PlatformViewMojo* view = platform_view(); - view->Init(app); - view->Run(app_.url(), bundle_.Pass()); + view->Init(shell.Pass()); + view->Run(url, bundle_.Pass()); } -bool SkyApplicationImpl::ConfigureIncomingConnection( - mojo::ApplicationConnection* connection) { - return true; +void SkyApplicationImpl::AcceptConnection( + const mojo::String& requestor_url, + mojo::InterfaceRequest services, + mojo::ServiceProviderPtr exposed_services, + const mojo::String& resolved_url) { } -void SkyApplicationImpl::UnpackInitialResponse() { +void SkyApplicationImpl::RequestQuit() { +} + +void SkyApplicationImpl::UnpackInitialResponse(mojo::Shell* shell) { DCHECK(initial_response_); DCHECK(!bundle_); mojo::asset_bundle::AssetUnpackerPtr unpacker; - app_.ConnectToService("mojo:asset_bundle", &unpacker); + mojo::ConnectToService(shell, "mojo:asset_bundle", &unpacker); unpacker->UnpackZipStream(initial_response_->body.Pass(), mojo::GetProxy(&bundle_)); initial_response_ = nullptr; diff --git a/sky/shell/platform/mojo/sky_application_impl.h b/sky/shell/platform/mojo/sky_application_impl.h index 66d2ad310b8..1b6e24a778d 100644 --- a/sky/shell/platform/mojo/sky_application_impl.h +++ b/sky/shell/platform/mojo/sky_application_impl.h @@ -6,8 +6,8 @@ #define SKY_SHELL_PLATFORM_MOJO_SKY_APPLICATION_IMPL_H_ #include "base/message_loop/message_loop.h" -#include "mojo/public/cpp/application/application_impl.h" #include "mojo/public/cpp/bindings/strong_binding.h" +#include "mojo/public/interfaces/application/application.mojom.h" #include "mojo/public/interfaces/application/shell.mojom.h" #include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h" #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" @@ -17,25 +17,30 @@ namespace sky { namespace shell { -class SkyApplicationImpl : public mojo::ApplicationDelegate { +class SkyApplicationImpl : public mojo::Application { public: SkyApplicationImpl(mojo::InterfaceRequest application, mojo::URLResponsePtr response); ~SkyApplicationImpl() override; private: - // mojo::ApplicationDelegate - void Initialize(mojo::ApplicationImpl* app) override; - bool ConfigureIncomingConnection( - mojo::ApplicationConnection* connection) override; + // mojo::Application + void Initialize(mojo::ShellPtr shell, + mojo::Array args, + const mojo::String& url) override; + void AcceptConnection(const mojo::String& requestor_url, + mojo::InterfaceRequest services, + mojo::ServiceProviderPtr exposed_services, + const mojo::String& resolved_url) override; + void RequestQuit() override; PlatformViewMojo* platform_view() { return static_cast(shell_view_->view()); } - void UnpackInitialResponse(); + void UnpackInitialResponse(mojo::Shell* shell); - mojo::ApplicationImpl app_; + mojo::StrongBinding binding_; mojo::URLResponsePtr initial_response_; mojo::asset_bundle::AssetBundlePtr bundle_; scoped_ptr shell_view_; diff --git a/sky/shell/ui/internals.cc b/sky/shell/ui/internals.cc index 24fe7f233a8..02d859b47d9 100644 --- a/sky/shell/ui/internals.cc +++ b/sky/shell/ui/internals.cc @@ -32,7 +32,8 @@ void TakeRootBundleHandle(Dart_NativeArguments args) { } void TakeShellProxyHandle(Dart_NativeArguments args) { - Dart_SetIntegerReturnValue(args, 0); + Dart_SetIntegerReturnValue( + args, GetInternals()->TakeShellProxy().value()); } void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) { @@ -117,6 +118,10 @@ void Internals::Create( request.Pass(), base::WorkerPool::GetTaskRunner(true)); } +mojo::Handle Internals::TakeShellProxy() { + return services_ ? services_->shell.PassInterface().PassHandle().release() : mojo::Handle(); +} + mojo::Handle Internals::TakeServicesProvidedByEmbedder() { return service_provider_.PassInterface().PassHandle().release(); } diff --git a/sky/shell/ui/internals.h b/sky/shell/ui/internals.h index db2e1c61167..24a65fbafd7 100644 --- a/sky/shell/ui/internals.h +++ b/sky/shell/ui/internals.h @@ -30,6 +30,7 @@ class Internals ServicesDataPtr services, mojo::asset_bundle::AssetBundlePtr root_bundle); + mojo::Handle TakeShellProxy(); mojo::Handle TakeServicesProvidedByEmbedder(); mojo::Handle TakeRootBundleHandle(); mojo::Handle TakeServicesProvidedToEmbedder();