From: DongHyun Song Date: Tue, 7 Dec 2021 07:12:21 +0000 (+0900) Subject: [Service] Support requestTrustedRemoteMessagePort X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F72%2F267572%2F6;p=platform%2Fframework%2Fweb%2Fwrtjs.git [Service] Support requestTrustedRemoteMessagePort MessagePort API requestTrustedRemoteMessagePort is only able to communicate apps, which has same certificate. Thus, wrt-service cannot send the message by this API. - 'receive' was already handled by wrt-service-launcher To support this messaging (service --> trusted app), wrt-service-launcher will relay the message by creating the local port for wrt-service. Related chromium-efl patch: https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/267623/ Change-Id: Id107160c10b68945c9e634b4816925ecc60a9abb Signed-off-by: DongHyun Song --- diff --git a/wrt_app/service/device_api_router.ts b/wrt_app/service/device_api_router.ts index 98cbe038..b0a2b6d1 100644 --- a/wrt_app/service/device_api_router.ts +++ b/wrt_app/service/device_api_router.ts @@ -11,7 +11,6 @@ export class DeviceAPIRouter { funcGetMetadata: any; funcGetPackageInfo: any; funcRequestLocalMessagePort: any; - funcRequestTrustedLocalMessagePort: any; id: string; serviceId: string; @@ -19,6 +18,7 @@ export class DeviceAPIRouter { callerAppId: string; permissions: string[]; pkgApiVersion: string; + messagePortInfo: any; constructor(id: string, isGlobal: boolean) { this.id = id; @@ -28,6 +28,7 @@ export class DeviceAPIRouter { this.packageId = wrt.getPackageId(id); this.permissions = []; this.pkgApiVersion = ''; + this.messagePortInfo = {}; this.initWebapis(); if (isGlobal) { @@ -324,19 +325,28 @@ export class DeviceAPIRouter { refineMessagePortApis() { this.funcRequestLocalMessagePort = global.tizen.messageport.requestLocalMessagePort; - this.funcRequestTrustedLocalMessagePort = - global.tizen.messageport.requestTrustedLocalMessagePort; - const registerMessagePort = (name: string, portName: string) => { + const registerMessagePort = (name: string, portName: string, appId?: string, callback?: any) => { + let portInfo = `${name}::${this.serviceId}::${portName}`; + if (this.messagePortInfo[portInfo] === 'created') { + callback?.(); + return; + } let data_payload = [ - new global.tizen.ApplicationControlData(name, [ portName ]), - + new global.tizen.ApplicationControlData(name, [portName]), ]; + if (appId) { + data_payload.push(new global.tizen.ApplicationControlData('appId', [appId])); + } let appControl = new global.tizen.ApplicationControl( - "http://tizen.org/appcontrol/operation/default", null, null, null, - data_payload, null); + "http://tizen.org/appcontrol/operation/default", null, null, null, + data_payload, null); global.tizen.application.launchAppControl(appControl, this.serviceId, - () => console.debug(`'${this.serviceId}::${name}' is requsted`)); + () => { + console.debug(`'${portInfo}' is requsted`) + callback?.(); + this.messagePortInfo[portInfo] = 'created'; + }); } global.tizen.messageport.requestLocalMessagePort = (portName: string) => { @@ -347,5 +357,19 @@ export class DeviceAPIRouter { registerMessagePort('requestTrustedLocalMessagePort', portName); return this.funcRequestLocalMessagePort(portName); } + global.tizen.messageport.requestTrustedRemoteMessagePort = (appId: string, portName: string) => { + return { + messagePortName: portName, + appId, + isTrusted: true, + sendMessage: (data: any, localMessagePort?: any) => { + registerMessagePort('requestTrustedRemoteMessagePort', portName, appId, + () => { + let remotePort = global.tizen.messageport.requestRemoteMessagePort(this.serviceId, portName); + remotePort.sendMessage(data, localMessagePort); + }); + } + } + } } }