diff options
Diffstat (limited to 'mojo/services/public/js')
-rw-r--r-- | mojo/services/public/js/application.js | 38 | ||||
-rw-r--r-- | mojo/services/public/js/service_provider.js | 26 | ||||
-rw-r--r-- | mojo/services/public/js/shell.js | 26 |
3 files changed, 47 insertions, 43 deletions
diff --git a/mojo/services/public/js/application.js b/mojo/services/public/js/application.js index ed41628..d4aa1e6 100644 --- a/mojo/services/public/js/application.js +++ b/mojo/services/public/js/application.js @@ -4,30 +4,41 @@ define("mojo/services/public/js/application", [ "mojo/public/js/bindings", + "mojo/public/js/core", + "mojo/public/js/connection", "mojo/public/js/threading", + "mojo/public/interfaces/application/application.mojom", "mojo/services/public/js/service_provider", "mojo/services/public/js/shell", -], function(bindings, threading, serviceProvider, shell) { +], function(bindings, core, connection, threading, applicationMojom, serviceProvider, shell) { + const ApplicationInterface = applicationMojom.Application; const ProxyBindings = bindings.ProxyBindings; const ServiceProvider = serviceProvider.ServiceProvider; const Shell = shell.Shell; class Application { - constructor(shellHandle, url) { + constructor(appRequestHandle, url) { this.url = url; this.serviceProviders = []; this.exposedServiceProviders = []; - this.shellHandle_ = shellHandle; - this.shell = new Shell(shellHandle, { - initialize: this.initialize.bind(this), - acceptConnection: this.doAcceptConnection.bind(this), - }); + this.appRequestHandle_ = appRequestHandle; + this.appStub_ = + connection.bindHandleToStub(appRequestHandle, ApplicationInterface); + bindings.StubBindings(this.appStub_).delegate = { + initialize: this.doInitialize.bind(this), + acceptConnection: this.doAcceptConnection.bind(this), + }; } - initialize(args) { + doInitialize(shellProxy, args) { + this.shellProxy_ = shellProxy; + this.shell = new Shell(shellProxy); + this.initialize(args); } + initialize(args) {} + // The mojom signature of this function is: // AcceptConnection(string requestor_url, // ServiceProvider&? services, @@ -39,23 +50,20 @@ define("mojo/services/public/js/application", [ doAcceptConnection(requestorUrl, servicesRequest, exposedServicesProxy) { // Construct a new js ServiceProvider that can make outgoing calls on // exposedServicesProxy. - var serviceProvider = new ServiceProvider(exposedServicesProxy); + var serviceProvider = + new ServiceProvider(servicesRequest, exposedServicesProxy); this.serviceProviders.push(serviceProvider); - - // Then associate incoming calls with the serviceProvider. - ProxyBindings(servicesRequest).setLocalDelegate(serviceProvider); - this.acceptConnection(requestorUrl, serviceProvider); } - acceptConnection(requestorUrl, serviceProvider) { - } + acceptConnection(requestorUrl, serviceProvider) {} quit() { this.serviceProviders.forEach(function(sp) { sp.close(); }); this.shell.close(); + core.close(this.appRequestHandle_); threading.quit(); } } diff --git a/mojo/services/public/js/service_provider.js b/mojo/services/public/js/service_provider.js index 9566583..a6a81ca 100644 --- a/mojo/services/public/js/service_provider.js +++ b/mojo/services/public/js/service_provider.js @@ -18,10 +18,12 @@ define("mojo/services/public/js/service_provider", [ } class ServiceProvider { - constructor(service) { - this.proxy = service; + constructor(servicesRequest, exposedServicesProxy) { + this.proxy = exposedServicesProxy; this.providers_ = new Map(); // serviceName => see provideService() below this.pendingRequests_ = new Map(); // serviceName => serviceHandle + if (servicesRequest) + StubBindings(servicesRequest).delegate = this; } // Incoming requests @@ -34,11 +36,10 @@ define("mojo/services/public/js/service_provider", [ this.pendingRequests_.set(serviceName, serviceHandle); return; } - var proxy = connection.bindProxyHandle( - serviceHandle, provider.service, provider.service.client); - if (ProxyBindings(proxy).local) - ProxyBindings(proxy).setLocalDelegate(new provider.factory(proxy)); - provider.connections.push(ProxyBindings(proxy).connection); + + var stub = connection.bindHandleToStub(serviceHandle, provider.service); + StubBindings(stub).delegate = new provider.factory(); + provider.connections.push(StubBindings(stub).connection); } provideService(service, factory) { @@ -66,12 +67,11 @@ define("mojo/services/public/js/service_provider", [ if (!clientImpl && interfaceObject.client) throw new Error("Client implementation must be provided"); - var remoteProxy; - var clientFactory = function(x) {remoteProxy = x; return clientImpl;}; - var messagePipeHandle = connection.bindProxyClient( - clientFactory, interfaceObject.client, interfaceObject); - this.proxy.connectToService(interfaceObject.name, messagePipeHandle); - return remoteProxy; + var serviceProxy; + var serviceHandle = connection.bindProxy( + function(sp) {serviceProxy = sp;}, interfaceObject); + this.proxy.connectToService(interfaceObject.name, serviceHandle); + return serviceProxy; }; close() { diff --git a/mojo/services/public/js/shell.js b/mojo/services/public/js/shell.js index 9fc8552..e6c2dee 100644 --- a/mojo/services/public/js/shell.js +++ b/mojo/services/public/js/shell.js @@ -8,8 +8,8 @@ define("mojo/services/public/js/shell", [ "mojo/public/js/connection", "mojo/public/interfaces/application/shell.mojom", "mojo/public/interfaces/application/service_provider.mojom", - "mojo/services/public/js/service_provider", -], function(bindings, core, connection, shellMojom, spMojom, sp) { + "mojo/services/public/js/service_provider","console", +], function(bindings, core, connection, shellMojom, spMojom, sp, console) { const ProxyBindings = bindings.ProxyBindings; const StubBindings = bindings.StubBindings; @@ -18,13 +18,8 @@ define("mojo/services/public/js/shell", [ const ShellInterface = shellMojom.Shell; class Shell { - constructor(shellHandle, app) { - this.shellHandle = shellHandle; - this.proxy = connection.bindProxyHandle( - shellHandle, ShellInterface.client, ShellInterface); - - ProxyBindings(this.proxy).setLocalDelegate(app); - // TODO: call this serviceProviders_ + constructor(shellProxy) { + this.shellProxy = shellProxy; this.applications_ = new Map(); } @@ -33,11 +28,12 @@ define("mojo/services/public/js/shell", [ if (application) return application; - this.proxy.connectToApplication(url, function(services) { - application = new ServiceProvider(services); - }, function() { - return application; - }); + var application = new ServiceProvider(); + this.shellProxy.connectToApplication(url, + function(services) { + application.proxy = services; + }, + application); this.applications_.set(url, application); return application; } @@ -50,8 +46,8 @@ define("mojo/services/public/js/shell", [ this.applications_.forEach(function(application, url) { application.close(); }); + ProxyBindings(this.shellProxy).close(); this.applications_.clear(); - core.close(this.shellHandle); } } |