Add ICU message format support
[chromium-blink-merge.git] / third_party / mojo_services / src / public / js / shell.js
blobe8bab6f8b6470b56ac18c7492e0254ef17eb1c49
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 define("mojo/services/public/js/shell", [
6   "mojo/public/js/bindings",
7   "mojo/public/js/core",
8   "mojo/public/js/connection",
9   "mojo/public/interfaces/application/shell.mojom",
10   "mojo/public/interfaces/application/service_provider.mojom",
11   "mojo/services/public/js/service_exchange",
12 ], function(bindings, core, connection, shellMojom, spMojom, serviceExchange) {
14   const ProxyBindings = bindings.ProxyBindings;
15   const StubBindings = bindings.StubBindings;
16   const ServiceExchange = serviceExchange.ServiceExchange;
17   const ServiceProviderInterface = spMojom.ServiceProvider;
18   const ShellInterface = shellMojom.Shell;
20   class Shell {
21     constructor(shellProxy) {
22       this.shellProxy = shellProxy;
23       this.applications_ = new Map();
24     }
26     connectToApplication(url) {
27       var application = this.applications_.get(url);
28       if (application)
29         return application;
31       var application = new ServiceExchange();
32       this.shellProxy.connectToApplication(url,
33           function(servicesProxy) {
34             application.proxy = servicesProxy;
35           },
36           function(exposedServicesStub) {
37             application.stub = exposedServicesStub;
38             StubBindings(exposedServicesStub).delegate = application;
39           });
40       this.applications_.set(url, application);
41       return application;
42     }
44     connectToService(url, service) {
45       return this.connectToApplication(url).requestService(service);
46     };
48     close() {
49       this.applications_.forEach(function(application, url) {
50         application.close();
51       });
52       ProxyBindings(this.shellProxy).close();
53       this.applications_.clear();
54     }
55   }
57   var exports = {};
58   exports.Shell = Shell;
59   return exports;
60 });