blob: c3ce6c18508ca159e2c6835b1e61155b706c367f [file] [log] [blame]
Tim van der Lippe6d51bf02020-03-18 12:15:141/*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
Jan Scheffler5efb4bf2021-04-05 20:44:4231/* eslint-disable rulesdir/no_underscored_properties */
32
Tim van der Lippe2211a5f2021-04-23 12:59:5233import '../../core/root/root-legacy.js';
34
Tim van der Lippedbb97be2021-04-15 15:12:4335import * as RootModule from '../../core/root/root.js';
Tim van der Lippe6d51bf02020-03-18 12:15:1436
Tim van der Lippe3387bd42020-10-20 11:46:3137// Legacy runtime namespace definitions
38// @ts-ignore
Tim van der Lippe6d51bf02020-03-18 12:15:1439self.Runtime = self.Runtime || {};
Tim van der Lippe3387bd42020-10-20 11:46:3140// @ts-ignore
Tim van der Lippe6d51bf02020-03-18 12:15:1441Runtime = Runtime || {};
Tim van der Lippe6d51bf02020-03-18 12:15:1442// The following two variables are initialized in `build_release_applications`
Tim van der Lippe3387bd42020-10-20 11:46:3143// @ts-ignore
Tim van der Lippe6d51bf02020-03-18 12:15:1444Root.allDescriptors = Root.allDescriptors || [];
Tim van der Lippe3387bd42020-10-20 11:46:3145// @ts-ignore
Tim van der Lippe6d51bf02020-03-18 12:15:1446Root.applicationDescriptor = Root.applicationDescriptor || undefined;
47
Jan Scheffler5efb4bf2021-04-05 20:44:4248export async function startApplication(_appName: string): Promise<void> {
Tim van der Lippe6d51bf02020-03-18 12:15:1449 console.timeStamp('Root.Runtime.startApplication');
50
Jan Scheffler5efb4bf2021-04-05 20:44:4251 const allDescriptorsByName: {
52 [x: string]: RootModule.Runtime.ModuleDescriptor,
53 } = {};
54 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
55 // @ts-ignore
Tim van der Lippe6d51bf02020-03-18 12:15:1456 for (let i = 0; i < Root.allDescriptors.length; ++i) {
Jan Scheffler5efb4bf2021-04-05 20:44:4257 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
58 // @ts-ignore
Tim van der Lippe6d51bf02020-03-18 12:15:1459 const d = Root.allDescriptors[i];
60 allDescriptorsByName[d['name']] = d;
61 }
62
Jan Scheffler5efb4bf2021-04-05 20:44:4263 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
64 // @ts-ignore
Tim van der Lippe6d51bf02020-03-18 12:15:1465 const configuration = Root.applicationDescriptor.modules;
Tim van der Lippef866e2b2020-09-14 14:49:1366 const moduleDescriptors = [];
Tim van der Lippe6d51bf02020-03-18 12:15:1467 const coreModuleNames = [];
68 for (let i = 0; i < configuration.length; ++i) {
69 const descriptor = configuration[i];
70 const name = descriptor['name'];
Tim van der Lippef866e2b2020-09-14 14:49:1371 moduleDescriptors.push(allDescriptorsByName[name]);
Tim van der Lippe6d51bf02020-03-18 12:15:1472 if (descriptor['type'] === 'autostart') {
73 coreModuleNames.push(name);
74 }
75 }
76
Tim van der Lippe6d51bf02020-03-18 12:15:1477 for (let i = 0; i < moduleDescriptors.length; ++i) {
78 moduleDescriptors[i].name = configuration[i]['name'];
79 moduleDescriptors[i].condition = configuration[i]['condition'];
Tim van der Lippe6d51bf02020-03-18 12:15:1480 }
Tim van der Lippe7f2002c2020-09-28 14:54:0181 const runtimeInstance = RootModule.Runtime.Runtime.instance({forceNew: true, moduleDescriptors});
Tim van der Lippe3387bd42020-10-20 11:46:3182 // @ts-ignore Exposed for legacy layout tests
Tim van der Lippe7f2002c2020-09-28 14:54:0183 self.runtime = runtimeInstance;
Tim van der Lippe6d51bf02020-03-18 12:15:1484 if (coreModuleNames) {
Tim van der Lippe7f2002c2020-09-28 14:54:0185 await runtimeInstance.loadAutoStartModules(coreModuleNames);
Tim van der Lippe6d51bf02020-03-18 12:15:1486 }
Tim van der Lippe1ad9ada2020-11-04 17:08:4287 RootModule.Runtime.appStartedPromiseCallback();
Tim van der Lippe6d51bf02020-03-18 12:15:1488}
89
Jan Scheffler5efb4bf2021-04-05 20:44:4290export async function startWorker(appName: string): Promise<void> {
Tim van der Lippe6d51bf02020-03-18 12:15:1491 return startApplication(appName).then(sendWorkerReady);
92
Jan Scheffler5efb4bf2021-04-05 20:44:4293 function sendWorkerReady(): void {
Tim van der Lippe59ff4e22020-12-10 09:42:3594 // @ts-ignore
Tim van der Lippe6d51bf02020-03-18 12:15:1495 self.postMessage('workerReady');
96 }
97}