1 /*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "frameworks/bridge/declarative_frontend/jsview/js_web.h"
17
18 #include <optional>
19 #include <string>
20
21 #include "adapter/ohos/osal/pixel_map_ohos.h"
22 #include "pixel_map.h"
23 #include "pixel_map_napi.h"
24 #include "securec.h"
25
26 #include "base/log/ace_scoring_log.h"
27 #include "base/memory/ace_type.h"
28 #include "base/memory/referenced.h"
29 #include "base/utils/system_properties.h"
30 #include "base/utils/utils.h"
31 #include "base/web/webview/arkweb_utils/arkweb_utils.h"
32 #if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM)
33 #include "base/web/webview/ohos_interface/include/ohos_nweb/nweb.h"
34 #endif
35 #include "bridge/common/utils/engine_helper.h"
36 #include "bridge/declarative_frontend/engine/functions/js_click_function.h"
37 #include "bridge/declarative_frontend/engine/functions/js_common_utils.h"
38 #include "bridge/declarative_frontend/engine/functions/js_drag_function.h"
39 #include "bridge/declarative_frontend/engine/functions/js_event_function.h"
40 #include "bridge/declarative_frontend/engine/functions/js_key_function.h"
41 #include "bridge/declarative_frontend/engine/js_converter.h"
42 #include "bridge/declarative_frontend/engine/js_ref_ptr.h"
43 #include "bridge/declarative_frontend/jsview/js_utils.h"
44 #include "bridge/declarative_frontend/jsview/js_web_controller.h"
45 #include "bridge/declarative_frontend/jsview/models/web_model_impl.h"
46 #include "bridge/declarative_frontend/view_stack_processor.h"
47 #include "core/common/ace_application_info.h"
48 #include "core/common/container.h"
49 #include "core/common/container_scope.h"
50 #include "core/components/web/web_event.h"
51 #include "core/components_ng/pattern/web/web_model_ng.h"
52
53 #include "bridge/js_frontend/engine/common/js_engine.h"
54 #include "core/components/web/web_transfer_api.h"
55
56 #define ARKWEB_CREATE_JS_OBJECT(nativeClass, jsClass, funName, eventValue) \
57 napi_value Create##jsClass##Object(napi_env env, const RefPtr<nativeClass>& value) \
58 { \
59 JSRef<JSObject> jsObject = JSClass<jsClass>::NewInstance(); \
60 auto nativeObject = Referenced::Claim(jsObject->Unwrap<jsClass>()); \
61 nativeObject->funName(eventValue); \
62 return WrapNapiValue(env, JSRef<JSVal>::Cast(jsObject), static_cast<void*>(nativeObject.GetRawPtr())); \
63 }
64
65 namespace OHOS::Ace {
66 namespace {
67 const std::string RAWFILE_PREFIX = "resource://RAWFILE/";
68 const std::string BUNDLE_NAME_PREFIX = "bundleName:";
69 const std::string MODULE_NAME_PREFIX = "moduleName:";
70
71 const int32_t SELECTION_MENU_OPTION_PARAM_INDEX = 3;
72 const int32_t SELECTION_MENU_CONTENT_PARAM_INDEX = 2;
73 const int32_t PARAM_ZERO = 0;
74 const int32_t PARAM_ONE = 1;
75 const int32_t PARAM_TWO = 2;
76 constexpr Dimension PREVIEW_MENU_MARGIN_LEFT = 16.0_vp;
77 constexpr Dimension PREVIEW_MENU_MARGIN_RIGHT = 16.0_vp;
78 const int32_t WEB_AUDIO_SESSION_TYPE_AMBIENT = 3;
79
EraseSpace(std::string & data)80 void EraseSpace(std::string& data)
81 {
82 auto iter = data.begin();
83 while (iter != data.end()) {
84 if (isspace(*iter)) {
85 iter = data.erase(iter);
86 } else {
87 ++iter;
88 }
89 }
90 }
91 }
92
93 std::unique_ptr<WebModel> WebModel::instance_ = nullptr;
94 std::mutex WebModel::mutex_;
GetInstance()95 WebModel* WebModel::GetInstance()
96 {
97 if (!instance_) {
98 std::lock_guard<std::mutex> lock(mutex_);
99 if (!instance_) {
100 #ifdef NG_BUILD
101 instance_.reset(new NG::WebModelNG());
102 #else
103 if (Container::IsCurrentUseNewPipeline()) {
104 instance_.reset(new NG::WebModelNG());
105 } else {
106 instance_.reset(new Framework::WebModelImpl());
107 }
108 #endif
109 }
110 }
111 return instance_.get();
112 }
113
114 } // namespace OHOS::Ace
115
116 namespace OHOS::Ace::Framework {
117 using namespace OHOS::Ace::Framework::CommonUtils;
118 bool JSWeb::webDebuggingAccess_ = false;
119 int32_t JSWeb::webDebuggingPort_ = 0;
120 class JSWebDialog : public WebTransferBase<RefPtr<Result>> {
121 public:
JSBind(BindingTarget globalObj)122 static void JSBind(BindingTarget globalObj)
123 {
124 JSClass<JSWebDialog>::Declare("JsResult");
125 JSClass<JSWebDialog>::CustomMethod("handleConfirm", &JSWebDialog::Confirm);
126 JSClass<JSWebDialog>::CustomMethod("handleCancel", &JSWebDialog::Cancel);
127 JSClass<JSWebDialog>::CustomMethod("handlePromptConfirm", &JSWebDialog::PromptConfirm);
128 JSClass<JSWebDialog>::Bind(globalObj, &JSWebDialog::Constructor, &JSWebDialog::Destructor);
129 }
130
SetResult(const RefPtr<Result> & result)131 void SetResult(const RefPtr<Result>& result)
132 {
133 result_ = result;
134 transferValues_ = std::make_tuple(result_);
135 }
136
Confirm(const JSCallbackInfo & args)137 void Confirm(const JSCallbackInfo& args)
138 {
139 if (result_) {
140 result_->Confirm();
141 }
142 }
143
PromptConfirm(const JSCallbackInfo & args)144 void PromptConfirm(const JSCallbackInfo& args)
145 {
146 std::string message;
147 if (!result_) {
148 return;
149 }
150 if (args.Length() == 1 && args[0]->IsString()) {
151 message = args[0]->ToString();
152 result_->Confirm(message);
153 }
154 }
155
Cancel(const JSCallbackInfo & args)156 void Cancel(const JSCallbackInfo& args)
157 {
158 if (result_) {
159 result_->Cancel();
160 }
161 }
162
163 private:
Constructor(const JSCallbackInfo & args)164 static void Constructor(const JSCallbackInfo& args)
165 {
166 auto jsWebDialog = Referenced::MakeRefPtr<JSWebDialog>();
167 jsWebDialog->IncRefCount();
168 args.SetReturnValue(Referenced::RawPtr(jsWebDialog));
169 }
170
Destructor(JSWebDialog * jsWebDialog)171 static void Destructor(JSWebDialog* jsWebDialog)
172 {
173 if (jsWebDialog != nullptr) {
174 jsWebDialog->DecRefCount();
175 }
176 }
177
178 RefPtr<Result> result_;
179 };
180
181 class JSFullScreenExitHandler : public Referenced {
182 public:
JSBind(BindingTarget globalObj)183 static void JSBind(BindingTarget globalObj)
184 {
185 JSClass<JSFullScreenExitHandler>::Declare("FullScreenExitHandler");
186 JSClass<JSFullScreenExitHandler>::CustomMethod("exitFullScreen", &JSFullScreenExitHandler::ExitFullScreen);
187 JSClass<JSFullScreenExitHandler>::Bind(
188 globalObj, &JSFullScreenExitHandler::Constructor, &JSFullScreenExitHandler::Destructor);
189 }
190
SetHandler(const RefPtr<FullScreenExitHandler> & handler)191 void SetHandler(const RefPtr<FullScreenExitHandler>& handler)
192 {
193 fullScreenExitHandler_ = handler;
194 }
195
ExitFullScreen(const JSCallbackInfo & args)196 void ExitFullScreen(const JSCallbackInfo& args)
197 {
198 if (fullScreenExitHandler_) {
199 fullScreenExitHandler_->ExitFullScreen();
200 }
201 }
202
203 private:
Constructor(const JSCallbackInfo & args)204 static void Constructor(const JSCallbackInfo& args)
205 {
206 auto jsFullScreenExitHandler = Referenced::MakeRefPtr<JSFullScreenExitHandler>();
207 jsFullScreenExitHandler->IncRefCount();
208 args.SetReturnValue(Referenced::RawPtr(jsFullScreenExitHandler));
209 }
210
Destructor(JSFullScreenExitHandler * jsFullScreenExitHandler)211 static void Destructor(JSFullScreenExitHandler* jsFullScreenExitHandler)
212 {
213 if (jsFullScreenExitHandler != nullptr) {
214 jsFullScreenExitHandler->DecRefCount();
215 }
216 }
217 RefPtr<FullScreenExitHandler> fullScreenExitHandler_;
218 };
219
220 class JSWebKeyboardController : public WebTransferBase<RefPtr<WebCustomKeyboardHandler>> {
221 public:
JSBind(BindingTarget globalObj)222 static void JSBind(BindingTarget globalObj)
223 {
224 JSClass<JSWebKeyboardController>::Declare("WebKeyboardController");
225 JSClass<JSWebKeyboardController>::CustomMethod("insertText", &JSWebKeyboardController::InsertText);
226 JSClass<JSWebKeyboardController>::CustomMethod("deleteForward", &JSWebKeyboardController::DeleteForward);
227 JSClass<JSWebKeyboardController>::CustomMethod("deleteBackward", &JSWebKeyboardController::DeleteBackward);
228 JSClass<JSWebKeyboardController>::CustomMethod("sendFunctionKey", &JSWebKeyboardController::SendFunctionKey);
229 JSClass<JSWebKeyboardController>::CustomMethod("close", &JSWebKeyboardController::Close);
230 JSClass<JSWebKeyboardController>::Bind(
231 globalObj, &JSWebKeyboardController::Constructor, &JSWebKeyboardController::Destructor);
232 }
233
SeWebKeyboardController(const RefPtr<WebCustomKeyboardHandler> & controller)234 void SeWebKeyboardController(const RefPtr<WebCustomKeyboardHandler>& controller)
235 {
236 webKeyboardController_ = controller;
237 transferValues_ = std::make_tuple(webKeyboardController_);
238 }
239
InsertText(const JSCallbackInfo & args)240 void InsertText(const JSCallbackInfo& args)
241 {
242 if (!webKeyboardController_) {
243 return;
244 }
245
246 if (args.Length() < 1 || !(args[0]->IsString())) {
247 return;
248 }
249
250 webKeyboardController_->InsertText(args[0]->ToString());
251 }
252
DeleteForward(const JSCallbackInfo & args)253 void DeleteForward(const JSCallbackInfo& args)
254 {
255 if (!webKeyboardController_) {
256 return;
257 }
258
259 if (args.Length() < 1 || !(args[0]->IsNumber())) {
260 return;
261 }
262
263 webKeyboardController_->DeleteForward(args[0]->ToNumber<int32_t>());
264 }
265
DeleteBackward(const JSCallbackInfo & args)266 void DeleteBackward(const JSCallbackInfo& args)
267 {
268 if (!webKeyboardController_) {
269 return;
270 }
271
272 if (args.Length() < 1 || !(args[0]->IsNumber())) {
273 return;
274 }
275
276 webKeyboardController_->DeleteBackward(args[0]->ToNumber<int32_t>());
277 }
278
SendFunctionKey(const JSCallbackInfo & args)279 void SendFunctionKey(const JSCallbackInfo& args)
280 {
281 if (!webKeyboardController_) {
282 return;
283 }
284
285 if (args.Length() < 1 || !(args[0]->IsNumber())) {
286 return;
287 }
288
289 webKeyboardController_->SendFunctionKey(args[0]->ToNumber<int32_t>());
290 }
291
Close(const JSCallbackInfo & args)292 void Close(const JSCallbackInfo& args)
293 {
294 webKeyboardController_->Close();
295 }
296
297 private:
Constructor(const JSCallbackInfo & args)298 static void Constructor(const JSCallbackInfo& args)
299 {
300 auto jSWebKeyboardController = Referenced::MakeRefPtr<JSWebKeyboardController>();
301 jSWebKeyboardController->IncRefCount();
302 args.SetReturnValue(Referenced::RawPtr(jSWebKeyboardController));
303 }
304
Destructor(JSWebKeyboardController * jSWebKeyboardController)305 static void Destructor(JSWebKeyboardController* jSWebKeyboardController)
306 {
307 if (jSWebKeyboardController != nullptr) {
308 jSWebKeyboardController->DecRefCount();
309 }
310 }
311 RefPtr<WebCustomKeyboardHandler> webKeyboardController_;
312 };
313
314 class JSWebHttpAuth : public WebTransferBase<RefPtr<AuthResult>> {
315 public:
JSBind(BindingTarget globalObj)316 static void JSBind(BindingTarget globalObj)
317 {
318 JSClass<JSWebHttpAuth>::Declare("HttpAuthHandler");
319 JSClass<JSWebHttpAuth>::CustomMethod("confirm", &JSWebHttpAuth::Confirm);
320 JSClass<JSWebHttpAuth>::CustomMethod("cancel", &JSWebHttpAuth::Cancel);
321 JSClass<JSWebHttpAuth>::CustomMethod("isHttpAuthInfoSaved", &JSWebHttpAuth::IsHttpAuthInfoSaved);
322 JSClass<JSWebHttpAuth>::Bind(globalObj, &JSWebHttpAuth::Constructor, &JSWebHttpAuth::Destructor);
323 }
324
SetResult(const RefPtr<AuthResult> & result)325 void SetResult(const RefPtr<AuthResult>& result)
326 {
327 result_ = result;
328 transferValues_ = std::make_tuple(result_);
329 }
330
Confirm(const JSCallbackInfo & args)331 void Confirm(const JSCallbackInfo& args)
332 {
333 if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) {
334 auto code = JSVal(ToJSValue(false));
335 auto descriptionRef = JSRef<JSVal>::Make(code);
336 args.SetReturnValue(descriptionRef);
337 return;
338 }
339 std::string userName = args[0]->ToString();
340 std::string password = args[1]->ToString();
341 bool ret = false;
342 if (result_) {
343 result_->Confirm(userName, password);
344 ret = true;
345 }
346 auto code = JSVal(ToJSValue(ret));
347 auto descriptionRef = JSRef<JSVal>::Make(code);
348 args.SetReturnValue(descriptionRef);
349 }
350
Cancel(const JSCallbackInfo & args)351 void Cancel(const JSCallbackInfo& args)
352 {
353 if (result_) {
354 result_->Cancel();
355 }
356 }
357
IsHttpAuthInfoSaved(const JSCallbackInfo & args)358 void IsHttpAuthInfoSaved(const JSCallbackInfo& args)
359 {
360 bool ret = false;
361 if (result_) {
362 ret = result_->IsHttpAuthInfoSaved();
363 }
364 auto code = JSVal(ToJSValue(ret));
365 auto descriptionRef = JSRef<JSVal>::Make(code);
366 args.SetReturnValue(descriptionRef);
367 }
368
369 private:
Constructor(const JSCallbackInfo & args)370 static void Constructor(const JSCallbackInfo& args)
371 {
372 auto jsWebHttpAuth = Referenced::MakeRefPtr<JSWebHttpAuth>();
373 jsWebHttpAuth->IncRefCount();
374 args.SetReturnValue(Referenced::RawPtr(jsWebHttpAuth));
375 }
376
Destructor(JSWebHttpAuth * jsWebHttpAuth)377 static void Destructor(JSWebHttpAuth* jsWebHttpAuth)
378 {
379 if (jsWebHttpAuth != nullptr) {
380 jsWebHttpAuth->DecRefCount();
381 }
382 }
383
384 RefPtr<AuthResult> result_;
385 };
386
387 class JSWebSslError : public WebTransferBase<RefPtr<SslErrorResult>> {
388 public:
JSBind(BindingTarget globalObj)389 static void JSBind(BindingTarget globalObj)
390 {
391 JSClass<JSWebSslError>::Declare("SslErrorHandler");
392 JSClass<JSWebSslError>::CustomMethod("handleConfirm", &JSWebSslError::HandleConfirm);
393 JSClass<JSWebSslError>::CustomMethod("handleCancel", &JSWebSslError::HandleCancel);
394 JSClass<JSWebSslError>::Bind(globalObj, &JSWebSslError::Constructor, &JSWebSslError::Destructor);
395 }
396
SetResult(const RefPtr<SslErrorResult> & result)397 void SetResult(const RefPtr<SslErrorResult>& result)
398 {
399 result_ = result;
400 transferValues_ = std::make_tuple(result_);
401 }
402
HandleConfirm(const JSCallbackInfo & args)403 void HandleConfirm(const JSCallbackInfo& args)
404 {
405 if (result_) {
406 result_->HandleConfirm();
407 }
408 }
409
HandleCancel(const JSCallbackInfo & args)410 void HandleCancel(const JSCallbackInfo& args)
411 {
412 if (result_) {
413 result_->HandleCancel();
414 }
415 }
416
417 private:
Constructor(const JSCallbackInfo & args)418 static void Constructor(const JSCallbackInfo& args)
419 {
420 auto jsWebSslError = Referenced::MakeRefPtr<JSWebSslError>();
421 jsWebSslError->IncRefCount();
422 args.SetReturnValue(Referenced::RawPtr(jsWebSslError));
423 }
424
Destructor(JSWebSslError * jsWebSslError)425 static void Destructor(JSWebSslError* jsWebSslError)
426 {
427 if (jsWebSslError != nullptr) {
428 jsWebSslError->DecRefCount();
429 }
430 }
431
432 RefPtr<SslErrorResult> result_;
433 };
434
435 class JSWebAllSslError : public Referenced {
436 public:
JSBind(BindingTarget globalObj)437 static void JSBind(BindingTarget globalObj)
438 {
439 JSClass<JSWebAllSslError>::Declare("WebAllSslErrorResult");
440 JSClass<JSWebAllSslError>::CustomMethod("handleConfirm", &JSWebAllSslError::HandleConfirm);
441 JSClass<JSWebAllSslError>::CustomMethod("handleCancel", &JSWebAllSslError::HandleCancel);
442 JSClass<JSWebAllSslError>::Bind(globalObj, &JSWebAllSslError::Constructor, &JSWebAllSslError::Destructor);
443 }
444
SetResult(const RefPtr<AllSslErrorResult> & result)445 void SetResult(const RefPtr<AllSslErrorResult>& result)
446 {
447 result_ = result;
448 }
449
HandleConfirm(const JSCallbackInfo & args)450 void HandleConfirm(const JSCallbackInfo& args)
451 {
452 if (result_) {
453 result_->HandleConfirm();
454 }
455 }
456
HandleCancel(const JSCallbackInfo & args)457 void HandleCancel(const JSCallbackInfo& args)
458 {
459 bool abortLoading = false;
460 if (args.Length() >= 1 && args[0]->IsBoolean()) {
461 abortLoading = args[0]->ToBoolean();
462 }
463 if (result_) {
464 result_->HandleCancel(abortLoading);
465 }
466 }
467
468 private:
Constructor(const JSCallbackInfo & args)469 static void Constructor(const JSCallbackInfo& args)
470 {
471 auto jsWebAllSslError = Referenced::MakeRefPtr<JSWebAllSslError>();
472 jsWebAllSslError->IncRefCount();
473 args.SetReturnValue(Referenced::RawPtr(jsWebAllSslError));
474 }
475
Destructor(JSWebAllSslError * jsWebAllSslError)476 static void Destructor(JSWebAllSslError* jsWebAllSslError)
477 {
478 if (jsWebAllSslError != nullptr) {
479 jsWebAllSslError->DecRefCount();
480 }
481 }
482
483 RefPtr<AllSslErrorResult> result_;
484 };
485
486 class JSWebSslSelectCert : public WebTransferBase<RefPtr<SslSelectCertResult>> {
487 public:
JSBind(BindingTarget globalObj)488 static void JSBind(BindingTarget globalObj)
489 {
490 JSClass<JSWebSslSelectCert>::Declare("ClientAuthenticationHandler");
491 JSClass<JSWebSslSelectCert>::CustomMethod("confirm", &JSWebSslSelectCert::HandleConfirm);
492 JSClass<JSWebSslSelectCert>::CustomMethod("cancel", &JSWebSslSelectCert::HandleCancel);
493 JSClass<JSWebSslSelectCert>::CustomMethod("ignore", &JSWebSslSelectCert::HandleIgnore);
494 JSClass<JSWebSslSelectCert>::Bind(globalObj, &JSWebSslSelectCert::Constructor, &JSWebSslSelectCert::Destructor);
495 }
496
SetResult(const RefPtr<SslSelectCertResult> & result)497 void SetResult(const RefPtr<SslSelectCertResult>& result)
498 {
499 result_ = result;
500 transferValues_ = std::make_tuple(result_);
501 }
502
HandleConfirm(const JSCallbackInfo & args)503 void HandleConfirm(const JSCallbackInfo& args)
504 {
505 std::string privateKeyFile;
506 std::string certChainFile;
507 if (args.Length() == 1 && args[0]->IsString()) {
508 privateKeyFile = args[0]->ToString();
509 } else if (args.Length() == 2 && args[0]->IsString() && args[1]->IsString()) {
510 privateKeyFile = args[0]->ToString();
511 certChainFile = args[1]->ToString();
512 } else {
513 return;
514 }
515
516 if (result_) {
517 result_->HandleConfirm(privateKeyFile, certChainFile);
518 }
519 }
520
HandleCancel(const JSCallbackInfo & args)521 void HandleCancel(const JSCallbackInfo& args)
522 {
523 if (result_) {
524 result_->HandleCancel();
525 }
526 }
527
HandleIgnore(const JSCallbackInfo & args)528 void HandleIgnore(const JSCallbackInfo& args)
529 {
530 if (result_) {
531 result_->HandleIgnore();
532 }
533 }
534
535 private:
Constructor(const JSCallbackInfo & args)536 static void Constructor(const JSCallbackInfo& args)
537 {
538 auto jsWebSslSelectCert = Referenced::MakeRefPtr<JSWebSslSelectCert>();
539 jsWebSslSelectCert->IncRefCount();
540 args.SetReturnValue(Referenced::RawPtr(jsWebSslSelectCert));
541 }
542
Destructor(JSWebSslSelectCert * jsWebSslSelectCert)543 static void Destructor(JSWebSslSelectCert* jsWebSslSelectCert)
544 {
545 if (jsWebSslSelectCert != nullptr) {
546 jsWebSslSelectCert->DecRefCount();
547 }
548 }
549
550 RefPtr<SslSelectCertResult> result_;
551 };
552
553 class JSWebConsoleLog : public WebTransferBase<RefPtr<WebConsoleLog>> {
554 public:
JSBind(BindingTarget globalObj)555 static void JSBind(BindingTarget globalObj)
556 {
557 JSClass<JSWebConsoleLog>::Declare("ConsoleMessage");
558 JSClass<JSWebConsoleLog>::CustomMethod("getLineNumber", &JSWebConsoleLog::GetLineNumber);
559 JSClass<JSWebConsoleLog>::CustomMethod("getMessage", &JSWebConsoleLog::GetLog);
560 JSClass<JSWebConsoleLog>::CustomMethod("getMessageLevel", &JSWebConsoleLog::GetLogLevel);
561 JSClass<JSWebConsoleLog>::CustomMethod("getSourceId", &JSWebConsoleLog::GetSourceId);
562 JSClass<JSWebConsoleLog>::Bind(globalObj, &JSWebConsoleLog::Constructor, &JSWebConsoleLog::Destructor);
563 }
564
SetMessage(const RefPtr<WebConsoleLog> & message)565 void SetMessage(const RefPtr<WebConsoleLog>& message)
566 {
567 message_ = message;
568 transferValues_ = std::make_tuple(message_);
569 }
570
GetLineNumber(const JSCallbackInfo & args)571 void GetLineNumber(const JSCallbackInfo& args)
572 {
573 auto code = JSVal(ToJSValue(message_->GetLineNumber()));
574 auto descriptionRef = JSRef<JSVal>::Make(code);
575 args.SetReturnValue(descriptionRef);
576 }
577
GetLog(const JSCallbackInfo & args)578 void GetLog(const JSCallbackInfo& args)
579 {
580 auto code = JSVal(ToJSValue(message_->GetLog()));
581 auto descriptionRef = JSRef<JSVal>::Make(code);
582 args.SetReturnValue(descriptionRef);
583 }
584
GetLogLevel(const JSCallbackInfo & args)585 void GetLogLevel(const JSCallbackInfo& args)
586 {
587 auto code = JSVal(ToJSValue(message_->GetLogLevel()));
588 auto descriptionRef = JSRef<JSVal>::Make(code);
589 args.SetReturnValue(descriptionRef);
590 }
591
GetSourceId(const JSCallbackInfo & args)592 void GetSourceId(const JSCallbackInfo& args)
593 {
594 auto code = JSVal(ToJSValue(message_->GetSourceId()));
595 auto descriptionRef = JSRef<JSVal>::Make(code);
596 args.SetReturnValue(descriptionRef);
597 }
598
599 private:
Constructor(const JSCallbackInfo & args)600 static void Constructor(const JSCallbackInfo& args)
601 {
602 auto jsWebConsoleLog = Referenced::MakeRefPtr<JSWebConsoleLog>();
603 jsWebConsoleLog->IncRefCount();
604 args.SetReturnValue(Referenced::RawPtr(jsWebConsoleLog));
605 }
606
Destructor(JSWebConsoleLog * jsWebConsoleLog)607 static void Destructor(JSWebConsoleLog* jsWebConsoleLog)
608 {
609 if (jsWebConsoleLog != nullptr) {
610 jsWebConsoleLog->DecRefCount();
611 }
612 }
613
614 RefPtr<WebConsoleLog> message_;
615 };
616
617 class JSWebGeolocation : public WebTransferBase<RefPtr<WebGeolocation>> {
618 public:
JSBind(BindingTarget globalObj)619 static void JSBind(BindingTarget globalObj)
620 {
621 JSClass<JSWebGeolocation>::Declare("WebGeolocation");
622 JSClass<JSWebGeolocation>::CustomMethod("invoke", &JSWebGeolocation::Invoke);
623 JSClass<JSWebGeolocation>::Bind(globalObj, &JSWebGeolocation::Constructor, &JSWebGeolocation::Destructor);
624 }
625
SetEvent(const LoadWebGeolocationShowEvent & eventInfo)626 void SetEvent(const LoadWebGeolocationShowEvent& eventInfo)
627 {
628 webGeolocation_ = eventInfo.GetWebGeolocation();
629 transferValues_ = std::make_tuple(webGeolocation_);
630 }
631
Invoke(const JSCallbackInfo & args)632 void Invoke(const JSCallbackInfo& args)
633 {
634 std::string origin;
635 bool allow = false;
636 bool retain = false;
637 if (args[0]->IsString()) {
638 origin = args[0]->ToString();
639 }
640 if (args[1]->IsBoolean()) {
641 allow = args[1]->ToBoolean();
642 }
643 if (args[2]->IsBoolean()) {
644 retain = args[2]->ToBoolean();
645 }
646 if (webGeolocation_) {
647 webGeolocation_->Invoke(origin, allow, retain);
648 }
649 }
650
651 private:
Constructor(const JSCallbackInfo & args)652 static void Constructor(const JSCallbackInfo& args)
653 {
654 auto jsWebGeolocation = Referenced::MakeRefPtr<JSWebGeolocation>();
655 jsWebGeolocation->IncRefCount();
656 args.SetReturnValue(Referenced::RawPtr(jsWebGeolocation));
657 }
658
Destructor(JSWebGeolocation * jsWebGeolocation)659 static void Destructor(JSWebGeolocation* jsWebGeolocation)
660 {
661 if (jsWebGeolocation != nullptr) {
662 jsWebGeolocation->DecRefCount();
663 }
664 }
665
666 RefPtr<WebGeolocation> webGeolocation_;
667 };
668
669 class JSWebPermissionRequest : public WebTransferBase<RefPtr<WebPermissionRequest>> {
670 public:
JSBind(BindingTarget globalObj)671 static void JSBind(BindingTarget globalObj)
672 {
673 JSClass<JSWebPermissionRequest>::Declare("WebPermissionRequest");
674 JSClass<JSWebPermissionRequest>::CustomMethod("deny", &JSWebPermissionRequest::Deny);
675 JSClass<JSWebPermissionRequest>::CustomMethod("getOrigin", &JSWebPermissionRequest::GetOrigin);
676 JSClass<JSWebPermissionRequest>::CustomMethod("getAccessibleResource", &JSWebPermissionRequest::GetResources);
677 JSClass<JSWebPermissionRequest>::CustomMethod("grant", &JSWebPermissionRequest::Grant);
678 JSClass<JSWebPermissionRequest>::Bind(
679 globalObj, &JSWebPermissionRequest::Constructor, &JSWebPermissionRequest::Destructor);
680 }
681
SetEvent(const WebPermissionRequestEvent & eventInfo)682 void SetEvent(const WebPermissionRequestEvent& eventInfo)
683 {
684 webPermissionRequest_ = eventInfo.GetWebPermissionRequest();
685 transferValues_ = std::make_tuple(webPermissionRequest_);
686 }
687
Deny(const JSCallbackInfo & args)688 void Deny(const JSCallbackInfo& args)
689 {
690 if (webPermissionRequest_) {
691 webPermissionRequest_->Deny();
692 }
693 }
694
GetOrigin(const JSCallbackInfo & args)695 void GetOrigin(const JSCallbackInfo& args)
696 {
697 std::string origin;
698 if (webPermissionRequest_) {
699 origin = webPermissionRequest_->GetOrigin();
700 }
701 auto originJs = JSVal(ToJSValue(origin));
702 auto originJsRef = JSRef<JSVal>::Make(originJs);
703 args.SetReturnValue(originJsRef);
704 }
705
GetResources(const JSCallbackInfo & args)706 void GetResources(const JSCallbackInfo& args)
707 {
708 JSRef<JSArray> result = JSRef<JSArray>::New();
709 if (webPermissionRequest_) {
710 std::vector<std::string> resources = webPermissionRequest_->GetResources();
711 uint32_t index = 0;
712 for (auto iterator = resources.begin(); iterator != resources.end(); ++iterator) {
713 auto valueStr = JSVal(ToJSValue(*iterator));
714 auto value = JSRef<JSVal>::Make(valueStr);
715 result->SetValueAt(index++, value);
716 }
717 }
718 args.SetReturnValue(result);
719 }
720
Grant(const JSCallbackInfo & args)721 void Grant(const JSCallbackInfo& args)
722 {
723 if (args.Length() < 1) {
724 if (webPermissionRequest_) {
725 webPermissionRequest_->Deny();
726 }
727 }
728 std::vector<std::string> resources;
729 if (args[0]->IsArray()) {
730 JSRef<JSArray> array = JSRef<JSArray>::Cast(args[0]);
731 for (size_t i = 0; i < array->Length(); i++) {
732 JSRef<JSVal> val = array->GetValueAt(i);
733 if (!val->IsString()) {
734 continue;
735 }
736 std::string res;
737 if (!ConvertFromJSValue(val, res)) {
738 continue;
739 }
740 resources.push_back(res);
741 }
742 }
743
744 if (webPermissionRequest_) {
745 webPermissionRequest_->Grant(resources);
746 }
747 }
748
749 private:
Constructor(const JSCallbackInfo & args)750 static void Constructor(const JSCallbackInfo& args)
751 {
752 auto jsWebPermissionRequest = Referenced::MakeRefPtr<JSWebPermissionRequest>();
753 jsWebPermissionRequest->IncRefCount();
754 args.SetReturnValue(Referenced::RawPtr(jsWebPermissionRequest));
755 }
756
Destructor(JSWebPermissionRequest * jsWebPermissionRequest)757 static void Destructor(JSWebPermissionRequest* jsWebPermissionRequest)
758 {
759 if (jsWebPermissionRequest != nullptr) {
760 jsWebPermissionRequest->DecRefCount();
761 }
762 }
763
764 RefPtr<WebPermissionRequest> webPermissionRequest_;
765 };
766
767 class JSScreenCaptureRequest : public WebTransferBase<RefPtr<WebScreenCaptureRequest>> {
768 public:
JSBind(BindingTarget globalObj)769 static void JSBind(BindingTarget globalObj)
770 {
771 JSClass<JSScreenCaptureRequest>::Declare("ScreenCaptureRequest");
772 JSClass<JSScreenCaptureRequest>::CustomMethod("deny", &JSScreenCaptureRequest::Deny);
773 JSClass<JSScreenCaptureRequest>::CustomMethod("getOrigin", &JSScreenCaptureRequest::GetOrigin);
774 JSClass<JSScreenCaptureRequest>::CustomMethod("grant", &JSScreenCaptureRequest::Grant);
775 JSClass<JSScreenCaptureRequest>::Bind(
776 globalObj, &JSScreenCaptureRequest::Constructor, &JSScreenCaptureRequest::Destructor);
777 }
778
SetEvent(const WebScreenCaptureRequestEvent & eventInfo)779 void SetEvent(const WebScreenCaptureRequestEvent& eventInfo)
780 {
781 request_ = eventInfo.GetWebScreenCaptureRequest();
782 transferValues_ = std::make_tuple(request_);
783 }
784
Deny(const JSCallbackInfo & args)785 void Deny(const JSCallbackInfo& args)
786 {
787 if (request_) {
788 request_->Deny();
789 }
790 }
791
GetOrigin(const JSCallbackInfo & args)792 void GetOrigin(const JSCallbackInfo& args)
793 {
794 std::string origin;
795 if (request_) {
796 origin = request_->GetOrigin();
797 }
798 auto originJs = JSVal(ToJSValue(origin));
799 auto originJsRef = JSRef<JSVal>::Make(originJs);
800 args.SetReturnValue(originJsRef);
801 }
802
Grant(const JSCallbackInfo & args)803 void Grant(const JSCallbackInfo& args)
804 {
805 if (!request_) {
806 return;
807 }
808 if (args.Length() < 1 || !args[0]->IsObject()) {
809 request_->Deny();
810 return;
811 }
812 JSRef<JSObject> paramObject = JSRef<JSObject>::Cast(args[0]);
813 auto captureModeObj = paramObject->GetProperty("captureMode");
814 if (!captureModeObj->IsNumber()) {
815 request_->Deny();
816 return;
817 }
818 int32_t captureMode = captureModeObj->ToNumber<int32_t>();
819 request_->SetCaptureMode(captureMode);
820 request_->SetSourceId(-1);
821 request_->Grant();
822 }
823
824 private:
Constructor(const JSCallbackInfo & args)825 static void Constructor(const JSCallbackInfo& args)
826 {
827 auto jsScreenCaptureRequest = Referenced::MakeRefPtr<JSScreenCaptureRequest>();
828 jsScreenCaptureRequest->IncRefCount();
829 args.SetReturnValue(Referenced::RawPtr(jsScreenCaptureRequest));
830 }
831
Destructor(JSScreenCaptureRequest * jsScreenCaptureRequest)832 static void Destructor(JSScreenCaptureRequest* jsScreenCaptureRequest)
833 {
834 if (jsScreenCaptureRequest != nullptr) {
835 jsScreenCaptureRequest->DecRefCount();
836 }
837 }
838
839 RefPtr<WebScreenCaptureRequest> request_;
840 };
841
842 class JSNativeEmbedGestureRequest : public WebTransferBase<RefPtr<GestureEventResult>> {
843 public:
JSBind(BindingTarget globalObj)844 static void JSBind(BindingTarget globalObj)
845 {
846 JSClass<JSNativeEmbedGestureRequest>::Declare("NativeEmbedGesture");
847 JSClass<JSNativeEmbedGestureRequest>::CustomMethod(
848 "setGestureEventResult", &JSNativeEmbedGestureRequest::SetGestureEventResult);
849 JSClass<JSNativeEmbedGestureRequest>::Bind(
850 globalObj, &JSNativeEmbedGestureRequest::Constructor, &JSNativeEmbedGestureRequest::Destructor);
851 }
852
SetResult(const RefPtr<GestureEventResult> & result)853 void SetResult(const RefPtr<GestureEventResult>& result)
854 {
855 eventResult_ = result;
856 transferValues_ = std::make_tuple(eventResult_);
857 }
858
SetGestureEventResult(const JSCallbackInfo & args)859 void SetGestureEventResult(const JSCallbackInfo& args)
860 {
861 if (eventResult_) {
862 bool result = true;
863 bool stopPropagation = true;
864 if (args.Length() == PARAM_ONE && args[PARAM_ZERO]->IsBoolean()) {
865 result = args[PARAM_ZERO]->ToBoolean();
866 eventResult_->SetGestureEventResult(result);
867 } else if (args.Length() == PARAM_TWO && args[PARAM_ZERO]->IsBoolean() && args[PARAM_ONE]->IsBoolean()) {
868 result = args[PARAM_ZERO]->ToBoolean();
869 stopPropagation = args[PARAM_ONE]->ToBoolean();
870 eventResult_->SetGestureEventResult(result, stopPropagation);
871 }
872 }
873 }
874
875 private:
Constructor(const JSCallbackInfo & args)876 static void Constructor(const JSCallbackInfo& args)
877 {
878 auto jSNativeEmbedGestureRequest = Referenced::MakeRefPtr<JSNativeEmbedGestureRequest>();
879 jSNativeEmbedGestureRequest->IncRefCount();
880 args.SetReturnValue(Referenced::RawPtr(jSNativeEmbedGestureRequest));
881 }
882
Destructor(JSNativeEmbedGestureRequest * jSNativeEmbedGestureRequest)883 static void Destructor(JSNativeEmbedGestureRequest* jSNativeEmbedGestureRequest)
884 {
885 if (jSNativeEmbedGestureRequest != nullptr) {
886 jSNativeEmbedGestureRequest->DecRefCount();
887 }
888 }
889
890 RefPtr<GestureEventResult> eventResult_;
891 };
892
893 class JSNativeEmbedMouseRequest : public Referenced {
894 public:
JSBind(BindingTarget globalObj)895 static void JSBind(BindingTarget globalObj)
896 {
897 JSClass<JSNativeEmbedMouseRequest>::Declare("NativeEmbedMouse");
898 JSClass<JSNativeEmbedMouseRequest>::CustomMethod(
899 "setMouseEventResult", &JSNativeEmbedMouseRequest::SetMouseEventResult);
900 JSClass<JSNativeEmbedMouseRequest>::Bind(
901 globalObj, &JSNativeEmbedMouseRequest::Constructor, &JSNativeEmbedMouseRequest::Destructor);
902 }
903
SetResult(const RefPtr<MouseEventResult> & result)904 void SetResult(const RefPtr<MouseEventResult>& result)
905 {
906 eventResult_ = result;
907 }
908
SetMouseEventResult(const JSCallbackInfo & args)909 void SetMouseEventResult(const JSCallbackInfo& args)
910 {
911 RETURN_IF_CALLING_FROM_M114();
912 if (eventResult_) {
913 bool result = true;
914 bool stopPropagation = true;
915 if (args.Length() == PARAM_ONE && args[PARAM_ZERO]->IsBoolean()) {
916 result = args[PARAM_ZERO]->ToBoolean();
917 } else if (args.Length() == PARAM_TWO && args[PARAM_ZERO]->IsBoolean() && args[PARAM_ONE]->IsBoolean()) {
918 result = args[PARAM_ZERO]->ToBoolean();
919 stopPropagation = args[PARAM_ONE]->ToBoolean();
920 }
921 eventResult_->SetMouseEventResult(result, stopPropagation);
922 }
923 }
924
925 private:
Constructor(const JSCallbackInfo & args)926 static void Constructor(const JSCallbackInfo& args)
927 {
928 auto jSNativeEmbedMouseRequest = Referenced::MakeRefPtr<JSNativeEmbedMouseRequest>();
929 jSNativeEmbedMouseRequest->IncRefCount();
930 args.SetReturnValue(Referenced::RawPtr(jSNativeEmbedMouseRequest));
931 }
932
Destructor(JSNativeEmbedMouseRequest * jSNativeEmbedMouseRequest)933 static void Destructor(JSNativeEmbedMouseRequest* jSNativeEmbedMouseRequest)
934 {
935 if (jSNativeEmbedMouseRequest != nullptr) {
936 jSNativeEmbedMouseRequest->DecRefCount();
937 }
938 }
939
940 RefPtr<MouseEventResult> eventResult_;
941 };
942
943 class JSWebWindowNewHandler : public WebTransferBase<RefPtr<WebWindowNewHandler>> {
944 public:
945 struct ChildWindowInfo {
946 int32_t parentWebId_ = -1;
947 JSRef<JSObject> controller_;
948 };
949
JSBind(BindingTarget globalObj)950 static void JSBind(BindingTarget globalObj)
951 {
952 JSClass<JSWebWindowNewHandler>::Declare("WebWindowNewHandler");
953 JSClass<JSWebWindowNewHandler>::CustomMethod("setWebController", &JSWebWindowNewHandler::SetWebController);
954 JSClass<JSWebWindowNewHandler>::Bind(
955 globalObj, &JSWebWindowNewHandler::Constructor, &JSWebWindowNewHandler::Destructor);
956 }
957
SetEvent(const WebWindowNewEvent & eventInfo)958 void SetEvent(const WebWindowNewEvent& eventInfo)
959 {
960 handler_ = eventInfo.GetWebWindowNewHandler();
961 transferValues_ = std::make_tuple(handler_);
962 }
963
PopController(int32_t id,int32_t * parentId=nullptr)964 static JSRef<JSObject> PopController(int32_t id, int32_t* parentId = nullptr)
965 {
966 auto iter = controller_map_.find(id);
967 if (iter == controller_map_.end()) {
968 return JSRef<JSVal>::Make();
969 }
970 auto controller = iter->second.controller_;
971 if (parentId) {
972 *parentId = iter->second.parentWebId_;
973 }
974 controller_map_.erase(iter);
975 return controller;
976 }
977
ExistController(JSRef<JSObject> & controller,int32_t & parentWebId)978 static bool ExistController(JSRef<JSObject>& controller, int32_t& parentWebId)
979 {
980 auto getThisVarFunction = controller->GetProperty("innerGetThisVar");
981 if (!getThisVarFunction->IsFunction()) {
982 parentWebId = -1;
983 return false;
984 }
985 auto func = JSRef<JSFunc>::Cast(getThisVarFunction);
986 auto thisVar = func->Call(controller, 0, {});
987 int64_t thisPtr = thisVar->ToNumber<int64_t>();
988 for (auto iter = controller_map_.begin(); iter != controller_map_.end(); iter++) {
989 auto getThisVarFunction1 = iter->second.controller_->GetProperty("innerGetThisVar");
990 if (getThisVarFunction1->IsFunction()) {
991 auto func1 = JSRef<JSFunc>::Cast(getThisVarFunction1);
992 auto thisVar1 = func1->Call(iter->second.controller_, 0, {});
993 if (thisPtr == thisVar1->ToNumber<int64_t>()) {
994 parentWebId = iter->second.parentWebId_;
995 return true;
996 }
997 }
998 }
999 parentWebId = -1;
1000 return false;
1001 }
1002
SetWebController(const JSCallbackInfo & args)1003 void SetWebController(const JSCallbackInfo& args)
1004 {
1005 if (handler_) {
1006 int32_t parentNWebId = handler_->GetParentNWebId();
1007 if (parentNWebId == -1) {
1008 TAG_LOGE(AceLogTag::ACE_WEB, "SetWebController parent's web isn't inited");
1009 return;
1010 }
1011 if (args.Length() < 1 || !args[0]->IsObject()) {
1012 WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false);
1013 return;
1014 }
1015 auto controller = JSRef<JSObject>::Cast(args[0]);
1016 if (controller.IsEmpty()) {
1017 WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false);
1018 return;
1019 }
1020 auto getWebIdFunction = controller->GetProperty("innerGetWebId");
1021 if (!getWebIdFunction->IsFunction()) {
1022 WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false);
1023 return;
1024 }
1025 auto func = JSRef<JSFunc>::Cast(getWebIdFunction);
1026 auto webId = func->Call(controller, 0, {});
1027 int32_t childWebId = webId->ToNumber<int32_t>();
1028 if (childWebId == parentNWebId || childWebId != -1) {
1029 WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false);
1030 return;
1031 }
1032 controller_map_.insert(
1033 std::pair<int32_t, ChildWindowInfo>(handler_->GetId(), { parentNWebId, controller }));
1034 } else {
1035 TAG_LOGE(AceLogTag::ACE_WEB, "SetWebController handler is empty");
1036 }
1037 }
1038
1039 private:
Constructor(const JSCallbackInfo & args)1040 static void Constructor(const JSCallbackInfo& args)
1041 {
1042 auto jsWebWindowNewHandler = Referenced::MakeRefPtr<JSWebWindowNewHandler>();
1043 jsWebWindowNewHandler->IncRefCount();
1044 args.SetReturnValue(Referenced::RawPtr(jsWebWindowNewHandler));
1045 }
1046
Destructor(JSWebWindowNewHandler * jsWebWindowNewHandler)1047 static void Destructor(JSWebWindowNewHandler* jsWebWindowNewHandler)
1048 {
1049 if (jsWebWindowNewHandler != nullptr) {
1050 jsWebWindowNewHandler->DecRefCount();
1051 }
1052 }
1053
1054 RefPtr<WebWindowNewHandler> handler_;
1055 static std::unordered_map<int32_t, ChildWindowInfo> controller_map_;
1056 };
1057 std::unordered_map<int32_t, JSWebWindowNewHandler::ChildWindowInfo> JSWebWindowNewHandler::controller_map_;
1058
1059 class JSDataResubmitted : public WebTransferBase<RefPtr<DataResubmitted>> {
1060 public:
JSBind(BindingTarget globalObj)1061 static void JSBind(BindingTarget globalObj)
1062 {
1063 JSClass<JSDataResubmitted>::Declare("DataResubmissionHandler");
1064 JSClass<JSDataResubmitted>::CustomMethod("resend", &JSDataResubmitted::Resend);
1065 JSClass<JSDataResubmitted>::CustomMethod("cancel", &JSDataResubmitted::Cancel);
1066 JSClass<JSDataResubmitted>::Bind(globalObj, &JSDataResubmitted::Constructor, &JSDataResubmitted::Destructor);
1067 }
1068
SetHandler(const RefPtr<DataResubmitted> & handler)1069 void SetHandler(const RefPtr<DataResubmitted>& handler)
1070 {
1071 dataResubmitted_ = handler;
1072 transferValues_ = std::make_tuple(dataResubmitted_);
1073 }
1074
Resend(const JSCallbackInfo & args)1075 void Resend(const JSCallbackInfo& args)
1076 {
1077 if (dataResubmitted_) {
1078 dataResubmitted_->Resend();
1079 }
1080 }
1081
Cancel(const JSCallbackInfo & args)1082 void Cancel(const JSCallbackInfo& args)
1083 {
1084 if (dataResubmitted_) {
1085 dataResubmitted_->Cancel();
1086 }
1087 }
1088
1089 private:
Constructor(const JSCallbackInfo & args)1090 static void Constructor(const JSCallbackInfo& args)
1091 {
1092 auto jsDataResubmitted = Referenced::MakeRefPtr<JSDataResubmitted>();
1093 jsDataResubmitted->IncRefCount();
1094 args.SetReturnValue(Referenced::RawPtr(jsDataResubmitted));
1095 }
1096
Destructor(JSDataResubmitted * jsDataResubmitted)1097 static void Destructor(JSDataResubmitted* jsDataResubmitted)
1098 {
1099 if (jsDataResubmitted != nullptr) {
1100 jsDataResubmitted->DecRefCount();
1101 }
1102 }
1103 RefPtr<DataResubmitted> dataResubmitted_;
1104 };
1105
1106 class JSWebResourceError : public Referenced {
1107 public:
JSBind(BindingTarget globalObj)1108 static void JSBind(BindingTarget globalObj)
1109 {
1110 JSClass<JSWebResourceError>::Declare("WebResourceError");
1111 JSClass<JSWebResourceError>::CustomMethod("getErrorCode", &JSWebResourceError::GetErrorCode);
1112 JSClass<JSWebResourceError>::CustomMethod("getErrorInfo", &JSWebResourceError::GetErrorInfo);
1113 JSClass<JSWebResourceError>::Bind(globalObj, &JSWebResourceError::Constructor, &JSWebResourceError::Destructor);
1114 }
1115
SetEvent(const ReceivedErrorEvent & eventInfo)1116 void SetEvent(const ReceivedErrorEvent& eventInfo)
1117 {
1118 error_ = eventInfo.GetError();
1119 }
1120
SetOverrideErrorPageEvent(const OnOverrideErrorPageEvent & eventInfo)1121 void SetOverrideErrorPageEvent(const OnOverrideErrorPageEvent& eventInfo)
1122 {
1123 error_ = eventInfo.GetError();
1124 }
1125
GetErrorCode(const JSCallbackInfo & args)1126 void GetErrorCode(const JSCallbackInfo& args)
1127 {
1128 auto code = JSVal(ToJSValue(error_->GetCode()));
1129 auto descriptionRef = JSRef<JSVal>::Make(code);
1130 args.SetReturnValue(descriptionRef);
1131 }
1132
GetErrorInfo(const JSCallbackInfo & args)1133 void GetErrorInfo(const JSCallbackInfo& args)
1134 {
1135 auto info = JSVal(ToJSValue(error_->GetInfo()));
1136 auto descriptionRef = JSRef<JSVal>::Make(info);
1137 args.SetReturnValue(descriptionRef);
1138 }
1139
1140 private:
Constructor(const JSCallbackInfo & args)1141 static void Constructor(const JSCallbackInfo& args)
1142 {
1143 auto jSWebResourceError = Referenced::MakeRefPtr<JSWebResourceError>();
1144 jSWebResourceError->IncRefCount();
1145 args.SetReturnValue(Referenced::RawPtr(jSWebResourceError));
1146 }
1147
Destructor(JSWebResourceError * jSWebResourceError)1148 static void Destructor(JSWebResourceError* jSWebResourceError)
1149 {
1150 if (jSWebResourceError != nullptr) {
1151 jSWebResourceError->DecRefCount();
1152 }
1153 }
1154
1155 RefPtr<WebError> error_;
1156 };
1157
1158 class JSWebResourceResponse : public WebTransferBase<RefPtr<WebResponse>> {
1159 public:
JSBind(BindingTarget globalObj)1160 static void JSBind(BindingTarget globalObj)
1161 {
1162 JSClass<JSWebResourceResponse>::Declare("WebResourceResponse");
1163 JSClass<JSWebResourceResponse>::CustomMethod("getResponseData", &JSWebResourceResponse::GetResponseData);
1164 JSClass<JSWebResourceResponse>::CustomMethod("getResponseDataEx", &JSWebResourceResponse::GetResponseDataEx);
1165 JSClass<JSWebResourceResponse>::CustomMethod(
1166 "getResponseEncoding", &JSWebResourceResponse::GetResponseEncoding);
1167 JSClass<JSWebResourceResponse>::CustomMethod(
1168 "getResponseMimeType", &JSWebResourceResponse::GetResponseMimeType);
1169 JSClass<JSWebResourceResponse>::CustomMethod("getReasonMessage", &JSWebResourceResponse::GetReasonMessage);
1170 JSClass<JSWebResourceResponse>::CustomMethod("getResponseCode", &JSWebResourceResponse::GetResponseCode);
1171 JSClass<JSWebResourceResponse>::CustomMethod("getResponseHeader", &JSWebResourceResponse::GetResponseHeader);
1172 JSClass<JSWebResourceResponse>::CustomMethod("setResponseData", &JSWebResourceResponse::SetResponseData);
1173 JSClass<JSWebResourceResponse>::CustomMethod(
1174 "setResponseEncoding", &JSWebResourceResponse::SetResponseEncoding);
1175 JSClass<JSWebResourceResponse>::CustomMethod(
1176 "setResponseMimeType", &JSWebResourceResponse::SetResponseMimeType);
1177 JSClass<JSWebResourceResponse>::CustomMethod("setReasonMessage", &JSWebResourceResponse::SetReasonMessage);
1178 JSClass<JSWebResourceResponse>::CustomMethod("setResponseCode", &JSWebResourceResponse::SetResponseCode);
1179 JSClass<JSWebResourceResponse>::CustomMethod("setResponseHeader", &JSWebResourceResponse::SetResponseHeader);
1180 JSClass<JSWebResourceResponse>::CustomMethod("setResponseIsReady", &JSWebResourceResponse::SetResponseIsReady);
1181 JSClass<JSWebResourceResponse>::CustomMethod("getResponseIsReady", &JSWebResourceResponse::GetResponseIsReady);
1182 JSClass<JSWebResourceResponse>::Bind(
1183 globalObj, &JSWebResourceResponse::Constructor, &JSWebResourceResponse::Destructor);
1184 }
1185
JSWebResourceResponse()1186 JSWebResourceResponse() : response_(AceType::MakeRefPtr<WebResponse>()) {}
1187
SetEvent(const ReceivedHttpErrorEvent & eventInfo)1188 void SetEvent(const ReceivedHttpErrorEvent& eventInfo)
1189 {
1190 response_ = eventInfo.GetResponse();
1191 transferValues_ = std::make_tuple(response_);
1192 }
1193
GetResponseData(const JSCallbackInfo & args)1194 void GetResponseData(const JSCallbackInfo& args)
1195 {
1196 auto data = JSVal(ToJSValue(response_->GetData()));
1197 auto descriptionRef = JSRef<JSVal>::Make(data);
1198 args.SetReturnValue(descriptionRef);
1199 }
1200
GetResponseDataEx(const JSCallbackInfo & args)1201 void GetResponseDataEx(const JSCallbackInfo& args)
1202 {
1203 args.SetReturnValue(responseData_);
1204 }
1205
GetResponseIsReady(const JSCallbackInfo & args)1206 void GetResponseIsReady(const JSCallbackInfo& args)
1207 {
1208 auto status = JSVal(ToJSValue(response_->GetResponseStatus()));
1209 auto descriptionRef = JSRef<JSVal>::Make(status);
1210 args.SetReturnValue(descriptionRef);
1211 }
1212
GetResponseEncoding(const JSCallbackInfo & args)1213 void GetResponseEncoding(const JSCallbackInfo& args)
1214 {
1215 auto encoding = JSVal(ToJSValue(response_->GetEncoding()));
1216 auto descriptionRef = JSRef<JSVal>::Make(encoding);
1217 args.SetReturnValue(descriptionRef);
1218 }
1219
GetResponseMimeType(const JSCallbackInfo & args)1220 void GetResponseMimeType(const JSCallbackInfo& args)
1221 {
1222 auto mimeType = JSVal(ToJSValue(response_->GetMimeType()));
1223 auto descriptionRef = JSRef<JSVal>::Make(mimeType);
1224 args.SetReturnValue(descriptionRef);
1225 }
1226
GetReasonMessage(const JSCallbackInfo & args)1227 void GetReasonMessage(const JSCallbackInfo& args)
1228 {
1229 auto reason = JSVal(ToJSValue(response_->GetReason()));
1230 auto descriptionRef = JSRef<JSVal>::Make(reason);
1231 args.SetReturnValue(descriptionRef);
1232 }
1233
GetResponseCode(const JSCallbackInfo & args)1234 void GetResponseCode(const JSCallbackInfo& args)
1235 {
1236 auto code = JSVal(ToJSValue(response_->GetStatusCode()));
1237 auto descriptionRef = JSRef<JSVal>::Make(code);
1238 args.SetReturnValue(descriptionRef);
1239 }
1240
GetResponseHeader(const JSCallbackInfo & args)1241 void GetResponseHeader(const JSCallbackInfo& args)
1242 {
1243 auto map = response_->GetHeaders();
1244 std::map<std::string, std::string>::iterator iterator;
1245 uint32_t index = 0;
1246 JSRef<JSArray> headers = JSRef<JSArray>::New();
1247 for (iterator = map.begin(); iterator != map.end(); ++iterator) {
1248 JSRef<JSObject> header = JSRef<JSObject>::New();
1249 header->SetProperty("headerKey", iterator->first);
1250 header->SetProperty("headerValue", iterator->second);
1251 headers->SetValueAt(index++, header);
1252 }
1253 args.SetReturnValue(headers);
1254 }
1255
GetResponseObj() const1256 RefPtr<WebResponse> GetResponseObj() const
1257 {
1258 return response_;
1259 }
1260
SetResponseData(const JSCallbackInfo & args)1261 void SetResponseData(const JSCallbackInfo& args)
1262 {
1263 if (args.Length() <= 0) {
1264 return;
1265 }
1266
1267 responseData_ = args[0];
1268 if (args[0]->IsNumber()) {
1269 auto fd = args[0]->ToNumber<int32_t>();
1270 response_->SetFileHandle(fd);
1271 return;
1272 }
1273 if (args[0]->IsString()) {
1274 auto data = args[0]->ToString();
1275 response_->SetData(data);
1276 return;
1277 }
1278 if (args[0]->IsArrayBuffer()) {
1279 JsiRef<JsiArrayBuffer> arrayBuffer = JsiRef<JsiArrayBuffer>::Cast(args[0]);
1280 int32_t bufferSize = arrayBuffer->ByteLength();
1281 void* buffer = arrayBuffer->GetBuffer();
1282 const char* charPtr = static_cast<const char*>(buffer);
1283 std::string data(charPtr, bufferSize);
1284 response_->SetData(data);
1285 response_->SetBuffer(static_cast<char*>(buffer), bufferSize);
1286 return;
1287 }
1288 if (args[0]->IsObject()) {
1289 std::string resourceUrl;
1290 std::string url;
1291 if (!JSViewAbstract::ParseJsMedia(args[0], resourceUrl)) {
1292 return;
1293 }
1294 auto np = resourceUrl.find_first_of("/");
1295 url = (np == std::string::npos) ? resourceUrl : resourceUrl.erase(np, 1);
1296 response_->SetResourceUrl(url);
1297 return;
1298 }
1299 }
1300
SetResponseEncoding(const JSCallbackInfo & args)1301 void SetResponseEncoding(const JSCallbackInfo& args)
1302 {
1303 if ((args.Length() <= 0) || !(args[0]->IsString())) {
1304 return;
1305 }
1306 auto encode = args[0]->ToString();
1307 response_->SetEncoding(encode);
1308 }
1309
SetResponseMimeType(const JSCallbackInfo & args)1310 void SetResponseMimeType(const JSCallbackInfo& args)
1311 {
1312 if ((args.Length() <= 0) || !(args[0]->IsString())) {
1313 return;
1314 }
1315 auto mineType = args[0]->ToString();
1316 response_->SetMimeType(mineType);
1317 }
1318
SetReasonMessage(const JSCallbackInfo & args)1319 void SetReasonMessage(const JSCallbackInfo& args)
1320 {
1321 if ((args.Length() <= 0) || !(args[0]->IsString())) {
1322 return;
1323 }
1324 auto reason = args[0]->ToString();
1325 response_->SetReason(reason);
1326 }
1327
SetResponseCode(const JSCallbackInfo & args)1328 void SetResponseCode(const JSCallbackInfo& args)
1329 {
1330 if ((args.Length() <= 0) || !(args[0]->IsNumber())) {
1331 return;
1332 }
1333 auto statusCode = args[0]->ToNumber<int32_t>();
1334 if (statusCode == -1) {
1335 TAG_LOGE(AceLogTag::ACE_WEB, "SetResponseCode: arg value is not supported!");
1336 }
1337
1338 response_->SetStatusCode(statusCode);
1339 }
1340
SetResponseHeader(const JSCallbackInfo & args)1341 void SetResponseHeader(const JSCallbackInfo& args)
1342 {
1343 if ((args.Length() <= 0) || !(args[0]->IsArray())) {
1344 return;
1345 }
1346 JSRef<JSArray> array = JSRef<JSArray>::Cast(args[0]);
1347 for (size_t i = 0; i < array->Length(); i++) {
1348 if (!(array->GetValueAt(i)->IsObject())) {
1349 return;
1350 }
1351 auto obj = JSRef<JSObject>::Cast(array->GetValueAt(i));
1352 auto headerKey = obj->GetProperty("headerKey");
1353 auto headerValue = obj->GetProperty("headerValue");
1354 if (!headerKey->IsString() || !headerValue->IsString()) {
1355 return;
1356 }
1357 auto keystr = headerKey->ToString();
1358 auto valstr = headerValue->ToString();
1359 response_->SetHeadersVal(keystr, valstr);
1360 }
1361 }
1362
SetResponseIsReady(const JSCallbackInfo & args)1363 void SetResponseIsReady(const JSCallbackInfo& args)
1364 {
1365 if ((args.Length() <= 0) || !(args[0]->IsBoolean())) {
1366 return;
1367 }
1368 bool isReady = false;
1369 if (!ConvertFromJSValue(args[0], isReady)) {
1370 return;
1371 }
1372 response_->SetResponseStatus(isReady);
1373 }
1374
1375 private:
Constructor(const JSCallbackInfo & args)1376 static void Constructor(const JSCallbackInfo& args)
1377 {
1378 auto jSWebResourceResponse = Referenced::MakeRefPtr<JSWebResourceResponse>();
1379 jSWebResourceResponse->IncRefCount();
1380 args.SetReturnValue(Referenced::RawPtr(jSWebResourceResponse));
1381 }
1382
Destructor(JSWebResourceResponse * jSWebResourceResponse)1383 static void Destructor(JSWebResourceResponse* jSWebResourceResponse)
1384 {
1385 if (jSWebResourceResponse != nullptr) {
1386 jSWebResourceResponse->DecRefCount();
1387 }
1388 }
1389
1390 RefPtr<WebResponse> response_;
1391 JSRef<JSVal> responseData_;
1392 };
1393
1394 class JSWebResourceRequest : public WebTransferBase<RefPtr<WebRequest>> {
1395 public:
JSBind(BindingTarget globalObj)1396 static void JSBind(BindingTarget globalObj)
1397 {
1398 JSClass<JSWebResourceRequest>::Declare("WebResourceRequest");
1399 JSClass<JSWebResourceRequest>::CustomMethod("getRequestUrl", &JSWebResourceRequest::GetRequestUrl);
1400 JSClass<JSWebResourceRequest>::CustomMethod("getRequestHeader", &JSWebResourceRequest::GetRequestHeader);
1401 JSClass<JSWebResourceRequest>::CustomMethod("getRequestMethod", &JSWebResourceRequest::GetRequestMethod);
1402 JSClass<JSWebResourceRequest>::CustomMethod("isRequestGesture", &JSWebResourceRequest::IsRequestGesture);
1403 JSClass<JSWebResourceRequest>::CustomMethod("isMainFrame", &JSWebResourceRequest::IsMainFrame);
1404 JSClass<JSWebResourceRequest>::CustomMethod("isRedirect", &JSWebResourceRequest::IsRedirect);
1405 JSClass<JSWebResourceRequest>::Bind(
1406 globalObj, &JSWebResourceRequest::Constructor, &JSWebResourceRequest::Destructor);
1407 }
1408
SetErrorEvent(const ReceivedErrorEvent & eventInfo)1409 void SetErrorEvent(const ReceivedErrorEvent& eventInfo)
1410 {
1411 request_ = eventInfo.GetRequest();
1412 transferValues_ = std::make_tuple(request_);
1413 }
1414
SetHttpErrorEvent(const ReceivedHttpErrorEvent & eventInfo)1415 void SetHttpErrorEvent(const ReceivedHttpErrorEvent& eventInfo)
1416 {
1417 request_ = eventInfo.GetRequest();
1418 transferValues_ = std::make_tuple(request_);
1419 }
1420
SetOnInterceptRequestEvent(const OnInterceptRequestEvent & eventInfo)1421 void SetOnInterceptRequestEvent(const OnInterceptRequestEvent& eventInfo)
1422 {
1423 request_ = eventInfo.GetRequest();
1424 transferValues_ = std::make_tuple(request_);
1425 }
1426
SetOnOverrideErrorPageEvent(const OnOverrideErrorPageEvent & eventInfo)1427 void SetOnOverrideErrorPageEvent(const OnOverrideErrorPageEvent& eventInfo)
1428 {
1429 request_ = eventInfo.GetWebResourceRequest();
1430 transferValues_ = std::make_tuple(request_);
1431 }
1432
SetLoadInterceptEvent(const LoadInterceptEvent & eventInfo)1433 void SetLoadInterceptEvent(const LoadInterceptEvent& eventInfo)
1434 {
1435 request_ = eventInfo.GetRequest();
1436 transferValues_ = std::make_tuple(request_);
1437 }
1438
IsRedirect(const JSCallbackInfo & args)1439 void IsRedirect(const JSCallbackInfo& args)
1440 {
1441 auto isRedirect = JSVal(ToJSValue(request_->IsRedirect()));
1442 auto descriptionRef = JSRef<JSVal>::Make(isRedirect);
1443 args.SetReturnValue(descriptionRef);
1444 }
1445
GetRequestUrl(const JSCallbackInfo & args)1446 void GetRequestUrl(const JSCallbackInfo& args)
1447 {
1448 auto url = JSVal(ToJSValue(request_->GetUrl()));
1449 auto descriptionRef = JSRef<JSVal>::Make(url);
1450 args.SetReturnValue(descriptionRef);
1451 }
1452
GetRequestMethod(const JSCallbackInfo & args)1453 void GetRequestMethod(const JSCallbackInfo& args)
1454 {
1455 auto method = JSVal(ToJSValue(request_->GetMethod()));
1456 auto descriptionRef = JSRef<JSVal>::Make(method);
1457 args.SetReturnValue(descriptionRef);
1458 }
1459
IsRequestGesture(const JSCallbackInfo & args)1460 void IsRequestGesture(const JSCallbackInfo& args)
1461 {
1462 auto isRequestGesture = JSVal(ToJSValue(request_->HasGesture()));
1463 auto descriptionRef = JSRef<JSVal>::Make(isRequestGesture);
1464 args.SetReturnValue(descriptionRef);
1465 }
1466
IsMainFrame(const JSCallbackInfo & args)1467 void IsMainFrame(const JSCallbackInfo& args)
1468 {
1469 auto isMainFrame = JSVal(ToJSValue(request_->IsMainFrame()));
1470 auto descriptionRef = JSRef<JSVal>::Make(isMainFrame);
1471 args.SetReturnValue(descriptionRef);
1472 }
1473
GetRequestHeader(const JSCallbackInfo & args)1474 void GetRequestHeader(const JSCallbackInfo& args)
1475 {
1476 auto map = request_->GetHeaders();
1477 std::map<std::string, std::string>::iterator iterator;
1478 uint32_t index = 0;
1479 JSRef<JSArray> headers = JSRef<JSArray>::New();
1480 for (iterator = map.begin(); iterator != map.end(); ++iterator) {
1481 JSRef<JSObject> header = JSRef<JSObject>::New();
1482 header->SetProperty("headerKey", iterator->first);
1483 header->SetProperty("headerValue", iterator->second);
1484 headers->SetValueAt(index++, header);
1485 }
1486 args.SetReturnValue(headers);
1487 }
1488
SetLoadOverrideEvent(const LoadOverrideEvent & eventInfo)1489 void SetLoadOverrideEvent(const LoadOverrideEvent& eventInfo)
1490 {
1491 request_ = eventInfo.GetRequest();
1492 transferValues_ = std::make_tuple(request_);
1493 }
1494
1495 private:
Constructor(const JSCallbackInfo & args)1496 static void Constructor(const JSCallbackInfo& args)
1497 {
1498 auto jSWebResourceRequest = Referenced::MakeRefPtr<JSWebResourceRequest>();
1499 jSWebResourceRequest->IncRefCount();
1500 args.SetReturnValue(Referenced::RawPtr(jSWebResourceRequest));
1501 }
1502
Destructor(JSWebResourceRequest * jSWebResourceRequest)1503 static void Destructor(JSWebResourceRequest* jSWebResourceRequest)
1504 {
1505 if (jSWebResourceRequest != nullptr) {
1506 jSWebResourceRequest->DecRefCount();
1507 }
1508 }
1509
1510 RefPtr<WebRequest> request_;
1511 };
1512
1513 class JSFileSelectorParam : public WebTransferBase<RefPtr<WebFileSelectorParam>> {
1514 public:
JSBind(BindingTarget globalObj)1515 static void JSBind(BindingTarget globalObj)
1516 {
1517 JSClass<JSFileSelectorParam>::Declare("FileSelectorParam");
1518 JSClass<JSFileSelectorParam>::CustomMethod("getTitle", &JSFileSelectorParam::GetTitle);
1519 JSClass<JSFileSelectorParam>::CustomMethod("getMode", &JSFileSelectorParam::GetMode);
1520 JSClass<JSFileSelectorParam>::CustomMethod("getAcceptType", &JSFileSelectorParam::GetAcceptType);
1521 JSClass<JSFileSelectorParam>::CustomMethod("isCapture", &JSFileSelectorParam::IsCapture);
1522 JSClass<JSFileSelectorParam>::CustomMethod("getMimeTypes", &JSFileSelectorParam::GetMimeType);
1523 JSClass<JSFileSelectorParam>::Bind(
1524 globalObj, &JSFileSelectorParam::Constructor, &JSFileSelectorParam::Destructor);
1525 }
1526
SetParam(const FileSelectorEvent & eventInfo)1527 void SetParam(const FileSelectorEvent& eventInfo)
1528 {
1529 param_ = eventInfo.GetParam();
1530 transferValues_ = std::make_tuple(param_);
1531 }
1532
GetTitle(const JSCallbackInfo & args)1533 void GetTitle(const JSCallbackInfo& args)
1534 {
1535 auto title = JSVal(ToJSValue(param_->GetTitle()));
1536 auto descriptionRef = JSRef<JSVal>::Make(title);
1537 args.SetReturnValue(descriptionRef);
1538 }
1539
GetMode(const JSCallbackInfo & args)1540 void GetMode(const JSCallbackInfo& args)
1541 {
1542 auto mode = JSVal(ToJSValue(param_->GetMode()));
1543 auto descriptionRef = JSRef<JSVal>::Make(mode);
1544 args.SetReturnValue(descriptionRef);
1545 }
1546
IsCapture(const JSCallbackInfo & args)1547 void IsCapture(const JSCallbackInfo& args)
1548 {
1549 auto isCapture = JSVal(ToJSValue(param_->IsCapture()));
1550 auto descriptionRef = JSRef<JSVal>::Make(isCapture);
1551 args.SetReturnValue(descriptionRef);
1552 }
1553
GetAcceptType(const JSCallbackInfo & args)1554 void GetAcceptType(const JSCallbackInfo& args)
1555 {
1556 auto acceptTypes = param_->GetAcceptType();
1557 JSRef<JSArray> result = JSRef<JSArray>::New();
1558 std::vector<std::string>::iterator iterator;
1559 uint32_t index = 0;
1560 for (iterator = acceptTypes.begin(); iterator != acceptTypes.end(); ++iterator) {
1561 auto valueStr = JSVal(ToJSValue(*iterator));
1562 auto value = JSRef<JSVal>::Make(valueStr);
1563 result->SetValueAt(index++, value);
1564 }
1565 args.SetReturnValue(result);
1566 }
1567
GetMimeType(const JSCallbackInfo & args)1568 void GetMimeType(const JSCallbackInfo& args)
1569 {
1570 auto mimeTypes = param_->GetMimeType();
1571 JSRef<JSArray> result = JSRef<JSArray>::New();
1572 std::vector<std::string>::iterator iterator;
1573 uint32_t index = 0;
1574 for (iterator = mimeTypes.begin(); iterator != mimeTypes.end(); ++iterator) {
1575 auto valueStr = JSVal(ToJSValue(*iterator));
1576 auto value = JSRef<JSVal>::Make(valueStr);
1577 result->SetValueAt(index++, value);
1578 }
1579 args.SetReturnValue(result);
1580 }
1581
1582 private:
Constructor(const JSCallbackInfo & args)1583 static void Constructor(const JSCallbackInfo& args)
1584 {
1585 auto jSFilerSelectorParam = Referenced::MakeRefPtr<JSFileSelectorParam>();
1586 jSFilerSelectorParam->IncRefCount();
1587 args.SetReturnValue(Referenced::RawPtr(jSFilerSelectorParam));
1588 }
1589
Destructor(JSFileSelectorParam * jSFilerSelectorParam)1590 static void Destructor(JSFileSelectorParam* jSFilerSelectorParam)
1591 {
1592 if (jSFilerSelectorParam != nullptr) {
1593 jSFilerSelectorParam->DecRefCount();
1594 }
1595 }
1596
1597 RefPtr<WebFileSelectorParam> param_;
1598 };
1599
1600 class JSFileSelectorResult : public WebTransferBase<RefPtr<FileSelectorResult>> {
1601 public:
JSBind(BindingTarget globalObj)1602 static void JSBind(BindingTarget globalObj)
1603 {
1604 JSClass<JSFileSelectorResult>::Declare("FileSelectorResult");
1605 JSClass<JSFileSelectorResult>::CustomMethod("handleFileList", &JSFileSelectorResult::HandleFileList);
1606 JSClass<JSFileSelectorResult>::Bind(
1607 globalObj, &JSFileSelectorResult::Constructor, &JSFileSelectorResult::Destructor);
1608 }
1609
SetResult(const FileSelectorEvent & eventInfo)1610 void SetResult(const FileSelectorEvent& eventInfo)
1611 {
1612 result_ = eventInfo.GetFileSelectorResult();
1613 transferValues_ = std::make_tuple(result_);
1614 }
1615
HandleFileList(const JSCallbackInfo & args)1616 void HandleFileList(const JSCallbackInfo& args)
1617 {
1618 std::vector<std::string> fileList;
1619 if (args[0]->IsArray()) {
1620 JSRef<JSArray> array = JSRef<JSArray>::Cast(args[0]);
1621 for (size_t i = 0; i < array->Length(); i++) {
1622 JSRef<JSVal> val = array->GetValueAt(i);
1623 if (!val->IsString()) {
1624 continue;
1625 }
1626 std::string fileName;
1627 if (!ConvertFromJSValue(val, fileName)) {
1628 continue;
1629 }
1630 fileList.push_back(fileName);
1631 }
1632 }
1633
1634 if (result_) {
1635 result_->HandleFileList(fileList);
1636 }
1637 }
1638
1639 private:
Constructor(const JSCallbackInfo & args)1640 static void Constructor(const JSCallbackInfo& args)
1641 {
1642 auto jsFileSelectorResult = Referenced::MakeRefPtr<JSFileSelectorResult>();
1643 jsFileSelectorResult->IncRefCount();
1644 args.SetReturnValue(Referenced::RawPtr(jsFileSelectorResult));
1645 }
1646
Destructor(JSFileSelectorResult * jsFileSelectorResult)1647 static void Destructor(JSFileSelectorResult* jsFileSelectorResult)
1648 {
1649 if (jsFileSelectorResult != nullptr) {
1650 jsFileSelectorResult->DecRefCount();
1651 }
1652 }
1653
1654 RefPtr<FileSelectorResult> result_;
1655 };
1656
1657 class JSContextMenuParam : public WebTransferBase<RefPtr<WebContextMenuParam>> {
1658 public:
JSBind(BindingTarget globalObj)1659 static void JSBind(BindingTarget globalObj)
1660 {
1661 JSClass<JSContextMenuParam>::Declare("WebContextMenuParam");
1662 JSClass<JSContextMenuParam>::CustomMethod("x", &JSContextMenuParam::GetXCoord);
1663 JSClass<JSContextMenuParam>::CustomMethod("y", &JSContextMenuParam::GetYCoord);
1664 JSClass<JSContextMenuParam>::CustomMethod("getLinkUrl", &JSContextMenuParam::GetLinkUrl);
1665 JSClass<JSContextMenuParam>::CustomMethod("getUnfilteredLinkUrl", &JSContextMenuParam::GetUnfilteredLinkUrl);
1666 JSClass<JSContextMenuParam>::CustomMethod("getSourceUrl", &JSContextMenuParam::GetSourceUrl);
1667 JSClass<JSContextMenuParam>::CustomMethod("existsImageContents", &JSContextMenuParam::HasImageContents);
1668 JSClass<JSContextMenuParam>::CustomMethod("getSelectionText", &JSContextMenuParam::GetSelectionText);
1669 JSClass<JSContextMenuParam>::CustomMethod("isEditable", &JSContextMenuParam::IsEditable);
1670 JSClass<JSContextMenuParam>::CustomMethod("getEditStateFlags", &JSContextMenuParam::GetEditStateFlags);
1671 JSClass<JSContextMenuParam>::CustomMethod("getSourceType", &JSContextMenuParam::GetSourceType);
1672 JSClass<JSContextMenuParam>::CustomMethod("getInputFieldType", &JSContextMenuParam::GetInputFieldType);
1673 JSClass<JSContextMenuParam>::CustomMethod("getMediaType", &JSContextMenuParam::GetMediaType);
1674 JSClass<JSContextMenuParam>::CustomMethod("getPreviewWidth", &JSContextMenuParam::GetPreviewWidth);
1675 JSClass<JSContextMenuParam>::CustomMethod("getPreviewHeight", &JSContextMenuParam::GetPreviewHeight);
1676 JSClass<JSContextMenuParam>::Bind(globalObj, &JSContextMenuParam::Constructor, &JSContextMenuParam::Destructor);
1677 }
1678
UpdatePreviewSize()1679 void UpdatePreviewSize()
1680 {
1681 if (previewWidth_ >= 0 && previewHeight_ >= 0) {
1682 return;
1683 }
1684 if (param_) {
1685 int32_t x = 0;
1686 int32_t y = 0;
1687 param_->GetImageRect(x, y, previewWidth_, previewHeight_);
1688 }
1689 }
1690
GetPreviewWidth(const JSCallbackInfo & args)1691 void GetPreviewWidth(const JSCallbackInfo& args)
1692 {
1693 auto ret = JSVal(ToJSValue(previewWidth_));
1694 auto descriptionRef = JSRef<JSVal>::Make(ret);
1695 args.SetReturnValue(descriptionRef);
1696 }
1697
GetPreviewHeight(const JSCallbackInfo & args)1698 void GetPreviewHeight(const JSCallbackInfo& args)
1699 {
1700 auto ret = JSVal(ToJSValue(previewHeight_));
1701 auto descriptionRef = JSRef<JSVal>::Make(ret);
1702 args.SetReturnValue(descriptionRef);
1703 }
1704
SetParam(const ContextMenuEvent & eventInfo)1705 void SetParam(const ContextMenuEvent& eventInfo)
1706 {
1707 param_ = eventInfo.GetParam();
1708 UpdatePreviewSize();
1709 transferValues_ = std::make_tuple(param_);
1710 }
1711
GetXCoord(const JSCallbackInfo & args)1712 void GetXCoord(const JSCallbackInfo& args)
1713 {
1714 int32_t ret = -1;
1715 if (param_) {
1716 ret = param_->GetXCoord();
1717 }
1718 auto xCoord = JSVal(ToJSValue(ret));
1719 auto descriptionRef = JSRef<JSVal>::Make(xCoord);
1720 args.SetReturnValue(descriptionRef);
1721 }
1722
GetYCoord(const JSCallbackInfo & args)1723 void GetYCoord(const JSCallbackInfo& args)
1724 {
1725 int32_t ret = -1;
1726 if (param_) {
1727 ret = param_->GetYCoord();
1728 }
1729 auto yCoord = JSVal(ToJSValue(ret));
1730 auto descriptionRef = JSRef<JSVal>::Make(yCoord);
1731 args.SetReturnValue(descriptionRef);
1732 }
1733
GetLinkUrl(const JSCallbackInfo & args)1734 void GetLinkUrl(const JSCallbackInfo& args)
1735 {
1736 std::string url;
1737 if (param_) {
1738 url = param_->GetLinkUrl();
1739 }
1740 auto linkUrl = JSVal(ToJSValue(url));
1741 auto descriptionRef = JSRef<JSVal>::Make(linkUrl);
1742 args.SetReturnValue(descriptionRef);
1743 }
1744
GetUnfilteredLinkUrl(const JSCallbackInfo & args)1745 void GetUnfilteredLinkUrl(const JSCallbackInfo& args)
1746 {
1747 std::string url;
1748 if (param_) {
1749 url = param_->GetUnfilteredLinkUrl();
1750 }
1751 auto unfilteredLinkUrl = JSVal(ToJSValue(url));
1752 auto descriptionRef = JSRef<JSVal>::Make(unfilteredLinkUrl);
1753 args.SetReturnValue(descriptionRef);
1754 }
1755
GetSourceUrl(const JSCallbackInfo & args)1756 void GetSourceUrl(const JSCallbackInfo& args)
1757 {
1758 std::string url;
1759 if (param_) {
1760 url = param_->GetSourceUrl();
1761 }
1762 auto sourceUrl = JSVal(ToJSValue(url));
1763 auto descriptionRef = JSRef<JSVal>::Make(sourceUrl);
1764 args.SetReturnValue(descriptionRef);
1765 }
1766
HasImageContents(const JSCallbackInfo & args)1767 void HasImageContents(const JSCallbackInfo& args)
1768 {
1769 bool ret = false;
1770 if (param_) {
1771 ret = param_->HasImageContents();
1772 }
1773 auto hasImageContents = JSVal(ToJSValue(ret));
1774 auto descriptionRef = JSRef<JSVal>::Make(hasImageContents);
1775 args.SetReturnValue(descriptionRef);
1776 }
1777
GetSelectionText(const JSCallbackInfo & args)1778 void GetSelectionText(const JSCallbackInfo& args)
1779 {
1780 std::string text;
1781 if (param_) {
1782 text = param_->GetSelectionText();
1783 }
1784 auto jsText = JSVal(ToJSValue(text));
1785 auto descriptionRef = JSRef<JSVal>::Make(jsText);
1786 args.SetReturnValue(descriptionRef);
1787 }
1788
IsEditable(const JSCallbackInfo & args)1789 void IsEditable(const JSCallbackInfo& args)
1790 {
1791 bool flag = false;
1792 if (param_) {
1793 flag = param_->IsEditable();
1794 }
1795 auto jsFlag = JSVal(ToJSValue(flag));
1796 auto descriptionRef = JSRef<JSVal>::Make(jsFlag);
1797 args.SetReturnValue(descriptionRef);
1798 }
1799
GetEditStateFlags(const JSCallbackInfo & args)1800 void GetEditStateFlags(const JSCallbackInfo& args)
1801 {
1802 int32_t flags = 0;
1803 if (param_) {
1804 flags = param_->GetEditStateFlags();
1805 }
1806 auto jsFlags = JSVal(ToJSValue(flags));
1807 auto descriptionRef = JSRef<JSVal>::Make(jsFlags);
1808 args.SetReturnValue(descriptionRef);
1809 }
1810
GetSourceType(const JSCallbackInfo & args)1811 void GetSourceType(const JSCallbackInfo& args)
1812 {
1813 int32_t type = 0;
1814 if (param_) {
1815 type = param_->GetSourceType();
1816 }
1817 auto jsType = JSVal(ToJSValue(type));
1818 auto descriptionRef = JSRef<JSVal>::Make(jsType);
1819 args.SetReturnValue(descriptionRef);
1820 }
1821
GetInputFieldType(const JSCallbackInfo & args)1822 void GetInputFieldType(const JSCallbackInfo& args)
1823 {
1824 int32_t type = 0;
1825 if (param_) {
1826 type = param_->GetInputFieldType();
1827 }
1828 auto jsType = JSVal(ToJSValue(type));
1829 auto descriptionRef = JSRef<JSVal>::Make(jsType);
1830 args.SetReturnValue(descriptionRef);
1831 }
1832
GetMediaType(const JSCallbackInfo & args)1833 void GetMediaType(const JSCallbackInfo& args)
1834 {
1835 int32_t type = 0;
1836 if (param_) {
1837 type = param_->GetMediaType();
1838 }
1839 if (type > 1) {
1840 RETURN_IF_CALLING_FROM_M114();
1841 }
1842 auto jsType = JSVal(ToJSValue(type));
1843 auto descriptionRef = JSRef<JSVal>::Make(jsType);
1844 args.SetReturnValue(descriptionRef);
1845 }
1846
1847 private:
Constructor(const JSCallbackInfo & args)1848 static void Constructor(const JSCallbackInfo& args)
1849 {
1850 auto jSContextMenuParam = Referenced::MakeRefPtr<JSContextMenuParam>();
1851 jSContextMenuParam->IncRefCount();
1852 args.SetReturnValue(Referenced::RawPtr(jSContextMenuParam));
1853 }
1854
Destructor(JSContextMenuParam * jSContextMenuParam)1855 static void Destructor(JSContextMenuParam* jSContextMenuParam)
1856 {
1857 if (jSContextMenuParam != nullptr) {
1858 jSContextMenuParam->DecRefCount();
1859 }
1860 }
1861
1862 RefPtr<WebContextMenuParam> param_;
1863
1864 int32_t previewWidth_ = -1;
1865
1866 int32_t previewHeight_ = -1;
1867 };
1868
1869 class JSContextMenuResult : public WebTransferBase<RefPtr<ContextMenuResult>> {
1870 public:
JSBind(BindingTarget globalObj)1871 static void JSBind(BindingTarget globalObj)
1872 {
1873 JSClass<JSContextMenuResult>::Declare("WebContextMenuResult");
1874 JSClass<JSContextMenuResult>::CustomMethod("closeContextMenu", &JSContextMenuResult::Cancel);
1875 JSClass<JSContextMenuResult>::CustomMethod("copyImage", &JSContextMenuResult::CopyImage);
1876 JSClass<JSContextMenuResult>::CustomMethod("copy", &JSContextMenuResult::Copy);
1877 JSClass<JSContextMenuResult>::CustomMethod("paste", &JSContextMenuResult::Paste);
1878 JSClass<JSContextMenuResult>::CustomMethod("cut", &JSContextMenuResult::Cut);
1879 JSClass<JSContextMenuResult>::CustomMethod("selectAll", &JSContextMenuResult::SelectAll);
1880 JSClass<JSContextMenuResult>::CustomMethod("undo", &JSContextMenuResult::Undo);
1881 JSClass<JSContextMenuResult>::CustomMethod("redo", &JSContextMenuResult::Redo);
1882 JSClass<JSContextMenuResult>::CustomMethod("pasteAndMatchStyle", &JSContextMenuResult::PasteAndMatchStyle);
1883 JSClass<JSContextMenuResult>::Bind(
1884 globalObj, &JSContextMenuResult::Constructor, &JSContextMenuResult::Destructor);
1885 }
1886
SetResult(const ContextMenuEvent & eventInfo)1887 void SetResult(const ContextMenuEvent& eventInfo)
1888 {
1889 result_ = eventInfo.GetContextMenuResult();
1890 transferValues_ = std::make_tuple(result_);
1891 }
1892
Cancel(const JSCallbackInfo & args)1893 void Cancel(const JSCallbackInfo& args)
1894 {
1895 if (result_) {
1896 result_->Cancel();
1897 }
1898 }
1899
CopyImage(const JSCallbackInfo & args)1900 void CopyImage(const JSCallbackInfo& args)
1901 {
1902 if (result_) {
1903 result_->CopyImage();
1904 }
1905 }
1906
Copy(const JSCallbackInfo & args)1907 void Copy(const JSCallbackInfo& args)
1908 {
1909 if (result_) {
1910 result_->Copy();
1911 }
1912 }
1913
Paste(const JSCallbackInfo & args)1914 void Paste(const JSCallbackInfo& args)
1915 {
1916 if (result_) {
1917 result_->Paste();
1918 }
1919 }
1920
Cut(const JSCallbackInfo & args)1921 void Cut(const JSCallbackInfo& args)
1922 {
1923 if (result_) {
1924 result_->Cut();
1925 }
1926 }
1927
SelectAll(const JSCallbackInfo & args)1928 void SelectAll(const JSCallbackInfo& args)
1929 {
1930 if (result_) {
1931 result_->SelectAll();
1932 }
1933 }
1934
Undo(const JSCallbackInfo & args)1935 void Undo(const JSCallbackInfo& args)
1936 {
1937 RETURN_IF_CALLING_FROM_M114();
1938 if (result_) {
1939 result_->Undo();
1940 }
1941 }
1942
Redo(const JSCallbackInfo & args)1943 void Redo(const JSCallbackInfo& args)
1944 {
1945 RETURN_IF_CALLING_FROM_M114();
1946 if (result_) {
1947 result_->Redo();
1948 }
1949 }
1950
PasteAndMatchStyle(const JSCallbackInfo & args)1951 void PasteAndMatchStyle(const JSCallbackInfo& args)
1952 {
1953 RETURN_IF_CALLING_FROM_M114();
1954 if (result_) {
1955 result_->PasteAndMatchStyle();
1956 }
1957 }
1958
1959 private:
Constructor(const JSCallbackInfo & args)1960 static void Constructor(const JSCallbackInfo& args)
1961 {
1962 auto jsContextMenuResult = Referenced::MakeRefPtr<JSContextMenuResult>();
1963 jsContextMenuResult->IncRefCount();
1964 args.SetReturnValue(Referenced::RawPtr(jsContextMenuResult));
1965 }
1966
Destructor(JSContextMenuResult * jsContextMenuResult)1967 static void Destructor(JSContextMenuResult* jsContextMenuResult)
1968 {
1969 if (jsContextMenuResult != nullptr) {
1970 jsContextMenuResult->DecRefCount();
1971 }
1972 }
1973
1974 RefPtr<ContextMenuResult> result_;
1975 };
1976
1977 class JSWebAppLinkCallback : public Referenced {
1978 public:
JSBind(BindingTarget globalObj)1979 static void JSBind(BindingTarget globalObj)
1980 {
1981 JSClass<JSWebAppLinkCallback>::Declare("WebAppLinkCallback");
1982 JSClass<JSWebAppLinkCallback>::CustomMethod("continueLoad", &JSWebAppLinkCallback::ContinueLoad);
1983 JSClass<JSWebAppLinkCallback>::CustomMethod("cancelLoad", &JSWebAppLinkCallback::CancelLoad);
1984 JSClass<JSWebAppLinkCallback>::Bind(
1985 globalObj, &JSWebAppLinkCallback::Constructor, &JSWebAppLinkCallback::Destructor);
1986 }
1987
SetEvent(const WebAppLinkEvent & eventInfo)1988 void SetEvent(const WebAppLinkEvent& eventInfo)
1989 {
1990 callback_ = eventInfo.GetCallback();
1991 }
1992
ContinueLoad(const JSCallbackInfo & args)1993 void ContinueLoad(const JSCallbackInfo& args)
1994 {
1995 if (callback_) {
1996 callback_->ContinueLoad();
1997 }
1998 }
1999
CancelLoad(const JSCallbackInfo & args)2000 void CancelLoad(const JSCallbackInfo& args)
2001 {
2002 if (callback_) {
2003 callback_->CancelLoad();
2004 }
2005 }
2006
2007 private:
Constructor(const JSCallbackInfo & args)2008 static void Constructor(const JSCallbackInfo& args)
2009 {
2010 auto jsWebAppLinkCallback = Referenced::MakeRefPtr<JSWebAppLinkCallback>();
2011 jsWebAppLinkCallback->IncRefCount();
2012 args.SetReturnValue(Referenced::RawPtr(jsWebAppLinkCallback));
2013 }
2014
Destructor(JSWebAppLinkCallback * jsWebAppLinkCallback)2015 static void Destructor(JSWebAppLinkCallback* jsWebAppLinkCallback)
2016 {
2017 if (jsWebAppLinkCallback != nullptr) {
2018 jsWebAppLinkCallback->DecRefCount();
2019 }
2020 }
2021
2022 RefPtr<WebAppLinkCallback> callback_;
2023 };
2024
JSBind(BindingTarget globalObj)2025 void JSWeb::JSBind(BindingTarget globalObj)
2026 {
2027 JSClass<JSWeb>::Declare("Web");
2028 JSClass<JSWeb>::StaticMethod("create", &JSWeb::Create);
2029 JSClass<JSWeb>::StaticMethod("onAlert", &JSWeb::OnAlert);
2030 JSClass<JSWeb>::StaticMethod("onBeforeUnload", &JSWeb::OnBeforeUnload);
2031 JSClass<JSWeb>::StaticMethod("onConfirm", &JSWeb::OnConfirm);
2032 JSClass<JSWeb>::StaticMethod("onPrompt", &JSWeb::OnPrompt);
2033 JSClass<JSWeb>::StaticMethod("onConsole", &JSWeb::OnConsoleLog);
2034 JSClass<JSWeb>::StaticMethod("onFullScreenEnter", &JSWeb::OnFullScreenEnter);
2035 JSClass<JSWeb>::StaticMethod("onFullScreenExit", &JSWeb::OnFullScreenExit);
2036 JSClass<JSWeb>::StaticMethod("onPageBegin", &JSWeb::OnPageStart);
2037 JSClass<JSWeb>::StaticMethod("onPageEnd", &JSWeb::OnPageFinish);
2038 JSClass<JSWeb>::StaticMethod("onProgressChange", &JSWeb::OnProgressChange);
2039 JSClass<JSWeb>::StaticMethod("onTitleReceive", &JSWeb::OnTitleReceive);
2040 JSClass<JSWeb>::StaticMethod("onGeolocationHide", &JSWeb::OnGeolocationHide);
2041 JSClass<JSWeb>::StaticMethod("onGeolocationShow", &JSWeb::OnGeolocationShow);
2042 JSClass<JSWeb>::StaticMethod("onRequestSelected", &JSWeb::OnRequestFocus);
2043 JSClass<JSWeb>::StaticMethod("onShowFileSelector", &JSWeb::OnFileSelectorShow);
2044 JSClass<JSWeb>::StaticMethod("javaScriptAccess", &JSWeb::JsEnabled);
2045 JSClass<JSWeb>::StaticMethod("fileExtendAccess", &JSWeb::ContentAccessEnabled);
2046 JSClass<JSWeb>::StaticMethod("fileAccess", &JSWeb::FileAccessEnabled);
2047 JSClass<JSWeb>::StaticMethod("onDownloadStart", &JSWeb::OnDownloadStart);
2048 JSClass<JSWeb>::StaticMethod("onErrorReceive", &JSWeb::OnErrorReceive);
2049 JSClass<JSWeb>::StaticMethod("onHttpErrorReceive", &JSWeb::OnHttpErrorReceive);
2050 JSClass<JSWeb>::StaticMethod("onInterceptRequest", &JSWeb::OnInterceptRequest);
2051 JSClass<JSWeb>::StaticMethod("onOverrideErrorPage", &JSWeb::OnOverrideErrorPage);
2052 JSClass<JSWeb>::StaticMethod("onUrlLoadIntercept", &JSWeb::OnUrlLoadIntercept);
2053 JSClass<JSWeb>::StaticMethod("onLoadIntercept", &JSWeb::OnLoadIntercept);
2054 JSClass<JSWeb>::StaticMethod("onlineImageAccess", &JSWeb::OnLineImageAccessEnabled);
2055 JSClass<JSWeb>::StaticMethod("domStorageAccess", &JSWeb::DomStorageAccessEnabled);
2056 JSClass<JSWeb>::StaticMethod("imageAccess", &JSWeb::ImageAccessEnabled);
2057 JSClass<JSWeb>::StaticMethod("mixedMode", &JSWeb::MixedMode);
2058 JSClass<JSWeb>::StaticMethod("enableNativeEmbedMode", &JSWeb::EnableNativeEmbedMode);
2059 JSClass<JSWeb>::StaticMethod("nativeEmbedOptions", &JSWeb::NativeEmbedOptions);
2060 JSClass<JSWeb>::StaticMethod("registerNativeEmbedRule", &JSWeb::RegisterNativeEmbedRule);
2061 JSClass<JSWeb>::StaticMethod("zoomAccess", &JSWeb::ZoomAccessEnabled);
2062 JSClass<JSWeb>::StaticMethod("geolocationAccess", &JSWeb::GeolocationAccessEnabled);
2063 JSClass<JSWeb>::StaticMethod("javaScriptProxy", &JSWeb::JavaScriptProxy);
2064 JSClass<JSWeb>::StaticMethod("userAgent", &JSWeb::UserAgent);
2065 JSClass<JSWeb>::StaticMethod("onRenderExited", &JSWeb::OnRenderExited);
2066 JSClass<JSWeb>::StaticMethod("onRefreshAccessedHistory", &JSWeb::OnRefreshAccessedHistory);
2067 JSClass<JSWeb>::StaticMethod("cacheMode", &JSWeb::CacheMode);
2068 JSClass<JSWeb>::StaticMethod("overviewModeAccess", &JSWeb::OverviewModeAccess);
2069 JSClass<JSWeb>::StaticMethod("webDebuggingAccess", &JSWeb::WebDebuggingAccess);
2070 JSClass<JSWeb>::StaticMethod("wideViewModeAccess", &JSWeb::WideViewModeAccess);
2071 JSClass<JSWeb>::StaticMethod("fileFromUrlAccess", &JSWeb::FileFromUrlAccess);
2072 JSClass<JSWeb>::StaticMethod("databaseAccess", &JSWeb::DatabaseAccess);
2073 JSClass<JSWeb>::StaticMethod("textZoomRatio", &JSWeb::TextZoomRatio);
2074 JSClass<JSWeb>::StaticMethod("textZoomAtio", &JSWeb::TextZoomRatio);
2075 JSClass<JSWeb>::StaticMethod("initialScale", &JSWeb::InitialScale);
2076 JSClass<JSWeb>::StaticMethod("backgroundColor", &JSWeb::BackgroundColor);
2077 JSClass<JSWeb>::StaticMethod("onKeyEvent", &JSWeb::OnKeyEvent);
2078 JSClass<JSWeb>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
2079 JSClass<JSWeb>::StaticMethod("onMouse", &JSWeb::OnMouse);
2080 JSClass<JSWeb>::StaticMethod("onResourceLoad", &JSWeb::OnResourceLoad);
2081 JSClass<JSWeb>::StaticMethod("onScaleChange", &JSWeb::OnScaleChange);
2082 JSClass<JSWeb>::StaticMethod("password", &JSWeb::Password);
2083 JSClass<JSWeb>::StaticMethod("tableData", &JSWeb::TableData);
2084 JSClass<JSWeb>::StaticMethod("onFileSelectorShow", &JSWeb::OnFileSelectorShowAbandoned);
2085 JSClass<JSWeb>::StaticMethod("onHttpAuthRequest", &JSWeb::OnHttpAuthRequest);
2086 JSClass<JSWeb>::StaticMethod("onSslErrorReceive", &JSWeb::OnSslErrRequest);
2087 JSClass<JSWeb>::StaticMethod("onSslErrorEventReceive", &JSWeb::OnSslErrorRequest);
2088 JSClass<JSWeb>::StaticMethod("onSslErrorEvent", &JSWeb::OnAllSslErrorRequest);
2089 JSClass<JSWeb>::StaticMethod("onClientAuthenticationRequest", &JSWeb::OnSslSelectCertRequest);
2090 JSClass<JSWeb>::StaticMethod("onPermissionRequest", &JSWeb::OnPermissionRequest);
2091 JSClass<JSWeb>::StaticMethod("onContextMenuShow", &JSWeb::OnContextMenuShow);
2092 JSClass<JSWeb>::StaticMethod("onContextMenuHide", &JSWeb::OnContextMenuHide);
2093 JSClass<JSWeb>::StaticMethod("onSearchResultReceive", &JSWeb::OnSearchResultReceive);
2094 JSClass<JSWeb>::StaticMethod("mediaPlayGestureAccess", &JSWeb::MediaPlayGestureAccess);
2095 JSClass<JSWeb>::StaticMethod("onDragStart", &JSWeb::JsOnDragStart);
2096 JSClass<JSWeb>::StaticMethod("onDragEnter", &JSWeb::JsOnDragEnter);
2097 JSClass<JSWeb>::StaticMethod("onDragMove", &JSWeb::JsOnDragMove);
2098 JSClass<JSWeb>::StaticMethod("onDragLeave", &JSWeb::JsOnDragLeave);
2099 JSClass<JSWeb>::StaticMethod("onDrop", &JSWeb::JsOnDrop);
2100 JSClass<JSWeb>::StaticMethod("onScroll", &JSWeb::OnScroll);
2101 JSClass<JSWeb>::StaticMethod("rotate", &JSWeb::WebRotate);
2102 JSClass<JSWeb>::StaticMethod("pinchSmooth", &JSWeb::PinchSmoothModeEnabled);
2103 JSClass<JSWeb>::StaticMethod("onAttach", &JSInteractableView::JsOnAttach);
2104 JSClass<JSWeb>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
2105 JSClass<JSWeb>::StaticMethod("onDetach", &JSInteractableView::JsOnDetach);
2106 JSClass<JSWeb>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
2107 JSClass<JSWeb>::StaticMethod("onWindowNew", &JSWeb::OnWindowNew);
2108 JSClass<JSWeb>::StaticMethod("onActivateContent", &JSWeb::OnActivateContent);
2109 JSClass<JSWeb>::StaticMethod("onWindowExit", &JSWeb::OnWindowExit);
2110 JSClass<JSWeb>::StaticMethod("multiWindowAccess", &JSWeb::MultiWindowAccessEnabled);
2111 JSClass<JSWeb>::StaticMethod("allowWindowOpenMethod", &JSWeb::AllowWindowOpenMethod);
2112 JSClass<JSWeb>::StaticMethod("webCursiveFont", &JSWeb::WebCursiveFont);
2113 JSClass<JSWeb>::StaticMethod("webFantasyFont", &JSWeb::WebFantasyFont);
2114 JSClass<JSWeb>::StaticMethod("webFixedFont", &JSWeb::WebFixedFont);
2115 JSClass<JSWeb>::StaticMethod("webSansSerifFont", &JSWeb::WebSansSerifFont);
2116 JSClass<JSWeb>::StaticMethod("webSerifFont", &JSWeb::WebSerifFont);
2117 JSClass<JSWeb>::StaticMethod("webStandardFont", &JSWeb::WebStandardFont);
2118 JSClass<JSWeb>::StaticMethod("defaultFixedFontSize", &JSWeb::DefaultFixedFontSize);
2119 JSClass<JSWeb>::StaticMethod("defaultFontSize", &JSWeb::DefaultFontSize);
2120 JSClass<JSWeb>::StaticMethod("defaultTextEncodingFormat", &JSWeb::DefaultTextEncodingFormat);
2121 JSClass<JSWeb>::StaticMethod("minFontSize", &JSWeb::MinFontSize);
2122 JSClass<JSWeb>::StaticMethod("minLogicalFontSize", &JSWeb::MinLogicalFontSize);
2123 JSClass<JSWeb>::StaticMethod("blockNetwork", &JSWeb::BlockNetwork);
2124 JSClass<JSWeb>::StaticMethod("onPageVisible", &JSWeb::OnPageVisible);
2125 JSClass<JSWeb>::StaticMethod("onInterceptKeyEvent", &JSWeb::OnInterceptKeyEvent);
2126 JSClass<JSWeb>::StaticMethod("onDataResubmitted", &JSWeb::OnDataResubmitted);
2127 JSClass<JSWeb>::StaticMethod("onFaviconReceived", &JSWeb::OnFaviconReceived);
2128 JSClass<JSWeb>::StaticMethod("onTouchIconUrlReceived", &JSWeb::OnTouchIconUrlReceived);
2129 JSClass<JSWeb>::StaticMethod("darkMode", &JSWeb::DarkMode);
2130 JSClass<JSWeb>::StaticMethod("forceDarkAccess", &JSWeb::ForceDarkAccess);
2131 JSClass<JSWeb>::StaticMethod("overScrollMode", &JSWeb::OverScrollMode);
2132 JSClass<JSWeb>::StaticMethod("blurOnKeyboardHideMode", &JSWeb::BlurOnKeyboardHideMode);
2133 JSClass<JSWeb>::StaticMethod("horizontalScrollBarAccess", &JSWeb::HorizontalScrollBarAccess);
2134 JSClass<JSWeb>::StaticMethod("verticalScrollBarAccess", &JSWeb::VerticalScrollBarAccess);
2135 JSClass<JSWeb>::StaticMethod("onAudioStateChanged", &JSWeb::OnAudioStateChanged);
2136 JSClass<JSWeb>::StaticMethod("mediaOptions", &JSWeb::MediaOptions);
2137 JSClass<JSWeb>::StaticMethod("onFirstContentfulPaint", &JSWeb::OnFirstContentfulPaint);
2138 JSClass<JSWeb>::StaticMethod("onFirstMeaningfulPaint", &JSWeb::OnFirstMeaningfulPaint);
2139 JSClass<JSWeb>::StaticMethod("onLargestContentfulPaint", &JSWeb::OnLargestContentfulPaint);
2140 JSClass<JSWeb>::StaticMethod("onSafeBrowsingCheckResult", &JSWeb::OnSafeBrowsingCheckResult);
2141 JSClass<JSWeb>::StaticMethod("onNavigationEntryCommitted", &JSWeb::OnNavigationEntryCommitted);
2142 JSClass<JSWeb>::StaticMethod("onIntelligentTrackingPreventionResult",
2143 &JSWeb::OnIntelligentTrackingPreventionResult);
2144 JSClass<JSWeb>::StaticMethod("onControllerAttached", &JSWeb::OnControllerAttached);
2145 JSClass<JSWeb>::StaticMethod("onOverScroll", &JSWeb::OnOverScroll);
2146 JSClass<JSWeb>::StaticMethod("onNativeEmbedLifecycleChange", &JSWeb::OnNativeEmbedLifecycleChange);
2147 JSClass<JSWeb>::StaticMethod("onNativeEmbedVisibilityChange", &JSWeb::OnNativeEmbedVisibilityChange);
2148 JSClass<JSWeb>::StaticMethod("onNativeEmbedGestureEvent", &JSWeb::OnNativeEmbedGestureEvent);
2149 JSClass<JSWeb>::StaticMethod("onNativeEmbedMouseEvent", &JSWeb::OnNativeEmbedMouseEvent);
2150 JSClass<JSWeb>::StaticMethod("copyOptions", &JSWeb::CopyOption);
2151 JSClass<JSWeb>::StaticMethod("onScreenCaptureRequest", &JSWeb::OnScreenCaptureRequest);
2152 JSClass<JSWeb>::StaticMethod("layoutMode", &JSWeb::SetLayoutMode);
2153 JSClass<JSWeb>::StaticMethod("nestedScroll", &JSWeb::SetNestedScroll);
2154 JSClass<JSWeb>::StaticMethod("metaViewport", &JSWeb::SetMetaViewport);
2155 JSClass<JSWeb>::StaticMethod("javaScriptOnDocumentStart", &JSWeb::JavaScriptOnDocumentStart);
2156 JSClass<JSWeb>::StaticMethod("javaScriptOnDocumentEnd", &JSWeb::JavaScriptOnDocumentEnd);
2157 JSClass<JSWeb>::StaticMethod("onOverrideUrlLoading", &JSWeb::OnOverrideUrlLoading);
2158 JSClass<JSWeb>::StaticMethod("textAutosizing", &JSWeb::TextAutosizing);
2159 JSClass<JSWeb>::StaticMethod("enableNativeMediaPlayer", &JSWeb::EnableNativeVideoPlayer);
2160 JSClass<JSWeb>::StaticMethod("onRenderProcessNotResponding", &JSWeb::OnRenderProcessNotResponding);
2161 JSClass<JSWeb>::StaticMethod("onRenderProcessResponding", &JSWeb::OnRenderProcessResponding);
2162 JSClass<JSWeb>::StaticMethod("selectionMenuOptions", &JSWeb::SelectionMenuOptions);
2163 JSClass<JSWeb>::StaticMethod("onViewportFitChanged", &JSWeb::OnViewportFitChanged);
2164 JSClass<JSWeb>::StaticMethod("onInterceptKeyboardAttach", &JSWeb::OnInterceptKeyboardAttach);
2165 JSClass<JSWeb>::StaticMethod("onAdsBlocked", &JSWeb::OnAdsBlocked);
2166 JSClass<JSWeb>::StaticMethod("forceDisplayScrollBar", &JSWeb::ForceDisplayScrollBar);
2167 JSClass<JSWeb>::StaticMethod("keyboardAvoidMode", &JSWeb::KeyboardAvoidMode);
2168 JSClass<JSWeb>::StaticMethod("editMenuOptions", &JSWeb::EditMenuOptions);
2169 JSClass<JSWeb>::StaticMethod("enableHapticFeedback", &JSWeb::EnableHapticFeedback);
2170 JSClass<JSWeb>::StaticMethod("bindSelectionMenu", &JSWeb::BindSelectionMenu);
2171 JSClass<JSWeb>::StaticMethod("optimizeParserBudget", &JSWeb::OptimizeParserBudgetEnabled);
2172 JSClass<JSWeb>::StaticMethod("runJavaScriptOnHeadEnd", &JSWeb::RunJavaScriptOnHeadEnd);
2173 JSClass<JSWeb>::StaticMethod("runJavaScriptOnDocumentStart", &JSWeb::RunJavaScriptOnDocumentStart);
2174 JSClass<JSWeb>::StaticMethod("runJavaScriptOnDocumentEnd", &JSWeb::RunJavaScriptOnDocumentEnd);
2175 JSClass<JSWeb>::StaticMethod("enableWebAVSession", &JSWeb::EnableWebAVSession);
2176 JSClass<JSWeb>::StaticMethod("enableDataDetector", &JSWeb::EnableDataDetector);
2177 JSClass<JSWeb>::StaticMethod("dataDetectorConfig", &JSWeb::DataDetectorConfig);
2178 JSClass<JSWeb>::StaticMethod("bypassVsyncCondition", &JSWeb::BypassVsyncCondition);
2179 JSClass<JSWeb>::StaticMethod("enableFollowSystemFontWeight", &JSWeb::EnableFollowSystemFontWeight);
2180 JSClass<JSWeb>::StaticMethod("onLoadStarted", &JSWeb::OnLoadStarted);
2181 JSClass<JSWeb>::StaticMethod("onLoadFinished", &JSWeb::OnLoadFinished);
2182 JSClass<JSWeb>::StaticMethod("gestureFocusMode", &JSWeb::GestureFocusMode);
2183 JSClass<JSWeb>::StaticMethod("onPdfScrollAtBottom", &JSWeb::OnPdfScrollAtBottom);
2184 JSClass<JSWeb>::StaticMethod("onPdfLoadEvent", &JSWeb::OnPdfLoadEvent);
2185 JSClass<JSWeb>::InheritAndBind<JSViewAbstract>(globalObj);
2186 JSWebDialog::JSBind(globalObj);
2187 JSWebGeolocation::JSBind(globalObj);
2188 JSWebResourceRequest::JSBind(globalObj);
2189 JSWebResourceError::JSBind(globalObj);
2190 JSWebResourceResponse::JSBind(globalObj);
2191 JSWebConsoleLog::JSBind(globalObj);
2192 JSFileSelectorParam::JSBind(globalObj);
2193 JSFileSelectorResult::JSBind(globalObj);
2194 JSFullScreenExitHandler::JSBind(globalObj);
2195 JSWebHttpAuth::JSBind(globalObj);
2196 JSWebSslError::JSBind(globalObj);
2197 JSWebAllSslError::JSBind(globalObj);
2198 JSWebSslSelectCert::JSBind(globalObj);
2199 JSWebPermissionRequest::JSBind(globalObj);
2200 JSContextMenuParam::JSBind(globalObj);
2201 JSContextMenuResult::JSBind(globalObj);
2202 JSWebWindowNewHandler::JSBind(globalObj);
2203 JSDataResubmitted::JSBind(globalObj);
2204 JSScreenCaptureRequest::JSBind(globalObj);
2205 JSNativeEmbedGestureRequest::JSBind(globalObj);
2206 JSNativeEmbedMouseRequest::JSBind(globalObj);
2207 JSWebAppLinkCallback::JSBind(globalObj);
2208 JSWebKeyboardController::JSBind(globalObj);
2209 }
2210
GetNapiEnv()2211 napi_env GetNapiEnv()
2212 {
2213 auto engine = EngineHelper::GetCurrentEngine();
2214 CHECK_NULL_RETURN(engine, nullptr);
2215 auto nativeEngine = engine->GetNativeEngine();
2216 CHECK_NULL_RETURN(nativeEngine, nullptr);
2217 return reinterpret_cast<napi_env>(nativeEngine);
2218 }
2219
WrapNapiValue(napi_env env,const JSRef<JSVal> & obj,void * nativeValue)2220 napi_value WrapNapiValue(napi_env env, const JSRef<JSVal>& obj, void* nativeValue)
2221 {
2222 napi_value undefined;
2223 napi_get_undefined(env, &undefined);
2224 CHECK_NULL_RETURN(obj->IsObject(), undefined);
2225 ArkNativeEngine* nativeEngine = reinterpret_cast<ArkNativeEngine*>(env);
2226 CHECK_NULL_RETURN(nativeEngine, undefined);
2227 panda::Local<JsiValue> value = obj.Get().GetLocalHandle();
2228 JSValueWrapper valueWrapper = value;
2229 ScopeRAII scope(env);
2230 napi_value napiValue = nativeEngine->ValueToNapiValue(valueWrapper);
2231 napi_valuetype valueType = napi_undefined;
2232 napi_typeof(env, napiValue, &valueType);
2233 if (valueType != napi_object) {
2234 return undefined;
2235 }
2236 napi_wrap(env, napiValue, nativeValue,
2237 [](napi_env env, void *data, void *hint) {}, nullptr, nullptr);
2238 return napiValue;
2239 }
2240
LoadWebConsoleLogEventToJSValue(const LoadWebConsoleLogEvent & eventInfo)2241 JSRef<JSVal> LoadWebConsoleLogEventToJSValue(const LoadWebConsoleLogEvent& eventInfo)
2242 {
2243 JSRef<JSObject> obj = JSRef<JSObject>::New();
2244
2245 JSRef<JSObject> messageObj = JSClass<JSWebConsoleLog>::NewInstance();
2246 auto jsWebConsoleLog = Referenced::Claim(messageObj->Unwrap<JSWebConsoleLog>());
2247 jsWebConsoleLog->SetMessage(eventInfo.GetMessage());
2248 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(messageObj), static_cast<void *>(jsWebConsoleLog.GetRawPtr()));
2249
2250 obj->SetPropertyObject("message", messageObj);
2251
2252 return JSRef<JSVal>::Cast(obj);
2253 }
2254
CreateConsoleHandler(const LoadWebConsoleLogEvent & eventInfo)2255 JSRef<JSVal> JSWeb::CreateConsoleHandler(const LoadWebConsoleLogEvent& eventInfo)
2256 {
2257 JSRef<JSObject> messageObj = JSClass<JSWebConsoleLog>::NewInstance();
2258 auto jsWebConsoleLog = Referenced::Claim(messageObj->Unwrap<JSWebConsoleLog>());
2259 if (!jsWebConsoleLog) {
2260 return messageObj;
2261 }
2262 jsWebConsoleLog->SetMessage(eventInfo.GetMessage());
2263 return messageObj;
2264 }
2265
WebDialogEventToJSValue(const WebDialogEvent & eventInfo)2266 JSRef<JSVal> WebDialogEventToJSValue(const WebDialogEvent& eventInfo)
2267 {
2268 JSRef<JSObject> obj = JSRef<JSObject>::New();
2269
2270 JSRef<JSObject> resultObj = JSClass<JSWebDialog>::NewInstance();
2271 auto jsWebDialog = Referenced::Claim(resultObj->Unwrap<JSWebDialog>());
2272 jsWebDialog->SetResult(eventInfo.GetResult());
2273 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(resultObj), static_cast<void *>(jsWebDialog.GetRawPtr()));
2274 obj->SetProperty("url", eventInfo.GetUrl());
2275 obj->SetProperty("message", eventInfo.GetMessage());
2276 if (eventInfo.GetType() == DialogEventType::DIALOG_EVENT_PROMPT) {
2277 obj->SetProperty("value", eventInfo.GetValue());
2278 }
2279 obj->SetPropertyObject("result", resultObj);
2280 if (eventInfo.GetType() == DialogEventType::DIALOG_EVENT_BEFORE_UNLOAD) {
2281 obj->SetProperty("isReload", eventInfo.GetIsReload());
2282 }
2283 return JSRef<JSVal>::Cast(obj);
2284 }
2285
CreateCommonDialogResultHandler(const WebDialogEvent & eventInfo)2286 JSRef<JSVal> JSWeb::CreateCommonDialogResultHandler(const WebDialogEvent& eventInfo)
2287 {
2288 JSRef<JSObject> resultObj = JSClass<JSWebDialog>::NewInstance();
2289 auto jsWebDialog = Referenced::Claim(resultObj->Unwrap<JSWebDialog>());
2290 jsWebDialog->SetResult(eventInfo.GetResult());
2291 return resultObj;
2292 }
2293
LoadEventToJSValue(const BaseLoadEvent & eventInfo)2294 JSRef<JSVal> LoadEventToJSValue(const BaseLoadEvent& eventInfo)
2295 {
2296 JSRef<JSObject> obj = JSRef<JSObject>::New();
2297 obj->SetProperty("url", eventInfo.GetLoadedUrl());
2298 return JSRef<JSVal>::Cast(obj);
2299 }
2300
ContextMenuHideEventToJSValue(const ContextMenuHideEvent & eventInfo)2301 JSRef<JSVal> ContextMenuHideEventToJSValue(const ContextMenuHideEvent& eventInfo)
2302 {
2303 JSRef<JSObject> obj = JSRef<JSObject>::New();
2304 obj->SetProperty("info", eventInfo.GetInfo());
2305 return JSRef<JSVal>::Cast(obj);
2306 }
2307
PdfScrollEventToJSValue(const PdfScrollEvent & eventInfo)2308 JSRef<JSVal> PdfScrollEventToJSValue(const PdfScrollEvent& eventInfo)
2309 {
2310 JSRef<JSObject> obj = JSRef<JSObject>::New();
2311 obj->SetProperty("url", eventInfo.GetUrl());
2312 return JSRef<JSVal>::Cast(obj);
2313 }
2314
PdfLoadEventToJSValue(const PdfLoadEvent & eventInfo)2315 JSRef<JSVal> PdfLoadEventToJSValue(const PdfLoadEvent& eventInfo)
2316 {
2317 JSRef<JSObject> obj = JSRef<JSObject>::New();
2318 obj->SetProperty("result", eventInfo.GetResult());
2319 obj->SetProperty("url", eventInfo.GetUrl());
2320 return JSRef<JSVal>::Cast(obj);
2321 }
2322
FullScreenEnterEventToJSValue(const FullScreenEnterEvent & eventInfo)2323 JSRef<JSVal> FullScreenEnterEventToJSValue(const FullScreenEnterEvent& eventInfo)
2324 {
2325 JSRef<JSObject> obj = JSRef<JSObject>::New();
2326 JSRef<JSObject> resultObj = JSClass<JSFullScreenExitHandler>::NewInstance();
2327 auto jsFullScreenExitHandler = Referenced::Claim(resultObj->Unwrap<JSFullScreenExitHandler>());
2328 if (!jsFullScreenExitHandler) {
2329 return JSRef<JSVal>::Cast(obj);
2330 }
2331 jsFullScreenExitHandler->SetHandler(eventInfo.GetHandler());
2332
2333 obj->SetPropertyObject("handler", resultObj);
2334 obj->SetProperty("videoWidth", eventInfo.GetVideoNaturalWidth());
2335 obj->SetProperty("videoHeight", eventInfo.GetVideoNaturalHeight());
2336 return JSRef<JSVal>::Cast(obj);
2337 }
2338
CreateFullScreenEnterHandler(const FullScreenEnterEvent & eventInfo)2339 JSRef<JSVal> JSWeb::CreateFullScreenEnterHandler(const FullScreenEnterEvent& eventInfo)
2340 {
2341 JSRef<JSObject> resultObj = JSClass<JSFullScreenExitHandler>::NewInstance();
2342 auto jsFullScreenExitHandler = Referenced::Claim(resultObj->Unwrap<JSFullScreenExitHandler>());
2343 jsFullScreenExitHandler->SetHandler(eventInfo.GetHandler());
2344 return resultObj;
2345 }
2346
FullScreenExitEventToJSValue(const FullScreenExitEvent & eventInfo)2347 JSRef<JSVal> FullScreenExitEventToJSValue(const FullScreenExitEvent& eventInfo)
2348 {
2349 return JSRef<JSVal>::Make(ToJSValue(eventInfo.IsFullScreen()));
2350 }
2351
LoadWebProgressChangeEventToJSValue(const LoadWebProgressChangeEvent & eventInfo)2352 JSRef<JSVal> LoadWebProgressChangeEventToJSValue(const LoadWebProgressChangeEvent& eventInfo)
2353 {
2354 JSRef<JSObject> obj = JSRef<JSObject>::New();
2355 obj->SetProperty("newProgress", eventInfo.GetNewProgress());
2356 return JSRef<JSVal>::Cast(obj);
2357 }
2358
LoadWebTitleReceiveEventToJSValue(const LoadWebTitleReceiveEvent & eventInfo)2359 JSRef<JSVal> LoadWebTitleReceiveEventToJSValue(const LoadWebTitleReceiveEvent& eventInfo)
2360 {
2361 JSRef<JSObject> obj = JSRef<JSObject>::New();
2362 obj->SetProperty("title", eventInfo.GetTitle());
2363 obj->SetProperty("isRealTitle", eventInfo.GetIsRealTitle());
2364 return JSRef<JSVal>::Cast(obj);
2365 }
2366
UrlLoadInterceptEventToJSValue(const UrlLoadInterceptEvent & eventInfo)2367 JSRef<JSVal> UrlLoadInterceptEventToJSValue(const UrlLoadInterceptEvent& eventInfo)
2368 {
2369 JSRef<JSObject> obj = JSRef<JSObject>::New();
2370 obj->SetProperty("data", eventInfo.GetData());
2371 return JSRef<JSVal>::Cast(obj);
2372 }
2373
LoadInterceptEventToJSValue(const LoadInterceptEvent & eventInfo)2374 JSRef<JSVal> LoadInterceptEventToJSValue(const LoadInterceptEvent& eventInfo)
2375 {
2376 JSRef<JSObject> obj = JSRef<JSObject>::New();
2377 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
2378 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
2379 requestEvent->SetLoadInterceptEvent(eventInfo);
2380 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(requestObj), static_cast<void *>(requestEvent.GetRawPtr()));
2381 obj->SetPropertyObject("data", requestObj);
2382 return JSRef<JSVal>::Cast(obj);
2383 }
2384
CreateLoadInterceptHandler(const LoadInterceptEvent & eventInfo)2385 JSRef<JSVal> JSWeb::CreateLoadInterceptHandler(const LoadInterceptEvent& eventInfo)
2386 {
2387 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
2388 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
2389 if (!requestEvent) {
2390 return requestObj;
2391 }
2392 requestEvent->SetLoadInterceptEvent(eventInfo);
2393 return requestObj;
2394 }
2395
LoadWebGeolocationHideEventToJSValue(const LoadWebGeolocationHideEvent & eventInfo)2396 JSRef<JSVal> LoadWebGeolocationHideEventToJSValue(const LoadWebGeolocationHideEvent& eventInfo)
2397 {
2398 return JSRef<JSVal>::Make(ToJSValue(eventInfo.GetOrigin()));
2399 }
2400
LoadWebGeolocationShowEventToJSValue(const LoadWebGeolocationShowEvent & eventInfo)2401 JSRef<JSVal> LoadWebGeolocationShowEventToJSValue(const LoadWebGeolocationShowEvent& eventInfo)
2402 {
2403 JSRef<JSObject> obj = JSRef<JSObject>::New();
2404 obj->SetProperty("origin", eventInfo.GetOrigin());
2405 JSRef<JSObject> geolocationObj = JSClass<JSWebGeolocation>::NewInstance();
2406 auto geolocationEvent = Referenced::Claim(geolocationObj->Unwrap<JSWebGeolocation>());
2407 geolocationEvent->SetEvent(eventInfo);
2408 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(geolocationObj), static_cast<void *>(geolocationEvent.GetRawPtr()));
2409 obj->SetPropertyObject("geolocation", geolocationObj);
2410 return JSRef<JSVal>::Cast(obj);
2411 }
2412
CreateGeolocationShowHandler(const LoadWebGeolocationShowEvent & eventInfo)2413 JSRef<JSVal> JSWeb::CreateGeolocationShowHandler(const LoadWebGeolocationShowEvent& eventInfo)
2414 {
2415 JSRef<JSObject> geolocationObj = JSClass<JSWebGeolocation>::NewInstance();
2416 auto geolocationEvent = Referenced::Claim(geolocationObj->Unwrap<JSWebGeolocation>());
2417 geolocationEvent->SetEvent(eventInfo);
2418 return geolocationObj;
2419 }
2420
DownloadStartEventToJSValue(const DownloadStartEvent & eventInfo)2421 JSRef<JSVal> DownloadStartEventToJSValue(const DownloadStartEvent& eventInfo)
2422 {
2423 JSRef<JSObject> obj = JSRef<JSObject>::New();
2424 obj->SetProperty("url", eventInfo.GetUrl());
2425 obj->SetProperty("userAgent", eventInfo.GetUserAgent());
2426 obj->SetProperty("contentDisposition", eventInfo.GetContentDisposition());
2427 obj->SetProperty("mimetype", eventInfo.GetMimetype());
2428 obj->SetProperty("contentLength", eventInfo.GetContentLength());
2429 return JSRef<JSVal>::Cast(obj);
2430 }
2431
LoadWebRequestFocusEventToJSValue(const LoadWebRequestFocusEvent & eventInfo)2432 JSRef<JSVal> LoadWebRequestFocusEventToJSValue(const LoadWebRequestFocusEvent& eventInfo)
2433 {
2434 return JSRef<JSVal>::Make(ToJSValue(eventInfo.GetRequestFocus()));
2435 }
2436
WebHttpAuthEventToJSValue(const WebHttpAuthEvent & eventInfo)2437 JSRef<JSVal> WebHttpAuthEventToJSValue(const WebHttpAuthEvent& eventInfo)
2438 {
2439 JSRef<JSObject> obj = JSRef<JSObject>::New();
2440 JSRef<JSObject> resultObj = JSClass<JSWebHttpAuth>::NewInstance();
2441 auto jsWebHttpAuth = Referenced::Claim(resultObj->Unwrap<JSWebHttpAuth>());
2442 if (!jsWebHttpAuth) {
2443 return JSRef<JSVal>::Cast(obj);
2444 }
2445 jsWebHttpAuth->SetResult(eventInfo.GetResult());
2446 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(resultObj), static_cast<void *>(jsWebHttpAuth.GetRawPtr()));
2447 obj->SetPropertyObject("handler", resultObj);
2448 obj->SetProperty("host", eventInfo.GetHost());
2449 obj->SetProperty("realm", eventInfo.GetRealm());
2450 return JSRef<JSVal>::Cast(obj);
2451 }
2452
CreateHttpAuthRequestHandler(const WebHttpAuthEvent & eventInfo)2453 JSRef<JSVal> JSWeb::CreateHttpAuthRequestHandler(const WebHttpAuthEvent& eventInfo)
2454 {
2455 JSRef<JSObject> resultObj = JSClass<JSWebHttpAuth>::NewInstance();
2456 auto jsWebHttpAuth = Referenced::Claim(resultObj->Unwrap<JSWebHttpAuth>());
2457 if (!jsWebHttpAuth) {
2458 return resultObj;
2459 }
2460 jsWebHttpAuth->SetResult(eventInfo.GetResult());
2461 return resultObj;
2462 }
2463
WebSslErrorEventToJSValue(const WebSslErrorEvent & eventInfo)2464 JSRef<JSVal> WebSslErrorEventToJSValue(const WebSslErrorEvent& eventInfo)
2465 {
2466 JSRef<JSObject> obj = JSRef<JSObject>::New();
2467 JSRef<JSObject> resultObj = JSClass<JSWebSslError>::NewInstance();
2468 auto jsWebSslError = Referenced::Claim(resultObj->Unwrap<JSWebSslError>());
2469 if (!jsWebSslError) {
2470 return JSRef<JSVal>::Cast(obj);
2471 }
2472 jsWebSslError->SetResult(eventInfo.GetResult());
2473 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(resultObj), static_cast<void *>(jsWebSslError.GetRawPtr()));
2474 obj->SetPropertyObject("handler", resultObj);
2475 obj->SetProperty("error", eventInfo.GetError());
2476
2477 auto engine = EngineHelper::GetCurrentEngine();
2478 if (!engine) {
2479 return JSRef<JSVal>::Cast(obj);
2480 }
2481 NativeEngine* nativeEngine = engine->GetNativeEngine();
2482 napi_env env = reinterpret_cast<napi_env>(nativeEngine);
2483 std::vector<std::string> certChainDerData = eventInfo.GetCertChainData();
2484 JSRef<JSArray> certsArr = JSRef<JSArray>::New();
2485 for (uint8_t i = 0; i < certChainDerData.size(); i++) {
2486 if (i == UINT8_MAX) {
2487 TAG_LOGE(AceLogTag::ACE_WEB, "Cert chain data array reach max.");
2488 break;
2489 }
2490
2491 void *data = nullptr;
2492 napi_value buffer = nullptr;
2493 napi_value item = nullptr;
2494 napi_status status = napi_create_arraybuffer(env, certChainDerData[i].size(), &data, &buffer);
2495 if (status != napi_ok) {
2496 TAG_LOGE(AceLogTag::ACE_WEB, "Create array buffer failed, status = %{public}d.", status);
2497 continue;
2498 }
2499 int retCode = memcpy_s(data, certChainDerData[i].size(),
2500 certChainDerData[i].data(), certChainDerData[i].size());
2501 if (retCode != 0) {
2502 TAG_LOGE(AceLogTag::ACE_WEB, "Cert chain data failed, index = %{public}u.", i);
2503 continue;
2504 }
2505 status = napi_create_typedarray(env, napi_uint8_array, certChainDerData[i].size(), buffer, 0, &item);
2506 if (status != napi_ok) {
2507 TAG_LOGE(AceLogTag::ACE_WEB, "Create typed array failed, status = %{public}d.", status);
2508 continue;
2509 }
2510 JSRef<JSVal> cert = JsConverter::ConvertNapiValueToJsVal(item);
2511 certsArr->SetValueAt(i, cert);
2512 }
2513 obj->SetPropertyObject("certChainData", certsArr);
2514 return JSRef<JSVal>::Cast(obj);
2515 }
2516
CreateSslErrorEventReceiveHandler(const WebSslErrorEvent & eventInfo)2517 JSRef<JSVal> JSWeb::CreateSslErrorEventReceiveHandler(const WebSslErrorEvent& eventInfo)
2518 {
2519 JSRef<JSObject> resultObj = JSClass<JSWebSslError>::NewInstance();
2520 auto jsWebSslError = Referenced::Claim(resultObj->Unwrap<JSWebSslError>());
2521 if (!jsWebSslError) {
2522 return resultObj;
2523 }
2524 jsWebSslError->SetResult(eventInfo.GetResult());
2525 return resultObj;
2526 }
2527
WebAllSslErrorEventToJSValue(const WebAllSslErrorEvent & eventInfo)2528 JSRef<JSVal> WebAllSslErrorEventToJSValue(const WebAllSslErrorEvent& eventInfo)
2529 {
2530 JSRef<JSObject> obj = JSRef<JSObject>::New();
2531 JSRef<JSObject> resultObj = JSClass<JSWebAllSslError>::NewInstance();
2532 auto jsWebAllSslError = Referenced::Claim(resultObj->Unwrap<JSWebAllSslError>());
2533 if (!jsWebAllSslError) {
2534 return JSRef<JSVal>::Cast(obj);
2535 }
2536 jsWebAllSslError->SetResult(eventInfo.GetResult());
2537 obj->SetPropertyObject("handler", resultObj);
2538 obj->SetProperty("error", eventInfo.GetError());
2539 obj->SetProperty("url", eventInfo.GetUrl());
2540 obj->SetProperty("originalUrl", eventInfo.GetOriginalUrl());
2541 obj->SetProperty("referrer", eventInfo.GetReferrer());
2542 obj->SetProperty("isFatalError", eventInfo.GetIsFatalError());
2543 obj->SetProperty("isMainFrame", eventInfo.GetIsMainFrame());
2544
2545 auto engine = EngineHelper::GetCurrentEngine();
2546 if (!engine || !engine->GetNativeEngine()) {
2547 return JSRef<JSVal>::Cast(obj);
2548 }
2549 napi_env env = reinterpret_cast<napi_env>(engine->GetNativeEngine());
2550 std::vector<std::string> certChainDerData = eventInfo.GetCertChainData();
2551 JSRef<JSArray> certsArr = JSRef<JSArray>::New();
2552 for (uint8_t i = 0; i < certChainDerData.size(); i++) {
2553 if (i == UINT8_MAX) {
2554 TAG_LOGE(AceLogTag::ACE_WEB, "Cert chain data array reach max.");
2555 break;
2556 }
2557 void *data = nullptr;
2558 napi_value buffer = nullptr;
2559 napi_value item = nullptr;
2560 napi_status status = napi_create_arraybuffer(env, certChainDerData[i].size(), &data, &buffer);
2561 if (status != napi_ok) {
2562 TAG_LOGE(AceLogTag::ACE_WEB, "Create array buffer failed, status = %{public}d.", status);
2563 continue;
2564 }
2565 if (memcpy_s(data, certChainDerData[i].size(), certChainDerData[i].data(), certChainDerData[i].size()) != 0) {
2566 TAG_LOGE(AceLogTag::ACE_WEB, "Cert chain data failed, index = %{public}u.", i);
2567 continue;
2568 }
2569 status = napi_create_typedarray(env, napi_uint8_array, certChainDerData[i].size(), buffer, 0, &item);
2570 if (status != napi_ok) {
2571 TAG_LOGE(AceLogTag::ACE_WEB, "Create typed array failed, status = %{public}d.", status);
2572 continue;
2573 }
2574 JSRef<JSVal> cert = JsConverter::ConvertNapiValueToJsVal(item);
2575 certsArr->SetValueAt(i, cert);
2576 }
2577 obj->SetPropertyObject("certChainData", certsArr);
2578 return JSRef<JSVal>::Cast(obj);
2579 }
2580
CreateSslErrorEventHandler(const WebAllSslErrorEvent & eventInfo)2581 JSRef<JSVal> JSWeb::CreateSslErrorEventHandler(const WebAllSslErrorEvent& eventInfo)
2582 {
2583 JSRef<JSObject> resultObj = JSClass<JSWebAllSslError>::NewInstance();
2584 auto jsWebAllSslError = Referenced::Claim(resultObj->Unwrap<JSWebAllSslError>());
2585 if (!jsWebAllSslError) {
2586 return resultObj;
2587 }
2588 jsWebAllSslError->SetResult(eventInfo.GetResult());
2589 return resultObj;
2590 }
2591
WebSslSelectCertEventToJSValue(const WebSslSelectCertEvent & eventInfo)2592 JSRef<JSVal> WebSslSelectCertEventToJSValue(const WebSslSelectCertEvent& eventInfo)
2593 {
2594 JSRef<JSObject> obj = JSRef<JSObject>::New();
2595 JSRef<JSObject> resultObj = JSClass<JSWebSslSelectCert>::NewInstance();
2596 auto jsWebSslSelectCert = Referenced::Claim(resultObj->Unwrap<JSWebSslSelectCert>());
2597 if (!jsWebSslSelectCert) {
2598 return JSRef<JSVal>::Cast(obj);
2599 }
2600 jsWebSslSelectCert->SetResult(eventInfo.GetResult());
2601 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(resultObj), static_cast<void *>(jsWebSslSelectCert.GetRawPtr()));
2602 obj->SetPropertyObject("handler", resultObj);
2603 obj->SetProperty("host", eventInfo.GetHost());
2604 obj->SetProperty("port", eventInfo.GetPort());
2605
2606 JSRef<JSArray> keyTypesArr = JSRef<JSArray>::New();
2607 const std::vector<std::string>& keyTypes = eventInfo.GetKeyTypes();
2608 for (int32_t idx = 0; idx < static_cast<int32_t>(keyTypes.size()); ++idx) {
2609 JSRef<JSVal> keyType = JSRef<JSVal>::Make(ToJSValue(keyTypes[idx]));
2610 keyTypesArr->SetValueAt(idx, keyType);
2611 }
2612 obj->SetPropertyObject("keyTypes", keyTypesArr);
2613
2614 JSRef<JSArray> issuersArr = JSRef<JSArray>::New();
2615 const std::vector<std::string>& issuers = eventInfo.GetIssuers_();
2616 for (int32_t idx = 0; idx < static_cast<int32_t>(issuers.size()); ++idx) {
2617 JSRef<JSVal> issuer = JSRef<JSVal>::Make(ToJSValue(issuers[idx]));
2618 issuersArr->SetValueAt(idx, issuer);
2619 }
2620
2621 obj->SetPropertyObject("issuers", issuersArr);
2622
2623 return JSRef<JSVal>::Cast(obj);
2624 }
2625
CreateClientAuthenticationRequestHandler(const WebSslSelectCertEvent & eventInfo)2626 JSRef<JSVal> JSWeb::CreateClientAuthenticationRequestHandler(const WebSslSelectCertEvent& eventInfo)
2627 {
2628 JSRef<JSObject> resultObj = JSClass<JSWebSslSelectCert>::NewInstance();
2629 auto jsWebSslSelectCert = Referenced::Claim(resultObj->Unwrap<JSWebSslSelectCert>());
2630 if (!jsWebSslSelectCert) {
2631 return resultObj;
2632 }
2633 jsWebSslSelectCert->SetResult(eventInfo.GetResult());
2634 return resultObj;
2635 }
2636
SearchResultReceiveEventToJSValue(const SearchResultReceiveEvent & eventInfo)2637 JSRef<JSVal> SearchResultReceiveEventToJSValue(const SearchResultReceiveEvent& eventInfo)
2638 {
2639 JSRef<JSObject> obj = JSRef<JSObject>::New();
2640 obj->SetProperty("activeMatchOrdinal", eventInfo.GetActiveMatchOrdinal());
2641 obj->SetProperty("numberOfMatches", eventInfo.GetNumberOfMatches());
2642 obj->SetProperty("isDoneCounting", eventInfo.GetIsDoneCounting());
2643 return JSRef<JSVal>::Cast(obj);
2644 }
2645
LoadOverrideEventToJSValue(const LoadOverrideEvent & eventInfo)2646 JSRef<JSVal> LoadOverrideEventToJSValue(const LoadOverrideEvent& eventInfo)
2647 {
2648 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
2649 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
2650 requestEvent->SetLoadOverrideEvent(eventInfo);
2651 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(requestObj), static_cast<void *>(requestEvent.GetRawPtr()));
2652 return JSRef<JSVal>::Cast(requestObj);
2653 }
2654
CreateOverrideUrlLoadingHandler(const LoadOverrideEvent & eventInfo)2655 JSRef<JSVal> JSWeb::CreateOverrideUrlLoadingHandler(const LoadOverrideEvent& eventInfo)
2656 {
2657 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
2658 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
2659 if (!requestEvent) {
2660 return requestObj;
2661 }
2662 requestEvent->SetLoadOverrideEvent(eventInfo);
2663 return requestObj;
2664 }
2665
AdsBlockedEventToJSValue(const AdsBlockedEvent & eventInfo)2666 JSRef<JSVal> AdsBlockedEventToJSValue(const AdsBlockedEvent& eventInfo)
2667 {
2668 JSRef<JSObject> obj = JSRef<JSObject>::New();
2669 obj->SetProperty("url", eventInfo.GetUrl());
2670
2671 JSRef<JSArray> adsBlockedArr = JSRef<JSArray>::New();
2672 const std::vector<std::string>& adsBlocked = eventInfo.GetAdsBlocked();
2673 for (int32_t idx = 0; idx < static_cast<int32_t>(adsBlocked.size()); ++idx) {
2674 JSRef<JSVal> blockedUrl = JSRef<JSVal>::Make(ToJSValue(adsBlocked[idx]));
2675 adsBlockedArr->SetValueAt(idx, blockedUrl);
2676 }
2677 obj->SetPropertyObject("adsBlocked", adsBlockedArr);
2678
2679 return JSRef<JSVal>::Cast(obj);
2680 }
2681
ParseRawfileWebSrc(const JSRef<JSVal> & srcValue,std::string & webSrc)2682 void JSWeb::ParseRawfileWebSrc(const JSRef<JSVal>& srcValue, std::string& webSrc)
2683 {
2684 if (!srcValue->IsObject() || webSrc.substr(0, RAWFILE_PREFIX.size()) != RAWFILE_PREFIX) {
2685 return;
2686 }
2687 std::string bundleName;
2688 std::string moduleName;
2689 GetJsMediaBundleInfo(srcValue, bundleName, moduleName);
2690 auto container = Container::Current();
2691 CHECK_NULL_VOID(container);
2692 if ((!bundleName.empty() && !moduleName.empty()) &&
2693 (bundleName != container->GetBundleName() || moduleName != container->GetModuleName())) {
2694 webSrc = RAWFILE_PREFIX + BUNDLE_NAME_PREFIX + bundleName + "/" + MODULE_NAME_PREFIX + moduleName + "/" +
2695 webSrc.substr(RAWFILE_PREFIX.size());
2696 }
2697 }
2698
GetJsPixelMap(const FaviconReceivedEvent & eventInfo,JSRef<JSVal> & jsPixelMap)2699 void GetJsPixelMap(const FaviconReceivedEvent& eventInfo, JSRef<JSVal>& jsPixelMap)
2700 {
2701 const RefPtr<WebFaviconReceived>& handler = eventInfo.GetHandler();
2702 if (!handler) {
2703 return;
2704 }
2705 std::shared_ptr<Media::PixelMap> pixelMap = handler->GetPixelMap();
2706 if (!pixelMap) {
2707 return;
2708 }
2709
2710 RefPtr<Framework::JsEngine> engine = EngineHelper::GetCurrentEngine();
2711 if (!engine) {
2712 return;
2713 }
2714 NativeEngine* nativeEngine = engine->GetNativeEngine();
2715 if (!nativeEngine) {
2716 return;
2717 }
2718 napi_env env = reinterpret_cast<napi_env>(nativeEngine);
2719 napi_value napiValue = OHOS::Media::PixelMapNapi::CreatePixelMap(env, pixelMap);
2720 if (!napiValue) {
2721 return;
2722 }
2723
2724 jsPixelMap = JsConverter::ConvertNapiValueToJsVal(napiValue);
2725 }
2726
FaviconReceivedEventToJSValue(const FaviconReceivedEvent & eventInfo)2727 JSRef<JSObject> FaviconReceivedEventToJSValue(const FaviconReceivedEvent& eventInfo)
2728 {
2729 JSRef<JSObject> obj = JSRef<JSObject>::New();
2730 if (obj.IsEmpty()) {
2731 return JSRef<JSVal>::Cast(obj);
2732 }
2733
2734 JSRef<JSVal> jsPixelMap;
2735 GetJsPixelMap(eventInfo, jsPixelMap);
2736 if (jsPixelMap.IsEmpty()) {
2737 return JSRef<JSVal>::Cast(obj);
2738 }
2739
2740 obj->SetPropertyObject("favicon", jsPixelMap);
2741 return JSRef<JSObject>::Cast(obj);
2742 }
2743
SetCallbackFromController(const JSRef<JSObject> controller)2744 void JSWeb::SetCallbackFromController(const JSRef<JSObject> controller)
2745 {
2746 auto setWebDetachFunction = controller->GetProperty("setWebDetach");
2747 std::function<void(int32_t)> setWebDetachCallback = nullptr;
2748 if (setWebDetachFunction->IsFunction()) {
2749 setWebDetachCallback = [webviewController = controller, func = JSRef<JSFunc>::Cast(setWebDetachFunction)](
2750 int32_t webId) {
2751 JSRef<JSVal> argv[] = { JSRef<JSVal>::Make(ToJSValue(webId)) };
2752 func->Call(webviewController, 1, argv);
2753 };
2754 }
2755
2756 auto setFaviconFunction = controller->GetProperty("innerSetFavicon");
2757 std::function<void(const std::shared_ptr<BaseEventInfo>&)> setFaviconCallback = nullptr;
2758 if (setFaviconFunction->IsFunction()) {
2759 setFaviconCallback = [webviewController = controller, func = JSRef<JSFunc>::Cast(setFaviconFunction)](
2760 std::shared_ptr<BaseEventInfo> param) {
2761 if (!param) {
2762 return;
2763 }
2764
2765 napi_env env = GetNapiEnv();
2766 if (!env) {
2767 return;
2768 }
2769 napi_handle_scope scope = nullptr;
2770 auto napi_status = napi_open_handle_scope(env, &scope);
2771 if (napi_status != napi_ok) {
2772 return;
2773 }
2774
2775 JSRef<JSVal> argv[] = {
2776 FaviconReceivedEventToJSValue(static_cast<const FaviconReceivedEvent&>(*param)) };
2777 func->Call(webviewController, 1, argv);
2778
2779 napi_close_handle_scope(env, scope);
2780 };
2781 }
2782
2783 auto setRequestPermissionsFromUserFunction = controller->GetProperty("requestPermissionsFromUserWeb");
2784 std::function<void(const std::shared_ptr<BaseEventInfo>&)> requestPermissionsFromUserCallback = nullptr;
2785 if (setRequestPermissionsFromUserFunction->IsFunction()) {
2786 requestPermissionsFromUserCallback = [webviewController = controller,
2787 func = JSRef<JSFunc>::Cast(setRequestPermissionsFromUserFunction)]
2788 (const std::shared_ptr<BaseEventInfo>& info) {
2789 auto* eventInfo = TypeInfoHelper::DynamicCast<WebPermissionRequestEvent>(info.get());
2790 if (!eventInfo) {
2791 return;
2792 }
2793 JSRef<JSObject> obj = JSRef<JSObject>::New();
2794 JSRef<JSObject> permissionObj = JSClass<JSWebPermissionRequest>::NewInstance();
2795 auto permissionEvent = Referenced::Claim(permissionObj->Unwrap<JSWebPermissionRequest>());
2796 permissionEvent->SetEvent(*eventInfo);
2797 obj->SetPropertyObject("request", permissionObj);
2798 JSRef<JSVal> argv[] = { JSRef<JSVal>::Cast(obj) };
2799 auto result = func->Call(webviewController, 1, argv);
2800 };
2801 }
2802
2803 auto setOpenAppLinkFunction = controller->GetProperty("openAppLink");
2804 std::function<void(const std::shared_ptr<BaseEventInfo>&)> openAppLinkCallback = nullptr;
2805 if (setOpenAppLinkFunction->IsFunction()) {
2806 TAG_LOGD(AceLogTag::ACE_WEB, "WebDelegate::OnOpenAppLink setOpenAppLinkFunction 2");
2807 openAppLinkCallback = [webviewController = controller,
2808 func = JSRef<JSFunc>::Cast(setOpenAppLinkFunction)]
2809 (const std::shared_ptr<BaseEventInfo>& info) {
2810 auto* eventInfo = TypeInfoHelper::DynamicCast<WebAppLinkEvent>(info.get());
2811 if (!eventInfo) {
2812 return;
2813 }
2814 JSRef<JSObject> obj = JSRef<JSObject>::New();
2815 JSRef<JSObject> callbackObj = JSClass<JSWebAppLinkCallback>::NewInstance();
2816 auto callbackEvent = Referenced::Claim(callbackObj->Unwrap<JSWebAppLinkCallback>());
2817 callbackEvent->SetEvent(*eventInfo);
2818 obj->SetPropertyObject("result", callbackObj);
2819 JSRef<JSVal> urlVal = JSRef<JSVal>::Make(ToJSValue(eventInfo->GetUrl()));
2820 obj->SetPropertyObject("url", urlVal);
2821 JSRef<JSVal> argv[] = { JSRef<JSVal>::Cast(obj) };
2822 auto result = func->Call(webviewController, 1, argv);
2823 };
2824 }
2825
2826 auto fileSelectorShowFromUserFunction = controller->GetProperty("fileSelectorShowFromUserWeb");
2827 std::function<void(const std::shared_ptr<BaseEventInfo>&)> fileSelectorShowFromUserCallback = nullptr;
2828 if (fileSelectorShowFromUserFunction->IsFunction()) {
2829 fileSelectorShowFromUserCallback = [webviewController = controller,
2830 func = JSRef<JSFunc>::Cast(fileSelectorShowFromUserFunction)]
2831 (const std::shared_ptr<BaseEventInfo>& info) {
2832 auto* eventInfo = TypeInfoHelper::DynamicCast<FileSelectorEvent>(info.get());
2833 if (!eventInfo) {
2834 return;
2835 }
2836 JSRef<JSObject> obj = JSRef<JSObject>::New();
2837 JSRef<JSObject> paramObj = JSClass<JSFileSelectorParam>::NewInstance();
2838 auto fileSelectorParam = Referenced::Claim(paramObj->Unwrap<JSFileSelectorParam>());
2839 fileSelectorParam->SetParam(*eventInfo);
2840 obj->SetPropertyObject("fileparam", paramObj);
2841
2842 JSRef<JSObject> resultObj = JSClass<JSFileSelectorResult>::NewInstance();
2843 auto fileSelectorResult = Referenced::Claim(resultObj->Unwrap<JSFileSelectorResult>());
2844
2845 fileSelectorResult->SetResult(*eventInfo);
2846
2847 obj->SetPropertyObject("fileresult", resultObj);
2848 JSRef<JSVal> argv[] = { JSRef<JSVal>::Cast(obj) };
2849 auto result = func->Call(webviewController, 1, argv);
2850 };
2851 }
2852
2853 WebModel::GetInstance()->SetDefaultFileSelectorShow(std::move(fileSelectorShowFromUserCallback));
2854 WebModel::GetInstance()->SetPermissionClipboard(std::move(requestPermissionsFromUserCallback));
2855 WebModel::GetInstance()->SetOpenAppLinkFunction(std::move(openAppLinkCallback));
2856 WebModel::GetInstance()->SetWebDetachFunction(std::move(setWebDetachCallback));
2857 WebModel::GetInstance()->SetFaviconFunction(std::move(setFaviconCallback));
2858 }
2859
Create(const JSCallbackInfo & info)2860 void JSWeb::Create(const JSCallbackInfo& info)
2861 {
2862 if (info.Length() < 1 || !info[0]->IsObject()) {
2863 return;
2864 }
2865 auto paramObject = JSRef<JSObject>::Cast(info[0]);
2866 JSRef<JSVal> srcValue = paramObject->GetProperty("src");
2867 std::string webSrc;
2868 std::optional<std::string> dstSrc;
2869 if (srcValue->IsString()) {
2870 dstSrc = srcValue->ToString();
2871 } else if (ParseJsMedia(srcValue, webSrc)) {
2872 ParseRawfileWebSrc(srcValue, webSrc);
2873 int np = static_cast<int>(webSrc.find_first_of("/"));
2874 dstSrc = np < 0 ? webSrc : webSrc.erase(np, 1);
2875 }
2876 if (!dstSrc) {
2877 return;
2878 }
2879 auto controllerObj = paramObject->GetProperty("controller");
2880 if (!controllerObj->IsObject()) {
2881 return;
2882 }
2883 JsiRef<JsiValue> type = JsiRef<JsiValue>::Make();
2884 bool isHasType = paramObject->HasProperty("type");
2885 if (isHasType) {
2886 type = paramObject->GetProperty("type");
2887 } else {
2888 type = paramObject->GetProperty("renderMode");
2889 }
2890 RenderMode renderMode = RenderMode::ASYNC_RENDER;
2891 if (type->IsNumber() && (type->ToNumber<int32_t>() >= 0) && (type->ToNumber<int32_t>() <= 1)) {
2892 renderMode = static_cast<RenderMode>(type->ToNumber<int32_t>());
2893 }
2894 std::string debugRenderMode = SystemProperties::GetWebDebugRenderMode();
2895 if (debugRenderMode != "none") {
2896 if (debugRenderMode == "async") {
2897 renderMode = RenderMode::ASYNC_RENDER;
2898 } else if (debugRenderMode == "sync") {
2899 renderMode = RenderMode::SYNC_RENDER;
2900 } else {
2901 TAG_LOGW(AceLogTag::ACE_WEB, "JSWeb::Create unsupport debug render mode: %{public}s",
2902 debugRenderMode.c_str());
2903 }
2904 TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::Create use debug render mode: %{public}s", debugRenderMode.c_str());
2905 }
2906
2907 bool incognitoMode = false;
2908 ParseJsBool(paramObject->GetProperty("incognitoMode"), incognitoMode);
2909
2910 std::string sharedRenderProcessToken = "";
2911 ParseJsString(paramObject->GetProperty("sharedRenderProcessToken"), sharedRenderProcessToken);
2912
2913 auto controller = JSRef<JSObject>::Cast(controllerObj);
2914 auto setWebIdFunction = controller->GetProperty("setWebId");
2915 if (setWebIdFunction->IsFunction()) {
2916 auto setIdCallback = [webviewController = controller, func = JSRef<JSFunc>::Cast(setWebIdFunction)](
2917 int32_t webId) {
2918 JSRef<JSVal> argv[] = { JSRef<JSVal>::Make(ToJSValue(webId)) };
2919 func->Call(webviewController, 1, argv);
2920 };
2921
2922 auto setHapPathFunction = controller->GetProperty("innerSetHapPath");
2923 std::function<void(const std::string&)> setHapPathCallback = nullptr;
2924 if (setHapPathFunction->IsFunction()) {
2925 setHapPathCallback = [webviewController = controller, func = JSRef<JSFunc>::Cast(setHapPathFunction)](
2926 const std::string& hapPath) {
2927 JSRef<JSVal> argv[] = { JSRef<JSVal>::Make(ToJSValue(hapPath)) };
2928 func->Call(webviewController, 1, argv);
2929 };
2930 }
2931
2932 int32_t parentNWebId = -1;
2933 bool isPopup = JSWebWindowNewHandler::ExistController(controller, parentNWebId);
2934 WebModel::GetInstance()->Create(isPopup ? "" : dstSrc.value(), std::move(setIdCallback),
2935 std::move(setHapPathCallback), parentNWebId, isPopup, renderMode, incognitoMode, sharedRenderProcessToken);
2936
2937 JSWeb::SetCallbackFromController(controller);
2938
2939 auto getCmdLineFunction = controller->GetProperty("getCustomeSchemeCmdLine");
2940 if (!getCmdLineFunction->IsFunction()) {
2941 return;
2942 }
2943 std::string cmdLine = JSRef<JSFunc>::Cast(getCmdLineFunction)->Call(controller, 0, {})->ToString();
2944 if (!cmdLine.empty()) {
2945 WebModel::GetInstance()->SetCustomScheme(cmdLine);
2946 }
2947
2948 auto updateInstanceIdFunction = controller->GetProperty("updateInstanceId");
2949 if (updateInstanceIdFunction->IsFunction()) {
2950 std::function<void(int32_t)> updateInstanceIdCallback = [webviewController = controller,
2951 func = JSRef<JSFunc>::Cast(updateInstanceIdFunction)](int32_t newId) {
2952 auto newIdVal = JSRef<JSVal>::Make(ToJSValue(newId));
2953 auto result = func->Call(webviewController, 1, &newIdVal);
2954 };
2955 NG::WebModelNG::GetInstance()->SetUpdateInstanceIdCallback(std::move(updateInstanceIdCallback));
2956 }
2957
2958 auto getWebDebugingFunction = controller->GetProperty("getWebDebuggingAccess");
2959 if (!getWebDebugingFunction->IsFunction()) {
2960 return;
2961 }
2962 bool webDebuggingAccess = JSRef<JSFunc>::Cast(getWebDebugingFunction)->Call(controller, 0, {})->ToBoolean();
2963 int32_t webDebuggingPort = 0;
2964 auto getWebDebuggingPortFunction = controller->GetProperty("getWebDebuggingPort");
2965 if (getWebDebuggingPortFunction->IsFunction()) {
2966 webDebuggingPort = JSRef<JSFunc>::Cast(getWebDebuggingPortFunction)
2967 ->Call(controller, 0, {})
2968 ->ToNumber<int32_t>();
2969 }
2970
2971 // Don't compare JSWeb::webDebuggingAccess_ and webDebuggingAccess, call SetWebDebuggingAccess directly.
2972 // To ensure JSWeb::webDebuggingAccess_ always equals to WebPattern's class member.
2973 if (webDebuggingPort > 0) {
2974 WebModel::GetInstance()->SetWebDebuggingAccessEnabledAndPort(
2975 webDebuggingAccess, webDebuggingPort);
2976 } else {
2977 WebModel::GetInstance()->SetWebDebuggingAccessEnabled(webDebuggingAccess);
2978 }
2979 JSWeb::webDebuggingAccess_ = webDebuggingAccess;
2980 JSWeb::webDebuggingPort_ = webDebuggingPort;
2981 return;
2982
2983 } else {
2984 auto* jsWebController = controller->Unwrap<JSWebController>();
2985 CHECK_NULL_VOID(jsWebController);
2986 WebModel::GetInstance()->Create(
2987 dstSrc.value(), jsWebController->GetController(), renderMode, incognitoMode, sharedRenderProcessToken);
2988 }
2989
2990 WebModel::GetInstance()->SetFocusable(true);
2991 WebModel::GetInstance()->SetFocusNode(true);
2992 }
2993
WebRotate(const JSCallbackInfo & args)2994 void JSWeb::WebRotate(const JSCallbackInfo& args) {}
2995
OnAlert(const JSCallbackInfo & args)2996 void JSWeb::OnAlert(const JSCallbackInfo& args)
2997 {
2998 JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_ALERT);
2999 }
3000
OnBeforeUnload(const JSCallbackInfo & args)3001 void JSWeb::OnBeforeUnload(const JSCallbackInfo& args)
3002 {
3003 JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_BEFORE_UNLOAD);
3004 }
3005
OnConfirm(const JSCallbackInfo & args)3006 void JSWeb::OnConfirm(const JSCallbackInfo& args)
3007 {
3008 JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_CONFIRM);
3009 }
3010
OnPrompt(const JSCallbackInfo & args)3011 void JSWeb::OnPrompt(const JSCallbackInfo& args)
3012 {
3013 JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_PROMPT);
3014 }
3015
OnCommonDialog(const JSCallbackInfo & args,int dialogEventType)3016 void JSWeb::OnCommonDialog(const JSCallbackInfo& args, int dialogEventType)
3017 {
3018 if (!args[0]->IsFunction()) {
3019 return;
3020 }
3021 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3022 auto jsFunc =
3023 AceType::MakeRefPtr<JsEventFunction<WebDialogEvent, 1>>(JSRef<JSFunc>::Cast(args[0]), WebDialogEventToJSValue);
3024 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3025 const BaseEventInfo* info) -> bool {
3026 auto webNode = node.Upgrade();
3027 CHECK_NULL_RETURN(webNode, false);
3028 ContainerScope scope(webNode->GetInstanceId());
3029 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3030 auto pipelineContext = PipelineContext::GetCurrentContext();
3031 if (pipelineContext) {
3032 pipelineContext->UpdateCurrentActiveNode(node);
3033 }
3034 auto* eventInfo = TypeInfoHelper::DynamicCast<WebDialogEvent>(info);
3035 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3036 if (message->IsBoolean()) {
3037 return message->ToBoolean();
3038 } else {
3039 return false;
3040 }
3041 };
3042 WebModel::GetInstance()->SetOnCommonDialog(jsCallback, dialogEventType);
3043 }
3044
OnConsoleLog(const JSCallbackInfo & args)3045 void JSWeb::OnConsoleLog(const JSCallbackInfo& args)
3046 {
3047 if (!args[0]->IsFunction()) {
3048 return;
3049 }
3050 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebConsoleLogEvent, 1>>(
3051 JSRef<JSFunc>::Cast(args[0]), LoadWebConsoleLogEventToJSValue);
3052
3053 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3054 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3055 const BaseEventInfo* info) -> bool {
3056 bool result = false;
3057 auto webNode = node.Upgrade();
3058 CHECK_NULL_RETURN(webNode, false);
3059 ContainerScope scope(webNode->GetInstanceId());
3060 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, result);
3061 auto pipelineContext = PipelineContext::GetCurrentContext();
3062 if (pipelineContext) {
3063 pipelineContext->UpdateCurrentActiveNode(node);
3064 }
3065 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebConsoleLogEvent>(info);
3066 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3067 if (message->IsBoolean()) {
3068 result = message->ToBoolean();
3069 }
3070 return result;
3071 };
3072
3073 WebModel::GetInstance()->SetOnConsoleLog(jsCallback);
3074 }
3075
OnPageStart(const JSCallbackInfo & args)3076 void JSWeb::OnPageStart(const JSCallbackInfo& args)
3077 {
3078 if (!args[0]->IsFunction()) {
3079 return;
3080 }
3081 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebPageStartEvent, 1>>(
3082 JSRef<JSFunc>::Cast(args[0]), LoadEventToJSValue);
3083
3084 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3085 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3086 const BaseEventInfo* info) {
3087 auto webNode = node.Upgrade();
3088 CHECK_NULL_VOID(webNode);
3089 ContainerScope scope(webNode->GetInstanceId());
3090 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3091 auto pipelineContext = PipelineContext::GetCurrentContext();
3092 if (pipelineContext) {
3093 pipelineContext->UpdateCurrentActiveNode(node);
3094 }
3095 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebPageStartEvent>(info);
3096 func->Execute(*eventInfo);
3097 };
3098 WebModel::GetInstance()->SetOnPageStart(jsCallback);
3099 }
3100
OnPageFinish(const JSCallbackInfo & args)3101 void JSWeb::OnPageFinish(const JSCallbackInfo& args)
3102 {
3103 if (!args[0]->IsFunction()) {
3104 return;
3105 }
3106 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebPageFinishEvent, 1>>(
3107 JSRef<JSFunc>::Cast(args[0]), LoadEventToJSValue);
3108
3109 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3110 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3111 const BaseEventInfo* info) {
3112 auto webNode = node.Upgrade();
3113 CHECK_NULL_VOID(webNode);
3114 ContainerScope scope(webNode->GetInstanceId());
3115 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3116 auto pipelineContext = PipelineContext::GetCurrentContext();
3117 if (pipelineContext) {
3118 pipelineContext->UpdateCurrentActiveNode(node);
3119 }
3120 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebPageFinishEvent>(info);
3121 func->Execute(*eventInfo);
3122 };
3123 WebModel::GetInstance()->SetOnPageFinish(jsCallback);
3124 }
3125
OnProgressChange(const JSCallbackInfo & args)3126 void JSWeb::OnProgressChange(const JSCallbackInfo& args)
3127 {
3128 if (args.Length() < 1 || !args[0]->IsFunction()) {
3129 return;
3130 }
3131 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebProgressChangeEvent, 1>>(
3132 JSRef<JSFunc>::Cast(args[0]), LoadWebProgressChangeEventToJSValue);
3133
3134 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3135 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3136 const BaseEventInfo* info) {
3137 auto webNode = node.Upgrade();
3138 CHECK_NULL_VOID(webNode);
3139 ContainerScope scope(webNode->GetInstanceId());
3140 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3141 auto pipelineContext = PipelineContext::GetCurrentContext();
3142 if (pipelineContext) {
3143 pipelineContext->UpdateCurrentActiveNode(node);
3144 }
3145 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebProgressChangeEvent>(info);
3146 func->ExecuteWithValue(*eventInfo);
3147 };
3148 WebModel::GetInstance()->SetOnProgressChange(jsCallback);
3149 }
3150
OnTitleReceive(const JSCallbackInfo & args)3151 void JSWeb::OnTitleReceive(const JSCallbackInfo& args)
3152 {
3153 if (!args[0]->IsFunction()) {
3154 return;
3155 }
3156 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3157 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebTitleReceiveEvent, 1>>(
3158 JSRef<JSFunc>::Cast(args[0]), LoadWebTitleReceiveEventToJSValue);
3159 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3160 const BaseEventInfo* info) {
3161 auto webNode = node.Upgrade();
3162 CHECK_NULL_VOID(webNode);
3163 ContainerScope scope(webNode->GetInstanceId());
3164 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3165 auto pipelineContext = PipelineContext::GetCurrentContext();
3166 if (pipelineContext) {
3167 pipelineContext->UpdateCurrentActiveNode(node);
3168 }
3169 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebTitleReceiveEvent>(info);
3170 func->Execute(*eventInfo);
3171 };
3172 WebModel::GetInstance()->SetOnTitleReceive(jsCallback);
3173 }
3174
OnFullScreenExit(const JSCallbackInfo & args)3175 void JSWeb::OnFullScreenExit(const JSCallbackInfo& args)
3176 {
3177 if (!args[0]->IsFunction()) {
3178 return;
3179 }
3180 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3181 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FullScreenExitEvent, 1>>(
3182 JSRef<JSFunc>::Cast(args[0]), FullScreenExitEventToJSValue);
3183 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3184 const BaseEventInfo* info) {
3185 auto webNode = node.Upgrade();
3186 CHECK_NULL_VOID(webNode);
3187 ContainerScope scope(webNode->GetInstanceId());
3188 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3189 auto pipelineContext = PipelineContext::GetCurrentContext();
3190 if (pipelineContext) {
3191 pipelineContext->UpdateCurrentActiveNode(node);
3192 }
3193 auto* eventInfo = TypeInfoHelper::DynamicCast<FullScreenExitEvent>(info);
3194 func->Execute(*eventInfo);
3195 };
3196 WebModel::GetInstance()->SetOnFullScreenExit(jsCallback);
3197 }
3198
OnFullScreenEnter(const JSCallbackInfo & args)3199 void JSWeb::OnFullScreenEnter(const JSCallbackInfo& args)
3200 {
3201 if (args.Length() < 1 || !args[0]->IsFunction()) {
3202 return;
3203 }
3204 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3205 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FullScreenEnterEvent, 1>>(
3206 JSRef<JSFunc>::Cast(args[0]), FullScreenEnterEventToJSValue);
3207 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3208 const BaseEventInfo* info) {
3209 auto webNode = node.Upgrade();
3210 CHECK_NULL_VOID(webNode);
3211 ContainerScope scope(webNode->GetInstanceId());
3212 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3213 CHECK_NULL_VOID(func);
3214 auto pipelineContext = PipelineContext::GetCurrentContext();
3215 if (pipelineContext) {
3216 pipelineContext->UpdateCurrentActiveNode(node);
3217 }
3218 auto* eventInfo = TypeInfoHelper::DynamicCast<FullScreenEnterEvent>(info);
3219 CHECK_NULL_VOID(eventInfo);
3220 func->Execute(*eventInfo);
3221 };
3222 WebModel::GetInstance()->SetOnFullScreenEnter(jsCallback);
3223 }
3224
OnGeolocationHide(const JSCallbackInfo & args)3225 void JSWeb::OnGeolocationHide(const JSCallbackInfo& args)
3226 {
3227 if (!args[0]->IsFunction()) {
3228 return;
3229 }
3230 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3231 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebGeolocationHideEvent, 1>>(
3232 JSRef<JSFunc>::Cast(args[0]), LoadWebGeolocationHideEventToJSValue);
3233 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3234 const BaseEventInfo* info) {
3235 auto webNode = node.Upgrade();
3236 CHECK_NULL_VOID(webNode);
3237 ContainerScope scope(webNode->GetInstanceId());
3238 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3239 auto pipelineContext = PipelineContext::GetCurrentContext();
3240 if (pipelineContext) {
3241 pipelineContext->UpdateCurrentActiveNode(node);
3242 }
3243 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebGeolocationHideEvent>(info);
3244 func->Execute(*eventInfo);
3245 };
3246 WebModel::GetInstance()->SetOnGeolocationHide(jsCallback);
3247 }
3248
OnGeolocationShow(const JSCallbackInfo & args)3249 void JSWeb::OnGeolocationShow(const JSCallbackInfo& args)
3250 {
3251 if (!args[0]->IsFunction()) {
3252 return;
3253 }
3254 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3255 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebGeolocationShowEvent, 1>>(
3256 JSRef<JSFunc>::Cast(args[0]), LoadWebGeolocationShowEventToJSValue);
3257 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3258 const BaseEventInfo* info) {
3259 auto webNode = node.Upgrade();
3260 CHECK_NULL_VOID(webNode);
3261 ContainerScope scope(webNode->GetInstanceId());
3262 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3263 auto pipelineContext = PipelineContext::GetCurrentContext();
3264 if (pipelineContext) {
3265 pipelineContext->UpdateCurrentActiveNode(node);
3266 }
3267 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebGeolocationShowEvent>(info);
3268 func->Execute(*eventInfo);
3269 };
3270 WebModel::GetInstance()->SetOnGeolocationShow(jsCallback);
3271 }
3272
OnRequestFocus(const JSCallbackInfo & args)3273 void JSWeb::OnRequestFocus(const JSCallbackInfo& args)
3274 {
3275 if (!args[0]->IsFunction()) {
3276 return;
3277 }
3278 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3279 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebRequestFocusEvent, 1>>(
3280 JSRef<JSFunc>::Cast(args[0]), LoadWebRequestFocusEventToJSValue);
3281 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3282 const BaseEventInfo* info) {
3283 auto webNode = node.Upgrade();
3284 CHECK_NULL_VOID(webNode);
3285 ContainerScope scope(webNode->GetInstanceId());
3286 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3287 auto pipelineContext = PipelineContext::GetCurrentContext();
3288 if (pipelineContext) {
3289 pipelineContext->UpdateCurrentActiveNode(node);
3290 }
3291 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebRequestFocusEvent>(info);
3292 func->Execute(*eventInfo);
3293 };
3294 WebModel::GetInstance()->SetOnRequestFocus(jsCallback);
3295 }
3296
OnDownloadStart(const JSCallbackInfo & args)3297 void JSWeb::OnDownloadStart(const JSCallbackInfo& args)
3298 {
3299 if (!args[0]->IsFunction()) {
3300 return;
3301 }
3302 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3303 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<DownloadStartEvent, 1>>(
3304 JSRef<JSFunc>::Cast(args[0]), DownloadStartEventToJSValue);
3305 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3306 const BaseEventInfo* info) {
3307 auto webNode = node.Upgrade();
3308 CHECK_NULL_VOID(webNode);
3309 ContainerScope scope(webNode->GetInstanceId());
3310 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3311 auto pipelineContext = PipelineContext::GetCurrentContext();
3312 if (pipelineContext) {
3313 pipelineContext->UpdateCurrentActiveNode(node);
3314 }
3315 auto* eventInfo = TypeInfoHelper::DynamicCast<DownloadStartEvent>(info);
3316 func->Execute(*eventInfo);
3317 };
3318 WebModel::GetInstance()->SetOnDownloadStart(jsCallback);
3319 }
3320
OnHttpAuthRequest(const JSCallbackInfo & args)3321 void JSWeb::OnHttpAuthRequest(const JSCallbackInfo& args)
3322 {
3323 if (args.Length() < 1 || !args[0]->IsFunction()) {
3324 return;
3325 }
3326 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3327 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebHttpAuthEvent, 1>>(
3328 JSRef<JSFunc>::Cast(args[0]), WebHttpAuthEventToJSValue);
3329 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3330 const BaseEventInfo* info) -> bool {
3331 auto webNode = node.Upgrade();
3332 CHECK_NULL_RETURN(webNode, false);
3333 ContainerScope scope(webNode->GetInstanceId());
3334 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3335 auto pipelineContext = PipelineContext::GetCurrentContext();
3336 if (pipelineContext) {
3337 pipelineContext->UpdateCurrentActiveNode(node);
3338 }
3339 auto* eventInfo = TypeInfoHelper::DynamicCast<WebHttpAuthEvent>(info);
3340 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3341 if (message->IsBoolean()) {
3342 return message->ToBoolean();
3343 }
3344 return false;
3345 };
3346 WebModel::GetInstance()->SetOnHttpAuthRequest(jsCallback);
3347 }
3348
OnSslErrRequest(const JSCallbackInfo & args)3349 void JSWeb::OnSslErrRequest(const JSCallbackInfo& args)
3350 {
3351 return;
3352 }
3353
OnSslErrorRequest(const JSCallbackInfo & args)3354 void JSWeb::OnSslErrorRequest(const JSCallbackInfo& args)
3355 {
3356 if (args.Length() < 1 || !args[0]->IsFunction()) {
3357 return;
3358 }
3359 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3360 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebSslErrorEvent, 1>>(
3361 JSRef<JSFunc>::Cast(args[0]), WebSslErrorEventToJSValue);
3362 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3363 const BaseEventInfo* info) -> bool {
3364 auto webNode = node.Upgrade();
3365 CHECK_NULL_RETURN(webNode, false);
3366 ContainerScope scope(webNode->GetInstanceId());
3367 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3368 auto pipelineContext = PipelineContext::GetCurrentContext();
3369 if (pipelineContext) {
3370 pipelineContext->UpdateCurrentActiveNode(node);
3371 }
3372 auto* eventInfo = TypeInfoHelper::DynamicCast<WebSslErrorEvent>(info);
3373 func->Execute(*eventInfo);
3374 return true;
3375 };
3376 WebModel::GetInstance()->SetOnSslErrorRequest(jsCallback);
3377 }
3378
OnAllSslErrorRequest(const JSCallbackInfo & args)3379 void JSWeb::OnAllSslErrorRequest(const JSCallbackInfo& args)
3380 {
3381 if (args.Length() < 1 || !args[0]->IsFunction()) {
3382 return;
3383 }
3384 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3385 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebAllSslErrorEvent, 1>>(
3386 JSRef<JSFunc>::Cast(args[0]), WebAllSslErrorEventToJSValue);
3387 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3388 const BaseEventInfo* info) -> bool {
3389 auto webNode = node.Upgrade();
3390 CHECK_NULL_RETURN(webNode, false);
3391 ContainerScope scope(webNode->GetInstanceId());
3392 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3393 auto pipelineContext = PipelineContext::GetCurrentContext();
3394 if (pipelineContext) {
3395 pipelineContext->UpdateCurrentActiveNode(node);
3396 }
3397 auto* eventInfo = TypeInfoHelper::DynamicCast<WebAllSslErrorEvent>(info);
3398 func->Execute(*eventInfo);
3399 return true;
3400 };
3401 WebModel::GetInstance()->SetOnAllSslErrorRequest(jsCallback);
3402 }
3403
OnSslSelectCertRequest(const JSCallbackInfo & args)3404 void JSWeb::OnSslSelectCertRequest(const JSCallbackInfo& args)
3405 {
3406 if (args.Length() < 1 || !args[0]->IsFunction()) {
3407 return;
3408 }
3409 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3410 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebSslSelectCertEvent, 1>>(
3411 JSRef<JSFunc>::Cast(args[0]), WebSslSelectCertEventToJSValue);
3412 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3413 const BaseEventInfo* info) -> bool {
3414 auto webNode = node.Upgrade();
3415 CHECK_NULL_RETURN(webNode, false);
3416 ContainerScope scope(webNode->GetInstanceId());
3417 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3418 auto pipelineContext = PipelineContext::GetCurrentContext();
3419 if (pipelineContext) {
3420 pipelineContext->UpdateCurrentActiveNode(node);
3421 }
3422 auto* eventInfo = TypeInfoHelper::DynamicCast<WebSslSelectCertEvent>(info);
3423 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3424 if (message->IsBoolean()) {
3425 return message->ToBoolean();
3426 }
3427 return false;
3428 };
3429 WebModel::GetInstance()->SetOnSslSelectCertRequest(jsCallback);
3430 }
3431
MediaPlayGestureAccess(bool isNeedGestureAccess)3432 void JSWeb::MediaPlayGestureAccess(bool isNeedGestureAccess)
3433 {
3434 WebModel::GetInstance()->SetMediaPlayGestureAccess(isNeedGestureAccess);
3435 }
3436
OnKeyEvent(const JSCallbackInfo & args)3437 void JSWeb::OnKeyEvent(const JSCallbackInfo& args)
3438 {
3439 if (args.Length() < 1 || !args[0]->IsFunction()) {
3440 return;
3441 }
3442
3443 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3444 RefPtr<JsKeyFunction> jsOnKeyEventFunc = AceType::MakeRefPtr<JsKeyFunction>(JSRef<JSFunc>::Cast(args[0]));
3445 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsOnKeyEventFunc), node = frameNode](
3446 KeyEventInfo& keyEventInfo) {
3447 auto webNode = node.Upgrade();
3448 CHECK_NULL_VOID(webNode);
3449 ContainerScope scope(webNode->GetInstanceId());
3450 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3451 auto pipelineContext = PipelineContext::GetCurrentContext();
3452 if (pipelineContext) {
3453 pipelineContext->UpdateCurrentActiveNode(node);
3454 }
3455 func->Execute(keyEventInfo);
3456 };
3457 WebModel::GetInstance()->SetOnKeyEvent(jsCallback);
3458 }
3459
ReceivedErrorEventToJSValue(const ReceivedErrorEvent & eventInfo)3460 JSRef<JSVal> ReceivedErrorEventToJSValue(const ReceivedErrorEvent& eventInfo)
3461 {
3462 JSRef<JSObject> obj = JSRef<JSObject>::New();
3463
3464 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
3465 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
3466 requestEvent->SetErrorEvent(eventInfo);
3467 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(requestObj), static_cast<void *>(requestEvent.GetRawPtr()));
3468
3469 JSRef<JSObject> errorObj = JSClass<JSWebResourceError>::NewInstance();
3470 auto errorEvent = Referenced::Claim(errorObj->Unwrap<JSWebResourceError>());
3471 errorEvent->SetEvent(eventInfo);
3472
3473 obj->SetPropertyObject("request", requestObj);
3474 obj->SetPropertyObject("error", errorObj);
3475
3476 return JSRef<JSVal>::Cast(obj);
3477 }
3478
CreateRequestErrorHandler(const ReceivedErrorEvent & eventInfo)3479 JSRef<JSVal> JSWeb::CreateRequestErrorHandler(const ReceivedErrorEvent& eventInfo)
3480 {
3481 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
3482 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
3483 if (!requestEvent) {
3484 return requestObj;
3485 }
3486 requestEvent->SetErrorEvent(eventInfo);
3487 return requestObj;
3488 }
3489
CreateResponseErrorHandler(const ReceivedErrorEvent & eventInfo)3490 JSRef<JSVal> JSWeb::CreateResponseErrorHandler(const ReceivedErrorEvent& eventInfo)
3491 {
3492 JSRef<JSObject> errorObj = JSClass<JSWebResourceError>::NewInstance();
3493 auto errorEvent = Referenced::Claim(errorObj->Unwrap<JSWebResourceError>());
3494 if (!errorEvent) {
3495 return errorObj;
3496 }
3497 errorEvent->SetEvent(eventInfo);
3498 return errorObj;
3499 }
3500
ReceivedHttpErrorEventToJSValue(const ReceivedHttpErrorEvent & eventInfo)3501 JSRef<JSVal> ReceivedHttpErrorEventToJSValue(const ReceivedHttpErrorEvent& eventInfo)
3502 {
3503 JSRef<JSObject> obj = JSRef<JSObject>::New();
3504
3505 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
3506 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
3507 requestEvent->SetHttpErrorEvent(eventInfo);
3508 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(requestObj), static_cast<void *>(requestEvent.GetRawPtr()));
3509
3510 JSRef<JSObject> responseObj = JSClass<JSWebResourceResponse>::NewInstance();
3511 auto responseEvent = Referenced::Claim(responseObj->Unwrap<JSWebResourceResponse>());
3512 responseEvent->SetEvent(eventInfo);
3513 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(responseObj), static_cast<void *>(responseEvent.GetRawPtr()));
3514
3515 obj->SetPropertyObject("request", requestObj);
3516 obj->SetPropertyObject("response", responseObj);
3517
3518 return JSRef<JSVal>::Cast(obj);
3519 }
3520
CreateHttpErrorReceiveRequestHandler(const ReceivedHttpErrorEvent & eventInfo)3521 JSRef<JSVal> JSWeb::CreateHttpErrorReceiveRequestHandler(const ReceivedHttpErrorEvent& eventInfo)
3522 {
3523 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
3524 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
3525 if (!requestEvent) {
3526 return requestObj;
3527 }
3528 requestEvent->SetHttpErrorEvent(eventInfo);
3529 return requestObj;
3530 }
3531
CreateHttpErrorReceiveResponseHandler(const ReceivedHttpErrorEvent & eventInfo)3532 JSRef<JSVal> JSWeb::CreateHttpErrorReceiveResponseHandler(const ReceivedHttpErrorEvent& eventInfo)
3533 {
3534 JSRef<JSObject> responseObj = JSClass<JSWebResourceResponse>::NewInstance();
3535 auto responseEvent = Referenced::Claim(responseObj->Unwrap<JSWebResourceResponse>());
3536 if (!responseEvent) {
3537 return responseObj;
3538 }
3539 responseEvent->SetEvent(eventInfo);
3540 return responseObj;
3541 }
3542
OnErrorReceive(const JSCallbackInfo & args)3543 void JSWeb::OnErrorReceive(const JSCallbackInfo& args)
3544 {
3545 if (!args[0]->IsFunction()) {
3546 return;
3547 }
3548 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3549 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ReceivedErrorEvent, 1>>(
3550 JSRef<JSFunc>::Cast(args[0]), ReceivedErrorEventToJSValue);
3551 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3552 const BaseEventInfo* info) {
3553 auto webNode = node.Upgrade();
3554 CHECK_NULL_VOID(webNode);
3555 ContainerScope scope(webNode->GetInstanceId());
3556 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3557 auto pipelineContext = PipelineContext::GetCurrentContext();
3558 if (pipelineContext) {
3559 pipelineContext->UpdateCurrentActiveNode(node);
3560 }
3561 auto* eventInfo = TypeInfoHelper::DynamicCast<ReceivedErrorEvent>(info);
3562 func->Execute(*eventInfo);
3563 };
3564 WebModel::GetInstance()->SetOnErrorReceive(jsCallback);
3565 }
3566
OnHttpErrorReceive(const JSCallbackInfo & args)3567 void JSWeb::OnHttpErrorReceive(const JSCallbackInfo& args)
3568 {
3569 if (!args[0]->IsFunction()) {
3570 return;
3571 }
3572 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3573 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ReceivedHttpErrorEvent, 1>>(
3574 JSRef<JSFunc>::Cast(args[0]), ReceivedHttpErrorEventToJSValue);
3575 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3576 const BaseEventInfo* info) {
3577 auto webNode = node.Upgrade();
3578 CHECK_NULL_VOID(webNode);
3579 ContainerScope scope(webNode->GetInstanceId());
3580 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3581 auto pipelineContext = PipelineContext::GetCurrentContext();
3582 if (pipelineContext) {
3583 pipelineContext->UpdateCurrentActiveNode(node);
3584 }
3585 auto* eventInfo = TypeInfoHelper::DynamicCast<ReceivedHttpErrorEvent>(info);
3586 func->Execute(*eventInfo);
3587 };
3588 WebModel::GetInstance()->SetOnHttpErrorReceive(jsCallback);
3589 }
3590
OnInterceptRequestEventToJSValue(const OnInterceptRequestEvent & eventInfo)3591 JSRef<JSVal> OnInterceptRequestEventToJSValue(const OnInterceptRequestEvent& eventInfo)
3592 {
3593 JSRef<JSObject> obj = JSRef<JSObject>::New();
3594 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
3595 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
3596 requestEvent->SetOnInterceptRequestEvent(eventInfo);
3597 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(requestObj), static_cast<void *>(requestEvent.GetRawPtr()));
3598 obj->SetPropertyObject("request", requestObj);
3599 return JSRef<JSVal>::Cast(obj);
3600 }
3601
CreateInterceptRequestHandler(const OnInterceptRequestEvent & eventInfo)3602 JSRef<JSVal> JSWeb::CreateInterceptRequestHandler(const OnInterceptRequestEvent& eventInfo)
3603 {
3604 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
3605 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
3606 if (!requestEvent) {
3607 return requestObj;
3608 }
3609 requestEvent->SetOnInterceptRequestEvent(eventInfo);
3610 return requestObj;
3611 }
3612
OnInterceptRequest(const JSCallbackInfo & args)3613 void JSWeb::OnInterceptRequest(const JSCallbackInfo& args)
3614 {
3615 if ((args.Length() <= 0) || !args[0]->IsFunction()) {
3616 return;
3617 }
3618 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3619 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<OnInterceptRequestEvent, 1>>(
3620 JSRef<JSFunc>::Cast(args[0]), OnInterceptRequestEventToJSValue);
3621 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3622 const BaseEventInfo* info) -> RefPtr<WebResponse> {
3623 auto webNode = node.Upgrade();
3624 CHECK_NULL_RETURN(webNode, nullptr);
3625 ContainerScope scope(webNode->GetInstanceId());
3626 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, nullptr);
3627 auto pipelineContext = PipelineContext::GetCurrentContext();
3628 if (pipelineContext) {
3629 pipelineContext->UpdateCurrentActiveNode(node);
3630 }
3631 auto* eventInfo = TypeInfoHelper::DynamicCast<OnInterceptRequestEvent>(info);
3632 JSRef<JSVal> obj = func->ExecuteWithValue(*eventInfo);
3633 if (!obj->IsObject()) {
3634 return nullptr;
3635 }
3636 auto jsResponse = JSRef<JSObject>::Cast(obj)->Unwrap<JSWebResourceResponse>();
3637 if (jsResponse) {
3638 return jsResponse->GetResponseObj();
3639 }
3640 return nullptr;
3641 };
3642 WebModel::GetInstance()->SetOnInterceptRequest(jsCallback);
3643 }
3644
OnOverrideErrorPageEventToJSValue(const OnOverrideErrorPageEvent & eventInfo)3645 JSRef<JSVal> OnOverrideErrorPageEventToJSValue(const OnOverrideErrorPageEvent& eventInfo)
3646 {
3647 JSRef<JSObject> obj = JSRef<JSObject>::New();
3648 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
3649 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
3650 requestEvent->SetOnOverrideErrorPageEvent(eventInfo);
3651
3652 JSRef<JSObject> errorObj = JSClass<JSWebResourceError>::NewInstance();
3653 auto errorEvent = Referenced::Claim(errorObj->Unwrap<JSWebResourceError>());
3654 errorEvent->SetOverrideErrorPageEvent(eventInfo);
3655
3656 obj->SetPropertyObject("request", requestObj);
3657 obj->SetPropertyObject("error", errorObj);
3658
3659 return JSRef<JSVal>::Cast(obj);
3660 }
3661
OnOverrideErrorPage(const JSCallbackInfo & args)3662 void JSWeb::OnOverrideErrorPage(const JSCallbackInfo& args)
3663 {
3664 RETURN_IF_CALLING_FROM_M114();
3665 if ((args.Length() <= 0) || !args[0]->IsFunction()) {
3666 return;
3667 }
3668 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3669 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<OnOverrideErrorPageEvent, 1>>(
3670 JSRef<JSFunc>::Cast(args[0]), OnOverrideErrorPageEventToJSValue);
3671 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3672 const BaseEventInfo* info) -> std::string {
3673 auto webNode = node.Upgrade();
3674 CHECK_NULL_RETURN(webNode, nullptr);
3675 ContainerScope scope(webNode->GetInstanceId());
3676 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, nullptr);
3677 auto pipelineContext = PipelineContext::GetCurrentContext();
3678 if (pipelineContext) {
3679 pipelineContext->UpdateCurrentActiveNode(node);
3680 }
3681 auto* eventInfo = TypeInfoHelper::DynamicCast<OnOverrideErrorPageEvent>(info);
3682 if (!eventInfo) {
3683 return "";
3684 }
3685 JSRef<JSVal> html = func->ExecuteWithValue(*eventInfo);
3686 if (html->IsString()) {
3687 return html->ToString();
3688 }
3689 return "";
3690 };
3691 WebModel::GetInstance()->SetOnOverrideErrorPage(jsCallback);
3692 }
3693
OnUrlLoadIntercept(const JSCallbackInfo & args)3694 void JSWeb::OnUrlLoadIntercept(const JSCallbackInfo& args)
3695 {
3696 if (!args[0]->IsFunction()) {
3697 return;
3698 }
3699 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3700 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<UrlLoadInterceptEvent, 1>>(
3701 JSRef<JSFunc>::Cast(args[0]), UrlLoadInterceptEventToJSValue);
3702 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3703 const BaseEventInfo* info) -> bool {
3704 auto webNode = node.Upgrade();
3705 CHECK_NULL_RETURN(webNode, false);
3706 ContainerScope scope(webNode->GetInstanceId());
3707 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3708 auto pipelineContext = PipelineContext::GetCurrentContext();
3709 if (pipelineContext) {
3710 pipelineContext->UpdateCurrentActiveNode(node);
3711 }
3712 auto* eventInfo = TypeInfoHelper::DynamicCast<UrlLoadInterceptEvent>(info);
3713 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3714 if (message->IsBoolean()) {
3715 return message->ToBoolean();
3716 }
3717 return false;
3718 };
3719 WebModel::GetInstance()->SetOnUrlLoadIntercept(jsCallback);
3720 }
3721
OnLoadIntercept(const JSCallbackInfo & args)3722 void JSWeb::OnLoadIntercept(const JSCallbackInfo& args)
3723 {
3724 if (!args[0]->IsFunction()) {
3725 return;
3726 }
3727 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadInterceptEvent, 1>>(
3728 JSRef<JSFunc>::Cast(args[0]), LoadInterceptEventToJSValue);
3729
3730 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3731 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3732 const BaseEventInfo* info) -> bool {
3733 auto webNode = node.Upgrade();
3734 CHECK_NULL_RETURN(webNode, false);
3735 ContainerScope scope(webNode->GetInstanceId());
3736 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3737 auto pipelineContext = PipelineContext::GetCurrentContext();
3738 if (pipelineContext) {
3739 pipelineContext->UpdateCurrentActiveNode(node);
3740 }
3741 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadInterceptEvent>(info);
3742 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3743 if (message->IsBoolean()) {
3744 return message->ToBoolean();
3745 }
3746 return false;
3747 };
3748 WebModel::GetInstance()->SetOnLoadIntercept(std::move(uiCallback));
3749 }
3750
FileSelectorEventToJSValue(const FileSelectorEvent & eventInfo)3751 JSRef<JSVal> FileSelectorEventToJSValue(const FileSelectorEvent& eventInfo)
3752 {
3753 JSRef<JSObject> obj = JSRef<JSObject>::New();
3754
3755 JSRef<JSObject> paramObj = JSClass<JSFileSelectorParam>::NewInstance();
3756 auto fileSelectorParam = Referenced::Claim(paramObj->Unwrap<JSFileSelectorParam>());
3757 fileSelectorParam->SetParam(eventInfo);
3758 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(paramObj), static_cast<void *>(fileSelectorParam.GetRawPtr()));
3759
3760 JSRef<JSObject> resultObj = JSClass<JSFileSelectorResult>::NewInstance();
3761 auto fileSelectorResult = Referenced::Claim(resultObj->Unwrap<JSFileSelectorResult>());
3762 fileSelectorResult->SetResult(eventInfo);
3763 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(resultObj), static_cast<void *>(fileSelectorResult.GetRawPtr()));
3764
3765 obj->SetPropertyObject("result", resultObj);
3766 obj->SetPropertyObject("fileSelector", paramObj);
3767 return JSRef<JSVal>::Cast(obj);
3768 }
3769
CreateFileSelectorResultHandler(const FileSelectorEvent & eventInfo)3770 JSRef<JSVal> JSWeb::CreateFileSelectorResultHandler(const FileSelectorEvent& eventInfo)
3771 {
3772 JSRef<JSObject> resultObj = JSClass<JSFileSelectorResult>::NewInstance();
3773 auto fileSelectorResult = Referenced::Claim(resultObj->Unwrap<JSFileSelectorResult>());
3774 fileSelectorResult->SetResult(eventInfo);
3775 return resultObj;
3776 }
3777
CreateFileSelectorParamHandler(const FileSelectorEvent & eventInfo)3778 JSRef<JSVal> JSWeb::CreateFileSelectorParamHandler(const FileSelectorEvent& eventInfo)
3779 {
3780 JSRef<JSObject> paramObj = JSClass<JSFileSelectorParam>::NewInstance();
3781 auto fileSelectorParam = Referenced::Claim(paramObj->Unwrap<JSFileSelectorParam>());
3782 fileSelectorParam->SetParam(eventInfo);
3783 return paramObj;
3784 }
3785
OnFileSelectorShow(const JSCallbackInfo & args)3786 void JSWeb::OnFileSelectorShow(const JSCallbackInfo& args)
3787 {
3788 if (!args[0]->IsFunction()) {
3789 return;
3790 }
3791
3792 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3793 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FileSelectorEvent, 1>>(
3794 JSRef<JSFunc>::Cast(args[0]), FileSelectorEventToJSValue);
3795 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3796 const BaseEventInfo* info) -> bool {
3797 auto webNode = node.Upgrade();
3798 CHECK_NULL_RETURN(webNode, false);
3799 ContainerScope scope(webNode->GetInstanceId());
3800 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3801 auto pipelineContext = PipelineContext::GetCurrentContext();
3802 if (pipelineContext) {
3803 pipelineContext->UpdateCurrentActiveNode(node);
3804 }
3805 auto* eventInfo = TypeInfoHelper::DynamicCast<FileSelectorEvent>(info);
3806 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3807 if (message->IsBoolean()) {
3808 return message->ToBoolean();
3809 }
3810 return false;
3811 };
3812 WebModel::GetInstance()->SetOnFileSelectorShow(jsCallback);
3813 }
3814
ContextMenuEventToJSValue(const ContextMenuEvent & eventInfo)3815 JSRef<JSVal> ContextMenuEventToJSValue(const ContextMenuEvent& eventInfo)
3816 {
3817 JSRef<JSObject> obj = JSRef<JSObject>::New();
3818
3819 JSRef<JSObject> paramObj = JSClass<JSContextMenuParam>::NewInstance();
3820 auto contextMenuParam = Referenced::Claim(paramObj->Unwrap<JSContextMenuParam>());
3821 contextMenuParam->SetParam(eventInfo);
3822 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(paramObj), static_cast<void *>(contextMenuParam.GetRawPtr()));
3823
3824 JSRef<JSObject> resultObj = JSClass<JSContextMenuResult>::NewInstance();
3825 auto contextMenuResult = Referenced::Claim(resultObj->Unwrap<JSContextMenuResult>());
3826 contextMenuResult->SetResult(eventInfo);
3827 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(resultObj), static_cast<void *>(contextMenuResult.GetRawPtr()));
3828
3829 obj->SetPropertyObject("result", resultObj);
3830 obj->SetPropertyObject("param", paramObj);
3831 return JSRef<JSVal>::Cast(obj);
3832 }
3833
CreateContextMenuParamHandler(const ContextMenuEvent & eventInfo)3834 JSRef<JSVal> JSWeb::CreateContextMenuParamHandler(const ContextMenuEvent& eventInfo)
3835 {
3836 JSRef<JSObject> paramObj = JSClass<JSContextMenuParam>::NewInstance();
3837 auto contextMenuParam = Referenced::Claim(paramObj->Unwrap<JSContextMenuParam>());
3838 contextMenuParam->SetParam(eventInfo);
3839 return paramObj;
3840 }
3841
CreateContextMenuResultHandler(const ContextMenuEvent & eventInfo)3842 JSRef<JSVal> JSWeb::CreateContextMenuResultHandler(const ContextMenuEvent& eventInfo)
3843 {
3844 JSRef<JSObject> resultObj = JSClass<JSContextMenuResult>::NewInstance();
3845 auto contextMenuResult = Referenced::Claim(resultObj->Unwrap<JSContextMenuResult>());
3846 contextMenuResult->SetResult(eventInfo);
3847 return resultObj;
3848 }
3849
OnContextMenuShow(const JSCallbackInfo & args)3850 void JSWeb::OnContextMenuShow(const JSCallbackInfo& args)
3851 {
3852 if (args.Length() < 1 || !args[0]->IsFunction()) {
3853 return;
3854 }
3855 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3856 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ContextMenuEvent, 1>>(
3857 JSRef<JSFunc>::Cast(args[0]), ContextMenuEventToJSValue);
3858 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
3859 const BaseEventInfo* info) -> bool {
3860 auto webNode = node.Upgrade();
3861 CHECK_NULL_RETURN(webNode, false);
3862 ContainerScope scope(webNode->GetInstanceId());
3863 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3864 auto pipelineContext = PipelineContext::GetCurrentContext();
3865 if (pipelineContext) {
3866 pipelineContext->UpdateCurrentActiveNode(node);
3867 }
3868 auto* eventInfo = TypeInfoHelper::DynamicCast<ContextMenuEvent>(info);
3869 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3870 if (message->IsBoolean()) {
3871 return message->ToBoolean();
3872 }
3873 return false;
3874 };
3875 WebModel::GetInstance()->SetOnContextMenuShow(jsCallback);
3876 }
3877
ParseBindSelectionMenuParam(const JSCallbackInfo & info,const JSRef<JSObject> & menuOptions,NG::MenuParam & menuParam)3878 void ParseBindSelectionMenuParam(
3879 const JSCallbackInfo& info, const JSRef<JSObject>& menuOptions, NG::MenuParam& menuParam)
3880 {
3881 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3882 auto onDisappearValue = menuOptions->GetProperty("onDisappear");
3883 if (onDisappearValue->IsFunction()) {
3884 RefPtr<JsFunction> jsOnDisAppearFunc =
3885 AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(onDisappearValue));
3886 auto onDisappear = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDisAppearFunc),
3887 node = frameNode]() {
3888 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3889 ACE_SCORING_EVENT("onDisappear");
3890 PipelineContext::SetCallBackNode(node);
3891 func->Execute();
3892 };
3893 menuParam.onDisappear = std::move(onDisappear);
3894 }
3895
3896 auto onAppearValue = menuOptions->GetProperty("onAppear");
3897 if (onAppearValue->IsFunction()) {
3898 RefPtr<JsFunction> jsOnAppearFunc =
3899 AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(onAppearValue));
3900 auto onAppear = [execCtx = info.GetExecutionContext(), func = std::move(jsOnAppearFunc),
3901 node = frameNode]() {
3902 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3903 ACE_SCORING_EVENT("onAppear");
3904 PipelineContext::SetCallBackNode(node);
3905 func->Execute();
3906 };
3907 menuParam.onAppear = std::move(onAppear);
3908 }
3909 }
3910
ParseBindSelectionMenuOptionParam(const JSCallbackInfo & info,const JSRef<JSVal> & args,NG::MenuParam & menuParam,std::function<void ()> & previewBuildFunc)3911 void ParseBindSelectionMenuOptionParam(const JSCallbackInfo& info, const JSRef<JSVal>& args,
3912 NG::MenuParam& menuParam, std::function<void()>& previewBuildFunc)
3913 {
3914 auto menuOptions = JSRef<JSObject>::Cast(args);
3915 ParseBindSelectionMenuParam(info, menuOptions, menuParam);
3916
3917 auto preview = menuOptions->GetProperty("preview");
3918 if (!preview->IsFunction()) {
3919 return;
3920 }
3921 auto menuType = menuOptions->GetProperty("menuType");
3922 bool isPreviewMenu = menuType->IsNumber() && menuType->ToNumber<int32_t>() == 1;
3923 menuParam.hapticFeedbackMode = HapticFeedbackMode::DISABLED;
3924 if (isPreviewMenu) {
3925 menuParam.previewMode = MenuPreviewMode::CUSTOM;
3926 auto previewMenuOptions = menuOptions->GetProperty("previewMenuOptions");
3927 if (previewMenuOptions->IsObject()) {
3928 auto previewMenuOptionsObj = JSRef<JSObject>::Cast(previewMenuOptions);
3929 auto hapticFeedbackMode = previewMenuOptionsObj->GetProperty("hapticFeedbackMode");
3930 if (hapticFeedbackMode->IsNumber()) {
3931 menuParam.hapticFeedbackMode = HapticFeedbackMode(hapticFeedbackMode->ToNumber<int32_t>());
3932 }
3933 }
3934 RefPtr<JsFunction> previewBuilderFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(preview));
3935 CHECK_NULL_VOID(previewBuilderFunc);
3936 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3937 previewBuildFunc = [execCtx = info.GetExecutionContext(), func = std::move(previewBuilderFunc),
3938 node = frameNode]() {
3939 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3940 ACE_SCORING_EVENT("BindSelectionMenuPreviwer");
3941 PipelineContext::SetCallBackNode(node);
3942 func->Execute();
3943 };
3944 }
3945 }
3946
GetSelectionMenuParam(const JSCallbackInfo & info,ResponseType responseType,std::function<void ()> & previewBuilder,WebElementType elementType)3947 NG::MenuParam GetSelectionMenuParam(const JSCallbackInfo &info, ResponseType responseType,
3948 std::function<void()> &previewBuilder, WebElementType elementType)
3949 {
3950 NG::MenuParam menuParam;
3951 if (info.Length() > SELECTION_MENU_OPTION_PARAM_INDEX && info[SELECTION_MENU_OPTION_PARAM_INDEX]->IsObject()) {
3952 ParseBindSelectionMenuOptionParam(info, info[SELECTION_MENU_OPTION_PARAM_INDEX], menuParam, previewBuilder);
3953 }
3954
3955 if (responseType != ResponseType::LONG_PRESS) {
3956 menuParam.previewMode = MenuPreviewMode::NONE;
3957 menuParam.menuBindType = MenuBindingType::RIGHT_CLICK;
3958 }
3959 menuParam.contextMenuRegisterType = NG::ContextMenuRegisterType::CUSTOM_TYPE;
3960 menuParam.type = NG::MenuType::CONTEXT_MENU;
3961 NG::PaddingProperty paddings;
3962 paddings.start = NG::CalcLength(PREVIEW_MENU_MARGIN_LEFT);
3963 paddings.end = NG::CalcLength(PREVIEW_MENU_MARGIN_RIGHT);
3964 menuParam.layoutRegionMargin = paddings;
3965 menuParam.disappearScaleToTarget = true;
3966 menuParam.isPreviewContainScale = (elementType == WebElementType::IMAGE);
3967 menuParam.isShow = true;
3968 return menuParam;
3969 }
3970
CheckSelectionMenuParam(const JSCallbackInfo & info)3971 bool CheckSelectionMenuParam(const JSCallbackInfo &info)
3972 {
3973 if (info.Length() < SELECTION_MENU_OPTION_PARAM_INDEX || !info[0]->IsNumber() || !info[1]->IsObject() ||
3974 !info[SELECTION_MENU_CONTENT_PARAM_INDEX]->IsNumber()) {
3975 return false;
3976 }
3977 std::vector<WebElementType> supportType = {WebElementType::IMAGE, WebElementType::LINK};
3978 int32_t elementType = info[0]->ToNumber<int32_t>();
3979 auto supportType_iter = std::find_if(supportType.begin(), supportType.end(), [elementType](auto &type) {
3980 return static_cast<int32_t>(type) == elementType;
3981 });
3982 if (supportType_iter == supportType.end()) {
3983 TAG_LOGW(AceLogTag::ACE_WEB, "WebElementType param err");
3984 return false;
3985 }
3986 if (info[SELECTION_MENU_CONTENT_PARAM_INDEX]->ToNumber<int32_t>() !=
3987 static_cast<int32_t>(ResponseType::LONG_PRESS)) {
3988 TAG_LOGW(AceLogTag::ACE_WEB, "WebResponseType param err");
3989 return false;
3990 }
3991 return true;
3992 }
BindSelectionMenu(const JSCallbackInfo & info)3993 void JSWeb::BindSelectionMenu(const JSCallbackInfo& info)
3994 {
3995 if (!CheckSelectionMenuParam(info)) {
3996 return;
3997 }
3998 WebElementType elementType = static_cast<WebElementType>(info[0]->ToNumber<int32_t>());
3999 if (elementType == WebElementType::LINK) {
4000 RETURN_IF_CALLING_FROM_M114();
4001 }
4002 ResponseType responseType =
4003 static_cast<ResponseType>(info[SELECTION_MENU_CONTENT_PARAM_INDEX]->ToNumber<int32_t>());
4004
4005 // Builder
4006 JSRef<JSObject> menuObj = JSRef<JSObject>::Cast(info[1]);
4007 auto builder = menuObj->GetProperty("builder");
4008 if (!builder->IsFunction()) {
4009 TAG_LOGW(AceLogTag::ACE_WEB, "BindSelectionMenu menu builder param err");
4010 return;
4011 }
4012 auto builderFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(builder));
4013 CHECK_NULL_VOID(builderFunc);
4014 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4015 std::function<void()> menuBuilder = [execCtx = info.GetExecutionContext(), func = std::move(builderFunc),
4016 node = frameNode]() {
4017 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4018 ACE_SCORING_EVENT("BindSelectionMenu");
4019 PipelineContext::SetCallBackNode(node);
4020 func->Execute();
4021 };
4022
4023 std::function<void()> previewBuilder = nullptr;
4024 NG::MenuParam menuParam = GetSelectionMenuParam(info, responseType, previewBuilder, elementType);
4025 WebModel::GetInstance()->SetNewDragStyle(true);
4026 auto previewSelectionMenuParam = std::make_shared<WebPreviewSelectionMenuParam>(
4027 elementType, responseType, menuBuilder, previewBuilder, menuParam);
4028 WebModel::GetInstance()->SetPreviewSelectionMenu(previewSelectionMenuParam);
4029 }
4030
OnContextMenuHide(const JSCallbackInfo & args)4031 void JSWeb::OnContextMenuHide(const JSCallbackInfo& args)
4032 {
4033 if (!args[0]->IsFunction()) {
4034 return;
4035 }
4036 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4037 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ContextMenuHideEvent, 1>>(
4038 JSRef<JSFunc>::Cast(args[0]), ContextMenuHideEventToJSValue);
4039
4040 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4041 const BaseEventInfo* info) {
4042 auto webNode = node.Upgrade();
4043 CHECK_NULL_VOID(webNode);
4044 ContainerScope scope(webNode->GetInstanceId());
4045 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4046 auto pipelineContext = PipelineContext::GetCurrentContext();
4047 if (pipelineContext) {
4048 pipelineContext->UpdateCurrentActiveNode(node);
4049 }
4050 auto* eventInfo = TypeInfoHelper::DynamicCast<ContextMenuHideEvent>(info);
4051 func->Execute(*eventInfo);
4052 };
4053 WebModel::GetInstance()->SetOnContextMenuHide(jsCallback);
4054 }
4055
JsEnabled(bool isJsEnabled)4056 void JSWeb::JsEnabled(bool isJsEnabled)
4057 {
4058 WebModel::GetInstance()->SetJsEnabled(isJsEnabled);
4059 }
4060
ContentAccessEnabled(bool isContentAccessEnabled)4061 void JSWeb::ContentAccessEnabled(bool isContentAccessEnabled)
4062 {
4063 #if !defined(NG_BUILD) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
4064 auto stack = ViewStackProcessor::GetInstance();
4065 auto webComponent = AceType::DynamicCast<WebComponent>(stack->GetMainComponent());
4066 if (!webComponent) {
4067 return;
4068 }
4069 webComponent->SetContentAccessEnabled(isContentAccessEnabled);
4070 #else
4071 TAG_LOGW(AceLogTag::ACE_WEB, "do not support components in new pipeline mode");
4072 #endif
4073 }
4074
FileAccessEnabled(bool isFileAccessEnabled)4075 void JSWeb::FileAccessEnabled(bool isFileAccessEnabled)
4076 {
4077 WebModel::GetInstance()->SetFileAccessEnabled(isFileAccessEnabled);
4078 }
4079
OnLineImageAccessEnabled(bool isOnLineImageAccessEnabled)4080 void JSWeb::OnLineImageAccessEnabled(bool isOnLineImageAccessEnabled)
4081 {
4082 WebModel::GetInstance()->SetOnLineImageAccessEnabled(isOnLineImageAccessEnabled);
4083 }
4084
DomStorageAccessEnabled(bool isDomStorageAccessEnabled)4085 void JSWeb::DomStorageAccessEnabled(bool isDomStorageAccessEnabled)
4086 {
4087 WebModel::GetInstance()->SetDomStorageAccessEnabled(isDomStorageAccessEnabled);
4088 }
4089
ImageAccessEnabled(bool isImageAccessEnabled)4090 void JSWeb::ImageAccessEnabled(bool isImageAccessEnabled)
4091 {
4092 WebModel::GetInstance()->SetImageAccessEnabled(isImageAccessEnabled);
4093 }
4094
MixedMode(int32_t mixedMode)4095 void JSWeb::MixedMode(int32_t mixedMode)
4096 {
4097 auto mixedContentMode = MixedModeContent::MIXED_CONTENT_NEVER_ALLOW;
4098 switch (mixedMode) {
4099 case 0:
4100 mixedContentMode = MixedModeContent::MIXED_CONTENT_ALWAYS_ALLOW;
4101 break;
4102 case 1:
4103 mixedContentMode = MixedModeContent::MIXED_CONTENT_COMPATIBILITY_MODE;
4104 break;
4105 default:
4106 mixedContentMode = MixedModeContent::MIXED_CONTENT_NEVER_ALLOW;
4107 break;
4108 }
4109 WebModel::GetInstance()->SetMixedMode(mixedContentMode);
4110 }
4111
ZoomAccessEnabled(bool isZoomAccessEnabled)4112 void JSWeb::ZoomAccessEnabled(bool isZoomAccessEnabled)
4113 {
4114 WebModel::GetInstance()->SetZoomAccessEnabled(isZoomAccessEnabled);
4115 }
4116
EnableNativeEmbedMode(bool isEmbedModeEnabled)4117 void JSWeb::EnableNativeEmbedMode(bool isEmbedModeEnabled)
4118 {
4119 WebModel::GetInstance()->SetNativeEmbedModeEnabled(isEmbedModeEnabled);
4120 }
4121
NativeEmbedOptions(const JSCallbackInfo & args)4122 void JSWeb::NativeEmbedOptions(const JSCallbackInfo& args)
4123 {
4124 if (args.Length() < 1 || !args[0]->IsObject()) {
4125 return;
4126 }
4127 auto paramObject = JSRef<JSObject>::Cast(args[0]);
4128 std::optional<bool> enable;
4129 JSRef<JSVal> enableJsValue = paramObject->GetProperty("supportDefaultIntrinsicSize");
4130 if (enableJsValue->IsBoolean()) {
4131 enable = enableJsValue->ToBoolean();
4132 WebModel::GetInstance()->SetIntrinsicSizeEnabled(*enable);
4133 }
4134
4135 RETURN_IF_CALLING_FROM_M114();
4136 auto cssDisplayChangeObj = paramObject->GetProperty("supportCssDisplayChange");
4137 if (cssDisplayChangeObj->IsBoolean()) {
4138 bool cssDisplayChange = cssDisplayChangeObj->ToBoolean();
4139 WebModel::GetInstance()->SetCssDisplayChangeEnabled(cssDisplayChange);
4140 }
4141 }
4142
RegisterNativeEmbedRule(const std::string & tag,const std::string & type)4143 void JSWeb::RegisterNativeEmbedRule(const std::string& tag, const std::string& type)
4144 {
4145 WebModel::GetInstance()->RegisterNativeEmbedRule(tag, type);
4146 }
4147
GeolocationAccessEnabled(bool isGeolocationAccessEnabled)4148 void JSWeb::GeolocationAccessEnabled(bool isGeolocationAccessEnabled)
4149 {
4150 WebModel::GetInstance()->SetGeolocationAccessEnabled(isGeolocationAccessEnabled);
4151 }
4152
JavaScriptProxy(const JSCallbackInfo & args)4153 void JSWeb::JavaScriptProxy(const JSCallbackInfo& args)
4154 {
4155 if (args.Length() < 1 || !args[0]->IsObject()) {
4156 return;
4157 }
4158 auto paramObject = JSRef<JSObject>::Cast(args[0]);
4159 auto controllerObj = paramObject->GetProperty("controller");
4160 auto object = JSRef<JSVal>::Cast(paramObject->GetProperty("object"));
4161 auto name = JSRef<JSVal>::Cast(paramObject->GetProperty("name"));
4162 auto methodList = JSRef<JSVal>::Cast(paramObject->GetProperty("methodList"));
4163 auto asyncMethodList = JSRef<JSVal>::Cast(paramObject->GetProperty("asyncMethodList"));
4164 auto permission = JSRef<JSVal>::Cast(paramObject->GetProperty("permission"));
4165 if (!controllerObj->IsObject()) {
4166 return;
4167 }
4168 auto controller = JSRef<JSObject>::Cast(controllerObj);
4169 auto jsProxyFunction = controller->GetProperty("jsProxy");
4170 if (jsProxyFunction->IsFunction()) {
4171 auto jsProxyCallback = [webviewController = controller, func = JSRef<JSFunc>::Cast(jsProxyFunction), object,
4172 name, methodList, asyncMethodList, permission]() {
4173 JSRef<JSVal> argv[] = { object, name, methodList, asyncMethodList, permission };
4174 func->Call(webviewController, 5, argv);
4175 };
4176
4177 WebModel::GetInstance()->SetJsProxyCallback(jsProxyCallback);
4178 }
4179 #if !defined(CROSS_PLATFORM)
4180 auto jsWebController = controller->Unwrap<JSWebController>();
4181 if (jsWebController) {
4182 jsWebController->SetJavascriptInterface(args);
4183 }
4184 #endif
4185 }
4186
UserAgent(const std::string & userAgent)4187 void JSWeb::UserAgent(const std::string& userAgent)
4188 {
4189 WebModel::GetInstance()->SetUserAgent(userAgent);
4190 }
4191
RenderExitedEventToJSValue(const RenderExitedEvent & eventInfo)4192 JSRef<JSVal> RenderExitedEventToJSValue(const RenderExitedEvent& eventInfo)
4193 {
4194 JSRef<JSObject> obj = JSRef<JSObject>::New();
4195 obj->SetProperty("renderExitReason", eventInfo.GetExitedReason());
4196 return JSRef<JSVal>::Cast(obj);
4197 }
4198
RefreshAccessedHistoryEventToJSValue(const RefreshAccessedHistoryEvent & eventInfo)4199 JSRef<JSVal> RefreshAccessedHistoryEventToJSValue(const RefreshAccessedHistoryEvent& eventInfo)
4200 {
4201 JSRef<JSObject> obj = JSRef<JSObject>::New();
4202 obj->SetProperty("url", eventInfo.GetVisitedUrl());
4203 obj->SetProperty("isRefreshed", eventInfo.IsRefreshed());
4204 return JSRef<JSVal>::Cast(obj);
4205 }
4206
OnRenderExited(const JSCallbackInfo & args)4207 void JSWeb::OnRenderExited(const JSCallbackInfo& args)
4208 {
4209 if (!args[0]->IsFunction()) {
4210 return;
4211 }
4212 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4213 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<RenderExitedEvent, 1>>(
4214 JSRef<JSFunc>::Cast(args[0]), RenderExitedEventToJSValue);
4215 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4216 const BaseEventInfo* info) {
4217 auto webNode = node.Upgrade();
4218 CHECK_NULL_VOID(webNode);
4219 ContainerScope scope(webNode->GetInstanceId());
4220 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4221 auto pipelineContext = PipelineContext::GetCurrentContext();
4222 if (pipelineContext) {
4223 pipelineContext->UpdateCurrentActiveNode(node);
4224 }
4225 auto* eventInfo = TypeInfoHelper::DynamicCast<RenderExitedEvent>(info);
4226 func->Execute(*eventInfo);
4227 };
4228 WebModel::GetInstance()->SetRenderExitedId(jsCallback);
4229 }
4230
OnRefreshAccessedHistory(const JSCallbackInfo & args)4231 void JSWeb::OnRefreshAccessedHistory(const JSCallbackInfo& args)
4232 {
4233 if (!args[0]->IsFunction()) {
4234 return;
4235 }
4236 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4237 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<RefreshAccessedHistoryEvent, 1>>(
4238 JSRef<JSFunc>::Cast(args[0]), RefreshAccessedHistoryEventToJSValue);
4239 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4240 const BaseEventInfo* info) {
4241 auto webNode = node.Upgrade();
4242 CHECK_NULL_VOID(webNode);
4243 ContainerScope scope(webNode->GetInstanceId());
4244 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4245 auto pipelineContext = PipelineContext::GetCurrentContext();
4246 if (pipelineContext) {
4247 pipelineContext->UpdateCurrentActiveNode(node);
4248 }
4249 auto* eventInfo = TypeInfoHelper::DynamicCast<RefreshAccessedHistoryEvent>(info);
4250 func->Execute(*eventInfo);
4251 };
4252 WebModel::GetInstance()->SetRefreshAccessedHistoryId(jsCallback);
4253 }
4254
CacheMode(int32_t cacheMode)4255 void JSWeb::CacheMode(int32_t cacheMode)
4256 {
4257 auto mode = WebCacheMode::DEFAULT;
4258 switch (cacheMode) {
4259 case 0:
4260 mode = WebCacheMode::DEFAULT;
4261 break;
4262 case 1:
4263 mode = WebCacheMode::USE_CACHE_ELSE_NETWORK;
4264 break;
4265 case 2:
4266 mode = WebCacheMode::USE_NO_CACHE;
4267 break;
4268 case 3:
4269 mode = WebCacheMode::USE_CACHE_ONLY;
4270 break;
4271 default:
4272 mode = WebCacheMode::DEFAULT;
4273 break;
4274 }
4275 WebModel::GetInstance()->SetCacheMode(mode);
4276 }
4277
OverScrollMode(int overScrollMode)4278 void JSWeb::OverScrollMode(int overScrollMode)
4279 {
4280 auto mode = OverScrollMode::NEVER;
4281 switch (overScrollMode) {
4282 case 0:
4283 mode = OverScrollMode::NEVER;
4284 break;
4285 case 1:
4286 mode = OverScrollMode::ALWAYS;
4287 break;
4288 default:
4289 mode = OverScrollMode::NEVER;
4290 break;
4291 }
4292 WebModel::GetInstance()->SetOverScrollMode(mode);
4293 }
4294
BlurOnKeyboardHideMode(int blurOnKeyboardHideMode)4295 void JSWeb::BlurOnKeyboardHideMode(int blurOnKeyboardHideMode)
4296 {
4297 auto mode = BlurOnKeyboardHideMode::SILENT;
4298 switch (blurOnKeyboardHideMode) {
4299 case 0:
4300 mode = BlurOnKeyboardHideMode::SILENT;
4301 break;
4302 case 1:
4303 mode = BlurOnKeyboardHideMode::BLUR;
4304 break;
4305 default:
4306 mode = BlurOnKeyboardHideMode::SILENT;
4307 break;
4308 }
4309 WebModel::GetInstance()->SetBlurOnKeyboardHideMode(mode);
4310 }
4311
OverviewModeAccess(bool isOverviewModeAccessEnabled)4312 void JSWeb::OverviewModeAccess(bool isOverviewModeAccessEnabled)
4313 {
4314 WebModel::GetInstance()->SetOverviewModeAccessEnabled(isOverviewModeAccessEnabled);
4315 }
4316
FileFromUrlAccess(bool isFileFromUrlAccessEnabled)4317 void JSWeb::FileFromUrlAccess(bool isFileFromUrlAccessEnabled)
4318 {
4319 WebModel::GetInstance()->SetFileFromUrlAccessEnabled(isFileFromUrlAccessEnabled);
4320 }
4321
DatabaseAccess(bool isDatabaseAccessEnabled)4322 void JSWeb::DatabaseAccess(bool isDatabaseAccessEnabled)
4323 {
4324 WebModel::GetInstance()->SetDatabaseAccessEnabled(isDatabaseAccessEnabled);
4325 }
4326
TextZoomRatio(int32_t textZoomRatioNum)4327 void JSWeb::TextZoomRatio(int32_t textZoomRatioNum)
4328 {
4329 WebModel::GetInstance()->SetTextZoomRatio(textZoomRatioNum);
4330 }
4331
WebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled)4332 void JSWeb::WebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled)
4333 {
4334 WebModel::GetInstance()->SetWebDebuggingAccessEnabled(isWebDebuggingAccessEnabled);
4335 }
4336
OnMouse(const JSCallbackInfo & args)4337 void JSWeb::OnMouse(const JSCallbackInfo& args)
4338 {
4339 if (args.Length() < 1 || !args[0]->IsFunction()) {
4340 return;
4341 }
4342
4343 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4344 RefPtr<JsClickFunction> jsOnMouseFunc = AceType::MakeRefPtr<JsClickFunction>(JSRef<JSFunc>::Cast(args[0]));
4345 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsOnMouseFunc), node = frameNode](
4346 MouseInfo& info) {
4347 auto webNode = node.Upgrade();
4348 CHECK_NULL_VOID(webNode);
4349 ContainerScope scope(webNode->GetInstanceId());
4350 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4351 auto pipelineContext = PipelineContext::GetCurrentContext();
4352 if (pipelineContext) {
4353 pipelineContext->UpdateCurrentActiveNode(node);
4354 }
4355 func->Execute(info);
4356 };
4357 WebModel::GetInstance()->SetOnMouseEvent(jsCallback);
4358 }
4359
ResourceLoadEventToJSValue(const ResourceLoadEvent & eventInfo)4360 JSRef<JSVal> ResourceLoadEventToJSValue(const ResourceLoadEvent& eventInfo)
4361 {
4362 JSRef<JSObject> obj = JSRef<JSObject>::New();
4363 obj->SetProperty("url", eventInfo.GetOnResourceLoadUrl());
4364 return JSRef<JSVal>::Cast(obj);
4365 }
4366
OnResourceLoad(const JSCallbackInfo & args)4367 void JSWeb::OnResourceLoad(const JSCallbackInfo& args)
4368 {
4369 if (args.Length() < 1 || !args[0]->IsFunction()) {
4370 return;
4371 }
4372 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4373 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ResourceLoadEvent, 1>>(
4374 JSRef<JSFunc>::Cast(args[0]), ResourceLoadEventToJSValue);
4375 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4376 const BaseEventInfo* info) {
4377 auto webNode = node.Upgrade();
4378 CHECK_NULL_VOID(webNode);
4379 ContainerScope scope(webNode->GetInstanceId());
4380 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4381 auto pipelineContext = PipelineContext::GetCurrentContext();
4382 if (pipelineContext) {
4383 pipelineContext->UpdateCurrentActiveNode(node);
4384 }
4385 auto* eventInfo = TypeInfoHelper::DynamicCast<ResourceLoadEvent>(info);
4386 func->Execute(*eventInfo);
4387 };
4388 WebModel::GetInstance()->SetResourceLoadId(jsCallback);
4389 }
4390
ScaleChangeEventToJSValue(const ScaleChangeEvent & eventInfo)4391 JSRef<JSVal> ScaleChangeEventToJSValue(const ScaleChangeEvent& eventInfo)
4392 {
4393 JSRef<JSObject> obj = JSRef<JSObject>::New();
4394 obj->SetProperty("oldScale", eventInfo.GetOnScaleChangeOldScale());
4395 obj->SetProperty("newScale", eventInfo.GetOnScaleChangeNewScale());
4396 return JSRef<JSVal>::Cast(obj);
4397 }
4398
OnScaleChange(const JSCallbackInfo & args)4399 void JSWeb::OnScaleChange(const JSCallbackInfo& args)
4400 {
4401 if (args.Length() < 1 || !args[0]->IsFunction()) {
4402 return;
4403 }
4404 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4405 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ScaleChangeEvent, 1>>(
4406 JSRef<JSFunc>::Cast(args[0]), ScaleChangeEventToJSValue);
4407 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4408 const BaseEventInfo* info) {
4409 auto webNode = node.Upgrade();
4410 CHECK_NULL_VOID(webNode);
4411 ContainerScope scope(webNode->GetInstanceId());
4412 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4413 auto pipelineContext = PipelineContext::GetCurrentContext();
4414 if (pipelineContext) {
4415 pipelineContext->UpdateCurrentActiveNode(node);
4416 }
4417 auto* eventInfo = TypeInfoHelper::DynamicCast<ScaleChangeEvent>(info);
4418 func->Execute(*eventInfo);
4419 };
4420 WebModel::GetInstance()->SetScaleChangeId(jsCallback);
4421 }
4422
ScrollEventToJSValue(const WebOnScrollEvent & eventInfo)4423 JSRef<JSVal> ScrollEventToJSValue(const WebOnScrollEvent& eventInfo)
4424 {
4425 JSRef<JSObject> obj = JSRef<JSObject>::New();
4426 obj->SetProperty("xOffset", eventInfo.GetX());
4427 obj->SetProperty("yOffset", eventInfo.GetY());
4428 return JSRef<JSVal>::Cast(obj);
4429 }
4430
OnScroll(const JSCallbackInfo & args)4431 void JSWeb::OnScroll(const JSCallbackInfo& args)
4432 {
4433 if (args.Length() < 1 || !args[0]->IsFunction()) {
4434 return;
4435 }
4436
4437 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4438 auto jsFunc =
4439 AceType::MakeRefPtr<JsEventFunction<WebOnScrollEvent, 1>>(JSRef<JSFunc>::Cast(args[0]), ScrollEventToJSValue);
4440 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4441 const BaseEventInfo* info) {
4442 auto webNode = node.Upgrade();
4443 CHECK_NULL_VOID(webNode);
4444 ContainerScope scope(webNode->GetInstanceId());
4445 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4446 auto pipelineContext = PipelineContext::GetCurrentContext();
4447 if (pipelineContext) {
4448 pipelineContext->UpdateCurrentActiveNode(node);
4449 }
4450 auto* eventInfo = TypeInfoHelper::DynamicCast<WebOnScrollEvent>(info);
4451 func->Execute(*eventInfo);
4452 };
4453 WebModel::GetInstance()->SetScrollId(jsCallback);
4454 }
4455
PermissionRequestEventToJSValue(const WebPermissionRequestEvent & eventInfo)4456 JSRef<JSVal> PermissionRequestEventToJSValue(const WebPermissionRequestEvent& eventInfo)
4457 {
4458 JSRef<JSObject> obj = JSRef<JSObject>::New();
4459 JSRef<JSObject> permissionObj = JSClass<JSWebPermissionRequest>::NewInstance();
4460 auto permissionEvent = Referenced::Claim(permissionObj->Unwrap<JSWebPermissionRequest>());
4461 permissionEvent->SetEvent(eventInfo);
4462 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(permissionObj), static_cast<void*>(permissionEvent.GetRawPtr()));
4463 obj->SetPropertyObject("request", permissionObj);
4464 return JSRef<JSVal>::Cast(obj);
4465 }
4466
CreatePermissionRequestHandler(const WebPermissionRequestEvent & eventInfo)4467 JSRef<JSVal> JSWeb::CreatePermissionRequestHandler(const WebPermissionRequestEvent& eventInfo)
4468 {
4469 JSRef<JSObject> permissionObj = JSClass<JSWebPermissionRequest>::NewInstance();
4470 auto permissionEvent = Referenced::Claim(permissionObj->Unwrap<JSWebPermissionRequest>());
4471 permissionEvent->SetEvent(eventInfo);
4472 return permissionObj;
4473 }
4474
OnPermissionRequest(const JSCallbackInfo & args)4475 void JSWeb::OnPermissionRequest(const JSCallbackInfo& args)
4476 {
4477 if (args.Length() < 1 || !args[0]->IsFunction()) {
4478 return;
4479 }
4480 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4481 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebPermissionRequestEvent, 1>>(
4482 JSRef<JSFunc>::Cast(args[0]), PermissionRequestEventToJSValue);
4483 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4484 const BaseEventInfo* info) {
4485 auto webNode = node.Upgrade();
4486 CHECK_NULL_VOID(webNode);
4487 ContainerScope scope(webNode->GetInstanceId());
4488 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4489 auto pipelineContext = PipelineContext::GetCurrentContext();
4490 if (pipelineContext) {
4491 pipelineContext->UpdateCurrentActiveNode(node);
4492 }
4493 auto* eventInfo = TypeInfoHelper::DynamicCast<WebPermissionRequestEvent>(info);
4494 func->Execute(*eventInfo);
4495 };
4496 WebModel::GetInstance()->SetPermissionRequestEventId(jsCallback);
4497 }
4498
ScreenCaptureRequestEventToJSValue(const WebScreenCaptureRequestEvent & eventInfo)4499 JSRef<JSVal> ScreenCaptureRequestEventToJSValue(const WebScreenCaptureRequestEvent& eventInfo)
4500 {
4501 JSRef<JSObject> obj = JSRef<JSObject>::New();
4502 JSRef<JSObject> requestObj = JSClass<JSScreenCaptureRequest>::NewInstance();
4503 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSScreenCaptureRequest>());
4504 requestEvent->SetEvent(eventInfo);
4505 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(requestObj), static_cast<void *>(requestEvent.GetRawPtr()));
4506 obj->SetPropertyObject("handler", requestObj);
4507 return JSRef<JSVal>::Cast(obj);
4508 }
4509
CreateScreenCaptureHandler(const WebScreenCaptureRequestEvent & eventInfo)4510 JSRef<JSVal> JSWeb::CreateScreenCaptureHandler(const WebScreenCaptureRequestEvent& eventInfo)
4511 {
4512 JSRef<JSObject> requestObj = JSClass<JSScreenCaptureRequest>::NewInstance();
4513 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSScreenCaptureRequest>());
4514 requestEvent->SetEvent(eventInfo);
4515 return requestObj;
4516 }
4517
OnScreenCaptureRequest(const JSCallbackInfo & args)4518 void JSWeb::OnScreenCaptureRequest(const JSCallbackInfo& args)
4519 {
4520 if (args.Length() < 1 || !args[0]->IsFunction()) {
4521 return;
4522 }
4523 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4524 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebScreenCaptureRequestEvent, 1>>(
4525 JSRef<JSFunc>::Cast(args[0]), ScreenCaptureRequestEventToJSValue);
4526 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4527 const BaseEventInfo* info) {
4528 auto webNode = node.Upgrade();
4529 CHECK_NULL_VOID(webNode);
4530 ContainerScope scope(webNode->GetInstanceId());
4531 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4532 auto pipelineContext = PipelineContext::GetCurrentContext();
4533 if (pipelineContext) {
4534 pipelineContext->UpdateCurrentActiveNode(node);
4535 }
4536 auto* eventInfo = TypeInfoHelper::DynamicCast<WebScreenCaptureRequestEvent>(info);
4537 func->Execute(*eventInfo);
4538 };
4539 WebModel::GetInstance()->SetScreenCaptureRequestEventId(jsCallback);
4540 }
4541
BackgroundColor(const JSCallbackInfo & info)4542 void JSWeb::BackgroundColor(const JSCallbackInfo& info)
4543 {
4544 if (info.Length() < 1) {
4545 return;
4546 }
4547 Color backgroundColor;
4548 if (!ParseJsColor(info[0], backgroundColor)) {
4549 WebModel::GetInstance()->SetDefaultBackgroundColor();
4550 } else {
4551 WebModel::GetInstance()->SetBackgroundColor(backgroundColor);
4552 }
4553 }
4554
InitialScale(float scale)4555 void JSWeb::InitialScale(float scale)
4556 {
4557 WebModel::GetInstance()->InitialScale(scale);
4558 }
4559
Password(bool password)4560 void JSWeb::Password(bool password) {}
4561
TableData(bool tableData)4562 void JSWeb::TableData(bool tableData) {}
4563
OnFileSelectorShowAbandoned(const JSCallbackInfo & args)4564 void JSWeb::OnFileSelectorShowAbandoned(const JSCallbackInfo& args) {}
4565
WideViewModeAccess(const JSCallbackInfo & args)4566 void JSWeb::WideViewModeAccess(const JSCallbackInfo& args) {}
4567
WebDebuggingAccess(const JSCallbackInfo & args)4568 void JSWeb::WebDebuggingAccess(const JSCallbackInfo& args) {}
4569
OnSearchResultReceive(const JSCallbackInfo & args)4570 void JSWeb::OnSearchResultReceive(const JSCallbackInfo& args)
4571 {
4572 if (!args[0]->IsFunction()) {
4573 return;
4574 }
4575 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4576 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<SearchResultReceiveEvent, 1>>(
4577 JSRef<JSFunc>::Cast(args[0]), SearchResultReceiveEventToJSValue);
4578 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4579 const BaseEventInfo* info) {
4580 auto webNode = node.Upgrade();
4581 CHECK_NULL_VOID(webNode);
4582 ContainerScope scope(webNode->GetInstanceId());
4583 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4584 auto pipelineContext = PipelineContext::GetCurrentContext();
4585 if (pipelineContext) {
4586 pipelineContext->UpdateCurrentActiveNode(node);
4587 }
4588 auto* eventInfo = TypeInfoHelper::DynamicCast<SearchResultReceiveEvent>(info);
4589 func->Execute(*eventInfo);
4590 };
4591 WebModel::GetInstance()->SetSearchResultReceiveEventId(jsCallback);
4592 }
4593
JsOnDragStart(const JSCallbackInfo & info)4594 void JSWeb::JsOnDragStart(const JSCallbackInfo& info)
4595 {
4596 if (info.Length() < 1 || !info[0]->IsFunction()) {
4597 return;
4598 }
4599
4600 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4601 RefPtr<JsDragFunction> jsOnDragStartFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(info[0]));
4602 auto onDragStartId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragStartFunc), node = frameNode](
4603 const RefPtr<DragEvent>& info, const std::string& extraParams) -> NG::DragDropBaseInfo {
4604 NG::DragDropBaseInfo itemInfo;
4605 auto webNode = node.Upgrade();
4606 CHECK_NULL_RETURN(webNode, itemInfo);
4607 ContainerScope scope(webNode->GetInstanceId());
4608 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, itemInfo);
4609 auto pipelineContext = PipelineContext::GetCurrentContext();
4610 if (pipelineContext) {
4611 pipelineContext->UpdateCurrentActiveNode(node);
4612 }
4613 auto ret = func->Execute(info, extraParams);
4614 if (!ret->IsObject()) {
4615 return itemInfo;
4616 }
4617 auto component = ParseDragNode(ret);
4618 if (component) {
4619 itemInfo.node = component;
4620 return itemInfo;
4621 }
4622
4623 auto builderObj = JSRef<JSObject>::Cast(ret);
4624 #if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM)
4625 auto pixmap_impl = builderObj->GetProperty("pixelMap");
4626 itemInfo.pixelMap = CreatePixelMapFromNapiValue(pixmap_impl);
4627 #endif
4628
4629 #if defined(PIXEL_MAP_SUPPORTED)
4630 auto pixmap_ng = builderObj->GetProperty("pixelMap");
4631 itemInfo.pixelMap = CreatePixelMapFromNapiValue(pixmap_ng);
4632 #endif
4633 auto extraInfo = builderObj->GetProperty("extraInfo");
4634 ParseJsString(extraInfo, itemInfo.extraInfo);
4635 component = ParseDragNode(builderObj->GetProperty("builder"));
4636 itemInfo.node = component;
4637 return itemInfo;
4638 };
4639
4640 WebModel::GetInstance()->SetOnDragStart(std::move(onDragStartId));
4641 }
4642
JsOnDragEnter(const JSCallbackInfo & info)4643 void JSWeb::JsOnDragEnter(const JSCallbackInfo& info)
4644 {
4645 if (info.Length() < 1 || !info[0]->IsFunction()) {
4646 return;
4647 }
4648
4649 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4650 RefPtr<JsDragFunction> jsOnDragEnterFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(info[0]));
4651 auto onDragEnterId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragEnterFunc), node = frameNode](
4652 const RefPtr<DragEvent>& info, const std::string& extraParams) {
4653 auto webNode = node.Upgrade();
4654 CHECK_NULL_VOID(webNode);
4655 ContainerScope scope(webNode->GetInstanceId());
4656 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4657 ACE_SCORING_EVENT("onDragEnter");
4658 auto pipelineContext = PipelineContext::GetCurrentContext();
4659 if (pipelineContext) {
4660 pipelineContext->UpdateCurrentActiveNode(node);
4661 }
4662 func->Execute(info, extraParams);
4663 };
4664
4665 WebModel::GetInstance()->SetOnDragEnter(onDragEnterId);
4666 }
4667
JsOnDragMove(const JSCallbackInfo & info)4668 void JSWeb::JsOnDragMove(const JSCallbackInfo& info)
4669 {
4670 if (info.Length() < 1 || !info[0]->IsFunction()) {
4671 return;
4672 }
4673
4674 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4675 RefPtr<JsDragFunction> jsOnDragMoveFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(info[0]));
4676 auto onDragMoveId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragMoveFunc), node = frameNode](
4677 const RefPtr<DragEvent>& info, const std::string& extraParams) {
4678 auto webNode = node.Upgrade();
4679 CHECK_NULL_VOID(webNode);
4680 ContainerScope scope(webNode->GetInstanceId());
4681 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4682 ACE_SCORING_EVENT("onDragMove");
4683 auto pipelineContext = PipelineContext::GetCurrentContext();
4684 if (pipelineContext) {
4685 pipelineContext->UpdateCurrentActiveNode(node);
4686 }
4687 func->Execute(info, extraParams);
4688 };
4689
4690 WebModel::GetInstance()->SetOnDragMove(onDragMoveId);
4691 }
4692
JsOnDragLeave(const JSCallbackInfo & info)4693 void JSWeb::JsOnDragLeave(const JSCallbackInfo& info)
4694 {
4695 if (info.Length() < 1 || !info[0]->IsFunction()) {
4696 return;
4697 }
4698
4699 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4700 RefPtr<JsDragFunction> jsOnDragLeaveFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(info[0]));
4701 auto onDragLeaveId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragLeaveFunc), node = frameNode](
4702 const RefPtr<DragEvent>& info, const std::string& extraParams) {
4703 auto webNode = node.Upgrade();
4704 CHECK_NULL_VOID(webNode);
4705 ContainerScope scope(webNode->GetInstanceId());
4706 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4707 ACE_SCORING_EVENT("onDragLeave");
4708 auto pipelineContext = PipelineContext::GetCurrentContext();
4709 if (pipelineContext) {
4710 pipelineContext->UpdateCurrentActiveNode(node);
4711 }
4712 func->Execute(info, extraParams);
4713 };
4714
4715 WebModel::GetInstance()->SetOnDragLeave(onDragLeaveId);
4716 }
4717
JsOnDrop(const JSCallbackInfo & info)4718 void JSWeb::JsOnDrop(const JSCallbackInfo& info)
4719 {
4720 if (info.Length() < 1 || !info[0]->IsFunction()) {
4721 return;
4722 }
4723
4724 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4725 RefPtr<JsDragFunction> jsOnDropFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(info[0]));
4726 auto onDropId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDropFunc), node = frameNode](
4727 const RefPtr<DragEvent>& info, const std::string& extraParams) {
4728 auto webNode = node.Upgrade();
4729 CHECK_NULL_VOID(webNode);
4730 ContainerScope scope(webNode->GetInstanceId());
4731 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4732 ACE_SCORING_EVENT("onDrop");
4733 auto pipelineContext = PipelineContext::GetCurrentContext();
4734 if (pipelineContext) {
4735 pipelineContext->UpdateCurrentActiveNode(node);
4736 }
4737 func->Execute(info, extraParams);
4738 };
4739
4740 WebModel::GetInstance()->SetOnDrop(onDropId);
4741 }
4742
PinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)4743 void JSWeb::PinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)
4744 {
4745 WebModel::GetInstance()->SetPinchSmoothModeEnabled(isPinchSmoothModeEnabled);
4746 }
4747
WindowNewEventToJSValue(const WebWindowNewEvent & eventInfo)4748 JSRef<JSVal> WindowNewEventToJSValue(const WebWindowNewEvent& eventInfo)
4749 {
4750 JSRef<JSObject> obj = JSRef<JSObject>::New();
4751 obj->SetProperty("isAlert", eventInfo.IsAlert());
4752 obj->SetProperty("isUserTrigger", eventInfo.IsUserTrigger());
4753 obj->SetProperty("targetUrl", eventInfo.GetTargetUrl());
4754 JSRef<JSObject> handlerObj = JSClass<JSWebWindowNewHandler>::NewInstance();
4755 auto handler = Referenced::Claim(handlerObj->Unwrap<JSWebWindowNewHandler>());
4756 handler->SetEvent(eventInfo);
4757 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(handlerObj), static_cast<void *>(handler.GetRawPtr()));
4758 obj->SetPropertyObject("handler", handlerObj);
4759 return JSRef<JSVal>::Cast(obj);
4760 }
4761
CreateJSWindowNewHandler(const WebWindowNewEvent & eventInfo)4762 JSRef<JSVal> JSWeb::CreateJSWindowNewHandler(const WebWindowNewEvent& eventInfo)
4763 {
4764 JSRef<JSObject> handlerObj = Framework::JSClass<JSWebWindowNewHandler>::NewInstance();
4765 auto handler = Referenced::Claim(handlerObj->Unwrap<JSWebWindowNewHandler>());
4766 handler->SetEvent(eventInfo);
4767 return handlerObj;
4768 }
4769
HandleWindowNewEvent(const WebWindowNewEvent * eventInfo)4770 bool JSWeb::HandleWindowNewEvent(const WebWindowNewEvent* eventInfo)
4771 {
4772 if (eventInfo == nullptr) {
4773 return false;
4774 }
4775 auto handler = eventInfo->GetWebWindowNewHandler();
4776 if (handler && !handler->IsFrist()) {
4777 int32_t parentId = -1;
4778 auto controller = JSWebWindowNewHandler::PopController(handler->GetId(), &parentId);
4779 if (!controller.IsEmpty()) {
4780 auto getWebIdFunction = controller->GetProperty("innerGetWebId");
4781 if (getWebIdFunction->IsFunction()) {
4782 auto func = JSRef<JSFunc>::Cast(getWebIdFunction);
4783 auto webId = func->Call(controller, 0, {});
4784 handler->SetWebController(webId->ToNumber<int32_t>());
4785 }
4786 auto completeWindowNewFunction = controller->GetProperty("innerCompleteWindowNew");
4787 if (completeWindowNewFunction->IsFunction()) {
4788 auto func = JSRef<JSFunc>::Cast(completeWindowNewFunction);
4789 JSRef<JSVal> argv[] = { JSRef<JSVal>::Make(ToJSValue(parentId)) };
4790 func->Call(controller, 1, argv);
4791 }
4792 }
4793 return false;
4794 }
4795 return true;
4796 }
4797
OnWindowNew(const JSCallbackInfo & args)4798 void JSWeb::OnWindowNew(const JSCallbackInfo& args)
4799 {
4800 if (args.Length() < 1 || !args[0]->IsFunction()) {
4801 return;
4802 }
4803
4804 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4805 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebWindowNewEvent, 1>>(
4806 JSRef<JSFunc>::Cast(args[0]), WindowNewEventToJSValue);
4807 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4808 const std::shared_ptr<BaseEventInfo>& info) {
4809 ACE_SCORING_EVENT("OnWindowNew CallBack");
4810 auto webNode = node.Upgrade();
4811 CHECK_NULL_VOID(webNode);
4812 ContainerScope scope(webNode->GetInstanceId());
4813 auto pipelineContext = PipelineContext::GetCurrentContext();
4814 if (pipelineContext) {
4815 pipelineContext->UpdateCurrentActiveNode(node);
4816 }
4817 auto* eventInfo = TypeInfoHelper::DynamicCast<WebWindowNewEvent>(info.get());
4818 if (!func || !HandleWindowNewEvent(eventInfo)) {
4819 return;
4820 }
4821 func->Execute(*eventInfo);
4822 };
4823 WebModel::GetInstance()->SetWindowNewEvent(jsCallback);
4824 }
4825
ActivateContentEventToJSValue(const WebActivateContentEvent & eventInfo)4826 JSRef<JSVal> ActivateContentEventToJSValue(const WebActivateContentEvent& eventInfo)
4827 {
4828 JSRef<JSObject> obj = JSRef<JSObject>::New();
4829 return JSRef<JSVal>::Cast(obj);
4830 }
4831
OnActivateContent(const JSCallbackInfo & args)4832 void JSWeb::OnActivateContent(const JSCallbackInfo& args)
4833 {
4834 if (args.Length() < 1 || !args[0]->IsFunction()) {
4835 return;
4836 }
4837 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4838 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebActivateContentEvent, 1>>(
4839 JSRef<JSFunc>::Cast(args[0]), ActivateContentEventToJSValue);
4840 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4841 const BaseEventInfo* info) {
4842 auto webNode = node.Upgrade();
4843 CHECK_NULL_VOID(webNode);
4844 ContainerScope scope(webNode->GetInstanceId());
4845 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4846 auto pipelineContext = PipelineContext::GetCurrentContext();
4847 if (pipelineContext) {
4848 pipelineContext->UpdateCurrentActiveNode(node);
4849 }
4850 auto* eventInfo = TypeInfoHelper::DynamicCast<WebActivateContentEvent>(info);
4851 func->Execute(*eventInfo);
4852 };
4853 WebModel::GetInstance()->SetActivateContentEventId(jsCallback);
4854 }
4855
WindowExitEventToJSValue(const WebWindowExitEvent & eventInfo)4856 JSRef<JSVal> WindowExitEventToJSValue(const WebWindowExitEvent& eventInfo)
4857 {
4858 JSRef<JSObject> obj = JSRef<JSObject>::New();
4859 return JSRef<JSVal>::Cast(obj);
4860 }
4861
OnWindowExit(const JSCallbackInfo & args)4862 void JSWeb::OnWindowExit(const JSCallbackInfo& args)
4863 {
4864 if (args.Length() < 1 || !args[0]->IsFunction()) {
4865 return;
4866 }
4867 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4868 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebWindowExitEvent, 1>>(
4869 JSRef<JSFunc>::Cast(args[0]), WindowExitEventToJSValue);
4870 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4871 const BaseEventInfo* info) {
4872 auto webNode = node.Upgrade();
4873 CHECK_NULL_VOID(webNode);
4874 ContainerScope scope(webNode->GetInstanceId());
4875 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4876 auto pipelineContext = PipelineContext::GetCurrentContext();
4877 if (pipelineContext) {
4878 pipelineContext->UpdateCurrentActiveNode(node);
4879 }
4880 auto* eventInfo = TypeInfoHelper::DynamicCast<WebWindowExitEvent>(info);
4881 func->Execute(*eventInfo);
4882 };
4883 WebModel::GetInstance()->SetWindowExitEventId(jsCallback);
4884 }
4885
MultiWindowAccessEnabled(bool isMultiWindowAccessEnable)4886 void JSWeb::MultiWindowAccessEnabled(bool isMultiWindowAccessEnable)
4887 {
4888 WebModel::GetInstance()->SetMultiWindowAccessEnabled(isMultiWindowAccessEnable);
4889 }
4890
AllowWindowOpenMethod(bool isAllowWindowOpenMethod)4891 void JSWeb::AllowWindowOpenMethod(bool isAllowWindowOpenMethod)
4892 {
4893 WebModel::GetInstance()->SetAllowWindowOpenMethod(isAllowWindowOpenMethod);
4894 }
4895
WebCursiveFont(const std::string & cursiveFontFamily)4896 void JSWeb::WebCursiveFont(const std::string& cursiveFontFamily)
4897 {
4898 WebModel::GetInstance()->SetWebCursiveFont(cursiveFontFamily);
4899 }
4900
WebFantasyFont(const std::string & fantasyFontFamily)4901 void JSWeb::WebFantasyFont(const std::string& fantasyFontFamily)
4902 {
4903 WebModel::GetInstance()->SetWebFantasyFont(fantasyFontFamily);
4904 }
4905
WebFixedFont(const std::string & fixedFontFamily)4906 void JSWeb::WebFixedFont(const std::string& fixedFontFamily)
4907 {
4908 WebModel::GetInstance()->SetWebFixedFont(fixedFontFamily);
4909 }
4910
WebSansSerifFont(const std::string & sansSerifFontFamily)4911 void JSWeb::WebSansSerifFont(const std::string& sansSerifFontFamily)
4912 {
4913 WebModel::GetInstance()->SetWebSansSerifFont(sansSerifFontFamily);
4914 }
4915
WebSerifFont(const std::string & serifFontFamily)4916 void JSWeb::WebSerifFont(const std::string& serifFontFamily)
4917 {
4918 WebModel::GetInstance()->SetWebSerifFont(serifFontFamily);
4919 }
4920
WebStandardFont(const std::string & standardFontFamily)4921 void JSWeb::WebStandardFont(const std::string& standardFontFamily)
4922 {
4923 WebModel::GetInstance()->SetWebStandardFont(standardFontFamily);
4924 }
4925
DefaultFixedFontSize(int32_t defaultFixedFontSize)4926 void JSWeb::DefaultFixedFontSize(int32_t defaultFixedFontSize)
4927 {
4928 WebModel::GetInstance()->SetDefaultFixedFontSize(defaultFixedFontSize);
4929 }
4930
DefaultFontSize(int32_t defaultFontSize)4931 void JSWeb::DefaultFontSize(int32_t defaultFontSize)
4932 {
4933 WebModel::GetInstance()->SetDefaultFontSize(defaultFontSize);
4934 }
4935
DefaultTextEncodingFormat(const JSCallbackInfo & args)4936 void JSWeb::DefaultTextEncodingFormat(const JSCallbackInfo& args)
4937 {
4938 if (args.Length() < 1 || !args[0]->IsString()) {
4939 return;
4940 }
4941 std::string textEncodingFormat = args[0]->ToString();
4942 EraseSpace(textEncodingFormat);
4943 if (textEncodingFormat.empty()) {
4944 WebModel::GetInstance()->SetDefaultTextEncodingFormat("UTF-8");
4945 return;
4946 }
4947 WebModel::GetInstance()->SetDefaultTextEncodingFormat(textEncodingFormat);
4948 }
4949
MinFontSize(int32_t minFontSize)4950 void JSWeb::MinFontSize(int32_t minFontSize)
4951 {
4952 WebModel::GetInstance()->SetMinFontSize(minFontSize);
4953 }
4954
MinLogicalFontSize(int32_t minLogicalFontSize)4955 void JSWeb::MinLogicalFontSize(int32_t minLogicalFontSize)
4956 {
4957 WebModel::GetInstance()->SetMinLogicalFontSize(minLogicalFontSize);
4958 }
4959
BlockNetwork(bool isNetworkBlocked)4960 void JSWeb::BlockNetwork(bool isNetworkBlocked)
4961 {
4962 WebModel::GetInstance()->SetBlockNetwork(isNetworkBlocked);
4963 }
4964
PageVisibleEventToJSValue(const PageVisibleEvent & eventInfo)4965 JSRef<JSVal> PageVisibleEventToJSValue(const PageVisibleEvent& eventInfo)
4966 {
4967 JSRef<JSObject> obj = JSRef<JSObject>::New();
4968 obj->SetProperty("url", eventInfo.GetUrl());
4969 return JSRef<JSVal>::Cast(obj);
4970 }
4971
OnPageVisible(const JSCallbackInfo & args)4972 void JSWeb::OnPageVisible(const JSCallbackInfo& args)
4973 {
4974 TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::OnPageVisible init by developer");
4975 if (!args[0]->IsFunction()) {
4976 return;
4977 }
4978 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4979 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<PageVisibleEvent, 1>>(
4980 JSRef<JSFunc>::Cast(args[0]), PageVisibleEventToJSValue);
4981
4982 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
4983 const std::shared_ptr<BaseEventInfo>& info) {
4984 TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::OnPageVisible uiCallback enter");
4985 auto webNode = node.Upgrade();
4986 CHECK_NULL_VOID(webNode);
4987 ContainerScope scope(webNode->GetInstanceId());
4988 auto context = PipelineBase::GetCurrentContext();
4989 if (context) {
4990 context->UpdateCurrentActiveNode(node);
4991 }
4992 auto executor = Container::CurrentTaskExecutorSafely();
4993 CHECK_NULL_VOID(executor);
4994 executor->PostTask([execCtx, postFunc = func, info]() {
4995 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4996 TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::OnPageVisible async event execute");
4997 auto* eventInfo = TypeInfoHelper::DynamicCast<PageVisibleEvent>(info.get());
4998 postFunc->Execute(*eventInfo);
4999 }, TaskExecutor::TaskType::UI, "ArkUIWebPageVisible");
5000 };
5001 WebModel::GetInstance()->SetPageVisibleId(std::move(uiCallback));
5002 }
5003
OnInterceptKeyEvent(const JSCallbackInfo & args)5004 void JSWeb::OnInterceptKeyEvent(const JSCallbackInfo& args)
5005 {
5006 if (args.Length() < 1 || !args[0]->IsFunction()) {
5007 return;
5008 }
5009
5010 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5011 RefPtr<JsKeyFunction> jsOnPreKeyEventFunc = AceType::MakeRefPtr<JsKeyFunction>(JSRef<JSFunc>::Cast(args[0]));
5012 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsOnPreKeyEventFunc), node = frameNode](
5013 KeyEventInfo& keyEventInfo) -> bool {
5014 bool result = false;
5015 ACE_SCORING_EVENT("onPreKeyEvent");
5016 auto webNode = node.Upgrade();
5017 CHECK_NULL_RETURN(webNode, false);
5018 ContainerScope scope(webNode->GetInstanceId());
5019 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, result);
5020 auto pipelineContext = PipelineContext::GetCurrentContext();
5021 if (pipelineContext) {
5022 pipelineContext->UpdateCurrentActiveNode(node);
5023 }
5024 JSRef<JSVal> obj = func->ExecuteWithValue(keyEventInfo);
5025 if (obj->IsBoolean()) {
5026 result = obj->ToBoolean();
5027 }
5028 return result;
5029 };
5030 WebModel::GetInstance()->SetOnInterceptKeyEventCallback(uiCallback);
5031 }
5032
DataResubmittedEventToJSValue(const DataResubmittedEvent & eventInfo)5033 JSRef<JSVal> DataResubmittedEventToJSValue(const DataResubmittedEvent& eventInfo)
5034 {
5035 JSRef<JSObject> obj = JSRef<JSObject>::New();
5036 JSRef<JSObject> resultObj = JSClass<JSDataResubmitted>::NewInstance();
5037 auto jsDataResubmitted = Referenced::Claim(resultObj->Unwrap<JSDataResubmitted>());
5038 if (!jsDataResubmitted) {
5039 return JSRef<JSVal>::Cast(obj);
5040 }
5041 jsDataResubmitted->SetHandler(eventInfo.GetHandler());
5042 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(resultObj), static_cast<void *>(jsDataResubmitted.GetRawPtr()));
5043 obj->SetPropertyObject("handler", resultObj);
5044 return JSRef<JSVal>::Cast(obj);
5045 }
5046
CreateDataResubmittedHandler(const DataResubmittedEvent & eventInfo)5047 JSRef<JSVal> JSWeb::CreateDataResubmittedHandler(const DataResubmittedEvent& eventInfo)
5048 {
5049 JSRef<JSObject> resultObj = JSClass<JSDataResubmitted>::NewInstance();
5050 auto jsDataResubmitted = Referenced::Claim(resultObj->Unwrap<JSDataResubmitted>());
5051 if (!jsDataResubmitted) {
5052 return resultObj;
5053 }
5054 jsDataResubmitted->SetHandler(eventInfo.GetHandler());
5055 return resultObj;
5056 }
5057
OnDataResubmitted(const JSCallbackInfo & args)5058 void JSWeb::OnDataResubmitted(const JSCallbackInfo& args)
5059 {
5060 if (args.Length() < 1 || !args[0]->IsFunction()) {
5061 return;
5062 }
5063 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<DataResubmittedEvent, 1>>(
5064 JSRef<JSFunc>::Cast(args[0]), DataResubmittedEventToJSValue);
5065
5066 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5067 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5068 const std::shared_ptr<BaseEventInfo>& info) {
5069 auto webNode = node.Upgrade();
5070 CHECK_NULL_VOID(webNode);
5071 ContainerScope scope(webNode->GetInstanceId());
5072 auto context = PipelineBase::GetCurrentContext();
5073 if (context) {
5074 context->UpdateCurrentActiveNode(node);
5075 }
5076 auto executor = Container::CurrentTaskExecutorSafely();
5077 CHECK_NULL_VOID(executor);
5078 executor->PostSyncTask([execCtx, postFunc = func, info]() {
5079 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5080 auto* eventInfo = TypeInfoHelper::DynamicCast<DataResubmittedEvent>(info.get());
5081 postFunc->Execute(*eventInfo);
5082 }, TaskExecutor::TaskType::UI, "ArkUIWebDataResubmitted");
5083 };
5084 WebModel::GetInstance()->SetOnDataResubmitted(uiCallback);
5085 }
5086
CreateFaviconReceivedHandler(const FaviconReceivedEvent & eventInfo)5087 JSRef<JSVal> JSWeb::CreateFaviconReceivedHandler(const FaviconReceivedEvent& eventInfo)
5088 {
5089 JSRef<JSVal> obj = JSRef<JSObject>::New();
5090 if (obj.IsEmpty()) {
5091 return JSRef<JSVal>::Cast(obj);
5092 }
5093 #if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
5094 JSRef<JSVal> jsPixelMap;
5095 GetJsPixelMap(eventInfo, jsPixelMap);
5096 if (jsPixelMap.IsEmpty()) {
5097 return JSRef<JSVal>::Cast(obj);
5098 }
5099 return jsPixelMap;
5100 #else
5101 return JSRef<JSVal>::Cast(obj);
5102 #endif
5103 }
5104
GetBytesPerPixel(OHOS::Ace::PixelFormat format)5105 uint32_t JSWeb::GetBytesPerPixel(OHOS::Ace::PixelFormat format)
5106 {
5107 const uint32_t BYTES_PER_PIXEL_2 = 2;
5108 const uint32_t BYTES_PER_PIXEL_3 = 3;
5109 const uint32_t BYTES_PER_PIXEL_4 = 4;
5110 switch (format) {
5111 case OHOS::Ace::PixelFormat::RGB_565:
5112 return BYTES_PER_PIXEL_2;
5113 case OHOS::Ace::PixelFormat::RGBA_8888:
5114 return BYTES_PER_PIXEL_4;
5115 case OHOS::Ace::PixelFormat::BGRA_8888:
5116 return BYTES_PER_PIXEL_4;
5117 case OHOS::Ace::PixelFormat::RGB_888:
5118 return BYTES_PER_PIXEL_3;
5119 default:
5120 TAG_LOGE(AceLogTag::ACE_WEB, "Unknown PixelFormat: %{public}d, using default 4 bytes per pixel",
5121 static_cast<int32_t>(format));
5122 return BYTES_PER_PIXEL_4;
5123 }
5124 }
5125
OnFaviconReceived(const JSCallbackInfo & args)5126 void JSWeb::OnFaviconReceived(const JSCallbackInfo& args)
5127 {
5128 if (args.Length() < 1 || !args[0]->IsFunction()) {
5129 return;
5130 }
5131 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5132 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FaviconReceivedEvent, 1>>(
5133 JSRef<JSFunc>::Cast(args[0]), FaviconReceivedEventToJSValue);
5134
5135 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5136 const std::shared_ptr<BaseEventInfo>& info) {
5137 auto webNode = node.Upgrade();
5138 CHECK_NULL_VOID(webNode);
5139 ContainerScope scope(webNode->GetInstanceId());
5140 auto context = PipelineBase::GetCurrentContext();
5141 if (context) {
5142 context->UpdateCurrentActiveNode(node);
5143 }
5144 auto executor = Container::CurrentTaskExecutorSafely();
5145 CHECK_NULL_VOID(executor);
5146
5147 executor->PostTask([execCtx, postFunc = func, info]() {
5148 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5149 auto* eventInfo = TypeInfoHelper::DynamicCast<FaviconReceivedEvent>(info.get());
5150 postFunc->Execute(*eventInfo);
5151 }, TaskExecutor::TaskType::UI, "ArkUIWebFaviconReceived");
5152 };
5153 WebModel::GetInstance()->SetFaviconReceivedId(uiCallback);
5154 }
5155
TouchIconUrlEventToJSValue(const TouchIconUrlEvent & eventInfo)5156 JSRef<JSVal> TouchIconUrlEventToJSValue(const TouchIconUrlEvent& eventInfo)
5157 {
5158 JSRef<JSObject> obj = JSRef<JSObject>::New();
5159 obj->SetProperty("url", eventInfo.GetUrl());
5160 obj->SetProperty("precomposed", eventInfo.GetPreComposed());
5161 return JSRef<JSVal>::Cast(obj);
5162 }
5163
OnTouchIconUrlReceived(const JSCallbackInfo & args)5164 void JSWeb::OnTouchIconUrlReceived(const JSCallbackInfo& args)
5165 {
5166 if (!args[0]->IsFunction()) {
5167 return;
5168 }
5169 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5170 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<TouchIconUrlEvent, 1>>(
5171 JSRef<JSFunc>::Cast(args[0]), TouchIconUrlEventToJSValue);
5172
5173 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5174 const std::shared_ptr<BaseEventInfo>& info) {
5175 auto webNode = node.Upgrade();
5176 CHECK_NULL_VOID(webNode);
5177 ContainerScope scope(webNode->GetInstanceId());
5178 auto context = PipelineBase::GetCurrentContext();
5179 if (context) {
5180 context->UpdateCurrentActiveNode(node);
5181 }
5182 auto executor = Container::CurrentTaskExecutorSafely();
5183 CHECK_NULL_VOID(executor);
5184 executor->PostTask([execCtx, postFunc = func, info]() {
5185 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5186 auto* eventInfo = TypeInfoHelper::DynamicCast<TouchIconUrlEvent>(info.get());
5187 postFunc->Execute(*eventInfo);
5188 }, TaskExecutor::TaskType::UI, "ArkUIWebTouchIconUrlReceived");
5189 };
5190 WebModel::GetInstance()->SetTouchIconUrlId(uiCallback);
5191 }
5192
DarkMode(int32_t darkMode)5193 void JSWeb::DarkMode(int32_t darkMode)
5194 {
5195 auto mode = WebDarkMode::Off;
5196 switch (darkMode) {
5197 case 0:
5198 mode = WebDarkMode::Off;
5199 break;
5200 case 1:
5201 mode = WebDarkMode::On;
5202 break;
5203 case 2:
5204 mode = WebDarkMode::Auto;
5205 break;
5206 default:
5207 mode = WebDarkMode::Off;
5208 break;
5209 }
5210 WebModel::GetInstance()->SetDarkMode(mode);
5211 }
5212
ForceDarkAccess(bool access)5213 void JSWeb::ForceDarkAccess(bool access)
5214 {
5215 WebModel::GetInstance()->SetForceDarkAccess(access);
5216 }
5217
HorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled)5218 void JSWeb::HorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled)
5219 {
5220 WebModel::GetInstance()->SetHorizontalScrollBarAccessEnabled(isHorizontalScrollBarAccessEnabled);
5221 }
5222
VerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled)5223 void JSWeb::VerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled)
5224 {
5225 WebModel::GetInstance()->SetVerticalScrollBarAccessEnabled(isVerticalScrollBarAccessEnabled);
5226 }
5227
AudioStateChangedEventToJSValue(const AudioStateChangedEvent & eventInfo)5228 JSRef<JSVal> AudioStateChangedEventToJSValue(const AudioStateChangedEvent& eventInfo)
5229 {
5230 JSRef<JSObject> obj = JSRef<JSObject>::New();
5231 obj->SetProperty("playing", eventInfo.IsPlaying());
5232 return JSRef<JSVal>::Cast(obj);
5233 }
5234
OnAudioStateChanged(const JSCallbackInfo & args)5235 void JSWeb::OnAudioStateChanged(const JSCallbackInfo& args)
5236 {
5237 if (!args[0]->IsFunction()) {
5238 return;
5239 }
5240
5241 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5242 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<AudioStateChangedEvent, 1>>(
5243 JSRef<JSFunc>::Cast(args[0]), AudioStateChangedEventToJSValue);
5244
5245 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5246 const std::shared_ptr<BaseEventInfo>& info) {
5247 auto webNode = node.Upgrade();
5248 CHECK_NULL_VOID(webNode);
5249 ContainerScope scope(webNode->GetInstanceId());
5250 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5251 auto pipelineContext = PipelineContext::GetCurrentContext();
5252 if (pipelineContext) {
5253 pipelineContext->UpdateCurrentActiveNode(node);
5254 }
5255 auto* eventInfo = TypeInfoHelper::DynamicCast<AudioStateChangedEvent>(info.get());
5256 func->Execute(*eventInfo);
5257 };
5258 WebModel::GetInstance()->SetAudioStateChangedId(std::move(uiCallback));
5259 }
5260
MediaOptions(const JSCallbackInfo & args)5261 void JSWeb::MediaOptions(const JSCallbackInfo& args)
5262 {
5263 if (!args[0]->IsObject()) {
5264 return;
5265 }
5266 auto paramObject = JSRef<JSObject>::Cast(args[0]);
5267 auto resumeIntervalObj = paramObject->GetProperty("resumeInterval");
5268 if (resumeIntervalObj->IsNumber()) {
5269 int32_t resumeInterval = resumeIntervalObj->ToNumber<int32_t>();
5270 WebModel::GetInstance()->SetAudioResumeInterval(resumeInterval);
5271 }
5272
5273 auto audioExclusiveObj = paramObject->GetProperty("audioExclusive");
5274 if (audioExclusiveObj->IsBoolean()) {
5275 bool audioExclusive = audioExclusiveObj->ToBoolean();
5276 WebModel::GetInstance()->SetAudioExclusive(audioExclusive);
5277 }
5278
5279 RETURN_IF_CALLING_FROM_M114();
5280 auto audioSessionTypeObj = paramObject->GetProperty("audioSessionType");
5281 auto audioSessionType = WebAudioSessionType::AUTO;
5282 if (audioSessionTypeObj->IsNumber()) {
5283 int32_t audioSessionTypeIntValue = audioSessionTypeObj->ToNumber<int32_t>();
5284 switch (audioSessionTypeIntValue) {
5285 case 0:
5286 audioSessionType = WebAudioSessionType::AUTO;
5287 break;
5288 case WEB_AUDIO_SESSION_TYPE_AMBIENT:
5289 audioSessionType = WebAudioSessionType::AMBIENT;
5290 break;
5291 default:
5292 audioSessionType = WebAudioSessionType::AUTO;
5293 }
5294 }
5295 WebModel::GetInstance()->SetAudioSessionType(audioSessionType);
5296 }
5297
FirstContentfulPaintEventToJSValue(const FirstContentfulPaintEvent & eventInfo)5298 JSRef<JSVal> FirstContentfulPaintEventToJSValue(const FirstContentfulPaintEvent& eventInfo)
5299 {
5300 JSRef<JSObject> obj = JSRef<JSObject>::New();
5301 obj->SetProperty<int64_t>("navigationStartTick", eventInfo.GetNavigationStartTick());
5302 obj->SetProperty<int64_t>("firstContentfulPaintMs", eventInfo.GetFirstContentfulPaintMs());
5303 return JSRef<JSVal>::Cast(obj);
5304 }
5305
OnFirstContentfulPaint(const JSCallbackInfo & args)5306 void JSWeb::OnFirstContentfulPaint(const JSCallbackInfo& args)
5307 {
5308 if (!args[0]->IsFunction()) {
5309 return;
5310 }
5311 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5312 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FirstContentfulPaintEvent, 1>>(
5313 JSRef<JSFunc>::Cast(args[0]), FirstContentfulPaintEventToJSValue);
5314
5315 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5316 const std::shared_ptr<BaseEventInfo>& info) {
5317 auto webNode = node.Upgrade();
5318 CHECK_NULL_VOID(webNode);
5319 ContainerScope scope(webNode->GetInstanceId());
5320 auto context = PipelineBase::GetCurrentContext();
5321 if (context) {
5322 context->UpdateCurrentActiveNode(node);
5323 }
5324 auto executor = Container::CurrentTaskExecutorSafely();
5325 CHECK_NULL_VOID(executor);
5326 executor->PostTask([execCtx, postFunc = func, info]() {
5327 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5328 auto* eventInfo = TypeInfoHelper::DynamicCast<FirstContentfulPaintEvent>(info.get());
5329 postFunc->Execute(*eventInfo);
5330 }, TaskExecutor::TaskType::UI, "ArkUIWebFirstContentfulPaint");
5331 };
5332 WebModel::GetInstance()->SetFirstContentfulPaintId(std::move(uiCallback));
5333 }
5334
FirstMeaningfulPaintEventToJSValue(const FirstMeaningfulPaintEvent & eventInfo)5335 JSRef<JSVal> FirstMeaningfulPaintEventToJSValue(const FirstMeaningfulPaintEvent& eventInfo)
5336 {
5337 JSRef<JSObject> obj = JSRef<JSObject>::New();
5338 obj->SetProperty("navigationStartTime", eventInfo.GetNavigationStartTime());
5339 obj->SetProperty("firstMeaningfulPaintTime", eventInfo.GetFirstMeaningfulPaintTime());
5340 return JSRef<JSVal>::Cast(obj);
5341 }
5342
OnFirstMeaningfulPaint(const JSCallbackInfo & args)5343 void JSWeb::OnFirstMeaningfulPaint(const JSCallbackInfo& args)
5344 {
5345 if (args.Length() < 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsFunction()) {
5346 return;
5347 }
5348 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5349 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FirstMeaningfulPaintEvent, 1>>(
5350 JSRef<JSFunc>::Cast(args[0]), FirstMeaningfulPaintEventToJSValue);
5351 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5352 const std::shared_ptr<BaseEventInfo>& info) {
5353 auto webNode = node.Upgrade();
5354 CHECK_NULL_VOID(webNode);
5355 ContainerScope scope(webNode->GetInstanceId());
5356 auto context = PipelineBase::GetCurrentContext();
5357 if (context) {
5358 context->UpdateCurrentActiveNode(node);
5359 }
5360 auto executor = Container::CurrentTaskExecutorSafely();
5361 CHECK_NULL_VOID(executor);
5362 executor->PostTask([execCtx, postFunc = func, info]() {
5363 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5364 auto* eventInfo = TypeInfoHelper::DynamicCast<FirstMeaningfulPaintEvent>(info.get());
5365 postFunc->Execute(*eventInfo);
5366 }, TaskExecutor::TaskType::UI, "ArkUIWebFirstMeaningfulPaint");
5367 };
5368 WebModel::GetInstance()->SetFirstMeaningfulPaintId(std::move(uiCallback));
5369 }
5370
LargestContentfulPaintEventToJSValue(const LargestContentfulPaintEvent & eventInfo)5371 JSRef<JSVal> LargestContentfulPaintEventToJSValue(const LargestContentfulPaintEvent& eventInfo)
5372 {
5373 JSRef<JSObject> obj = JSRef<JSObject>::New();
5374 obj->SetProperty("navigationStartTime", eventInfo.GetNavigationStartTime());
5375 obj->SetProperty("largestImagePaintTime", eventInfo.GetLargestImagePaintTime());
5376 obj->SetProperty("largestTextPaintTime", eventInfo.GetLargestTextPaintTime());
5377 obj->SetProperty("largestImageLoadStartTime", eventInfo.GetLargestImageLoadStartTime());
5378 obj->SetProperty("largestImageLoadEndTime", eventInfo.GetLargestImageLoadEndTime());
5379 obj->SetProperty("imageBPP", eventInfo.GetImageBPP());
5380 return JSRef<JSVal>::Cast(obj);
5381 }
5382
OnLargestContentfulPaint(const JSCallbackInfo & args)5383 void JSWeb::OnLargestContentfulPaint(const JSCallbackInfo& args)
5384 {
5385 if (args.Length() < 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsFunction()) {
5386 return;
5387 }
5388 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5389 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LargestContentfulPaintEvent, 1>>(
5390 JSRef<JSFunc>::Cast(args[0]), LargestContentfulPaintEventToJSValue);
5391 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5392 const std::shared_ptr<BaseEventInfo>& info) {
5393 auto webNode = node.Upgrade();
5394 CHECK_NULL_VOID(webNode);
5395 ContainerScope scope(webNode->GetInstanceId());
5396 auto context = PipelineBase::GetCurrentContext();
5397 if (context) {
5398 context->UpdateCurrentActiveNode(node);
5399 }
5400 auto executor = Container::CurrentTaskExecutorSafely();
5401 CHECK_NULL_VOID(executor);
5402 executor->PostTask([execCtx, postFunc = func, info]() {
5403 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5404 auto* eventInfo = TypeInfoHelper::DynamicCast<LargestContentfulPaintEvent>(info.get());
5405 postFunc->Execute(*eventInfo);
5406 }, TaskExecutor::TaskType::UI, "ArkUIWebLargestContentfulPaint");
5407 };
5408 WebModel::GetInstance()->SetLargestContentfulPaintId(std::move(uiCallback));
5409 }
5410
SafeBrowsingCheckResultEventToJSValue(const SafeBrowsingCheckResultEvent & eventInfo)5411 JSRef<JSVal> SafeBrowsingCheckResultEventToJSValue(const SafeBrowsingCheckResultEvent& eventInfo)
5412 {
5413 JSRef<JSObject> obj = JSRef<JSObject>::New();
5414 obj->SetProperty("threatType", eventInfo.GetThreatType());
5415 return JSRef<JSVal>::Cast(obj);
5416 }
5417
OnSafeBrowsingCheckResult(const JSCallbackInfo & args)5418 void JSWeb::OnSafeBrowsingCheckResult(const JSCallbackInfo& args)
5419 {
5420 if (args.Length() < 1 || !args[0]->IsFunction()) {
5421 return;
5422 }
5423 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5424 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<SafeBrowsingCheckResultEvent, 1>>(
5425 JSRef<JSFunc>::Cast(args[0]), SafeBrowsingCheckResultEventToJSValue);
5426
5427 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5428 const std::shared_ptr<BaseEventInfo>& info) {
5429 auto webNode = node.Upgrade();
5430 CHECK_NULL_VOID(webNode);
5431 ContainerScope scope(webNode->GetInstanceId());
5432 auto context = PipelineBase::GetCurrentContext();
5433 if (context) {
5434 context->UpdateCurrentActiveNode(node);
5435 }
5436 auto executor = Container::CurrentTaskExecutorSafely();
5437 CHECK_NULL_VOID(executor);
5438 executor->PostTask([execCtx, postFunc = func, info]() {
5439 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5440 auto* eventInfo = TypeInfoHelper::DynamicCast<SafeBrowsingCheckResultEvent>(info.get());
5441 postFunc->Execute(*eventInfo);
5442 }, TaskExecutor::TaskType::UI, "ArkUIWebSafeBrowsingCheckResult");
5443 };
5444 WebModel::GetInstance()->SetSafeBrowsingCheckResultId(std::move(uiCallback));
5445 }
5446
NavigationEntryCommittedEventToJSValue(const NavigationEntryCommittedEvent & eventInfo)5447 JSRef<JSVal> NavigationEntryCommittedEventToJSValue(const NavigationEntryCommittedEvent& eventInfo)
5448 {
5449 JSRef<JSObject> obj = JSRef<JSObject>::New();
5450 obj->SetProperty("isMainFrame", eventInfo.IsMainFrame());
5451 obj->SetProperty("isSameDocument", eventInfo.IsSameDocument());
5452 obj->SetProperty("didReplaceEntry", eventInfo.DidReplaceEntry());
5453 obj->SetProperty("navigationType", static_cast<int>(eventInfo.GetNavigationType()));
5454 obj->SetProperty("url", eventInfo.GetUrl());
5455 return JSRef<JSVal>::Cast(obj);
5456 }
5457
OnNavigationEntryCommitted(const JSCallbackInfo & args)5458 void JSWeb::OnNavigationEntryCommitted(const JSCallbackInfo& args)
5459 {
5460 if (!args[0]->IsFunction()) {
5461 return;
5462 }
5463 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5464 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<NavigationEntryCommittedEvent, 1>>(
5465 JSRef<JSFunc>::Cast(args[0]), NavigationEntryCommittedEventToJSValue);
5466
5467 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5468 const std::shared_ptr<BaseEventInfo>& info) {
5469 auto webNode = node.Upgrade();
5470 CHECK_NULL_VOID(webNode);
5471 ContainerScope scope(webNode->GetInstanceId());
5472 auto context = PipelineBase::GetCurrentContext();
5473 if (context) {
5474 context->UpdateCurrentActiveNode(node);
5475 }
5476 auto executor = Container::CurrentTaskExecutorSafely();
5477 CHECK_NULL_VOID(executor);
5478 executor->PostTask([execCtx, postFunc = func, info]() {
5479 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5480 auto* eventInfo = TypeInfoHelper::DynamicCast<NavigationEntryCommittedEvent>(info.get());
5481 postFunc->Execute(*eventInfo);
5482 }, TaskExecutor::TaskType::UI, "ArkUIWebNavigationEntryCommitted");
5483 };
5484 WebModel::GetInstance()->SetNavigationEntryCommittedId(std::move(uiCallback));
5485 }
5486
IntelligentTrackingPreventionResultEventToJSValue(const IntelligentTrackingPreventionResultEvent & eventInfo)5487 JSRef<JSVal> IntelligentTrackingPreventionResultEventToJSValue(
5488 const IntelligentTrackingPreventionResultEvent& eventInfo)
5489 {
5490 JSRef<JSObject> obj = JSRef<JSObject>::New();
5491 obj->SetProperty("host", eventInfo.GetHost());
5492 obj->SetProperty("trackerHost", eventInfo.GetTrackerHost());
5493 return JSRef<JSVal>::Cast(obj);
5494 }
5495
OnIntelligentTrackingPreventionResult(const JSCallbackInfo & args)5496 void JSWeb::OnIntelligentTrackingPreventionResult(const JSCallbackInfo& args)
5497 {
5498 if (args.Length() < 1 || !args[0]->IsFunction()) {
5499 return;
5500 }
5501 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5502 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<IntelligentTrackingPreventionResultEvent, 1>>(
5503 JSRef<JSFunc>::Cast(args[0]), IntelligentTrackingPreventionResultEventToJSValue);
5504
5505 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5506 const std::shared_ptr<BaseEventInfo>& info) {
5507 auto webNode = node.Upgrade();
5508 CHECK_NULL_VOID(webNode);
5509 ContainerScope scope(webNode->GetInstanceId());
5510 auto context = PipelineBase::GetCurrentContext();
5511 if (context) {
5512 context->UpdateCurrentActiveNode(node);
5513 }
5514 auto executor = Container::CurrentTaskExecutorSafely();
5515 CHECK_NULL_VOID(executor);
5516 executor->PostTask([execCtx, postFunc = func, info]() {
5517 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5518 auto* eventInfo = TypeInfoHelper::DynamicCast<IntelligentTrackingPreventionResultEvent>(info.get());
5519 postFunc->Execute(*eventInfo);
5520 }, TaskExecutor::TaskType::UI, "ArkUIWebIntelligentTrackingPreventionResult");
5521 };
5522 WebModel::GetInstance()->SetIntelligentTrackingPreventionResultId(std::move(uiCallback));
5523 }
5524
OnControllerAttached(const JSCallbackInfo & args)5525 void JSWeb::OnControllerAttached(const JSCallbackInfo& args)
5526 {
5527 if (!args[0]->IsFunction()) {
5528 return;
5529 }
5530 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5531 auto jsFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(args[0]));
5532 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode]() {
5533 auto webNode = node.Upgrade();
5534 CHECK_NULL_VOID(webNode);
5535 ContainerScope scope(webNode->GetInstanceId());
5536 auto context = PipelineBase::GetCurrentContext();
5537 if (context) {
5538 context->UpdateCurrentActiveNode(node);
5539 }
5540 auto executor = Container::CurrentTaskExecutorSafely();
5541 CHECK_NULL_VOID(executor);
5542 executor->PostSyncTask([execCtx, postFunc = func]() {
5543 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5544 postFunc->Execute();
5545 }, TaskExecutor::TaskType::UI, "ArkUIWebControllerAttached");
5546 };
5547 WebModel::GetInstance()->SetOnControllerAttached(std::move(uiCallback));
5548 }
5549
EmbedLifecycleChangeToJSValue(const NativeEmbedDataInfo & eventInfo)5550 JSRef<JSVal> EmbedLifecycleChangeToJSValue(const NativeEmbedDataInfo& eventInfo)
5551 {
5552 JSRef<JSObject> obj = JSRef<JSObject>::New();
5553 obj->SetProperty("status", static_cast<int32_t>(eventInfo.GetStatus()));
5554 obj->SetProperty("surfaceId", eventInfo.GetSurfaceId());
5555 obj->SetProperty("embedId", eventInfo.GetEmbedId());
5556
5557 JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
5558 JSRef<JSObject> requestObj = objectTemplate->NewInstance();
5559 requestObj->SetProperty("id", eventInfo.GetEmebdInfo().id);
5560 requestObj->SetProperty("type", eventInfo.GetEmebdInfo().type);
5561 requestObj->SetProperty("src", eventInfo.GetEmebdInfo().src);
5562 requestObj->SetProperty("tag", eventInfo.GetEmebdInfo().tag);
5563 requestObj->SetProperty("width", eventInfo.GetEmebdInfo().width);
5564 requestObj->SetProperty("height", eventInfo.GetEmebdInfo().height);
5565 requestObj->SetProperty("url", eventInfo.GetEmebdInfo().url);
5566
5567 JSRef<JSObject> positionObj = objectTemplate->NewInstance();
5568 positionObj->SetProperty("x", eventInfo.GetEmebdInfo().x);
5569 positionObj->SetProperty("y", eventInfo.GetEmebdInfo().y);
5570 requestObj->SetPropertyObject("position", positionObj);
5571
5572 auto params = eventInfo.GetEmebdInfo().params;
5573 JSRef<JSObject> paramsObj = objectTemplate->NewInstance();
5574 for (const auto& item : params) {
5575 paramsObj->SetProperty(item.first.c_str(), item.second.c_str());
5576 }
5577 requestObj->SetPropertyObject("params", paramsObj);
5578
5579 obj->SetPropertyObject("info", requestObj);
5580
5581 return JSRef<JSVal>::Cast(obj);
5582 }
5583
EmbedVisibilityChangeToJSValue(const NativeEmbedVisibilityInfo & visibilityInfo)5584 JSRef<JSVal> EmbedVisibilityChangeToJSValue(const NativeEmbedVisibilityInfo& visibilityInfo)
5585 {
5586 JSRef<JSObject> obj = JSRef<JSObject>::New();
5587 obj->SetProperty("visibility", visibilityInfo.GetVisibility());
5588 obj->SetProperty("embedId", visibilityInfo.GetEmbedId());
5589
5590 return JSRef<JSVal>::Cast(obj);
5591 }
5592
OnNativeEmbedLifecycleChange(const JSCallbackInfo & args)5593 void JSWeb::OnNativeEmbedLifecycleChange(const JSCallbackInfo& args)
5594 {
5595 if (args.Length() < 1 || !args[0]->IsFunction()) {
5596 return;
5597 }
5598 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<NativeEmbedDataInfo, 1>>(
5599 JSRef<JSFunc>::Cast(args[0]), EmbedLifecycleChangeToJSValue);
5600 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5601 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5602 const BaseEventInfo* info) {
5603 int32_t instanceId = Container::CurrentIdSafely();
5604 auto webNode = node.Upgrade();
5605 if (webNode) {
5606 instanceId = webNode->GetInstanceId();
5607 }
5608 ContainerScope scope(instanceId);
5609 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5610 auto* eventInfo = TypeInfoHelper::DynamicCast<NativeEmbedDataInfo>(info);
5611 func->Execute(*eventInfo);
5612 };
5613 WebModel::GetInstance()->SetNativeEmbedLifecycleChangeId(jsCallback);
5614 }
5615
OnNativeEmbedVisibilityChange(const JSCallbackInfo & args)5616 void JSWeb::OnNativeEmbedVisibilityChange(const JSCallbackInfo& args)
5617 {
5618 if (args.Length() < 1 || !args[0]->IsFunction()) {
5619 return;
5620 }
5621 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<NativeEmbedVisibilityInfo, 1>>(
5622 JSRef<JSFunc>::Cast(args[0]), EmbedVisibilityChangeToJSValue);
5623 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5624 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5625 const BaseEventInfo* info) {
5626 auto webNode = node.Upgrade();
5627 CHECK_NULL_VOID(webNode);
5628 ContainerScope scope(webNode->GetInstanceId());
5629 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5630 auto* eventInfo = TypeInfoHelper::DynamicCast<NativeEmbedVisibilityInfo>(info);
5631 func->Execute(*eventInfo);
5632 };
5633 WebModel::GetInstance()->SetNativeEmbedVisibilityChangeId(jsCallback);
5634 }
5635
CreateTouchInfo(const TouchLocationInfo & touchInfo,TouchEventInfo & info)5636 JSRef<JSObject> CreateTouchInfo(const TouchLocationInfo& touchInfo, TouchEventInfo& info)
5637 {
5638 JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
5639 objectTemplate->SetInternalFieldCount(1);
5640 JSRef<JSObject> touchInfoObj = objectTemplate->NewInstance();
5641 const OHOS::Ace::Offset& globalLocation = touchInfo.GetGlobalLocation();
5642 const OHOS::Ace::Offset& localLocation = touchInfo.GetLocalLocation();
5643 const OHOS::Ace::Offset& screenLocation = touchInfo.GetScreenLocation();
5644 const OHOS::Ace::Offset& globalDisplayLocation = touchInfo.GetGlobalDisplayLocation();
5645 touchInfoObj->SetProperty<int32_t>("type", static_cast<int32_t>(touchInfo.GetTouchType()));
5646 touchInfoObj->SetProperty<int32_t>("id", touchInfo.GetFingerId());
5647 touchInfoObj->SetProperty<double>("displayX", screenLocation.GetX());
5648 touchInfoObj->SetProperty<double>("displayY", screenLocation.GetY());
5649 touchInfoObj->SetProperty<double>("windowX", globalLocation.GetX());
5650 touchInfoObj->SetProperty<double>("windowY", globalLocation.GetY());
5651 touchInfoObj->SetProperty<double>("screenX", globalLocation.GetX());
5652 touchInfoObj->SetProperty<double>("screenY", globalLocation.GetY());
5653 touchInfoObj->SetProperty<double>("x", localLocation.GetX());
5654 touchInfoObj->SetProperty<double>("y", localLocation.GetY());
5655 touchInfoObj->SetProperty<double>("globalDisplayX", globalDisplayLocation.GetX());
5656 touchInfoObj->SetProperty<double>("globalDisplayY", globalDisplayLocation.GetY());
5657 touchInfoObj->Wrap<TouchEventInfo>(&info);
5658 return touchInfoObj;
5659 }
5660
NativeEmbeadTouchToJSValue(const NativeEmbeadTouchInfo & eventInfo)5661 JSRef<JSVal> NativeEmbeadTouchToJSValue(const NativeEmbeadTouchInfo& eventInfo)
5662 {
5663 JSRef<JSObject> obj = JSRef<JSObject>::New();
5664 obj->SetProperty("embedId", eventInfo.GetEmbedId());
5665 auto info = eventInfo.GetTouchEventInfo();
5666 JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
5667 JSRef<JSObject> eventObj = objectTemplate->NewInstance();
5668 JSRef<JSArray> touchArr = JSRef<JSArray>::New();
5669 JSRef<JSArray> changeTouchArr = JSRef<JSArray>::New();
5670 eventObj->SetProperty("source", static_cast<int32_t>(info.GetSourceDevice()));
5671 eventObj->SetProperty("timestamp", static_cast<double>(GetSysTimestamp()));
5672 auto target = CreateEventTargetObject(info);
5673 eventObj->SetPropertyObject("target", target);
5674 eventObj->SetProperty("pressure", info.GetForce());
5675 eventObj->SetProperty("sourceTool", static_cast<int32_t>(info.GetSourceTool()));
5676 eventObj->SetProperty("targetDisplayId", static_cast<int32_t>(info.GetTargetDisplayId()));
5677 eventObj->SetProperty("deviceId", static_cast<int64_t>(info.GetDeviceId()));
5678
5679 if (info.GetChangedTouches().empty()) {
5680 return JSRef<JSVal>::Cast(obj);
5681 }
5682 uint32_t index = 0;
5683 TouchLocationInfo changeTouch = info.GetChangedTouches().back();
5684 JSRef<JSObject> changeTouchElement = CreateTouchInfo(changeTouch, info);
5685 changeTouchArr->SetValueAt(index, changeTouchElement);
5686 if (info.GetChangedTouches().size() > 0) {
5687 eventObj->SetProperty("type", static_cast<int32_t>(changeTouch.GetTouchType()));
5688 }
5689
5690 const std::list<TouchLocationInfo>& touchList = info.GetTouches();
5691 for (const TouchLocationInfo& location : touchList) {
5692 if (location.GetFingerId() == changeTouch.GetFingerId()) {
5693 JSRef<JSObject> touchElement = CreateTouchInfo(changeTouch, info);
5694 touchArr->SetValueAt(index++, touchElement);
5695 } else {
5696 JSRef<JSObject> touchElement = CreateTouchInfo(location, info);
5697 touchArr->SetValueAt(index++, touchElement);
5698 }
5699 }
5700 eventObj->SetPropertyObject("touches", touchArr);
5701 eventObj->SetPropertyObject("changedTouches", changeTouchArr);
5702 obj->SetPropertyObject("touchEvent", eventObj);
5703 JSRef<JSObject> requestObj = JSClass<JSNativeEmbedGestureRequest>::NewInstance();
5704 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSNativeEmbedGestureRequest>());
5705 requestEvent->SetResult(eventInfo.GetResult());
5706 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(requestObj), static_cast<void *>(requestEvent.GetRawPtr()));
5707 obj->SetPropertyObject("result", requestObj);
5708 return JSRef<JSVal>::Cast(obj);
5709 }
5710
NativeEmbeadMouseToJSValue(const NativeEmbeadMouseInfo & eventInfo)5711 JSRef<JSVal> NativeEmbeadMouseToJSValue(const NativeEmbeadMouseInfo& eventInfo)
5712 {
5713 auto info = eventInfo.GetMouseEventInfo();
5714 JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
5715 JSRef<JSObject> eventObj = objectTemplate->NewInstance();
5716 eventObj->SetProperty("source", static_cast<int32_t>(info.GetSourceDevice()));
5717 eventObj->SetProperty("timestamp", static_cast<double>(GetSysTimestamp()));
5718 auto target = CreateEventTargetObject(info);
5719 eventObj->SetPropertyObject("target", target);
5720 eventObj->SetProperty("pressure", info.GetForce());
5721 eventObj->SetProperty("sourceTool", static_cast<int32_t>(info.GetSourceTool()));
5722 eventObj->SetProperty("targetDisplayId", static_cast<int32_t>(info.GetTargetDisplayId()));
5723 eventObj->SetProperty("deviceId", static_cast<int64_t>(info.GetDeviceId()));
5724
5725 eventObj->SetProperty<int32_t>("button", static_cast<int32_t>(info.GetButton()));
5726 eventObj->SetProperty<int32_t>("action", static_cast<int32_t>(info.GetAction()));
5727 Offset globalOffset = info.GetGlobalLocation();
5728 Offset localOffset = info.GetLocalLocation();
5729 Offset screenOffset = info.GetScreenLocation();
5730 eventObj->SetProperty<double>("displayX", screenOffset.GetX());
5731 eventObj->SetProperty<double>("displayY", screenOffset.GetY());
5732 eventObj->SetProperty<double>("windowX", globalOffset.GetX());
5733 eventObj->SetProperty<double>("windowY", globalOffset.GetY());
5734 eventObj->SetProperty<double>("screenX", globalOffset.GetX());
5735 eventObj->SetProperty<double>("screenY", globalOffset.GetY());
5736 eventObj->SetProperty<double>("x", localOffset.GetX());
5737 eventObj->SetProperty<double>("y", localOffset.GetY());
5738
5739 JSRef<JSObject> obj = JSRef<JSObject>::New();
5740 obj->SetProperty("embedId", eventInfo.GetEmbedId());
5741 obj->SetPropertyObject("mouseEvent", eventObj);
5742 JSRef<JSObject> requestObj = JSClass<JSNativeEmbedMouseRequest>::NewInstance();
5743 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSNativeEmbedMouseRequest>());
5744 requestEvent->SetResult(eventInfo.GetResult());
5745 obj->SetPropertyObject("result", requestObj);
5746 return JSRef<JSVal>::Cast(obj);
5747 }
5748
CreateNativeEmbedGestureHandler(const NativeEmbeadTouchInfo & eventInfo)5749 JSRef<JSVal> JSWeb::CreateNativeEmbedGestureHandler(const NativeEmbeadTouchInfo& eventInfo)
5750 {
5751 JSRef<JSObject> requestObj = JSClass<JSNativeEmbedGestureRequest>::NewInstance();
5752 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSNativeEmbedGestureRequest>());
5753 requestEvent->SetResult(eventInfo.GetResult());
5754 return requestObj;
5755 }
5756
OnNativeEmbedGestureEvent(const JSCallbackInfo & args)5757 void JSWeb::OnNativeEmbedGestureEvent(const JSCallbackInfo& args)
5758 {
5759 if (args.Length() < 1 || !args[0]->IsFunction()) {
5760 return;
5761 }
5762 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<NativeEmbeadTouchInfo, 1>>(
5763 JSRef<JSFunc>::Cast(args[0]), NativeEmbeadTouchToJSValue);
5764 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5765 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5766 const BaseEventInfo* info) {
5767 auto webNode = node.Upgrade();
5768 CHECK_NULL_VOID(webNode);
5769 ContainerScope scope(webNode->GetInstanceId());
5770 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5771 auto* eventInfo = TypeInfoHelper::DynamicCast<NativeEmbeadTouchInfo>(info);
5772 func->Execute(*eventInfo);
5773 };
5774 WebModel::GetInstance()->SetNativeEmbedGestureEventId(jsCallback);
5775 }
5776
OnNativeEmbedMouseEvent(const JSCallbackInfo & args)5777 void JSWeb::OnNativeEmbedMouseEvent(const JSCallbackInfo& args)
5778 {
5779 RETURN_IF_CALLING_FROM_M114();
5780 if (args.Length() < 1 || !args[0]->IsFunction()) {
5781 return;
5782 }
5783 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<NativeEmbeadMouseInfo, 1>>(
5784 JSRef<JSFunc>::Cast(args[0]), NativeEmbeadMouseToJSValue);
5785 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5786 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5787 const BaseEventInfo* info) {
5788 auto webNode = node.Upgrade();
5789 CHECK_NULL_VOID(webNode);
5790 ContainerScope scope(webNode->GetInstanceId());
5791 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5792 auto* eventInfo = TypeInfoHelper::DynamicCast<NativeEmbeadMouseInfo>(info);
5793 func->Execute(*eventInfo);
5794 };
5795 WebModel::GetInstance()->SetNativeEmbedMouseEventId(jsCallback);
5796 }
5797
OverScrollEventToJSValue(const WebOnOverScrollEvent & eventInfo)5798 JSRef<JSVal> OverScrollEventToJSValue(const WebOnOverScrollEvent& eventInfo)
5799 {
5800 JSRef<JSObject> obj = JSRef<JSObject>::New();
5801 obj->SetProperty("xOffset", eventInfo.GetX());
5802 obj->SetProperty("yOffset", eventInfo.GetY());
5803 return JSRef<JSVal>::Cast(obj);
5804 }
5805
OnOverScroll(const JSCallbackInfo & args)5806 void JSWeb::OnOverScroll(const JSCallbackInfo& args)
5807 {
5808 if (args.Length() < 1 || !args[0]->IsFunction()) {
5809 return;
5810 }
5811 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5812 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebOnOverScrollEvent, 1>>(
5813 JSRef<JSFunc>::Cast(args[0]), OverScrollEventToJSValue);
5814 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
5815 const BaseEventInfo* info) {
5816 auto webNode = node.Upgrade();
5817 CHECK_NULL_VOID(webNode);
5818 ContainerScope scope(webNode->GetInstanceId());
5819 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5820 auto pipelineContext = PipelineContext::GetCurrentContext();
5821 if (pipelineContext) {
5822 pipelineContext->UpdateCurrentActiveNode(node);
5823 }
5824 auto* eventInfo = TypeInfoHelper::DynamicCast<WebOnOverScrollEvent>(info);
5825 func->Execute(*eventInfo);
5826 };
5827 WebModel::GetInstance()->SetOverScrollId(jsCallback);
5828 }
5829
SetLayoutMode(int32_t layoutMode)5830 void JSWeb::SetLayoutMode(int32_t layoutMode)
5831 {
5832 auto mode = WebLayoutMode::NONE;
5833 switch (layoutMode) {
5834 case 0:
5835 mode = WebLayoutMode::NONE;
5836 break;
5837 case 1:
5838 mode = WebLayoutMode::FIT_CONTENT;
5839 break;
5840 default:
5841 mode = WebLayoutMode::NONE;
5842 break;
5843 }
5844 WebModel::GetInstance()->SetLayoutMode(mode);
5845 }
5846
SetNestedScroll(const JSCallbackInfo & args)5847 void JSWeb::SetNestedScroll(const JSCallbackInfo& args)
5848 {
5849 NestedScrollOptionsExt nestedOpt = {
5850 .scrollUp = NestedScrollMode::SELF_FIRST,
5851 .scrollDown = NestedScrollMode::SELF_FIRST,
5852 .scrollLeft = NestedScrollMode::SELF_FIRST,
5853 .scrollRight = NestedScrollMode::SELF_FIRST,
5854 };
5855 if (args.Length() < 1 || !args[0]->IsObject()) {
5856 WebModel::GetInstance()->SetNestedScrollExt(nestedOpt);
5857 return;
5858 }
5859 JSRef<JSObject> obj = JSRef<JSObject>::Cast(args[0]);
5860 int32_t froward = -1;
5861 JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollForward"), froward);
5862 if (CheckNestedScrollMode(froward)) {
5863 nestedOpt.scrollDown = static_cast<NestedScrollMode>(froward);
5864 nestedOpt.scrollRight = static_cast<NestedScrollMode>(froward);
5865 }
5866 int32_t backward = -1;
5867 JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollBackward"), backward);
5868 if (CheckNestedScrollMode(backward)) {
5869 nestedOpt.scrollUp = static_cast<NestedScrollMode>(backward);
5870 nestedOpt.scrollLeft = static_cast<NestedScrollMode>(backward);
5871 }
5872 int32_t scrollUp = -1;
5873 JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollUp"), scrollUp);
5874 if (CheckNestedScrollMode(scrollUp)) {
5875 nestedOpt.scrollUp = static_cast<NestedScrollMode>(scrollUp);
5876 }
5877 int32_t scrollDown = -1;
5878 JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollDown"), scrollDown);
5879 if (CheckNestedScrollMode(scrollDown)) {
5880 nestedOpt.scrollDown = static_cast<NestedScrollMode>(scrollDown);
5881 }
5882 int32_t scrollLeft = -1;
5883 JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollLeft"), scrollLeft);
5884 if (CheckNestedScrollMode(scrollLeft)) {
5885 nestedOpt.scrollLeft = static_cast<NestedScrollMode>(scrollLeft);
5886 }
5887 int32_t scrollRight = -1;
5888 JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollRight"), scrollRight);
5889 if (CheckNestedScrollMode(scrollRight)) {
5890 nestedOpt.scrollRight = static_cast<NestedScrollMode>(scrollRight);
5891 }
5892 WebModel::GetInstance()->SetNestedScrollExt(nestedOpt);
5893 args.ReturnSelf();
5894 }
5895
CheckNestedScrollMode(const int32_t & modeValue)5896 bool JSWeb::CheckNestedScrollMode(const int32_t& modeValue)
5897 {
5898 return modeValue >= static_cast<int32_t>(NestedScrollMode::SELF_ONLY) &&
5899 modeValue <= static_cast<int32_t>(NestedScrollMode::PARALLEL);
5900 }
5901
SetMetaViewport(const JSCallbackInfo & args)5902 void JSWeb::SetMetaViewport(const JSCallbackInfo& args)
5903 {
5904 if (args.Length() < 1 || !args[0]->IsBoolean()) {
5905 return;
5906 }
5907 bool enabled = args[0]->ToBoolean();
5908 WebModel::GetInstance()->SetMetaViewport(enabled);
5909 }
5910
ParseScriptItems(const JSCallbackInfo & args,ScriptItems & scriptItems,ScriptItemsByOrder & scriptItemsByOrder)5911 void JSWeb::ParseScriptItems(
5912 const JSCallbackInfo& args, ScriptItems& scriptItems, ScriptItemsByOrder& scriptItemsByOrder)
5913 {
5914 if (args.Length() != 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsArray()) {
5915 return;
5916 }
5917 auto paramArray = JSRef<JSArray>::Cast(args[0]);
5918 size_t length = paramArray->Length();
5919 if (length == 0) {
5920 return;
5921 }
5922 std::string script;
5923 std::vector<std::string> scriptRules;
5924 for (size_t i = 0; i < length; i++) {
5925 auto item = paramArray->GetValueAt(i);
5926 if (!item->IsObject()) {
5927 return;
5928 }
5929 auto itemObject = JSRef<JSObject>::Cast(item);
5930 JSRef<JSVal> jsScript = itemObject->GetProperty("script");
5931 JSRef<JSVal> jsScriptRules = itemObject->GetProperty("scriptRules");
5932 if (!jsScriptRules->IsArray() || JSRef<JSArray>::Cast(jsScriptRules)->Length() == 0) {
5933 return;
5934 }
5935 if (!JSViewAbstract::ParseJsString(jsScript, script)) {
5936 return;
5937 }
5938 scriptRules.clear();
5939 if (!JSViewAbstract::ParseJsStrArray(jsScriptRules, scriptRules)) {
5940 return;
5941 }
5942 if (scriptItems.find(script) == scriptItems.end()) {
5943 scriptItems.insert(std::make_pair(script, scriptRules));
5944 scriptItemsByOrder.emplace_back(script);
5945 }
5946 }
5947 }
5948
JavaScriptOnDocumentStart(const JSCallbackInfo & args)5949 void JSWeb::JavaScriptOnDocumentStart(const JSCallbackInfo& args)
5950 {
5951 ScriptItems scriptItems;
5952 ScriptItemsByOrder scriptItemsByOrder;
5953 ParseScriptItems(args, scriptItems, scriptItemsByOrder);
5954
5955 WebModel::GetInstance()->JavaScriptOnDocumentStart(scriptItems);
5956 }
5957
JavaScriptOnDocumentEnd(const JSCallbackInfo & args)5958 void JSWeb::JavaScriptOnDocumentEnd(const JSCallbackInfo& args)
5959 {
5960 ScriptItems scriptItems;
5961 ScriptItemsByOrder scriptItemsByOrder;
5962 ParseScriptItems(args, scriptItems, scriptItemsByOrder);
5963
5964 WebModel::GetInstance()->JavaScriptOnDocumentEnd(scriptItems);
5965 }
5966
RunJavaScriptOnDocumentStart(const JSCallbackInfo & args)5967 void JSWeb::RunJavaScriptOnDocumentStart(const JSCallbackInfo& args)
5968 {
5969 ScriptItems scriptItems;
5970 ScriptItemsByOrder scriptItemsByOrder;
5971 ParseScriptItems(args, scriptItems, scriptItemsByOrder);
5972
5973 WebModel::GetInstance()->JavaScriptOnDocumentStartByOrder(scriptItems, scriptItemsByOrder);
5974 }
5975
RunJavaScriptOnDocumentEnd(const JSCallbackInfo & args)5976 void JSWeb::RunJavaScriptOnDocumentEnd(const JSCallbackInfo& args)
5977 {
5978 ScriptItems scriptItems;
5979 ScriptItemsByOrder scriptItemsByOrder;
5980 ParseScriptItems(args, scriptItems, scriptItemsByOrder);
5981
5982 WebModel::GetInstance()->JavaScriptOnDocumentEndByOrder(scriptItems, scriptItemsByOrder);
5983 }
5984
RunJavaScriptOnHeadEnd(const JSCallbackInfo & args)5985 void JSWeb::RunJavaScriptOnHeadEnd(const JSCallbackInfo& args)
5986 {
5987 ScriptItems scriptItems;
5988 ScriptItemsByOrder scriptItemsByOrder;
5989 ParseScriptItems(args, scriptItems, scriptItemsByOrder);
5990
5991 WebModel::GetInstance()->JavaScriptOnHeadReadyByOrder(scriptItems, scriptItemsByOrder);
5992 }
5993
OnOverrideUrlLoading(const JSCallbackInfo & args)5994 void JSWeb::OnOverrideUrlLoading(const JSCallbackInfo& args)
5995 {
5996 if (args.Length() < 1 || !args[0]->IsFunction()) {
5997 return;
5998 }
5999 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadOverrideEvent, 1>>(
6000 JSRef<JSFunc>::Cast(args[0]), LoadOverrideEventToJSValue);
6001
6002 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6003 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
6004 const BaseEventInfo* info) -> bool {
6005 auto webNode = node.Upgrade();
6006 CHECK_NULL_RETURN(webNode, false);
6007 ContainerScope scope(webNode->GetInstanceId());
6008 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
6009 auto pipelineContext = PipelineContext::GetCurrentContext();
6010 if (pipelineContext) {
6011 pipelineContext->UpdateCurrentActiveNode(node);
6012 }
6013 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadOverrideEvent>(info);
6014 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
6015 if (message->IsBoolean()) {
6016 return message->ToBoolean();
6017 }
6018 return false;
6019 };
6020 WebModel::GetInstance()->SetOnOverrideUrlLoading(std::move(uiCallback));
6021 }
6022
CopyOption(int32_t copyOption)6023 void JSWeb::CopyOption(int32_t copyOption)
6024 {
6025 auto mode = CopyOptions::Local;
6026 switch (copyOption) {
6027 case static_cast<int32_t>(CopyOptions::None):
6028 mode = CopyOptions::None;
6029 break;
6030 case static_cast<int32_t>(CopyOptions::InApp):
6031 mode = CopyOptions::InApp;
6032 break;
6033 case static_cast<int32_t>(CopyOptions::Local):
6034 mode = CopyOptions::Local;
6035 break;
6036 case static_cast<int32_t>(CopyOptions::Distributed):
6037 mode = CopyOptions::Distributed;
6038 break;
6039 default:
6040 mode = CopyOptions::Local;
6041 break;
6042 }
6043 WebModel::GetInstance()->SetCopyOptionMode(mode);
6044 }
6045
TextAutosizing(const JSCallbackInfo & args)6046 void JSWeb::TextAutosizing(const JSCallbackInfo& args)
6047 {
6048 if (args.Length() < 1 || !args[0]->IsBoolean()) {
6049 return;
6050 }
6051 bool isTextAutosizing = args[0]->ToBoolean();
6052 WebModel::GetInstance()->SetTextAutosizing(isTextAutosizing);
6053 }
6054
EnableNativeVideoPlayer(const JSCallbackInfo & args)6055 void JSWeb::EnableNativeVideoPlayer(const JSCallbackInfo& args)
6056 {
6057 if (args.Length() < 1 || !args[0]->IsObject()) {
6058 return;
6059 }
6060 auto paramObject = JSRef<JSObject>::Cast(args[0]);
6061 std::optional<bool> enable;
6062 std::optional<bool> shouldOverlay;
6063 JSRef<JSVal> enableJsValue = paramObject->GetProperty("enable");
6064 if (enableJsValue->IsBoolean()) {
6065 enable = enableJsValue->ToBoolean();
6066 }
6067 JSRef<JSVal> shouldOverlayJsValue = paramObject->GetProperty("shouldOverlay");
6068 if (shouldOverlayJsValue->IsBoolean()) {
6069 shouldOverlay = shouldOverlayJsValue->ToBoolean();
6070 }
6071 if (!enable || !shouldOverlay) {
6072 // invalid NativeVideoPlayerConfig
6073 return;
6074 }
6075 WebModel::GetInstance()->SetNativeVideoPlayerConfig(*enable, *shouldOverlay);
6076 }
6077
RenderProcessNotRespondingToJSValue(const RenderProcessNotRespondingEvent & eventInfo)6078 JSRef<JSVal> RenderProcessNotRespondingToJSValue(const RenderProcessNotRespondingEvent& eventInfo)
6079 {
6080 JSRef<JSObject> obj = JSRef<JSObject>::New();
6081 obj->SetProperty("jsStack", eventInfo.GetJsStack());
6082 obj->SetProperty("pid", eventInfo.GetPid());
6083 obj->SetProperty("reason", eventInfo.GetReason());
6084 return JSRef<JSVal>::Cast(obj);
6085 }
6086
OnRenderProcessNotResponding(const JSCallbackInfo & args)6087 void JSWeb::OnRenderProcessNotResponding(const JSCallbackInfo& args)
6088 {
6089 if (args.Length() < 1 || !args[0]->IsFunction()) {
6090 return;
6091 }
6092 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6093 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<RenderProcessNotRespondingEvent, 1>>(
6094 JSRef<JSFunc>::Cast(args[0]), RenderProcessNotRespondingToJSValue);
6095 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
6096 const BaseEventInfo* info) {
6097 auto webNode = node.Upgrade();
6098 CHECK_NULL_VOID(webNode);
6099 ContainerScope scope(webNode->GetInstanceId());
6100 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
6101 auto pipelineContext = PipelineContext::GetCurrentContext();
6102 if (pipelineContext) {
6103 pipelineContext->UpdateCurrentActiveNode(node);
6104 }
6105 auto* eventInfo = TypeInfoHelper::DynamicCast<RenderProcessNotRespondingEvent>(info);
6106 func->Execute(*eventInfo);
6107 };
6108 WebModel::GetInstance()->SetRenderProcessNotRespondingId(jsCallback);
6109 }
6110
RenderProcessRespondingEventToJSValue(const RenderProcessRespondingEvent & eventInfo)6111 JSRef<JSVal> RenderProcessRespondingEventToJSValue(const RenderProcessRespondingEvent& eventInfo)
6112 {
6113 JSRef<JSObject> obj = JSRef<JSObject>::New();
6114 return JSRef<JSVal>::Cast(obj);
6115 }
6116
OnRenderProcessResponding(const JSCallbackInfo & args)6117 void JSWeb::OnRenderProcessResponding(const JSCallbackInfo& args)
6118 {
6119 if (args.Length() < 1 || !args[0]->IsFunction()) {
6120 return;
6121 }
6122 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6123 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<RenderProcessRespondingEvent, 1>>(
6124 JSRef<JSFunc>::Cast(args[0]), RenderProcessRespondingEventToJSValue);
6125 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
6126 const BaseEventInfo* info) {
6127 auto webNode = node.Upgrade();
6128 CHECK_NULL_VOID(webNode);
6129 ContainerScope scope(webNode->GetInstanceId());
6130 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
6131 auto pipelineContext = PipelineContext::GetCurrentContext();
6132 if (pipelineContext) {
6133 pipelineContext->UpdateCurrentActiveNode(node);
6134 }
6135 auto* eventInfo = TypeInfoHelper::DynamicCast<RenderProcessRespondingEvent>(info);
6136 func->Execute(*eventInfo);
6137 };
6138 WebModel::GetInstance()->SetRenderProcessRespondingId(jsCallback);
6139 }
6140
SelectionMenuOptions(const JSCallbackInfo & args)6141 void JSWeb::SelectionMenuOptions(const JSCallbackInfo& args)
6142 {
6143 if (args.Length() != 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsArray()) {
6144 return;
6145 }
6146 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6147 auto menuItamArray = JSRef<JSArray>::Cast(args[0]);
6148 WebMenuOptionsParam optionParam;
6149 NG::MenuOptionsParam menuOption;
6150 for (size_t i = 0; i < menuItamArray->Length(); i++) {
6151 auto menuItem = menuItamArray->GetValueAt(i);
6152 if (!menuItem->IsObject()) {
6153 return;
6154 }
6155 auto menuItemObject = JSRef<JSObject>::Cast(menuItem);
6156 auto jsContent = menuItemObject->GetProperty("content");
6157 auto jsStartIcon = menuItemObject->GetProperty("startIcon");
6158 std::string content;
6159 if (!ParseJsMedia(jsContent, content)) {
6160 return;
6161 }
6162 menuOption.content = content;
6163 std::string icon;
6164 menuOption.icon.reset();
6165 if (ParseJsMedia(jsStartIcon, icon)) {
6166 menuOption.icon = icon;
6167 }
6168 auto jsAction = menuItemObject->GetProperty("action");
6169 if (jsAction.IsEmpty() || !jsAction->IsFunction()) {
6170 return;
6171 }
6172 auto jsFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(jsAction));
6173 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc),
6174 node = frameNode](const std::string selectInfo) {
6175 auto webNode = node.Upgrade();
6176 CHECK_NULL_VOID(webNode);
6177 ContainerScope scope(webNode->GetInstanceId());
6178 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
6179 auto pipelineContext = PipelineContext::GetCurrentContext();
6180 if (pipelineContext) {
6181 pipelineContext->UpdateCurrentActiveNode(node);
6182 pipelineContext->SetCallBackNode(node);
6183 }
6184 auto newSelectInfo = JSRef<JSVal>::Make(ToJSValue(selectInfo));
6185 func->ExecuteJS(1, &newSelectInfo);
6186 };
6187 menuOption.action = std::move(jsCallback);
6188 optionParam.menuOption.push_back(menuOption);
6189 }
6190 WebModel::GetInstance()->SetSelectionMenuOptions(std::move(optionParam));
6191 }
6192
ViewportFitChangedToJSValue(const ViewportFitChangedEvent & eventInfo)6193 JSRef<JSVal> ViewportFitChangedToJSValue(const ViewportFitChangedEvent& eventInfo)
6194 {
6195 JSRef<JSObject> obj = JSRef<JSObject>::New();
6196 obj->SetProperty("viewportFit", eventInfo.GetViewportFit());
6197 return JSRef<JSVal>::Cast(obj);
6198 }
6199
OnViewportFitChanged(const JSCallbackInfo & args)6200 void JSWeb::OnViewportFitChanged(const JSCallbackInfo& args)
6201 {
6202 if (args.Length() < 1 || !args[0]->IsFunction()) {
6203 return;
6204 }
6205 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6206 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ViewportFitChangedEvent, 1>>(
6207 JSRef<JSFunc>::Cast(args[0]), ViewportFitChangedToJSValue);
6208 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
6209 const BaseEventInfo* info) {
6210 auto webNode = node.Upgrade();
6211 CHECK_NULL_VOID(webNode);
6212 ContainerScope scope(webNode->GetInstanceId());
6213 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
6214 auto pipelineContext = PipelineContext::GetCurrentContext();
6215 if (pipelineContext) {
6216 pipelineContext->UpdateCurrentActiveNode(node);
6217 }
6218 auto* eventInfo = TypeInfoHelper::DynamicCast<ViewportFitChangedEvent>(info);
6219 func->Execute(*eventInfo);
6220 };
6221 WebModel::GetInstance()->SetViewportFitChangedId(jsCallback);
6222 }
6223
InterceptKeyboardEventToJSValue(const InterceptKeyboardEvent & eventInfo)6224 JSRef<JSVal> InterceptKeyboardEventToJSValue(const InterceptKeyboardEvent& eventInfo)
6225 {
6226 JSRef<JSObject> obj = JSRef<JSObject>::New();
6227 JSRef<JSObject> webKeyboardControllerObj = JSClass<JSWebKeyboardController>::NewInstance();
6228 auto webKeyboardController = Referenced::Claim(webKeyboardControllerObj->Unwrap<JSWebKeyboardController>());
6229 webKeyboardController->SeWebKeyboardController(eventInfo.GetCustomKeyboardHandler());
6230 WrapNapiValue(GetNapiEnv(), JSRef<JSVal>::Cast(webKeyboardControllerObj),
6231 static_cast<void*>(webKeyboardController.GetRawPtr()));
6232 obj->SetPropertyObject("controller", webKeyboardControllerObj);
6233
6234 JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
6235 JSRef<JSObject> attributesObj = objectTemplate->NewInstance();
6236 for (const auto& item : eventInfo.GetAttributesMap()) {
6237 attributesObj->SetProperty(item.first.c_str(), item.second.c_str());
6238 }
6239 obj->SetPropertyObject("attributes", attributesObj);
6240 return JSRef<JSVal>::Cast(obj);
6241 }
6242
ParseJsCustomKeyboardOption(const JsiExecutionContext & context,const JSRef<JSVal> & keyboardOpt,WebKeyboardOption & keyboardOption)6243 void JSWeb::ParseJsCustomKeyboardOption(const JsiExecutionContext& context, const JSRef<JSVal>& keyboardOpt,
6244 WebKeyboardOption& keyboardOption)
6245 {
6246 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption enter");
6247 if (!keyboardOpt->IsObject()) {
6248 return;
6249 }
6250
6251 JSRef<JSObject> keyboradOptObj = JSRef<JSObject>::Cast(keyboardOpt);
6252 auto useSystemKeyboardObj = keyboradOptObj->GetProperty("useSystemKeyboard");
6253 if (useSystemKeyboardObj->IsNull() || !useSystemKeyboardObj->IsBoolean()) {
6254 return;
6255 }
6256
6257 bool isSystemKeyboard = useSystemKeyboardObj->ToBoolean();
6258 keyboardOption.isSystemKeyboard_ = isSystemKeyboard;
6259 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption isSystemKeyboard is %{public}d",
6260 isSystemKeyboard);
6261 if (isSystemKeyboard) {
6262 auto enterKeyTypeObj = keyboradOptObj->GetProperty("enterKeyType");
6263 if (enterKeyTypeObj->IsNull() || !enterKeyTypeObj->IsNumber()) {
6264 return;
6265 }
6266 int32_t enterKeyType = enterKeyTypeObj->ToNumber<int32_t>();
6267 keyboardOption.enterKeyTpye_ = enterKeyType;
6268 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption \
6269 isSystemKeyboard is %{public}d, enterKeyType is %{public}d", isSystemKeyboard, enterKeyType);
6270 } else {
6271 auto builder = keyboradOptObj->GetProperty("customKeyboard");
6272 if (builder->IsNull()) {
6273 TAG_LOGE(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption" \
6274 ", parse customKeyboard, builder is null");
6275 return;
6276 }
6277
6278 if (!builder->IsFunction()) {
6279 TAG_LOGE(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption" \
6280 ", parse customKeyboard, builder is invalid");
6281 return;
6282 }
6283
6284 auto builderFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(builder));
6285 CHECK_NULL_VOID(builderFunc);
6286 WeakPtr<NG::FrameNode> targetNode =
6287 AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6288 auto buildFunc = [execCtx = context, func = std::move(builderFunc), node = targetNode]() {
6289 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
6290 ACE_SCORING_EVENT("WebCustomKeyboard");
6291 PipelineContext::SetCallBackNode(node);
6292 func->Execute();
6293 };
6294 keyboardOption.customKeyboardBuilder_ = buildFunc;
6295 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption" \
6296 ", isSystemKeyboard is %{public}d, parseCustomBuilder end", isSystemKeyboard);
6297 }
6298 }
6299
OnInterceptKeyboardAttach(const JSCallbackInfo & args)6300 void JSWeb::OnInterceptKeyboardAttach(const JSCallbackInfo& args)
6301 {
6302 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard OnInterceptKeyboardAttach register enter");
6303 if (args.Length() < 1 || !args[0]->IsFunction()) {
6304 return;
6305 }
6306 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<InterceptKeyboardEvent, 1>>(
6307 JSRef<JSFunc>::Cast(args[0]), InterceptKeyboardEventToJSValue);
6308
6309 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6310 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
6311 const BaseEventInfo* info) -> WebKeyboardOption {
6312 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard OnInterceptKeyboardAttach invoke enter");
6313 WebKeyboardOption opt;
6314 auto webNode = node.Upgrade();
6315 CHECK_NULL_RETURN(webNode, opt);
6316 ContainerScope scope(webNode->GetInstanceId());
6317 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, opt);
6318 auto pipelineContext = PipelineContext::GetCurrentContext();
6319 if (pipelineContext) {
6320 pipelineContext->UpdateCurrentActiveNode(node);
6321 }
6322 auto* eventInfo = TypeInfoHelper::DynamicCast<InterceptKeyboardEvent>(info);
6323 JSRef<JSVal> keyboardOpt = func->ExecuteWithValue(*eventInfo);
6324 ParseJsCustomKeyboardOption(execCtx, keyboardOpt, opt);
6325 return opt;
6326 };
6327 WebModel::GetInstance()->SetOnInterceptKeyboardAttach(std::move(uiCallback));
6328 }
6329
OnAdsBlocked(const JSCallbackInfo & args)6330 void JSWeb::OnAdsBlocked(const JSCallbackInfo& args)
6331 {
6332 if (args.Length() < 1 || !args[0]->IsFunction()) {
6333 return;
6334 }
6335
6336 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6337 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<AdsBlockedEvent, 1>>(
6338 JSRef<JSFunc>::Cast(args[0]), AdsBlockedEventToJSValue);
6339 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
6340 const BaseEventInfo* info) {
6341 auto webNode = node.Upgrade();
6342 CHECK_NULL_VOID(webNode);
6343 ContainerScope scope(webNode->GetInstanceId());
6344 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
6345 auto pipelineContext = PipelineContext::GetCurrentContext();
6346 if (pipelineContext) {
6347 pipelineContext->UpdateCurrentActiveNode(node);
6348 }
6349 auto* eventInfo = TypeInfoHelper::DynamicCast<AdsBlockedEvent>(info);
6350 func->Execute(*eventInfo);
6351 };
6352 WebModel::GetInstance()->SetAdsBlockedEventId(jsCallback);
6353 }
6354
ForceDisplayScrollBar(const JSCallbackInfo & args)6355 void JSWeb::ForceDisplayScrollBar(const JSCallbackInfo& args)
6356 {
6357 if (args.Length() < 1 || !args[0]->IsBoolean()) {
6358 return;
6359 }
6360 bool isEnabled = args[0]->ToBoolean();
6361 WebModel::GetInstance()->SetOverlayScrollbarEnabled(isEnabled);
6362 }
6363
KeyboardAvoidMode(int32_t mode)6364 void JSWeb::KeyboardAvoidMode(int32_t mode)
6365 {
6366 if (mode < static_cast<int32_t>(WebKeyboardAvoidMode::RESIZE_VISUAL) ||
6367 mode > static_cast<int32_t>(WebKeyboardAvoidMode::DEFAULT)) {
6368 TAG_LOGE(AceLogTag::ACE_WEB, "KeyboardAvoidMode param err");
6369 return;
6370 }
6371 WebKeyboardAvoidMode avoidMode = static_cast<WebKeyboardAvoidMode>(mode);
6372 WebModel::GetInstance()->SetKeyboardAvoidMode(avoidMode);
6373 }
6374
EditMenuOptions(const JSCallbackInfo & info)6375 void JSWeb::EditMenuOptions(const JSCallbackInfo& info)
6376 {
6377 NG::OnCreateMenuCallback onCreateMenuCallback;
6378 NG::OnMenuItemClickCallback onMenuItemClick;
6379 NG::OnPrepareMenuCallback onPrepareMenuCallback;
6380 JSViewAbstract::ParseEditMenuOptions(info, onCreateMenuCallback, onMenuItemClick, onPrepareMenuCallback);
6381 WebModel::GetInstance()->SetEditMenuOptions(
6382 std::move(onCreateMenuCallback), std::move(onMenuItemClick), std::move(onPrepareMenuCallback));
6383 }
6384
EnableHapticFeedback(const JSCallbackInfo & args)6385 void JSWeb::EnableHapticFeedback(const JSCallbackInfo& args)
6386 {
6387 if (args.Length() < 1 || !args[0]->IsBoolean()) {
6388 return;
6389 }
6390 bool isEnabled = args[0]->ToBoolean();
6391 WebModel::GetInstance()->SetEnabledHapticFeedback(isEnabled);
6392 }
6393
OptimizeParserBudgetEnabled(bool enable)6394 void JSWeb::OptimizeParserBudgetEnabled(bool enable)
6395 {
6396 WebModel::GetInstance()->SetOptimizeParserBudgetEnabled(enable);
6397 }
6398
EnableWebAVSession(const JSCallbackInfo & args)6399 void JSWeb::EnableWebAVSession(const JSCallbackInfo& args)
6400 {
6401 if (args.Length() < 1 || !args[0]->IsBoolean()) {
6402 return;
6403 }
6404 bool isEnabled = args[0]->ToBoolean();
6405 WebModel::GetInstance()->SetWebMediaAVSessionEnabled(isEnabled);
6406 }
6407
EnableDataDetector(const JSCallbackInfo & args)6408 void JSWeb::EnableDataDetector(const JSCallbackInfo& args)
6409 {
6410 RETURN_IF_CALLING_FROM_M114();
6411 if (args.Length() < 1 || !args[0]->IsBoolean()) {
6412 return;
6413 }
6414 bool isEnabled = args[0]->ToBoolean();
6415 WebModel::GetInstance()->SetEnableDataDetector(isEnabled);
6416 }
6417
DataDetectorConfig(const JSCallbackInfo & args)6418 void JSWeb::DataDetectorConfig(const JSCallbackInfo& args)
6419 {
6420 RETURN_IF_CALLING_FROM_M114();
6421 if (args.Length() < 1) {
6422 return;
6423 }
6424 JSRef<JSVal> obj = args[0];
6425 if (!obj->IsObject()) {
6426 return;
6427 }
6428
6429 TextDetectConfig textDetectConfig;
6430 if (!JSViewAbstract::ParseDataDetectorConfig(args, textDetectConfig)) {
6431 return;
6432 }
6433 WebModel::GetInstance()->SetDataDetectorConfig(textDetectConfig);
6434 }
6435
BypassVsyncCondition(int32_t webBypassVsyncCondition)6436 void JSWeb::BypassVsyncCondition(int32_t webBypassVsyncCondition)
6437 {
6438 RETURN_IF_CALLING_FROM_M114();
6439 auto condition = WebBypassVsyncCondition::NONE;
6440 switch (webBypassVsyncCondition) {
6441 case 0:
6442 condition = WebBypassVsyncCondition::NONE;
6443 break;
6444 case 1:
6445 condition = WebBypassVsyncCondition::SCROLLBY_FROM_ZERO_OFFSET;
6446 break;
6447 default:
6448 condition = WebBypassVsyncCondition::NONE;
6449 break;
6450 }
6451 WebModel::GetInstance()->SetBypassVsyncCondition(condition);
6452 }
6453
EnableFollowSystemFontWeight(bool enableFollowSystemFontWeight)6454 void JSWeb::EnableFollowSystemFontWeight(bool enableFollowSystemFontWeight)
6455 {
6456 WebModel::GetInstance()->SetEnableFollowSystemFontWeight(enableFollowSystemFontWeight);
6457 }
6458
OnLoadStarted(const JSCallbackInfo & args)6459 void JSWeb::OnLoadStarted(const JSCallbackInfo& args)
6460 {
6461 if (!args[0]->IsFunction()) {
6462 return;
6463 }
6464 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadStartedEvent, 1>>(
6465 JSRef<JSFunc>::Cast(args[0]), LoadEventToJSValue);
6466
6467 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6468 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
6469 const BaseEventInfo* info) {
6470 auto webNode = node.Upgrade();
6471 CHECK_NULL_VOID(webNode);
6472 ContainerScope scope(webNode->GetInstanceId());
6473 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
6474 auto pipelineContext = PipelineContext::GetCurrentContext();
6475 if (pipelineContext) {
6476 pipelineContext->UpdateCurrentActiveNode(node);
6477 }
6478 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadStartedEvent>(info);
6479 func->Execute(*eventInfo);
6480 };
6481 WebModel::GetInstance()->SetOnLoadStarted(jsCallback);
6482 }
6483
OnLoadFinished(const JSCallbackInfo & args)6484 void JSWeb::OnLoadFinished(const JSCallbackInfo& args)
6485 {
6486 if (!args[0]->IsFunction()) {
6487 return;
6488 }
6489 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadFinishedEvent, 1>>(
6490 JSRef<JSFunc>::Cast(args[0]), LoadEventToJSValue);
6491
6492 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6493 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
6494 const BaseEventInfo* info) {
6495 auto webNode = node.Upgrade();
6496 CHECK_NULL_VOID(webNode);
6497 ContainerScope scope(webNode->GetInstanceId());
6498 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
6499 auto pipelineContext = PipelineContext::GetCurrentContext();
6500 if (pipelineContext) {
6501 pipelineContext->UpdateCurrentActiveNode(node);
6502 }
6503 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadFinishedEvent>(info);
6504 func->Execute(*eventInfo);
6505 };
6506 WebModel::GetInstance()->SetOnLoadFinished(jsCallback);
6507 }
6508
GestureFocusMode(int32_t gestureFocusMode)6509 void JSWeb::GestureFocusMode(int32_t gestureFocusMode)
6510 {
6511 RETURN_IF_CALLING_FROM_M114();
6512 if (gestureFocusMode < static_cast<int32_t>(GestureFocusMode::DEFAULT) ||
6513 gestureFocusMode > static_cast<int32_t>(GestureFocusMode::GESTURE_TAP_AND_LONG_PRESS)) {
6514 TAG_LOGE(AceLogTag::ACE_WEB, "GestureFocusMode param err");
6515 return;
6516 }
6517 auto mode = static_cast<enum GestureFocusMode>(gestureFocusMode);
6518 WebModel::GetInstance()->SetGestureFocusMode(mode);
6519 }
6520
OnPdfScrollAtBottom(const JSCallbackInfo & args)6521 void JSWeb::OnPdfScrollAtBottom(const JSCallbackInfo& args)
6522 {
6523 RETURN_IF_CALLING_FROM_M114();
6524 TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::OnPdfScrollAtBottom, callback set");
6525 if (args.Length() < 1 || !args[0]->IsFunction()) {
6526 return;
6527 }
6528 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<PdfScrollEvent, 1>>(
6529 JSRef<JSFunc>::Cast(args[0]), PdfScrollEventToJSValue);
6530
6531 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6532 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
6533 const BaseEventInfo* info) {
6534 auto webNode = node.Upgrade();
6535 CHECK_NULL_VOID(webNode);
6536 ContainerScope scope(webNode->GetInstanceId());
6537 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
6538 CHECK_NULL_VOID(func);
6539 auto pipelineContext = PipelineContext::GetCurrentContext();
6540 if (pipelineContext) {
6541 pipelineContext->UpdateCurrentActiveNode(node);
6542 }
6543 auto* eventInfo = TypeInfoHelper::DynamicCast<PdfScrollEvent>(info);
6544 CHECK_NULL_VOID(eventInfo);
6545 func->Execute(*eventInfo);
6546 };
6547 WebModel::GetInstance()->SetOnPdfScrollAtBottom(jsCallback);
6548 }
6549
OnPdfLoadEvent(const JSCallbackInfo & args)6550 void JSWeb::OnPdfLoadEvent(const JSCallbackInfo& args)
6551 {
6552 RETURN_IF_CALLING_FROM_M114();
6553 TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::OnPdfLoadEvent, callback set");
6554 if (args.Length() < 1 || !args[0]->IsFunction()) {
6555 return;
6556 }
6557 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<PdfLoadEvent, 1>>(
6558 JSRef<JSFunc>::Cast(args[0]), PdfLoadEventToJSValue);
6559
6560 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
6561 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
6562 const BaseEventInfo* info) {
6563 auto webNode = node.Upgrade();
6564 CHECK_NULL_VOID(webNode);
6565 ContainerScope scope(webNode->GetInstanceId());
6566 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
6567 CHECK_NULL_VOID(func);
6568 auto pipelineContext = PipelineContext::GetCurrentContext();
6569 if (pipelineContext) {
6570 pipelineContext->UpdateCurrentActiveNode(node);
6571 }
6572 auto* eventInfo = TypeInfoHelper::DynamicCast<PdfLoadEvent>(info);
6573 CHECK_NULL_VOID(eventInfo);
6574 func->Execute(*eventInfo);
6575 };
6576 WebModel::GetInstance()->SetOnPdfLoadEvent(jsCallback);
6577 }
6578
6579 ARKWEB_CREATE_JS_OBJECT(WebScreenCaptureRequest, JSScreenCaptureRequest, SetEvent, value)
6580 ARKWEB_CREATE_JS_OBJECT(WebGeolocation, JSWebGeolocation, SetEvent, LoadWebGeolocationShowEvent("", value))
6581 ARKWEB_CREATE_JS_OBJECT(Result, JSWebDialog, SetResult, value)
6582 ARKWEB_CREATE_JS_OBJECT(GestureEventResult, JSNativeEmbedGestureRequest, SetResult, value)
6583 ARKWEB_CREATE_JS_OBJECT(FileSelectorResult, JSFileSelectorResult, SetResult, FileSelectorEvent(nullptr, value))
6584 ARKWEB_CREATE_JS_OBJECT(WebFileSelectorParam, JSFileSelectorParam, SetParam, FileSelectorEvent(value, nullptr))
6585 ARKWEB_CREATE_JS_OBJECT(ContextMenuResult, JSContextMenuResult, SetResult, ContextMenuEvent(nullptr, value))
6586 ARKWEB_CREATE_JS_OBJECT(WebContextMenuParam, JSContextMenuParam, SetParam, ContextMenuEvent(value, nullptr))
6587 ARKWEB_CREATE_JS_OBJECT(WebConsoleLog, JSWebConsoleLog, SetMessage, value)
6588 ARKWEB_CREATE_JS_OBJECT(AuthResult, JSWebHttpAuth, SetResult, value)
6589 ARKWEB_CREATE_JS_OBJECT(SslErrorResult, JSWebSslError, SetResult, value)
6590 ARKWEB_CREATE_JS_OBJECT(SslSelectCertResult, JSWebSslSelectCert, SetResult, value)
6591 ARKWEB_CREATE_JS_OBJECT(WebResponse, JSWebResourceResponse, SetEvent, ReceivedHttpErrorEvent(nullptr, value))
6592 ARKWEB_CREATE_JS_OBJECT(WebRequest, JSWebResourceRequest, SetHttpErrorEvent, ReceivedHttpErrorEvent(value, nullptr))
6593 ARKWEB_CREATE_JS_OBJECT(DataResubmitted, JSDataResubmitted, SetHandler, value)
6594 ARKWEB_CREATE_JS_OBJECT(WebPermissionRequest, JSWebPermissionRequest, SetEvent, WebPermissionRequestEvent(value))
6595 ARKWEB_CREATE_JS_OBJECT(WebCustomKeyboardHandler, JSWebKeyboardController, SeWebKeyboardController, value)
6596 ARKWEB_CREATE_JS_OBJECT(
6597 WebWindowNewHandler, JSWebWindowNewHandler, SetEvent, WebWindowNewEvent(std::string(), false, false, value))
6598 } // namespace OHOS::Ace::Framework
6599