1 /*
2 * Copyright (c) 2023 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 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_navigator_bridge.h"
16
17 #include "core/interfaces/native/node/api.h"
18
19 namespace OHOS::Ace::NG {
SetTarget(ArkUIRuntimeCallInfo * runtimeCallInfo)20 ArkUINativeModuleValue NavigatorBridge::SetTarget(ArkUIRuntimeCallInfo* runtimeCallInfo)
21 {
22 EcmaVM* vm = runtimeCallInfo->GetVM();
23 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
24 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
25 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
26 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
27 std::string target = secondArg->ToString(vm)->ToString();
28 GetArkUIInternalNodeAPI()->GetNavigatorModifier().SetTarget(nativeNode, target.c_str());
29 return panda::JSValueRef::Undefined(vm);
30 }
31
ResetTarget(ArkUIRuntimeCallInfo * runtimeCallInfo)32 ArkUINativeModuleValue NavigatorBridge::ResetTarget(ArkUIRuntimeCallInfo* runtimeCallInfo)
33 {
34 EcmaVM* vm = runtimeCallInfo->GetVM();
35 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
36 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
37 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
38 GetArkUIInternalNodeAPI()->GetNavigatorModifier().ResetTarget(nativeNode);
39 return panda::JSValueRef::Undefined(vm);
40 }
41
SetType(ArkUIRuntimeCallInfo * runtimeCallInfo)42 ArkUINativeModuleValue NavigatorBridge::SetType(ArkUIRuntimeCallInfo* runtimeCallInfo)
43 {
44 EcmaVM* vm = runtimeCallInfo->GetVM();
45 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
46 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
47 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
48 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
49 if (secondArg->IsUndefined()) {
50 GetArkUIInternalNodeAPI()->GetNavigatorModifier().ResetType(nativeNode);
51 }
52 int32_t value = secondArg->Int32Value(vm);
53 GetArkUIInternalNodeAPI()->GetNavigatorModifier().SetType(nativeNode, value);
54 return panda::JSValueRef::Undefined(vm);
55 }
56
ResetType(ArkUIRuntimeCallInfo * runtimeCallInfo)57 ArkUINativeModuleValue NavigatorBridge::ResetType(ArkUIRuntimeCallInfo* runtimeCallInfo)
58 {
59 EcmaVM* vm = runtimeCallInfo->GetVM();
60 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
61 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
62 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
63 GetArkUIInternalNodeAPI()->GetNavigatorModifier().ResetType(nativeNode);
64 return panda::JSValueRef::Undefined(vm);
65 }
66
SetActive(ArkUIRuntimeCallInfo * runtimeCallInfo)67 ArkUINativeModuleValue NavigatorBridge::SetActive(ArkUIRuntimeCallInfo* runtimeCallInfo)
68 {
69 EcmaVM* vm = runtimeCallInfo->GetVM();
70 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
71 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
72 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
73 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
74 bool active = secondArg->ToBoolean(vm)->Value();
75 GetArkUIInternalNodeAPI()->GetNavigatorModifier().SetActive(nativeNode, active);
76 return panda::JSValueRef::Undefined(vm);
77 }
78
ResetActive(ArkUIRuntimeCallInfo * runtimeCallInfo)79 ArkUINativeModuleValue NavigatorBridge::ResetActive(ArkUIRuntimeCallInfo* runtimeCallInfo)
80 {
81 EcmaVM* vm = runtimeCallInfo->GetVM();
82 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
83 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
84 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
85 GetArkUIInternalNodeAPI()->GetNavigatorModifier().ResetActive(nativeNode);
86 return panda::JSValueRef::Undefined(vm);
87 }
88
SetParams(ArkUIRuntimeCallInfo * runtimeCallInfo)89 ArkUINativeModuleValue NavigatorBridge::SetParams(ArkUIRuntimeCallInfo* runtimeCallInfo)
90 {
91 EcmaVM* vm = runtimeCallInfo->GetVM();
92 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
93 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
94 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
95 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
96 if (secondArg->IsUndefined()) {
97 GetArkUIInternalNodeAPI()->GetNavigatorModifier().ResetParams(nativeNode);
98 }
99 std::string params = secondArg->ToString(vm)->ToString();
100 GetArkUIInternalNodeAPI()->GetNavigatorModifier().SetParams(nativeNode, params.c_str());
101 return panda::JSValueRef::Undefined(vm);
102 }
103
ResetParams(ArkUIRuntimeCallInfo * runtimeCallInfo)104 ArkUINativeModuleValue NavigatorBridge::ResetParams(ArkUIRuntimeCallInfo* runtimeCallInfo)
105 {
106 EcmaVM* vm = runtimeCallInfo->GetVM();
107 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
108 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
109 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
110 GetArkUIInternalNodeAPI()->GetNavigatorModifier().ResetParams(nativeNode);
111 return panda::JSValueRef::Undefined(vm);
112 }
113 } // namespace OHOS::Ace::NG
114