Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 1 | /* |
| 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 Scheffler | 5efb4bf | 2021-04-05 20:44:42 | [diff] [blame] | 31 | /* eslint-disable rulesdir/no_underscored_properties */ |
| 32 | |
Tim van der Lippe | 2211a5f | 2021-04-23 12:59:52 | [diff] [blame] | 33 | import '../../core/root/root-legacy.js'; |
| 34 | |
Tim van der Lippe | dbb97be | 2021-04-15 15:12:43 | [diff] [blame] | 35 | import * as RootModule from '../../core/root/root.js'; |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 36 | |
Tim van der Lippe | 3387bd4 | 2020-10-20 11:46:31 | [diff] [blame] | 37 | // Legacy runtime namespace definitions |
| 38 | // @ts-ignore |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 39 | self.Runtime = self.Runtime || {}; |
Tim van der Lippe | 3387bd4 | 2020-10-20 11:46:31 | [diff] [blame] | 40 | // @ts-ignore |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 41 | Runtime = Runtime || {}; |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 42 | // The following two variables are initialized in `build_release_applications` |
Tim van der Lippe | 3387bd4 | 2020-10-20 11:46:31 | [diff] [blame] | 43 | // @ts-ignore |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 44 | Root.allDescriptors = Root.allDescriptors || []; |
Tim van der Lippe | 3387bd4 | 2020-10-20 11:46:31 | [diff] [blame] | 45 | // @ts-ignore |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 46 | Root.applicationDescriptor = Root.applicationDescriptor || undefined; |
| 47 | |
Jan Scheffler | 5efb4bf | 2021-04-05 20:44:42 | [diff] [blame] | 48 | export async function startApplication(_appName: string): Promise<void> { |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 49 | console.timeStamp('Root.Runtime.startApplication'); |
| 50 | |
Jan Scheffler | 5efb4bf | 2021-04-05 20:44:42 | [diff] [blame] | 51 | 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 Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 56 | for (let i = 0; i < Root.allDescriptors.length; ++i) { |
Jan Scheffler | 5efb4bf | 2021-04-05 20:44:42 | [diff] [blame] | 57 | // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration |
| 58 | // @ts-ignore |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 59 | const d = Root.allDescriptors[i]; |
| 60 | allDescriptorsByName[d['name']] = d; |
| 61 | } |
| 62 | |
Jan Scheffler | 5efb4bf | 2021-04-05 20:44:42 | [diff] [blame] | 63 | // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration |
| 64 | // @ts-ignore |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 65 | const configuration = Root.applicationDescriptor.modules; |
Tim van der Lippe | f866e2b | 2020-09-14 14:49:13 | [diff] [blame] | 66 | const moduleDescriptors = []; |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 67 | const coreModuleNames = []; |
| 68 | for (let i = 0; i < configuration.length; ++i) { |
| 69 | const descriptor = configuration[i]; |
| 70 | const name = descriptor['name']; |
Tim van der Lippe | f866e2b | 2020-09-14 14:49:13 | [diff] [blame] | 71 | moduleDescriptors.push(allDescriptorsByName[name]); |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 72 | if (descriptor['type'] === 'autostart') { |
| 73 | coreModuleNames.push(name); |
| 74 | } |
| 75 | } |
| 76 | |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 77 | 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 Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 80 | } |
Tim van der Lippe | 7f2002c | 2020-09-28 14:54:01 | [diff] [blame] | 81 | const runtimeInstance = RootModule.Runtime.Runtime.instance({forceNew: true, moduleDescriptors}); |
Tim van der Lippe | 3387bd4 | 2020-10-20 11:46:31 | [diff] [blame] | 82 | // @ts-ignore Exposed for legacy layout tests |
Tim van der Lippe | 7f2002c | 2020-09-28 14:54:01 | [diff] [blame] | 83 | self.runtime = runtimeInstance; |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 84 | if (coreModuleNames) { |
Tim van der Lippe | 7f2002c | 2020-09-28 14:54:01 | [diff] [blame] | 85 | await runtimeInstance.loadAutoStartModules(coreModuleNames); |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 86 | } |
Tim van der Lippe | 1ad9ada | 2020-11-04 17:08:42 | [diff] [blame] | 87 | RootModule.Runtime.appStartedPromiseCallback(); |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 88 | } |
| 89 | |
Jan Scheffler | 5efb4bf | 2021-04-05 20:44:42 | [diff] [blame] | 90 | export async function startWorker(appName: string): Promise<void> { |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 91 | return startApplication(appName).then(sendWorkerReady); |
| 92 | |
Jan Scheffler | 5efb4bf | 2021-04-05 20:44:42 | [diff] [blame] | 93 | function sendWorkerReady(): void { |
Tim van der Lippe | 59ff4e2 | 2020-12-10 09:42:35 | [diff] [blame] | 94 | // @ts-ignore |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 95 | self.postMessage('workerReady'); |
| 96 | } |
| 97 | } |