base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / mojo / services / public / js / shell.js
blob338de5ee58a02c4a5a04cc2bd0ead20b87c40c51
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_provider",
12 ], function(bindings,
13 core,
14 connection,
15 shellMojom,
16 serviceProviderMojom,
17 serviceProvider) {
19 const ProxyBindings = bindings.ProxyBindings;
20 const StubBindings = bindings.StubBindings;
21 const ServiceProvider = serviceProvider.ServiceProvider;
22 const ServiceProviderInterface = serviceProviderMojom.ServiceProvider;
23 const ShellInterface = shellMojom.Shell;
25 class Shell {
26 constructor(shellHandle, app) {
27 this.shellHandle = shellHandle;
28 this.proxy = connection.bindProxyHandle(
29 shellHandle, ShellInterface.client, ShellInterface);
31 ProxyBindings(this.proxy).setLocalDelegate(app);
32 // TODO: call this serviceProviders_
33 this.applications_ = new Map();
36 connectToApplication(url) {
37 var application = this.applications_.get(url);
38 if (application)
39 return application;
41 this.proxy.connectToApplication(url, function(sp) {
42 application = new ServiceProvider(sp);
43 });
44 this.applications_.set(url, application);
45 return application;
48 connectToService(url, service, client) {
49 return this.connectToApplication(url).requestService(service, client);
52 close() {
53 this.applications_.forEach(function(application, url) {
54 application.close();
55 });
56 this.applications_.clear();
57 core.close(this.shellHandle);
61 var exports = {};
62 exports.Shell = Shell;
63 return exports;
64 });