summaryrefslogtreecommitdiffstats
path: root/mojo/services/public/js/application.js
blob: a50f84c4fe353e5147641524b22af647a2bf8826 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

define("mojo/services/public/js/application", [
  "mojo/services/public/js/service_provider",
  "mojo/services/public/js/shell",
  "mojo/public/js/threading",
], function(serviceProvider, shell, threading) {

  const ServiceProvider = serviceProvider.ServiceProvider;
  const Shell = shell.Shell;

  class Application {
    constructor(shellHandle, 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),
      });
    }

    initialize(args) {
    }

    doAcceptConnection(url, serviceProviderProxy, exposedServiceProviderProxy) {
      var serviceProvider = new ServiceProvider(serviceProviderProxy);
      this.serviceProviders.push(serviceProvider);

      var exposedServiceProvider =
          new ServiceProvider(exposedServiceProviderProxy);
      this.exposedServiceProviders.push(exposedServiceProvider);

      this.acceptConnection(url, serviceProvider, exposedServiceProvider);
    }

    acceptConnection(url, serviceProvider, exposedServiceProvider) {
    }

    quit() {
      this.serviceProviders.forEach(function(sp) {
        sp.close();
      });
      this.shell.close();
      threading.quit();
    }
  }

  var exports = {};
  exports.Application = Application;
  return exports;
});