提交 d679a524 编写于 作者: H Hans Muller

Added ServiceRegistry interface

ServiceRegistry enables a chain of Mojo applications to accumulate
services without wrapping and forwarding the incoming ServiceProvider
request.

Sky's DocumentView adds ViewManagerClient to the ServiceRegistry (if any)
that's provided to it via ConnectToApplication(). Sky applications can add
additional services with embedder.serviceRegistry.addServices().

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/958673002
上级 4b60c287
......@@ -8,27 +8,26 @@ import "mojo:bindings" as bindings;
import "mojo:core" as core;
import "package:mojo/public/interfaces/application/service_provider.mojom.dart";
import "package:mojo/public/interfaces/application/shell.mojom.dart";
import "package:services/service_registry/service_registry.mojom.dart";
final _EmbedderImpl embedder = new _EmbedderImpl();
class _EmbedderImpl {
ApplicationConnection _connection;
ServiceRegistry _serviceRegistry;
final ShellProxy shell = new ShellProxy.fromHandle(
new core.MojoHandle(internals.takeShellProxyHandle()));
ApplicationConnection get connection {
if (_connection == null) {
var stubHandle = new core.MojoHandle(
internals.takeServicesProvidedToEmbedder());
var proxyHandle = new core.MojoHandle(
internals.takeServicesProvidedByEmbedder());
var stubHandle =
new core.MojoHandle(internals.takeServicesProvidedToEmbedder());
var proxyHandle =
new core.MojoHandle(internals.takeServicesProvidedByEmbedder());
_connection = new ApplicationConection(
stubHandle.isValid ? ServiceProviderStub.fromHandle(stubHandle)
: null;
proxyHandle.isValid ? ServiceProviderProxy.fromHandle(proxyHandle)
: null;
);
stubHandle.isValid ? new ServiceProviderStub.fromHandle(stubHandle) : null,
proxyHandle.isValid ? new ServiceProviderProxy.fromHandle(proxyHandle) : null);
}
return _connection;
}
......@@ -48,5 +47,14 @@ class _EmbedderImpl {
appSp.ptr.connectToService(proxy.name, pipe.endpoints[1]);
appSp.close();
}
ServiceRegistryProxy get serviceRegistry {
if (_serviceRegistry == null) {
_serviceRegistry = new ServiceRegistryProxy.fromHandle(
new core.MojoHandle(internals.takeServiceRegistry()));
}
return _serviceRegistry;
}
}
......@@ -46,6 +46,7 @@ mojo_native_application("viewer") {
"//mojo/services/network/public/interfaces",
"//mojo/services/surfaces/public/interfaces",
"//mojo/services/view_manager/public/cpp",
"//services/service_registry:bindings",
"//skia",
"//sky/compositor",
"//sky/engine",
......
......@@ -103,6 +103,7 @@ DocumentView::DocumentView(
mojo::Shell* shell)
: response_(response.Pass()),
exported_services_(services.Pass()),
imported_services_(exported_services.Pass()),
shell_(shell),
web_view_(nullptr),
root_(nullptr),
......@@ -110,6 +111,7 @@ DocumentView::DocumentView(
bitmap_rasterizer_(nullptr),
weak_factory_(this) {
exported_services_.AddService(&view_manager_client_factory_);
InitServiceRegistry();
}
DocumentView::~DocumentView() {
......@@ -194,6 +196,10 @@ mojo::ScopedMessagePipeHandle DocumentView::TakeServicesProvidedByEmbedder() {
return services_provided_by_embedder_.PassMessagePipe();
}
mojo::ScopedMessagePipeHandle DocumentView::TakeServiceRegistry() {
return service_registry_.PassMessagePipe();
}
mojo::Shell* DocumentView::GetShell() {
return shell_;
}
......@@ -360,4 +366,16 @@ void DocumentView::StartDebuggerInspectorBackend() {
// FIXME: Do we need this for dart?
}
void DocumentView::InitServiceRegistry() {
mojo::ConnectToService(imported_services_.get(), &service_registry_);
mojo::Array<mojo::String> interface_names(1);
interface_names[0] = "ViewManagerClient";
mojo::ServiceProviderImpl* sp_impl(new mojo::ServiceProviderImpl());
sp_impl->AddService(&view_manager_client_factory_);
mojo::ServiceProviderPtr sp;
service_registry_service_provider_binding_.reset(
new mojo::StrongBinding<mojo::ServiceProvider>(sp_impl, &sp));
service_registry_->AddServices(interface_names.Pass(), sp.Pass());
}
} // namespace sky
......@@ -10,6 +10,7 @@
#include "mojo/public/cpp/application/lazy_interface_ptr.h"
#include "mojo/public/cpp/application/service_provider_impl.h"
#include "mojo/public/cpp/bindings/interface_impl.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/interfaces/application/application.mojom.h"
#include "mojo/services/content_handler/public/interfaces/content_handler.mojom.h"
#include "mojo/services/navigation/public/interfaces/navigation.mojom.h"
......@@ -17,6 +18,7 @@
#include "mojo/services/view_manager/public/cpp/view_manager_client_factory.h"
#include "mojo/services/view_manager/public/cpp/view_manager_delegate.h"
#include "mojo/services/view_manager/public/cpp/view_observer.h"
#include "services/service_registry/service_registry.mojom.h"
#include "sky/compositor/layer_client.h"
#include "sky/compositor/layer_host_client.h"
#include "sky/engine/public/platform/ServiceProvider.h"
......@@ -71,6 +73,7 @@ class DocumentView : public blink::ServiceProvider,
TestHarnessPtr TakeTestHarness();
mojo::ScopedMessagePipeHandle TakeServicesProvidedToEmbedder();
mojo::ScopedMessagePipeHandle TakeServicesProvidedByEmbedder();
mojo::ScopedMessagePipeHandle TakeServiceRegistry();
private:
// WebViewClient methods:
......@@ -122,8 +125,11 @@ class DocumentView : public blink::ServiceProvider,
void UpdateRootSizeAndViewportMetrics(const mojo::Rect& new_bounds);
void InitServiceRegistry();
mojo::URLResponsePtr response_;
mojo::ServiceProviderImpl exported_services_;
mojo::ServiceProviderPtr imported_services_;
mojo::InterfaceRequest<mojo::ServiceProvider> services_provided_to_embedder_;
mojo::ServiceProviderPtr services_provided_by_embedder_;
mojo::Shell* shell_;
......@@ -135,7 +141,9 @@ class DocumentView : public blink::ServiceProvider,
scoped_ptr<LayerHost> layer_host_;
scoped_refptr<Layer> root_layer_;
RasterizerBitmap* bitmap_rasterizer_; // Used for pixel tests.
service_registry::ServiceRegistryPtr service_registry_;
scoped_ptr<mojo::StrongBinding<mojo::ServiceProvider>>
service_registry_service_provider_binding_;
base::WeakPtrFactory<DocumentView> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DocumentView);
......
......@@ -59,6 +59,11 @@ void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) {
args, GetInternals()->TakeServicesProvidedToEmbedder().value());
}
void TakeServiceRegistry(Dart_NativeArguments args) {
Dart_SetIntegerReturnValue(
args, GetInternals()->TakeServiceRegistry().value());
}
const DartBuiltin::Natives kNativeFunctions[] = {
{"contentAsText", ContentAsText, 0},
{"notifyTestComplete", NotifyTestComplete, 1},
......@@ -66,6 +71,7 @@ const DartBuiltin::Natives kNativeFunctions[] = {
{"takeShellProxyHandle", TakeShellProxyHandle, 0},
{"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0},
{"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0},
{"takeServiceRegistry", TakeServiceRegistry, 0},
};
const DartBuiltin& GetBuiltin() {
......@@ -92,6 +98,7 @@ String renderTreeAsText() native "renderTreeAsText";
int takeShellProxyHandle() native "takeShellProxyHandle";
int takeServicesProvidedByEmbedder() native "takeServicesProvidedByEmbedder";
int takeServicesProvidedToEmbedder() native "takeServicesProvidedToEmbedder";
int takeServiceRegistry() native "takeServiceRegistry";
)DART";
} // namespace
......@@ -152,6 +159,12 @@ mojo::Handle Internals::TakeServicesProvidedByEmbedder() {
return document_view_->TakeServicesProvidedByEmbedder().release();
}
mojo::Handle Internals::TakeServiceRegistry() {
if (!document_view_)
return mojo::Handle();
return document_view_->TakeServiceRegistry().release();
}
// Returns a MessagePipe handle that's connected to this Shell. The caller
// owns the handle and is expected to use it to create the JS Application for
// the DocumentView.
......
......@@ -34,6 +34,7 @@ class Internals : public base::SupportsUserData::Data,
mojo::Handle TakeShellProxyHandle();
mojo::Handle TakeServicesProvidedToEmbedder();
mojo::Handle TakeServicesProvidedByEmbedder();
mojo::Handle TakeServiceRegistry();
void pauseAnimations(double pauseTime);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册