[WRTjs]javascript based web runtime 57/196857/6 accepted/tizen/unified/20190128.061758 submit/tizen/20190124.105017
authorjaekuk, lee <juku1999@samsung.com>
Fri, 4 Jan 2019 05:12:10 +0000 (14:12 +0900)
committerjaekuk, lee <juku1999@samsung.com>
Thu, 24 Jan 2019 08:32:41 +0000 (17:32 +0900)
Create new project for javascript based web runtime
to replace the existing web runtime

Change-Id: Ib343edbcc76d25117b89074c9552cbe68fa9594a
Signed-off-by: jaekuk, lee <juku1999@samsung.com>
15 files changed:
LICENSE [new file with mode: 0755]
packaging/wrtjs.manifest [new file with mode: 0755]
packaging/wrtjs.spec [new file with mode: 0755]
wrt_app/browser/init.js [new file with mode: 0755]
wrt_app/browser/wrt.js [new file with mode: 0755]
wrt_app/package.json [new file with mode: 0755]
wrt_app/renderer/init.js [new file with mode: 0755]
wrt_app/service/main.js [new file with mode: 0755]
wrt_app/src/extension_manager.js [new file with mode: 0755]
wrt_app/src/ipc_message.js [new file with mode: 0755]
wrt_app/src/main.js [new file with mode: 0755]
wrt_app/src/runtime.js [new file with mode: 0755]
wrt_app/src/was_event.js [new file with mode: 0755]
wrt_app/src/web_application.js [new file with mode: 0755]
wrt_app/worker/init.js [new file with mode: 0755]

diff --git a/LICENSE b/LICENSE
new file mode 100755 (executable)
index 0000000..247c97d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,203 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/packaging/wrtjs.manifest b/packaging/wrtjs.manifest
new file mode 100755 (executable)
index 0000000..96a1325
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+    <request>
+        <domain name="_"/>
+    </request>
+</manifest>
\ No newline at end of file
diff --git a/packaging/wrtjs.spec b/packaging/wrtjs.spec
new file mode 100755 (executable)
index 0000000..60e86ed
--- /dev/null
@@ -0,0 +1,33 @@
+Name:       wrtjs
+Summary:    Javascript based Runtime for Tizen
+Version:    1.0.0
+Release:    1
+Group:      Web Framework/Web Runtime
+License:    Apache-2.0
+URL:        https://www.tizen.org
+Source:    %{name}-%{version}.tar.gz
+
+BuildRequires: python, ninja, nodejs, nodejs-npm
+
+%description
+Web Runtime Engine based on Electron EFL
+
+%prep
+%setup -q
+
+%build
+%define _resourcedir /opt/usr/home/owner/data/wrt/app
+
+%install
+mkdir -p %{buildroot}%{_resourcedir}
+cp -r wrt_app/* %{buildroot}%{_resourcedir}/
+
+%postun
+
+%clean
+rm -fr %{buildroot}
+
+%files
+%manifest packaging/wrtjs.manifest
+%license LICENSE
+%{_resourcedir}/*
diff --git a/wrt_app/browser/init.js b/wrt_app/browser/init.js
new file mode 100755 (executable)
index 0000000..0dea6c7
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+require('../../electron.asar/browser/init')
diff --git a/wrt_app/browser/wrt.js b/wrt_app/browser/wrt.js
new file mode 100755 (executable)
index 0000000..b4fb83f
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+const {wrt} = process.binding('wrt');
+const {EventEmitter} = require('events')
+const util = require('util')
+
+Object.setPrototypeOf(Object.getPrototypeOf(wrt), EventEmitter.prototype)
+
+module.exports = wrt
+
+console.log = console.error = console.warn = function(...args) {
+  wrt.log(util.format(...args));
+};
+process.stdout.write = process.stderr.write = function (chunk, encoding, callback) {
+  if (Buffer.isBuffer(chunk)) {
+    chunk = chunk.toString(encoding)
+  }
+  wrt.log(chunk)
+  if (callback) {
+    callback()
+  }
+  return true
+}
diff --git a/wrt_app/package.json b/wrt_app/package.json
new file mode 100755 (executable)
index 0000000..0858c86
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "name": "wrtjs",
+  "version": "1.0.0",
+  "main": "src/main.js"
+}
diff --git a/wrt_app/renderer/init.js b/wrt_app/renderer/init.js
new file mode 100755 (executable)
index 0000000..ead2a61
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+require('../../electron.asar/renderer/init')
+
+process.on('uncaughtException', function (error) {
+  // Do nothing if the user has a custom uncaught exception handler.
+  var ref, stack
+  stack = (ref = error.stack) != null ? ref : error.name + ': ' + error.message
+  console.error('A JavaScript error occurred in the renderer process\n' + stack)
+})
diff --git a/wrt_app/service/main.js b/wrt_app/service/main.js
new file mode 100755 (executable)
index 0000000..733f8df
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+'use strict';
+
+const wrt = require('../browser/wrt');
+const vm = require('vm');
+
+wrt.on('start-service', (event, appID) => {
+  console.log('start service app : ' + appID);
+  let sandbox = { console: console };
+  let options = { filename: appID };
+  vm.runInNewContext(wrt.readService(appID), sandbox, options);
+})
+
+process.on('exit', (code) => {
+  console.log('Exit with code : ' + code);
+})
diff --git a/wrt_app/src/extension_manager.js b/wrt_app/src/extension_manager.js
new file mode 100755 (executable)
index 0000000..6d0f793
--- /dev/null
@@ -0,0 +1,349 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+'use strict';
+
+const fs = require('fs');
+const path = require('path');
+const MANIFEST_FILE = 'manifest.json';
+const PRELOAD_JS_FILE = 'preload.js';
+const EXTENSIONS_DB_FILE = 'extensions_db.json';
+const T_CRX = 'CRX';
+const T_WRT = 'WRT';
+const T_API = 'API';
+const {BrowserWindow} = require('electron');
+
+class ExtensionManager {
+    constructor() {
+        this.ext_path_ = path.join(__dirname.split('wrt')[0], 'electron/runtime_addon');
+        console.log('Extension path : ' + this.ext_path_);
+        this.extensions_list_ = null;
+        this.extensions_ = null;
+        this.extensions_API_ = null;
+    }
+
+    printAPIs() {
+        console.log('==========printAPIs==========');
+        for (var namespace in this.extensions_API_) {
+            console.log('namespace: ' + namespace);
+            for (var entry_symbol in this.extensions_API_[namespace]) {
+                console.log('extensions_API[' + namespace + '][' + entry_symbol + '] = ' + this.extensions_API_[namespace][entry_symbol]);
+            }
+        }
+    }
+
+    loadExtensionsListFromPath() {
+        var extensions_list = [],
+            filenames;
+        try {
+            filenames = fs.readdirSync(this.ext_path_);
+        } catch (e) {
+            console.error('LoadExtensionsListFromPath - fs.readdirSync error : ' + e);
+            return false;
+        }
+        if (filenames) {
+            for (var i in filenames) {
+                var filename = filenames[i],
+                    filepath = path.join(this.ext_path_, filename),
+                    stats = fs.statSync(filepath);
+
+                if (stats.isDirectory()) {
+                    var manifest_obj,
+                        manifest_path = path.join(filepath, MANIFEST_FILE);
+
+                    try {
+                        manifest_obj = JSON.parse(fs.readFileSync(manifest_path));
+                    } catch (e) {
+                        console.error('LoadExtensionsListFromPath - error : ' + e);
+                        continue;
+                    }
+                    var extension = new Object();
+
+                    extension.name = manifest_obj.name;
+                    extension.path = filepath;
+                    if (manifest_obj.type)  {
+                        extension.type = manifest_obj.type;
+                    } else {
+                        extension.type = 'WRT';
+                    }
+                    extension.activate = true; // activate by default
+                    extensions_list.push(extension);
+                }
+            }
+        }
+        this.extensions_list_ = extensions_list;
+        console.log('LoadExtensionsListFromPath ; ' + JSON.stringify(this.extensions_list_));
+        return true;
+    }
+
+    loadJsonDB(db_path) {
+        if (!db_path) {
+            db_path = path.join(this.ext_path_, EXTENSIONS_DB_FILE);
+        }
+        var extensions_list;
+        try {
+            extensions_list = JSON.parse(fs.readFileSync(db_path));
+        } catch (e) {
+            console.error('LoadJsonDB - open error : ' + e);
+            return false;
+            // For DEBUG purpose (load extensions from PATH, not via INSTALLER)
+            //return this.loadExtensionsListFromExtPath();
+        }
+        this.extensions_list_ = extensions_list;
+        return true;
+    }
+
+    saveJsonDB(db_path) {
+        if (!db_path) {
+            db_path = path.join(this.ext_path_, EXTENSIONS_DB_FILE);
+        }
+        var fd;
+        try {
+            fd = fs.openSync(db_path, 'w');
+        } catch (e) {
+            console.error('SaveJsonDB - open error : ' + e);
+            return false;
+        }
+        fs.writeSync(fd, JSON.stringify(this.extensions_list_));
+        fs.closeSync(fd);
+        return true;
+    }
+
+    generateJsFromAPIs(js_path) {
+        if (!js_path) {
+            js_path = path.join(this.ext_path_, PRELOAD_JS_FILE);
+        }
+        console.log('preload.js : ' + js_path);
+        var fd;
+        try {
+            fd = fs.openSync(js_path, 'w');
+        } catch (e) {
+            console.error('GenerateJsFromAPIs - open error : ' + e);
+            return false;
+        }
+        // Introduction Comments & preset
+        var comments = '// Auto-generated code by extensions_installer\n// Generated from “entry_points” field in package.json\n// var <entry_points_symbol> = <entry_points_class>;\n';
+        var preset = '\nvar EXTENSIONS_PATH = process.env.WAS_EXTENSIONS_PATH;\n';
+        fs.writeSync(fd, comments + preset);
+        // namespace
+        for (var namespace in this.extensions_API_) {
+            if (namespace != '_default_') {
+                fs.writeSync(fd, '\n//namespace\n');
+                fs.writeSync(fd, 'var ' + namespace + ' = new Object();\n');
+                // namespace.entry_points
+                fs.writeSync(fd, '\n//namespace.entry_points\n');
+                for (var entry_symbol in this.extensions_API_[namespace]) {
+                    fs.writeSync(fd, namespace + '.' + entry_symbol + ' = require("' + this.extensions_API_[namespace][entry_symbol] + '");\n');
+                }
+                // attach to root
+                fs.writeSync(fd, '\n//attach to window\n');
+                fs.writeSync(fd, 'window.' + namespace + ' = ' + namespace + ';\n');
+            } else { // '_default_'
+                // entry_points and attach to root
+                fs.writeSync(fd, '\n//default namespace - entry_points and attach to window\n');
+                /*eslint no-redeclare: 1*/
+                for (var entry_symbol in this.extensions_API_[namespace]) {
+                    fs.writeSync(fd, 'window.' + entry_symbol + ' = require("' + this.extensions_API_[namespace][entry_symbol] + '");\n');
+                }
+            }
+        }
+        fs.closeSync(fd);
+        return true;
+    }
+
+    build() {
+        // 0. load extensions_list_ from JSON DB
+        this.loadJsonDB();
+        var extensions = [];
+        var extensions_API = [];
+        // 1. load extensions from extension_list_
+        if (this.extensions_list_) {
+            for (var i in this.extensions_list_) {
+                var extension = this.extensions_list_[i];
+                if (extension.activate == false) {
+                    continue;
+                }
+                try {
+                    var manifest_obj, manifest_path = path.join(extension.path, MANIFEST_FILE);
+                    manifest_obj = JSON.parse(fs.readFileSync(manifest_path));
+                    console.log('manifest_obj : ' + JSON.stringify(manifest_obj));
+                    if (manifest_obj.type && manifest_obj.type.toUpperCase() === 'INSTALLER') {
+                        // do nothing for installer extension
+                        console.log('ExtensionManager.build ' + manifest_obj.name + ' is for installer - SKIP');
+                        continue;
+                    } else if (manifest_obj.type && manifest_obj.type.toUpperCase() === 'API') {
+                        var namespace = manifest_obj.namespace;
+                        if (!namespace) {
+                            namespace = '_default_';
+                        }
+                        if (!extensions_API[namespace]) {
+                            extensions_API[namespace] = [];
+                        }
+                        for (var entry_it in manifest_obj.entry_points) {
+                            for (var entry_symbol in manifest_obj.entry_points[entry_it]) {
+                                var module_path = manifest_obj.entry_points[entry_it][entry_symbol];
+                                if (extensions_API[namespace][entry_symbol]) {
+                                    console.log('extensions_API[' + namespace + '][' + entry_symbol + '] already registered :' + extensions_API[namespace][entry_symbol]);
+                                    continue;
+                                }
+                                extensions_API[namespace][entry_symbol] = path.join(extension.path, module_path);
+                                console.log('extensions_API[' + namespace + '][' + entry_symbol + '] registered :' + extensions_API[namespace][entry_symbol]);
+                            }
+                        }
+                    } else {
+                        var type;
+                        if (manifest_obj.main) {
+                            type = T_WRT;
+                        } else {
+                            type = T_CRX;
+                        }
+                        if (!extensions[type]) {
+                            extensions[type] = [];
+                        }
+                        if (extensions[type][manifest_obj.name]) {
+                            console.log('extensions[' + type + '][' + manifest_obj.name + '] already registered : ' + extensions[type][manifest_obj.name]);
+                            continue;
+                        }
+                        if (manifest_obj.main) {
+                            extensions[type][manifest_obj.name] = path.join(extension.path, manifest_obj.main);
+                        } else {
+                            extensions[type][manifest_obj.name] = extension.path;
+                        }
+                    }
+                    console.log('extensions[' + type + '][' + manifest_obj.name + '] = ' + extensions[type][manifest_obj.name] + ' registered');
+                } catch (e) {
+                    console.error('ExtensionManager.build error - ' + e);
+                }
+            }
+        }
+        if (this.extensions_ != null) {
+            delete this.extensions_;
+            this.extensions_ = null;
+        }
+        if (this.extensions_API_ != null) {
+            delete this.extensions_API_;
+            this.extensions_API_ = null;
+        }
+        this.extensions_ = extensions;
+        this.extensions_API_ = extensions_API;
+        return this.extensions_;
+    }
+
+    activate(event_emitter, name) {
+        if (!this.extensions_) {
+            return;
+        }
+        var extension, extension_path = null;
+        if (this.extensions_[T_WRT] !== undefined && this.extensions_[T_WRT][name] !== undefined) {
+            extension_path = this.extensions_[T_WRT][name];
+            console.log('activate: ' + extension_path + ' name:' + name);
+            try {
+                extension = require(extension_path);
+            } catch (e) {
+                console.error('activate - error on require() : ' + e);
+                return;
+            }
+            if (extension && extension.activate) {
+                extension.activate(event_emitter);
+            }
+            else console.log('extension.activate not defined!');
+        } else if (this.extensions_[T_CRX] !== undefined && this.extensions_[T_CRX][name] !== undefined) {
+            extension_path = this.extensions_[T_CRX][name];
+            console.log('activate 2: ' + extension_path + ' name:' + name);
+            try {
+                console.log('BrowserWindow.addExtension: ' + extension_path);
+                BrowserWindow.addExtension(extension_path);
+            } catch (e) {
+                console.error('activate - error on addExtension() : ' + e);
+            }
+            return;
+        }
+    }
+
+    deactivate(event_emitter, name) {
+        if (!this.extensions_) {
+            return;
+        }
+        console.log('deactivate: name:' + name);
+        var extension, extension_path = null;
+        if (this.extensions_[T_WRT] !== undefined && this.extensions_[T_WRT][name] !== undefined) {
+            try {
+                extension_path = this.extensions_[T_WRT][name];
+            } catch (e) {
+                console.error('deactivate - error : ' + e);
+                return;
+            }
+            console.log('deactivate: path:' + extension_path);
+            try {
+                extension = require(extension_path);
+            } catch (e) {
+                console.error('deactivate - error on require() : ' + e);
+            }
+            if (extension && extension.deactivate) {
+                extension.deactivate(event_emitter);
+            } else {
+                console.log('extension.deactivate not defined!');
+            }
+        } else if (this.extensions_[T_CRX] !== undefined && this.extensions_[T_CRX][name] !== undefined) {
+            extension_path = this.extensions_[T_CRX][name];
+            try {
+                BrowserWindow.removeExtension(name);
+            } catch (e) {
+                console.error('activate - error on removeExtension() : ' + e);
+            }
+        }
+    }
+
+    activateAll(event_emitter) {
+        if (!this.extensions_) {
+            console.log('activateAll - extensions not built');
+            return;
+        }
+        for (var name in this.extensions_[T_WRT]) {
+            this.activate(event_emitter, name);
+        }
+        for (var name in this.extensions_[T_CRX]) {
+            this.activate(event_emitter, name);
+        }
+    }
+
+    deactivateAll(event_emitter) {
+        if (!this.extensions_) {
+            console.log('deactivateAll - extensions not built');
+            return;
+        }
+        for (var name in this.extensions_[T_WRT]) {
+            this.deactivate(event_emitter, name);
+        }
+        for (var name in this.extensions_[T_CRX]) {
+            this.deactivate(event_emitter, name);
+        }
+    }
+
+    static getManifestFile() {
+        return MANIFEST_FILE;
+    }
+
+    static getPreloadJsFile() {
+        return PRELOAD_JS_FILE;
+    }
+
+    static getExtensionsPath() {
+        return ext_path_;
+    }
+}
+
+module.exports = ExtensionManager;
diff --git a/wrt_app/src/ipc_message.js b/wrt_app/src/ipc_message.js
new file mode 100755 (executable)
index 0000000..10509db
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+'use strict';
+
+module.exports = Object.freeze({
+    EXTENSIONS: {
+        INSTALLED: 'ipc:extensions:installed',
+        UNINSTALLED: 'ipc:extensions:uninstalled',
+        ACTIVATE: 'ipc:extensions:activate',
+        DEACTIVATE: 'ipc:extensions:deactivate'
+    }
+});
diff --git a/wrt_app/src/main.js b/wrt_app/src/main.js
new file mode 100755 (executable)
index 0000000..a6ae967
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+'use strict';
+
+process.on('uncaughtException', function (error) {
+  // Do nothing if the user has a custom uncaught exception handler.
+  var ref, stack
+  stack = (ref = error.stack) != null ? ref : error.name + ': ' + error.message
+  console.error('A JavaScript error occurred in the main process\n' + stack)
+})
+
+new (require('./runtime'))({
+  devMode: false,
+  noExtensions: false
+});
diff --git a/wrt_app/src/runtime.js b/wrt_app/src/runtime.js
new file mode 100755 (executable)
index 0000000..4a50762
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+'use strict';
+
+const wrt = require('../browser/wrt');  // Load first for log
+const ExtensionManager = require('./extension_manager');
+const {app, ipcMain} = require('electron');
+const IPC_MESSAGE = require('./ipc_message');
+const WAS_EVENT = require('./was_event');
+const WebApplication = require('./web_application');
+
+class Runtime {
+    constructor(options) {
+        this.webApplication = null;
+        this.handleIpcMessages();
+        this.extensionManager = null;
+        this.isLaunched = false;
+
+        var _this = this;
+        app.on('will-finish-launching', function() {
+            console.log('will-finish-launching');
+        });
+        app.on('before-quit', function(event) {
+            console.log('before-quit');
+        });
+        app.on('will-quit', function(event) {
+            console.log('will-quit');
+            _this.extensionManager.deactivateAll(app);
+            _this.killAllProcesses();
+        });
+        app.on('quit', function(event) {
+            console.log('quit');
+            wrt.exit();
+        });
+        app.on('browser-window-blur', function() {
+            console.log('browser-window-blur');
+        });
+        app.on('browser-window-focus', function() {
+            console.log('browser-window-focus');
+        });
+        app.on('browser-window-created', function() {
+            console.log('browser-window-created');
+            if (!_this.isLaunched) {
+                _this.extensionManager.activateAll(app);
+                _this.isLaunched = true;
+            }
+        });
+        app.on('gpu-process-crashed', function() {
+            console.error('gpu-process-crashed');
+        });
+        app.on('window-all-closed', function(event) {
+            console.log('window-all-closed');
+            app.quit();
+        });
+        app.on('will-finish-launching', function(event) {
+            console.log('will-finish-launching');
+        });
+        app.once('ready', function(event) {
+            console.log('ready');
+            _this.extensionManager = new ExtensionManager();
+            if (!options.noExtensions) {
+                _this.extensionManager.build();
+            }
+        });
+        wrt.on('app-control', function() {
+            console.log('app-control');
+            if (_this.webApplication) {
+                console.log("Close current app");
+                _this.webApplication.close();
+                _this.webApplication = null;
+            }
+
+            if (wrt.isElectronApp()) {
+                console.log("Electron App launch");
+                let filePath = wrt.getPath();
+                let pkgJson = require(filePath.substr(7, filePath.length - 12));
+                let mainJsPath = filePath.substr(7, filePath.length - 19) +
+                                                (pkgJson.main || 'index.js');
+
+                const Module = require('module');
+                Module._load(mainJsPath, Module, true);
+                app.emit('ready');
+            } else {
+                _this.webApplication = new WebApplication(options);
+                _this.webApplication.loadURL();
+                if (wrt.appID !== 'NVPDzvckj9.RuntimeAddonSetting') {
+                    _this.extensionManager.activateAll(app);
+                }
+            }
+        });
+        wrt.on('suspend', function() {
+            console.log('suspend');
+            _this.webApplication.suspend();
+        });
+        wrt.on('resume', function() {
+            console.log('resume');
+            _this.webApplication.resume();
+        });
+    }
+    onAppControl() {}
+    onLanguageChanged() {}
+    onLowMemory() {}
+    killAllProcesses() {}
+    handleIpcMessages() {
+        var _this = this;
+        ipcMain.on(IPC_MESSAGE.EXTENSIONS.INSTALLED, (sender, name) => {
+            console.log('handleIpcMessages: INSTALLED ' + name);
+            _this.extensionManager.build();
+            return _this.extensionManager.activate(app, name);
+        });
+        ipcMain.on(IPC_MESSAGE.EXTENSIONS.UNINSTALLED, (sender, name) => {
+            console.log('handleIpcMessages: UNINSTALLED ' + name);
+            return _this.extensionManager.deactivate(app, name);
+        });
+        ipcMain.on(IPC_MESSAGE.EXTENSIONS.ACTIVATE, (sender, name) => {
+            console.log('handleIpcMessages: ACTIVATE ' + name);
+            return _this.extensionManager.activate(app, name);
+        });
+        ipcMain.on(IPC_MESSAGE.EXTENSIONS.DEACTIVATE, (sender, name) => {
+            console.log('handleIpcMessages: DEACTIVATE ' + name);
+            return _this.extensionManager.deactivate(app, name);
+        });
+    }
+}
+module.exports = Runtime;
diff --git a/wrt_app/src/was_event.js b/wrt_app/src/was_event.js
new file mode 100755 (executable)
index 0000000..bf843d5
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+'use strict';
+
+module.exports = Object.freeze({
+    RUNTIME: {
+        MINIMIZE: 'was:runtime:minimize',
+        UNMINIMIZE: 'was:runtime:unminimize',
+        MAXIMIZE: 'was:runtime:maximize',
+        UNMAXIMIZE: 'was:runtime:unmaximize',
+        FOCUS: 'was:runtime:focus',
+        UNFOCUS: 'was:runtime:unfocus'
+    },
+    WEBAPPLICATION: {
+        SUSPEND: 'was:webapplication:suspend',
+        RESUME: 'was:webapplication:resume'
+    }
+});
diff --git a/wrt_app/src/web_application.js b/wrt_app/src/web_application.js
new file mode 100755 (executable)
index 0000000..e3cf6da
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+'use strict';
+
+const {BrowserWindow, app} = require('electron');
+const WAS_EVENT = require('./was_event');
+const wrt = require('../browser/wrt');
+
+class WebApplication {
+    constructor(options) {
+        let winopt = this.getBrowserWindowOption();
+        console.log('opt: ' + JSON.stringify(winopt));
+        this.mainWindow = new BrowserWindow(winopt);
+        if (options.devMode) {
+            this.mainWindow.webContents.openDevTools({
+                detached: true
+            });
+        }
+        console.log('mainWindow id : ' + this.mainWindow.id);
+        this.handleEvents(winopt);
+        this.firstRendered = false;
+        this.backgroundSupport = wrt.getBackgroundSupport();
+    }
+    close() {
+        this.mainWindow.close();
+    }
+    getBrowserWindowOption() {
+        return {
+            fullscreen: false,
+            show: false,
+            webPreferences: {
+                nodeIntegration: false,
+                nodeIntegrationInWorker: false
+            },
+            'web-preferences': {
+                'direct-write': true,
+                'subpixel-font-scaling': false,
+                'web-security': false
+            }
+        };
+    }
+    handleEvents(options) {
+        var self = this;
+        this.mainWindow.on('ready-to-show', function() {
+            console.log('mainWindow ready-to-show');
+            wrt.hideSplashScreen(1);
+            self.firstRendered = true;
+
+            if (!self.mainWindow.isVisible()) {
+                console.log('show browserWindow');
+                self.mainWindow.show();
+            }
+        });
+        this.mainWindow.on('closed', function() {
+            console.log('mainWindow closed!');
+            self.mainWindow = null;
+        });
+        this.mainWindow.webContents.on('crashed', function() {
+            console.error('webContents crashed');
+            app.exit(100);
+        });
+        this.mainWindow.webContents.on('did-start-loading', function() {
+            console.log('webContents did-start-loading');
+        });
+        this.mainWindow.webContents.on('did-finish-load', function() {
+            console.log('webContents did-finish-load');
+        });
+    }
+    loadURL(url) {
+        console.log('loadURL');
+        this.mainWindow.loadURL(url ? url : wrt.getPath());
+    }
+    suspend() {
+        console.log('WebApplication : suspend');
+        BrowserWindow.getAllWindows().forEach((window) => {
+            window.hide();
+            if (!this.backgroundSupport)
+                window.setEnabled(false);
+        });
+    }
+    resume() {
+        console.log('WebApplication : resume');
+        if (!this.firstRendered) {
+            return;
+        }
+        BrowserWindow.getAllWindows().forEach((window) => {
+            window.show();
+            if (!this.backgroundSupport)
+                window.setEnabled(true);
+        });
+    }
+}
+module.exports = WebApplication;
diff --git a/wrt_app/worker/init.js b/wrt_app/worker/init.js
new file mode 100755 (executable)
index 0000000..676b55a
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+require('../../electron.asar/worker/init')