From: Youngsoo Choi Date: Thu, 26 Sep 2019 06:46:45 +0000 (-0700) Subject: [Service][UI] Provide sandbox context for each ui servcie app X-Git-Tag: submit/tizen/20191001.060134^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=679e34719546f3c7d9a32c74ce64d039e2ce2d3f;p=platform%2Fframework%2Fweb%2Fwrtjs.git [Service][UI] Provide sandbox context for each ui servcie app This provides sandbox context for each ui service application and supports startService handler, onStart, and onStop APIs. Change-Id: I72291fe162ab6966deabc20ae7ded77f0d8f6f08 Signed-off-by: Youngsoo Choi --- diff --git a/wrt_app/src/runtime.js b/wrt_app/src/runtime.js index 2fb132bf..f39e244f 100755 --- a/wrt_app/src/runtime.js +++ b/wrt_app/src/runtime.js @@ -30,6 +30,7 @@ class Runtime { this.addonManager = null; this.isLaunched = false; this.inspectorEnabledByVconf = false; + this.sandbox = []; this.webContents = null; var _this = this; @@ -178,17 +179,39 @@ class Runtime { }); wrt.on('message', function(event, type, params) { console.log('message type(' + type + ') params : ' + params); + const app_id = params[0]; + const vm = require('vm'); if (type === 'startService') { - const vm = require('vm'); - const fs = require('fs'); - let sandbox = { - console: console, - module: module, - require: require, - }; - let options = {}; - let code = fs.readFileSync(params[1]); - vm.runInNewContext(code, sandbox, options); + if (_this.sandbox[app_id] === undefined) { + const fs = require('fs'); + _this.sandbox[app_id] = { + console: console, + module: module, + require: require, + }; + let options = {}; + let code = fs.readFileSync(params[1]); + vm.runInNewContext(code, _this.sandbox[app_id], options); + } + if (_this.sandbox[app_id]['started'] === undefined) { + _this.sandbox[app_id]['started'] = true; + _this.sandbox[app_id]['stopped'] = undefined; + const start_callback_string = 'if (module.exports.onStart !== undefined) { module.exports.onStart(); }'; + vm.runInContext(start_callback_string, _this.sandbox[app_id]); + } else { + console.log('UI service has been started.'); + } + event.preventDefault(); + } else if (type === 'stopService') { + if (_this.sandbox[app_id]['stopped'] === undefined) { + _this.sandbox[app_id]['stopped'] = true; + _this.sandbox[app_id]['started'] = undefined; + const stop_callback_string = 'if (module.exports.onStop !== undefined) { module.exports.onStop(); }'; + vm.runInContext(stop_callback_string, _this.sandbox[app_id]); + _this.sandbox[app_id] = undefined; + } else { + console.log('UI service has been stopped.'); + } event.preventDefault(); } });