1 /*
2 * Copyright (c) 2021-2022 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 "js_window.h"
17 #include <new>
18
19 #ifndef WINDOW_PREVIEW
20 #include "js_transition_controller.h"
21 #else
22 #include "mock/js_transition_controller.h"
23 #endif
24
25 #include "js_window_utils.h"
26 #include "window.h"
27 #include "window_helper.h"
28 #include "window_manager_hilog.h"
29 #include "window_option.h"
30 #include "wm_math.h"
31 #include "pixel_map.h"
32 #include "pixel_map_napi.h"
33 #include "napi_remote_object.h"
34 #include "permission.h"
35 #include "request_info.h"
36
37 namespace OHOS {
38 namespace Rosen {
39 using namespace AbilityRuntime;
40 namespace {
41 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JsWindow"};
42 constexpr Rect g_emptyRect = {0, 0, 0, 0};
43 }
44
45 static thread_local std::map<std::string, std::shared_ptr<NativeReference>> g_jsWindowMap;
46 std::recursive_mutex g_mutex;
47 static int ctorCnt = 0;
48 static int dtorCnt = 0;
49 static int finalizerCnt = 0;
JsWindow(const sptr<Window> & window)50 JsWindow::JsWindow(const sptr<Window>& window)
51 : windowToken_(window), registerManager_(std::make_unique<JsWindowRegisterManager>())
52 {
53 NotifyNativeWinDestroyFunc func = [](std::string windowName) {
54 std::lock_guard<std::recursive_mutex> lock(g_mutex);
55 if (windowName.empty() || g_jsWindowMap.count(windowName) == 0) {
56 WLOGFE("[NAPI]Can not find window %{public}s ", windowName.c_str());
57 return;
58 }
59 g_jsWindowMap.erase(windowName);
60 WLOGFD("[NAPI]Destroy window %{public}s in js window", windowName.c_str());
61 };
62 windowToken_->RegisterWindowDestroyedListener(func);
63 WLOGFD("[NAPI] constructorCnt: %{public}d", ++ctorCnt);
64 }
65
~JsWindow()66 JsWindow::~JsWindow()
67 {
68 WLOGFD("[NAPI] deConstructorCnt:%{public}d", ++dtorCnt);
69 windowToken_ = nullptr;
70 }
71
GetWindowName()72 std::string JsWindow::GetWindowName()
73 {
74 if (windowToken_ == nullptr) {
75 return "";
76 }
77 return windowToken_->GetWindowName();
78 }
79
Finalizer(NativeEngine * engine,void * data,void * hint)80 void JsWindow::Finalizer(NativeEngine* engine, void* data, void* hint)
81 {
82 WLOGFD("[NAPI]finalizerCnt:%{public}d", ++finalizerCnt);
83 auto jsWin = std::unique_ptr<JsWindow>(static_cast<JsWindow*>(data));
84 if (jsWin == nullptr) {
85 WLOGFE("[NAPI]jsWin is nullptr");
86 return;
87 }
88 std::string windowName = jsWin->GetWindowName();
89 WLOGFD("[NAPI]Window %{public}s", windowName.c_str());
90 std::lock_guard<std::recursive_mutex> lock(g_mutex);
91 g_jsWindowMap.erase(windowName);
92 WLOGFD("[NAPI]Remove window %{public}s from g_jsWindowMap", windowName.c_str());
93 }
94
Show(NativeEngine * engine,NativeCallbackInfo * info)95 NativeValue* JsWindow::Show(NativeEngine* engine, NativeCallbackInfo* info)
96 {
97 WLOGFD("[NAPI]Show");
98 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
99 return (me != nullptr) ? me->OnShow(*engine, *info) : nullptr;
100 }
101
ShowWindow(NativeEngine * engine,NativeCallbackInfo * info)102 NativeValue* JsWindow::ShowWindow(NativeEngine* engine, NativeCallbackInfo* info)
103 {
104 WLOGFD("[NAPI]Show");
105 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
106 return (me != nullptr) ? me->OnShowWindow(*engine, *info) : nullptr;
107 }
108
ShowWithAnimation(NativeEngine * engine,NativeCallbackInfo * info)109 NativeValue* JsWindow::ShowWithAnimation(NativeEngine* engine, NativeCallbackInfo* info)
110 {
111 WLOGFD("[NAPI]ShowWithAnimation");
112 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
113 return (me != nullptr) ? me->OnShowWithAnimation(*engine, *info) : nullptr;
114 }
115
Destroy(NativeEngine * engine,NativeCallbackInfo * info)116 NativeValue* JsWindow::Destroy(NativeEngine* engine, NativeCallbackInfo* info)
117 {
118 WLOGFD("[NAPI]Destroy");
119 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
120 return (me != nullptr) ? me->OnDestroy(*engine, *info) : nullptr;
121 }
122
DestroyWindow(NativeEngine * engine,NativeCallbackInfo * info)123 NativeValue* JsWindow::DestroyWindow(NativeEngine* engine, NativeCallbackInfo* info)
124 {
125 WLOGFD("[NAPI]Destroy");
126 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
127 return (me != nullptr) ? me->OnDestroyWindow(*engine, *info) : nullptr;
128 }
129
Hide(NativeEngine * engine,NativeCallbackInfo * info)130 NativeValue* JsWindow::Hide(NativeEngine* engine, NativeCallbackInfo* info)
131 {
132 WLOGFD("[NAPI]Hide");
133 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
134 return (me != nullptr) ? me->OnHide(*engine, *info) : nullptr;
135 }
136
HideWithAnimation(NativeEngine * engine,NativeCallbackInfo * info)137 NativeValue* JsWindow::HideWithAnimation(NativeEngine* engine, NativeCallbackInfo* info)
138 {
139 WLOGFD("[NAPI]HideWithAnimation");
140 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
141 return (me != nullptr) ? me->OnHideWithAnimation(*engine, *info) : nullptr;
142 }
143
MoveTo(NativeEngine * engine,NativeCallbackInfo * info)144 NativeValue* JsWindow::MoveTo(NativeEngine* engine, NativeCallbackInfo* info)
145 {
146 WLOGFD("[NAPI]MoveTo");
147 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
148 return (me != nullptr) ? me->OnMoveTo(*engine, *info) : nullptr;
149 }
150
MoveWindowTo(NativeEngine * engine,NativeCallbackInfo * info)151 NativeValue* JsWindow::MoveWindowTo(NativeEngine* engine, NativeCallbackInfo* info)
152 {
153 WLOGFD("[NAPI]MoveTo");
154 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
155 return (me != nullptr) ? me->OnMoveWindowTo(*engine, *info) : nullptr;
156 }
157
Resize(NativeEngine * engine,NativeCallbackInfo * info)158 NativeValue* JsWindow::Resize(NativeEngine* engine, NativeCallbackInfo* info)
159 {
160 WLOGFD("[NAPI]Resize");
161 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
162 return (me != nullptr) ? me->OnResize(*engine, *info) : nullptr;
163 }
164
ResizeWindow(NativeEngine * engine,NativeCallbackInfo * info)165 NativeValue* JsWindow::ResizeWindow(NativeEngine* engine, NativeCallbackInfo* info)
166 {
167 WLOGFD("[NAPI]Resize");
168 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
169 return (me != nullptr) ? me->OnResizeWindow(*engine, *info) : nullptr;
170 }
171
SetWindowType(NativeEngine * engine,NativeCallbackInfo * info)172 NativeValue* JsWindow::SetWindowType(NativeEngine* engine, NativeCallbackInfo* info)
173 {
174 WLOGFD("[NAPI]SetWindowType");
175 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
176 return (me != nullptr) ? me->OnSetWindowType(*engine, *info) : nullptr;
177 }
178
SetWindowMode(NativeEngine * engine,NativeCallbackInfo * info)179 NativeValue* JsWindow::SetWindowMode(NativeEngine* engine, NativeCallbackInfo* info)
180 {
181 WLOGFD("[NAPI]SetWindowMode");
182 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
183 return (me != nullptr) ? me->OnSetWindowMode(*engine, *info) : nullptr;
184 }
185
GetProperties(NativeEngine * engine,NativeCallbackInfo * info)186 NativeValue* JsWindow::GetProperties(NativeEngine* engine, NativeCallbackInfo* info)
187 {
188 WLOGFD("[NAPI]GetProperties");
189 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
190 return (me != nullptr) ? me->OnGetProperties(*engine, *info) : nullptr;
191 }
192
GetWindowPropertiesSync(NativeEngine * engine,NativeCallbackInfo * info)193 NativeValue* JsWindow::GetWindowPropertiesSync(NativeEngine* engine, NativeCallbackInfo* info)
194 {
195 WLOGFD("[NAPI]GetProperties");
196 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
197 return (me != nullptr) ? me->OnGetWindowPropertiesSync(*engine, *info) : nullptr;
198 }
199
RegisterWindowCallback(NativeEngine * engine,NativeCallbackInfo * info)200 NativeValue* JsWindow::RegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info)
201 {
202 WLOGFD("[NAPI]RegisterWindowCallback");
203 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
204 return (me != nullptr) ? me->OnRegisterWindowCallback(*engine, *info) : nullptr;
205 }
206
UnregisterWindowCallback(NativeEngine * engine,NativeCallbackInfo * info)207 NativeValue* JsWindow::UnregisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info)
208 {
209 WLOGFD("[NAPI]UnregisterWindowCallback");
210 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
211 return (me != nullptr) ? me->OnUnregisterWindowCallback(*engine, *info) : nullptr;
212 }
213
BindDialogTarget(NativeEngine * engine,NativeCallbackInfo * info)214 NativeValue* JsWindow::BindDialogTarget(NativeEngine* engine, NativeCallbackInfo* info)
215 {
216 WLOGFD("[NAPI]BindDialogTarget");
217 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
218 return (me != nullptr) ? me->OnBindDialogTarget(*engine, *info) : nullptr;
219 }
220
LoadContent(NativeEngine * engine,NativeCallbackInfo * info)221 NativeValue* JsWindow::LoadContent(NativeEngine* engine, NativeCallbackInfo* info)
222 {
223 WLOGFD("[NAPI]LoadContent");
224 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
225 return (me != nullptr) ? me->OnLoadContent(*engine, *info) : nullptr;
226 }
227
SetUIContent(NativeEngine * engine,NativeCallbackInfo * info)228 NativeValue* JsWindow::SetUIContent(NativeEngine* engine, NativeCallbackInfo* info)
229 {
230 WLOGFD("[NAPI]LoadContent");
231 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
232 return (me != nullptr) ? me->OnSetUIContent(*engine, *info) : nullptr;
233 }
234
SetFullScreen(NativeEngine * engine,NativeCallbackInfo * info)235 NativeValue* JsWindow::SetFullScreen(NativeEngine* engine, NativeCallbackInfo* info)
236 {
237 WLOGFD("[NAPI]SetFullScreen");
238 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
239 return (me != nullptr) ? me->OnSetFullScreen(*engine, *info) : nullptr;
240 }
241
SetLayoutFullScreen(NativeEngine * engine,NativeCallbackInfo * info)242 NativeValue* JsWindow::SetLayoutFullScreen(NativeEngine* engine, NativeCallbackInfo* info)
243 {
244 WLOGFD("[NAPI]SetLayoutFullScreen");
245 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
246 return (me != nullptr) ? me->OnSetLayoutFullScreen(*engine, *info) : nullptr;
247 }
248
SetWindowLayoutFullScreen(NativeEngine * engine,NativeCallbackInfo * info)249 NativeValue* JsWindow::SetWindowLayoutFullScreen(NativeEngine* engine, NativeCallbackInfo* info)
250 {
251 WLOGFD("[NAPI]SetLayoutFullScreen");
252 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
253 return (me != nullptr) ? me->OnSetWindowLayoutFullScreen(*engine, *info) : nullptr;
254 }
255
SetSystemBarEnable(NativeEngine * engine,NativeCallbackInfo * info)256 NativeValue* JsWindow::SetSystemBarEnable(NativeEngine* engine, NativeCallbackInfo* info)
257 {
258 WLOGFD("[NAPI]SetSystemBarEnable");
259 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
260 return (me != nullptr) ? me->OnSetSystemBarEnable(*engine, *info) : nullptr;
261 }
262
SetWindowSystemBarEnable(NativeEngine * engine,NativeCallbackInfo * info)263 NativeValue* JsWindow::SetWindowSystemBarEnable(NativeEngine* engine, NativeCallbackInfo* info)
264 {
265 WLOGFD("[NAPI]SetSystemBarEnable");
266 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
267 return (me != nullptr) ? me->OnSetWindowSystemBarEnable(*engine, *info) : nullptr;
268 }
269
SetSystemBarProperties(NativeEngine * engine,NativeCallbackInfo * info)270 NativeValue* JsWindow::SetSystemBarProperties(NativeEngine* engine, NativeCallbackInfo* info)
271 {
272 WLOGFD("[NAPI]SetSystemBarProperties");
273 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
274 return (me != nullptr) ? me->OnSetSystemBarProperties(*engine, *info) : nullptr;
275 }
276
SetWindowSystemBarProperties(NativeEngine * engine,NativeCallbackInfo * info)277 NativeValue* JsWindow::SetWindowSystemBarProperties(NativeEngine* engine, NativeCallbackInfo* info)
278 {
279 WLOGFD("[NAPI]SetWindowSystemBarProperties");
280 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
281 return (me != nullptr) ? me->OnSetWindowSystemBarProperties(*engine, *info) : nullptr;
282 }
283
GetAvoidArea(NativeEngine * engine,NativeCallbackInfo * info)284 NativeValue* JsWindow::GetAvoidArea(NativeEngine* engine, NativeCallbackInfo* info)
285 {
286 WLOGFD("[NAPI]GetAvoidArea");
287 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
288 return (me != nullptr) ? me->OnGetAvoidArea(*engine, *info) : nullptr;
289 }
290
GetWindowAvoidAreaSync(NativeEngine * engine,NativeCallbackInfo * info)291 NativeValue* JsWindow::GetWindowAvoidAreaSync(NativeEngine* engine, NativeCallbackInfo* info)
292 {
293 WLOGFD("[NAPI]GetAvoidArea");
294 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
295 return (me != nullptr) ? me->OnGetWindowAvoidAreaSync(*engine, *info) : nullptr;
296 }
297
IsShowing(NativeEngine * engine,NativeCallbackInfo * info)298 NativeValue* JsWindow::IsShowing(NativeEngine* engine, NativeCallbackInfo* info)
299 {
300 WLOGFD("[NAPI]IsShowing");
301 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
302 return (me != nullptr) ? me->OnIsShowing(*engine, *info) : nullptr;
303 }
304
IsWindowShowingSync(NativeEngine * engine,NativeCallbackInfo * info)305 NativeValue* JsWindow::IsWindowShowingSync(NativeEngine* engine, NativeCallbackInfo* info)
306 {
307 WLOGFD("[NAPI]IsShowing");
308 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
309 return (me != nullptr) ? me->OnIsWindowShowingSync(*engine, *info) : nullptr;
310 }
311
IsSupportWideGamut(NativeEngine * engine,NativeCallbackInfo * info)312 NativeValue* JsWindow::IsSupportWideGamut(NativeEngine* engine, NativeCallbackInfo* info)
313 {
314 WLOGFD("[NAPI]IsSupportWideGamut");
315 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
316 return (me != nullptr) ? me->OnIsSupportWideGamut(*engine, *info) : nullptr;
317 }
318
IsWindowSupportWideGamut(NativeEngine * engine,NativeCallbackInfo * info)319 NativeValue* JsWindow::IsWindowSupportWideGamut(NativeEngine* engine, NativeCallbackInfo* info)
320 {
321 WLOGFD("[NAPI]IsSupportWideGamut");
322 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
323 return (me != nullptr) ? me->OnIsWindowSupportWideGamut(*engine, *info) : nullptr;
324 }
325
SetBackgroundColor(NativeEngine * engine,NativeCallbackInfo * info)326 NativeValue* JsWindow::SetBackgroundColor(NativeEngine* engine, NativeCallbackInfo* info)
327 {
328 WLOGFD("[NAPI]SetBackgroundColor");
329 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
330 return (me != nullptr) ? me->OnSetBackgroundColor(*engine, *info) : nullptr;
331 }
332
SetWindowBackgroundColorSync(NativeEngine * engine,NativeCallbackInfo * info)333 NativeValue* JsWindow::SetWindowBackgroundColorSync(NativeEngine* engine, NativeCallbackInfo* info)
334 {
335 WLOGFD("[NAPI]SetBackgroundColor");
336 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
337 return (me != nullptr) ? me->OnSetWindowBackgroundColorSync(*engine, *info) : nullptr;
338 }
339
SetBrightness(NativeEngine * engine,NativeCallbackInfo * info)340 NativeValue* JsWindow::SetBrightness(NativeEngine* engine, NativeCallbackInfo* info)
341 {
342 WLOGFD("[NAPI]SetBrightness");
343 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
344 return (me != nullptr) ? me->OnSetBrightness(*engine, *info) : nullptr;
345 }
346
SetWindowBrightness(NativeEngine * engine,NativeCallbackInfo * info)347 NativeValue* JsWindow::SetWindowBrightness(NativeEngine* engine, NativeCallbackInfo* info)
348 {
349 WLOGFD("[NAPI]SetBrightness");
350 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
351 return (me != nullptr) ? me->OnSetWindowBrightness(*engine, *info) : nullptr;
352 }
353
SetDimBehind(NativeEngine * engine,NativeCallbackInfo * info)354 NativeValue* JsWindow::SetDimBehind(NativeEngine* engine, NativeCallbackInfo* info)
355 {
356 WLOGFD("[NAPI]SetDimBehind");
357 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
358 return (me != nullptr) ? me->OnSetDimBehind(*engine, *info) : nullptr;
359 }
360
SetFocusable(NativeEngine * engine,NativeCallbackInfo * info)361 NativeValue* JsWindow::SetFocusable(NativeEngine* engine, NativeCallbackInfo* info)
362 {
363 WLOGFD("[NAPI]SetFocusable");
364 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
365 return (me != nullptr) ? me->OnSetFocusable(*engine, *info) : nullptr;
366 }
367
SetWindowFocusable(NativeEngine * engine,NativeCallbackInfo * info)368 NativeValue* JsWindow::SetWindowFocusable(NativeEngine* engine, NativeCallbackInfo* info)
369 {
370 WLOGFD("[NAPI]SetFocusable");
371 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
372 return (me != nullptr) ? me->OnSetWindowFocusable(*engine, *info) : nullptr;
373 }
374
SetKeepScreenOn(NativeEngine * engine,NativeCallbackInfo * info)375 NativeValue* JsWindow::SetKeepScreenOn(NativeEngine* engine, NativeCallbackInfo* info)
376 {
377 WLOGFD("[NAPI]SetKeepScreenOn");
378 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
379 return (me != nullptr) ? me->OnSetKeepScreenOn(*engine, *info) : nullptr;
380 }
381
SetWindowKeepScreenOn(NativeEngine * engine,NativeCallbackInfo * info)382 NativeValue* JsWindow::SetWindowKeepScreenOn(NativeEngine* engine, NativeCallbackInfo* info)
383 {
384 WLOGFD("[NAPI]SetKeepScreenOn");
385 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
386 return (me != nullptr) ? me->OnSetWindowKeepScreenOn(*engine, *info) : nullptr;
387 }
388
SetWakeUpScreen(NativeEngine * engine,NativeCallbackInfo * info)389 NativeValue* JsWindow::SetWakeUpScreen(NativeEngine* engine, NativeCallbackInfo* info)
390 {
391 WLOGFD("[NAPI]SetWakeUpScreen");
392 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
393 return (me != nullptr) ? me->OnSetWakeUpScreen(*engine, *info) : nullptr;
394 }
395
SetOutsideTouchable(NativeEngine * engine,NativeCallbackInfo * info)396 NativeValue* JsWindow::SetOutsideTouchable(NativeEngine* engine, NativeCallbackInfo* info)
397 {
398 WLOGFD("[NAPI]SetOutsideTouchable");
399 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
400 return (me != nullptr) ? me->OnSetOutsideTouchable(*engine, *info) : nullptr;
401 }
402
SetPrivacyMode(NativeEngine * engine,NativeCallbackInfo * info)403 NativeValue* JsWindow::SetPrivacyMode(NativeEngine* engine, NativeCallbackInfo* info)
404 {
405 WLOGFD("[NAPI]SetPrivacyMode");
406 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
407 return (me != nullptr) ? me->OnSetPrivacyMode(*engine, *info) : nullptr;
408 }
409
SetWindowPrivacyMode(NativeEngine * engine,NativeCallbackInfo * info)410 NativeValue* JsWindow::SetWindowPrivacyMode(NativeEngine* engine, NativeCallbackInfo* info)
411 {
412 WLOGFD("[NAPI]SetPrivacyMode");
413 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
414 return (me != nullptr) ? me->OnSetWindowPrivacyMode(*engine, *info) : nullptr;
415 }
416
SetTouchable(NativeEngine * engine,NativeCallbackInfo * info)417 NativeValue* JsWindow::SetTouchable(NativeEngine* engine, NativeCallbackInfo* info)
418 {
419 WLOGFD("[NAPI]SetTouchable");
420 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
421 return (me != nullptr) ? me->OnSetTouchable(*engine, *info) : nullptr;
422 }
423
SetWindowTouchable(NativeEngine * engine,NativeCallbackInfo * info)424 NativeValue* JsWindow::SetWindowTouchable(NativeEngine* engine, NativeCallbackInfo* info)
425 {
426 WLOGFD("[NAPI]SetTouchable");
427 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
428 return (me != nullptr) ? me->OnSetWindowTouchable(*engine, *info) : nullptr;
429 }
430
SetTransparent(NativeEngine * engine,NativeCallbackInfo * info)431 NativeValue* JsWindow::SetTransparent(NativeEngine* engine, NativeCallbackInfo* info)
432 {
433 WLOGFD("[NAPI]SetTransparent");
434 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
435 return (me != nullptr) ? me->OnSetTransparent(*engine, *info) : nullptr;
436 }
437
SetCallingWindow(NativeEngine * engine,NativeCallbackInfo * info)438 NativeValue* JsWindow::SetCallingWindow(NativeEngine* engine, NativeCallbackInfo* info)
439 {
440 WLOGFD("[NAPI]SetCallingWindow");
441 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
442 return (me != nullptr) ? me->OnSetCallingWindow(*engine, *info) : nullptr;
443 }
444
SetPreferredOrientation(NativeEngine * engine,NativeCallbackInfo * info)445 NativeValue* JsWindow::SetPreferredOrientation(NativeEngine* engine, NativeCallbackInfo* info)
446 {
447 WLOGFD("[NAPI]SetPreferredOrientation");
448 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
449 return (me != nullptr) ? me->OnSetPreferredOrientation(*engine, *info) : nullptr;
450 }
451
SetSnapshotSkip(NativeEngine * engine,NativeCallbackInfo * info)452 NativeValue* JsWindow::SetSnapshotSkip(NativeEngine* engine, NativeCallbackInfo* info)
453 {
454 WLOGFD("NAPI");
455 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
456 return (me != nullptr) ? me->OnSetSnapshotSkip(*engine, *info) : nullptr;
457 }
458
DisableWindowDecor(NativeEngine * engine,NativeCallbackInfo * info)459 NativeValue* JsWindow::DisableWindowDecor(NativeEngine* engine, NativeCallbackInfo* info)
460 {
461 WLOGFD("[NAPI]DisableWindowDecor");
462 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
463 return (me != nullptr) ? me->OnDisableWindowDecor(*engine, *info) : nullptr;
464 }
465
SetColorSpace(NativeEngine * engine,NativeCallbackInfo * info)466 NativeValue* JsWindow::SetColorSpace(NativeEngine* engine, NativeCallbackInfo* info)
467 {
468 WLOGFD("[NAPI]SetColorSpace");
469 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
470 return (me != nullptr) ? me->OnSetColorSpace(*engine, *info) : nullptr;
471 }
472
SetWindowColorSpace(NativeEngine * engine,NativeCallbackInfo * info)473 NativeValue* JsWindow::SetWindowColorSpace(NativeEngine* engine, NativeCallbackInfo* info)
474 {
475 WLOGFD("[NAPI]SetColorSpace");
476 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
477 return (me != nullptr) ? me->OnSetWindowColorSpace(*engine, *info) : nullptr;
478 }
479
GetColorSpace(NativeEngine * engine,NativeCallbackInfo * info)480 NativeValue* JsWindow::GetColorSpace(NativeEngine* engine, NativeCallbackInfo* info)
481 {
482 WLOGFD("[NAPI]GetColorSpace");
483 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
484 return (me != nullptr) ? me->OnGetColorSpace(*engine, *info) : nullptr;
485 }
486
GetWindowColorSpaceSync(NativeEngine * engine,NativeCallbackInfo * info)487 NativeValue* JsWindow::GetWindowColorSpaceSync(NativeEngine* engine, NativeCallbackInfo* info)
488 {
489 WLOGFD("[NAPI]GetColorSpace");
490 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
491 return (me != nullptr) ? me->OnGetWindowColorSpaceSync(*engine, *info) : nullptr;
492 }
493
Dump(NativeEngine * engine,NativeCallbackInfo * info)494 NativeValue* JsWindow::Dump(NativeEngine* engine, NativeCallbackInfo* info)
495 {
496 WLOGFD("[NAPI]Dump");
497 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
498 return (me != nullptr) ? me->OnDump(*engine, *info) : nullptr;
499 }
500
SetForbidSplitMove(NativeEngine * engine,NativeCallbackInfo * info)501 NativeValue* JsWindow::SetForbidSplitMove(NativeEngine* engine, NativeCallbackInfo* info)
502 {
503 WLOGFD("[NAPI]SetForbidSplitMove");
504 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
505 return (me != nullptr) ? me->OnSetForbidSplitMove(*engine, *info) : nullptr;
506 }
507
Opacity(NativeEngine * engine,NativeCallbackInfo * info)508 NativeValue* JsWindow::Opacity(NativeEngine* engine, NativeCallbackInfo* info)
509 {
510 WLOGFD("[NAPI]Opacity");
511 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
512 return (me != nullptr) ? me->OnOpacity(*engine, *info) : nullptr;
513 }
514
Scale(NativeEngine * engine,NativeCallbackInfo * info)515 NativeValue* JsWindow::Scale(NativeEngine* engine, NativeCallbackInfo* info)
516 {
517 WLOGFD("[NAPI]Scale");
518 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
519 return (me != nullptr) ? me->OnScale(*engine, *info) : nullptr;
520 }
521
Rotate(NativeEngine * engine,NativeCallbackInfo * info)522 NativeValue* JsWindow::Rotate(NativeEngine* engine, NativeCallbackInfo* info)
523 {
524 WLOGFD("[NAPI]Rotate");
525 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
526 return (me != nullptr) ? me->OnRotate(*engine, *info) : nullptr;
527 }
528
Translate(NativeEngine * engine,NativeCallbackInfo * info)529 NativeValue* JsWindow::Translate(NativeEngine* engine, NativeCallbackInfo* info)
530 {
531 WLOGFD("[NAPI]Translate");
532 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
533 return (me != nullptr) ? me->OnTranslate(*engine, *info) : nullptr;
534 }
535
GetTransitionController(NativeEngine * engine,NativeCallbackInfo * info)536 NativeValue* JsWindow::GetTransitionController(NativeEngine* engine, NativeCallbackInfo* info)
537 {
538 WLOGFD("[NAPI]GetTransitionController");
539 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
540 return (me != nullptr) ? me->OnGetTransitionController(*engine, *info) : nullptr;
541 }
542
SetCornerRadius(NativeEngine * engine,NativeCallbackInfo * info)543 NativeValue* JsWindow::SetCornerRadius(NativeEngine* engine, NativeCallbackInfo* info)
544 {
545 WLOGFD("[NAPI]SetCornerRadius");
546 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
547 return (me != nullptr) ? me->OnSetCornerRadius(*engine, *info) : nullptr;
548 }
549
SetShadow(NativeEngine * engine,NativeCallbackInfo * info)550 NativeValue* JsWindow::SetShadow(NativeEngine* engine, NativeCallbackInfo* info)
551 {
552 WLOGFD("[NAPI]SetShadow");
553 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
554 return (me != nullptr) ? me->OnSetShadow(*engine, *info) : nullptr;
555 }
556
SetBlur(NativeEngine * engine,NativeCallbackInfo * info)557 NativeValue* JsWindow::SetBlur(NativeEngine* engine, NativeCallbackInfo* info)
558 {
559 WLOGFD("[NAPI]SetBlur");
560 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
561 return (me != nullptr) ? me->OnSetBlur(*engine, *info) : nullptr;
562 }
563
SetBackdropBlur(NativeEngine * engine,NativeCallbackInfo * info)564 NativeValue* JsWindow::SetBackdropBlur(NativeEngine* engine, NativeCallbackInfo* info)
565 {
566 WLOGFD("[NAPI]SetBackdropBlur");
567 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
568 return (me != nullptr) ? me->OnSetBackdropBlur(*engine, *info) : nullptr;
569 }
570
SetBackdropBlurStyle(NativeEngine * engine,NativeCallbackInfo * info)571 NativeValue* JsWindow::SetBackdropBlurStyle(NativeEngine* engine, NativeCallbackInfo* info)
572 {
573 WLOGFD("[NAPI]SetBackdropBlurStyle");
574 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
575 return (me != nullptr) ? me->OnSetBackdropBlurStyle(*engine, *info) : nullptr;
576 }
577
OnShow(NativeEngine & engine,NativeCallbackInfo & info)578 NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info)
579 {
580 WMError errCode = WMError::WM_OK;
581 if (info.argc > 1) {
582 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
583 errCode = WMError::WM_ERROR_INVALID_PARAM;
584 }
585 wptr<Window> weakToken(windowToken_);
586 AsyncTask::CompleteCallback complete =
587 [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
588 auto weakWindow = weakToken.promote();
589 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
590 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
591 WLOGFE("[NAPI]window is nullptr or get invalid param");
592 return;
593 }
594 WMError ret = weakWindow->Show(0, false);
595 if (ret == WMError::WM_OK) {
596 task.Resolve(engine, engine.CreateUndefined());
597 } else {
598 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window show failed"));
599 }
600 WLOGFD("[NAPI]Window [%{public}u, %{public}s] show end, ret = %{public}d",
601 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
602 };
603 NativeValue* result = nullptr;
604 NativeValue* lastParam = (info.argc == 0) ? nullptr :
605 (info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
606 AsyncTask::Schedule("JsWindow::OnShow",
607 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
608 return result;
609 }
610
OnShowWindow(NativeEngine & engine,NativeCallbackInfo & info)611 NativeValue* JsWindow::OnShowWindow(NativeEngine& engine, NativeCallbackInfo& info)
612 {
613 wptr<Window> weakToken(windowToken_);
614 AsyncTask::CompleteCallback complete =
615 [weakToken](NativeEngine& engine, AsyncTask& task, int32_t status) {
616 auto weakWindow = weakToken.promote();
617 if (weakWindow == nullptr) {
618 task.Reject(engine, CreateJsError(engine,
619 static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
620 WLOGFE("[NAPI]window is nullptr or get invalid param");
621 return;
622 }
623 WMError ret = weakWindow->Show(0, false);
624 if (ret == WMError::WM_OK) {
625 task.Resolve(engine, engine.CreateUndefined());
626 } else {
627 task.Reject(engine, CreateJsError(engine,
628 static_cast<int32_t>(WM_JS_TO_ERROR_CODE_MAP.at(ret)), "Window show failed"));
629 }
630 WLOGFD("[NAPI]Window [%{public}u, %{public}s] show end, ret = %{public}d",
631 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
632 };
633 NativeValue* result = nullptr;
634 NativeValue* lastParam = (info.argc == 0) ? nullptr :
635 ((info.argv[0] != nullptr && info.argv[0]->TypeOf() == NATIVE_FUNCTION) ?
636 info.argv[0] : nullptr);
637 AsyncTask::Schedule("JsWindow::OnShow",
638 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
639 return result;
640 }
641
OnShowWithAnimation(NativeEngine & engine,NativeCallbackInfo & info)642 NativeValue* JsWindow::OnShowWithAnimation(NativeEngine& engine, NativeCallbackInfo& info)
643 {
644 WmErrorCode errCode = WmErrorCode::WM_OK;
645 auto winType = windowToken_->GetType();
646 if (!WindowHelper::IsSystemWindow(winType)) {
647 WLOGFE("[NAPI]window Type %{public}u is not supported", static_cast<uint32_t>(winType));
648 errCode = WmErrorCode::WM_ERROR_INVALID_CALLING;
649 }
650 wptr<Window> weakToken(windowToken_);
651 AsyncTask::CompleteCallback complete =
652 [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
653 if (errCode != WmErrorCode::WM_OK) {
654 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
655 return;
656 }
657 auto weakWindow = weakToken.promote();
658 if (weakWindow == nullptr) {
659 WLOGFE("[NAPI]window is nullptr");
660 task.Reject(engine, CreateJsError(engine,
661 static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
662 return;
663 }
664 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->Show(0, true));
665 if (ret == WmErrorCode::WM_OK) {
666 task.Resolve(engine, engine.CreateUndefined());
667 } else {
668 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window show failed"));
669 }
670 WLOGFD("[NAPI]Window [%{public}u, %{public}s] ShowWithAnimation end, ret = %{public}d",
671 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
672 };
673 NativeValue* result = nullptr;
674 NativeValue* lastParam = (info.argc == 0) ? nullptr :
675 ((info.argv[0] != nullptr && info.argv[0]->TypeOf() == NATIVE_FUNCTION) ?
676 info.argv[0] : nullptr);
677 AsyncTask::Schedule("JsWindow::OnShowWithAnimation",
678 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
679 return result;
680 }
681
OnDestroy(NativeEngine & engine,NativeCallbackInfo & info)682 NativeValue* JsWindow::OnDestroy(NativeEngine& engine, NativeCallbackInfo& info)
683 {
684 WMError errCode = WMError::WM_OK;
685 if (info.argc > 1) {
686 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
687 errCode = WMError::WM_ERROR_INVALID_PARAM;
688 }
689 wptr<Window> weakToken(windowToken_);
690 AsyncTask::CompleteCallback complete =
691 [this, weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
692 auto weakWindow = weakToken.promote();
693 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
694 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
695 WLOGFE("[NAPI]window is nullptr or get invalid param");
696 return;
697 }
698 WMError ret = weakWindow->Destroy();
699 WLOGFD("[NAPI]Window [%{public}u, %{public}s] destroy end, ret = %{public}d",
700 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
701 if (ret != WMError::WM_OK) {
702 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window destroy failed"));
703 return;
704 }
705 windowToken_ = nullptr; // ensure window dtor when finalizer invalid
706 task.Resolve(engine, engine.CreateUndefined());
707 };
708
709 NativeValue* lastParam = (info.argc == 0) ? nullptr :
710 (info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
711 NativeValue* result = nullptr;
712 AsyncTask::Schedule("JsWindow::OnDestroy",
713 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
714 return result;
715 }
716
OnDestroyWindow(NativeEngine & engine,NativeCallbackInfo & info)717 NativeValue* JsWindow::OnDestroyWindow(NativeEngine& engine, NativeCallbackInfo& info)
718 {
719 wptr<Window> weakToken(windowToken_);
720 AsyncTask::CompleteCallback complete =
721 [this, weakToken](NativeEngine& engine, AsyncTask& task, int32_t status) {
722 auto weakWindow = weakToken.promote();
723 if (weakWindow == nullptr) {
724 WLOGFE("[NAPI]window is nullptr or get invalid param");
725 task.Reject(engine,
726 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
727 return;
728 }
729 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->Destroy());
730 WLOGFD("[NAPI]Window [%{public}u, %{public}s] destroy end, ret = %{public}d",
731 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
732 if (ret != WmErrorCode::WM_OK) {
733 task.Reject(engine,
734 CreateJsError(engine, static_cast<int32_t>(ret),
735 "Window destroy failed"));
736 return;
737 }
738 windowToken_ = nullptr; // ensure window dtor when finalizer invalid
739 task.Resolve(engine, engine.CreateUndefined());
740 };
741
742 NativeValue* lastParam = (info.argc == 0) ? nullptr :
743 ((info.argv[0] != nullptr && info.argv[0]->TypeOf() == NATIVE_FUNCTION) ?
744 info.argv[0] : nullptr);
745 NativeValue* result = nullptr;
746 AsyncTask::Schedule("JsWindow::OnDestroyWindow",
747 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
748 return result;
749 }
750
OnHide(NativeEngine & engine,NativeCallbackInfo & info)751 NativeValue* JsWindow::OnHide(NativeEngine& engine, NativeCallbackInfo& info)
752 {
753 wptr<Window> weakToken(windowToken_);
754 AsyncTask::CompleteCallback complete =
755 [weakToken](NativeEngine& engine, AsyncTask& task, int32_t status) {
756 auto weakWindow = weakToken.promote();
757 if (weakWindow == nullptr) {
758 WLOGFE("[NAPI]window is nullptr or get invalid param");
759 task.Reject(engine,
760 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
761 return;
762 }
763 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->Hide(0, false));
764 if (ret == WmErrorCode::WM_OK) {
765 task.Resolve(engine, engine.CreateUndefined());
766 } else {
767 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window hide failed"));
768 }
769 WLOGFD("[NAPI]Window [%{public}u, %{public}s] hide end, ret = %{public}d",
770 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
771 };
772
773 NativeValue* result = nullptr;
774 NativeValue* lastParam = (info.argc == 0) ? nullptr :
775 (info.argv[0] != nullptr && info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
776 AsyncTask::Schedule("JsWindow::OnHide",
777 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
778 return result;
779 }
780
OnHideWithAnimation(NativeEngine & engine,NativeCallbackInfo & info)781 NativeValue* JsWindow::OnHideWithAnimation(NativeEngine& engine, NativeCallbackInfo& info)
782 {
783 WmErrorCode errCode = WmErrorCode::WM_OK;
784 if (windowToken_) {
785 auto winType = windowToken_->GetType();
786 if (!WindowHelper::IsSystemWindow(winType)) {
787 WLOGFE("[NAPI]window Type %{public}u is not supported", static_cast<uint32_t>(winType));
788 errCode = WmErrorCode::WM_ERROR_INVALID_CALLING;
789 }
790 } else {
791 errCode = WmErrorCode::WM_ERROR_INVALID_CALLING;
792 }
793 wptr<Window> weakToken(windowToken_);
794 AsyncTask::CompleteCallback complete =
795 [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
796 if (errCode != WmErrorCode::WM_OK) {
797 task.Reject(engine,
798 CreateJsError(engine, static_cast<int32_t>(errCode)));
799 return;
800 }
801 auto weakWindow = weakToken.promote();
802 if (weakWindow == nullptr) {
803 WLOGFE("[NAPI]window is nullptr");
804 task.Reject(engine,
805 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
806 return;
807 }
808 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->Hide(0, true));
809 if (ret == WmErrorCode::WM_OK) {
810 task.Resolve(engine, engine.CreateUndefined());
811 } else {
812 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window show failed"));
813 }
814 WLOGFD("[NAPI]Window [%{public}u, %{public}s] HideWithAnimation end, ret = %{public}d",
815 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
816 };
817 NativeValue* result = nullptr;
818 NativeValue* lastParam = (info.argc == 0) ? nullptr :
819 ((info.argv[0] != nullptr && info.argv[0]->TypeOf() == NATIVE_FUNCTION) ?
820 info.argv[0] : nullptr);
821 AsyncTask::Schedule("JsWindow::OnHideWithAnimation",
822 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
823 return result;
824 }
825
OnMoveTo(NativeEngine & engine,NativeCallbackInfo & info)826 NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info)
827 {
828 WMError errCode = WMError::WM_OK;
829 if (info.argc < 2 || info.argc > 3) { // 2:minimum param num, 3: maximum param num
830 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
831 errCode = WMError::WM_ERROR_INVALID_PARAM;
832 }
833 int32_t x = 0;
834 if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[0], x)) {
835 WLOGFE("[NAPI]Failed to convert parameter to x");
836 errCode = WMError::WM_ERROR_INVALID_PARAM;
837 }
838
839 int32_t y = 0;
840 if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[1], y)) {
841 WLOGFE("[NAPI]Failed to convert parameter to y");
842 errCode = WMError::WM_ERROR_INVALID_PARAM;
843 }
844
845 wptr<Window> weakToken(windowToken_);
846 AsyncTask::CompleteCallback complete =
847 [weakToken, errCode, x, y](NativeEngine& engine, AsyncTask& task, int32_t status) {
848 auto weakWindow = weakToken.promote();
849 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
850 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
851 WLOGFE("[NAPI]window is nullptr or get invalid param");
852 return;
853 }
854 WMError ret = weakWindow->MoveTo(x, y);
855 if (ret == WMError::WM_OK) {
856 task.Resolve(engine, engine.CreateUndefined());
857 } else {
858 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window move failed"));
859 }
860 WLOGFD("[NAPI]Window [%{public}u, %{public}s] move end, ret = %{public}d",
861 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
862 };
863 // 2: params num; 2: index of callback
864 NativeValue* lastParam = (info.argc <= 2) ? nullptr :
865 (info.argv[2]->TypeOf() == NATIVE_FUNCTION ? info.argv[2] : nullptr);
866 NativeValue* result = nullptr;
867 AsyncTask::Schedule("JsWindow::OnMoveTo",
868 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
869 return result;
870 }
871
OnMoveWindowTo(NativeEngine & engine,NativeCallbackInfo & info)872 NativeValue* JsWindow::OnMoveWindowTo(NativeEngine& engine, NativeCallbackInfo& info)
873 {
874 WmErrorCode errCode = WmErrorCode::WM_OK;
875 if (info.argc < 2) { // 2:minimum param num
876 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
877 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
878 }
879 int32_t x = 0;
880 if (errCode == WmErrorCode::WM_OK && !ConvertFromJsValue(engine, info.argv[0], x)) {
881 WLOGFE("[NAPI]Failed to convert parameter to x");
882 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
883 }
884 int32_t y = 0;
885 if (errCode == WmErrorCode::WM_OK && !ConvertFromJsValue(engine, info.argv[1], y)) {
886 WLOGFE("[NAPI]Failed to convert parameter to y");
887 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
888 }
889 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
890 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
891 return engine.CreateUndefined();
892 }
893
894 wptr<Window> weakToken(windowToken_);
895 AsyncTask::CompleteCallback complete =
896 [weakToken, x, y](NativeEngine& engine, AsyncTask& task, int32_t status) {
897 auto weakWindow = weakToken.promote();
898 if (weakWindow == nullptr) {
899 WLOGFE("[NAPI]window is nullptr");
900 task.Reject(engine, CreateJsError(engine,
901 static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
902 return;
903 }
904 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->MoveTo(x, y));
905 if (ret == WmErrorCode::WM_OK) {
906 task.Resolve(engine, engine.CreateUndefined());
907 } else {
908 task.Reject(engine,
909 CreateJsError(engine, static_cast<int32_t>(ret),
910 "Window move failed"));
911 }
912 WLOGFD("[NAPI]Window [%{public}u, %{public}s] move end, ret = %{public}d",
913 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
914 };
915
916 // 2: params num; 2: index of callback
917 NativeValue* lastParam = (info.argc <= 2) ? nullptr :
918 ((info.argv[2] != nullptr && info.argv[2]->TypeOf() == NATIVE_FUNCTION) ?
919 info.argv[2] : nullptr);
920 NativeValue* result = nullptr;
921 AsyncTask::Schedule("JsWindow::OnMoveWindowTo",
922 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
923 return result;
924 }
925
OnResize(NativeEngine & engine,NativeCallbackInfo & info)926 NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info)
927 {
928 WMError errCode = WMError::WM_OK;
929 if (info.argc < 2 || info.argc > 3) { // 2: minimum param num, 3: maximum param num
930 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
931 errCode = WMError::WM_ERROR_INVALID_PARAM;
932 }
933 int32_t width = 0;
934 if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[0], width)) {
935 WLOGFE("[NAPI]Failed to convert parameter to width");
936 errCode = WMError::WM_ERROR_INVALID_PARAM;
937 }
938 int32_t height = 0;
939 if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[1], height)) {
940 WLOGFE("[NAPI]Failed to convert parameter to height");
941 errCode = WMError::WM_ERROR_INVALID_PARAM;
942 }
943 if (width <= 0 || height <= 0) {
944 WLOGFE("[NAPI]width or height should greater than 0!");
945 errCode = WMError::WM_ERROR_INVALID_PARAM;
946 }
947 wptr<Window> weakToken(windowToken_);
948 AsyncTask::CompleteCallback complete =
949 [weakToken, errCode, width, height](NativeEngine& engine, AsyncTask& task, int32_t status) {
950 auto weakWindow = weakToken.promote();
951 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
952 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
953 WLOGFE("[NAPI]window is nullptr or get invalid param");
954 return;
955 }
956 WMError ret = weakWindow->Resize(static_cast<uint32_t>(width), static_cast<uint32_t>(height));
957 if (ret == WMError::WM_OK) {
958 task.Resolve(engine, engine.CreateUndefined());
959 } else {
960 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window resize failed"));
961 }
962 WLOGFD("[NAPI]Window [%{public}u, %{public}s] resize end, ret = %{public}d",
963 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
964 };
965 // 2: params num; 2: index of callback
966 NativeValue* lastParam = (info.argc <= 2) ? nullptr :
967 (info.argv[2]->TypeOf() == NATIVE_FUNCTION ? info.argv[2] : nullptr);
968 NativeValue* result = nullptr;
969 AsyncTask::Schedule("JsWindow::OnResize",
970 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
971 return result;
972 }
973
OnResizeWindow(NativeEngine & engine,NativeCallbackInfo & info)974 NativeValue* JsWindow::OnResizeWindow(NativeEngine& engine, NativeCallbackInfo& info)
975 {
976 WmErrorCode errCode = WmErrorCode::WM_OK;
977 if (info.argc < 2) { // 2: minimum param num
978 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
979 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
980 }
981 int32_t width = 0;
982 if (errCode == WmErrorCode::WM_OK && !ConvertFromJsValue(engine, info.argv[0], width)) {
983 WLOGFE("[NAPI]Failed to convert parameter to width");
984 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
985 }
986 int32_t height = 0;
987 if (errCode == WmErrorCode::WM_OK && !ConvertFromJsValue(engine, info.argv[1], height)) {
988 WLOGFE("[NAPI]Failed to convert parameter to height");
989 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
990 }
991 if (width <= 0 || height <= 0) {
992 WLOGFE("[NAPI]width or height should greater than 0!");
993 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
994 }
995 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
996 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
997 return engine.CreateUndefined();
998 }
999
1000 wptr<Window> weakToken(windowToken_);
1001 AsyncTask::CompleteCallback complete =
1002 [weakToken, width, height](NativeEngine& engine, AsyncTask& task, int32_t status) {
1003 auto weakWindow = weakToken.promote();
1004 if (weakWindow == nullptr) {
1005 task.Reject(engine,
1006 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1007 return;
1008 }
1009 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(
1010 weakWindow->Resize(static_cast<uint32_t>(width), static_cast<uint32_t>(height)));
1011 if (ret == WmErrorCode::WM_OK) {
1012 task.Resolve(engine, engine.CreateUndefined());
1013 } else {
1014 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window resize failed"));
1015 }
1016 WLOGFD("[NAPI]Window [%{public}u, %{public}s] resize end, ret = %{public}d",
1017 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
1018 };
1019
1020 // 2: params num; 2: index of callback
1021 NativeValue* lastParam = (info.argc <= 2) ? nullptr :
1022 ((info.argv[2] != nullptr && info.argv[2]->TypeOf() == NATIVE_FUNCTION) ?
1023 info.argv[2] : nullptr);
1024 NativeValue* result = nullptr;
1025 AsyncTask::Schedule("JsWindow::OnResizeWindow",
1026 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1027 return result;
1028 }
1029
OnSetWindowType(NativeEngine & engine,NativeCallbackInfo & info)1030 NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& info)
1031 {
1032 WMError errCode = WMError::WM_OK;
1033 if (info.argc < 1 || info.argc > 2) { // 2 is max num of argc
1034 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1035 errCode = WMError::WM_ERROR_INVALID_PARAM;
1036 }
1037 WindowType winType = WindowType::SYSTEM_WINDOW_BASE;
1038 if (errCode == WMError::WM_OK) {
1039 NativeNumber* nativeType = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
1040 if (nativeType == nullptr) {
1041 WLOGFE("[NAPI]Failed to convert parameter to windowType");
1042 errCode = WMError::WM_ERROR_INVALID_PARAM;
1043 } else if (static_cast<uint32_t>(*nativeType) >= static_cast<uint32_t>(WindowType::SYSTEM_WINDOW_BASE)) {
1044 winType = static_cast<WindowType>(static_cast<uint32_t>(*nativeType)); // adapt to the old version
1045 } else {
1046 if (JS_TO_NATIVE_WINDOW_TYPE_MAP.count(
1047 static_cast<ApiWindowType>(static_cast<uint32_t>(*nativeType))) != 0) {
1048 winType = JS_TO_NATIVE_WINDOW_TYPE_MAP.at(
1049 static_cast<ApiWindowType>(static_cast<uint32_t>(*nativeType)));
1050 } else {
1051 WLOGFE("[NAPI]Do not surppot this type: %{public}u", static_cast<uint32_t>(*nativeType));
1052 errCode = WMError::WM_ERROR_INVALID_PARAM;
1053 }
1054 }
1055 }
1056
1057 wptr<Window> weakToken(windowToken_);
1058 AsyncTask::CompleteCallback complete =
1059 [weakToken, winType, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
1060 auto weakWindow = weakToken.promote();
1061 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
1062 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
1063 WLOGFE("[NAPI]window is nullptr or get invalid param");
1064 return;
1065 }
1066 WMError ret = weakWindow->SetWindowType(winType);
1067 if (ret == WMError::WM_OK) {
1068 task.Resolve(engine, engine.CreateUndefined());
1069 } else {
1070 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window set type failed"));
1071 }
1072 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set type end, ret = %{public}d",
1073 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
1074 };
1075
1076 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
1077 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
1078 NativeValue* result = nullptr;
1079 AsyncTask::Schedule("JsWindow::OnSetWindowType",
1080 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1081 return result;
1082 }
1083
OnSetWindowMode(NativeEngine & engine,NativeCallbackInfo & info)1084 NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& info)
1085 {
1086 if (!Permission::IsSystemCalling()) {
1087 WLOGFE("set window mode permission denied!");
1088 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
1089 return engine.CreateUndefined();
1090 }
1091 WmErrorCode errCode = WmErrorCode::WM_OK;
1092 if (info.argc < 1) {
1093 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1094 }
1095 WindowMode winMode = WindowMode::WINDOW_MODE_FULLSCREEN;
1096 if (errCode == WmErrorCode::WM_OK) {
1097 NativeNumber* nativeMode = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
1098 if (nativeMode == nullptr) {
1099 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1100 } else {
1101 if (static_cast<uint32_t>(*nativeMode) >= static_cast<uint32_t>(WindowMode::WINDOW_MODE_SPLIT_PRIMARY)) {
1102 winMode = static_cast<WindowMode>(static_cast<uint32_t>(*nativeMode));
1103 } else if (static_cast<uint32_t>(*nativeMode) >= static_cast<uint32_t>(ApiWindowMode::UNDEFINED) &&
1104 static_cast<uint32_t>(*nativeMode) <= static_cast<uint32_t>(ApiWindowMode::MODE_END)) {
1105 winMode = JS_TO_NATIVE_WINDOW_MODE_MAP.at(
1106 static_cast<ApiWindowMode>(static_cast<uint32_t>(*nativeMode)));
1107 } else {
1108 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1109 }
1110 }
1111 }
1112 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
1113 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1114 return engine.CreateUndefined();
1115 }
1116 wptr<Window> weakToken(windowToken_);
1117 AsyncTask::CompleteCallback complete =
1118 [weakToken, winMode](NativeEngine& engine, AsyncTask& task, int32_t status) {
1119 auto weakWindow = weakToken.promote();
1120 if (weakWindow == nullptr) {
1121 task.Reject(engine, CreateJsError(engine,
1122 static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1123 return;
1124 }
1125 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->SetWindowMode(winMode));
1126 if (ret == WmErrorCode::WM_OK) {
1127 task.Resolve(engine, engine.CreateUndefined());
1128 } else {
1129 task.Reject(engine,
1130 CreateJsError(engine, static_cast<int32_t>(ret), "Window set mode failed"));
1131 }
1132 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set type end, ret = %{public}d",
1133 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
1134 };
1135
1136 NativeValue* lastParam = (info.argc == 1) ? nullptr :
1137 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
1138 info.argv[1] : nullptr);
1139 NativeValue* result = nullptr;
1140 AsyncTask::Schedule("JsWindow::OnSetWindowMode",
1141 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1142 return result;
1143 }
1144
OnGetProperties(NativeEngine & engine,NativeCallbackInfo & info)1145 NativeValue* JsWindow::OnGetProperties(NativeEngine& engine, NativeCallbackInfo& info)
1146 {
1147 WMError errCode = WMError::WM_OK;
1148 if (info.argc > 1) {
1149 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1150 errCode = WMError::WM_ERROR_INVALID_PARAM;
1151 }
1152 wptr<Window> weakToken(windowToken_);
1153 AsyncTask::CompleteCallback complete =
1154 [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
1155 auto weakWindow = weakToken.promote();
1156 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
1157 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
1158 WLOGFE("[NAPI]window is nullptr or get invalid param");
1159 return;
1160 }
1161 auto objValue = CreateJsWindowPropertiesObject(engine, weakWindow);
1162 if (objValue != nullptr) {
1163 task.Resolve(engine, objValue);
1164 } else {
1165 task.Reject(engine, CreateJsError(engine,
1166 static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "Window get properties failed"));
1167 }
1168 WLOGFD("[NAPI]Window [%{public}u, %{public}s] get properties end, objValue = %{public}p",
1169 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), objValue);
1170 };
1171
1172 NativeValue* lastParam = (info.argc == 0) ? nullptr :
1173 (info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
1174 NativeValue* result = nullptr;
1175 AsyncTask::Schedule("JsWindow::OnGetProperties",
1176 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1177 return result;
1178 }
1179
OnGetWindowPropertiesSync(NativeEngine & engine,NativeCallbackInfo & info)1180 NativeValue* JsWindow::OnGetWindowPropertiesSync(NativeEngine& engine, NativeCallbackInfo& info)
1181 {
1182 wptr<Window> weakToken(windowToken_);
1183 auto window = weakToken.promote();
1184 if (window == nullptr) {
1185 WLOGFE("[NAPI]window is nullptr or get invalid param");
1186 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1187 return engine.CreateUndefined();
1188 }
1189 auto objValue = CreateJsWindowPropertiesObject(engine, window);
1190 WLOGFD("[NAPI]Window [%{public}u, %{public}s] get properties end, objValue = %{public}p",
1191 window->GetWindowId(), window->GetWindowName().c_str(), objValue);
1192 if (objValue != nullptr) {
1193 return objValue;
1194 } else {
1195 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1196 return engine.CreateUndefined();
1197 }
1198 }
1199
OnRegisterWindowCallback(NativeEngine & engine,NativeCallbackInfo & info)1200 NativeValue* JsWindow::OnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info)
1201 {
1202 if (windowToken_ == nullptr) {
1203 WLOGFE("[NAPI]Window is nullptr");
1204 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1205 return engine.CreateUndefined();
1206 }
1207 if (info.argc < 2) { // 2: params num
1208 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1209 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1210 return engine.CreateUndefined();
1211 }
1212 std::string cbType;
1213 if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
1214 WLOGFE("[NAPI]Failed to convert parameter to callbackType");
1215 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1216 return engine.CreateUndefined();
1217 }
1218 NativeValue* value = info.argv[1];
1219 if (!value->IsCallable()) {
1220 WLOGFD("[NAPI]Callback(info->argv[1]) is not callable");
1221 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1222 return engine.CreateUndefined();
1223 }
1224 registerManager_->RegisterListener(windowToken_, cbType, CaseType::CASE_WINDOW, engine, value);
1225 WLOGFD("[NAPI]Register end, window [%{public}u, %{public}s], type = %{public}s, callback = %{public}p",
1226 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), cbType.c_str(), value);
1227 return engine.CreateUndefined();
1228 }
1229
OnUnregisterWindowCallback(NativeEngine & engine,NativeCallbackInfo & info)1230 NativeValue* JsWindow::OnUnregisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info)
1231 {
1232 if (windowToken_ == nullptr || info.argc < 1) { // 2: maximum params nums
1233 WLOGFE("[NAPI]Window is nullptr or argc is invalid: %{public}zu", info.argc);
1234 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1235 return engine.CreateUndefined();
1236 }
1237 std::string cbType;
1238 if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
1239 WLOGFE("[NAPI]Failed to convert parameter to callbackType");
1240 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1241 return engine.CreateUndefined();
1242 }
1243
1244 NativeValue* value = nullptr;
1245 if (info.argc == 1) {
1246 registerManager_->UnregisterListener(windowToken_, cbType, CaseType::CASE_WINDOW, value);
1247 } else {
1248 value = info.argv[1];
1249 if (value == nullptr || !value->IsCallable()) {
1250 registerManager_->UnregisterListener(windowToken_, cbType, CaseType::CASE_WINDOW, nullptr);
1251 } else {
1252 registerManager_->UnregisterListener(windowToken_, cbType, CaseType::CASE_WINDOW, value);
1253 }
1254 }
1255
1256 WLOGFD("[NAPI]Unregister end, window [%{public}u, %{public}s], type = %{public}s, callback = %{public}p",
1257 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), cbType.c_str(), value);
1258 return engine.CreateUndefined();
1259 }
1260
OnBindDialogTarget(NativeEngine & engine,NativeCallbackInfo & info)1261 NativeValue* JsWindow::OnBindDialogTarget(NativeEngine& engine, NativeCallbackInfo& info)
1262 {
1263 WmErrorCode errCode = WmErrorCode::WM_OK;
1264 if (windowToken_ == nullptr || info.argc <= 1) { // 1: invalid params nums
1265 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1266 }
1267
1268 NativeValue* value = nullptr;
1269 sptr<IRemoteObject> token = nullptr;
1270 token = NAPI_ohos_rpc_getNativeRemoteObject(
1271 reinterpret_cast<napi_env>(&engine), reinterpret_cast<napi_value>(info.argv[0]));
1272 if (token == nullptr) {
1273 std::shared_ptr<AbilityRuntime::RequestInfo> requestInfo = AbilityRuntime::RequestInfo::UnwrapRequestInfo(engine, info.argv[0]);
1274 if (requestInfo != nullptr) {
1275 token = requestInfo->GetToken();
1276 }
1277 }
1278 if (token == nullptr) {
1279 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1280 }
1281
1282 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
1283 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1284 return engine.CreateUndefined();
1285 }
1286
1287 value = info.argv[1];
1288 if (value == nullptr || !value->IsCallable()) {
1289 registerManager_->RegisterListener(windowToken_,
1290 "dialogDeathRecipient", CaseType::CASE_WINDOW, engine, nullptr);
1291 } else {
1292 registerManager_->RegisterListener(windowToken_,
1293 "dialogDeathRecipient", CaseType::CASE_WINDOW, engine, value);
1294 }
1295
1296 wptr<Window> weakToken(windowToken_);
1297 AsyncTask::CompleteCallback complete =
1298 [weakToken, token](NativeEngine& engine, AsyncTask& task, int32_t status) {
1299 auto weakWindow = weakToken.promote();
1300 if (weakWindow == nullptr) {
1301 task.Reject(engine, CreateJsError(engine,
1302 static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1303 return;
1304 }
1305
1306 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->BindDialogTarget(token));
1307 if (ret == WmErrorCode::WM_OK) {
1308 task.Resolve(engine, engine.CreateUndefined());
1309 } else {
1310 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Bind Dialog Target failed"));
1311 }
1312
1313 WLOGFD("[NAPI]BindDialogTarget end, window [%{public}u, %{public}s]",
1314 weakToken->GetWindowId(), weakToken->GetWindowName().c_str());
1315 };
1316
1317 NativeValue* result = nullptr;
1318 NativeValue* lastParam = (info.argc == 2) ? nullptr :
1319 (info.argv[2]->TypeOf() == NATIVE_FUNCTION ? info.argv[2] : nullptr);
1320 AsyncTask::Schedule("JsWindow::OnBindDialogTarget",
1321 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1322 return result;
1323 }
1324
LoadContentTask(std::shared_ptr<NativeReference> contentStorage,std::string contextUrl,sptr<Window> weakWindow,NativeEngine & engine,AsyncTask & task)1325 static void LoadContentTask(std::shared_ptr<NativeReference> contentStorage, std::string contextUrl,
1326 sptr<Window> weakWindow, NativeEngine& engine, AsyncTask& task)
1327 {
1328 NativeValue* nativeStorage = (contentStorage == nullptr) ? nullptr : contentStorage->Get();
1329 AppExecFwk::Ability* ability = nullptr;
1330 GetAPI7Ability(engine, ability);
1331 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(
1332 weakWindow->SetUIContent(contextUrl, &engine, nativeStorage, false, ability));
1333 if (ret == WmErrorCode::WM_OK) {
1334 task.Resolve(engine, engine.CreateUndefined());
1335 } else {
1336 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window load content failed"));
1337 }
1338 WLOGFD("[NAPI]Window [%{public}u, %{public}s] load content end, ret = %{public}d",
1339 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
1340 return;
1341 }
1342
LoadContentScheduleOld(NativeEngine & engine,NativeCallbackInfo & info)1343 NativeValue* JsWindow::LoadContentScheduleOld(NativeEngine& engine, NativeCallbackInfo& info)
1344 {
1345 WMError errCode = WMError::WM_OK;
1346 if (info.argc < 1 || info.argc > 2) { // 2 maximum param num
1347 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1348 errCode = WMError::WM_ERROR_INVALID_PARAM;
1349 }
1350 std::string contextUrl;
1351 if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[0], contextUrl)) {
1352 WLOGFE("[NAPI]Failed to convert parameter to context url");
1353 errCode = WMError::WM_ERROR_INVALID_PARAM;
1354 }
1355 NativeValue* storage = nullptr;
1356 NativeValue* callBack = nullptr;
1357 if (info.argc == 2) { // 2 param num
1358 callBack = info.argv[1];
1359 }
1360 std::shared_ptr<NativeReference> contentStorage = (storage == nullptr) ? nullptr :
1361 std::shared_ptr<NativeReference>(engine.CreateReference(storage, 1));
1362 wptr<Window> weakToken(windowToken_);
1363 AsyncTask::CompleteCallback complete =
1364 [weakToken, contentStorage, contextUrl, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
1365 auto weakWindow = weakToken.promote();
1366 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
1367 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
1368 WLOGFE("[NAPI]Window is nullptr or get invalid param");
1369 return;
1370 }
1371 LoadContentTask(contentStorage, contextUrl, weakWindow, engine, task);
1372 };
1373 NativeValue* result = nullptr;
1374 AsyncTask::Schedule("JsWindow::OnLoadContent",
1375 engine, CreateAsyncTaskWithLastParam(engine, callBack, nullptr, std::move(complete), &result));
1376 return result;
1377 }
1378
LoadContentScheduleNew(NativeEngine & engine,NativeCallbackInfo & info)1379 NativeValue* JsWindow::LoadContentScheduleNew(NativeEngine& engine, NativeCallbackInfo& info)
1380 {
1381 WmErrorCode errCode = WmErrorCode::WM_OK;
1382 if (info.argc < 2) { // 2 param num
1383 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1384 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1385 }
1386 std::string contextUrl;
1387 if (errCode == WmErrorCode::WM_OK && !ConvertFromJsValue(engine, info.argv[0], contextUrl)) {
1388 WLOGFE("[NAPI]Failed to convert parameter to context url");
1389 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1390 }
1391 NativeValue* storage = nullptr;
1392 NativeValue* callBack = nullptr;
1393 if (info.argc == 2) { // 2: num of params
1394 storage = info.argv[1];
1395 } else if (info.argc >= 3) { // 3: num of params
1396 storage = info.argv[1];
1397 callBack = ((info.argv[2] != nullptr && info.argv[2]->TypeOf() == NATIVE_FUNCTION) ? // 2 param num
1398 info.argv[2] : nullptr); // 2 param num
1399 }
1400 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
1401 WLOGFE("[NAPI]Window is nullptr or get invalid param");
1402 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1403 return engine.CreateUndefined();
1404 }
1405 std::shared_ptr<NativeReference> contentStorage = (storage == nullptr) ? nullptr :
1406 std::shared_ptr<NativeReference>(engine.CreateReference(storage, 1));
1407 wptr<Window> weakToken(windowToken_);
1408 AsyncTask::CompleteCallback complete =
1409 [weakToken, contentStorage, contextUrl](NativeEngine& engine, AsyncTask& task, int32_t status) {
1410 auto weakWindow = weakToken.promote();
1411 if (weakWindow == nullptr) {
1412 WLOGFE("[NAPI]Window is nullptr or get invalid param");
1413 task.Reject(engine, CreateJsError(engine,
1414 static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1415 return;
1416 }
1417 LoadContentTask(contentStorage, contextUrl, weakWindow, engine, task);
1418 };
1419 NativeValue* result = nullptr;
1420 AsyncTask::Schedule("JsWindow::OnLoadContent",
1421 engine, CreateAsyncTaskWithLastParam(engine, callBack, nullptr, std::move(complete), &result));
1422 return result;
1423 }
1424
OnLoadContent(NativeEngine & engine,NativeCallbackInfo & info)1425 NativeValue* JsWindow::OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info)
1426 {
1427 bool oldApi = false;
1428 if (info.argc == 1) {
1429 oldApi = true;
1430 } else if (info.argc == 2) { // 2 param num
1431 NativeValue* value = info.argv[1];
1432 if (value== nullptr || value->TypeOf() != NATIVE_FUNCTION) {
1433 oldApi = false;
1434 } else {
1435 oldApi = true;
1436 }
1437 }
1438 if (oldApi) {
1439 return LoadContentScheduleOld(engine, info);
1440 } else {
1441 return LoadContentScheduleNew(engine, info);
1442 }
1443 }
1444
OnSetUIContent(NativeEngine & engine,NativeCallbackInfo & info)1445 NativeValue* JsWindow::OnSetUIContent(NativeEngine& engine, NativeCallbackInfo& info)
1446 {
1447 WmErrorCode errCode = WmErrorCode::WM_OK;
1448 if (info.argc < 1) { // 2 maximum param num
1449 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1450 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1451 }
1452 std::string contextUrl;
1453 if (errCode == WmErrorCode::WM_OK && !ConvertFromJsValue(engine, info.argv[0], contextUrl)) {
1454 WLOGFE("[NAPI]Failed to convert parameter to context url");
1455 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1456 }
1457 NativeValue* storage = nullptr;
1458 NativeValue* callBack = nullptr;
1459 if (info.argc >= 2) { // 2 param num
1460 callBack = info.argv[1];
1461 }
1462 std::shared_ptr<NativeReference> contentStorage = (storage == nullptr) ? nullptr :
1463 std::shared_ptr<NativeReference>(engine.CreateReference(storage, 1));
1464 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
1465 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1466 return engine.CreateUndefined();
1467 }
1468
1469 wptr<Window> weakToken(windowToken_);
1470 AsyncTask::CompleteCallback complete =
1471 [weakToken, contentStorage, contextUrl](NativeEngine& engine, AsyncTask& task, int32_t status) {
1472 auto weakWindow = weakToken.promote();
1473 if (weakWindow == nullptr) {
1474 WLOGFE("[NAPI]Window is nullptr");
1475 task.Reject(engine,
1476 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1477 return;
1478 }
1479 LoadContentTask(contentStorage, contextUrl, weakWindow, engine, task);
1480 };
1481 NativeValue* result = nullptr;
1482 AsyncTask::Schedule("JsWindow::OnSetUIContent",
1483 engine, CreateAsyncTaskWithLastParam(engine, callBack, nullptr, std::move(complete), &result));
1484 return result;
1485 }
1486
OnSetFullScreen(NativeEngine & engine,NativeCallbackInfo & info)1487 NativeValue* JsWindow::OnSetFullScreen(NativeEngine& engine, NativeCallbackInfo& info)
1488 {
1489 WMError errCode = WMError::WM_OK;
1490 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
1491 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1492 errCode = WMError::WM_ERROR_INVALID_PARAM;
1493 }
1494 bool isFullScreen = false;
1495 if (errCode == WMError::WM_OK) {
1496 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
1497 if (nativeVal == nullptr) {
1498 WLOGFE("[NAPI]Failed to convert parameter to isFullScreen");
1499 errCode = WMError::WM_ERROR_INVALID_PARAM;
1500 } else {
1501 isFullScreen = static_cast<bool>(*nativeVal);
1502 }
1503 }
1504
1505 wptr<Window> weakToken(windowToken_);
1506 AsyncTask::CompleteCallback complete =
1507 [weakToken, isFullScreen, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
1508 auto weakWindow = weakToken.promote();
1509 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
1510 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
1511 return;
1512 }
1513 WMError ret = weakWindow->SetFullScreen(isFullScreen);
1514 if (ret == WMError::WM_OK) {
1515 task.Resolve(engine, engine.CreateUndefined());
1516 } else {
1517 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window SetFullScreen failed."));
1518 }
1519 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set full screen end, ret = %{public}d",
1520 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
1521 };
1522
1523 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
1524 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
1525 NativeValue* result = nullptr;
1526 AsyncTask::Schedule("JsWindow::OnSetFullScreen",
1527 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1528 return result;
1529 }
1530
OnSetLayoutFullScreen(NativeEngine & engine,NativeCallbackInfo & info)1531 NativeValue* JsWindow::OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbackInfo& info)
1532 {
1533 WMError errCode = WMError::WM_OK;
1534 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
1535 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1536 errCode = WMError::WM_ERROR_INVALID_PARAM;
1537 }
1538 bool isLayoutFullScreen = false;
1539 if (errCode == WMError::WM_OK) {
1540 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
1541 if (nativeVal == nullptr) {
1542 WLOGFE("[NAPI]Failed to convert parameter to isLayoutFullScreen");
1543 errCode = WMError::WM_ERROR_INVALID_PARAM;
1544 } else {
1545 isLayoutFullScreen = static_cast<bool>(*nativeVal);
1546 }
1547 }
1548 wptr<Window> weakToken(windowToken_);
1549 AsyncTask::CompleteCallback complete =
1550 [weakToken, isLayoutFullScreen, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
1551 auto weakWindow = weakToken.promote();
1552 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
1553 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
1554 return;
1555 }
1556 WMError ret = weakWindow->SetLayoutFullScreen(isLayoutFullScreen);
1557 if (ret == WMError::WM_OK) {
1558 task.Resolve(engine, engine.CreateUndefined());
1559 } else {
1560 task.Reject(engine, CreateJsError(engine,
1561 static_cast<int32_t>(ret), "Window OnSetLayoutFullScreen failed."));
1562 }
1563 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set layout full screen end, ret = %{public}d",
1564 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
1565 };
1566 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
1567 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
1568 NativeValue* result = nullptr;
1569 AsyncTask::Schedule("JsWindow::OnSetLayoutFullScreen",
1570 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1571 return result;
1572 }
1573
OnSetWindowLayoutFullScreen(NativeEngine & engine,NativeCallbackInfo & info)1574 NativeValue* JsWindow::OnSetWindowLayoutFullScreen(NativeEngine& engine, NativeCallbackInfo& info)
1575 {
1576 WmErrorCode errCode = WmErrorCode::WM_OK;
1577 if (info.argc < 1) { // 1: params num
1578 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1579 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1580 }
1581 bool isLayoutFullScreen = false;
1582 if (errCode == WmErrorCode::WM_OK) {
1583 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
1584 if (nativeVal == nullptr) {
1585 WLOGFE("[NAPI]Failed to convert parameter to isLayoutFullScreen");
1586 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1587 } else {
1588 isLayoutFullScreen = static_cast<bool>(*nativeVal);
1589 }
1590 }
1591 if (errCode != WmErrorCode::WM_OK) {
1592 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1593 return engine.CreateUndefined();
1594 }
1595
1596 wptr<Window> weakToken(windowToken_);
1597 AsyncTask::CompleteCallback complete =
1598 [weakToken, isLayoutFullScreen](NativeEngine& engine, AsyncTask& task, int32_t status) {
1599 auto weakWindow = weakToken.promote();
1600 if (weakWindow == nullptr) {
1601 task.Reject(engine,
1602 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY),
1603 "Invalidate params."));
1604 return;
1605 }
1606 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->SetLayoutFullScreen(isLayoutFullScreen));
1607 if (ret == WmErrorCode::WM_OK) {
1608 task.Resolve(engine, engine.CreateUndefined());
1609 } else {
1610 task.Reject(engine, CreateJsError(engine,
1611 static_cast<int32_t>(ret), "Window OnSetLayoutFullScreen failed."));
1612 }
1613 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set layout full screen end, ret = %{public}d",
1614 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
1615 };
1616
1617 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
1618 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
1619 info.argv[1] : nullptr);
1620 NativeValue* result = nullptr;
1621 AsyncTask::Schedule("JsWindow::OnSetWindowLayoutFullScreen",
1622 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1623 return result;
1624 }
1625
OnSetSystemBarEnable(NativeEngine & engine,NativeCallbackInfo & info)1626 NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallbackInfo& info)
1627 {
1628 WMError errCode = WMError::WM_OK;
1629 if (info.argc > 2 || windowToken_ == nullptr) { // 2: maximum params num
1630 WLOGFE("[NAPI]Window is nullptr or argc is invalid: %{public}zu", info.argc);
1631 errCode = WMError::WM_ERROR_INVALID_PARAM;
1632 }
1633 std::map<WindowType, SystemBarProperty> systemBarProperties;
1634 if (errCode == WMError::WM_OK && !GetSystemBarStatus(systemBarProperties, engine, info, windowToken_)) {
1635 errCode = WMError::WM_ERROR_INVALID_PARAM;
1636 }
1637 wptr<Window> weakToken(windowToken_);
1638 AsyncTask::CompleteCallback complete =
1639 [weakToken, systemBarProperties, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
1640 auto weakWindow = weakToken.promote();
1641 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
1642 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
1643 WLOGFE("[NAPI]window is nullptr or get invalid param");
1644 return;
1645 }
1646 WMError ret = weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR,
1647 systemBarProperties.at(WindowType::WINDOW_TYPE_STATUS_BAR));
1648 ret = weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR,
1649 systemBarProperties.at(WindowType::WINDOW_TYPE_NAVIGATION_BAR));
1650 if (ret == WMError::WM_OK) {
1651 task.Resolve(engine, engine.CreateUndefined());
1652 } else {
1653 task.Reject(engine, CreateJsError(engine,
1654 static_cast<int32_t>(ret), "JsWindow::OnSetSystemBarEnable failed"));
1655 }
1656 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set system bar enable end, ret = %{public}d",
1657 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
1658 };
1659 NativeValue* lastParam = nullptr;
1660 if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_FUNCTION) {
1661 lastParam = info.argv[0];
1662 } else if (info.argc > 1 && info.argv[1]->TypeOf() == NATIVE_FUNCTION) {
1663 lastParam = info.argv[1];
1664 }
1665 NativeValue* result = nullptr;
1666 AsyncTask::Schedule("JsWindow::OnSetSystemBarEnable",
1667 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1668 return result;
1669 }
1670
OnSetWindowSystemBarEnable(NativeEngine & engine,NativeCallbackInfo & info)1671 NativeValue* JsWindow::OnSetWindowSystemBarEnable(NativeEngine& engine, NativeCallbackInfo& info)
1672 {
1673 WmErrorCode errCode = WmErrorCode::WM_OK;
1674 std::map<WindowType, SystemBarProperty> systemBarProperties;
1675 if (info.argc < 1 || windowToken_ == nullptr || // 1: params num
1676 !GetSystemBarStatus(systemBarProperties, engine, info, windowToken_)) {
1677 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1678 }
1679 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
1680 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1681 return engine.CreateUndefined();
1682 }
1683 wptr<Window> weakToken(windowToken_);
1684 AsyncTask::CompleteCallback complete =
1685 [weakToken, systemBarProperties](NativeEngine& engine, AsyncTask& task, int32_t status) {
1686 auto weakWindow = weakToken.promote();
1687 if (weakWindow == nullptr) {
1688 task.Reject(engine,
1689 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1690 return;
1691 }
1692 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(
1693 weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR,
1694 systemBarProperties.at(WindowType::WINDOW_TYPE_STATUS_BAR)));
1695 if (ret != WmErrorCode::WM_OK) {
1696 task.Reject(engine, CreateJsError(engine,
1697 static_cast<int32_t>(ret), "JsWindow::OnSetWindowSystemBarEnable failed"));
1698 }
1699 ret = WM_JS_TO_ERROR_CODE_MAP.at(
1700 weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR,
1701 systemBarProperties.at(WindowType::WINDOW_TYPE_NAVIGATION_BAR)));
1702 if (ret == WmErrorCode::WM_OK) {
1703 task.Resolve(engine, engine.CreateUndefined());
1704 } else {
1705 task.Reject(engine, CreateJsError(engine,
1706 static_cast<int32_t>(ret), "JsWindow::OnSetWindowSystemBarEnable failed"));
1707 }
1708 };
1709 NativeValue* lastParam = nullptr;
1710 if (info.argc >= 1 && info.argv[0] != nullptr && info.argv[0]->TypeOf() == NATIVE_FUNCTION) {
1711 lastParam = info.argv[0];
1712 } else if (info.argc >= 2 && // 2 arg count
1713 info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) {
1714 lastParam = info.argv[1];
1715 }
1716 NativeValue* result = nullptr;
1717 AsyncTask::Schedule("JsWindow::OnSetWindowSystemBarEnable",
1718 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1719 return result;
1720 }
1721
OnSetSystemBarProperties(NativeEngine & engine,NativeCallbackInfo & info)1722 NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCallbackInfo& info)
1723 {
1724 WMError errCode = WMError::WM_OK;
1725 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
1726 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1727 errCode = WMError::WM_ERROR_INVALID_PARAM;
1728 }
1729 std::map<WindowType, SystemBarProperty> systemBarProperties;
1730 if (errCode == WMError::WM_OK) {
1731 NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
1732 if (nativeObj == nullptr) {
1733 WLOGFE("[NAPI]Failed to convert object to SystemBarProperties");
1734 errCode = WMError::WM_ERROR_INVALID_PARAM;
1735 } else {
1736 if (!SetSystemBarPropertiesFromJs(engine, nativeObj, systemBarProperties, windowToken_)) {
1737 WLOGFE("[NAPI]Failed to GetSystemBarProperties From Js Object");
1738 errCode = WMError::WM_ERROR_INVALID_PARAM;
1739 }
1740 }
1741 }
1742 wptr<Window> weakToken(windowToken_);
1743 AsyncTask::CompleteCallback complete =
1744 [weakToken, systemBarProperties, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
1745 auto weakWindow = weakToken.promote();
1746 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
1747 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
1748 WLOGFE("[NAPI]window is nullptr or get invalid param");
1749 return;
1750 }
1751 WMError ret = weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR,
1752 systemBarProperties.at(WindowType::WINDOW_TYPE_STATUS_BAR));
1753 ret = weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR,
1754 systemBarProperties.at(WindowType::WINDOW_TYPE_NAVIGATION_BAR));
1755 if (ret == WMError::WM_OK) {
1756 task.Resolve(engine, engine.CreateUndefined());
1757 } else {
1758 task.Reject(engine, CreateJsError(engine,
1759 static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindow::OnSetSystemBarProperties failed"));
1760 }
1761 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set system bar properties end, ret = %{public}d",
1762 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
1763 };
1764
1765 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
1766 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
1767 NativeValue* result = nullptr;
1768 AsyncTask::Schedule("JsWindow::OnSetSystemBarProperties",
1769 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1770 return result;
1771 }
1772
OnSetWindowSystemBarProperties(NativeEngine & engine,NativeCallbackInfo & info)1773 NativeValue* JsWindow::OnSetWindowSystemBarProperties(NativeEngine& engine, NativeCallbackInfo& info)
1774 {
1775 WmErrorCode errCode = WmErrorCode::WM_OK;
1776 if (info.argc < 1) { // 2: maximum params num
1777 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1778 }
1779 std::map<WindowType, SystemBarProperty> systemBarProperties;
1780 if (errCode == WmErrorCode::WM_OK) {
1781 NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
1782 if (nativeObj == nullptr) {
1783 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1784 } else {
1785 if (!SetSystemBarPropertiesFromJs(engine, nativeObj, systemBarProperties, windowToken_)) {
1786 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1787 }
1788 }
1789 }
1790 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
1791 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1792 return engine.CreateUndefined();
1793 }
1794
1795 wptr<Window> weakToken(windowToken_);
1796 AsyncTask::CompleteCallback complete =
1797 [weakToken, systemBarProperties](NativeEngine& engine, AsyncTask& task, int32_t status) {
1798 auto weakWindow = weakToken.promote();
1799 if (weakWindow == nullptr) {
1800 task.Reject(engine,
1801 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1802 return;
1803 }
1804 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(
1805 weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR,
1806 systemBarProperties.at(WindowType::WINDOW_TYPE_STATUS_BAR)));
1807 if (ret != WmErrorCode::WM_OK) {
1808 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret)));
1809 }
1810 ret = WM_JS_TO_ERROR_CODE_MAP.at(
1811 weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR,
1812 systemBarProperties.at(WindowType::WINDOW_TYPE_NAVIGATION_BAR)));
1813 if (ret != WmErrorCode::WM_OK) {
1814 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret)));
1815 }
1816 task.Resolve(engine, engine.CreateUndefined());
1817 };
1818
1819 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
1820 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
1821 info.argv[1] : nullptr);
1822 NativeValue* result = nullptr;
1823 AsyncTask::Schedule("JsWindow::OnSetWindowSystemBarProperties",
1824 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1825 return result;
1826 }
1827
OnGetAvoidArea(NativeEngine & engine,NativeCallbackInfo & info)1828 NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& info)
1829 {
1830 WMError errCode = WMError::WM_OK;
1831 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
1832 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1833 errCode = WMError::WM_ERROR_INVALID_PARAM;
1834 }
1835 AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_SYSTEM;
1836 if (errCode == WMError::WM_OK) {
1837 NativeNumber* nativeMode = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
1838 if (nativeMode == nullptr) {
1839 WLOGFE("[NAPI]Failed to convert parameter to AvoidAreaType");
1840 errCode = WMError::WM_ERROR_INVALID_PARAM;
1841 } else {
1842 avoidAreaType = static_cast<AvoidAreaType>(static_cast<uint32_t>(*nativeMode));
1843 errCode = ((avoidAreaType > AvoidAreaType::TYPE_KEYBOARD) ||
1844 (avoidAreaType < AvoidAreaType::TYPE_SYSTEM)) ? WMError::WM_ERROR_INVALID_PARAM : WMError::WM_OK;
1845 }
1846 }
1847 wptr<Window> weakToken(windowToken_);
1848 AsyncTask::CompleteCallback complete =
1849 [weakToken, errCode, avoidAreaType](NativeEngine& engine, AsyncTask& task, int32_t status) {
1850 auto weakWindow = weakToken.promote();
1851 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
1852 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
1853 WLOGFE("[NAPI]window is nullptr or get invalid param");
1854 return;
1855 }
1856 // getAvoidRect by avoidAreaType
1857 AvoidArea avoidArea;
1858 WMError ret = weakWindow->GetAvoidAreaByType(avoidAreaType, avoidArea);
1859 if (ret != WMError::WM_OK) {
1860 avoidArea.topRect_ = g_emptyRect;
1861 avoidArea.leftRect_ = g_emptyRect;
1862 avoidArea.rightRect_ = g_emptyRect;
1863 avoidArea.bottomRect_ = g_emptyRect;
1864 }
1865 NativeValue* avoidAreaObj = ConvertAvoidAreaToJsValue(engine, avoidArea, avoidAreaType);
1866 if (avoidAreaObj != nullptr) {
1867 task.Resolve(engine, avoidAreaObj);
1868 } else {
1869 task.Reject(engine, CreateJsError(engine,
1870 static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindow::OnGetAvoidArea failed"));
1871 }
1872 WLOGFD("[NAPI]Window [%{public}u, %{public}s] get avoid area end, ret = %{public}d",
1873 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret);
1874 };
1875 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
1876 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
1877 NativeValue* result = nullptr;
1878 AsyncTask::Schedule("JsWindow::OnGetAvoidArea",
1879 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1880 return result;
1881 }
1882
OnGetWindowAvoidAreaSync(NativeEngine & engine,NativeCallbackInfo & info)1883 NativeValue* JsWindow::OnGetWindowAvoidAreaSync(NativeEngine& engine, NativeCallbackInfo& info)
1884 {
1885 WmErrorCode errCode = WmErrorCode::WM_OK;
1886 if (info.argc < 1) { // 1: params num
1887 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1888 return engine.CreateUndefined();
1889 }
1890 AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_SYSTEM;
1891 NativeNumber* nativeMode = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
1892 if (nativeMode == nullptr) {
1893 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1894 } else {
1895 avoidAreaType = static_cast<AvoidAreaType>(static_cast<uint32_t>(*nativeMode));
1896 errCode = ((avoidAreaType > AvoidAreaType::TYPE_KEYBOARD) || (avoidAreaType < AvoidAreaType::TYPE_SYSTEM)) ?
1897 WmErrorCode::WM_ERROR_INVALID_PARAM : WmErrorCode::WM_OK;
1898 }
1899 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
1900 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1901 return engine.CreateUndefined();
1902 }
1903
1904 wptr<Window> weakToken(windowToken_);
1905 auto window = weakToken.promote();
1906 if (window == nullptr) {
1907 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1908 return engine.CreateUndefined();
1909 }
1910 // getAvoidRect by avoidAreaType
1911 AvoidArea avoidArea;
1912 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->GetAvoidAreaByType(avoidAreaType, avoidArea));
1913 if (ret != WmErrorCode::WM_OK) {
1914 avoidArea.topRect_ = g_emptyRect;
1915 avoidArea.leftRect_ = g_emptyRect;
1916 avoidArea.rightRect_ = g_emptyRect;
1917 avoidArea.bottomRect_ = g_emptyRect;
1918 }
1919 NativeValue* avoidAreaObj = ConvertAvoidAreaToJsValue(engine, avoidArea, avoidAreaType);
1920 if (avoidAreaObj != nullptr) {
1921 return avoidAreaObj;
1922 } else {
1923 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1924 return engine.CreateUndefined();
1925 }
1926 }
1927
OnIsShowing(NativeEngine & engine,NativeCallbackInfo & info)1928 NativeValue* JsWindow::OnIsShowing(NativeEngine& engine, NativeCallbackInfo& info)
1929 {
1930 WMError errCode = WMError::WM_OK;
1931 if (info.argc > 1) {
1932 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1933 errCode = WMError::WM_ERROR_INVALID_PARAM;
1934 }
1935 wptr<Window> weakToken(windowToken_);
1936 AsyncTask::CompleteCallback complete =
1937 [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
1938 auto weakWindow = weakToken.promote();
1939 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
1940 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
1941 WLOGFE("[NAPI]window is nullptr or get invalid param");
1942 return;
1943 }
1944 bool state = weakWindow->GetWindowState() == WindowState::STATE_SHOWN;
1945 task.Resolve(engine, CreateJsValue(engine, state));
1946 WLOGFD("[NAPI]Window [%{public}u, %{public}s] get show state end, state = %{public}u",
1947 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), state);
1948 };
1949
1950 NativeValue* lastParam = (info.argc == 0) ? nullptr :
1951 (info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
1952 NativeValue* result = nullptr;
1953 AsyncTask::Schedule("JsWindow::OnIsShowing",
1954 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
1955 return result;
1956 }
1957
OnIsWindowShowingSync(NativeEngine & engine,NativeCallbackInfo & info)1958 NativeValue* JsWindow::OnIsWindowShowingSync(NativeEngine& engine, NativeCallbackInfo& info)
1959 {
1960 wptr<Window> weakToken(windowToken_);
1961 auto window = weakToken.promote();
1962 if (window == nullptr) {
1963 WLOGFE("[NAPI]window is nullptr");
1964 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
1965 return engine.CreateUndefined();
1966 }
1967 bool state = (window->GetWindowState() == WindowState::STATE_SHOWN);
1968 WLOGFD("[NAPI]Window [%{public}u, %{public}s] get show state end, state = %{public}u",
1969 window->GetWindowId(), window->GetWindowName().c_str(), state);
1970 return CreateJsValue(engine, state);
1971 }
1972
OnSetPreferredOrientation(NativeEngine & engine,NativeCallbackInfo & info)1973 NativeValue* JsWindow::OnSetPreferredOrientation(NativeEngine& engine, NativeCallbackInfo& info)
1974 {
1975 WmErrorCode errCode = WmErrorCode::WM_OK;
1976 Orientation requestedOrientation = Orientation::UNSPECIFIED;
1977 if (info.argc < 1) { // 1: params num
1978 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
1979 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1980 } else {
1981 NativeNumber* nativeType = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
1982 if (nativeType == nullptr) {
1983 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1984 WLOGFE("[NAPI]Failed to convert parameter to Orientation");
1985 } else {
1986 requestedOrientation = JS_TO_NATIVE_ORIENTATION_MAP.at(
1987 static_cast<ApiOrientation>(static_cast<uint32_t>(*nativeType)));
1988 if (requestedOrientation < Orientation::BEGIN || requestedOrientation > Orientation::END) {
1989 WLOGFE("[NAPI]Orientation %{public}u invalid!", static_cast<uint32_t>(requestedOrientation));
1990 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
1991 }
1992 }
1993 }
1994 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
1995 WLOGFE("[NAPI]get invalid param");
1996 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
1997 return engine.CreateUndefined();
1998 }
1999
2000 wptr<Window> weakToken(windowToken_);
2001 AsyncTask::CompleteCallback complete =
2002 [weakToken, requestedOrientation](NativeEngine& engine, AsyncTask& task, int32_t status) {
2003 auto weakWindow = weakToken.promote();
2004 if (weakWindow == nullptr) {
2005 WLOGFE("[NAPI]Window is nullptr");
2006 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY),
2007 "OnSetPreferredOrientation failed"));
2008 return;
2009 }
2010 weakWindow->SetRequestedOrientation(requestedOrientation);
2011 task.Resolve(engine, engine.CreateUndefined());
2012 WLOGFD("[NAPI]Window [%{public}u, %{public}s] OnSetPreferredOrientation end, orientation = %{public}u",
2013 weakWindow->GetWindowId(),
2014 weakWindow->GetWindowName().c_str(),
2015 static_cast<uint32_t>(requestedOrientation));
2016 };
2017
2018 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2019 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
2020 info.argv[1] : nullptr);
2021 NativeValue* result = nullptr;
2022 AsyncTask::Schedule("JsWindow::OnSetPreferredOrientation",
2023 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2024 return result;
2025 }
2026
OnIsSupportWideGamut(NativeEngine & engine,NativeCallbackInfo & info)2027 NativeValue* JsWindow::OnIsSupportWideGamut(NativeEngine& engine, NativeCallbackInfo& info)
2028 {
2029 WMError errCode = WMError::WM_OK;
2030 if (info.argc > 1) {
2031 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2032 errCode = WMError::WM_ERROR_INVALID_PARAM;
2033 }
2034 wptr<Window> weakToken(windowToken_);
2035 AsyncTask::CompleteCallback complete =
2036 [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2037 auto weakWindow = weakToken.promote();
2038 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
2039 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
2040 WLOGFE("[NAPI]window is nullptr or get invalid param");
2041 return;
2042 }
2043 bool flag = weakWindow->IsSupportWideGamut();
2044 task.Resolve(engine, CreateJsValue(engine, flag));
2045 WLOGFD("[NAPI]Window [%{public}u, %{public}s] OnIsSupportWideGamut end, ret = %{public}u",
2046 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), flag);
2047 };
2048
2049 NativeValue* lastParam = (info.argc == 0) ? nullptr :
2050 (info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
2051 NativeValue* result = nullptr;
2052 AsyncTask::Schedule("JsWindow::OnIsSupportWideGamut",
2053 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2054 return result;
2055 }
2056
OnIsWindowSupportWideGamut(NativeEngine & engine,NativeCallbackInfo & info)2057 NativeValue* JsWindow::OnIsWindowSupportWideGamut(NativeEngine& engine, NativeCallbackInfo& info)
2058 {
2059 wptr<Window> weakToken(windowToken_);
2060 AsyncTask::CompleteCallback complete =
2061 [weakToken](NativeEngine& engine, AsyncTask& task, int32_t status) {
2062 auto weakWindow = weakToken.promote();
2063 if (weakWindow == nullptr) {
2064 WLOGFE("[NAPI]window is nullptr or get invalid param");
2065 task.Reject(engine,
2066 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
2067 return;
2068 }
2069 bool flag = weakWindow->IsSupportWideGamut();
2070 task.Resolve(engine, CreateJsValue(engine, flag));
2071 WLOGFD("[NAPI]Window [%{public}u, %{public}s] OnIsWindowSupportWideGamut end, ret = %{public}u",
2072 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), flag);
2073 };
2074
2075 NativeValue* lastParam = (info.argc == 0) ? nullptr :
2076 ((info.argv[0] != nullptr && info.argv[0]->TypeOf() == NATIVE_FUNCTION) ?
2077 info.argv[0] : nullptr);
2078 NativeValue* result = nullptr;
2079 AsyncTask::Schedule("JsWindow::OnIsWindowSupportWideGamut",
2080 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2081 return result;
2082 }
2083
OnSetBackgroundColor(NativeEngine & engine,NativeCallbackInfo & info)2084 NativeValue* JsWindow::OnSetBackgroundColor(NativeEngine& engine, NativeCallbackInfo& info)
2085 {
2086 WMError errCode = WMError::WM_OK;
2087 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
2088 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2089 errCode = WMError::WM_ERROR_INVALID_PARAM;
2090 }
2091 std::string color;
2092 if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[0], color)) {
2093 WLOGFE("[NAPI]Failed to convert parameter to background color");
2094 errCode = WMError::WM_ERROR_INVALID_PARAM;
2095 }
2096
2097 wptr<Window> weakToken(windowToken_);
2098 AsyncTask::CompleteCallback complete =
2099 [weakToken, color, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2100 auto weakWindow = weakToken.promote();
2101 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
2102 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
2103 return;
2104 }
2105 WMError ret = weakWindow->SetBackgroundColor(color);
2106 if (ret == WMError::WM_OK) {
2107 task.Resolve(engine, engine.CreateUndefined());
2108 } else {
2109 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret),
2110 "Window set background color failed"));
2111 }
2112 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set background color end",
2113 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
2114 };
2115
2116 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2117 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
2118 NativeValue* result = nullptr;
2119 AsyncTask::Schedule("JsWindow::OnSetBackgroundColor",
2120 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2121 return result;
2122 }
2123
OnSetWindowBackgroundColorSync(NativeEngine & engine,NativeCallbackInfo & info)2124 NativeValue* JsWindow::OnSetWindowBackgroundColorSync(NativeEngine& engine, NativeCallbackInfo& info)
2125 {
2126 WmErrorCode errCode = WmErrorCode::WM_OK;
2127 if (info.argc < 1) { // 1: params num
2128 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2129 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2130 }
2131 std::string color;
2132 if (errCode == WmErrorCode::WM_OK && !ConvertFromJsValue(engine, info.argv[0], color)) {
2133 WLOGFE("[NAPI]Failed to convert parameter to background color");
2134 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2135 }
2136 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
2137 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
2138 return engine.CreateUndefined();
2139 }
2140
2141 wptr<Window> weakToken(windowToken_);
2142 auto window = weakToken.promote();
2143 if (window == nullptr) {
2144 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
2145 return engine.CreateUndefined();
2146 }
2147 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->SetBackgroundColor(color));
2148 if (ret == WmErrorCode::WM_OK) {
2149 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set background color end",
2150 window->GetWindowId(), window->GetWindowName().c_str());
2151 return engine.CreateUndefined();
2152 } else {
2153 engine.Throw(CreateJsError(engine, static_cast<int32_t>(ret)));
2154 return engine.CreateUndefined();
2155 }
2156 }
2157
OnSetBrightness(NativeEngine & engine,NativeCallbackInfo & info)2158 NativeValue* JsWindow::OnSetBrightness(NativeEngine& engine, NativeCallbackInfo& info)
2159 {
2160 WMError errCode = WMError::WM_OK;
2161 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
2162 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2163 errCode = WMError::WM_ERROR_INVALID_PARAM;
2164 }
2165 float brightness = UNDEFINED_BRIGHTNESS;
2166 if (errCode == WMError::WM_OK) {
2167 NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
2168 if (nativeVal == nullptr) {
2169 WLOGFE("[NAPI]Failed to convert parameter to brightness");
2170 errCode = WMError::WM_ERROR_INVALID_PARAM;
2171 } else {
2172 brightness = static_cast<double>(*nativeVal);
2173 }
2174 }
2175
2176 wptr<Window> weakToken(windowToken_);
2177 AsyncTask::CompleteCallback complete =
2178 [weakToken, brightness, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2179 auto weakWindow = weakToken.promote();
2180 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
2181 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
2182 return;
2183 }
2184 WMError ret = weakWindow->SetBrightness(brightness);
2185 if (ret == WMError::WM_OK) {
2186 task.Resolve(engine, engine.CreateUndefined());
2187 } else {
2188 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window set brightness failed"));
2189 }
2190 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set brightness end",
2191 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
2192 };
2193
2194 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2195 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
2196 NativeValue* result = nullptr;
2197 AsyncTask::Schedule("JsWindow::OnSetBrightness",
2198 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2199 return result;
2200 }
2201
OnSetWindowBrightness(NativeEngine & engine,NativeCallbackInfo & info)2202 NativeValue* JsWindow::OnSetWindowBrightness(NativeEngine& engine, NativeCallbackInfo& info)
2203 {
2204 WmErrorCode errCode = WmErrorCode::WM_OK;
2205 if (info.argc < 1) { // 1: params num
2206 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2207 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2208 }
2209 float brightness = UNDEFINED_BRIGHTNESS;
2210 if (errCode == WmErrorCode::WM_OK) {
2211 NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
2212 if (nativeVal == nullptr) {
2213 WLOGFE("[NAPI]Failed to convert parameter to brightness");
2214 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2215 } else {
2216 brightness = static_cast<double>(*nativeVal);
2217 }
2218 }
2219 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
2220 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
2221 return engine.CreateUndefined();
2222 }
2223
2224 wptr<Window> weakToken(windowToken_);
2225 AsyncTask::CompleteCallback complete =
2226 [weakToken, brightness](NativeEngine& engine, AsyncTask& task, int32_t status) {
2227 auto weakWindow = weakToken.promote();
2228 if (weakWindow == nullptr) {
2229 task.Reject(engine,
2230 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY),
2231 "Invalidate params."));
2232 return;
2233 }
2234 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->SetBrightness(brightness));
2235 if (ret == WmErrorCode::WM_OK) {
2236 task.Resolve(engine, engine.CreateUndefined());
2237 } else {
2238 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window set brightness failed"));
2239 }
2240 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set brightness end",
2241 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
2242 };
2243
2244 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2245 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
2246 info.argv[1] : nullptr);
2247 NativeValue* result = nullptr;
2248 AsyncTask::Schedule("JsWindow::OnSetWindowBrightness",
2249 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2250 return result;
2251 }
2252
OnSetDimBehind(NativeEngine & engine,NativeCallbackInfo & info)2253 NativeValue* JsWindow::OnSetDimBehind(NativeEngine& engine, NativeCallbackInfo& info)
2254 {
2255 AsyncTask::CompleteCallback complete =
2256 [](NativeEngine& engine, AsyncTask& task, int32_t status) {
2257 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_DEVICE_NOT_SUPPORT)));
2258 };
2259
2260 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2261 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
2262 NativeValue* result = nullptr;
2263 AsyncTask::Schedule("JsWindow::OnSetDimBehind",
2264 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2265 return result;
2266 }
2267
OnSetFocusable(NativeEngine & engine,NativeCallbackInfo & info)2268 NativeValue* JsWindow::OnSetFocusable(NativeEngine& engine, NativeCallbackInfo& info)
2269 {
2270 WMError errCode = WMError::WM_OK;
2271 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
2272 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2273 errCode = WMError::WM_ERROR_INVALID_PARAM;
2274 }
2275 bool focusable = true;
2276 if (errCode == WMError::WM_OK) {
2277 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
2278 if (nativeVal == nullptr) {
2279 WLOGFE("[NAPI]Failed to convert parameter to focusable");
2280 errCode = WMError::WM_ERROR_INVALID_PARAM;
2281 } else {
2282 focusable = static_cast<bool>(*nativeVal);
2283 }
2284 }
2285
2286 wptr<Window> weakToken(windowToken_);
2287 AsyncTask::CompleteCallback complete =
2288 [weakToken, focusable, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2289 auto weakWindow = weakToken.promote();
2290 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
2291 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
2292 return;
2293 }
2294 WMError ret = weakWindow->SetFocusable(focusable);
2295 if (ret == WMError::WM_OK) {
2296 task.Resolve(engine, engine.CreateUndefined());
2297 } else {
2298 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window set focusable failed"));
2299 }
2300 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set focusable end",
2301 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
2302 };
2303
2304 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2305 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
2306 NativeValue* result = nullptr;
2307 AsyncTask::Schedule("JsWindow::OnSetFocusable",
2308 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2309 return result;
2310 }
2311
OnSetWindowFocusable(NativeEngine & engine,NativeCallbackInfo & info)2312 NativeValue* JsWindow::OnSetWindowFocusable(NativeEngine& engine, NativeCallbackInfo& info)
2313 {
2314 WmErrorCode errCode = WmErrorCode::WM_OK;
2315 if (info.argc < 1) { // 1: maximum params num
2316 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2317 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2318 }
2319 bool focusable = true;
2320 if (errCode == WmErrorCode::WM_OK) {
2321 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
2322 if (nativeVal == nullptr) {
2323 WLOGFE("[NAPI]Failed to convert parameter to focusable");
2324 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2325 } else {
2326 focusable = static_cast<bool>(*nativeVal);
2327 }
2328 }
2329 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
2330 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
2331 return engine.CreateUndefined();
2332 }
2333
2334 wptr<Window> weakToken(windowToken_);
2335 AsyncTask::CompleteCallback complete =
2336 [weakToken, focusable](NativeEngine& engine, AsyncTask& task, int32_t status) {
2337 auto weakWindow = weakToken.promote();
2338 if (weakWindow == nullptr) {
2339 task.Reject(engine,
2340 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY),
2341 "Invalidate params."));
2342 return;
2343 }
2344 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->SetFocusable(focusable));
2345 if (ret == WmErrorCode::WM_OK) {
2346 task.Resolve(engine, engine.CreateUndefined());
2347 } else {
2348 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window set focusable failed"));
2349 }
2350 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set focusable end",
2351 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
2352 };
2353
2354 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2355 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
2356 info.argv[1] : nullptr);
2357 NativeValue* result = nullptr;
2358 AsyncTask::Schedule("JsWindow::OnSetWindowFocusable",
2359 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2360 return result;
2361 }
2362
OnSetKeepScreenOn(NativeEngine & engine,NativeCallbackInfo & info)2363 NativeValue* JsWindow::OnSetKeepScreenOn(NativeEngine& engine, NativeCallbackInfo& info)
2364 {
2365 WMError errCode = WMError::WM_OK;
2366 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
2367 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2368 errCode = WMError::WM_ERROR_INVALID_PARAM;
2369 }
2370 bool keepScreenOn = true;
2371 if (errCode == WMError::WM_OK) {
2372 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
2373 if (nativeVal == nullptr) {
2374 WLOGFE("[NAPI]Failed to convert parameter to keepScreenOn");
2375 errCode = WMError::WM_ERROR_INVALID_PARAM;
2376 } else {
2377 keepScreenOn = static_cast<bool>(*nativeVal);
2378 }
2379 }
2380
2381 wptr<Window> weakToken(windowToken_);
2382 AsyncTask::CompleteCallback complete =
2383 [weakToken, keepScreenOn, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2384 auto weakWindow = weakToken.promote();
2385 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
2386 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
2387 return;
2388 }
2389 WMError ret = weakWindow->SetKeepScreenOn(keepScreenOn);
2390 if (ret == WMError::WM_OK) {
2391 task.Resolve(engine, engine.CreateUndefined());
2392 } else {
2393 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret),
2394 "Window set keep screen on failed"));
2395 }
2396 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set keep screen on end",
2397 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
2398 };
2399
2400 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2401 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
2402 NativeValue* result = nullptr;
2403 AsyncTask::Schedule("JsWindow::OnSetKeepScreenOn",
2404 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2405 return result;
2406 }
2407
OnSetWindowKeepScreenOn(NativeEngine & engine,NativeCallbackInfo & info)2408 NativeValue* JsWindow::OnSetWindowKeepScreenOn(NativeEngine& engine, NativeCallbackInfo& info)
2409 {
2410 WmErrorCode errCode = WmErrorCode::WM_OK;
2411 if (info.argc < 1) { // 1: params num
2412 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2413 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2414 }
2415 bool keepScreenOn = true;
2416 if (errCode == WmErrorCode::WM_OK) {
2417 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
2418 if (nativeVal == nullptr) {
2419 WLOGFE("[NAPI]Failed to convert parameter to keepScreenOn");
2420 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2421 } else {
2422 keepScreenOn = static_cast<bool>(*nativeVal);
2423 }
2424 }
2425 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
2426 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
2427 return engine.CreateUndefined();
2428 }
2429
2430 wptr<Window> weakToken(windowToken_);
2431 AsyncTask::CompleteCallback complete =
2432 [weakToken, keepScreenOn](NativeEngine& engine, AsyncTask& task, int32_t status) {
2433 auto weakWindow = weakToken.promote();
2434 if (weakWindow == nullptr) {
2435 task.Reject(engine,
2436 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY),
2437 "Invalidate params."));
2438 return;
2439 }
2440 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->SetKeepScreenOn(keepScreenOn));
2441 if (ret == WmErrorCode::WM_OK) {
2442 task.Resolve(engine, engine.CreateUndefined());
2443 } else {
2444 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret),
2445 "Window set keep screen on failed"));
2446 }
2447 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set keep screen on end",
2448 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
2449 };
2450
2451 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2452 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
2453 info.argv[1] : nullptr);
2454 NativeValue* result = nullptr;
2455 AsyncTask::Schedule("JsWindow::OnSetWindowKeepScreenOn",
2456 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2457 return result;
2458 }
2459
OnSetWakeUpScreen(NativeEngine & engine,NativeCallbackInfo & info)2460 NativeValue* JsWindow::OnSetWakeUpScreen(NativeEngine& engine, NativeCallbackInfo& info)
2461 {
2462 if (!Permission::IsSystemCalling()) {
2463 WLOGFE("set wake up screen permission denied!");
2464 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
2465 return engine.CreateUndefined();
2466 }
2467 WmErrorCode errCode = WmErrorCode::WM_OK;
2468 if (info.argc < 1 || windowToken_ == nullptr) {
2469 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2470 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
2471 return engine.CreateUndefined();
2472 }
2473 bool wakeUp = false;
2474 if (errCode == WmErrorCode::WM_OK) {
2475 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
2476 if (nativeVal == nullptr) {
2477 WLOGFE("[NAPI]Failed to convert parameter to keepScreenOn");
2478 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
2479 return engine.CreateUndefined();
2480 } else {
2481 wakeUp = static_cast<bool>(*nativeVal);
2482 }
2483 }
2484
2485 windowToken_->SetTurnScreenOn(wakeUp);
2486 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set wake up screen %{public}d end",
2487 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), wakeUp);
2488 return engine.CreateUndefined();
2489 }
2490
OnSetOutsideTouchable(NativeEngine & engine,NativeCallbackInfo & info)2491 NativeValue* JsWindow::OnSetOutsideTouchable(NativeEngine& engine, NativeCallbackInfo& info)
2492 {
2493 AsyncTask::CompleteCallback complete =
2494 [](NativeEngine& engine, AsyncTask& task, int32_t status) {
2495 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_DEVICE_NOT_SUPPORT)));
2496 };
2497
2498 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2499 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
2500 NativeValue* result = nullptr;
2501 AsyncTask::Schedule("JsWindow::OnSetOutsideTouchable",
2502 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2503 return result;
2504 }
2505
OnSetPrivacyMode(NativeEngine & engine,NativeCallbackInfo & info)2506 NativeValue* JsWindow::OnSetPrivacyMode(NativeEngine& engine, NativeCallbackInfo& info)
2507 {
2508 WMError errCode = WMError::WM_OK;
2509 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
2510 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2511 errCode = WMError::WM_ERROR_INVALID_PARAM;
2512 }
2513 bool isPrivacyMode = false;
2514 if (errCode == WMError::WM_OK) {
2515 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
2516 if (nativeVal == nullptr) {
2517 WLOGFE("[NAPI]Failed to convert parameter to isPrivacyMode");
2518 errCode = WMError::WM_ERROR_INVALID_PARAM;
2519 } else {
2520 isPrivacyMode = static_cast<bool>(*nativeVal);
2521 }
2522 }
2523
2524 wptr<Window> weakToken(windowToken_);
2525 AsyncTask::CompleteCallback complete =
2526 [weakToken, isPrivacyMode, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2527 auto weakWindow = weakToken.promote();
2528 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
2529 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params"));
2530 return;
2531 }
2532 weakWindow->SetPrivacyMode(isPrivacyMode);
2533 task.Resolve(engine, engine.CreateUndefined());
2534 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set privacy mode end, mode = %{public}u",
2535 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), isPrivacyMode);
2536 };
2537
2538 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2539 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
2540 NativeValue* result = nullptr;
2541 AsyncTask::Schedule("JsWindow::OnSetPrivacyMode",
2542 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2543 return result;
2544 }
2545
OnSetWindowPrivacyMode(NativeEngine & engine,NativeCallbackInfo & info)2546 NativeValue* JsWindow::OnSetWindowPrivacyMode(NativeEngine& engine, NativeCallbackInfo& info)
2547 {
2548 WmErrorCode errCode = WmErrorCode::WM_OK;
2549 if (info.argc < 1) { // 1: params num
2550 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2551 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2552 }
2553 bool isPrivacyMode = false;
2554 if (errCode == WmErrorCode::WM_OK) {
2555 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
2556 if (nativeVal == nullptr) {
2557 WLOGFE("[NAPI]Failed to convert parameter to isPrivacyMode");
2558 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2559 } else {
2560 isPrivacyMode = static_cast<bool>(*nativeVal);
2561 }
2562 }
2563 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
2564 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
2565 return engine.CreateUndefined();
2566 }
2567
2568 wptr<Window> weakToken(windowToken_);
2569 AsyncTask::CompleteCallback complete =
2570 [weakToken, isPrivacyMode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2571 auto weakWindow = weakToken.promote();
2572 if (weakWindow == nullptr) {
2573 task.Reject(engine,
2574 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY),
2575 "Invalidate params"));
2576 return;
2577 }
2578 weakWindow->SetPrivacyMode(isPrivacyMode);
2579 task.Resolve(engine, engine.CreateUndefined());
2580 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set privacy mode end, mode = %{public}u",
2581 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), isPrivacyMode);
2582 };
2583
2584 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2585 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
2586 info.argv[1] : nullptr);
2587 NativeValue* result = nullptr;
2588 AsyncTask::Schedule("JsWindow::OnSetWindowPrivacyMode",
2589 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2590 return result;
2591 }
2592
OnSetTouchable(NativeEngine & engine,NativeCallbackInfo & info)2593 NativeValue* JsWindow::OnSetTouchable(NativeEngine& engine, NativeCallbackInfo& info)
2594 {
2595 WMError errCode = WMError::WM_OK;
2596 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
2597 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2598 errCode = WMError::WM_ERROR_INVALID_PARAM;
2599 }
2600 bool touchable = true;
2601 if (errCode == WMError::WM_OK) {
2602 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
2603 if (nativeVal == nullptr) {
2604 WLOGFE("[NAPI]Failed to convert parameter to touchable");
2605 errCode = WMError::WM_ERROR_INVALID_PARAM;
2606 } else {
2607 touchable = static_cast<bool>(*nativeVal);
2608 }
2609 }
2610
2611 wptr<Window> weakToken(windowToken_);
2612 AsyncTask::CompleteCallback complete =
2613 [weakToken, touchable, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2614 auto weakWindow = weakToken.promote();
2615 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
2616 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
2617 return;
2618 }
2619 WMError ret = weakWindow->SetTouchable(touchable);
2620 if (ret == WMError::WM_OK) {
2621 task.Resolve(engine, engine.CreateUndefined());
2622 } else {
2623 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window set touchable failed"));
2624 }
2625 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set touchable end",
2626 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
2627 };
2628
2629 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2630 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
2631 NativeValue* result = nullptr;
2632 AsyncTask::Schedule("JsWindow::OnSetTouchable",
2633 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2634 return result;
2635 }
2636
OnSetWindowTouchable(NativeEngine & engine,NativeCallbackInfo & info)2637 NativeValue* JsWindow::OnSetWindowTouchable(NativeEngine& engine, NativeCallbackInfo& info)
2638 {
2639 WmErrorCode errCode = WmErrorCode::WM_OK;
2640 if (info.argc < 1) { // 1: params num
2641 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2642 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2643 }
2644 bool touchable = true;
2645 if (errCode == WmErrorCode::WM_OK) {
2646 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
2647 if (nativeVal == nullptr) {
2648 WLOGFE("[NAPI]Failed to convert parameter to touchable");
2649 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2650 } else {
2651 touchable = static_cast<bool>(*nativeVal);
2652 }
2653 }
2654 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
2655 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
2656 return engine.CreateUndefined();
2657 }
2658
2659 wptr<Window> weakToken(windowToken_);
2660 AsyncTask::CompleteCallback complete =
2661 [weakToken, touchable](NativeEngine& engine, AsyncTask& task, int32_t status) {
2662 auto weakWindow = weakToken.promote();
2663 if (weakWindow == nullptr) {
2664 task.Reject(engine,
2665 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY),
2666 "Invalidate params."));
2667 return;
2668 }
2669 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->SetTouchable(touchable));
2670 if (ret == WmErrorCode::WM_OK) {
2671 task.Resolve(engine, engine.CreateUndefined());
2672 } else {
2673 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window set touchable failed"));
2674 }
2675 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set touchable end",
2676 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
2677 };
2678
2679 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2680 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
2681 info.argv[1] : nullptr);
2682 NativeValue* result = nullptr;
2683 AsyncTask::Schedule("JsWindow::OnSetWindowTouchable",
2684 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2685 return result;
2686 }
2687
OnSetTransparent(NativeEngine & engine,NativeCallbackInfo & info)2688 NativeValue* JsWindow::OnSetTransparent(NativeEngine& engine, NativeCallbackInfo& info)
2689 {
2690 WMError errCode = WMError::WM_OK;
2691 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
2692 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2693 errCode = WMError::WM_ERROR_INVALID_PARAM;
2694 }
2695 bool isTransparent = true;
2696 if (errCode == WMError::WM_OK) {
2697 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
2698 if (nativeVal == nullptr) {
2699 WLOGFE("[NAPI]Failed to convert parameter to isTransparent");
2700 errCode = WMError::WM_ERROR_INVALID_PARAM;
2701 } else {
2702 isTransparent = static_cast<bool>(*nativeVal);
2703 }
2704 }
2705
2706 wptr<Window> weakToken(windowToken_);
2707 AsyncTask::CompleteCallback complete =
2708 [weakToken, isTransparent, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2709 auto weakWindow = weakToken.promote();
2710 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
2711 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
2712 return;
2713 }
2714 WMError ret = weakWindow->SetTransparent(isTransparent);
2715 if (ret == WMError::WM_OK) {
2716 task.Resolve(engine, engine.CreateUndefined());
2717 } else {
2718 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "Window set transparent failed"));
2719 }
2720 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set transparent end",
2721 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
2722 };
2723
2724 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2725 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
2726 NativeValue* result = nullptr;
2727 AsyncTask::Schedule("JsWindow::OnSetTransparent",
2728 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2729 return result;
2730 }
2731
OnSetCallingWindow(NativeEngine & engine,NativeCallbackInfo & info)2732 NativeValue* JsWindow::OnSetCallingWindow(NativeEngine& engine, NativeCallbackInfo& info)
2733 {
2734 WMError errCode = WMError::WM_OK;
2735 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
2736 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2737 errCode = WMError::WM_ERROR_INVALID_PARAM;
2738 }
2739 uint32_t callingWindow = INVALID_WINDOW_ID;
2740 if (errCode == WMError::WM_OK) {
2741 NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
2742 if (nativeVal == nullptr) {
2743 WLOGFE("[NAPI]Failed to convert parameter to touchable");
2744 errCode = WMError::WM_ERROR_INVALID_PARAM;
2745 } else {
2746 callingWindow = static_cast<uint32_t>(*nativeVal);
2747 }
2748 }
2749
2750 wptr<Window> weakToken(windowToken_);
2751 AsyncTask::CompleteCallback complete =
2752 [weakToken, callingWindow, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2753 auto weakWindow = weakToken.promote();
2754 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
2755 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
2756 return;
2757 }
2758 WMError ret = weakWindow->SetCallingWindow(callingWindow);
2759 if (ret == WMError::WM_OK) {
2760 task.Resolve(engine, engine.CreateUndefined());
2761 } else {
2762 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret),
2763 "Window set calling window failed"));
2764 }
2765 WLOGFD("[NAPI]Window [%{public}u, %{public}s] set calling window end",
2766 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
2767 };
2768
2769 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2770 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
2771 NativeValue* result = nullptr;
2772 AsyncTask::Schedule("JsWindow::OnSetCallingWindow",
2773 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2774 return result;
2775 }
2776
OnDisableWindowDecor(NativeEngine & engine,NativeCallbackInfo & info)2777 NativeValue* JsWindow::OnDisableWindowDecor(NativeEngine& engine, NativeCallbackInfo& info)
2778 {
2779 if (windowToken_ == nullptr) {
2780 return engine.CreateUndefined();
2781 }
2782 windowToken_->DisableAppWindowDecor();
2783 WLOGFD("[NAPI]Window [%{public}u, %{public}s] disable app window decor end",
2784 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str());
2785 return engine.CreateUndefined();
2786 }
2787
OnSetColorSpace(NativeEngine & engine,NativeCallbackInfo & info)2788 NativeValue* JsWindow::OnSetColorSpace(NativeEngine& engine, NativeCallbackInfo& info)
2789 {
2790 WMError errCode = WMError::WM_OK;
2791 ColorSpace colorSpace = ColorSpace::COLOR_SPACE_DEFAULT;
2792 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
2793 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2794 errCode = WMError::WM_ERROR_INVALID_PARAM;
2795 } else {
2796 NativeNumber* nativeType = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
2797 if (nativeType == nullptr) {
2798 errCode = WMError::WM_ERROR_INVALID_PARAM;
2799 WLOGFE("[NAPI]Failed to convert parameter to ColorSpace");
2800 } else {
2801 colorSpace = static_cast<ColorSpace>(static_cast<uint32_t>(*nativeType));
2802 if (colorSpace > ColorSpace::COLOR_SPACE_WIDE_GAMUT) {
2803 WLOGFE("[NAPI]ColorSpace %{public}u invalid!", static_cast<uint32_t>(colorSpace));
2804 errCode = WMError::WM_ERROR_INVALID_PARAM;
2805 }
2806 }
2807 }
2808
2809 wptr<Window> weakToken(windowToken_);
2810 AsyncTask::CompleteCallback complete =
2811 [weakToken, colorSpace, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2812 auto weakWindow = weakToken.promote();
2813 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
2814 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "OnSetColorSpace failed"));
2815 WLOGFE("[NAPI]window is nullptr or get invalid param");
2816 return;
2817 }
2818 weakWindow->SetColorSpace(colorSpace);
2819 task.Resolve(engine, engine.CreateUndefined());
2820 WLOGFD("[NAPI]Window [%{public}u, %{public}s] OnSetColorSpace end, colorSpace = %{public}u",
2821 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), static_cast<uint32_t>(colorSpace));
2822 };
2823
2824 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2825 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
2826 NativeValue* result = nullptr;
2827 AsyncTask::Schedule("JsWindow::OnSetColorSpace",
2828 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2829 return result;
2830 }
2831
OnSetWindowColorSpace(NativeEngine & engine,NativeCallbackInfo & info)2832 NativeValue* JsWindow::OnSetWindowColorSpace(NativeEngine& engine, NativeCallbackInfo& info)
2833 {
2834 WmErrorCode errCode = WmErrorCode::WM_OK;
2835 ColorSpace colorSpace = ColorSpace::COLOR_SPACE_DEFAULT;
2836 if (info.argc < 1) { // 1: params num
2837 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2838 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2839 } else {
2840 NativeNumber* nativeType = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
2841 if (nativeType == nullptr) {
2842 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2843 WLOGFE("[NAPI]Failed to convert parameter to ColorSpace");
2844 } else {
2845 colorSpace = static_cast<ColorSpace>(static_cast<uint32_t>(*nativeType));
2846 if (colorSpace > ColorSpace::COLOR_SPACE_WIDE_GAMUT) {
2847 WLOGFE("[NAPI]ColorSpace %{public}u invalid!", static_cast<uint32_t>(colorSpace));
2848 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2849 }
2850 }
2851 }
2852 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
2853 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
2854 return engine.CreateUndefined();
2855 }
2856
2857 wptr<Window> weakToken(windowToken_);
2858 AsyncTask::CompleteCallback complete =
2859 [weakToken, colorSpace](NativeEngine& engine, AsyncTask& task, int32_t status) {
2860 auto weakWindow = weakToken.promote();
2861 if (weakWindow == nullptr) {
2862 WLOGFE("[NAPI]window is nullptr");
2863 task.Reject(engine,
2864 CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY),
2865 "OnSetWindowColorSpace failed"));
2866 return;
2867 }
2868 weakWindow->SetColorSpace(colorSpace);
2869 task.Resolve(engine, engine.CreateUndefined());
2870 WLOGFD("[NAPI]Window [%{public}u, %{public}s] OnSetWindowColorSpace end, colorSpace = %{public}u",
2871 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), static_cast<uint32_t>(colorSpace));
2872 };
2873
2874 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
2875 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
2876 info.argv[1] : nullptr);
2877 NativeValue* result = nullptr;
2878 AsyncTask::Schedule("JsWindow::OnSetWindowColorSpace",
2879 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2880 return result;
2881 }
2882
OnGetColorSpace(NativeEngine & engine,NativeCallbackInfo & info)2883 NativeValue* JsWindow::OnGetColorSpace(NativeEngine& engine, NativeCallbackInfo& info)
2884 {
2885 WMError errCode = WMError::WM_OK;
2886 if (info.argc > 1) {
2887 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2888 errCode = WMError::WM_ERROR_INVALID_PARAM;
2889 }
2890 wptr<Window> weakToken(windowToken_);
2891 AsyncTask::CompleteCallback complete =
2892 [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
2893 auto weakWindow = weakToken.promote();
2894 if (weakWindow == nullptr || errCode != WMError::WM_OK) {
2895 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
2896 WLOGFE("[NAPI]window is nullptr or get invalid param");
2897 return;
2898 }
2899 ColorSpace colorSpace = weakWindow->GetColorSpace();
2900 task.Resolve(engine, CreateJsValue(engine, static_cast<uint32_t>(colorSpace)));
2901 WLOGFD("[NAPI]Window [%{public}u, %{public}s] OnGetColorSpace end, colorSpace = %{public}u",
2902 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), static_cast<uint32_t>(colorSpace));
2903 };
2904
2905 NativeValue* lastParam = (info.argc == 0) ? nullptr :
2906 (info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
2907 NativeValue* result = nullptr;
2908 AsyncTask::Schedule("JsWindow::OnGetColorSpace",
2909 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
2910 return result;
2911 }
2912
OnGetWindowColorSpaceSync(NativeEngine & engine,NativeCallbackInfo & info)2913 NativeValue* JsWindow::OnGetWindowColorSpaceSync(NativeEngine& engine, NativeCallbackInfo& info)
2914 {
2915 wptr<Window> weakToken(windowToken_);
2916 auto window = weakToken.promote();
2917 if (window == nullptr) {
2918 WLOGFE("[NAPI]window is nullptr");
2919 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
2920 return engine.CreateUndefined();
2921 }
2922 ColorSpace colorSpace = window->GetColorSpace();
2923 WLOGFD("[NAPI]Window [%{public}u, %{public}s] OnGetColorSpace end, colorSpace = %{public}u",
2924 window->GetWindowId(), window->GetWindowName().c_str(), static_cast<uint32_t>(colorSpace));
2925
2926 return CreateJsValue(engine, static_cast<uint32_t>(colorSpace));
2927 }
2928
OnDump(NativeEngine & engine,NativeCallbackInfo & info)2929 NativeValue* JsWindow::OnDump(NativeEngine& engine, NativeCallbackInfo& info)
2930 {
2931 WLOGFD("[NAPI]dump window start");
2932 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
2933 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
2934 return nullptr;
2935 }
2936 if (windowToken_ == nullptr) {
2937 WLOGFE("[NAPI]window is nullptr or get invalid param");
2938 return nullptr;
2939 }
2940 std::vector<std::string> params;
2941 if (!ConvertNativeValueToVector(engine, info.argv[0], params)) {
2942 WLOGFE("[NAPI]ConvertNativeValueToVector fail");
2943 return nullptr;
2944 }
2945 std::vector<std::string> dumpInfo;
2946 windowToken_->DumpInfo(params, dumpInfo);
2947 NativeValue* dumpInfoValue = CreateNativeArray(engine, dumpInfo);
2948 WLOGFD("[NAPI]Window [%{public}u, %{public}s] dump end",
2949 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str());
2950 return dumpInfoValue;
2951 }
2952
Snapshot(NativeEngine * engine,NativeCallbackInfo * info)2953 NativeValue* JsWindow::Snapshot(NativeEngine* engine, NativeCallbackInfo* info)
2954 {
2955 WLOGFD("[NAPI]Snapshot");
2956 JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
2957 return (me != nullptr) ? me->OnSnapshot(*engine, *info) : nullptr;
2958 }
2959
OnSetForbidSplitMove(NativeEngine & engine,NativeCallbackInfo & info)2960 NativeValue* JsWindow::OnSetForbidSplitMove(NativeEngine& engine, NativeCallbackInfo& info)
2961 {
2962 WmErrorCode errCode = WmErrorCode::WM_OK;
2963 if (info.argc < 1) { // 1: params num
2964 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2965 }
2966 bool isForbidSplitMove = false;
2967 if (errCode == WmErrorCode::WM_OK) {
2968 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
2969 if (nativeVal == nullptr) {
2970 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
2971 } else {
2972 isForbidSplitMove = static_cast<bool>(*nativeVal);
2973 }
2974 }
2975 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
2976 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
2977 return engine.CreateUndefined();
2978 }
2979 wptr<Window> weakToken(windowToken_);
2980 AsyncTask::CompleteCallback complete =
2981 [weakToken, isForbidSplitMove](NativeEngine& engine, AsyncTask& task, int32_t status) {
2982 auto weakWindow = weakToken.promote();
2983 if (weakWindow == nullptr) {
2984 task.Reject(engine, CreateJsError(engine,
2985 static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "Invalidate params."));
2986 return;
2987 }
2988 WmErrorCode ret;
2989 if (isForbidSplitMove) {
2990 ret = WM_JS_TO_ERROR_CODE_MAP.at(
2991 weakWindow->AddWindowFlag(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE));
2992 } else {
2993 ret = WM_JS_TO_ERROR_CODE_MAP.at(
2994 weakWindow->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE));
2995 }
2996 if (ret == WmErrorCode::WM_OK) {
2997 task.Resolve(engine, engine.CreateUndefined());
2998 } else {
2999 task.Reject(engine, CreateJsError(engine,
3000 static_cast<int32_t>(ret), "Window OnSetForbidSplitMove failed."));
3001 }
3002 };
3003 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
3004 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
3005 info.argv[1] : nullptr);
3006 NativeValue* result = nullptr;
3007 AsyncTask::Schedule("JsWindow::OnSetForbidSplitMove",
3008 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
3009 return result;
3010 }
3011
OnSnapshot(NativeEngine & engine,NativeCallbackInfo & info)3012 NativeValue* JsWindow::OnSnapshot(NativeEngine& engine, NativeCallbackInfo& info)
3013 {
3014 wptr<Window> weakToken(windowToken_);
3015 AsyncTask::CompleteCallback complete =
3016 [weakToken](NativeEngine& engine, AsyncTask& task, int32_t status) {
3017 auto weakWindow = weakToken.promote();
3018 if (weakWindow == nullptr) {
3019 WLOGFE("[NAPI]window is nullptr");
3020 task.Reject(engine, CreateJsError(engine,
3021 static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3022 return;
3023 }
3024
3025 std::shared_ptr<Media::PixelMap> pixelMap = weakWindow->Snapshot();
3026 if (pixelMap == nullptr) {
3027 task.Reject(engine, CreateJsError(engine,
3028 static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3029 WLOGFE("[NAPI]window snapshot get pixelmap is null");
3030 return;
3031 }
3032
3033 auto nativePixelMap = reinterpret_cast<NativeValue*>(
3034 Media::PixelMapNapi::CreatePixelMap(reinterpret_cast<napi_env>(&engine), pixelMap));
3035 if (nativePixelMap == nullptr) {
3036 WLOGFE("[NAPI]window snapshot get nativePixelMap is null");
3037 }
3038 task.Resolve(engine, nativePixelMap);
3039 WLOGFD("[NAPI]Window [%{public}u, %{public}s] OnSnapshot, WxH=%{public}dx%{public}d",
3040 weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(),
3041 pixelMap->GetWidth(), pixelMap->GetHeight());
3042 };
3043
3044 NativeValue* lastParam = (info.argc == 0) ? nullptr :
3045 ((info.argv[0] != nullptr && info.argv[0]->TypeOf() == NATIVE_FUNCTION) ?
3046 info.argv[0] : nullptr);
3047 NativeValue* result = nullptr;
3048 AsyncTask::Schedule("JsWindow::OnSnapshot",
3049 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
3050 return result;
3051 }
3052
OnSetSnapshotSkip(NativeEngine & engine,NativeCallbackInfo & info)3053 NativeValue* JsWindow::OnSetSnapshotSkip(NativeEngine& engine, NativeCallbackInfo& info)
3054 {
3055 WmErrorCode errCode = WmErrorCode::WM_OK;
3056 if (info.argc < 1) { // 1: params num
3057 WLOGFE("[NAPI] inbalid param");
3058 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
3059 }
3060 bool isSkip = false;
3061 if (errCode == WmErrorCode::WM_OK) {
3062 NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
3063 if (nativeVal == nullptr) {
3064 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
3065 } else {
3066 isSkip = static_cast<bool>(*nativeVal);
3067 }
3068 }
3069 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
3070 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3071 return engine.CreateUndefined();
3072 }
3073
3074 wptr<Window> weakToken(windowToken_);
3075 auto window = weakToken.promote();
3076 if (window == nullptr) {
3077 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3078 return engine.CreateUndefined();
3079 }
3080
3081 window->SetSnapshotSkip(isSkip);
3082 WLOGFD("NAPI [%{public}u, %{public}s] set snapshotSkip end",
3083 window->GetWindowId(), window->GetWindowName().c_str());
3084
3085 return engine.CreateUndefined();
3086 }
3087
OnOpacity(NativeEngine & engine,NativeCallbackInfo & info)3088 NativeValue* JsWindow::OnOpacity(NativeEngine& engine, NativeCallbackInfo& info)
3089 {
3090 if (info.argc < 1) {
3091 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
3092 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3093 return engine.CreateUndefined();
3094 }
3095 if (windowToken_ == nullptr) {
3096 WLOGFE("[NAPI]WindowToken_ is nullptr");
3097 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3098 return engine.CreateUndefined();
3099 }
3100 if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
3101 WLOGFE("[NAPI]Opacity is not allowed since window is not system window");
3102 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
3103 return engine.CreateUndefined();
3104 }
3105 NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
3106 if (nativeVal == nullptr) {
3107 WLOGFE("[NAPI]Failed to convert parameter to alpha");
3108 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3109 return engine.CreateUndefined();
3110 }
3111 if (MathHelper::LessNotEqual(*nativeVal, 0.0) || MathHelper::GreatNotEqual(*nativeVal, 1.0)) {
3112 WLOGFE("[NAPI]alpha should greater than 0 or smaller than 1.0");
3113 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3114 return engine.CreateUndefined();
3115 }
3116 float alpha = static_cast<double>(*nativeVal);
3117 windowToken_->SetAlpha(alpha);
3118 WLOGFD("[NAPI]Window [%{public}u, %{public}s] Opacity end, alpha = %{public}f",
3119 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), alpha);
3120 return engine.CreateUndefined();
3121 }
3122
IsPivotValid(double data)3123 static bool IsPivotValid(double data)
3124 {
3125 if (MathHelper::LessNotEqual(data, 0.0) || (MathHelper::GreatNotEqual(data, 1.0))) {
3126 return false;
3127 }
3128 return true;
3129 }
3130
IsScaleValid(double data)3131 static bool IsScaleValid(double data)
3132 {
3133 if (!MathHelper::GreatNotEqual(data, 0.0)) {
3134 return false;
3135 }
3136 return true;
3137 }
3138
ParseScaleOption(NativeEngine & engine,NativeObject * jsObject,Transform & trans)3139 bool JsWindow::ParseScaleOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans)
3140 {
3141 double data = 0.0f;
3142 if (ParseJsValue(jsObject, engine, "pivotX", data)) {
3143 if (!IsPivotValid(data)) {
3144 return false;
3145 }
3146 trans.pivotX_ = data;
3147 }
3148 if (ParseJsValue(jsObject, engine, "pivotY", data)) {
3149 if (!IsPivotValid(data)) {
3150 return false;
3151 }
3152 trans.pivotY_ = data;
3153 }
3154 if (ParseJsValue(jsObject, engine, "x", data)) {
3155 if (!IsScaleValid(data)) {
3156 return false;
3157 }
3158 trans.scaleX_ = data;
3159 }
3160 if (ParseJsValue(jsObject, engine, "y", data)) {
3161 if (!IsScaleValid(data)) {
3162 return false;
3163 }
3164 trans.scaleY_ = data;
3165 }
3166 return true;
3167 }
3168
OnScale(NativeEngine & engine,NativeCallbackInfo & info)3169 NativeValue* JsWindow::OnScale(NativeEngine& engine, NativeCallbackInfo& info)
3170 {
3171 if (info.argc < 1) {
3172 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
3173 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3174 return engine.CreateUndefined();
3175 }
3176 if (windowToken_ == nullptr) {
3177 WLOGFE("[NAPI]WindowToken_ is nullptr");
3178 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3179 return engine.CreateUndefined();
3180 }
3181 if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
3182 WLOGFE("[NAPI]Scale is not allowed since window is not system window");
3183 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
3184 return engine.CreateUndefined();
3185 }
3186 NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
3187 if (nativeObj == nullptr) {
3188 WLOGFE("[NAPI]Failed to convert object to ScaleOptions");
3189 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3190 return engine.CreateUndefined();
3191 }
3192 auto trans = windowToken_->GetTransform();
3193 if (!ParseScaleOption(engine, nativeObj, trans)) {
3194 WLOGFE("[NAPI] PivotX or PivotY should between 0.0 ~ 1.0, scale should greater than 0.0");
3195 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3196 return engine.CreateUndefined();
3197 }
3198 windowToken_->SetTransform(trans);
3199 WLOGFD("[NAPI]Window [%{public}u, %{public}s] Scale end",
3200 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str());
3201 WLOGFD("[NAPI]scaleX = %{public}f, scaleY = %{public}f, pivotX = %{public}f pivotY = %{public}f",
3202 trans.scaleX_, trans.scaleY_, trans.pivotX_, trans.pivotY_);
3203 return engine.CreateUndefined();
3204 }
3205
ParseRotateOption(NativeEngine & engine,NativeObject * jsObject,Transform & trans)3206 bool JsWindow::ParseRotateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans)
3207 {
3208 double data = 0.0f;
3209 if (ParseJsValue(jsObject, engine, "pivotX", data)) {
3210 if (!IsPivotValid(data)) {
3211 return false;
3212 }
3213 trans.pivotX_ = data;
3214 }
3215 if (ParseJsValue(jsObject, engine, "pivotY", data)) {
3216 if (!IsPivotValid(data)) {
3217 return false;
3218 }
3219 trans.pivotY_ = data;
3220 }
3221 if (ParseJsValue(jsObject, engine, "x", data)) {
3222 trans.rotationX_ = data;
3223 }
3224 if (ParseJsValue(jsObject, engine, "y", data)) {
3225 trans.rotationY_ = data;
3226 }
3227 if (ParseJsValue(jsObject, engine, "z", data)) {
3228 trans.rotationZ_ = data;
3229 }
3230 return true;
3231 }
3232
OnRotate(NativeEngine & engine,NativeCallbackInfo & info)3233 NativeValue* JsWindow::OnRotate(NativeEngine& engine, NativeCallbackInfo& info)
3234 {
3235 if (info.argc < 1) {
3236 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
3237 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3238 return engine.CreateUndefined();
3239 }
3240 if (windowToken_ == nullptr) {
3241 WLOGFE("[NAPI]WindowToken_ is nullptr");
3242 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3243 return engine.CreateUndefined();
3244 }
3245 if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
3246 WLOGFE("[NAPI]Rotate is not allowed since window is not system window");
3247 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
3248 return engine.CreateUndefined();
3249 }
3250 NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
3251 if (nativeObj == nullptr) {
3252 WLOGFE("[NAPI]Failed to convert object to RotateOptions");
3253 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3254 return engine.CreateUndefined();
3255 }
3256 // cannot use sync task since next transform base on current transform
3257 auto trans = windowToken_->GetTransform();
3258 if (!ParseRotateOption(engine, nativeObj, trans)) {
3259 WLOGFE("[NAPI] PivotX or PivotY should between 0.0 ~ 1.0");
3260 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3261 return engine.CreateUndefined();
3262 }
3263 windowToken_->SetTransform(trans);
3264 WLOGFD("[NAPI]Window [%{public}u, %{public}s] Rotate end",
3265 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str());
3266 WLOGFD("[NAPI]rotateX = %{public}f, rotateY = %{public}f," \
3267 "rotateZ = %{public}f pivotX = %{public}f pivotY = %{public}f",
3268 trans.rotationX_, trans.rotationY_, trans.rotationZ_, trans.pivotX_, trans.pivotY_);
3269 return engine.CreateUndefined();
3270 }
3271
ParseTranslateOption(NativeEngine & engine,NativeObject * jsObject,Transform & trans)3272 bool JsWindow::ParseTranslateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans)
3273 {
3274 double data = 0.0f;
3275 if (ParseJsValue(jsObject, engine, "x", data)) {
3276 trans.translateX_ = data;
3277 }
3278 if (ParseJsValue(jsObject, engine, "y", data)) {
3279 trans.translateY_ = data;
3280 }
3281 if (ParseJsValue(jsObject, engine, "z", data)) {
3282 trans.translateZ_ = data;
3283 }
3284 return true;
3285 }
3286
OnTranslate(NativeEngine & engine,NativeCallbackInfo & info)3287 NativeValue* JsWindow::OnTranslate(NativeEngine& engine, NativeCallbackInfo& info)
3288 {
3289 if (info.argc < 1) {
3290 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
3291 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3292 return engine.CreateUndefined();
3293 }
3294 if (windowToken_ == nullptr) {
3295 WLOGFE("[NAPI]WindowToken_ is nullptr");
3296 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3297 return engine.CreateUndefined();
3298 }
3299 if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
3300 WLOGFE("[NAPI]Translate is not allowed since window is not system window");
3301 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
3302 return engine.CreateUndefined();
3303 }
3304 NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
3305 if (nativeObj == nullptr) {
3306 WLOGFE("[NAPI]Failed to convert object to TranslateOptions");
3307 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3308 return engine.CreateUndefined();
3309 }
3310 auto trans = windowToken_->GetTransform();
3311 if (!ParseTranslateOption(engine, nativeObj, trans)) {
3312 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3313 return engine.CreateUndefined();
3314 }
3315 windowToken_->SetTransform(trans);
3316 WLOGFD("[NAPI]Window [%{public}u, %{public}s] Translate end," \
3317 "translateX = %{public}f, translateY = %{public}f, translateZ = %{public}f",
3318 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(),
3319 trans.translateX_, trans.translateY_, trans.translateZ_);
3320 return engine.CreateUndefined();
3321 }
3322
CreateTransitionController(NativeEngine & engine)3323 void JsWindow::CreateTransitionController(NativeEngine& engine)
3324 {
3325 if (windowToken_ == nullptr) {
3326 WLOGFE("[NAPI]windowToken_ is nullptr not match");
3327 return;
3328 }
3329 if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
3330 WLOGFE("[NAPI]CreateTransitionController is not allowed since window is not system window");
3331 return;
3332 }
3333 NativeValue* objValue = engine.CreateObject();
3334 auto name = GetWindowName();
3335 std::shared_ptr<NativeReference> jsWindowObj = FindJsWindowObject(name);
3336 if (jsWindowObj == nullptr || jsWindowObj->Get() == nullptr) {
3337 return;
3338 }
3339 sptr<JsTransitionController> nativeController = new JsTransitionController(
3340 engine, jsWindowObj, windowToken_);
3341 NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
3342 if (object == nullptr) {
3343 WLOGFE("[NAPI]Failed to convert to TransitionController Object");
3344 return;
3345 }
3346 object->SetNativePointer(new wptr<JsTransitionController>(nativeController),
3347 [](NativeEngine*, void* data, void*) {
3348 WLOGFE("Finalizer for wptr form native Transition Controller is called");
3349 delete static_cast<wptr<JsTransitionController>*>(data);
3350 }, nullptr);
3351 windowToken_->RegisterAnimationTransitionController(nativeController);
3352 jsTransControllerObj_.reset(engine.CreateReference(objValue, 1));
3353 nativeController->SetJsController(jsTransControllerObj_);
3354 WLOGFD("[NAPI]Window [%{public}u, %{public}s] CreateTransitionController end",
3355 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str());
3356 }
3357
OnGetTransitionController(NativeEngine & engine,NativeCallbackInfo & info)3358 NativeValue* JsWindow::OnGetTransitionController(NativeEngine& engine, NativeCallbackInfo& info)
3359 {
3360 if (windowToken_ == nullptr) {
3361 WLOGFE("[NAPI]WindowToken_ is nullptr");
3362 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3363 return engine.CreateUndefined();
3364 }
3365 if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
3366 WLOGFE("[NAPI]OnGetTransitionController is not allowed since window is not system window");
3367 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
3368 return engine.CreateUndefined();
3369 }
3370 if (jsTransControllerObj_ == nullptr || jsTransControllerObj_->Get() == nullptr) {
3371 CreateTransitionController(engine);
3372 }
3373 return jsTransControllerObj_ == nullptr ? nullptr : jsTransControllerObj_->Get();
3374 }
3375
OnSetCornerRadius(NativeEngine & engine,NativeCallbackInfo & info)3376 NativeValue* JsWindow::OnSetCornerRadius(NativeEngine& engine, NativeCallbackInfo& info)
3377 {
3378 if (!Permission::IsSystemCalling()) {
3379 WLOGFE("set corner radius permission denied!");
3380 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
3381 return engine.CreateUndefined();
3382 }
3383 if (info.argc < 1) {
3384 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
3385 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3386 return engine.CreateUndefined();
3387 }
3388 if (windowToken_ == nullptr) {
3389 WLOGFE("[NAPI]WindowToken_ is nullptr");
3390 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3391 return engine.CreateUndefined();
3392 }
3393 if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
3394 WLOGFE("[NAPI]SetCornerRadius is not allowed since window is not system window");
3395 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
3396 return engine.CreateUndefined();
3397 }
3398 NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
3399 if (nativeVal == nullptr || MathHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
3400 WLOGFE("[NAPI]SetCornerRadius invalid radius");
3401 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3402 return engine.CreateUndefined();
3403 }
3404 float radius = static_cast<double>(*nativeVal);
3405 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetCornerRadius(radius));
3406 if (ret != WmErrorCode::WM_OK) {
3407 WLOGFE("[NAPI]Window SetCornerRadius failed");
3408 engine.Throw(CreateJsError(engine, static_cast<int32_t>(ret)));
3409 return engine.CreateUndefined();
3410 }
3411 WLOGFD("[NAPI]Window [%{public}u, %{public}s] SetCornerRadius end, radius = %{public}f",
3412 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), radius);
3413 return engine.CreateUndefined();
3414 }
3415
OnSetShadow(NativeEngine & engine,NativeCallbackInfo & info)3416 NativeValue* JsWindow::OnSetShadow(NativeEngine& engine, NativeCallbackInfo& info)
3417 {
3418 WmErrorCode ret = WmErrorCode::WM_OK;
3419 if (info.argc < 1) { // 1: min param num
3420 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3421 return engine.CreateUndefined();
3422 }
3423 if (windowToken_ == nullptr) {
3424 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3425 return engine.CreateUndefined();
3426 }
3427 if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
3428 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
3429 return engine.CreateUndefined();
3430 }
3431
3432 { // parse the 1st param: radius
3433 NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
3434 if (nativeVal == nullptr || MathHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
3435 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3436 return engine.CreateUndefined();
3437 }
3438 ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetShadowRadius(static_cast<double>(*nativeVal)));
3439 }
3440
3441 if ((ret == WmErrorCode::WM_OK) && (info.argc >= 2)) { // parse the 2nd param: color
3442 std::string color;
3443 if (!ConvertFromJsValue(engine, info.argv[1], color)) {
3444 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3445 return engine.CreateUndefined();
3446 }
3447 ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetShadowColor(color));
3448 }
3449
3450 if (ret != WmErrorCode::WM_OK) {
3451 engine.Throw(CreateJsError(engine, static_cast<int32_t>(ret)));
3452 return engine.CreateUndefined();
3453 }
3454
3455 if (info.argc >= 3) { // parse the 3rd param: offsetX
3456 NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[2]); // 2: the 3rd param
3457 if (nativeVal == nullptr) {
3458 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3459 return engine.CreateUndefined();
3460 }
3461 windowToken_->SetShadowOffsetX(static_cast<double>(*nativeVal));
3462 }
3463
3464 if (info.argc >= 4) { // parse the 4th param: offsetY
3465 NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[3]); // 3: the 4th param
3466 if (nativeVal == nullptr) {
3467 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3468 return engine.CreateUndefined();
3469 }
3470 windowToken_->SetShadowOffsetY(static_cast<double>(*nativeVal));
3471 }
3472 return engine.CreateUndefined();
3473 }
3474
OnSetBlur(NativeEngine & engine,NativeCallbackInfo & info)3475 NativeValue* JsWindow::OnSetBlur(NativeEngine& engine, NativeCallbackInfo& info)
3476 {
3477 if (info.argc < 1) {
3478 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
3479 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3480 return engine.CreateUndefined();
3481 }
3482 if (windowToken_ == nullptr) {
3483 WLOGFE("[NAPI]WindowToken_ is nullptr");
3484 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3485 return engine.CreateUndefined();
3486 }
3487 if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
3488 WLOGFE("[NAPI]SetBlur is not allowed since window is not system window");
3489 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
3490 return engine.CreateUndefined();
3491 }
3492 NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
3493 if (nativeVal == nullptr || MathHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
3494 WLOGFE("[NAPI]SetBlur invalid radius");
3495 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3496 return engine.CreateUndefined();
3497 }
3498 float radius = static_cast<double>(*nativeVal);
3499 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetBlur(radius));
3500 if (ret != WmErrorCode::WM_OK) {
3501 WLOGFE("[NAPI]Window SetBlur failed");
3502 engine.Throw(CreateJsError(engine, static_cast<int32_t>(ret)));
3503 return engine.CreateUndefined();
3504 }
3505 WLOGFD("[NAPI]Window [%{public}u, %{public}s] SetBlur end, radius = %{public}f",
3506 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), radius);
3507 return engine.CreateUndefined();
3508 }
3509
OnSetBackdropBlur(NativeEngine & engine,NativeCallbackInfo & info)3510 NativeValue* JsWindow::OnSetBackdropBlur(NativeEngine& engine, NativeCallbackInfo& info)
3511 {
3512 if (info.argc < 1) {
3513 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
3514 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3515 return engine.CreateUndefined();
3516 }
3517 if (windowToken_ == nullptr) {
3518 WLOGFE("[NAPI]WindowToken_ is nullptr");
3519 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3520 return engine.CreateUndefined();
3521 }
3522 if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
3523 WLOGFE("[NAPI]SetBackdropBlur is not allowed since window is not system window");
3524 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
3525 return engine.CreateUndefined();
3526 }
3527 NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
3528 if (nativeVal == nullptr || MathHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
3529 WLOGFE("[NAPI]SetBackdropBlur invalid radius");
3530 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3531 return engine.CreateUndefined();
3532 }
3533 float radius = static_cast<double>(*nativeVal);
3534 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetBackdropBlur(radius));
3535 if (ret != WmErrorCode::WM_OK) {
3536 WLOGFE("[NAPI]Window SetBackdropBlur failed");
3537 engine.Throw(CreateJsError(engine, static_cast<int32_t>(ret)));
3538 return engine.CreateUndefined();
3539 }
3540 WLOGFD("[NAPI]Window [%{public}u, %{public}s] SetBackdropBlur end, radius = %{public}f",
3541 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), radius);
3542 return engine.CreateUndefined();
3543 }
3544
OnSetBackdropBlurStyle(NativeEngine & engine,NativeCallbackInfo & info)3545 NativeValue* JsWindow::OnSetBackdropBlurStyle(NativeEngine& engine, NativeCallbackInfo& info)
3546 {
3547 if (info.argc < 1) {
3548 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
3549 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3550 return engine.CreateUndefined();
3551 }
3552 if (windowToken_ == nullptr) {
3553 WLOGFE("[NAPI]WindowToken_ is nullptr");
3554 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
3555 return engine.CreateUndefined();
3556 }
3557 if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
3558 WLOGFE("[NAPI]SetBackdropBlurStyle is not allowed since window is not system window");
3559 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_CALLING)));
3560 return engine.CreateUndefined();
3561 }
3562
3563 NativeNumber* nativeMode = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
3564 if (nativeMode == nullptr ||
3565 static_cast<uint32_t>(*nativeMode) > static_cast<uint32_t>(WindowBlurStyle::WINDOW_BLUR_THICK)) {
3566 WLOGFE("[NAPI]SetBackdropBlurStyle Invalid window blur style");
3567 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
3568 return engine.CreateUndefined();
3569 }
3570 WindowBlurStyle style = static_cast<WindowBlurStyle>(static_cast<uint32_t>(*nativeMode));
3571 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetBackdropBlurStyle(style));
3572 if (ret != WmErrorCode::WM_OK) {
3573 WLOGFE("[NAPI]Window SetBackdropBlurStyle failed");
3574 engine.Throw(CreateJsError(engine, static_cast<int32_t>(ret)));
3575 return engine.CreateUndefined();
3576 }
3577
3578 WLOGFD("[NAPI]Window [%{public}u, %{public}s] SetBackdropBlurStyle end, style = %{public}u",
3579 windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), style);
3580 return engine.CreateUndefined();
3581 }
3582
FindJsWindowObject(std::string windowName)3583 std::shared_ptr<NativeReference> FindJsWindowObject(std::string windowName)
3584 {
3585 WLOGFD("[NAPI]Try to find window %{public}s in g_jsWindowMap", windowName.c_str());
3586 std::lock_guard<std::recursive_mutex> lock(g_mutex);
3587 if (g_jsWindowMap.find(windowName) == g_jsWindowMap.end()) {
3588 WLOGFD("[NAPI]Can not find window %{public}s in g_jsWindowMap", windowName.c_str());
3589 return nullptr;
3590 }
3591 return g_jsWindowMap[windowName];
3592 }
3593
CreateJsWindowObject(NativeEngine & engine,sptr<Window> & window)3594 NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window)
3595 {
3596 std::string windowName = window->GetWindowName();
3597 // avoid repeatedly create js window when getWindow
3598 std::shared_ptr<NativeReference> jsWindowObj = FindJsWindowObject(windowName);
3599 if (jsWindowObj != nullptr && jsWindowObj->Get() != nullptr) {
3600 WLOGFD("[NAPI]FindJsWindowObject %{public}s", windowName.c_str());
3601 return jsWindowObj->Get();
3602 }
3603 NativeValue* objValue = engine.CreateObject();
3604 NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
3605
3606 WLOGFD("[NAPI]CreateJsWindow %{public}s", windowName.c_str());
3607 std::unique_ptr<JsWindow> jsWindow = std::make_unique<JsWindow>(window);
3608 object->SetNativePointer(jsWindow.release(), JsWindow::Finalizer, nullptr);
3609
3610 BindFunctions(engine, object, "JsWindow");
3611
3612 std::shared_ptr<NativeReference> jsWindowRef;
3613 jsWindowRef.reset(engine.CreateReference(objValue, 1));
3614 std::lock_guard<std::recursive_mutex> lock(g_mutex);
3615 g_jsWindowMap[windowName] = jsWindowRef;
3616 return objValue;
3617 }
3618
BindFunctions(NativeEngine & engine,NativeObject * object,const char * moduleName)3619 void BindFunctions(NativeEngine& engine, NativeObject* object, const char *moduleName)
3620 {
3621 BindNativeFunction(engine, *object, "show", moduleName, JsWindow::Show);
3622 BindNativeFunction(engine, *object, "showWindow", moduleName, JsWindow::ShowWindow);
3623 BindNativeFunction(engine, *object, "showWithAnimation", moduleName, JsWindow::ShowWithAnimation);
3624 BindNativeFunction(engine, *object, "destroy", moduleName, JsWindow::Destroy);
3625 BindNativeFunction(engine, *object, "destroyWindow", moduleName, JsWindow::DestroyWindow);
3626 BindNativeFunction(engine, *object, "hide", moduleName, JsWindow::Hide);
3627 BindNativeFunction(engine, *object, "hideWithAnimation", moduleName, JsWindow::HideWithAnimation);
3628 BindNativeFunction(engine, *object, "moveTo", moduleName, JsWindow::MoveTo);
3629 BindNativeFunction(engine, *object, "moveWindowTo", moduleName, JsWindow::MoveWindowTo);
3630 BindNativeFunction(engine, *object, "resetSize", moduleName, JsWindow::Resize);
3631 BindNativeFunction(engine, *object, "resize", moduleName, JsWindow::ResizeWindow);
3632 BindNativeFunction(engine, *object, "setWindowType", moduleName, JsWindow::SetWindowType);
3633 BindNativeFunction(engine, *object, "setWindowMode", moduleName, JsWindow::SetWindowMode);
3634 BindNativeFunction(engine, *object, "getProperties", moduleName, JsWindow::GetProperties);
3635 BindNativeFunction(engine, *object, "getWindowProperties", moduleName, JsWindow::GetWindowPropertiesSync);
3636 BindNativeFunction(engine, *object, "on", moduleName, JsWindow::RegisterWindowCallback);
3637 BindNativeFunction(engine, *object, "off", moduleName, JsWindow::UnregisterWindowCallback);
3638 BindNativeFunction(engine, *object, "bindDialogTarget", moduleName, JsWindow::BindDialogTarget);
3639 BindNativeFunction(engine, *object, "loadContent", moduleName, JsWindow::LoadContent);
3640 BindNativeFunction(engine, *object, "setUIContent", moduleName, JsWindow::SetUIContent);
3641 BindNativeFunction(engine, *object, "setFullScreen", moduleName, JsWindow::SetFullScreen);
3642 BindNativeFunction(engine, *object, "setLayoutFullScreen", moduleName, JsWindow::SetLayoutFullScreen);
3643 BindNativeFunction(engine, *object, "setWindowLayoutFullScreen", moduleName, JsWindow::SetWindowLayoutFullScreen);
3644 BindNativeFunction(engine, *object, "setSystemBarEnable", moduleName, JsWindow::SetSystemBarEnable);
3645 BindNativeFunction(engine, *object, "setWindowSystemBarEnable", moduleName, JsWindow::SetWindowSystemBarEnable);
3646 BindNativeFunction(engine, *object, "setSystemBarProperties", moduleName, JsWindow::SetSystemBarProperties);
3647 BindNativeFunction(engine, *object, "setWindowSystemBarProperties",
3648 moduleName, JsWindow::SetWindowSystemBarProperties);
3649 BindNativeFunction(engine, *object, "getAvoidArea", moduleName, JsWindow::GetAvoidArea);
3650 BindNativeFunction(engine, *object, "getWindowAvoidArea", moduleName, JsWindow::GetWindowAvoidAreaSync);
3651 BindNativeFunction(engine, *object, "isShowing", moduleName, JsWindow::IsShowing);
3652 BindNativeFunction(engine, *object, "isWindowShowing", moduleName, JsWindow::IsWindowShowingSync);
3653 BindNativeFunction(engine, *object, "isSupportWideGamut", moduleName, JsWindow::IsSupportWideGamut);
3654 BindNativeFunction(engine, *object, "isWindowSupportWideGamut", moduleName, JsWindow::IsWindowSupportWideGamut);
3655 BindNativeFunction(engine, *object, "setColorSpace", moduleName, JsWindow::SetColorSpace);
3656 BindNativeFunction(engine, *object, "setWindowColorSpace", moduleName, JsWindow::SetWindowColorSpace);
3657 BindNativeFunction(engine, *object, "getColorSpace", moduleName, JsWindow::GetColorSpace);
3658 BindNativeFunction(engine, *object, "getWindowColorSpace", moduleName, JsWindow::GetWindowColorSpaceSync);
3659 BindNativeFunction(engine, *object, "setBackgroundColor", moduleName, JsWindow::SetBackgroundColor);
3660 BindNativeFunction(engine, *object, "setWindowBackgroundColor", moduleName, JsWindow::SetWindowBackgroundColorSync);
3661 BindNativeFunction(engine, *object, "setBrightness", moduleName, JsWindow::SetBrightness);
3662 BindNativeFunction(engine, *object, "setWindowBrightness", moduleName, JsWindow::SetWindowBrightness);
3663 BindNativeFunction(engine, *object, "setDimBehind", moduleName, JsWindow::SetDimBehind);
3664 BindNativeFunction(engine, *object, "setFocusable", moduleName, JsWindow::SetFocusable);
3665 BindNativeFunction(engine, *object, "setWindowFocusable", moduleName, JsWindow::SetWindowFocusable);
3666 BindNativeFunction(engine, *object, "setKeepScreenOn", moduleName, JsWindow::SetKeepScreenOn);
3667 BindNativeFunction(engine, *object, "setWindowKeepScreenOn", moduleName, JsWindow::SetWindowKeepScreenOn);
3668 BindNativeFunction(engine, *object, "setWakeUpScreen", moduleName, JsWindow::SetWakeUpScreen);
3669 BindNativeFunction(engine, *object, "setOutsideTouchable", moduleName, JsWindow::SetOutsideTouchable);
3670 BindNativeFunction(engine, *object, "setPrivacyMode", moduleName, JsWindow::SetPrivacyMode);
3671 BindNativeFunction(engine, *object, "setWindowPrivacyMode", moduleName, JsWindow::SetWindowPrivacyMode);
3672 BindNativeFunction(engine, *object, "setTouchable", moduleName, JsWindow::SetTouchable);
3673 BindNativeFunction(engine, *object, "setWindowTouchable", moduleName, JsWindow::SetWindowTouchable);
3674 BindNativeFunction(engine, *object, "setTransparent", moduleName, JsWindow::SetTransparent);
3675 BindNativeFunction(engine, *object, "setCallingWindow", moduleName, JsWindow::SetCallingWindow);
3676 BindNativeFunction(engine, *object, "setSnapshotSkip", moduleName, JsWindow::SetSnapshotSkip);
3677 BindNativeFunction(engine, *object, "disableWindowDecor", moduleName, JsWindow::DisableWindowDecor);
3678 BindNativeFunction(engine, *object, "dump", moduleName, JsWindow::Dump);
3679 BindNativeFunction(engine, *object, "setForbidSplitMove", moduleName, JsWindow::SetForbidSplitMove);
3680 BindNativeFunction(engine, *object, "setPreferredOrientation", moduleName, JsWindow::SetPreferredOrientation);
3681 BindNativeFunction(engine, *object, "opacity", moduleName, JsWindow::Opacity);
3682 BindNativeFunction(engine, *object, "scale", moduleName, JsWindow::Scale);
3683 BindNativeFunction(engine, *object, "rotate", moduleName, JsWindow::Rotate);
3684 BindNativeFunction(engine, *object, "translate", moduleName, JsWindow::Translate);
3685 BindNativeFunction(engine, *object, "getTransitionController", moduleName, JsWindow::GetTransitionController);
3686 BindNativeFunction(engine, *object, "snapshot", moduleName, JsWindow::Snapshot);
3687 BindNativeFunction(engine, *object, "setCornerRadius", moduleName, JsWindow::SetCornerRadius);
3688 BindNativeFunction(engine, *object, "setShadow", moduleName, JsWindow::SetShadow);
3689 BindNativeFunction(engine, *object, "setBlur", moduleName, JsWindow::SetBlur);
3690 BindNativeFunction(engine, *object, "setBackdropBlur", moduleName, JsWindow::SetBackdropBlur);
3691 BindNativeFunction(engine, *object, "setBackdropBlurStyle", moduleName, JsWindow::SetBackdropBlurStyle);
3692 }
3693 } // namespace Rosen
3694 } // namespace OHOS
3695