1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "napi_common_open_link_options.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "int_wrapper.h"
20 #include "napi_common_util.h"
21 #include "napi_common_want.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
25
UnwrapOpenLinkOptions(napi_env env,napi_value param,AAFwk::OpenLinkOptions & openLinkOptions,AAFwk::Want & want)26 bool UnwrapOpenLinkOptions(napi_env env, napi_value param, AAFwk::OpenLinkOptions &openLinkOptions, AAFwk::Want &want)
27 {
28 TAG_LOGI(AAFwkTag::JSNAPI, "called");
29
30 if (!IsTypeForNapiValue(env, param, napi_object)) {
31 TAG_LOGE(AAFwkTag::JSNAPI, "invalid params");
32 return false;
33 }
34
35 napi_value jsValue = GetPropertyValueByPropertyName(env, param, "parameters", napi_object);
36 if (jsValue != nullptr) {
37 AAFwk::WantParams wantParams;
38 if (UnwrapWantParams(env, jsValue, wantParams)) {
39 want.SetParams(wantParams);
40 }
41 }
42
43 bool appLinkingOnly = false;
44 if (UnwrapBooleanByPropertyName(env, param, APP_LINKING_ONLY.c_str(), appLinkingOnly)) {
45 openLinkOptions.SetAppLinkingOnly(appLinkingOnly);
46 want.SetParam(APP_LINKING_ONLY, appLinkingOnly);
47 }
48 if (!want.HasParameter(APP_LINKING_ONLY)) {
49 want.SetParam(APP_LINKING_ONLY, false);
50 }
51
52 return true;
53 }
54 } // namespace AppExecFwk
55 } // namespace OHOS
56