add js interface bindDialogTarget

Signed-off-by: zhengjiangliang <zhengjiangliang@huawei.com>
Change-Id: I66e3289a49120900a6a6c82ac813a7084286e599
This commit is contained in:
zhengjiangliang 2023-01-18 15:22:12 +08:00 committed by z00514981
parent 8ddcc35b4b
commit 96b41b4a6b
3 changed files with 46 additions and 0 deletions

View File

@ -64,6 +64,7 @@ ohos_shared_library("window_native_kit") {
external_deps = [ external_deps = [
"ability_runtime:ability_manager", "ability_runtime:ability_manager",
"ability_runtime:dialog_request_info",
"ability_runtime:runtime", "ability_runtime:runtime",
"access_token:libaccesstoken_sdk", "access_token:libaccesstoken_sdk",
"bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_base",

View File

@ -32,6 +32,7 @@
#include "pixel_map_napi.h" #include "pixel_map_napi.h"
#include "napi_remote_object.h" #include "napi_remote_object.h"
#include "permission.h" #include "permission.h"
#include "request_info.h"
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
@ -1267,6 +1268,12 @@ NativeValue* JsWindow::OnBindDialogTarget(NativeEngine& engine, NativeCallbackIn
sptr<IRemoteObject> token = nullptr; sptr<IRemoteObject> token = nullptr;
token = NAPI_ohos_rpc_getNativeRemoteObject( token = NAPI_ohos_rpc_getNativeRemoteObject(
reinterpret_cast<napi_env>(&engine), reinterpret_cast<napi_value>(info.argv[0])); reinterpret_cast<napi_env>(&engine), reinterpret_cast<napi_value>(info.argv[0]));
if (token == nullptr) {
std::shared_ptr<AbilityRuntime::RequestInfo> requestInfo = AbilityRuntime::RequestInfo::UnwrapRequestInfo(engine, info.argv[0]);
if (requestInfo != nullptr) {
token = requestInfo->GetToken();
}
}
if (token == nullptr) { if (token == nullptr) {
errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
} }

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#ifndef OHOS_ABILITY_RUNTIME_REQUEST_INFO_H
#define OHOS_ABILITY_RUNTIME_REQUEST_INFO_H
namespace OHOS {
namespace AbilityRuntime {
class RequestInfo {
public:
static NativeValue* WrapRequestInfo(NativeEngine &engine, RequestInfo *request) {
return nullptr;
};
static std::shared_ptr<RequestInfo> UnwrapRequestInfo(NativeEngine &engine, NativeValue *jsParam) {
return nullptr;
};
sptr<IRemoteObject> GetToken() {
return callerToken_;
};
private:
sptr<IRemoteObject> callerToken_;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_REQUEST_INFO_H