• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "js_extension_window_config.h"
16 #include <string>
17 #include "js_window_utils.h"
18 #include "window_manager_hilog.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 using namespace AbilityRuntime;
23 namespace {
24 constexpr char EXTENSION_WINDOW_CONFIG_NAME[] = "__extension_window_config_ptr__";
25 constexpr size_t ARGC_ZERO = 0;
26 constexpr size_t ARGC_ONE = 1;
27 
NapiGetUndefined(napi_env env)28 napi_value NapiGetUndefined(napi_env env)
29 {
30     napi_value result = nullptr;
31     napi_get_undefined(env, &result);
32     return result;
33 }
34 
BindNativePropertys(napi_env env,napi_value object,const char * name,napi_callback getter,napi_callback setter)35 void BindNativePropertys(napi_env env, napi_value object, const char* name, napi_callback getter,
36     napi_callback setter)
37 {
38     napi_property_descriptor properties[ARGC_ONE];
39     properties[ARGC_ZERO].utf8name = name;
40     properties[ARGC_ZERO].name = nullptr;
41     properties[ARGC_ZERO].method = nullptr;
42     properties[ARGC_ZERO].getter = getter;
43     properties[ARGC_ZERO].setter = setter;
44     properties[ARGC_ZERO].value = nullptr;
45     properties[ARGC_ZERO].attributes = napi_default;
46     properties[ARGC_ZERO].data = nullptr;
47     napi_define_properties(env, object, ARGC_ONE, properties);
48 }
49 } // namespace
50 
JsExtensionWindowConfig(const std::shared_ptr<ExtensionWindowConfig> & extensionWindowConfig)51 JsExtensionWindowConfig::JsExtensionWindowConfig(const std::shared_ptr<ExtensionWindowConfig>& extensionWindowConfig)
52     : extensionWindowConfig_(extensionWindowConfig)
53 {
54 }
55 
56 JsExtensionWindowConfig::~JsExtensionWindowConfig() = default;
57 
Finalizer(napi_env env,void * data,void * hint)58 void JsExtensionWindowConfig::Finalizer(napi_env env, void* data, void* hint)
59 {
60     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
61     std::unique_ptr<JsExtensionWindowConfig>(static_cast<JsExtensionWindowConfig *>(data));
62 }
63 
CreateJsExtensionWindowConfig(napi_env env,const std::shared_ptr<ExtensionWindowConfig> & extensionWindowConfig)64 napi_value CreateJsExtensionWindowConfig(napi_env env,
65     const std::shared_ptr<ExtensionWindowConfig>& extensionWindowConfig)
66 {
67     napi_value objValue = nullptr;
68     napi_create_object(env, &objValue);
69     if (objValue == nullptr) {
70         TLOGE(WmsLogTag::WMS_UIEXT, "objValue is null.");
71         return NapiGetUndefined(env);
72     }
73     std::unique_ptr<JsExtensionWindowConfig> jsExtensionWindowConfig =
74         std::make_unique<JsExtensionWindowConfig>(extensionWindowConfig);
75     SetNamedNativePointer(env, objValue, EXTENSION_WINDOW_CONFIG_NAME, jsExtensionWindowConfig.release(),
76         JsExtensionWindowConfig::Finalizer);
77     BindNativePropertys(env, objValue, "windowName", JsExtensionWindowConfig::GetWindowName,
78         JsExtensionWindowConfig::SetWindowName);
79     BindNativePropertys(env, objValue, "windowAttribute", JsExtensionWindowConfig::GetWindowAttribute,
80         JsExtensionWindowConfig::SetWindowAttribute);
81     BindNativePropertys(env, objValue, "windowRect", JsExtensionWindowConfig::GetWindowRect,
82         JsExtensionWindowConfig::SetWindowRect);
83     BindNativePropertys(env, objValue, "subWindowOptions", JsExtensionWindowConfig::GetSubWindowOptions,
84         JsExtensionWindowConfig::SetSubWindowOptions);
85     BindNativePropertys(env, objValue, "systemWindowOptions", JsExtensionWindowConfig::GetSystemWindowOptions,
86         JsExtensionWindowConfig::SetSystemWindowOptions);
87     return objValue;
88 }
89 
GetWindowName(napi_env env,napi_callback_info info)90 napi_value JsExtensionWindowConfig::GetWindowName(napi_env env, napi_callback_info info)
91 {
92     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
93     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetWindowName,
94         EXTENSION_WINDOW_CONFIG_NAME);
95 }
96 
OnGetWindowName(napi_env env,NapiCallbackInfo & info)97 napi_value JsExtensionWindowConfig::OnGetWindowName(napi_env env, NapiCallbackInfo& info)
98 {
99     return CreateJsValue(env, extensionWindowConfig_->windowName);
100 }
101 
GetWindowAttribute(napi_env env,napi_callback_info info)102 napi_value JsExtensionWindowConfig::GetWindowAttribute(napi_env env, napi_callback_info info)
103 {
104     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
105     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetWindowAttribute,
106         EXTENSION_WINDOW_CONFIG_NAME);
107 }
108 
OnGetWindowAttribute(napi_env env,NapiCallbackInfo & info)109 napi_value JsExtensionWindowConfig::OnGetWindowAttribute(napi_env env, NapiCallbackInfo& info)
110 {
111     return CreateJsValue(env, static_cast<int32_t>(extensionWindowConfig_->windowAttribute));
112 }
113 
GetWindowRect(napi_env env,napi_callback_info info)114 napi_value JsExtensionWindowConfig::GetWindowRect(napi_env env, napi_callback_info info)
115 {
116     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
117     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetWindowRect,
118         EXTENSION_WINDOW_CONFIG_NAME);
119 }
120 
OnGetWindowRect(napi_env env,NapiCallbackInfo & info)121 napi_value JsExtensionWindowConfig::OnGetWindowRect(napi_env env, NapiCallbackInfo& info)
122 {
123     napi_value objValue = nullptr;
124     napi_create_object(env, &objValue);
125     if (objValue == nullptr) {
126         TLOGE(WmsLogTag::WMS_UIEXT, "objValue is null.");
127         return NapiGetUndefined(env);
128     }
129     std::unique_ptr<JsExtensionWindowConfig> jsExtensionWindowConfig =
130         std::make_unique<JsExtensionWindowConfig>(extensionWindowConfig_);
131     SetNamedNativePointer(env, objValue, EXTENSION_WINDOW_CONFIG_NAME, jsExtensionWindowConfig.release(),
132         JsExtensionWindowConfig::Finalizer);
133     BindNativePropertys(env, objValue, "left", JsExtensionWindowConfig::GetWindowRectLeft,
134         JsExtensionWindowConfig::SetWindowRectLeft);
135     BindNativePropertys(env, objValue, "top", JsExtensionWindowConfig::GetWindowRectTop,
136         JsExtensionWindowConfig::SetWindowRectTop);
137     BindNativePropertys(env, objValue, "width", JsExtensionWindowConfig::GetWindowRectWidth,
138         JsExtensionWindowConfig::SetWindowRectWidth);
139     BindNativePropertys(env, objValue, "height", JsExtensionWindowConfig::GetWindowRectHeight,
140         JsExtensionWindowConfig::SetWindowRectHeight);
141     return objValue;
142 }
143 
GetWindowRectLeft(napi_env env,napi_callback_info info)144 napi_value JsExtensionWindowConfig::GetWindowRectLeft(napi_env env, napi_callback_info info)
145 {
146     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
147     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetWindowRectLeft,
148         EXTENSION_WINDOW_CONFIG_NAME);
149 }
150 
OnGetWindowRectLeft(napi_env env,NapiCallbackInfo & info)151 napi_value JsExtensionWindowConfig::OnGetWindowRectLeft(napi_env env, NapiCallbackInfo& info)
152 {
153     return CreateJsValue(env, extensionWindowConfig_->windowRect.posX_);
154 }
155 
GetWindowRectTop(napi_env env,napi_callback_info info)156 napi_value JsExtensionWindowConfig::GetWindowRectTop(napi_env env, napi_callback_info info)
157 {
158     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
159     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetWindowRectTop,
160         EXTENSION_WINDOW_CONFIG_NAME);
161 }
162 
OnGetWindowRectTop(napi_env env,NapiCallbackInfo & info)163 napi_value JsExtensionWindowConfig::OnGetWindowRectTop(napi_env env, NapiCallbackInfo& info)
164 {
165     return CreateJsValue(env, extensionWindowConfig_->windowRect.posY_);
166 }
167 
GetWindowRectWidth(napi_env env,napi_callback_info info)168 napi_value JsExtensionWindowConfig::GetWindowRectWidth(napi_env env, napi_callback_info info)
169 {
170     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
171     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetWindowRectWidth,
172         EXTENSION_WINDOW_CONFIG_NAME);
173 }
174 
OnGetWindowRectWidth(napi_env env,NapiCallbackInfo & info)175 napi_value JsExtensionWindowConfig::OnGetWindowRectWidth(napi_env env, NapiCallbackInfo& info)
176 {
177     return CreateJsValue(env, extensionWindowConfig_->windowRect.width_);
178 }
179 
GetWindowRectHeight(napi_env env,napi_callback_info info)180 napi_value JsExtensionWindowConfig::GetWindowRectHeight(napi_env env, napi_callback_info info)
181 {
182     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
183     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetWindowRectHeight,
184         EXTENSION_WINDOW_CONFIG_NAME);
185 }
186 
OnGetWindowRectHeight(napi_env env,NapiCallbackInfo & info)187 napi_value JsExtensionWindowConfig::OnGetWindowRectHeight(napi_env env, NapiCallbackInfo& info)
188 {
189     return CreateJsValue(env, extensionWindowConfig_->windowRect.height_);
190 }
191 
GetSubWindowOptions(napi_env env,napi_callback_info info)192 napi_value JsExtensionWindowConfig::GetSubWindowOptions(napi_env env, napi_callback_info info)
193 {
194     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
195     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetSubWindowOptions,
196         EXTENSION_WINDOW_CONFIG_NAME);
197 }
198 
OnGetSubWindowOptions(napi_env env,NapiCallbackInfo & info)199 napi_value JsExtensionWindowConfig::OnGetSubWindowOptions(napi_env env, NapiCallbackInfo& info)
200 {
201     napi_value objValue = nullptr;
202     napi_create_object(env, &objValue);
203     if (objValue == nullptr) {
204         TLOGE(WmsLogTag::WMS_UIEXT, "objValue is null.");
205         return NapiGetUndefined(env);
206     }
207     std::unique_ptr<JsExtensionWindowConfig> jsExtensionWindowConfig =
208         std::make_unique<JsExtensionWindowConfig>(extensionWindowConfig_);
209     SetNamedNativePointer(env, objValue, EXTENSION_WINDOW_CONFIG_NAME, jsExtensionWindowConfig.release(),
210         JsExtensionWindowConfig::Finalizer);
211     BindNativePropertys(env, objValue, "title", JsExtensionWindowConfig::GetSubWindowOptionsTitle,
212         JsExtensionWindowConfig::SetSubWindowOptionsTitle);
213     BindNativePropertys(env, objValue, "decorEnabled", JsExtensionWindowConfig::GetSubWindowOptionsDecorEnabled,
214         JsExtensionWindowConfig::SetSubWindowOptionsDecorEnabled);
215     BindNativePropertys(env, objValue, "isModal", JsExtensionWindowConfig::GetSubWindowOptionsIsModal,
216         JsExtensionWindowConfig::SetSubWindowOptionsIsModal);
217     BindNativePropertys(env, objValue, "isTopmost", JsExtensionWindowConfig::GetSubWindowOptionsIsTopmost,
218         JsExtensionWindowConfig::SetSubWindowOptionsIsTopmost);
219     return objValue;
220 }
221 
GetSubWindowOptionsTitle(napi_env env,napi_callback_info info)222 napi_value JsExtensionWindowConfig::GetSubWindowOptionsTitle(napi_env env, napi_callback_info info)
223 {
224     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
225     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetSubWindowOptionsTitle,
226         EXTENSION_WINDOW_CONFIG_NAME);
227 }
228 
OnGetSubWindowOptionsTitle(napi_env env,NapiCallbackInfo & info)229 napi_value JsExtensionWindowConfig::OnGetSubWindowOptionsTitle(napi_env env, NapiCallbackInfo& info)
230 {
231     return CreateJsValue(env, extensionWindowConfig_->subWindowOptions.title);
232 }
233 
GetSubWindowOptionsDecorEnabled(napi_env env,napi_callback_info info)234 napi_value JsExtensionWindowConfig::GetSubWindowOptionsDecorEnabled(napi_env env, napi_callback_info info)
235 {
236     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
237     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetSubWindowOptionsDecorEnabled,
238         EXTENSION_WINDOW_CONFIG_NAME);
239 }
240 
OnGetSubWindowOptionsDecorEnabled(napi_env env,NapiCallbackInfo & info)241 napi_value JsExtensionWindowConfig::OnGetSubWindowOptionsDecorEnabled(napi_env env, NapiCallbackInfo& info)
242 {
243     return CreateJsValue(env, extensionWindowConfig_->subWindowOptions.decorEnabled);
244 }
245 
GetSubWindowOptionsIsModal(napi_env env,napi_callback_info info)246 napi_value JsExtensionWindowConfig::GetSubWindowOptionsIsModal(napi_env env, napi_callback_info info)
247 {
248     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
249     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetSubWindowOptionsIsModal,
250         EXTENSION_WINDOW_CONFIG_NAME);
251 }
252 
OnGetSubWindowOptionsIsModal(napi_env env,NapiCallbackInfo & info)253 napi_value JsExtensionWindowConfig::OnGetSubWindowOptionsIsModal(napi_env env, NapiCallbackInfo& info)
254 {
255     return CreateJsValue(env, extensionWindowConfig_->subWindowOptions.isModal);
256 }
257 
GetSubWindowOptionsIsTopmost(napi_env env,napi_callback_info info)258 napi_value JsExtensionWindowConfig::GetSubWindowOptionsIsTopmost(napi_env env, napi_callback_info info)
259 {
260     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
261     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetSubWindowOptionsIsTopmost,
262         EXTENSION_WINDOW_CONFIG_NAME);
263 }
264 
OnGetSubWindowOptionsIsTopmost(napi_env env,NapiCallbackInfo & info)265 napi_value JsExtensionWindowConfig::OnGetSubWindowOptionsIsTopmost(napi_env env, NapiCallbackInfo& info)
266 {
267     return CreateJsValue(env, extensionWindowConfig_->subWindowOptions.isTopmost);
268 }
269 
GetSystemWindowOptions(napi_env env,napi_callback_info info)270 napi_value JsExtensionWindowConfig::GetSystemWindowOptions(napi_env env, napi_callback_info info)
271 {
272     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
273     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetSystemWindowOptions,
274         EXTENSION_WINDOW_CONFIG_NAME);
275 }
276 
OnGetSystemWindowOptions(napi_env env,NapiCallbackInfo & info)277 napi_value JsExtensionWindowConfig::OnGetSystemWindowOptions(napi_env env, NapiCallbackInfo& info)
278 {
279     napi_value objValue = nullptr;
280     napi_create_object(env, &objValue);
281     if (objValue == nullptr) {
282         TLOGE(WmsLogTag::WMS_UIEXT, "objValue is null.");
283         return NapiGetUndefined(env);
284     }
285     std::unique_ptr<JsExtensionWindowConfig> jsExtensionWindowConfig =
286         std::make_unique<JsExtensionWindowConfig>(extensionWindowConfig_);
287     SetNamedNativePointer(env, objValue, EXTENSION_WINDOW_CONFIG_NAME, jsExtensionWindowConfig.release(),
288         JsExtensionWindowConfig::Finalizer);
289     BindNativePropertys(env, objValue, "windowType", JsExtensionWindowConfig::GetSystemWindowOptionsWindowType,
290         JsExtensionWindowConfig::SetSystemWindowOptionsWindowType);
291     return objValue;
292 }
293 
GetSystemWindowOptionsWindowType(napi_env env,napi_callback_info info)294 napi_value JsExtensionWindowConfig::GetSystemWindowOptionsWindowType(napi_env env, napi_callback_info info)
295 {
296     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
297     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnGetSystemWindowOptionsWindowType,
298         EXTENSION_WINDOW_CONFIG_NAME);
299 }
300 
OnGetSystemWindowOptionsWindowType(napi_env env,NapiCallbackInfo & info)301 napi_value JsExtensionWindowConfig::OnGetSystemWindowOptionsWindowType(napi_env env, NapiCallbackInfo& info)
302 {
303     return CreateJsValue(env, extensionWindowConfig_->systemWindowOptions.windowType);
304 }
305 
SetWindowName(napi_env env,napi_callback_info info)306 napi_value JsExtensionWindowConfig::SetWindowName(napi_env env, napi_callback_info info)
307 {
308     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
309     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetWindowName,
310         EXTENSION_WINDOW_CONFIG_NAME);
311 }
312 
OnSetWindowName(napi_env env,NapiCallbackInfo & info)313 napi_value JsExtensionWindowConfig::OnSetWindowName(napi_env env, NapiCallbackInfo& info)
314 {
315     if (info.argc < ARGC_ONE) {
316         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
317         return NapiGetUndefined(env);
318     }
319     napi_value result = info.argv[ARGC_ZERO];
320     std::string windowName;
321     if (!ConvertFromJsValue(env, result, windowName)) {
322         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert windowName");
323         return NapiGetUndefined(env);
324     }
325     extensionWindowConfig_->windowName = windowName;
326     return result;
327 }
328 
SetWindowAttribute(napi_env env,napi_callback_info info)329 napi_value JsExtensionWindowConfig::SetWindowAttribute(napi_env env, napi_callback_info info)
330 {
331     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
332     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetWindowAttribute,
333         EXTENSION_WINDOW_CONFIG_NAME);
334 }
335 
OnSetWindowAttribute(napi_env env,NapiCallbackInfo & info)336 napi_value JsExtensionWindowConfig::OnSetWindowAttribute(napi_env env, NapiCallbackInfo& info)
337 {
338     if (info.argc < ARGC_ONE) {
339         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
340         return NapiGetUndefined(env);
341     }
342     napi_value result = info.argv[ARGC_ZERO];
343     int32_t value = 0;
344     if (!ConvertFromJsValue(env, result, value)) {
345         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert windowAttribute");
346         return NapiGetUndefined(env);
347     }
348     extensionWindowConfig_->windowAttribute = ExtensionWindowAttribute(value);
349     return result;
350 }
351 
SetWindowRect(napi_env env,napi_callback_info info)352 napi_value JsExtensionWindowConfig::SetWindowRect(napi_env env, napi_callback_info info)
353 {
354     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
355     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetWindowRect,
356         EXTENSION_WINDOW_CONFIG_NAME);
357 }
358 
OnSetWindowRect(napi_env env,NapiCallbackInfo & info)359 napi_value JsExtensionWindowConfig::OnSetWindowRect(napi_env env, NapiCallbackInfo& info)
360 {
361     if (info.argc < ARGC_ONE) {
362         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
363         return NapiGetUndefined(env);
364     }
365     napi_value result = info.argv[ARGC_ZERO];
366     int32_t res = 0;
367     if (!ParseJsValue(result, env, "left", res)) {
368         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert left");
369         return NapiGetUndefined(env);
370     }
371     extensionWindowConfig_->windowRect.posX_ = res;
372     if (!ParseJsValue(result, env, "top", res)) {
373         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert top");
374         return NapiGetUndefined(env);
375     }
376     extensionWindowConfig_->windowRect.posY_ = res;
377     uint32_t ures = 0;
378     if (!ParseJsValue(result, env, "width", ures)) {
379         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert width");
380         return NapiGetUndefined(env);
381     }
382     extensionWindowConfig_->windowRect.width_ = ures;
383     if (!ParseJsValue(result, env, "height", ures)) {
384         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert height");
385         return NapiGetUndefined(env);
386     }
387     extensionWindowConfig_->windowRect.height_ = ures;
388     return result;
389 }
390 
SetWindowRectLeft(napi_env env,napi_callback_info info)391 napi_value JsExtensionWindowConfig::SetWindowRectLeft(napi_env env, napi_callback_info info)
392 {
393     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
394     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetWindowRectLeft,
395         EXTENSION_WINDOW_CONFIG_NAME);
396 }
397 
OnSetWindowRectLeft(napi_env env,NapiCallbackInfo & info)398 napi_value JsExtensionWindowConfig::OnSetWindowRectLeft(napi_env env, NapiCallbackInfo& info)
399 {
400     if (info.argc < ARGC_ONE) {
401         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
402         return NapiGetUndefined(env);
403     }
404     napi_value result = info.argv[ARGC_ZERO];
405     int32_t left = 0;
406     if (!ConvertFromJsValue(env, result, left)) {
407         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert left");
408         return NapiGetUndefined(env);
409     }
410     extensionWindowConfig_->windowRect.posX_ = left;
411     return result;
412 }
413 
SetWindowRectTop(napi_env env,napi_callback_info info)414 napi_value JsExtensionWindowConfig::SetWindowRectTop(napi_env env, napi_callback_info info)
415 {
416     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
417     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetWindowRectTop,
418         EXTENSION_WINDOW_CONFIG_NAME);
419 }
420 
OnSetWindowRectTop(napi_env env,NapiCallbackInfo & info)421 napi_value JsExtensionWindowConfig::OnSetWindowRectTop(napi_env env, NapiCallbackInfo& info)
422 {
423     if (info.argc < ARGC_ONE) {
424         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
425         return NapiGetUndefined(env);
426     }
427     napi_value result = info.argv[ARGC_ZERO];
428     int32_t top = 0;
429     if (!ConvertFromJsValue(env, result, top)) {
430         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert top");
431         return NapiGetUndefined(env);
432     }
433     extensionWindowConfig_->windowRect.posY_ = top;
434     return result;
435 }
436 
SetWindowRectWidth(napi_env env,napi_callback_info info)437 napi_value JsExtensionWindowConfig::SetWindowRectWidth(napi_env env, napi_callback_info info)
438 {
439     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
440     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetWindowRectWidth,
441         EXTENSION_WINDOW_CONFIG_NAME);
442 }
443 
OnSetWindowRectWidth(napi_env env,NapiCallbackInfo & info)444 napi_value JsExtensionWindowConfig::OnSetWindowRectWidth(napi_env env, NapiCallbackInfo& info)
445 {
446     if (info.argc < ARGC_ONE) {
447         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
448         return NapiGetUndefined(env);
449     }
450     napi_value result = info.argv[ARGC_ZERO];
451     uint32_t width = 0;
452     if (!ConvertFromJsValue(env, result, width)) {
453         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert width");
454         return NapiGetUndefined(env);
455     }
456     extensionWindowConfig_->windowRect.width_ = width;
457     return result;
458 }
459 
SetWindowRectHeight(napi_env env,napi_callback_info info)460 napi_value JsExtensionWindowConfig::SetWindowRectHeight(napi_env env, napi_callback_info info)
461 {
462     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
463     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetWindowRectHeight,
464         EXTENSION_WINDOW_CONFIG_NAME);
465 }
466 
OnSetWindowRectHeight(napi_env env,NapiCallbackInfo & info)467 napi_value JsExtensionWindowConfig::OnSetWindowRectHeight(napi_env env, NapiCallbackInfo& info)
468 {
469     if (info.argc < ARGC_ONE) {
470         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
471         return NapiGetUndefined(env);
472     }
473     napi_value result = info.argv[ARGC_ZERO];
474     uint32_t height = 0;
475     if (!ConvertFromJsValue(env, result, height)) {
476         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert height");
477         return NapiGetUndefined(env);
478     }
479     extensionWindowConfig_->windowRect.height_ = height;
480     return result;
481 }
482 
SetSubWindowOptions(napi_env env,napi_callback_info info)483 napi_value JsExtensionWindowConfig::SetSubWindowOptions(napi_env env, napi_callback_info info)
484 {
485     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
486     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetSubWindowOptions,
487         EXTENSION_WINDOW_CONFIG_NAME);
488 }
489 
OnSetSubWindowOptions(napi_env env,NapiCallbackInfo & info)490 napi_value JsExtensionWindowConfig::OnSetSubWindowOptions(napi_env env, NapiCallbackInfo& info)
491 {
492     if (info.argc < ARGC_ONE) {
493         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
494         return NapiGetUndefined(env);
495     }
496     napi_value result = info.argv[ARGC_ZERO];
497     std::string title;
498     if (!ParseJsValue(result, env, "title", title)) {
499         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert title");
500         return NapiGetUndefined(env);
501     }
502     extensionWindowConfig_->subWindowOptions.title = title;
503 
504     bool decorEnabled = false;
505     if (!ParseJsValue(result, env, "decorEnabled", decorEnabled)) {
506         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert decorEnabled");
507         return NapiGetUndefined(env);
508     }
509     extensionWindowConfig_->subWindowOptions.decorEnabled = decorEnabled;
510 
511     bool isModal = false;
512     if (!ParseJsValue(result, env, "isModal", isModal)) {
513         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert isModal");
514         return NapiGetUndefined(env);
515     }
516     extensionWindowConfig_->subWindowOptions.isModal = isModal;
517 
518     bool isTopmost = false;
519     if (!ParseJsValue(result, env, "isTopmost", isTopmost)) {
520         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert isTopmost");
521         return NapiGetUndefined(env);
522     }
523     extensionWindowConfig_->subWindowOptions.isTopmost = isTopmost;
524     return result;
525 }
526 
SetSubWindowOptionsTitle(napi_env env,napi_callback_info info)527 napi_value JsExtensionWindowConfig::SetSubWindowOptionsTitle(napi_env env, napi_callback_info info)
528 {
529     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
530     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetSubWindowOptionsTitle,
531         EXTENSION_WINDOW_CONFIG_NAME);
532 }
533 
OnSetSubWindowOptionsTitle(napi_env env,NapiCallbackInfo & info)534 napi_value JsExtensionWindowConfig::OnSetSubWindowOptionsTitle(napi_env env, NapiCallbackInfo& info)
535 {
536     if (info.argc < ARGC_ONE) {
537         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
538         return NapiGetUndefined(env);
539     }
540     napi_value result = info.argv[ARGC_ZERO];
541     std::string title;
542     if (!ConvertFromJsValue(env, result, title)) {
543         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert title");
544         return NapiGetUndefined(env);
545     }
546     extensionWindowConfig_->subWindowOptions.title = title;
547     return result;
548 }
549 
550 
SetSubWindowOptionsDecorEnabled(napi_env env,napi_callback_info info)551 napi_value JsExtensionWindowConfig::SetSubWindowOptionsDecorEnabled(napi_env env, napi_callback_info info)
552 {
553     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
554     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetSubWindowOptionsDecorEnabled,
555         EXTENSION_WINDOW_CONFIG_NAME);
556 }
557 
OnSetSubWindowOptionsDecorEnabled(napi_env env,NapiCallbackInfo & info)558 napi_value JsExtensionWindowConfig::OnSetSubWindowOptionsDecorEnabled(napi_env env, NapiCallbackInfo& info)
559 {
560     if (info.argc < ARGC_ONE) {
561         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
562         return NapiGetUndefined(env);
563     }
564     napi_value result = info.argv[ARGC_ZERO];
565     bool decorEnabled = false;
566     if (!ConvertFromJsValue(env, result, decorEnabled)) {
567         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert decorEnabled");
568         return NapiGetUndefined(env);
569     }
570     extensionWindowConfig_->subWindowOptions.decorEnabled = decorEnabled;
571     return result;
572 }
573 
SetSubWindowOptionsIsModal(napi_env env,napi_callback_info info)574 napi_value JsExtensionWindowConfig::SetSubWindowOptionsIsModal(napi_env env, napi_callback_info info)
575 {
576     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
577     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetSubWindowOptionsIsModal,
578         EXTENSION_WINDOW_CONFIG_NAME);
579 }
580 
OnSetSubWindowOptionsIsModal(napi_env env,NapiCallbackInfo & info)581 napi_value JsExtensionWindowConfig::OnSetSubWindowOptionsIsModal(napi_env env, NapiCallbackInfo& info)
582 {
583     if (info.argc < ARGC_ONE) {
584         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
585         return NapiGetUndefined(env);
586     }
587     napi_value result = info.argv[ARGC_ZERO];
588     bool isModal = false;
589     if (!ConvertFromJsValue(env, result, isModal)) {
590         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert isModal");
591         return NapiGetUndefined(env);
592     }
593     extensionWindowConfig_->subWindowOptions.isModal = isModal;
594     return result;
595 }
596 
SetSubWindowOptionsIsTopmost(napi_env env,napi_callback_info info)597 napi_value JsExtensionWindowConfig::SetSubWindowOptionsIsTopmost(napi_env env, napi_callback_info info)
598 {
599     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
600     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetSubWindowOptionsIsTopmost,
601         EXTENSION_WINDOW_CONFIG_NAME);
602 }
603 
OnSetSubWindowOptionsIsTopmost(napi_env env,NapiCallbackInfo & info)604 napi_value JsExtensionWindowConfig::OnSetSubWindowOptionsIsTopmost(napi_env env, NapiCallbackInfo& info)
605 {
606     if (info.argc < ARGC_ONE) {
607         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
608         return NapiGetUndefined(env);
609     }
610     napi_value result = info.argv[ARGC_ZERO];
611     bool isTopmost = false;
612     if (!ConvertFromJsValue(env, result, isTopmost)) {
613         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert isTopmost");
614         return NapiGetUndefined(env);
615     }
616     extensionWindowConfig_->subWindowOptions.isTopmost = isTopmost;
617     return result;
618 }
619 
SetSystemWindowOptions(napi_env env,napi_callback_info info)620 napi_value JsExtensionWindowConfig::SetSystemWindowOptions(napi_env env, napi_callback_info info)
621 {
622     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
623     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetSystemWindowOptions,
624         EXTENSION_WINDOW_CONFIG_NAME);
625 }
626 
OnSetSystemWindowOptions(napi_env env,NapiCallbackInfo & info)627 napi_value JsExtensionWindowConfig::OnSetSystemWindowOptions(napi_env env, NapiCallbackInfo& info)
628 {
629     if (info.argc < ARGC_ONE) {
630         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
631         return NapiGetUndefined(env);
632     }
633     napi_value result = info.argv[ARGC_ZERO];
634     int32_t windowType = 0;
635     if (!ParseJsValue(result, env, "windowType", windowType)) {
636         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert windowType");
637         return NapiGetUndefined(env);
638     }
639     extensionWindowConfig_->systemWindowOptions.windowType = windowType;
640     return result;
641 }
642 
SetSystemWindowOptionsWindowType(napi_env env,napi_callback_info info)643 napi_value JsExtensionWindowConfig::SetSystemWindowOptionsWindowType(napi_env env, napi_callback_info info)
644 {
645     TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]called");
646     GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsExtensionWindowConfig, OnSetSystemWindowOptionsWindowType,
647         EXTENSION_WINDOW_CONFIG_NAME);
648 }
649 
OnSetSystemWindowOptionsWindowType(napi_env env,NapiCallbackInfo & info)650 napi_value JsExtensionWindowConfig::OnSetSystemWindowOptionsWindowType(napi_env env, NapiCallbackInfo& info)
651 {
652     if (info.argc < ARGC_ONE) {
653         TLOGE(WmsLogTag::WMS_UIEXT, "info argc less then one.");
654         return NapiGetUndefined(env);
655     }
656     napi_value result = info.argv[ARGC_ZERO];
657     int32_t windowType = 0;
658     if (!ConvertFromJsValue(env, result, windowType)) {
659         TLOGE(WmsLogTag::WMS_UIEXT, "failed to convert windowType");
660         return NapiGetUndefined(env);
661     }
662     extensionWindowConfig_->systemWindowOptions.windowType = windowType;
663     return result;
664 }
665 } // namespace Rosen
666 } // namespace OHOS