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 #include "js_window_manager.h"
16 #include <ability.h>
17 #include <cinttypes>
18 #include <new>
19 #include "ability_context.h"
20 #include "display_manager.h"
21 #include "dm_common.h"
22 #include "wm_common.h"
23 #include "js_window.h"
24 #include "js_window_utils.h"
25 #include "window_helper.h"
26 #include "window_manager_hilog.h"
27 #include "window_option.h"
28 #include "singleton_container.h"
29 namespace OHOS {
30 namespace Rosen {
31 using namespace AbilityRuntime;
32 namespace {
33 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JsWindowManager"};
34 }
35
JsWindowManager()36 JsWindowManager::JsWindowManager() : registerManager_(std::make_unique<JsWindowRegisterManager>())
37 {
38 }
39
~JsWindowManager()40 JsWindowManager::~JsWindowManager()
41 {
42 }
43
Finalizer(NativeEngine * engine,void * data,void * hint)44 void JsWindowManager::Finalizer(NativeEngine* engine, void* data, void* hint)
45 {
46 WLOGFI("[NAPI]Finalizer");
47 std::unique_ptr<JsWindowManager>(static_cast<JsWindowManager*>(data));
48 }
49
Create(NativeEngine * engine,NativeCallbackInfo * info)50 NativeValue* JsWindowManager::Create(NativeEngine* engine, NativeCallbackInfo* info)
51 {
52 JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
53 return (me != nullptr) ? me->OnCreate(*engine, *info) : nullptr;
54 }
55
CreateWindow(NativeEngine * engine,NativeCallbackInfo * info)56 NativeValue* JsWindowManager::CreateWindow(NativeEngine* engine, NativeCallbackInfo* info)
57 {
58 JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
59 return (me != nullptr) ? me->OnCreateWindow(*engine, *info) : nullptr;
60 }
61
FindWindow(NativeEngine * engine,NativeCallbackInfo * info)62 NativeValue* JsWindowManager::FindWindow(NativeEngine* engine, NativeCallbackInfo* info)
63 {
64 JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
65 return (me != nullptr) ? me->OnFindWindow(*engine, *info) : nullptr;
66 }
67
FindWindowSync(NativeEngine * engine,NativeCallbackInfo * info)68 NativeValue* JsWindowManager::FindWindowSync(NativeEngine* engine, NativeCallbackInfo* info)
69 {
70 JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
71 return (me != nullptr) ? me->OnFindWindowSync(*engine, *info) : nullptr;
72 }
73
MinimizeAll(NativeEngine * engine,NativeCallbackInfo * info)74 NativeValue* JsWindowManager::MinimizeAll(NativeEngine* engine, NativeCallbackInfo* info)
75 {
76 JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
77 return (me != nullptr) ? me->OnMinimizeAll(*engine, *info) : nullptr;
78 }
79
ToggleShownStateForAllAppWindows(NativeEngine * engine,NativeCallbackInfo * info)80 NativeValue* JsWindowManager::ToggleShownStateForAllAppWindows(NativeEngine* engine, NativeCallbackInfo* info)
81 {
82 JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
83 return (me != nullptr) ? me->OnToggleShownStateForAllAppWindows(*engine, *info) : nullptr;
84 }
85
RegisterWindowManagerCallback(NativeEngine * engine,NativeCallbackInfo * info)86 NativeValue* JsWindowManager::RegisterWindowManagerCallback(NativeEngine* engine, NativeCallbackInfo* info)
87 {
88 JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
89 return (me != nullptr) ? me->OnRegisterWindowMangerCallback(*engine, *info) : nullptr;
90 }
91
UnregisterWindowMangerCallback(NativeEngine * engine,NativeCallbackInfo * info)92 NativeValue* JsWindowManager::UnregisterWindowMangerCallback(NativeEngine* engine, NativeCallbackInfo* info)
93 {
94 JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
95 return (me != nullptr) ? me->OnUnregisterWindowManagerCallback(*engine, *info) : nullptr;
96 }
97
GetTopWindow(NativeEngine * engine,NativeCallbackInfo * info)98 NativeValue* JsWindowManager::GetTopWindow(NativeEngine* engine, NativeCallbackInfo* info)
99 {
100 JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
101 return (me != nullptr) ? me->OnGetTopWindow(*engine, *info) : nullptr;
102 }
103
GetLastWindow(NativeEngine * engine,NativeCallbackInfo * info)104 NativeValue* JsWindowManager::GetLastWindow(NativeEngine* engine, NativeCallbackInfo* info)
105 {
106 JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
107 return (me != nullptr) ? me->OnGetLastWindow(*engine, *info) : nullptr;
108 }
109
SetWindowLayoutMode(NativeEngine * engine,NativeCallbackInfo * info)110 NativeValue* JsWindowManager::SetWindowLayoutMode(NativeEngine* engine, NativeCallbackInfo* info)
111 {
112 JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
113 return (me != nullptr) ? me->OnSetWindowLayoutMode(*engine, *info) : nullptr;
114 }
115
GetNativeContext(NativeEngine & engine,NativeValue * nativeContext,void * & contextPtr,WMError & errCode)116 static void GetNativeContext(NativeEngine& engine, NativeValue* nativeContext, void*& contextPtr, WMError& errCode)
117 {
118 AppExecFwk::Ability* ability = nullptr;
119 bool isOldApi = GetAPI7Ability(engine, ability);
120 WLOGFI("[NAPI]FA mode:%{public}u", isOldApi);
121 if (isOldApi) {
122 return;
123 }
124 if (nativeContext != nullptr) {
125 auto objContext = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeContext);
126 if (objContext == nullptr) {
127 WLOGFE("[NAPI]ConvertNativeValueTo Context Object failed");
128 errCode = WMError::WM_ERROR_INVALID_PARAM;
129 return;
130 }
131 contextPtr = objContext->GetNativePointer();
132 }
133 }
134
GetParentId(NativeEngine & engine)135 static uint32_t GetParentId(NativeEngine& engine)
136 {
137 AppExecFwk::Ability* ability = nullptr;
138 uint32_t parentId = 0;
139 bool isOldApi = GetAPI7Ability(engine, ability);
140 if (isOldApi) {
141 if (ability == nullptr) {
142 WLOGE("[NAPI]FA mode GetAPI7Ability failed");
143 return parentId;
144 }
145 auto window = ability->GetWindow();
146 if (window == nullptr) {
147 WLOGE("[NAPI]Get mainWindow failed");
148 return parentId;
149 }
150 parentId = window->GetWindowId();
151 }
152 return parentId;
153 }
154
GetWindowTypeAndParentId(NativeEngine & engine,uint32_t & parentId,WindowType & winType,NativeValue * nativeString,NativeValue * nativeType)155 static bool GetWindowTypeAndParentId(NativeEngine& engine, uint32_t& parentId, WindowType& winType,
156 NativeValue* nativeString, NativeValue* nativeType)
157 {
158 NativeNumber* type = ConvertNativeValueTo<NativeNumber>(nativeType);
159 if (type == nullptr) {
160 WLOGFE("[NAPI]Failed to convert parameter to windowType");
161 return false;
162 }
163 // adapt to the old version
164 if (static_cast<uint32_t>(*type) >= static_cast<uint32_t>(WindowType::SYSTEM_WINDOW_BASE)) {
165 winType = static_cast<WindowType>(static_cast<uint32_t>(*type));
166 } else {
167 if (static_cast<uint32_t>(*type) >= static_cast<uint32_t>(ApiWindowType::TYPE_BASE) &&
168 static_cast<uint32_t>(*type) < static_cast<uint32_t>(ApiWindowType::TYPE_END)) {
169 winType = JS_TO_NATIVE_WINDOW_TYPE_MAP.at(static_cast<ApiWindowType>(static_cast<uint32_t>(*type)));
170 } else {
171 WLOGFE("[NAPI]Type %{public}u is not supported", static_cast<uint32_t>(*type));
172 return false;
173 }
174 }
175 AppExecFwk::Ability* ability = nullptr;
176 bool isOldApi = GetAPI7Ability(engine, ability);
177 if (isOldApi) {
178 if (ability == nullptr || !WindowHelper::IsSubWindow(winType)) {
179 WLOGE("[NAPI]FA mode GetAPI7Ability failed or type %{public}u is not subWinodw", winType);
180 return false;
181 }
182 auto window = ability->GetWindow();
183 if (window == nullptr) {
184 WLOGE("[NAPI]Get mainWindow failed");
185 return false;
186 }
187 parentId = window->GetWindowId();
188 } else {
189 if (!WindowHelper::IsSystemWindow(winType)) {
190 WLOGFE("[NAPI]Only SystemWindow support create in stage mode, type is %{public}u", winType);
191 return false;
192 }
193 }
194 return true;
195 }
196
CreateNewSystemWindowTask(void * contextPtr,sptr<WindowOption> windowOption,NativeEngine & engine,AsyncTask & task)197 static void CreateNewSystemWindowTask(void* contextPtr, sptr<WindowOption> windowOption,
198 NativeEngine& engine, AsyncTask& task)
199 {
200 WLOGFI("[NAPI]CreateSystemWindowTask");
201 if (windowOption == nullptr) {
202 int32_t err = static_cast<int32_t>(WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY);
203 task.Reject(engine, CreateJsError(engine, err, "New window option failed"));
204 WLOGFE("[NAPI]New window option failed");
205 return;
206 }
207 auto context = static_cast<std::weak_ptr<AbilityRuntime::Context>*>(contextPtr);
208 if (contextPtr == nullptr || context == nullptr) {
209 int32_t err = static_cast<int32_t>(WmErrorCode::WM_ERROR_CONTEXT_ABNORMALLY);
210 task.Reject(engine, CreateJsError(engine, err, "Context is nullptr"));
211 WLOGFE("[NAPI]Context is nullptr");
212 return;
213 }
214 if (windowOption->GetWindowType() == WindowType::WINDOW_TYPE_FLOAT ||
215 windowOption->GetWindowType() == WindowType::WINDOW_TYPE_FLOAT_CAMERA) {
216 auto abilityContext = Context::ConvertTo<AbilityRuntime::AbilityContext>(context->lock());
217 if (abilityContext != nullptr) {
218 if (!CheckCallingPermission("ohos.permission.SYSTEM_FLOAT_WINDOW")) {
219 int32_t err = static_cast<int32_t>(WmErrorCode::WM_ERROR_NO_PERMISSION);
220 task.Reject(engine, CreateJsError(engine, err, "TYPE_FLOAT CheckCallingPermission failed"));
221 return;
222 }
223 }
224 }
225
226 sptr<Window> window = Window::Create(windowOption->GetWindowName(), windowOption, context->lock());
227 if (window != nullptr) {
228 task.Resolve(engine, CreateJsWindowObject(engine, window));
229 } else {
230 WLOGFE("[NAPI]Create window failed");
231 int32_t err = static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY);
232 task.Reject(engine, CreateJsError(engine, err, "Create window failed"));
233 }
234 }
235
CreateSystemWindowTask(void * contextPtr,std::string windowName,WindowType winType,NativeEngine & engine,AsyncTask & task)236 static void CreateSystemWindowTask(void* contextPtr, std::string windowName, WindowType winType,
237 NativeEngine& engine, AsyncTask& task)
238 {
239 WLOGFI("[NAPI]CreateSystemWindowTask");
240 auto context = static_cast<std::weak_ptr<AbilityRuntime::Context>*>(contextPtr);
241 if (contextPtr == nullptr || context == nullptr) {
242 int32_t err = static_cast<int32_t>(WMError::WM_ERROR_NULLPTR);
243 task.Reject(engine, CreateJsError(engine, err, "Context is nullptr"));
244 WLOGFE("[NAPI]Context is nullptr");
245 return;
246 }
247 if (winType == WindowType::WINDOW_TYPE_FLOAT || winType == WindowType::WINDOW_TYPE_FLOAT_CAMERA) {
248 auto abilityContext = Context::ConvertTo<AbilityRuntime::AbilityContext>(context->lock());
249 if (abilityContext != nullptr) {
250 if (!CheckCallingPermission("ohos.permission.SYSTEM_FLOAT_WINDOW")) {
251 int32_t err = static_cast<int32_t>(WMError::WM_ERROR_INVALID_PERMISSION);
252 task.Reject(engine, CreateJsError(engine, err, "TYPE_FLOAT CheckCallingPermission failed"));
253 return;
254 }
255 }
256 }
257 sptr<WindowOption> windowOption = new(std::nothrow) WindowOption();
258 if (windowOption == nullptr) {
259 int32_t err = static_cast<int32_t>(WMError::WM_ERROR_NULLPTR);
260 task.Reject(engine, CreateJsError(engine, err, "New window option failed"));
261 WLOGFE("[NAPI]New window option failed");
262 return;
263 }
264 windowOption->SetWindowType(winType);
265 sptr<Window> window = Window::Create(windowName, windowOption, context->lock());
266 if (window != nullptr) {
267 task.Resolve(engine, CreateJsWindowObject(engine, window));
268 } else {
269 WLOGFE("[NAPI]Create window failed");
270 int32_t err = static_cast<int32_t>(WMError::WM_ERROR_NULLPTR);
271 task.Reject(engine, CreateJsError(engine, err, "Create window failed"));
272 }
273 }
274
CreateNewSubWindowTask(sptr<WindowOption> windowOption,NativeEngine & engine,AsyncTask & task)275 static void CreateNewSubWindowTask(sptr<WindowOption> windowOption, NativeEngine& engine, AsyncTask& task)
276 {
277 if (windowOption == nullptr) {
278 int32_t err = static_cast<int32_t>(WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY);
279 task.Reject(engine, CreateJsError(engine, err, "New window option failed"));
280 WLOGFE("[NAPI]New window option failed");
281 return;
282 }
283 windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING);
284 if (windowOption->GetParentId() == INVALID_WINDOW_ID) {
285 uint32_t parentId = GetParentId(engine);
286 if (!parentId) {
287 int32_t err = static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY);
288 task.Reject(engine, CreateJsError(engine, err, "parent window missed"));
289 WLOGFE("[NAPI]can not find parent window");
290 return;
291 }
292 windowOption->SetParentId(parentId);
293 }
294 sptr<Window> window = Window::Create(windowOption->GetWindowName(), windowOption);
295 if (window != nullptr) {
296 task.Resolve(engine, CreateJsWindowObject(engine, window));
297 } else {
298 WLOGFE("[NAPI]Create window failed");
299 int32_t err = static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY);
300 task.Reject(engine, CreateJsError(engine, err, "Create window failed"));
301 }
302 }
303
CreateSubWindowTask(uint32_t parentWinId,std::string windowName,WindowType winType,NativeEngine & engine,AsyncTask & task,bool newErrorCode=false)304 static void CreateSubWindowTask(uint32_t parentWinId, std::string windowName, WindowType winType,
305 NativeEngine& engine, AsyncTask& task, bool newErrorCode = false)
306 {
307 WLOGFI("[NAPI]CreateSubWindowTask, parent id = %{public}u", parentWinId);
308 sptr<WindowOption> windowOption = new(std::nothrow) WindowOption();
309 if (windowOption == nullptr) {
310 int32_t err = newErrorCode ? static_cast<int32_t>(WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY)
311 : static_cast<int32_t>(WMError::WM_ERROR_NULLPTR);
312 task.Reject(engine, CreateJsError(engine, err, "New window option failed"));
313 WLOGFE("[NAPI]New window option failed");
314 return;
315 }
316 windowOption->SetWindowType(winType);
317 windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING);
318 windowOption->SetParentId(parentWinId);
319 sptr<Window> window = Window::Create(windowName, windowOption);
320 if (window != nullptr) {
321 task.Resolve(engine, CreateJsWindowObject(engine, window));
322 } else {
323 WLOGFE("[NAPI]Create window failed");
324 int32_t err = newErrorCode ? static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)
325 : static_cast<int32_t>(WMError::WM_ERROR_NULLPTR);
326 task.Reject(engine, CreateJsError(engine, err, "Create window failed"));
327 }
328 }
329
OnCreate(NativeEngine & engine,NativeCallbackInfo & info)330 NativeValue* JsWindowManager::OnCreate(NativeEngine& engine, NativeCallbackInfo& info)
331 {
332 WLOGFD("[NAPI]OnCreate");
333 NativeValue* nativeString = nullptr;
334 NativeValue* nativeContext = nullptr;
335 NativeValue* nativeType = nullptr;
336 NativeValue* callback = nullptr;
337 if (info.argc >= 2 && info.argv[0]->TypeOf() == NATIVE_STRING) { // 2: minimum params num
338 nativeString = info.argv[0];
339 nativeType = info.argv[1];
340 // 2: minimum params num
341 callback = (info.argc == 2) ? nullptr :
342 (info.argv[2]->TypeOf() == NATIVE_FUNCTION ? info.argv[2] : nullptr); // 2: index of callback
343 } else if (info.argc >= 3) { // 3: minimum params num
344 nativeContext = info.argv[0]->TypeOf() == NATIVE_OBJECT ? info.argv[0] : nullptr;
345 nativeString = info.argv[1];
346 nativeType = info.argv[2]; // 2: index of type
347 // 3: minimum params num;
348 callback = (info.argc == 3) ? nullptr :
349 (info.argv[3]->TypeOf() == NATIVE_FUNCTION ? info.argv[3] : nullptr); // 3: index of callback
350 }
351 std::string windowName;
352 WMError errCode = WMError::WM_OK;
353 if (!ConvertFromJsValue(engine, nativeString, windowName)) {
354 WLOGFE("[NAPI]Failed to convert parameter to windowName");
355 errCode = WMError::WM_ERROR_INVALID_PARAM;
356 }
357 uint32_t parentId = INVALID_WINDOW_ID;
358 WindowType winType = WindowType::SYSTEM_WINDOW_BASE;
359 if (errCode == WMError::WM_OK &&
360 !GetWindowTypeAndParentId(engine, parentId, winType, nativeString, nativeType)) {
361 errCode = WMError::WM_ERROR_INVALID_PARAM;
362 }
363 void* contextPtr = nullptr;
364 GetNativeContext(engine, nativeContext, contextPtr, errCode);
365
366 WLOGFI("[NAPI]Window name = %{public}s, type = %{public}u, err = %{public}d", windowName.c_str(), winType, errCode);
367 AsyncTask::CompleteCallback complete =
368 [=](NativeEngine& engine, AsyncTask& task, int32_t status) {
369 if (errCode != WMError::WM_OK) {
370 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params"));
371 return;
372 }
373 if (parentId == INVALID_WINDOW_ID) {
374 return CreateSystemWindowTask(contextPtr, windowName, winType, engine, task);
375 } else {
376 return CreateSubWindowTask(parentId, windowName, winType, engine, task);
377 }
378 };
379 NativeValue* result = nullptr;
380 AsyncTask::Schedule("JsWindowManager::OnCreate", engine,
381 CreateAsyncTaskWithLastParam(engine, callback, nullptr, std::move(complete), &result));
382 return result;
383 }
384
ParseConfigOption(NativeEngine & engine,NativeObject * jsObject,WindowOption & option,void * & contextPtr)385 bool JsWindowManager::ParseConfigOption(NativeEngine& engine, NativeObject* jsObject,
386 WindowOption& option, void*& contextPtr)
387 {
388 std::string windowName;
389 if (ParseJsValue(jsObject, engine, "name", windowName)) {
390 option.SetWindowName(windowName);
391 } else {
392 WLOGFE("[NAPI]Failed to convert parameter to windowName");
393 return false;
394 }
395
396 uint32_t winType;
397 if (ParseJsValue(jsObject, engine, "windowType", winType)) {
398 if (winType >= static_cast<uint32_t>(ApiWindowType::TYPE_BASE) &&
399 winType < static_cast<uint32_t>(ApiWindowType::TYPE_END)) {
400 option.SetWindowType(JS_TO_NATIVE_WINDOW_TYPE_MAP.at(static_cast<ApiWindowType>(winType)));
401 } else {
402 option.SetWindowType(static_cast<WindowType>(winType));
403 }
404 } else {
405 WLOGFE("[NAPI]Failed to convert parameter to winType");
406 return false;
407 }
408 if (!(WindowHelper::IsSystemWindow(option.GetWindowType()) ||
409 WindowHelper::IsSubWindow(option.GetWindowType()))) {
410 WLOGFE("[NAPI]Convert parameter to invalid winType");
411 return false;
412 }
413
414 NativeValue* value = jsObject->GetProperty("ctx");
415 if (value->TypeOf() == NATIVE_UNDEFINED) {
416 return true;
417 }
418 WMError errCode = WMError::WM_OK;
419 GetNativeContext(engine, value, contextPtr, errCode);
420 if (errCode != WMError::WM_OK) {
421 return false;
422 }
423
424 int64_t displayId = static_cast<int64_t>(DISPLAY_ID_INVALID);
425 if (ParseJsValue(jsObject, engine, "displayId", displayId)) {
426 if (displayId < 0 ||
427 SingletonContainer::Get<DisplayManager>().GetDisplayById(static_cast<uint64_t>(displayId)) == nullptr) {
428 return false;
429 }
430 option.SetDisplayId(displayId);
431 } else {
432 return true;
433 }
434
435 int64_t parentId = -1;
436 if (ParseJsValue(jsObject, engine, "parentId", parentId)) {
437 option.SetParentId(parentId);
438 }
439
440 return true;
441 }
442
OnCreateWindow(NativeEngine & engine,NativeCallbackInfo & info)443 NativeValue* JsWindowManager::OnCreateWindow(NativeEngine& engine, NativeCallbackInfo& info)
444 {
445 WLOGFD("[NAPI]Called");
446 if (info.argc < 1) {
447 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
448 return engine.CreateUndefined();
449 }
450 NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
451 if (nativeObj == nullptr) {
452 WLOGFE("[NAPI]Failed to convert object to CreateWindow");
453 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
454 return engine.CreateUndefined();
455 }
456 WindowOption option;
457 void* contextPtr = nullptr;
458 if (!ParseConfigOption(engine, nativeObj, option, contextPtr)) {
459 WLOGFE("[NAPI]Failed to parse config");
460 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
461 return engine.CreateUndefined();
462 }
463 NativeValue* callback = nullptr;
464 if (info.argc > 1) {
465 callback = info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr; // 1: index of callback
466 }
467 AsyncTask::CompleteCallback complete =
468 [=](NativeEngine& engine, AsyncTask& task, int32_t status) {
469 sptr<WindowOption> windowOption = new WindowOption(option);
470 if (WindowHelper::IsSystemWindow(option.GetWindowType())) {
471 return CreateNewSystemWindowTask(contextPtr, windowOption, engine, task);
472 }
473 if (WindowHelper::IsSubWindow(option.GetWindowType())) {
474 return CreateNewSubWindowTask(windowOption, engine, task);
475 }
476 };
477
478 NativeValue* result = nullptr;
479 AsyncTask::Schedule("JsWindowManager::OnCreateWindow", engine,
480 CreateAsyncTaskWithLastParam(engine, callback, nullptr, std::move(complete), &result));
481 return result;
482 }
483
OnFindWindow(NativeEngine & engine,NativeCallbackInfo & info)484 NativeValue* JsWindowManager::OnFindWindow(NativeEngine& engine, NativeCallbackInfo& info)
485 {
486 WLOGFD("[NAPI]OnFindWindow");
487 std::string windowName;
488 WMError errCode = WMError::WM_OK;
489 if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
490 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
491 errCode = WMError::WM_ERROR_INVALID_PARAM;
492 } else {
493 if (!ConvertFromJsValue(engine, info.argv[0], windowName)) {
494 WLOGFE("[NAPI]Failed to convert parameter to windowName");
495 errCode = WMError::WM_ERROR_INVALID_PARAM;
496 }
497 }
498 WLOGFI("[NAPI]Window name = %{public}s, err = %{public}d", windowName.c_str(), errCode);
499 AsyncTask::CompleteCallback complete =
500 [=](NativeEngine& engine, AsyncTask& task, int32_t status) {
501 if (errCode != WMError::WM_OK) {
502 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params"));
503 return;
504 }
505 std::shared_ptr<NativeReference> jsWindowObj = FindJsWindowObject(windowName);
506 if (jsWindowObj != nullptr && jsWindowObj->Get() != nullptr) {
507 WLOGFI("[NAPI]Find window: %{public}s, use exist js window", windowName.c_str());
508 task.Resolve(engine, jsWindowObj->Get());
509 } else {
510 sptr<Window> window = Window::Find(windowName);
511 if (window == nullptr) {
512 WLOGFE("[NAPI]Cannot find window: %{public}s", windowName.c_str());
513 task.Reject(engine, CreateJsError(engine,
514 static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "Cannot find window"));
515 } else {
516 task.Resolve(engine, CreateJsWindowObject(engine, window));
517 WLOGFI("[NAPI]Find window: %{public}s, create js window", windowName.c_str());
518 }
519 }
520 };
521
522 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
523 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
524 NativeValue* result = nullptr;
525 AsyncTask::Schedule("JsWindowManager::OnFindWindow",
526 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
527 return result;
528 }
529
OnFindWindowSync(NativeEngine & engine,NativeCallbackInfo & info)530 NativeValue* JsWindowManager::OnFindWindowSync(NativeEngine& engine, NativeCallbackInfo& info)
531 {
532 WLOGFD("[NAPI]OnFindWindowSync");
533 std::string windowName;
534 WmErrorCode errCode = WmErrorCode::WM_OK;
535 if (info.argc < 1) { // 1: params num
536 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
537 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
538 } else {
539 if (!ConvertFromJsValue(engine, info.argv[0], windowName)) {
540 WLOGFE("[NAPI]Failed to convert parameter to windowName");
541 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
542 }
543 }
544 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
545 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
546 return engine.CreateUndefined();
547 }
548
549 WLOGFI("[NAPI]Window name = %{public}s, err = %{public}d", windowName.c_str(), errCode);
550 std::shared_ptr<NativeReference> jsWindowObj = FindJsWindowObject(windowName);
551 if (jsWindowObj != nullptr && jsWindowObj->Get() != nullptr) {
552 WLOGFI("[NAPI]Find window: %{public}s, use exist js window", windowName.c_str());
553 return jsWindowObj->Get();
554 } else {
555 sptr<Window> window = Window::Find(windowName);
556 if (window == nullptr) {
557 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
558 return engine.CreateUndefined();
559 } else {
560 return CreateJsWindowObject(engine, window);
561 }
562 }
563 }
564
OnMinimizeAll(NativeEngine & engine,NativeCallbackInfo & info)565 NativeValue* JsWindowManager::OnMinimizeAll(NativeEngine& engine, NativeCallbackInfo& info)
566 {
567 WLOGFI("[NAPI]OnMinimizeAll");
568 WmErrorCode errCode = WmErrorCode::WM_OK;
569 if (info.argc < 1) {
570 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
571 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
572 }
573 int64_t displayId = static_cast<int64_t>(DISPLAY_ID_INVALID);
574 if (errCode == WmErrorCode::WM_OK && !ConvertFromJsValue(engine, info.argv[0], displayId)) {
575 WLOGFE("[NAPI]Failed to convert parameter to displayId");
576 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
577 }
578 if (displayId < 0 ||
579 SingletonContainer::Get<DisplayManager>().GetDisplayById(static_cast<uint64_t>(displayId)) == nullptr) {
580 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
581 }
582 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
583 WLOGFE("JsWindowManager::OnMinimizeAll failed, Invalidate params.");
584 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
585 return engine.CreateUndefined();
586 }
587
588 WLOGFI("[NAPI]Display id = %{public}" PRIu64", err = %{public}d", static_cast<uint64_t>(displayId), errCode);
589 AsyncTask::CompleteCallback complete =
590 [=](NativeEngine& engine, AsyncTask& task, int32_t status) {
591 SingletonContainer::Get<WindowManager>().MinimizeAllAppWindows(static_cast<uint64_t>(displayId));
592 task.Resolve(engine, engine.CreateUndefined());
593 WLOGFI("[NAPI]OnMinimizeAll success");
594 };
595 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
596 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
597 info.argv[1] : nullptr);
598 NativeValue* result = nullptr;
599 AsyncTask::Schedule("JsWindowManager::OnMinimizeAll",
600 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
601 return result;
602 }
603
OnToggleShownStateForAllAppWindows(NativeEngine & engine,NativeCallbackInfo & info)604 NativeValue* JsWindowManager::OnToggleShownStateForAllAppWindows(NativeEngine& engine, NativeCallbackInfo& info)
605 {
606 WLOGFI("[NAPI]OnToggleShownStateForAllAppWindows");
607 AsyncTask::CompleteCallback complete =
608 [=](NativeEngine& engine, AsyncTask& task, int32_t status) {
609 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(
610 SingletonContainer::Get<WindowManager>().ToggleShownStateForAllAppWindows());
611 if (ret == WmErrorCode::WM_OK) {
612 task.Resolve(engine, engine.CreateUndefined());
613 WLOGFI("[NAPI]OnToggleShownStateForAllAppWindows success");
614 } else {
615 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret),
616 "OnToggleShownStateForAllAppWindows failed"));
617 }
618 };
619 NativeValue* lastParam = (info.argc <= 0) ? nullptr :
620 (info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
621 NativeValue* result = nullptr;
622 AsyncTask::Schedule("JsWindowManager::OnToggleShownStateForAllAppWindows",
623 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
624 return result;
625 }
626
OnRegisterWindowMangerCallback(NativeEngine & engine,NativeCallbackInfo & info)627 NativeValue* JsWindowManager::OnRegisterWindowMangerCallback(NativeEngine& engine, NativeCallbackInfo& info)
628 {
629 WLOGFD("[NAPI]OnRegisterWindowMangerCallback");
630 if (info.argc < 2) { // 2: params num
631 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
632 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
633 return engine.CreateUndefined();
634 }
635 std::string cbType;
636 if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
637 WLOGFE("[NAPI]Failed to convert parameter to callbackType");
638 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
639 return engine.CreateUndefined();
640 }
641 NativeValue* value = info.argv[1];
642 if (!value->IsCallable()) {
643 WLOGFI("[NAPI]Callback(argv[1]) is not callable");
644 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
645 return engine.CreateUndefined();
646 }
647
648 registerManager_->RegisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, engine, value);
649 WLOGFI("[NAPI]Register end, type = %{public}s, callback = %{public}p", cbType.c_str(), value);
650 return engine.CreateUndefined();
651 }
652
OnUnregisterWindowManagerCallback(NativeEngine & engine,NativeCallbackInfo & info)653 NativeValue* JsWindowManager::OnUnregisterWindowManagerCallback(NativeEngine& engine, NativeCallbackInfo& info)
654 {
655 WLOGFD("[NAPI]OnUnregisterWindowManagerCallback");
656 if (info.argc < 1) {
657 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
658 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
659 return engine.CreateUndefined();
660 }
661 std::string cbType;
662 if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
663 WLOGFE("[NAPI]Failed to convert parameter to callbackType");
664 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
665 return engine.CreateUndefined();
666 }
667
668 NativeValue* value = nullptr;
669 if (info.argc == 1) {
670 registerManager_->UnregisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, value);
671 } else {
672 value = info.argv[1];
673 if ((value== nullptr) || (!value->IsCallable())) {
674 registerManager_->UnregisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, nullptr);
675 } else {
676 registerManager_->UnregisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, value);
677 }
678 }
679 WLOGFI("[NAPI]Unregister end, type = %{public}s, callback = %{public}p", cbType.c_str(), value);
680 return engine.CreateUndefined();
681 }
682
GetTopWindowTask(void * contextPtr,NativeEngine & engine,AsyncTask & task)683 static void GetTopWindowTask(void* contextPtr, NativeEngine& engine, AsyncTask& task)
684 {
685 std::string windowName;
686 sptr<Window> window = nullptr;
687 AppExecFwk::Ability* ability = nullptr;
688 bool isOldApi = GetAPI7Ability(engine, ability);
689 if (isOldApi) {
690 if (ability->GetWindow() == nullptr) {
691 task.Reject(engine, CreateJsError(engine,
692 static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "FA mode can not get ability window"));
693 WLOGE("[NAPI]FA mode can not get ability window");
694 return;
695 }
696 window = Window::GetTopWindowWithId(ability->GetWindow()->GetWindowId());
697 } else {
698 auto context = static_cast<std::weak_ptr<AbilityRuntime::Context>*>(contextPtr);
699 if (contextPtr == nullptr || context == nullptr) {
700 task.Reject(engine, CreateJsError(engine,
701 static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "Stage mode without context"));
702 WLOGFE("[NAPI]Stage mode without context");
703 return;
704 }
705 window = Window::GetTopWindowWithContext(context->lock());
706 }
707 if (window == nullptr) {
708 task.Reject(engine, CreateJsError(engine,
709 static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "Get top window failed"));
710 WLOGFE("[NAPI]Get top window failed");
711 return;
712 }
713 windowName = window->GetWindowName();
714 std::shared_ptr<NativeReference> jsWindowObj = FindJsWindowObject(windowName);
715 if (jsWindowObj != nullptr && jsWindowObj->Get() != nullptr) {
716 task.Resolve(engine, jsWindowObj->Get());
717 } else {
718 task.Resolve(engine, CreateJsWindowObject(engine, window));
719 }
720 WLOGFI("[NAPI]Get top window %{public}s success", windowName.c_str());
721 return;
722 }
723
OnGetTopWindow(NativeEngine & engine,NativeCallbackInfo & info)724 NativeValue* JsWindowManager::OnGetTopWindow(NativeEngine& engine, NativeCallbackInfo& info)
725 {
726 WLOGFD("[NAPI]OnGetTopWindow");
727 WMError errCode = WMError::WM_OK;
728 NativeValue* nativeContext = nullptr;
729 NativeValue* nativeCallback = nullptr;
730 void* contextPtr = nullptr;
731 if (info.argc > 2) { // 2: maximum params num
732 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
733 errCode = WMError::WM_ERROR_INVALID_PARAM;
734 } else {
735 if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_OBJECT) { // (context, callback?)
736 nativeContext = info.argv[0];
737 nativeCallback = (info.argc == 1) ? nullptr :
738 (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
739 } else { // (callback?)
740 nativeCallback = (info.argc == 0) ? nullptr :
741 (info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
742 }
743 GetNativeContext(engine, nativeContext, contextPtr, errCode);
744 }
745
746 WLOGFI("[NAPI]Context %{public}p, err %{public}u", contextPtr, errCode);
747 AsyncTask::CompleteCallback complete =
748 [=](NativeEngine& engine, AsyncTask& task, int32_t status) {
749 if (errCode != WMError::WM_OK) {
750 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params"));
751 return;
752 }
753 return GetTopWindowTask(contextPtr, engine, task);
754 };
755 NativeValue* result = nullptr;
756 AsyncTask::Schedule("JsWindowManager::OnGetTopWindow",
757 engine, CreateAsyncTaskWithLastParam(engine, nativeCallback, nullptr, std::move(complete), &result));
758 return result;
759 }
760
OnGetLastWindow(NativeEngine & engine,NativeCallbackInfo & info)761 NativeValue* JsWindowManager::OnGetLastWindow(NativeEngine& engine, NativeCallbackInfo& info)
762 {
763 WLOGFD("[NAPI]OnGetLastWindow");
764 WMError errCode = WMError::WM_OK;
765 NativeValue* nativeContext = nullptr;
766 NativeValue* nativeCallback = nullptr;
767 void* contextPtr = nullptr;
768 if (info.argc < 1) {
769 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
770 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
771 return engine.CreateUndefined();
772 } else {
773 nativeContext = info.argv[0];
774 nativeCallback = (info.argc == 1) ? nullptr : info.argv[1];
775 GetNativeContext(engine, nativeContext, contextPtr, errCode);
776 }
777 if (errCode != WMError::WM_OK) {
778 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
779 return engine.CreateUndefined();
780 }
781
782 AsyncTask::CompleteCallback complete =
783 [=](NativeEngine& engine, AsyncTask& task, int32_t status) {
784 std::string windowName;
785 sptr<Window> window = nullptr;
786 auto context = static_cast<std::weak_ptr<AbilityRuntime::Context>*>(contextPtr);
787 if (contextPtr == nullptr || context == nullptr) {
788 task.Reject(engine, CreateJsError(engine,
789 static_cast<int32_t>(WmErrorCode::WM_ERROR_CONTEXT_ABNORMALLY),
790 "Stage mode without context"));
791 return;
792 }
793 window = Window::GetTopWindowWithContext(context->lock());
794 if (window == nullptr) {
795 task.Reject(engine, CreateJsError(engine,
796 static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY),
797 "Get top window failed"));
798 return;
799 }
800 windowName = window->GetWindowName();
801 std::shared_ptr<NativeReference> jsWindowObj = FindJsWindowObject(windowName);
802 if (jsWindowObj != nullptr && jsWindowObj->Get() != nullptr) {
803 task.Resolve(engine, jsWindowObj->Get());
804 } else {
805 task.Resolve(engine, CreateJsWindowObject(engine, window));
806 }
807 WLOGFI("[NAPI]Get top window %{public}s success", windowName.c_str());
808 };
809 NativeValue* result = nullptr;
810 AsyncTask::Schedule("JsWindowManager::OnGetTopWindow",
811 engine, CreateAsyncTaskWithLastParam(engine, nativeCallback, nullptr, std::move(complete), &result));
812 return result;
813 }
814
OnSetWindowLayoutMode(NativeEngine & engine,NativeCallbackInfo & info)815 NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, NativeCallbackInfo& info)
816 {
817 WLOGFD("[NAPI]OnSetWindowLayoutMode");
818 WmErrorCode errCode = WmErrorCode::WM_OK;
819 if (info.argc < 1) { // 1: minimum params num
820 WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
821 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
822 }
823 WindowLayoutMode winLayoutMode = WindowLayoutMode::CASCADE;
824 if (errCode == WmErrorCode::WM_OK) {
825 NativeNumber* nativeMode = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
826 if (nativeMode == nullptr) {
827 WLOGFE("[NAPI]Failed to convert parameter to windowLayoutMode");
828 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
829 } else {
830 winLayoutMode = static_cast<WindowLayoutMode>(static_cast<uint32_t>(*nativeMode));
831 }
832 }
833 if (winLayoutMode != WindowLayoutMode::CASCADE && winLayoutMode != WindowLayoutMode::TILE) {
834 errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
835 }
836 if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
837 WLOGFE("JsWindowManager::OnSetWindowLayoutMode failed, Invalidate params.");
838 engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
839 return engine.CreateUndefined();
840 }
841
842 WLOGFI("[NAPI]LayoutMode = %{public}u, err = %{public}d", winLayoutMode, errCode);
843 AsyncTask::CompleteCallback complete =
844 [=](NativeEngine& engine, AsyncTask& task, int32_t status) {
845 WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(
846 SingletonContainer::Get<WindowManager>().SetWindowLayoutMode(winLayoutMode));
847 if (ret == WmErrorCode::WM_OK) {
848 task.Resolve(engine, engine.CreateUndefined());
849 WLOGFI("[NAPI]SetWindowLayoutMode success");
850 } else {
851 task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "SetWindowLayoutMode failed"));
852 }
853 };
854 // 1: maximum params num; 1: index of callback
855 NativeValue* lastParam = (info.argc <= 1) ? nullptr :
856 ((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
857 info.argv[1] : nullptr);
858 NativeValue* result = nullptr;
859 AsyncTask::Schedule("JsWindowManager::OnSetWindowLayoutMode",
860 engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
861 return result;
862 }
863
JsWindowManagerInit(NativeEngine * engine,NativeValue * exportObj)864 NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj)
865 {
866 WLOGFD("[NAPI]JsWindowManagerInit");
867
868 if (engine == nullptr || exportObj == nullptr) {
869 WLOGFE("[NAPI]JsWindowManagerInit engine or exportObj is nullptr");
870 return nullptr;
871 }
872
873 NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
874 if (object == nullptr) {
875 WLOGFE("[NAPI]JsWindowManagerInit object is nullptr");
876 return nullptr;
877 }
878
879 std::unique_ptr<JsWindowManager> jsWinManager = std::make_unique<JsWindowManager>();
880 object->SetNativePointer(jsWinManager.release(), JsWindowManager::Finalizer, nullptr);
881 object->SetProperty("WindowType", WindowTypeInit(engine));
882 object->SetProperty("AvoidAreaType", AvoidAreaTypeInit(engine));
883 object->SetProperty("WindowMode", WindowModeInit(engine));
884 object->SetProperty("ColorSpace", ColorSpaceInit(engine));
885 object->SetProperty("WindowStageEventType", WindowStageEventTypeInit(engine));
886 object->SetProperty("WindowLayoutMode", WindowLayoutModeInit(engine));
887 object->SetProperty("Orientation", OrientationInit(engine));
888 object->SetProperty("BlurStyle", BlurStyleInit(engine));
889 object->SetProperty("WmErrorCode", WindowErrorCodeInit(engine));
890 object->SetProperty("WMError", WindowErrorInit(engine));
891 const char *moduleName = "JsWindowManager";
892 BindNativeFunction(*engine, *object, "create", moduleName, JsWindowManager::Create);
893 BindNativeFunction(*engine, *object, "createWindow", moduleName, JsWindowManager::CreateWindow);
894 BindNativeFunction(*engine, *object, "find", moduleName, JsWindowManager::FindWindow);
895 BindNativeFunction(*engine, *object, "findWindow", moduleName, JsWindowManager::FindWindowSync);
896 BindNativeFunction(*engine, *object, "on", moduleName, JsWindowManager::RegisterWindowManagerCallback);
897 BindNativeFunction(*engine, *object, "off", moduleName, JsWindowManager::UnregisterWindowMangerCallback);
898 BindNativeFunction(*engine, *object, "getTopWindow", moduleName, JsWindowManager::GetTopWindow);
899 BindNativeFunction(*engine, *object, "getLastWindow", moduleName, JsWindowManager::GetLastWindow);
900 BindNativeFunction(*engine, *object, "minimizeAll", moduleName, JsWindowManager::MinimizeAll);
901 BindNativeFunction(*engine, *object, "toggleShownStateForAllAppWindows", moduleName,
902 JsWindowManager::ToggleShownStateForAllAppWindows);
903 BindNativeFunction(*engine, *object, "setWindowLayoutMode", moduleName, JsWindowManager::SetWindowLayoutMode);
904 return engine->CreateUndefined();
905 }
906 } // namespace Rosen
907 } // namespace OHOS
908