From: Youngsoo Choi Date: Thu, 30 Jul 2020 02:35:16 +0000 (-0700) Subject: [Service] Expose app id related APIs to public and add getCallerAppId X-Git-Tag: accepted/tizen/unified/20200826.133035~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4602d90a1c273e4ced1991e2b869d1b43f35a9ed;p=platform%2Fframework%2Fweb%2Fwrtjs.git [Service] Expose app id related APIs to public and add getCallerAppId This exposes getServiceId and getPackageId APIs to puglic profile. Also, this newly adds getCallerAppId for the use of service apps. For instance, it can be used when a service app wants to make a messageport connection with a caller web app. If there's no caller app, it returns ''. Change-Id: Icfe221cb23acfb3587b38bd75fdce28ea5d2a23e Signed-off-by: Youngsoo Choi --- diff --git a/wrt_app/common/service_manager.ts b/wrt_app/common/service_manager.ts index a4222ab..330e441 100644 --- a/wrt_app/common/service_manager.ts +++ b/wrt_app/common/service_manager.ts @@ -47,12 +47,17 @@ export function startService(id: string, filename?: string) { module: new Module, require: require, tizen: global.tizen, + webapis: wrt.tv ? global.webapis : global.webapis = {}, }; sandbox[id].module.exports.onStop = () => { callFunctionInContext('module.exports.onExit', id); }; - let service_id = id.split(':')[0]; - sandbox[id].webapis = wrt.tv ? global.webapis : {}; + let ids = id.split(':'); + let caller_app_id = ids[1] ?? ''; + sandbox[id].webapis.getCallerAppId = () => { + return caller_app_id; + } + let service_id = ids[0]; sandbox[id].webapis.getServiceId = () => { return service_id; } @@ -60,7 +65,7 @@ export function startService(id: string, filename?: string) { let app_info = global.tizen.application.getAppInfo(service_id); if (app_info) return app_info.packageId; - return ''; + return ids[0].split('.')[0]; } if (service_type !== 'UI') {