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 "pixel_map.h"
22 #include "pixel_map_napi.h"
23
24 #include "base/log/ace_scoring_log.h"
25 #include "base/memory/ace_type.h"
26 #include "base/memory/referenced.h"
27 #include "base/utils/utils.h"
28 #if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
29 #include "base/web/webview/ohos_nweb/include/nweb.h"
30 #else
31 #include "base/web/webview/ohos_interface/include/ohos_nweb/nweb.h"
32 #endif
33 #include "bridge/common/utils/engine_helper.h"
34 #include "bridge/declarative_frontend/engine/functions/js_click_function.h"
35 #include "bridge/declarative_frontend/engine/functions/js_drag_function.h"
36 #include "bridge/declarative_frontend/engine/functions/js_key_function.h"
37 #include "bridge/declarative_frontend/engine/js_converter.h"
38 #include "bridge/declarative_frontend/engine/js_ref_ptr.h"
39 #include "bridge/declarative_frontend/jsview/js_utils.h"
40 #include "bridge/declarative_frontend/jsview/js_web_controller.h"
41 #include "bridge/declarative_frontend/jsview/models/web_model_impl.h"
42 #include "bridge/declarative_frontend/view_stack_processor.h"
43 #include "core/common/ace_application_info.h"
44 #include "core/common/container.h"
45 #include "core/common/container_scope.h"
46 #include "core/components/web/web_event.h"
47 #include "core/components_ng/base/frame_node.h"
48 #include "core/components_ng/pattern/web/web_model_ng.h"
49 #include "core/pipeline/pipeline_base.h"
50
51 namespace OHOS::Ace {
52 namespace {
53 const std::string RAWFILE_PREFIX = "resource://RAWFILE/";
54 const std::string BUNDLE_NAME_PREFIX = "bundleName:";
55 const std::string MODULE_NAME_PREFIX = "moduleName:";
56
57 const int32_t SELECTION_MENU_OPTION_PARAM_INDEX = 3;
58 const int32_t SELECTION_MENU_CONTENT_PARAM_INDEX = 2;
59
EraseSpace(std::string & data)60 void EraseSpace(std::string& data)
61 {
62 auto iter = data.begin();
63 while (iter != data.end()) {
64 if (isspace(*iter)) {
65 iter = data.erase(iter);
66 } else {
67 ++iter;
68 }
69 }
70 }
71 }
72
73 std::unique_ptr<WebModel> WebModel::instance_ = nullptr;
74 std::mutex WebModel::mutex_;
GetInstance()75 WebModel* WebModel::GetInstance()
76 {
77 if (!instance_) {
78 std::lock_guard<std::mutex> lock(mutex_);
79 if (!instance_) {
80 #ifdef NG_BUILD
81 instance_.reset(new NG::WebModelNG());
82 #else
83 if (Container::IsCurrentUseNewPipeline()) {
84 instance_.reset(new NG::WebModelNG());
85 } else {
86 instance_.reset(new Framework::WebModelImpl());
87 }
88 #endif
89 }
90 }
91 return instance_.get();
92 }
93
94 } // namespace OHOS::Ace
95
96 namespace OHOS::Ace::Framework {
97 bool JSWeb::webDebuggingAccess_ = false;
98 class JSWebDialog : public Referenced {
99 public:
JSBind(BindingTarget globalObj)100 static void JSBind(BindingTarget globalObj)
101 {
102 JSClass<JSWebDialog>::Declare("WebDialog");
103 JSClass<JSWebDialog>::CustomMethod("handleConfirm", &JSWebDialog::Confirm);
104 JSClass<JSWebDialog>::CustomMethod("handleCancel", &JSWebDialog::Cancel);
105 JSClass<JSWebDialog>::CustomMethod("handlePromptConfirm", &JSWebDialog::PromptConfirm);
106 JSClass<JSWebDialog>::Bind(globalObj, &JSWebDialog::Constructor, &JSWebDialog::Destructor);
107 }
108
SetResult(const RefPtr<Result> & result)109 void SetResult(const RefPtr<Result>& result)
110 {
111 result_ = result;
112 }
113
Confirm(const JSCallbackInfo & args)114 void Confirm(const JSCallbackInfo& args)
115 {
116 if (result_) {
117 result_->Confirm();
118 }
119 }
120
PromptConfirm(const JSCallbackInfo & args)121 void PromptConfirm(const JSCallbackInfo& args)
122 {
123 std::string message;
124 if (!result_) {
125 return;
126 }
127 if (args.Length() == 1 && args[0]->IsString()) {
128 message = args[0]->ToString();
129 result_->Confirm(message);
130 }
131 }
132
Cancel(const JSCallbackInfo & args)133 void Cancel(const JSCallbackInfo& args)
134 {
135 if (result_) {
136 result_->Cancel();
137 }
138 }
139
140 private:
Constructor(const JSCallbackInfo & args)141 static void Constructor(const JSCallbackInfo& args)
142 {
143 auto jsWebDialog = Referenced::MakeRefPtr<JSWebDialog>();
144 jsWebDialog->IncRefCount();
145 args.SetReturnValue(Referenced::RawPtr(jsWebDialog));
146 }
147
Destructor(JSWebDialog * jsWebDialog)148 static void Destructor(JSWebDialog* jsWebDialog)
149 {
150 if (jsWebDialog != nullptr) {
151 jsWebDialog->DecRefCount();
152 }
153 }
154
155 RefPtr<Result> result_;
156 };
157
158 class JSFullScreenExitHandler : public Referenced {
159 public:
JSBind(BindingTarget globalObj)160 static void JSBind(BindingTarget globalObj)
161 {
162 JSClass<JSFullScreenExitHandler>::Declare("FullScreenExitHandler");
163 JSClass<JSFullScreenExitHandler>::CustomMethod("exitFullScreen", &JSFullScreenExitHandler::ExitFullScreen);
164 JSClass<JSFullScreenExitHandler>::Bind(
165 globalObj, &JSFullScreenExitHandler::Constructor, &JSFullScreenExitHandler::Destructor);
166 }
167
SetHandler(const RefPtr<FullScreenExitHandler> & handler)168 void SetHandler(const RefPtr<FullScreenExitHandler>& handler)
169 {
170 fullScreenExitHandler_ = handler;
171 }
172
ExitFullScreen(const JSCallbackInfo & args)173 void ExitFullScreen(const JSCallbackInfo& args)
174 {
175 if (fullScreenExitHandler_) {
176 fullScreenExitHandler_->ExitFullScreen();
177 }
178 }
179
180 private:
Constructor(const JSCallbackInfo & args)181 static void Constructor(const JSCallbackInfo& args)
182 {
183 auto jsFullScreenExitHandler = Referenced::MakeRefPtr<JSFullScreenExitHandler>();
184 jsFullScreenExitHandler->IncRefCount();
185 args.SetReturnValue(Referenced::RawPtr(jsFullScreenExitHandler));
186 }
187
Destructor(JSFullScreenExitHandler * jsFullScreenExitHandler)188 static void Destructor(JSFullScreenExitHandler* jsFullScreenExitHandler)
189 {
190 if (jsFullScreenExitHandler != nullptr) {
191 jsFullScreenExitHandler->DecRefCount();
192 }
193 }
194 RefPtr<FullScreenExitHandler> fullScreenExitHandler_;
195 };
196
197 class JSWebKeyboardController : public Referenced {
198 public:
JSBind(BindingTarget globalObj)199 static void JSBind(BindingTarget globalObj)
200 {
201 JSClass<JSWebKeyboardController>::Declare("WebKeyboardController");
202 JSClass<JSWebKeyboardController>::CustomMethod("insertText", &JSWebKeyboardController::InsertText);
203 JSClass<JSWebKeyboardController>::CustomMethod("deleteForward", &JSWebKeyboardController::DeleteForward);
204 JSClass<JSWebKeyboardController>::CustomMethod("deleteBackward", &JSWebKeyboardController::DeleteBackward);
205 JSClass<JSWebKeyboardController>::CustomMethod("sendFunctionKey", &JSWebKeyboardController::SendFunctionKey);
206 JSClass<JSWebKeyboardController>::CustomMethod("close", &JSWebKeyboardController::Close);
207 JSClass<JSWebKeyboardController>::Bind(
208 globalObj, &JSWebKeyboardController::Constructor, &JSWebKeyboardController::Destructor);
209 }
210
SeWebKeyboardController(const RefPtr<WebCustomKeyboardHandler> & controller)211 void SeWebKeyboardController(const RefPtr<WebCustomKeyboardHandler>& controller)
212 {
213 webKeyboardController_ = controller;
214 }
215
InsertText(const JSCallbackInfo & args)216 void InsertText(const JSCallbackInfo& args)
217 {
218 if (!webKeyboardController_) {
219 return;
220 }
221
222 if (args.Length() < 1 || !(args[0]->IsString())) {
223 return;
224 }
225
226 webKeyboardController_->InsertText(args[0]->ToString());
227 }
228
DeleteForward(const JSCallbackInfo & args)229 void DeleteForward(const JSCallbackInfo& args)
230 {
231 if (!webKeyboardController_) {
232 return;
233 }
234
235 if (args.Length() < 1 || !(args[0]->IsNumber())) {
236 return;
237 }
238
239 webKeyboardController_->DeleteForward(args[0]->ToNumber<int32_t>());
240 }
241
DeleteBackward(const JSCallbackInfo & args)242 void DeleteBackward(const JSCallbackInfo& args)
243 {
244 if (!webKeyboardController_) {
245 return;
246 }
247
248 if (args.Length() < 1 || !(args[0]->IsNumber())) {
249 return;
250 }
251
252 webKeyboardController_->DeleteBackward(args[0]->ToNumber<int32_t>());
253 }
254
SendFunctionKey(const JSCallbackInfo & args)255 void SendFunctionKey(const JSCallbackInfo& args)
256 {
257 if (!webKeyboardController_) {
258 return;
259 }
260
261 if (args.Length() < 1 || !(args[0]->IsNumber())) {
262 return;
263 }
264
265 webKeyboardController_->SendFunctionKey(args[0]->ToNumber<int32_t>());
266 }
267
Close(const JSCallbackInfo & args)268 void Close(const JSCallbackInfo& args)
269 {
270 webKeyboardController_->Close();
271 }
272
273 private:
Constructor(const JSCallbackInfo & args)274 static void Constructor(const JSCallbackInfo& args)
275 {
276 auto jSWebKeyboardController = Referenced::MakeRefPtr<JSWebKeyboardController>();
277 jSWebKeyboardController->IncRefCount();
278 args.SetReturnValue(Referenced::RawPtr(jSWebKeyboardController));
279 }
280
Destructor(JSWebKeyboardController * jSWebKeyboardController)281 static void Destructor(JSWebKeyboardController* jSWebKeyboardController)
282 {
283 if (jSWebKeyboardController != nullptr) {
284 jSWebKeyboardController->DecRefCount();
285 }
286 }
287 RefPtr<WebCustomKeyboardHandler> webKeyboardController_;
288 };
289
290 class JSWebHttpAuth : public Referenced {
291 public:
JSBind(BindingTarget globalObj)292 static void JSBind(BindingTarget globalObj)
293 {
294 JSClass<JSWebHttpAuth>::Declare("WebHttpAuthResult");
295 JSClass<JSWebHttpAuth>::CustomMethod("confirm", &JSWebHttpAuth::Confirm);
296 JSClass<JSWebHttpAuth>::CustomMethod("cancel", &JSWebHttpAuth::Cancel);
297 JSClass<JSWebHttpAuth>::CustomMethod("isHttpAuthInfoSaved", &JSWebHttpAuth::IsHttpAuthInfoSaved);
298 JSClass<JSWebHttpAuth>::Bind(globalObj, &JSWebHttpAuth::Constructor, &JSWebHttpAuth::Destructor);
299 }
300
SetResult(const RefPtr<AuthResult> & result)301 void SetResult(const RefPtr<AuthResult>& result)
302 {
303 result_ = result;
304 }
305
Confirm(const JSCallbackInfo & args)306 void Confirm(const JSCallbackInfo& args)
307 {
308 if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) {
309 auto code = JSVal(ToJSValue(false));
310 auto descriptionRef = JSRef<JSVal>::Make(code);
311 args.SetReturnValue(descriptionRef);
312 return;
313 }
314 std::string userName = args[0]->ToString();
315 std::string password = args[1]->ToString();
316 bool ret = false;
317 if (result_) {
318 result_->Confirm(userName, password);
319 ret = true;
320 }
321 auto code = JSVal(ToJSValue(ret));
322 auto descriptionRef = JSRef<JSVal>::Make(code);
323 args.SetReturnValue(descriptionRef);
324 }
325
Cancel(const JSCallbackInfo & args)326 void Cancel(const JSCallbackInfo& args)
327 {
328 if (result_) {
329 result_->Cancel();
330 }
331 }
332
IsHttpAuthInfoSaved(const JSCallbackInfo & args)333 void IsHttpAuthInfoSaved(const JSCallbackInfo& args)
334 {
335 bool ret = false;
336 if (result_) {
337 ret = result_->IsHttpAuthInfoSaved();
338 }
339 auto code = JSVal(ToJSValue(ret));
340 auto descriptionRef = JSRef<JSVal>::Make(code);
341 args.SetReturnValue(descriptionRef);
342 }
343
344 private:
Constructor(const JSCallbackInfo & args)345 static void Constructor(const JSCallbackInfo& args)
346 {
347 auto jsWebHttpAuth = Referenced::MakeRefPtr<JSWebHttpAuth>();
348 jsWebHttpAuth->IncRefCount();
349 args.SetReturnValue(Referenced::RawPtr(jsWebHttpAuth));
350 }
351
Destructor(JSWebHttpAuth * jsWebHttpAuth)352 static void Destructor(JSWebHttpAuth* jsWebHttpAuth)
353 {
354 if (jsWebHttpAuth != nullptr) {
355 jsWebHttpAuth->DecRefCount();
356 }
357 }
358
359 RefPtr<AuthResult> result_;
360 };
361
362 class JSWebSslError : public Referenced {
363 public:
JSBind(BindingTarget globalObj)364 static void JSBind(BindingTarget globalObj)
365 {
366 JSClass<JSWebSslError>::Declare("WebSslErrorResult");
367 JSClass<JSWebSslError>::CustomMethod("handleConfirm", &JSWebSslError::HandleConfirm);
368 JSClass<JSWebSslError>::CustomMethod("handleCancel", &JSWebSslError::HandleCancel);
369 JSClass<JSWebSslError>::Bind(globalObj, &JSWebSslError::Constructor, &JSWebSslError::Destructor);
370 }
371
SetResult(const RefPtr<SslErrorResult> & result)372 void SetResult(const RefPtr<SslErrorResult>& result)
373 {
374 result_ = result;
375 }
376
HandleConfirm(const JSCallbackInfo & args)377 void HandleConfirm(const JSCallbackInfo& args)
378 {
379 if (result_) {
380 result_->HandleConfirm();
381 }
382 }
383
HandleCancel(const JSCallbackInfo & args)384 void HandleCancel(const JSCallbackInfo& args)
385 {
386 if (result_) {
387 result_->HandleCancel();
388 }
389 }
390
391 private:
Constructor(const JSCallbackInfo & args)392 static void Constructor(const JSCallbackInfo& args)
393 {
394 auto jsWebSslError = Referenced::MakeRefPtr<JSWebSslError>();
395 jsWebSslError->IncRefCount();
396 args.SetReturnValue(Referenced::RawPtr(jsWebSslError));
397 }
398
Destructor(JSWebSslError * jsWebSslError)399 static void Destructor(JSWebSslError* jsWebSslError)
400 {
401 if (jsWebSslError != nullptr) {
402 jsWebSslError->DecRefCount();
403 }
404 }
405
406 RefPtr<SslErrorResult> result_;
407 };
408
409 class JSWebAllSslError : public Referenced {
410 public:
JSBind(BindingTarget globalObj)411 static void JSBind(BindingTarget globalObj)
412 {
413 JSClass<JSWebAllSslError>::Declare("WebAllSslErrorResult");
414 JSClass<JSWebAllSslError>::CustomMethod("handleConfirm", &JSWebAllSslError::HandleConfirm);
415 JSClass<JSWebAllSslError>::CustomMethod("handleCancel", &JSWebAllSslError::HandleCancel);
416 JSClass<JSWebAllSslError>::Bind(globalObj, &JSWebAllSslError::Constructor, &JSWebAllSslError::Destructor);
417 }
418
SetResult(const RefPtr<AllSslErrorResult> & result)419 void SetResult(const RefPtr<AllSslErrorResult>& result)
420 {
421 result_ = result;
422 }
423
HandleConfirm(const JSCallbackInfo & args)424 void HandleConfirm(const JSCallbackInfo& args)
425 {
426 if (result_) {
427 result_->HandleConfirm();
428 }
429 }
430
HandleCancel(const JSCallbackInfo & args)431 void HandleCancel(const JSCallbackInfo& args)
432 {
433 if (result_) {
434 result_->HandleCancel();
435 }
436 }
437
438 private:
Constructor(const JSCallbackInfo & args)439 static void Constructor(const JSCallbackInfo& args)
440 {
441 auto jsWebAllSslError = Referenced::MakeRefPtr<JSWebAllSslError>();
442 jsWebAllSslError->IncRefCount();
443 args.SetReturnValue(Referenced::RawPtr(jsWebAllSslError));
444 }
445
Destructor(JSWebAllSslError * jsWebAllSslError)446 static void Destructor(JSWebAllSslError* jsWebAllSslError)
447 {
448 if (jsWebAllSslError != nullptr) {
449 jsWebAllSslError->DecRefCount();
450 }
451 }
452
453 RefPtr<AllSslErrorResult> result_;
454 };
455
456 class JSWebSslSelectCert : public Referenced {
457 public:
JSBind(BindingTarget globalObj)458 static void JSBind(BindingTarget globalObj)
459 {
460 JSClass<JSWebSslSelectCert>::Declare("WebSslSelectCertResult");
461 JSClass<JSWebSslSelectCert>::CustomMethod("confirm", &JSWebSslSelectCert::HandleConfirm);
462 JSClass<JSWebSslSelectCert>::CustomMethod("cancel", &JSWebSslSelectCert::HandleCancel);
463 JSClass<JSWebSslSelectCert>::CustomMethod("ignore", &JSWebSslSelectCert::HandleIgnore);
464 JSClass<JSWebSslSelectCert>::Bind(globalObj, &JSWebSslSelectCert::Constructor, &JSWebSslSelectCert::Destructor);
465 }
466
SetResult(const RefPtr<SslSelectCertResult> & result)467 void SetResult(const RefPtr<SslSelectCertResult>& result)
468 {
469 result_ = result;
470 }
471
HandleConfirm(const JSCallbackInfo & args)472 void HandleConfirm(const JSCallbackInfo& args)
473 {
474 std::string privateKeyFile;
475 std::string certChainFile;
476 if (args.Length() == 1 && args[0]->IsString()) {
477 privateKeyFile = args[0]->ToString();
478 } else if (args.Length() == 2 && args[0]->IsString() && args[1]->IsString()) {
479 privateKeyFile = args[0]->ToString();
480 certChainFile = args[1]->ToString();
481 } else {
482 return;
483 }
484
485 if (result_) {
486 result_->HandleConfirm(privateKeyFile, certChainFile);
487 }
488 }
489
HandleCancel(const JSCallbackInfo & args)490 void HandleCancel(const JSCallbackInfo& args)
491 {
492 if (result_) {
493 result_->HandleCancel();
494 }
495 }
496
HandleIgnore(const JSCallbackInfo & args)497 void HandleIgnore(const JSCallbackInfo& args)
498 {
499 if (result_) {
500 result_->HandleIgnore();
501 }
502 }
503
504 private:
Constructor(const JSCallbackInfo & args)505 static void Constructor(const JSCallbackInfo& args)
506 {
507 auto jsWebSslSelectCert = Referenced::MakeRefPtr<JSWebSslSelectCert>();
508 jsWebSslSelectCert->IncRefCount();
509 args.SetReturnValue(Referenced::RawPtr(jsWebSslSelectCert));
510 }
511
Destructor(JSWebSslSelectCert * jsWebSslSelectCert)512 static void Destructor(JSWebSslSelectCert* jsWebSslSelectCert)
513 {
514 if (jsWebSslSelectCert != nullptr) {
515 jsWebSslSelectCert->DecRefCount();
516 }
517 }
518
519 RefPtr<SslSelectCertResult> result_;
520 };
521
522 class JSWebConsoleLog : public Referenced {
523 public:
JSBind(BindingTarget globalObj)524 static void JSBind(BindingTarget globalObj)
525 {
526 JSClass<JSWebConsoleLog>::Declare("ConsoleMessage");
527 JSClass<JSWebConsoleLog>::CustomMethod("getLineNumber", &JSWebConsoleLog::GetLineNumber);
528 JSClass<JSWebConsoleLog>::CustomMethod("getMessage", &JSWebConsoleLog::GetLog);
529 JSClass<JSWebConsoleLog>::CustomMethod("getMessageLevel", &JSWebConsoleLog::GetLogLevel);
530 JSClass<JSWebConsoleLog>::CustomMethod("getSourceId", &JSWebConsoleLog::GetSourceId);
531 JSClass<JSWebConsoleLog>::Bind(globalObj, &JSWebConsoleLog::Constructor, &JSWebConsoleLog::Destructor);
532 }
533
SetMessage(const RefPtr<WebConsoleLog> & message)534 void SetMessage(const RefPtr<WebConsoleLog>& message)
535 {
536 message_ = message;
537 }
538
GetLineNumber(const JSCallbackInfo & args)539 void GetLineNumber(const JSCallbackInfo& args)
540 {
541 auto code = JSVal(ToJSValue(message_->GetLineNumber()));
542 auto descriptionRef = JSRef<JSVal>::Make(code);
543 args.SetReturnValue(descriptionRef);
544 }
545
GetLog(const JSCallbackInfo & args)546 void GetLog(const JSCallbackInfo& args)
547 {
548 auto code = JSVal(ToJSValue(message_->GetLog()));
549 auto descriptionRef = JSRef<JSVal>::Make(code);
550 args.SetReturnValue(descriptionRef);
551 }
552
GetLogLevel(const JSCallbackInfo & args)553 void GetLogLevel(const JSCallbackInfo& args)
554 {
555 auto code = JSVal(ToJSValue(message_->GetLogLevel()));
556 auto descriptionRef = JSRef<JSVal>::Make(code);
557 args.SetReturnValue(descriptionRef);
558 }
559
GetSourceId(const JSCallbackInfo & args)560 void GetSourceId(const JSCallbackInfo& args)
561 {
562 auto code = JSVal(ToJSValue(message_->GetSourceId()));
563 auto descriptionRef = JSRef<JSVal>::Make(code);
564 args.SetReturnValue(descriptionRef);
565 }
566
567 private:
Constructor(const JSCallbackInfo & args)568 static void Constructor(const JSCallbackInfo& args)
569 {
570 auto jsWebConsoleLog = Referenced::MakeRefPtr<JSWebConsoleLog>();
571 jsWebConsoleLog->IncRefCount();
572 args.SetReturnValue(Referenced::RawPtr(jsWebConsoleLog));
573 }
574
Destructor(JSWebConsoleLog * jsWebConsoleLog)575 static void Destructor(JSWebConsoleLog* jsWebConsoleLog)
576 {
577 if (jsWebConsoleLog != nullptr) {
578 jsWebConsoleLog->DecRefCount();
579 }
580 }
581
582 RefPtr<WebConsoleLog> message_;
583 };
584
585 class JSWebGeolocation : public Referenced {
586 public:
JSBind(BindingTarget globalObj)587 static void JSBind(BindingTarget globalObj)
588 {
589 JSClass<JSWebGeolocation>::Declare("WebGeolocation");
590 JSClass<JSWebGeolocation>::CustomMethod("invoke", &JSWebGeolocation::Invoke);
591 JSClass<JSWebGeolocation>::Bind(globalObj, &JSWebGeolocation::Constructor, &JSWebGeolocation::Destructor);
592 }
593
SetEvent(const LoadWebGeolocationShowEvent & eventInfo)594 void SetEvent(const LoadWebGeolocationShowEvent& eventInfo)
595 {
596 webGeolocation_ = eventInfo.GetWebGeolocation();
597 }
598
Invoke(const JSCallbackInfo & args)599 void Invoke(const JSCallbackInfo& args)
600 {
601 std::string origin;
602 bool allow = false;
603 bool retain = false;
604 if (args[0]->IsString()) {
605 origin = args[0]->ToString();
606 }
607 if (args[1]->IsBoolean()) {
608 allow = args[1]->ToBoolean();
609 }
610 if (args[2]->IsBoolean()) {
611 retain = args[2]->ToBoolean();
612 }
613 if (webGeolocation_) {
614 webGeolocation_->Invoke(origin, allow, retain);
615 }
616 }
617
618 private:
Constructor(const JSCallbackInfo & args)619 static void Constructor(const JSCallbackInfo& args)
620 {
621 auto jsWebGeolocation = Referenced::MakeRefPtr<JSWebGeolocation>();
622 jsWebGeolocation->IncRefCount();
623 args.SetReturnValue(Referenced::RawPtr(jsWebGeolocation));
624 }
625
Destructor(JSWebGeolocation * jsWebGeolocation)626 static void Destructor(JSWebGeolocation* jsWebGeolocation)
627 {
628 if (jsWebGeolocation != nullptr) {
629 jsWebGeolocation->DecRefCount();
630 }
631 }
632
633 RefPtr<WebGeolocation> webGeolocation_;
634 };
635
636 class JSWebPermissionRequest : public Referenced {
637 public:
JSBind(BindingTarget globalObj)638 static void JSBind(BindingTarget globalObj)
639 {
640 JSClass<JSWebPermissionRequest>::Declare("WebPermissionRequest");
641 JSClass<JSWebPermissionRequest>::CustomMethod("deny", &JSWebPermissionRequest::Deny);
642 JSClass<JSWebPermissionRequest>::CustomMethod("getOrigin", &JSWebPermissionRequest::GetOrigin);
643 JSClass<JSWebPermissionRequest>::CustomMethod("getAccessibleResource", &JSWebPermissionRequest::GetResources);
644 JSClass<JSWebPermissionRequest>::CustomMethod("grant", &JSWebPermissionRequest::Grant);
645 JSClass<JSWebPermissionRequest>::Bind(
646 globalObj, &JSWebPermissionRequest::Constructor, &JSWebPermissionRequest::Destructor);
647 }
648
SetEvent(const WebPermissionRequestEvent & eventInfo)649 void SetEvent(const WebPermissionRequestEvent& eventInfo)
650 {
651 webPermissionRequest_ = eventInfo.GetWebPermissionRequest();
652 }
653
Deny(const JSCallbackInfo & args)654 void Deny(const JSCallbackInfo& args)
655 {
656 if (webPermissionRequest_) {
657 webPermissionRequest_->Deny();
658 }
659 }
660
GetOrigin(const JSCallbackInfo & args)661 void GetOrigin(const JSCallbackInfo& args)
662 {
663 std::string origin;
664 if (webPermissionRequest_) {
665 origin = webPermissionRequest_->GetOrigin();
666 }
667 auto originJs = JSVal(ToJSValue(origin));
668 auto originJsRef = JSRef<JSVal>::Make(originJs);
669 args.SetReturnValue(originJsRef);
670 }
671
GetResources(const JSCallbackInfo & args)672 void GetResources(const JSCallbackInfo& args)
673 {
674 JSRef<JSArray> result = JSRef<JSArray>::New();
675 if (webPermissionRequest_) {
676 std::vector<std::string> resources = webPermissionRequest_->GetResources();
677 uint32_t index = 0;
678 for (auto iterator = resources.begin(); iterator != resources.end(); ++iterator) {
679 auto valueStr = JSVal(ToJSValue(*iterator));
680 auto value = JSRef<JSVal>::Make(valueStr);
681 result->SetValueAt(index++, value);
682 }
683 }
684 args.SetReturnValue(result);
685 }
686
Grant(const JSCallbackInfo & args)687 void Grant(const JSCallbackInfo& args)
688 {
689 if (args.Length() < 1) {
690 if (webPermissionRequest_) {
691 webPermissionRequest_->Deny();
692 }
693 }
694 std::vector<std::string> resources;
695 if (args[0]->IsArray()) {
696 JSRef<JSArray> array = JSRef<JSArray>::Cast(args[0]);
697 for (size_t i = 0; i < array->Length(); i++) {
698 JSRef<JSVal> val = array->GetValueAt(i);
699 if (!val->IsString()) {
700 continue;
701 }
702 std::string res;
703 if (!ConvertFromJSValue(val, res)) {
704 continue;
705 }
706 resources.push_back(res);
707 }
708 }
709
710 if (webPermissionRequest_) {
711 webPermissionRequest_->Grant(resources);
712 }
713 }
714
715 private:
Constructor(const JSCallbackInfo & args)716 static void Constructor(const JSCallbackInfo& args)
717 {
718 auto jsWebPermissionRequest = Referenced::MakeRefPtr<JSWebPermissionRequest>();
719 jsWebPermissionRequest->IncRefCount();
720 args.SetReturnValue(Referenced::RawPtr(jsWebPermissionRequest));
721 }
722
Destructor(JSWebPermissionRequest * jsWebPermissionRequest)723 static void Destructor(JSWebPermissionRequest* jsWebPermissionRequest)
724 {
725 if (jsWebPermissionRequest != nullptr) {
726 jsWebPermissionRequest->DecRefCount();
727 }
728 }
729
730 RefPtr<WebPermissionRequest> webPermissionRequest_;
731 };
732
733 class JSScreenCaptureRequest : public Referenced {
734 public:
JSBind(BindingTarget globalObj)735 static void JSBind(BindingTarget globalObj)
736 {
737 JSClass<JSScreenCaptureRequest>::Declare("ScreenCaptureRequest");
738 JSClass<JSScreenCaptureRequest>::CustomMethod("deny", &JSScreenCaptureRequest::Deny);
739 JSClass<JSScreenCaptureRequest>::CustomMethod("getOrigin", &JSScreenCaptureRequest::GetOrigin);
740 JSClass<JSScreenCaptureRequest>::CustomMethod("grant", &JSScreenCaptureRequest::Grant);
741 JSClass<JSScreenCaptureRequest>::Bind(
742 globalObj, &JSScreenCaptureRequest::Constructor, &JSScreenCaptureRequest::Destructor);
743 }
744
SetEvent(const WebScreenCaptureRequestEvent & eventInfo)745 void SetEvent(const WebScreenCaptureRequestEvent& eventInfo)
746 {
747 request_ = eventInfo.GetWebScreenCaptureRequest();
748 }
749
Deny(const JSCallbackInfo & args)750 void Deny(const JSCallbackInfo& args)
751 {
752 if (request_) {
753 request_->Deny();
754 }
755 }
756
GetOrigin(const JSCallbackInfo & args)757 void GetOrigin(const JSCallbackInfo& args)
758 {
759 std::string origin;
760 if (request_) {
761 origin = request_->GetOrigin();
762 }
763 auto originJs = JSVal(ToJSValue(origin));
764 auto originJsRef = JSRef<JSVal>::Make(originJs);
765 args.SetReturnValue(originJsRef);
766 }
767
Grant(const JSCallbackInfo & args)768 void Grant(const JSCallbackInfo& args)
769 {
770 if (!request_) {
771 return;
772 }
773 if (args.Length() < 1 || !args[0]->IsObject()) {
774 request_->Deny();
775 return;
776 }
777 JSRef<JSObject> paramObject = JSRef<JSObject>::Cast(args[0]);
778 auto captureModeObj = paramObject->GetProperty("captureMode");
779 if (!captureModeObj->IsNumber()) {
780 request_->Deny();
781 return;
782 }
783 int32_t captureMode = captureModeObj->ToNumber<int32_t>();
784 request_->SetCaptureMode(captureMode);
785 request_->SetSourceId(-1);
786 request_->Grant();
787 }
788
789 private:
Constructor(const JSCallbackInfo & args)790 static void Constructor(const JSCallbackInfo& args)
791 {
792 auto jsScreenCaptureRequest = Referenced::MakeRefPtr<JSScreenCaptureRequest>();
793 jsScreenCaptureRequest->IncRefCount();
794 args.SetReturnValue(Referenced::RawPtr(jsScreenCaptureRequest));
795 }
796
Destructor(JSScreenCaptureRequest * jsScreenCaptureRequest)797 static void Destructor(JSScreenCaptureRequest* jsScreenCaptureRequest)
798 {
799 if (jsScreenCaptureRequest != nullptr) {
800 jsScreenCaptureRequest->DecRefCount();
801 }
802 }
803
804 RefPtr<WebScreenCaptureRequest> request_;
805 };
806
807 class JSNativeEmbedGestureRequest : public Referenced {
808 public:
JSBind(BindingTarget globalObj)809 static void JSBind(BindingTarget globalObj)
810 {
811 JSClass<JSNativeEmbedGestureRequest>::Declare("NativeEmbedGesture");
812 JSClass<JSNativeEmbedGestureRequest>::CustomMethod(
813 "setGestureEventResult", &JSNativeEmbedGestureRequest::SetGestureEventResult);
814 JSClass<JSNativeEmbedGestureRequest>::Bind(
815 globalObj, &JSNativeEmbedGestureRequest::Constructor, &JSNativeEmbedGestureRequest::Destructor);
816 }
817
SetResult(const RefPtr<GestureEventResult> & result)818 void SetResult(const RefPtr<GestureEventResult>& result)
819 {
820 eventResult_ = result;
821 }
822
SetGestureEventResult(const JSCallbackInfo & args)823 void SetGestureEventResult(const JSCallbackInfo& args)
824 {
825 if (eventResult_) {
826 bool result = true;
827 if (args.Length() == 1 && args[0]->IsBoolean()) {
828 result = args[0]->ToBoolean();
829 eventResult_->SetGestureEventResult(result);
830 }
831 }
832 }
833
834 private:
Constructor(const JSCallbackInfo & args)835 static void Constructor(const JSCallbackInfo& args)
836 {
837 auto jSNativeEmbedGestureRequest = Referenced::MakeRefPtr<JSNativeEmbedGestureRequest>();
838 jSNativeEmbedGestureRequest->IncRefCount();
839 args.SetReturnValue(Referenced::RawPtr(jSNativeEmbedGestureRequest));
840 }
841
Destructor(JSNativeEmbedGestureRequest * jSNativeEmbedGestureRequest)842 static void Destructor(JSNativeEmbedGestureRequest* jSNativeEmbedGestureRequest)
843 {
844 if (jSNativeEmbedGestureRequest != nullptr) {
845 jSNativeEmbedGestureRequest->DecRefCount();
846 }
847 }
848
849 RefPtr<GestureEventResult> eventResult_;
850 };
851
852 class JSWebWindowNewHandler : public Referenced {
853 public:
854 struct ChildWindowInfo {
855 int32_t parentWebId_ = -1;
856 JSRef<JSObject> controller_;
857 };
858
JSBind(BindingTarget globalObj)859 static void JSBind(BindingTarget globalObj)
860 {
861 JSClass<JSWebWindowNewHandler>::Declare("WebWindowNewHandler");
862 JSClass<JSWebWindowNewHandler>::CustomMethod("setWebController", &JSWebWindowNewHandler::SetWebController);
863 JSClass<JSWebWindowNewHandler>::Bind(
864 globalObj, &JSWebWindowNewHandler::Constructor, &JSWebWindowNewHandler::Destructor);
865 }
866
SetEvent(const WebWindowNewEvent & eventInfo)867 void SetEvent(const WebWindowNewEvent& eventInfo)
868 {
869 handler_ = eventInfo.GetWebWindowNewHandler();
870 }
871
PopController(int32_t id,int32_t * parentId=nullptr)872 static JSRef<JSObject> PopController(int32_t id, int32_t* parentId = nullptr)
873 {
874 auto iter = controller_map_.find(id);
875 if (iter == controller_map_.end()) {
876 return JSRef<JSVal>::Make();
877 }
878 auto controller = iter->second.controller_;
879 if (parentId) {
880 *parentId = iter->second.parentWebId_;
881 }
882 controller_map_.erase(iter);
883 return controller;
884 }
885
ExistController(JSRef<JSObject> & controller,int32_t & parentWebId)886 static bool ExistController(JSRef<JSObject>& controller, int32_t& parentWebId)
887 {
888 auto getThisVarFunction = controller->GetProperty("innerGetThisVar");
889 if (!getThisVarFunction->IsFunction()) {
890 parentWebId = -1;
891 return false;
892 }
893 auto func = JSRef<JSFunc>::Cast(getThisVarFunction);
894 auto thisVar = func->Call(controller, 0, {});
895 int64_t thisPtr = thisVar->ToNumber<int64_t>();
896 for (auto iter = controller_map_.begin(); iter != controller_map_.end(); iter++) {
897 auto getThisVarFunction1 = iter->second.controller_->GetProperty("innerGetThisVar");
898 if (getThisVarFunction1->IsFunction()) {
899 auto func1 = JSRef<JSFunc>::Cast(getThisVarFunction1);
900 auto thisVar1 = func1->Call(iter->second.controller_, 0, {});
901 if (thisPtr == thisVar1->ToNumber<int64_t>()) {
902 parentWebId = iter->second.parentWebId_;
903 return true;
904 }
905 }
906 }
907 parentWebId = -1;
908 return false;
909 }
910
SetWebController(const JSCallbackInfo & args)911 void SetWebController(const JSCallbackInfo& args)
912 {
913 if (handler_) {
914 int32_t parentNWebId = handler_->GetParentNWebId();
915 if (parentNWebId == -1) {
916 return;
917 }
918 if (args.Length() < 1 || !args[0]->IsObject()) {
919 WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false);
920 return;
921 }
922 auto controller = JSRef<JSObject>::Cast(args[0]);
923 if (controller.IsEmpty()) {
924 WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false);
925 return;
926 }
927 auto getWebIdFunction = controller->GetProperty("innerGetWebId");
928 if (!getWebIdFunction->IsFunction()) {
929 WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false);
930 return;
931 }
932 auto func = JSRef<JSFunc>::Cast(getWebIdFunction);
933 auto webId = func->Call(controller, 0, {});
934 int32_t childWebId = webId->ToNumber<int32_t>();
935 if (childWebId == parentNWebId || childWebId != -1) {
936 WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false);
937 return;
938 }
939 controller_map_.insert(
940 std::pair<int32_t, ChildWindowInfo>(handler_->GetId(), { parentNWebId, controller }));
941 }
942 }
943
944 private:
Constructor(const JSCallbackInfo & args)945 static void Constructor(const JSCallbackInfo& args)
946 {
947 auto jsWebWindowNewHandler = Referenced::MakeRefPtr<JSWebWindowNewHandler>();
948 jsWebWindowNewHandler->IncRefCount();
949 args.SetReturnValue(Referenced::RawPtr(jsWebWindowNewHandler));
950 }
951
Destructor(JSWebWindowNewHandler * jsWebWindowNewHandler)952 static void Destructor(JSWebWindowNewHandler* jsWebWindowNewHandler)
953 {
954 if (jsWebWindowNewHandler != nullptr) {
955 jsWebWindowNewHandler->DecRefCount();
956 }
957 }
958
959 RefPtr<WebWindowNewHandler> handler_;
960 static std::unordered_map<int32_t, ChildWindowInfo> controller_map_;
961 };
962 std::unordered_map<int32_t, JSWebWindowNewHandler::ChildWindowInfo> JSWebWindowNewHandler::controller_map_;
963
964 class JSDataResubmitted : public Referenced {
965 public:
JSBind(BindingTarget globalObj)966 static void JSBind(BindingTarget globalObj)
967 {
968 JSClass<JSDataResubmitted>::Declare("DataResubmissionHandler");
969 JSClass<JSDataResubmitted>::CustomMethod("resend", &JSDataResubmitted::Resend);
970 JSClass<JSDataResubmitted>::CustomMethod("cancel", &JSDataResubmitted::Cancel);
971 JSClass<JSDataResubmitted>::Bind(globalObj, &JSDataResubmitted::Constructor, &JSDataResubmitted::Destructor);
972 }
973
SetHandler(const RefPtr<DataResubmitted> & handler)974 void SetHandler(const RefPtr<DataResubmitted>& handler)
975 {
976 dataResubmitted_ = handler;
977 }
978
Resend(const JSCallbackInfo & args)979 void Resend(const JSCallbackInfo& args)
980 {
981 if (dataResubmitted_) {
982 dataResubmitted_->Resend();
983 }
984 }
985
Cancel(const JSCallbackInfo & args)986 void Cancel(const JSCallbackInfo& args)
987 {
988 if (dataResubmitted_) {
989 dataResubmitted_->Cancel();
990 }
991 }
992
993 private:
Constructor(const JSCallbackInfo & args)994 static void Constructor(const JSCallbackInfo& args)
995 {
996 auto jsDataResubmitted = Referenced::MakeRefPtr<JSDataResubmitted>();
997 jsDataResubmitted->IncRefCount();
998 args.SetReturnValue(Referenced::RawPtr(jsDataResubmitted));
999 }
1000
Destructor(JSDataResubmitted * jsDataResubmitted)1001 static void Destructor(JSDataResubmitted* jsDataResubmitted)
1002 {
1003 if (jsDataResubmitted != nullptr) {
1004 jsDataResubmitted->DecRefCount();
1005 }
1006 }
1007 RefPtr<DataResubmitted> dataResubmitted_;
1008 };
1009
1010 class JSWebResourceError : public Referenced {
1011 public:
JSBind(BindingTarget globalObj)1012 static void JSBind(BindingTarget globalObj)
1013 {
1014 JSClass<JSWebResourceError>::Declare("WebResourceError");
1015 JSClass<JSWebResourceError>::CustomMethod("getErrorCode", &JSWebResourceError::GetErrorCode);
1016 JSClass<JSWebResourceError>::CustomMethod("getErrorInfo", &JSWebResourceError::GetErrorInfo);
1017 JSClass<JSWebResourceError>::Bind(globalObj, &JSWebResourceError::Constructor, &JSWebResourceError::Destructor);
1018 }
1019
SetEvent(const ReceivedErrorEvent & eventInfo)1020 void SetEvent(const ReceivedErrorEvent& eventInfo)
1021 {
1022 error_ = eventInfo.GetError();
1023 }
1024
GetErrorCode(const JSCallbackInfo & args)1025 void GetErrorCode(const JSCallbackInfo& args)
1026 {
1027 auto code = JSVal(ToJSValue(error_->GetCode()));
1028 auto descriptionRef = JSRef<JSVal>::Make(code);
1029 args.SetReturnValue(descriptionRef);
1030 }
1031
GetErrorInfo(const JSCallbackInfo & args)1032 void GetErrorInfo(const JSCallbackInfo& args)
1033 {
1034 auto info = JSVal(ToJSValue(error_->GetInfo()));
1035 auto descriptionRef = JSRef<JSVal>::Make(info);
1036 args.SetReturnValue(descriptionRef);
1037 }
1038
1039 private:
Constructor(const JSCallbackInfo & args)1040 static void Constructor(const JSCallbackInfo& args)
1041 {
1042 auto jSWebResourceError = Referenced::MakeRefPtr<JSWebResourceError>();
1043 jSWebResourceError->IncRefCount();
1044 args.SetReturnValue(Referenced::RawPtr(jSWebResourceError));
1045 }
1046
Destructor(JSWebResourceError * jSWebResourceError)1047 static void Destructor(JSWebResourceError* jSWebResourceError)
1048 {
1049 if (jSWebResourceError != nullptr) {
1050 jSWebResourceError->DecRefCount();
1051 }
1052 }
1053
1054 RefPtr<WebError> error_;
1055 };
1056
1057 class JSWebResourceResponse : public Referenced {
1058 public:
JSBind(BindingTarget globalObj)1059 static void JSBind(BindingTarget globalObj)
1060 {
1061 JSClass<JSWebResourceResponse>::Declare("WebResourceResponse");
1062 JSClass<JSWebResourceResponse>::CustomMethod("getResponseData", &JSWebResourceResponse::GetResponseData);
1063 JSClass<JSWebResourceResponse>::CustomMethod("getResponseDataEx", &JSWebResourceResponse::GetResponseDataEx);
1064 JSClass<JSWebResourceResponse>::CustomMethod(
1065 "getResponseEncoding", &JSWebResourceResponse::GetResponseEncoding);
1066 JSClass<JSWebResourceResponse>::CustomMethod(
1067 "getResponseMimeType", &JSWebResourceResponse::GetResponseMimeType);
1068 JSClass<JSWebResourceResponse>::CustomMethod("getReasonMessage", &JSWebResourceResponse::GetReasonMessage);
1069 JSClass<JSWebResourceResponse>::CustomMethod("getResponseCode", &JSWebResourceResponse::GetResponseCode);
1070 JSClass<JSWebResourceResponse>::CustomMethod("getResponseHeader", &JSWebResourceResponse::GetResponseHeader);
1071 JSClass<JSWebResourceResponse>::CustomMethod("setResponseData", &JSWebResourceResponse::SetResponseData);
1072 JSClass<JSWebResourceResponse>::CustomMethod(
1073 "setResponseEncoding", &JSWebResourceResponse::SetResponseEncoding);
1074 JSClass<JSWebResourceResponse>::CustomMethod(
1075 "setResponseMimeType", &JSWebResourceResponse::SetResponseMimeType);
1076 JSClass<JSWebResourceResponse>::CustomMethod("setReasonMessage", &JSWebResourceResponse::SetReasonMessage);
1077 JSClass<JSWebResourceResponse>::CustomMethod("setResponseCode", &JSWebResourceResponse::SetResponseCode);
1078 JSClass<JSWebResourceResponse>::CustomMethod("setResponseHeader", &JSWebResourceResponse::SetResponseHeader);
1079 JSClass<JSWebResourceResponse>::CustomMethod("setResponseIsReady", &JSWebResourceResponse::SetResponseIsReady);
1080 JSClass<JSWebResourceResponse>::CustomMethod("getResponseIsReady", &JSWebResourceResponse::GetResponseIsReady);
1081 JSClass<JSWebResourceResponse>::Bind(
1082 globalObj, &JSWebResourceResponse::Constructor, &JSWebResourceResponse::Destructor);
1083 }
1084
JSWebResourceResponse()1085 JSWebResourceResponse() : response_(AceType::MakeRefPtr<WebResponse>()) {}
1086
SetEvent(const ReceivedHttpErrorEvent & eventInfo)1087 void SetEvent(const ReceivedHttpErrorEvent& eventInfo)
1088 {
1089 response_ = eventInfo.GetResponse();
1090 }
1091
GetResponseData(const JSCallbackInfo & args)1092 void GetResponseData(const JSCallbackInfo& args)
1093 {
1094 auto data = JSVal(ToJSValue(response_->GetData()));
1095 auto descriptionRef = JSRef<JSVal>::Make(data);
1096 args.SetReturnValue(descriptionRef);
1097 }
1098
GetResponseDataEx(const JSCallbackInfo & args)1099 void GetResponseDataEx(const JSCallbackInfo& args)
1100 {
1101 args.SetReturnValue(responseData_);
1102 }
1103
GetResponseIsReady(const JSCallbackInfo & args)1104 void GetResponseIsReady(const JSCallbackInfo& args)
1105 {
1106 auto status = JSVal(ToJSValue(response_->GetResponseStatus()));
1107 auto descriptionRef = JSRef<JSVal>::Make(status);
1108 args.SetReturnValue(descriptionRef);
1109 }
1110
GetResponseEncoding(const JSCallbackInfo & args)1111 void GetResponseEncoding(const JSCallbackInfo& args)
1112 {
1113 auto encoding = JSVal(ToJSValue(response_->GetEncoding()));
1114 auto descriptionRef = JSRef<JSVal>::Make(encoding);
1115 args.SetReturnValue(descriptionRef);
1116 }
1117
GetResponseMimeType(const JSCallbackInfo & args)1118 void GetResponseMimeType(const JSCallbackInfo& args)
1119 {
1120 auto mimeType = JSVal(ToJSValue(response_->GetMimeType()));
1121 auto descriptionRef = JSRef<JSVal>::Make(mimeType);
1122 args.SetReturnValue(descriptionRef);
1123 }
1124
GetReasonMessage(const JSCallbackInfo & args)1125 void GetReasonMessage(const JSCallbackInfo& args)
1126 {
1127 auto reason = JSVal(ToJSValue(response_->GetReason()));
1128 auto descriptionRef = JSRef<JSVal>::Make(reason);
1129 args.SetReturnValue(descriptionRef);
1130 }
1131
GetResponseCode(const JSCallbackInfo & args)1132 void GetResponseCode(const JSCallbackInfo& args)
1133 {
1134 auto code = JSVal(ToJSValue(response_->GetStatusCode()));
1135 auto descriptionRef = JSRef<JSVal>::Make(code);
1136 args.SetReturnValue(descriptionRef);
1137 }
1138
GetResponseHeader(const JSCallbackInfo & args)1139 void GetResponseHeader(const JSCallbackInfo& args)
1140 {
1141 auto map = response_->GetHeaders();
1142 std::map<std::string, std::string>::iterator iterator;
1143 uint32_t index = 0;
1144 JSRef<JSArray> headers = JSRef<JSArray>::New();
1145 for (iterator = map.begin(); iterator != map.end(); ++iterator) {
1146 JSRef<JSObject> header = JSRef<JSObject>::New();
1147 header->SetProperty("headerKey", iterator->first);
1148 header->SetProperty("headerValue", iterator->second);
1149 headers->SetValueAt(index++, header);
1150 }
1151 args.SetReturnValue(headers);
1152 }
1153
GetResponseObj() const1154 RefPtr<WebResponse> GetResponseObj() const
1155 {
1156 return response_;
1157 }
1158
SetResponseData(const JSCallbackInfo & args)1159 void SetResponseData(const JSCallbackInfo& args)
1160 {
1161 if (args.Length() <= 0) {
1162 return;
1163 }
1164
1165 responseData_ = args[0];
1166 if (args[0]->IsNumber()) {
1167 auto fd = args[0]->ToNumber<int32_t>();
1168 response_->SetFileHandle(fd);
1169 return;
1170 }
1171 if (args[0]->IsString()) {
1172 auto data = args[0]->ToString();
1173 response_->SetData(data);
1174 return;
1175 }
1176 if (args[0]->IsArrayBuffer()) {
1177 JsiRef<JsiArrayBuffer> arrayBuffer = JsiRef<JsiArrayBuffer>::Cast(args[0]);
1178 int32_t bufferSize = arrayBuffer->ByteLength();
1179 void* buffer = arrayBuffer->GetBuffer();
1180 const char* charPtr = static_cast<const char*>(buffer);
1181 std::string data(charPtr, bufferSize);
1182 response_->SetData(data);
1183 response_->SetBuffer(static_cast<char*>(buffer), bufferSize);
1184 return;
1185 }
1186 if (args[0]->IsObject()) {
1187 std::string resourceUrl;
1188 std::string url;
1189 if (!JSViewAbstract::ParseJsMedia(args[0], resourceUrl)) {
1190 return;
1191 }
1192 auto np = resourceUrl.find_first_of("/");
1193 url = (np == std::string::npos) ? resourceUrl : resourceUrl.erase(np, 1);
1194 response_->SetResourceUrl(url);
1195 return;
1196 }
1197 }
1198
SetResponseEncoding(const JSCallbackInfo & args)1199 void SetResponseEncoding(const JSCallbackInfo& args)
1200 {
1201 if ((args.Length() <= 0) || !(args[0]->IsString())) {
1202 return;
1203 }
1204 auto encode = args[0]->ToString();
1205 response_->SetEncoding(encode);
1206 }
1207
SetResponseMimeType(const JSCallbackInfo & args)1208 void SetResponseMimeType(const JSCallbackInfo& args)
1209 {
1210 if ((args.Length() <= 0) || !(args[0]->IsString())) {
1211 return;
1212 }
1213 auto mineType = args[0]->ToString();
1214 response_->SetMimeType(mineType);
1215 }
1216
SetReasonMessage(const JSCallbackInfo & args)1217 void SetReasonMessage(const JSCallbackInfo& args)
1218 {
1219 if ((args.Length() <= 0) || !(args[0]->IsString())) {
1220 return;
1221 }
1222 auto reason = args[0]->ToString();
1223 response_->SetReason(reason);
1224 }
1225
SetResponseCode(const JSCallbackInfo & args)1226 void SetResponseCode(const JSCallbackInfo& args)
1227 {
1228 if ((args.Length() <= 0) || !(args[0]->IsNumber())) {
1229 return;
1230 }
1231 auto statusCode = args[0]->ToNumber<int32_t>();
1232 response_->SetStatusCode(statusCode);
1233 }
1234
SetResponseHeader(const JSCallbackInfo & args)1235 void SetResponseHeader(const JSCallbackInfo& args)
1236 {
1237 if ((args.Length() <= 0) || !(args[0]->IsArray())) {
1238 return;
1239 }
1240 JSRef<JSArray> array = JSRef<JSArray>::Cast(args[0]);
1241 for (size_t i = 0; i < array->Length(); i++) {
1242 if (!(array->GetValueAt(i)->IsObject())) {
1243 return;
1244 }
1245 auto obj = JSRef<JSObject>::Cast(array->GetValueAt(i));
1246 auto headerKey = obj->GetProperty("headerKey");
1247 auto headerValue = obj->GetProperty("headerValue");
1248 if (!headerKey->IsString() || !headerValue->IsString()) {
1249 return;
1250 }
1251 auto keystr = headerKey->ToString();
1252 auto valstr = headerValue->ToString();
1253 response_->SetHeadersVal(keystr, valstr);
1254 }
1255 }
1256
SetResponseIsReady(const JSCallbackInfo & args)1257 void SetResponseIsReady(const JSCallbackInfo& args)
1258 {
1259 if ((args.Length() <= 0) || !(args[0]->IsBoolean())) {
1260 return;
1261 }
1262 bool isReady = false;
1263 if (!ConvertFromJSValue(args[0], isReady)) {
1264 return;
1265 }
1266 response_->SetResponseStatus(isReady);
1267 }
1268
1269 private:
Constructor(const JSCallbackInfo & args)1270 static void Constructor(const JSCallbackInfo& args)
1271 {
1272 auto jSWebResourceResponse = Referenced::MakeRefPtr<JSWebResourceResponse>();
1273 jSWebResourceResponse->IncRefCount();
1274 args.SetReturnValue(Referenced::RawPtr(jSWebResourceResponse));
1275 }
1276
Destructor(JSWebResourceResponse * jSWebResourceResponse)1277 static void Destructor(JSWebResourceResponse* jSWebResourceResponse)
1278 {
1279 if (jSWebResourceResponse != nullptr) {
1280 jSWebResourceResponse->DecRefCount();
1281 }
1282 }
1283
1284 RefPtr<WebResponse> response_;
1285 JSRef<JSVal> responseData_;
1286 };
1287
1288 class JSWebResourceRequest : public Referenced {
1289 public:
JSBind(BindingTarget globalObj)1290 static void JSBind(BindingTarget globalObj)
1291 {
1292 JSClass<JSWebResourceRequest>::Declare("WebResourceRequest");
1293 JSClass<JSWebResourceRequest>::CustomMethod("getRequestUrl", &JSWebResourceRequest::GetRequestUrl);
1294 JSClass<JSWebResourceRequest>::CustomMethod("getRequestHeader", &JSWebResourceRequest::GetRequestHeader);
1295 JSClass<JSWebResourceRequest>::CustomMethod("getRequestMethod", &JSWebResourceRequest::GetRequestMethod);
1296 JSClass<JSWebResourceRequest>::CustomMethod("isRequestGesture", &JSWebResourceRequest::IsRequestGesture);
1297 JSClass<JSWebResourceRequest>::CustomMethod("isMainFrame", &JSWebResourceRequest::IsMainFrame);
1298 JSClass<JSWebResourceRequest>::CustomMethod("isRedirect", &JSWebResourceRequest::IsRedirect);
1299 JSClass<JSWebResourceRequest>::Bind(
1300 globalObj, &JSWebResourceRequest::Constructor, &JSWebResourceRequest::Destructor);
1301 }
1302
SetErrorEvent(const ReceivedErrorEvent & eventInfo)1303 void SetErrorEvent(const ReceivedErrorEvent& eventInfo)
1304 {
1305 request_ = eventInfo.GetRequest();
1306 }
1307
SetHttpErrorEvent(const ReceivedHttpErrorEvent & eventInfo)1308 void SetHttpErrorEvent(const ReceivedHttpErrorEvent& eventInfo)
1309 {
1310 request_ = eventInfo.GetRequest();
1311 }
1312
SetOnInterceptRequestEvent(const OnInterceptRequestEvent & eventInfo)1313 void SetOnInterceptRequestEvent(const OnInterceptRequestEvent& eventInfo)
1314 {
1315 request_ = eventInfo.GetRequest();
1316 }
1317
SetLoadInterceptEvent(const LoadInterceptEvent & eventInfo)1318 void SetLoadInterceptEvent(const LoadInterceptEvent& eventInfo)
1319 {
1320 request_ = eventInfo.GetRequest();
1321 }
1322
IsRedirect(const JSCallbackInfo & args)1323 void IsRedirect(const JSCallbackInfo& args)
1324 {
1325 auto isRedirect = JSVal(ToJSValue(request_->IsRedirect()));
1326 auto descriptionRef = JSRef<JSVal>::Make(isRedirect);
1327 args.SetReturnValue(descriptionRef);
1328 }
1329
GetRequestUrl(const JSCallbackInfo & args)1330 void GetRequestUrl(const JSCallbackInfo& args)
1331 {
1332 auto url = JSVal(ToJSValue(request_->GetUrl()));
1333 auto descriptionRef = JSRef<JSVal>::Make(url);
1334 args.SetReturnValue(descriptionRef);
1335 }
1336
GetRequestMethod(const JSCallbackInfo & args)1337 void GetRequestMethod(const JSCallbackInfo& args)
1338 {
1339 auto method = JSVal(ToJSValue(request_->GetMethod()));
1340 auto descriptionRef = JSRef<JSVal>::Make(method);
1341 args.SetReturnValue(descriptionRef);
1342 }
1343
IsRequestGesture(const JSCallbackInfo & args)1344 void IsRequestGesture(const JSCallbackInfo& args)
1345 {
1346 auto isRequestGesture = JSVal(ToJSValue(request_->HasGesture()));
1347 auto descriptionRef = JSRef<JSVal>::Make(isRequestGesture);
1348 args.SetReturnValue(descriptionRef);
1349 }
1350
IsMainFrame(const JSCallbackInfo & args)1351 void IsMainFrame(const JSCallbackInfo& args)
1352 {
1353 auto isMainFrame = JSVal(ToJSValue(request_->IsMainFrame()));
1354 auto descriptionRef = JSRef<JSVal>::Make(isMainFrame);
1355 args.SetReturnValue(descriptionRef);
1356 }
1357
GetRequestHeader(const JSCallbackInfo & args)1358 void GetRequestHeader(const JSCallbackInfo& args)
1359 {
1360 auto map = request_->GetHeaders();
1361 std::map<std::string, std::string>::iterator iterator;
1362 uint32_t index = 0;
1363 JSRef<JSArray> headers = JSRef<JSArray>::New();
1364 for (iterator = map.begin(); iterator != map.end(); ++iterator) {
1365 JSRef<JSObject> header = JSRef<JSObject>::New();
1366 header->SetProperty("headerKey", iterator->first);
1367 header->SetProperty("headerValue", iterator->second);
1368 headers->SetValueAt(index++, header);
1369 }
1370 args.SetReturnValue(headers);
1371 }
1372
SetLoadOverrideEvent(const LoadOverrideEvent & eventInfo)1373 void SetLoadOverrideEvent(const LoadOverrideEvent& eventInfo)
1374 {
1375 request_ = eventInfo.GetRequest();
1376 }
1377
1378 private:
Constructor(const JSCallbackInfo & args)1379 static void Constructor(const JSCallbackInfo& args)
1380 {
1381 auto jSWebResourceRequest = Referenced::MakeRefPtr<JSWebResourceRequest>();
1382 jSWebResourceRequest->IncRefCount();
1383 args.SetReturnValue(Referenced::RawPtr(jSWebResourceRequest));
1384 }
1385
Destructor(JSWebResourceRequest * jSWebResourceRequest)1386 static void Destructor(JSWebResourceRequest* jSWebResourceRequest)
1387 {
1388 if (jSWebResourceRequest != nullptr) {
1389 jSWebResourceRequest->DecRefCount();
1390 }
1391 }
1392
1393 RefPtr<WebRequest> request_;
1394 };
1395
1396 class JSFileSelectorParam : public Referenced {
1397 public:
JSBind(BindingTarget globalObj)1398 static void JSBind(BindingTarget globalObj)
1399 {
1400 JSClass<JSFileSelectorParam>::Declare("FileSelectorParam");
1401 JSClass<JSFileSelectorParam>::CustomMethod("getTitle", &JSFileSelectorParam::GetTitle);
1402 JSClass<JSFileSelectorParam>::CustomMethod("getMode", &JSFileSelectorParam::GetMode);
1403 JSClass<JSFileSelectorParam>::CustomMethod("getAcceptType", &JSFileSelectorParam::GetAcceptType);
1404 JSClass<JSFileSelectorParam>::CustomMethod("isCapture", &JSFileSelectorParam::IsCapture);
1405 JSClass<JSFileSelectorParam>::Bind(
1406 globalObj, &JSFileSelectorParam::Constructor, &JSFileSelectorParam::Destructor);
1407 }
1408
SetParam(const FileSelectorEvent & eventInfo)1409 void SetParam(const FileSelectorEvent& eventInfo)
1410 {
1411 param_ = eventInfo.GetParam();
1412 }
1413
GetTitle(const JSCallbackInfo & args)1414 void GetTitle(const JSCallbackInfo& args)
1415 {
1416 auto title = JSVal(ToJSValue(param_->GetTitle()));
1417 auto descriptionRef = JSRef<JSVal>::Make(title);
1418 args.SetReturnValue(descriptionRef);
1419 }
1420
GetMode(const JSCallbackInfo & args)1421 void GetMode(const JSCallbackInfo& args)
1422 {
1423 auto mode = JSVal(ToJSValue(param_->GetMode()));
1424 auto descriptionRef = JSRef<JSVal>::Make(mode);
1425 args.SetReturnValue(descriptionRef);
1426 }
1427
IsCapture(const JSCallbackInfo & args)1428 void IsCapture(const JSCallbackInfo& args)
1429 {
1430 auto isCapture = JSVal(ToJSValue(param_->IsCapture()));
1431 auto descriptionRef = JSRef<JSVal>::Make(isCapture);
1432 args.SetReturnValue(descriptionRef);
1433 }
1434
GetAcceptType(const JSCallbackInfo & args)1435 void GetAcceptType(const JSCallbackInfo& args)
1436 {
1437 auto acceptTypes = param_->GetAcceptType();
1438 JSRef<JSArray> result = JSRef<JSArray>::New();
1439 std::vector<std::string>::iterator iterator;
1440 uint32_t index = 0;
1441 for (iterator = acceptTypes.begin(); iterator != acceptTypes.end(); ++iterator) {
1442 auto valueStr = JSVal(ToJSValue(*iterator));
1443 auto value = JSRef<JSVal>::Make(valueStr);
1444 result->SetValueAt(index++, value);
1445 }
1446 args.SetReturnValue(result);
1447 }
1448
1449 private:
Constructor(const JSCallbackInfo & args)1450 static void Constructor(const JSCallbackInfo& args)
1451 {
1452 auto jSFilerSelectorParam = Referenced::MakeRefPtr<JSFileSelectorParam>();
1453 jSFilerSelectorParam->IncRefCount();
1454 args.SetReturnValue(Referenced::RawPtr(jSFilerSelectorParam));
1455 }
1456
Destructor(JSFileSelectorParam * jSFilerSelectorParam)1457 static void Destructor(JSFileSelectorParam* jSFilerSelectorParam)
1458 {
1459 if (jSFilerSelectorParam != nullptr) {
1460 jSFilerSelectorParam->DecRefCount();
1461 }
1462 }
1463
1464 RefPtr<WebFileSelectorParam> param_;
1465 };
1466
1467 class JSFileSelectorResult : public Referenced {
1468 public:
JSBind(BindingTarget globalObj)1469 static void JSBind(BindingTarget globalObj)
1470 {
1471 JSClass<JSFileSelectorResult>::Declare("FileSelectorResult");
1472 JSClass<JSFileSelectorResult>::CustomMethod("handleFileList", &JSFileSelectorResult::HandleFileList);
1473 JSClass<JSFileSelectorResult>::Bind(
1474 globalObj, &JSFileSelectorResult::Constructor, &JSFileSelectorResult::Destructor);
1475 }
1476
SetResult(const FileSelectorEvent & eventInfo)1477 void SetResult(const FileSelectorEvent& eventInfo)
1478 {
1479 result_ = eventInfo.GetFileSelectorResult();
1480 }
1481
HandleFileList(const JSCallbackInfo & args)1482 void HandleFileList(const JSCallbackInfo& args)
1483 {
1484 std::vector<std::string> fileList;
1485 if (args[0]->IsArray()) {
1486 JSRef<JSArray> array = JSRef<JSArray>::Cast(args[0]);
1487 for (size_t i = 0; i < array->Length(); i++) {
1488 JSRef<JSVal> val = array->GetValueAt(i);
1489 if (!val->IsString()) {
1490 continue;
1491 }
1492 std::string fileName;
1493 if (!ConvertFromJSValue(val, fileName)) {
1494 continue;
1495 }
1496 fileList.push_back(fileName);
1497 }
1498 }
1499
1500 if (result_) {
1501 result_->HandleFileList(fileList);
1502 }
1503 }
1504
1505 private:
Constructor(const JSCallbackInfo & args)1506 static void Constructor(const JSCallbackInfo& args)
1507 {
1508 auto jsFileSelectorResult = Referenced::MakeRefPtr<JSFileSelectorResult>();
1509 jsFileSelectorResult->IncRefCount();
1510 args.SetReturnValue(Referenced::RawPtr(jsFileSelectorResult));
1511 }
1512
Destructor(JSFileSelectorResult * jsFileSelectorResult)1513 static void Destructor(JSFileSelectorResult* jsFileSelectorResult)
1514 {
1515 if (jsFileSelectorResult != nullptr) {
1516 jsFileSelectorResult->DecRefCount();
1517 }
1518 }
1519
1520 RefPtr<FileSelectorResult> result_;
1521 };
1522
1523 class JSContextMenuParam : public Referenced {
1524 public:
JSBind(BindingTarget globalObj)1525 static void JSBind(BindingTarget globalObj)
1526 {
1527 JSClass<JSContextMenuParam>::Declare("WebContextMenuParam");
1528 JSClass<JSContextMenuParam>::CustomMethod("x", &JSContextMenuParam::GetXCoord);
1529 JSClass<JSContextMenuParam>::CustomMethod("y", &JSContextMenuParam::GetYCoord);
1530 JSClass<JSContextMenuParam>::CustomMethod("getLinkUrl", &JSContextMenuParam::GetLinkUrl);
1531 JSClass<JSContextMenuParam>::CustomMethod("getUnfilteredLinkUrl", &JSContextMenuParam::GetUnfilteredLinkUrl);
1532 JSClass<JSContextMenuParam>::CustomMethod("getSourceUrl", &JSContextMenuParam::GetSourceUrl);
1533 JSClass<JSContextMenuParam>::CustomMethod("existsImageContents", &JSContextMenuParam::HasImageContents);
1534 JSClass<JSContextMenuParam>::CustomMethod("getSelectionText", &JSContextMenuParam::GetSelectionText);
1535 JSClass<JSContextMenuParam>::CustomMethod("isEditable", &JSContextMenuParam::IsEditable);
1536 JSClass<JSContextMenuParam>::CustomMethod("getEditStateFlags", &JSContextMenuParam::GetEditStateFlags);
1537 JSClass<JSContextMenuParam>::CustomMethod("getSourceType", &JSContextMenuParam::GetSourceType);
1538 JSClass<JSContextMenuParam>::CustomMethod("getInputFieldType", &JSContextMenuParam::GetInputFieldType);
1539 JSClass<JSContextMenuParam>::CustomMethod("getMediaType", &JSContextMenuParam::GetMediaType);
1540 JSClass<JSContextMenuParam>::CustomMethod("getPreviewWidth", &JSContextMenuParam::GetPreviewWidth);
1541 JSClass<JSContextMenuParam>::CustomMethod("getPreviewHeight", &JSContextMenuParam::GetPreviewHeight);
1542 JSClass<JSContextMenuParam>::Bind(globalObj, &JSContextMenuParam::Constructor, &JSContextMenuParam::Destructor);
1543 }
1544
UpdatePreviewSize()1545 void UpdatePreviewSize()
1546 {
1547 if (previewWidth_ >= 0 && previewHeight_ >= 0) {
1548 return;
1549 }
1550 if (param_) {
1551 int32_t x = 0;
1552 int32_t y = 0;
1553 param_->GetImageRect(x, y, previewWidth_, previewHeight_);
1554 }
1555 }
1556
GetPreviewWidth(const JSCallbackInfo & args)1557 void GetPreviewWidth(const JSCallbackInfo& args)
1558 {
1559 auto ret = JSVal(ToJSValue(previewWidth_));
1560 auto descriptionRef = JSRef<JSVal>::Make(ret);
1561 args.SetReturnValue(descriptionRef);
1562 }
1563
GetPreviewHeight(const JSCallbackInfo & args)1564 void GetPreviewHeight(const JSCallbackInfo& args)
1565 {
1566 auto ret = JSVal(ToJSValue(previewHeight_));
1567 auto descriptionRef = JSRef<JSVal>::Make(ret);
1568 args.SetReturnValue(descriptionRef);
1569 }
1570
SetParam(const ContextMenuEvent & eventInfo)1571 void SetParam(const ContextMenuEvent& eventInfo)
1572 {
1573 param_ = eventInfo.GetParam();
1574 UpdatePreviewSize();
1575 }
1576
GetXCoord(const JSCallbackInfo & args)1577 void GetXCoord(const JSCallbackInfo& args)
1578 {
1579 int32_t ret = -1;
1580 if (param_) {
1581 ret = param_->GetXCoord();
1582 }
1583 auto xCoord = JSVal(ToJSValue(ret));
1584 auto descriptionRef = JSRef<JSVal>::Make(xCoord);
1585 args.SetReturnValue(descriptionRef);
1586 }
1587
GetYCoord(const JSCallbackInfo & args)1588 void GetYCoord(const JSCallbackInfo& args)
1589 {
1590 int32_t ret = -1;
1591 if (param_) {
1592 ret = param_->GetYCoord();
1593 }
1594 auto yCoord = JSVal(ToJSValue(ret));
1595 auto descriptionRef = JSRef<JSVal>::Make(yCoord);
1596 args.SetReturnValue(descriptionRef);
1597 }
1598
GetLinkUrl(const JSCallbackInfo & args)1599 void GetLinkUrl(const JSCallbackInfo& args)
1600 {
1601 std::string url;
1602 if (param_) {
1603 url = param_->GetLinkUrl();
1604 }
1605 auto linkUrl = JSVal(ToJSValue(url));
1606 auto descriptionRef = JSRef<JSVal>::Make(linkUrl);
1607 args.SetReturnValue(descriptionRef);
1608 }
1609
GetUnfilteredLinkUrl(const JSCallbackInfo & args)1610 void GetUnfilteredLinkUrl(const JSCallbackInfo& args)
1611 {
1612 std::string url;
1613 if (param_) {
1614 url = param_->GetUnfilteredLinkUrl();
1615 }
1616 auto unfilteredLinkUrl = JSVal(ToJSValue(url));
1617 auto descriptionRef = JSRef<JSVal>::Make(unfilteredLinkUrl);
1618 args.SetReturnValue(descriptionRef);
1619 }
1620
GetSourceUrl(const JSCallbackInfo & args)1621 void GetSourceUrl(const JSCallbackInfo& args)
1622 {
1623 std::string url;
1624 if (param_) {
1625 url = param_->GetSourceUrl();
1626 }
1627 auto sourceUrl = JSVal(ToJSValue(url));
1628 auto descriptionRef = JSRef<JSVal>::Make(sourceUrl);
1629 args.SetReturnValue(descriptionRef);
1630 }
1631
HasImageContents(const JSCallbackInfo & args)1632 void HasImageContents(const JSCallbackInfo& args)
1633 {
1634 bool ret = false;
1635 if (param_) {
1636 ret = param_->HasImageContents();
1637 }
1638 auto hasImageContents = JSVal(ToJSValue(ret));
1639 auto descriptionRef = JSRef<JSVal>::Make(hasImageContents);
1640 args.SetReturnValue(descriptionRef);
1641 }
1642
GetSelectionText(const JSCallbackInfo & args)1643 void GetSelectionText(const JSCallbackInfo& args)
1644 {
1645 std::string text;
1646 if (param_) {
1647 text = param_->GetSelectionText();
1648 }
1649 auto jsText = JSVal(ToJSValue(text));
1650 auto descriptionRef = JSRef<JSVal>::Make(jsText);
1651 args.SetReturnValue(descriptionRef);
1652 }
1653
IsEditable(const JSCallbackInfo & args)1654 void IsEditable(const JSCallbackInfo& args)
1655 {
1656 bool flag = false;
1657 if (param_) {
1658 flag = param_->IsEditable();
1659 }
1660 auto jsFlag = JSVal(ToJSValue(flag));
1661 auto descriptionRef = JSRef<JSVal>::Make(jsFlag);
1662 args.SetReturnValue(descriptionRef);
1663 }
1664
GetEditStateFlags(const JSCallbackInfo & args)1665 void GetEditStateFlags(const JSCallbackInfo& args)
1666 {
1667 int32_t flags = 0;
1668 if (param_) {
1669 flags = param_->GetEditStateFlags();
1670 }
1671 auto jsFlags = JSVal(ToJSValue(flags));
1672 auto descriptionRef = JSRef<JSVal>::Make(jsFlags);
1673 args.SetReturnValue(descriptionRef);
1674 }
1675
GetSourceType(const JSCallbackInfo & args)1676 void GetSourceType(const JSCallbackInfo& args)
1677 {
1678 int32_t type = 0;
1679 if (param_) {
1680 type = param_->GetSourceType();
1681 }
1682 auto jsType = JSVal(ToJSValue(type));
1683 auto descriptionRef = JSRef<JSVal>::Make(jsType);
1684 args.SetReturnValue(descriptionRef);
1685 }
1686
GetInputFieldType(const JSCallbackInfo & args)1687 void GetInputFieldType(const JSCallbackInfo& args)
1688 {
1689 int32_t type = 0;
1690 if (param_) {
1691 type = param_->GetInputFieldType();
1692 }
1693 auto jsType = JSVal(ToJSValue(type));
1694 auto descriptionRef = JSRef<JSVal>::Make(jsType);
1695 args.SetReturnValue(descriptionRef);
1696 }
1697
GetMediaType(const JSCallbackInfo & args)1698 void GetMediaType(const JSCallbackInfo& args)
1699 {
1700 int32_t type = 0;
1701 if (param_) {
1702 type = param_->GetMediaType();
1703 }
1704 auto jsType = JSVal(ToJSValue(type));
1705 auto descriptionRef = JSRef<JSVal>::Make(jsType);
1706 args.SetReturnValue(descriptionRef);
1707 }
1708
1709 private:
Constructor(const JSCallbackInfo & args)1710 static void Constructor(const JSCallbackInfo& args)
1711 {
1712 auto jSContextMenuParam = Referenced::MakeRefPtr<JSContextMenuParam>();
1713 jSContextMenuParam->IncRefCount();
1714 args.SetReturnValue(Referenced::RawPtr(jSContextMenuParam));
1715 }
1716
Destructor(JSContextMenuParam * jSContextMenuParam)1717 static void Destructor(JSContextMenuParam* jSContextMenuParam)
1718 {
1719 if (jSContextMenuParam != nullptr) {
1720 jSContextMenuParam->DecRefCount();
1721 }
1722 }
1723
1724 RefPtr<WebContextMenuParam> param_;
1725
1726 int32_t previewWidth_ = -1;
1727
1728 int32_t previewHeight_ = -1;
1729 };
1730
1731 class JSContextMenuResult : public Referenced {
1732 public:
JSBind(BindingTarget globalObj)1733 static void JSBind(BindingTarget globalObj)
1734 {
1735 JSClass<JSContextMenuResult>::Declare("WebContextMenuResult");
1736 JSClass<JSContextMenuResult>::CustomMethod("closeContextMenu", &JSContextMenuResult::Cancel);
1737 JSClass<JSContextMenuResult>::CustomMethod("copyImage", &JSContextMenuResult::CopyImage);
1738 JSClass<JSContextMenuResult>::CustomMethod("copy", &JSContextMenuResult::Copy);
1739 JSClass<JSContextMenuResult>::CustomMethod("paste", &JSContextMenuResult::Paste);
1740 JSClass<JSContextMenuResult>::CustomMethod("cut", &JSContextMenuResult::Cut);
1741 JSClass<JSContextMenuResult>::CustomMethod("selectAll", &JSContextMenuResult::SelectAll);
1742 JSClass<JSContextMenuResult>::Bind(
1743 globalObj, &JSContextMenuResult::Constructor, &JSContextMenuResult::Destructor);
1744 }
1745
SetResult(const ContextMenuEvent & eventInfo)1746 void SetResult(const ContextMenuEvent& eventInfo)
1747 {
1748 result_ = eventInfo.GetContextMenuResult();
1749 }
1750
Cancel(const JSCallbackInfo & args)1751 void Cancel(const JSCallbackInfo& args)
1752 {
1753 if (result_) {
1754 result_->Cancel();
1755 }
1756 }
1757
CopyImage(const JSCallbackInfo & args)1758 void CopyImage(const JSCallbackInfo& args)
1759 {
1760 if (result_) {
1761 result_->CopyImage();
1762 }
1763 }
1764
Copy(const JSCallbackInfo & args)1765 void Copy(const JSCallbackInfo& args)
1766 {
1767 if (result_) {
1768 result_->Copy();
1769 }
1770 }
1771
Paste(const JSCallbackInfo & args)1772 void Paste(const JSCallbackInfo& args)
1773 {
1774 if (result_) {
1775 result_->Paste();
1776 }
1777 }
1778
Cut(const JSCallbackInfo & args)1779 void Cut(const JSCallbackInfo& args)
1780 {
1781 if (result_) {
1782 result_->Cut();
1783 }
1784 }
1785
SelectAll(const JSCallbackInfo & args)1786 void SelectAll(const JSCallbackInfo& args)
1787 {
1788 if (result_) {
1789 result_->SelectAll();
1790 }
1791 }
1792
1793 private:
Constructor(const JSCallbackInfo & args)1794 static void Constructor(const JSCallbackInfo& args)
1795 {
1796 auto jsContextMenuResult = Referenced::MakeRefPtr<JSContextMenuResult>();
1797 jsContextMenuResult->IncRefCount();
1798 args.SetReturnValue(Referenced::RawPtr(jsContextMenuResult));
1799 }
1800
Destructor(JSContextMenuResult * jsContextMenuResult)1801 static void Destructor(JSContextMenuResult* jsContextMenuResult)
1802 {
1803 if (jsContextMenuResult != nullptr) {
1804 jsContextMenuResult->DecRefCount();
1805 }
1806 }
1807
1808 RefPtr<ContextMenuResult> result_;
1809 };
1810
1811 class JSWebAppLinkCallback : public Referenced {
1812 public:
JSBind(BindingTarget globalObj)1813 static void JSBind(BindingTarget globalObj)
1814 {
1815 JSClass<JSWebAppLinkCallback>::Declare("WebAppLinkCallback");
1816 JSClass<JSWebAppLinkCallback>::CustomMethod("continueLoad", &JSWebAppLinkCallback::ContinueLoad);
1817 JSClass<JSWebAppLinkCallback>::CustomMethod("cancelLoad", &JSWebAppLinkCallback::CancelLoad);
1818 JSClass<JSWebAppLinkCallback>::Bind(
1819 globalObj, &JSWebAppLinkCallback::Constructor, &JSWebAppLinkCallback::Destructor);
1820 }
1821
SetEvent(const WebAppLinkEvent & eventInfo)1822 void SetEvent(const WebAppLinkEvent& eventInfo)
1823 {
1824 callback_ = eventInfo.GetCallback();
1825 }
1826
ContinueLoad(const JSCallbackInfo & args)1827 void ContinueLoad(const JSCallbackInfo& args)
1828 {
1829 if (callback_) {
1830 callback_->ContinueLoad();
1831 }
1832 }
1833
CancelLoad(const JSCallbackInfo & args)1834 void CancelLoad(const JSCallbackInfo& args)
1835 {
1836 if (callback_) {
1837 callback_->CancelLoad();
1838 }
1839 }
1840
1841 private:
Constructor(const JSCallbackInfo & args)1842 static void Constructor(const JSCallbackInfo& args)
1843 {
1844 auto jsWebAppLinkCallback = Referenced::MakeRefPtr<JSWebAppLinkCallback>();
1845 jsWebAppLinkCallback->IncRefCount();
1846 args.SetReturnValue(Referenced::RawPtr(jsWebAppLinkCallback));
1847 }
1848
Destructor(JSWebAppLinkCallback * jsWebAppLinkCallback)1849 static void Destructor(JSWebAppLinkCallback* jsWebAppLinkCallback)
1850 {
1851 if (jsWebAppLinkCallback != nullptr) {
1852 jsWebAppLinkCallback->DecRefCount();
1853 }
1854 }
1855
1856 RefPtr<WebAppLinkCallback> callback_;
1857 };
1858
JSBind(BindingTarget globalObj)1859 void JSWeb::JSBind(BindingTarget globalObj)
1860 {
1861 JSClass<JSWeb>::Declare("Web");
1862 JSClass<JSWeb>::StaticMethod("create", &JSWeb::Create);
1863 JSClass<JSWeb>::StaticMethod("onAlert", &JSWeb::OnAlert);
1864 JSClass<JSWeb>::StaticMethod("onBeforeUnload", &JSWeb::OnBeforeUnload);
1865 JSClass<JSWeb>::StaticMethod("onConfirm", &JSWeb::OnConfirm);
1866 JSClass<JSWeb>::StaticMethod("onPrompt", &JSWeb::OnPrompt);
1867 JSClass<JSWeb>::StaticMethod("onConsole", &JSWeb::OnConsoleLog);
1868 JSClass<JSWeb>::StaticMethod("onFullScreenEnter", &JSWeb::OnFullScreenEnter);
1869 JSClass<JSWeb>::StaticMethod("onFullScreenExit", &JSWeb::OnFullScreenExit);
1870 JSClass<JSWeb>::StaticMethod("onPageBegin", &JSWeb::OnPageStart);
1871 JSClass<JSWeb>::StaticMethod("onPageEnd", &JSWeb::OnPageFinish);
1872 JSClass<JSWeb>::StaticMethod("onProgressChange", &JSWeb::OnProgressChange);
1873 JSClass<JSWeb>::StaticMethod("onTitleReceive", &JSWeb::OnTitleReceive);
1874 JSClass<JSWeb>::StaticMethod("onGeolocationHide", &JSWeb::OnGeolocationHide);
1875 JSClass<JSWeb>::StaticMethod("onGeolocationShow", &JSWeb::OnGeolocationShow);
1876 JSClass<JSWeb>::StaticMethod("onRequestSelected", &JSWeb::OnRequestFocus);
1877 JSClass<JSWeb>::StaticMethod("onShowFileSelector", &JSWeb::OnFileSelectorShow);
1878 JSClass<JSWeb>::StaticMethod("javaScriptAccess", &JSWeb::JsEnabled);
1879 JSClass<JSWeb>::StaticMethod("fileExtendAccess", &JSWeb::ContentAccessEnabled);
1880 JSClass<JSWeb>::StaticMethod("fileAccess", &JSWeb::FileAccessEnabled);
1881 JSClass<JSWeb>::StaticMethod("onDownloadStart", &JSWeb::OnDownloadStart);
1882 JSClass<JSWeb>::StaticMethod("onErrorReceive", &JSWeb::OnErrorReceive);
1883 JSClass<JSWeb>::StaticMethod("onHttpErrorReceive", &JSWeb::OnHttpErrorReceive);
1884 JSClass<JSWeb>::StaticMethod("onInterceptRequest", &JSWeb::OnInterceptRequest);
1885 JSClass<JSWeb>::StaticMethod("onUrlLoadIntercept", &JSWeb::OnUrlLoadIntercept);
1886 JSClass<JSWeb>::StaticMethod("onLoadIntercept", &JSWeb::OnLoadIntercept);
1887 JSClass<JSWeb>::StaticMethod("onlineImageAccess", &JSWeb::OnLineImageAccessEnabled);
1888 JSClass<JSWeb>::StaticMethod("domStorageAccess", &JSWeb::DomStorageAccessEnabled);
1889 JSClass<JSWeb>::StaticMethod("imageAccess", &JSWeb::ImageAccessEnabled);
1890 JSClass<JSWeb>::StaticMethod("mixedMode", &JSWeb::MixedMode);
1891 JSClass<JSWeb>::StaticMethod("enableNativeEmbedMode", &JSWeb::EnableNativeEmbedMode);
1892 JSClass<JSWeb>::StaticMethod("registerNativeEmbedRule", &JSWeb::RegisterNativeEmbedRule);
1893 JSClass<JSWeb>::StaticMethod("zoomAccess", &JSWeb::ZoomAccessEnabled);
1894 JSClass<JSWeb>::StaticMethod("geolocationAccess", &JSWeb::GeolocationAccessEnabled);
1895 JSClass<JSWeb>::StaticMethod("javaScriptProxy", &JSWeb::JavaScriptProxy);
1896 JSClass<JSWeb>::StaticMethod("userAgent", &JSWeb::UserAgent);
1897 JSClass<JSWeb>::StaticMethod("onRenderExited", &JSWeb::OnRenderExited);
1898 JSClass<JSWeb>::StaticMethod("onRefreshAccessedHistory", &JSWeb::OnRefreshAccessedHistory);
1899 JSClass<JSWeb>::StaticMethod("cacheMode", &JSWeb::CacheMode);
1900 JSClass<JSWeb>::StaticMethod("overviewModeAccess", &JSWeb::OverviewModeAccess);
1901 JSClass<JSWeb>::StaticMethod("webDebuggingAccess", &JSWeb::WebDebuggingAccess);
1902 JSClass<JSWeb>::StaticMethod("wideViewModeAccess", &JSWeb::WideViewModeAccess);
1903 JSClass<JSWeb>::StaticMethod("fileFromUrlAccess", &JSWeb::FileFromUrlAccess);
1904 JSClass<JSWeb>::StaticMethod("databaseAccess", &JSWeb::DatabaseAccess);
1905 JSClass<JSWeb>::StaticMethod("textZoomRatio", &JSWeb::TextZoomRatio);
1906 JSClass<JSWeb>::StaticMethod("textZoomAtio", &JSWeb::TextZoomRatio);
1907 JSClass<JSWeb>::StaticMethod("initialScale", &JSWeb::InitialScale);
1908 JSClass<JSWeb>::StaticMethod("backgroundColor", &JSWeb::BackgroundColor);
1909 JSClass<JSWeb>::StaticMethod("onKeyEvent", &JSWeb::OnKeyEvent);
1910 JSClass<JSWeb>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
1911 JSClass<JSWeb>::StaticMethod("onMouse", &JSWeb::OnMouse);
1912 JSClass<JSWeb>::StaticMethod("onResourceLoad", &JSWeb::OnResourceLoad);
1913 JSClass<JSWeb>::StaticMethod("onScaleChange", &JSWeb::OnScaleChange);
1914 JSClass<JSWeb>::StaticMethod("password", &JSWeb::Password);
1915 JSClass<JSWeb>::StaticMethod("tableData", &JSWeb::TableData);
1916 JSClass<JSWeb>::StaticMethod("onFileSelectorShow", &JSWeb::OnFileSelectorShowAbandoned);
1917 JSClass<JSWeb>::StaticMethod("onHttpAuthRequest", &JSWeb::OnHttpAuthRequest);
1918 JSClass<JSWeb>::StaticMethod("onSslErrorReceive", &JSWeb::OnSslErrRequest);
1919 JSClass<JSWeb>::StaticMethod("onSslErrorEventReceive", &JSWeb::OnSslErrorRequest);
1920 JSClass<JSWeb>::StaticMethod("onSslErrorEvent", &JSWeb::OnAllSslErrorRequest);
1921 JSClass<JSWeb>::StaticMethod("onClientAuthenticationRequest", &JSWeb::OnSslSelectCertRequest);
1922 JSClass<JSWeb>::StaticMethod("onPermissionRequest", &JSWeb::OnPermissionRequest);
1923 JSClass<JSWeb>::StaticMethod("onContextMenuShow", &JSWeb::OnContextMenuShow);
1924 JSClass<JSWeb>::StaticMethod("onContextMenuHide", &JSWeb::OnContextMenuHide);
1925 JSClass<JSWeb>::StaticMethod("onSearchResultReceive", &JSWeb::OnSearchResultReceive);
1926 JSClass<JSWeb>::StaticMethod("mediaPlayGestureAccess", &JSWeb::MediaPlayGestureAccess);
1927 JSClass<JSWeb>::StaticMethod("onDragStart", &JSWeb::JsOnDragStart);
1928 JSClass<JSWeb>::StaticMethod("onDragEnter", &JSWeb::JsOnDragEnter);
1929 JSClass<JSWeb>::StaticMethod("onDragMove", &JSWeb::JsOnDragMove);
1930 JSClass<JSWeb>::StaticMethod("onDragLeave", &JSWeb::JsOnDragLeave);
1931 JSClass<JSWeb>::StaticMethod("onDrop", &JSWeb::JsOnDrop);
1932 JSClass<JSWeb>::StaticMethod("onScroll", &JSWeb::OnScroll);
1933 JSClass<JSWeb>::StaticMethod("rotate", &JSWeb::WebRotate);
1934 JSClass<JSWeb>::StaticMethod("pinchSmooth", &JSWeb::PinchSmoothModeEnabled);
1935 JSClass<JSWeb>::StaticMethod("onAttach", &JSInteractableView::JsOnAttach);
1936 JSClass<JSWeb>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
1937 JSClass<JSWeb>::StaticMethod("onDetach", &JSInteractableView::JsOnDetach);
1938 JSClass<JSWeb>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
1939 JSClass<JSWeb>::StaticMethod("onWindowNew", &JSWeb::OnWindowNew);
1940 JSClass<JSWeb>::StaticMethod("onWindowExit", &JSWeb::OnWindowExit);
1941 JSClass<JSWeb>::StaticMethod("multiWindowAccess", &JSWeb::MultiWindowAccessEnabled);
1942 JSClass<JSWeb>::StaticMethod("allowWindowOpenMethod", &JSWeb::AllowWindowOpenMethod);
1943 JSClass<JSWeb>::StaticMethod("webCursiveFont", &JSWeb::WebCursiveFont);
1944 JSClass<JSWeb>::StaticMethod("webFantasyFont", &JSWeb::WebFantasyFont);
1945 JSClass<JSWeb>::StaticMethod("webFixedFont", &JSWeb::WebFixedFont);
1946 JSClass<JSWeb>::StaticMethod("webSansSerifFont", &JSWeb::WebSansSerifFont);
1947 JSClass<JSWeb>::StaticMethod("webSerifFont", &JSWeb::WebSerifFont);
1948 JSClass<JSWeb>::StaticMethod("webStandardFont", &JSWeb::WebStandardFont);
1949 JSClass<JSWeb>::StaticMethod("defaultFixedFontSize", &JSWeb::DefaultFixedFontSize);
1950 JSClass<JSWeb>::StaticMethod("defaultFontSize", &JSWeb::DefaultFontSize);
1951 JSClass<JSWeb>::StaticMethod("defaultTextEncodingFormat", &JSWeb::DefaultTextEncodingFormat);
1952 JSClass<JSWeb>::StaticMethod("minFontSize", &JSWeb::MinFontSize);
1953 JSClass<JSWeb>::StaticMethod("minLogicalFontSize", &JSWeb::MinLogicalFontSize);
1954 JSClass<JSWeb>::StaticMethod("blockNetwork", &JSWeb::BlockNetwork);
1955 JSClass<JSWeb>::StaticMethod("onPageVisible", &JSWeb::OnPageVisible);
1956 JSClass<JSWeb>::StaticMethod("onInterceptKeyEvent", &JSWeb::OnInterceptKeyEvent);
1957 JSClass<JSWeb>::StaticMethod("onDataResubmitted", &JSWeb::OnDataResubmitted);
1958 JSClass<JSWeb>::StaticMethod("onFaviconReceived", &JSWeb::OnFaviconReceived);
1959 JSClass<JSWeb>::StaticMethod("onTouchIconUrlReceived", &JSWeb::OnTouchIconUrlReceived);
1960 JSClass<JSWeb>::StaticMethod("darkMode", &JSWeb::DarkMode);
1961 JSClass<JSWeb>::StaticMethod("forceDarkAccess", &JSWeb::ForceDarkAccess);
1962 JSClass<JSWeb>::StaticMethod("overScrollMode", &JSWeb::OverScrollMode);
1963 JSClass<JSWeb>::StaticMethod("horizontalScrollBarAccess", &JSWeb::HorizontalScrollBarAccess);
1964 JSClass<JSWeb>::StaticMethod("verticalScrollBarAccess", &JSWeb::VerticalScrollBarAccess);
1965 JSClass<JSWeb>::StaticMethod("onAudioStateChanged", &JSWeb::OnAudioStateChanged);
1966 JSClass<JSWeb>::StaticMethod("mediaOptions", &JSWeb::MediaOptions);
1967 JSClass<JSWeb>::StaticMethod("onFirstContentfulPaint", &JSWeb::OnFirstContentfulPaint);
1968 JSClass<JSWeb>::StaticMethod("onFirstMeaningfulPaint", &JSWeb::OnFirstMeaningfulPaint);
1969 JSClass<JSWeb>::StaticMethod("onLargestContentfulPaint", &JSWeb::OnLargestContentfulPaint);
1970 JSClass<JSWeb>::StaticMethod("onSafeBrowsingCheckResult", &JSWeb::OnSafeBrowsingCheckResult);
1971 JSClass<JSWeb>::StaticMethod("onNavigationEntryCommitted", &JSWeb::OnNavigationEntryCommitted);
1972 JSClass<JSWeb>::StaticMethod("onIntelligentTrackingPreventionResult",
1973 &JSWeb::OnIntelligentTrackingPreventionResult);
1974 JSClass<JSWeb>::StaticMethod("onControllerAttached", &JSWeb::OnControllerAttached);
1975 JSClass<JSWeb>::StaticMethod("onOverScroll", &JSWeb::OnOverScroll);
1976 JSClass<JSWeb>::StaticMethod("onNativeEmbedLifecycleChange", &JSWeb::OnNativeEmbedLifecycleChange);
1977 JSClass<JSWeb>::StaticMethod("onNativeEmbedVisibilityChange", &JSWeb::OnNativeEmbedVisibilityChange);
1978 JSClass<JSWeb>::StaticMethod("onNativeEmbedGestureEvent", &JSWeb::OnNativeEmbedGestureEvent);
1979 JSClass<JSWeb>::StaticMethod("copyOptions", &JSWeb::CopyOption);
1980 JSClass<JSWeb>::StaticMethod("onScreenCaptureRequest", &JSWeb::OnScreenCaptureRequest);
1981 JSClass<JSWeb>::StaticMethod("layoutMode", &JSWeb::SetLayoutMode);
1982 JSClass<JSWeb>::StaticMethod("nestedScroll", &JSWeb::SetNestedScroll);
1983 JSClass<JSWeb>::StaticMethod("metaViewport", &JSWeb::SetMetaViewport);
1984 JSClass<JSWeb>::StaticMethod("javaScriptOnDocumentStart", &JSWeb::JavaScriptOnDocumentStart);
1985 JSClass<JSWeb>::StaticMethod("javaScriptOnDocumentEnd", &JSWeb::JavaScriptOnDocumentEnd);
1986 JSClass<JSWeb>::StaticMethod("onOverrideUrlLoading", &JSWeb::OnOverrideUrlLoading);
1987 JSClass<JSWeb>::StaticMethod("textAutosizing", &JSWeb::TextAutosizing);
1988 JSClass<JSWeb>::StaticMethod("enableNativeMediaPlayer", &JSWeb::EnableNativeVideoPlayer);
1989 JSClass<JSWeb>::StaticMethod("onRenderProcessNotResponding", &JSWeb::OnRenderProcessNotResponding);
1990 JSClass<JSWeb>::StaticMethod("onRenderProcessResponding", &JSWeb::OnRenderProcessResponding);
1991 JSClass<JSWeb>::StaticMethod("onViewportFitChanged", &JSWeb::OnViewportFitChanged);
1992 JSClass<JSWeb>::StaticMethod("selectionMenuOptions", &JSWeb::SelectionMenuOptions);
1993 JSClass<JSWeb>::StaticMethod("onAdsBlocked", &JSWeb::OnAdsBlocked);
1994 JSClass<JSWeb>::StaticMethod("onInterceptKeyboardAttach", &JSWeb::OnInterceptKeyboardAttach);
1995 JSClass<JSWeb>::StaticMethod("forceDisplayScrollBar", &JSWeb::ForceDisplayScrollBar);
1996 JSClass<JSWeb>::StaticMethod("keyboardAvoidMode", &JSWeb::KeyboardAvoidMode);
1997 JSClass<JSWeb>::StaticMethod("editMenuOptions", &JSWeb::EditMenuOptions);
1998 JSClass<JSWeb>::StaticMethod("enableHapticFeedback", &JSWeb::EnableHapticFeedback);
1999 JSClass<JSWeb>::StaticMethod("bindSelectionMenu", &JSWeb::BindSelectionMenu);
2000
2001 JSClass<JSWeb>::InheritAndBind<JSViewAbstract>(globalObj);
2002 JSWebDialog::JSBind(globalObj);
2003 JSWebGeolocation::JSBind(globalObj);
2004 JSWebResourceRequest::JSBind(globalObj);
2005 JSWebResourceError::JSBind(globalObj);
2006 JSWebResourceResponse::JSBind(globalObj);
2007 JSWebConsoleLog::JSBind(globalObj);
2008 JSFileSelectorParam::JSBind(globalObj);
2009 JSFileSelectorResult::JSBind(globalObj);
2010 JSFullScreenExitHandler::JSBind(globalObj);
2011 JSWebHttpAuth::JSBind(globalObj);
2012 JSWebSslError::JSBind(globalObj);
2013 JSWebAllSslError::JSBind(globalObj);
2014 JSWebSslSelectCert::JSBind(globalObj);
2015 JSWebPermissionRequest::JSBind(globalObj);
2016 JSContextMenuParam::JSBind(globalObj);
2017 JSContextMenuResult::JSBind(globalObj);
2018 JSWebWindowNewHandler::JSBind(globalObj);
2019 JSDataResubmitted::JSBind(globalObj);
2020 JSScreenCaptureRequest::JSBind(globalObj);
2021 JSNativeEmbedGestureRequest::JSBind(globalObj);
2022 JSWebAppLinkCallback::JSBind(globalObj);
2023 JSWebKeyboardController::JSBind(globalObj);
2024 }
2025
LoadWebConsoleLogEventToJSValue(const LoadWebConsoleLogEvent & eventInfo)2026 JSRef<JSVal> LoadWebConsoleLogEventToJSValue(const LoadWebConsoleLogEvent& eventInfo)
2027 {
2028 JSRef<JSObject> obj = JSRef<JSObject>::New();
2029
2030 JSRef<JSObject> messageObj = JSClass<JSWebConsoleLog>::NewInstance();
2031 auto jsWebConsoleLog = Referenced::Claim(messageObj->Unwrap<JSWebConsoleLog>());
2032 jsWebConsoleLog->SetMessage(eventInfo.GetMessage());
2033
2034 obj->SetPropertyObject("message", messageObj);
2035
2036 return JSRef<JSVal>::Cast(obj);
2037 }
2038
WebDialogEventToJSValue(const WebDialogEvent & eventInfo)2039 JSRef<JSVal> WebDialogEventToJSValue(const WebDialogEvent& eventInfo)
2040 {
2041 JSRef<JSObject> obj = JSRef<JSObject>::New();
2042
2043 JSRef<JSObject> resultObj = JSClass<JSWebDialog>::NewInstance();
2044 auto jsWebDialog = Referenced::Claim(resultObj->Unwrap<JSWebDialog>());
2045 jsWebDialog->SetResult(eventInfo.GetResult());
2046
2047 obj->SetProperty("url", eventInfo.GetUrl());
2048 obj->SetProperty("message", eventInfo.GetMessage());
2049 if (eventInfo.GetType() == DialogEventType::DIALOG_EVENT_PROMPT) {
2050 obj->SetProperty("value", eventInfo.GetValue());
2051 }
2052 obj->SetPropertyObject("result", resultObj);
2053
2054 return JSRef<JSVal>::Cast(obj);
2055 }
2056
LoadWebPageFinishEventToJSValue(const LoadWebPageFinishEvent & eventInfo)2057 JSRef<JSVal> LoadWebPageFinishEventToJSValue(const LoadWebPageFinishEvent& eventInfo)
2058 {
2059 JSRef<JSObject> obj = JSRef<JSObject>::New();
2060 obj->SetProperty("url", eventInfo.GetLoadedUrl());
2061 return JSRef<JSVal>::Cast(obj);
2062 }
2063
ContextMenuHideEventToJSValue(const ContextMenuHideEvent & eventInfo)2064 JSRef<JSVal> ContextMenuHideEventToJSValue(const ContextMenuHideEvent& eventInfo)
2065 {
2066 JSRef<JSObject> obj = JSRef<JSObject>::New();
2067 obj->SetProperty("info", eventInfo.GetInfo());
2068 return JSRef<JSVal>::Cast(obj);
2069 }
2070
FullScreenEnterEventToJSValue(const FullScreenEnterEvent & eventInfo)2071 JSRef<JSVal> FullScreenEnterEventToJSValue(const FullScreenEnterEvent& eventInfo)
2072 {
2073 JSRef<JSObject> obj = JSRef<JSObject>::New();
2074 JSRef<JSObject> resultObj = JSClass<JSFullScreenExitHandler>::NewInstance();
2075 auto jsFullScreenExitHandler = Referenced::Claim(resultObj->Unwrap<JSFullScreenExitHandler>());
2076 if (!jsFullScreenExitHandler) {
2077 return JSRef<JSVal>::Cast(obj);
2078 }
2079 jsFullScreenExitHandler->SetHandler(eventInfo.GetHandler());
2080
2081 obj->SetPropertyObject("handler", resultObj);
2082 obj->SetProperty("videoWidth", eventInfo.GetVideoNaturalWidth());
2083 obj->SetProperty("videoHeight", eventInfo.GetVideoNaturalHeight());
2084 return JSRef<JSVal>::Cast(obj);
2085 }
2086
FullScreenExitEventToJSValue(const FullScreenExitEvent & eventInfo)2087 JSRef<JSVal> FullScreenExitEventToJSValue(const FullScreenExitEvent& eventInfo)
2088 {
2089 return JSRef<JSVal>::Make(ToJSValue(eventInfo.IsFullScreen()));
2090 }
2091
LoadWebPageStartEventToJSValue(const LoadWebPageStartEvent & eventInfo)2092 JSRef<JSVal> LoadWebPageStartEventToJSValue(const LoadWebPageStartEvent& eventInfo)
2093 {
2094 JSRef<JSObject> obj = JSRef<JSObject>::New();
2095 obj->SetProperty("url", eventInfo.GetLoadedUrl());
2096 return JSRef<JSVal>::Cast(obj);
2097 }
2098
LoadWebProgressChangeEventToJSValue(const LoadWebProgressChangeEvent & eventInfo)2099 JSRef<JSVal> LoadWebProgressChangeEventToJSValue(const LoadWebProgressChangeEvent& eventInfo)
2100 {
2101 JSRef<JSObject> obj = JSRef<JSObject>::New();
2102 obj->SetProperty("newProgress", eventInfo.GetNewProgress());
2103 return JSRef<JSVal>::Cast(obj);
2104 }
2105
LoadWebTitleReceiveEventToJSValue(const LoadWebTitleReceiveEvent & eventInfo)2106 JSRef<JSVal> LoadWebTitleReceiveEventToJSValue(const LoadWebTitleReceiveEvent& eventInfo)
2107 {
2108 JSRef<JSObject> obj = JSRef<JSObject>::New();
2109 obj->SetProperty("title", eventInfo.GetTitle());
2110 return JSRef<JSVal>::Cast(obj);
2111 }
2112
UrlLoadInterceptEventToJSValue(const UrlLoadInterceptEvent & eventInfo)2113 JSRef<JSVal> UrlLoadInterceptEventToJSValue(const UrlLoadInterceptEvent& eventInfo)
2114 {
2115 JSRef<JSObject> obj = JSRef<JSObject>::New();
2116 obj->SetProperty("data", eventInfo.GetData());
2117 return JSRef<JSVal>::Cast(obj);
2118 }
2119
LoadInterceptEventToJSValue(const LoadInterceptEvent & eventInfo)2120 JSRef<JSVal> LoadInterceptEventToJSValue(const LoadInterceptEvent& eventInfo)
2121 {
2122 JSRef<JSObject> obj = JSRef<JSObject>::New();
2123 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
2124 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
2125 requestEvent->SetLoadInterceptEvent(eventInfo);
2126 obj->SetPropertyObject("data", requestObj);
2127 return JSRef<JSVal>::Cast(obj);
2128 }
2129
LoadWebGeolocationHideEventToJSValue(const LoadWebGeolocationHideEvent & eventInfo)2130 JSRef<JSVal> LoadWebGeolocationHideEventToJSValue(const LoadWebGeolocationHideEvent& eventInfo)
2131 {
2132 return JSRef<JSVal>::Make(ToJSValue(eventInfo.GetOrigin()));
2133 }
2134
LoadWebGeolocationShowEventToJSValue(const LoadWebGeolocationShowEvent & eventInfo)2135 JSRef<JSVal> LoadWebGeolocationShowEventToJSValue(const LoadWebGeolocationShowEvent& eventInfo)
2136 {
2137 JSRef<JSObject> obj = JSRef<JSObject>::New();
2138 obj->SetProperty("origin", eventInfo.GetOrigin());
2139 JSRef<JSObject> geolocationObj = JSClass<JSWebGeolocation>::NewInstance();
2140 auto geolocationEvent = Referenced::Claim(geolocationObj->Unwrap<JSWebGeolocation>());
2141 geolocationEvent->SetEvent(eventInfo);
2142 obj->SetPropertyObject("geolocation", geolocationObj);
2143 return JSRef<JSVal>::Cast(obj);
2144 }
2145
DownloadStartEventToJSValue(const DownloadStartEvent & eventInfo)2146 JSRef<JSVal> DownloadStartEventToJSValue(const DownloadStartEvent& eventInfo)
2147 {
2148 JSRef<JSObject> obj = JSRef<JSObject>::New();
2149 obj->SetProperty("url", eventInfo.GetUrl());
2150 obj->SetProperty("userAgent", eventInfo.GetUserAgent());
2151 obj->SetProperty("contentDisposition", eventInfo.GetContentDisposition());
2152 obj->SetProperty("mimetype", eventInfo.GetMimetype());
2153 obj->SetProperty("contentLength", eventInfo.GetContentLength());
2154 return JSRef<JSVal>::Cast(obj);
2155 }
2156
LoadWebRequestFocusEventToJSValue(const LoadWebRequestFocusEvent & eventInfo)2157 JSRef<JSVal> LoadWebRequestFocusEventToJSValue(const LoadWebRequestFocusEvent& eventInfo)
2158 {
2159 return JSRef<JSVal>::Make(ToJSValue(eventInfo.GetRequestFocus()));
2160 }
2161
WebHttpAuthEventToJSValue(const WebHttpAuthEvent & eventInfo)2162 JSRef<JSVal> WebHttpAuthEventToJSValue(const WebHttpAuthEvent& eventInfo)
2163 {
2164 JSRef<JSObject> obj = JSRef<JSObject>::New();
2165 JSRef<JSObject> resultObj = JSClass<JSWebHttpAuth>::NewInstance();
2166 auto jsWebHttpAuth = Referenced::Claim(resultObj->Unwrap<JSWebHttpAuth>());
2167 if (!jsWebHttpAuth) {
2168 return JSRef<JSVal>::Cast(obj);
2169 }
2170 jsWebHttpAuth->SetResult(eventInfo.GetResult());
2171 obj->SetPropertyObject("handler", resultObj);
2172 obj->SetProperty("host", eventInfo.GetHost());
2173 obj->SetProperty("realm", eventInfo.GetRealm());
2174 return JSRef<JSVal>::Cast(obj);
2175 }
2176
WebSslErrorEventToJSValue(const WebSslErrorEvent & eventInfo)2177 JSRef<JSVal> WebSslErrorEventToJSValue(const WebSslErrorEvent& eventInfo)
2178 {
2179 JSRef<JSObject> obj = JSRef<JSObject>::New();
2180 JSRef<JSObject> resultObj = JSClass<JSWebSslError>::NewInstance();
2181 auto jsWebSslError = Referenced::Claim(resultObj->Unwrap<JSWebSslError>());
2182 if (!jsWebSslError) {
2183 return JSRef<JSVal>::Cast(obj);
2184 }
2185 jsWebSslError->SetResult(eventInfo.GetResult());
2186 obj->SetPropertyObject("handler", resultObj);
2187 obj->SetProperty("error", eventInfo.GetError());
2188 return JSRef<JSVal>::Cast(obj);
2189 }
2190
WebAllSslErrorEventToJSValue(const WebAllSslErrorEvent & eventInfo)2191 JSRef<JSVal> WebAllSslErrorEventToJSValue(const WebAllSslErrorEvent& eventInfo)
2192 {
2193 JSRef<JSObject> obj = JSRef<JSObject>::New();
2194 JSRef<JSObject> resultObj = JSClass<JSWebAllSslError>::NewInstance();
2195 auto jsWebAllSslError = Referenced::Claim(resultObj->Unwrap<JSWebAllSslError>());
2196 if (!jsWebAllSslError) {
2197 return JSRef<JSVal>::Cast(obj);
2198 }
2199 jsWebAllSslError->SetResult(eventInfo.GetResult());
2200 obj->SetPropertyObject("handler", resultObj);
2201 obj->SetProperty("error", eventInfo.GetError());
2202 obj->SetProperty("url", eventInfo.GetUrl());
2203 obj->SetProperty("originalUrl", eventInfo.GetOriginalUrl());
2204 obj->SetProperty("referrer", eventInfo.GetReferrer());
2205 obj->SetProperty("isFatalError", eventInfo.GetIsFatalError());
2206 obj->SetProperty("isMainFrame", eventInfo.GetIsMainFrame());
2207 return JSRef<JSVal>::Cast(obj);
2208 }
2209
WebSslSelectCertEventToJSValue(const WebSslSelectCertEvent & eventInfo)2210 JSRef<JSVal> WebSslSelectCertEventToJSValue(const WebSslSelectCertEvent& eventInfo)
2211 {
2212 JSRef<JSObject> obj = JSRef<JSObject>::New();
2213 JSRef<JSObject> resultObj = JSClass<JSWebSslSelectCert>::NewInstance();
2214 auto jsWebSslSelectCert = Referenced::Claim(resultObj->Unwrap<JSWebSslSelectCert>());
2215 if (!jsWebSslSelectCert) {
2216 return JSRef<JSVal>::Cast(obj);
2217 }
2218 jsWebSslSelectCert->SetResult(eventInfo.GetResult());
2219 obj->SetPropertyObject("handler", resultObj);
2220 obj->SetProperty("host", eventInfo.GetHost());
2221 obj->SetProperty("port", eventInfo.GetPort());
2222
2223 JSRef<JSArray> keyTypesArr = JSRef<JSArray>::New();
2224 const std::vector<std::string>& keyTypes = eventInfo.GetKeyTypes();
2225 for (int32_t idx = 0; idx < static_cast<int32_t>(keyTypes.size()); ++idx) {
2226 JSRef<JSVal> keyType = JSRef<JSVal>::Make(ToJSValue(keyTypes[idx]));
2227 keyTypesArr->SetValueAt(idx, keyType);
2228 }
2229 obj->SetPropertyObject("keyTypes", keyTypesArr);
2230
2231 JSRef<JSArray> issuersArr = JSRef<JSArray>::New();
2232 const std::vector<std::string>& issuers = eventInfo.GetIssuers_();
2233 for (int32_t idx = 0; idx < static_cast<int32_t>(issuers.size()); ++idx) {
2234 JSRef<JSVal> issuer = JSRef<JSVal>::Make(ToJSValue(issuers[idx]));
2235 issuersArr->SetValueAt(idx, issuer);
2236 }
2237
2238 obj->SetPropertyObject("issuers", issuersArr);
2239
2240 return JSRef<JSVal>::Cast(obj);
2241 }
2242
SearchResultReceiveEventToJSValue(const SearchResultReceiveEvent & eventInfo)2243 JSRef<JSVal> SearchResultReceiveEventToJSValue(const SearchResultReceiveEvent& eventInfo)
2244 {
2245 JSRef<JSObject> obj = JSRef<JSObject>::New();
2246 obj->SetProperty("activeMatchOrdinal", eventInfo.GetActiveMatchOrdinal());
2247 obj->SetProperty("numberOfMatches", eventInfo.GetNumberOfMatches());
2248 obj->SetProperty("isDoneCounting", eventInfo.GetIsDoneCounting());
2249 return JSRef<JSVal>::Cast(obj);
2250 }
2251
LoadOverrideEventToJSValue(const LoadOverrideEvent & eventInfo)2252 JSRef<JSVal> LoadOverrideEventToJSValue(const LoadOverrideEvent& eventInfo)
2253 {
2254 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
2255 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
2256 requestEvent->SetLoadOverrideEvent(eventInfo);
2257 return JSRef<JSVal>::Cast(requestObj);
2258 }
2259
AdsBlockedEventToJSValue(const AdsBlockedEvent & eventInfo)2260 JSRef<JSVal> AdsBlockedEventToJSValue(const AdsBlockedEvent& eventInfo)
2261 {
2262 JSRef<JSObject> obj = JSRef<JSObject>::New();
2263 obj->SetProperty("url", eventInfo.GetUrl());
2264
2265 JSRef<JSArray> adsBlockedArr = JSRef<JSArray>::New();
2266 const std::vector<std::string>& adsBlocked = eventInfo.GetAdsBlocked();
2267 for (int32_t idx = 0; idx < static_cast<int32_t>(adsBlocked.size()); ++idx) {
2268 JSRef<JSVal> blockedUrl = JSRef<JSVal>::Make(ToJSValue(adsBlocked[idx]));
2269 adsBlockedArr->SetValueAt(idx, blockedUrl);
2270 }
2271 obj->SetPropertyObject("adsBlocked", adsBlockedArr);
2272
2273 return JSRef<JSVal>::Cast(obj);
2274 }
2275
ParseRawfileWebSrc(const JSRef<JSVal> & srcValue,std::string & webSrc)2276 void JSWeb::ParseRawfileWebSrc(const JSRef<JSVal>& srcValue, std::string& webSrc)
2277 {
2278 if (!srcValue->IsObject() || webSrc.substr(0, RAWFILE_PREFIX.size()) != RAWFILE_PREFIX) {
2279 return;
2280 }
2281 std::string bundleName;
2282 std::string moduleName;
2283 GetJsMediaBundleInfo(srcValue, bundleName, moduleName);
2284 auto container = Container::Current();
2285 CHECK_NULL_VOID(container);
2286 if ((!bundleName.empty() && !moduleName.empty()) &&
2287 (bundleName != AceApplicationInfo::GetInstance().GetPackageName() ||
2288 moduleName != container->GetModuleName())) {
2289 webSrc = RAWFILE_PREFIX + BUNDLE_NAME_PREFIX + bundleName + "/" + MODULE_NAME_PREFIX + moduleName + "/" +
2290 webSrc.substr(RAWFILE_PREFIX.size());
2291 }
2292 }
2293
Create(const JSCallbackInfo & info)2294 void JSWeb::Create(const JSCallbackInfo& info)
2295 {
2296 if (info.Length() < 1 || !info[0]->IsObject()) {
2297 return;
2298 }
2299 auto paramObject = JSRef<JSObject>::Cast(info[0]);
2300 JSRef<JSVal> srcValue = paramObject->GetProperty("src");
2301 std::string webSrc;
2302 std::optional<std::string> dstSrc;
2303 if (srcValue->IsString()) {
2304 dstSrc = srcValue->ToString();
2305 } else if (ParseJsMedia(srcValue, webSrc)) {
2306 ParseRawfileWebSrc(srcValue, webSrc);
2307 int np = static_cast<int>(webSrc.find_first_of("/"));
2308 dstSrc = np < 0 ? webSrc : webSrc.erase(np, 1);
2309 }
2310 if (!dstSrc) {
2311 return;
2312 }
2313 auto controllerObj = paramObject->GetProperty("controller");
2314 if (!controllerObj->IsObject()) {
2315 return;
2316 }
2317 JsiRef<JsiValue> type = JsiRef<JsiValue>::Make();
2318 bool isHasType = paramObject->HasProperty("type");
2319 if (isHasType) {
2320 type = paramObject->GetProperty("type");
2321 } else {
2322 type = paramObject->GetProperty("renderMode");
2323 }
2324 RenderMode renderMode = RenderMode::ASYNC_RENDER;
2325 if (type->IsNumber() && (type->ToNumber<int32_t>() >= 0) && (type->ToNumber<int32_t>() <= 1)) {
2326 renderMode = static_cast<RenderMode>(type->ToNumber<int32_t>());
2327 }
2328
2329 bool incognitoMode = false;
2330 ParseJsBool(paramObject->GetProperty("incognitoMode"), incognitoMode);
2331
2332 std::string sharedRenderProcessToken = "";
2333 ParseJsString(paramObject->GetProperty("sharedRenderProcessToken"), sharedRenderProcessToken);
2334
2335 auto controller = JSRef<JSObject>::Cast(controllerObj);
2336 auto setWebIdFunction = controller->GetProperty("setWebId");
2337 if (setWebIdFunction->IsFunction()) {
2338 auto setIdCallback = [webviewController = controller, func = JSRef<JSFunc>::Cast(setWebIdFunction)](
2339 int32_t webId) {
2340 JSRef<JSVal> argv[] = { JSRef<JSVal>::Make(ToJSValue(webId)) };
2341 func->Call(webviewController, 1, argv);
2342 };
2343
2344 auto setHapPathFunction = controller->GetProperty("innerSetHapPath");
2345 std::function<void(const std::string&)> setHapPathCallback = nullptr;
2346 if (setHapPathFunction->IsFunction()) {
2347 setHapPathCallback = [webviewController = controller, func = JSRef<JSFunc>::Cast(setHapPathFunction)](
2348 const std::string& hapPath) {
2349 JSRef<JSVal> argv[] = { JSRef<JSVal>::Make(ToJSValue(hapPath)) };
2350 func->Call(webviewController, 1, argv);
2351 };
2352 }
2353
2354 auto setRequestPermissionsFromUserFunction = controller->GetProperty("requestPermissionsFromUserWeb");
2355 std::function<void(const std::shared_ptr<BaseEventInfo>&)> requestPermissionsFromUserCallback = nullptr;
2356 if (setRequestPermissionsFromUserFunction->IsFunction()) {
2357 requestPermissionsFromUserCallback = [webviewController = controller,
2358 func = JSRef<JSFunc>::Cast(setRequestPermissionsFromUserFunction)]
2359 (const std::shared_ptr<BaseEventInfo>& info) {
2360 auto* eventInfo = TypeInfoHelper::DynamicCast<WebPermissionRequestEvent>(info.get());
2361 JSRef<JSObject> obj = JSRef<JSObject>::New();
2362 JSRef<JSObject> permissionObj = JSClass<JSWebPermissionRequest>::NewInstance();
2363 auto permissionEvent = Referenced::Claim(permissionObj->Unwrap<JSWebPermissionRequest>());
2364 permissionEvent->SetEvent(*eventInfo);
2365 obj->SetPropertyObject("request", permissionObj);
2366 JSRef<JSVal> argv[] = { JSRef<JSVal>::Cast(obj) };
2367 auto result = func->Call(webviewController, 1, argv);
2368 };
2369 }
2370
2371 auto setOpenAppLinkFunction = controller->GetProperty("openAppLink");
2372 std::function<void(const std::shared_ptr<BaseEventInfo>&)> openAppLinkCallback = nullptr;
2373 if (setOpenAppLinkFunction->IsFunction()) {
2374 TAG_LOGI(AceLogTag::ACE_WEB, "WebDelegate::OnOpenAppLink setOpenAppLinkFunction 2");
2375 openAppLinkCallback = [webviewController = controller,
2376 func = JSRef<JSFunc>::Cast(setOpenAppLinkFunction)]
2377 (const std::shared_ptr<BaseEventInfo>& info) {
2378 auto* eventInfo = TypeInfoHelper::DynamicCast<WebAppLinkEvent>(info.get());
2379 JSRef<JSObject> obj = JSRef<JSObject>::New();
2380 JSRef<JSObject> callbackObj = JSClass<JSWebAppLinkCallback>::NewInstance();
2381 auto callbackEvent = Referenced::Claim(callbackObj->Unwrap<JSWebAppLinkCallback>());
2382 callbackEvent->SetEvent(*eventInfo);
2383 obj->SetPropertyObject("result", callbackObj);
2384 JSRef<JSVal> urlVal = JSRef<JSVal>::Make(ToJSValue(eventInfo->GetUrl()));
2385 obj->SetPropertyObject("url", urlVal);
2386 JSRef<JSVal> argv[] = { JSRef<JSVal>::Cast(obj) };
2387 auto result = func->Call(webviewController, 1, argv);
2388 };
2389 }
2390
2391 auto fileSelectorShowFromUserFunction = controller->GetProperty("fileSelectorShowFromUserWeb");
2392 std::function<void(const std::shared_ptr<BaseEventInfo>&)> fileSelectorShowFromUserCallback = nullptr;
2393 if (fileSelectorShowFromUserFunction->IsFunction()) {
2394 fileSelectorShowFromUserCallback = [webviewController = controller,
2395 func = JSRef<JSFunc>::Cast(fileSelectorShowFromUserFunction)]
2396 (const std::shared_ptr<BaseEventInfo>& info) {
2397 auto* eventInfo = TypeInfoHelper::DynamicCast<FileSelectorEvent>(info.get());
2398 JSRef<JSObject> obj = JSRef<JSObject>::New();
2399 JSRef<JSObject> paramObj = JSClass<JSFileSelectorParam>::NewInstance();
2400 auto fileSelectorParam = Referenced::Claim(paramObj->Unwrap<JSFileSelectorParam>());
2401 fileSelectorParam->SetParam(*eventInfo);
2402 obj->SetPropertyObject("fileparam", paramObj);
2403
2404 JSRef<JSObject> resultObj = JSClass<JSFileSelectorResult>::NewInstance();
2405 auto fileSelectorResult = Referenced::Claim(resultObj->Unwrap<JSFileSelectorResult>());
2406
2407 fileSelectorResult->SetResult(*eventInfo);
2408
2409 obj->SetPropertyObject("fileresult", resultObj);
2410 JSRef<JSVal> argv[] = { JSRef<JSVal>::Cast(obj) };
2411 auto result = func->Call(webviewController, 1, argv);
2412 };
2413 }
2414
2415 int32_t parentNWebId = -1;
2416 bool isPopup = JSWebWindowNewHandler::ExistController(controller, parentNWebId);
2417 WebModel::GetInstance()->Create(isPopup ? "" : dstSrc.value(), std::move(setIdCallback),
2418 std::move(setHapPathCallback), parentNWebId, isPopup, renderMode, incognitoMode, sharedRenderProcessToken);
2419
2420 WebModel::GetInstance()->SetDefaultFileSelectorShow(std::move(fileSelectorShowFromUserCallback));
2421 WebModel::GetInstance()->SetPermissionClipboard(std::move(requestPermissionsFromUserCallback));
2422 WebModel::GetInstance()->SetOpenAppLinkFunction(std::move(openAppLinkCallback));
2423 auto getCmdLineFunction = controller->GetProperty("getCustomeSchemeCmdLine");
2424 if (!getCmdLineFunction->IsFunction()) {
2425 return;
2426 }
2427 std::string cmdLine = JSRef<JSFunc>::Cast(getCmdLineFunction)->Call(controller, 0, {})->ToString();
2428 if (!cmdLine.empty()) {
2429 WebModel::GetInstance()->SetCustomScheme(cmdLine);
2430 }
2431
2432 auto updateInstanceIdFunction = controller->GetProperty("updateInstanceId");
2433 if (updateInstanceIdFunction->IsFunction()) {
2434 std::function<void(int32_t)> updateInstanceIdCallback = [webviewController = controller,
2435 func = JSRef<JSFunc>::Cast(updateInstanceIdFunction)](int32_t newId) {
2436 auto newIdVal = JSRef<JSVal>::Make(ToJSValue(newId));
2437 auto result = func->Call(webviewController, 1, &newIdVal);
2438 };
2439 NG::WebModelNG::GetInstance()->SetUpdateInstanceIdCallback(std::move(updateInstanceIdCallback));
2440 }
2441
2442 auto getWebDebugingFunction = controller->GetProperty("getWebDebuggingAccess");
2443 if (!getWebDebugingFunction->IsFunction()) {
2444 return;
2445 }
2446 bool webDebuggingAccess = JSRef<JSFunc>::Cast(getWebDebugingFunction)->Call(controller, 0, {})->ToBoolean();
2447 if (webDebuggingAccess == JSWeb::webDebuggingAccess_) {
2448 return;
2449 }
2450 WebModel::GetInstance()->SetWebDebuggingAccessEnabled(webDebuggingAccess);
2451 JSWeb::webDebuggingAccess_ = webDebuggingAccess;
2452 return;
2453
2454 } else {
2455 auto* jsWebController = controller->Unwrap<JSWebController>();
2456 CHECK_NULL_VOID(jsWebController);
2457 WebModel::GetInstance()->Create(
2458 dstSrc.value(), jsWebController->GetController(), renderMode, incognitoMode, sharedRenderProcessToken);
2459 }
2460
2461 WebModel::GetInstance()->SetFocusable(true);
2462 WebModel::GetInstance()->SetFocusNode(true);
2463 }
2464
WebRotate(const JSCallbackInfo & args)2465 void JSWeb::WebRotate(const JSCallbackInfo& args) {}
2466
OnAlert(const JSCallbackInfo & args)2467 void JSWeb::OnAlert(const JSCallbackInfo& args)
2468 {
2469 JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_ALERT);
2470 }
2471
OnBeforeUnload(const JSCallbackInfo & args)2472 void JSWeb::OnBeforeUnload(const JSCallbackInfo& args)
2473 {
2474 JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_BEFORE_UNLOAD);
2475 }
2476
OnConfirm(const JSCallbackInfo & args)2477 void JSWeb::OnConfirm(const JSCallbackInfo& args)
2478 {
2479 JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_CONFIRM);
2480 }
2481
OnPrompt(const JSCallbackInfo & args)2482 void JSWeb::OnPrompt(const JSCallbackInfo& args)
2483 {
2484 JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_PROMPT);
2485 }
2486
OnCommonDialog(const JSCallbackInfo & args,int dialogEventType)2487 void JSWeb::OnCommonDialog(const JSCallbackInfo& args, int dialogEventType)
2488 {
2489 if (!args[0]->IsFunction()) {
2490 return;
2491 }
2492 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2493 auto jsFunc =
2494 AceType::MakeRefPtr<JsEventFunction<WebDialogEvent, 1>>(JSRef<JSFunc>::Cast(args[0]), WebDialogEventToJSValue);
2495 auto instanceId = Container::CurrentId();
2496 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2497 const BaseEventInfo* info) -> bool {
2498 ContainerScope scope(instanceId);
2499 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
2500 auto pipelineContext = PipelineContext::GetCurrentContext();
2501 CHECK_NULL_RETURN(pipelineContext, false);
2502 pipelineContext->UpdateCurrentActiveNode(node);
2503 auto* eventInfo = TypeInfoHelper::DynamicCast<WebDialogEvent>(info);
2504 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
2505 if (message->IsBoolean()) {
2506 return message->ToBoolean();
2507 } else {
2508 return false;
2509 }
2510 };
2511 WebModel::GetInstance()->SetOnCommonDialog(jsCallback, dialogEventType);
2512 }
2513
OnConsoleLog(const JSCallbackInfo & args)2514 void JSWeb::OnConsoleLog(const JSCallbackInfo& args)
2515 {
2516 if (!args[0]->IsFunction()) {
2517 return;
2518 }
2519 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebConsoleLogEvent, 1>>(
2520 JSRef<JSFunc>::Cast(args[0]), LoadWebConsoleLogEventToJSValue);
2521
2522 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2523 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
2524 const BaseEventInfo* info) -> bool {
2525 bool result = false;
2526 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, result);
2527 auto pipelineContext = PipelineContext::GetCurrentContext();
2528 CHECK_NULL_RETURN(pipelineContext, false);
2529 pipelineContext->UpdateCurrentActiveNode(node);
2530 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebConsoleLogEvent>(info);
2531 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
2532 if (message->IsBoolean()) {
2533 result = message->ToBoolean();
2534 }
2535 return result;
2536 };
2537
2538 WebModel::GetInstance()->SetOnConsoleLog(jsCallback);
2539 }
2540
OnPageStart(const JSCallbackInfo & args)2541 void JSWeb::OnPageStart(const JSCallbackInfo& args)
2542 {
2543 if (!args[0]->IsFunction()) {
2544 return;
2545 }
2546 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebPageStartEvent, 1>>(
2547 JSRef<JSFunc>::Cast(args[0]), LoadWebPageStartEventToJSValue);
2548
2549 auto instanceId = Container::CurrentId();
2550 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2551 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2552 const BaseEventInfo* info) {
2553 ContainerScope scope(instanceId);
2554 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2555 auto pipelineContext = PipelineContext::GetCurrentContext();
2556 CHECK_NULL_VOID(pipelineContext);
2557 pipelineContext->UpdateCurrentActiveNode(node);
2558 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebPageStartEvent>(info);
2559 func->Execute(*eventInfo);
2560 };
2561 WebModel::GetInstance()->SetOnPageStart(jsCallback);
2562 }
2563
OnPageFinish(const JSCallbackInfo & args)2564 void JSWeb::OnPageFinish(const JSCallbackInfo& args)
2565 {
2566 if (!args[0]->IsFunction()) {
2567 return;
2568 }
2569 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebPageFinishEvent, 1>>(
2570 JSRef<JSFunc>::Cast(args[0]), LoadWebPageFinishEventToJSValue);
2571
2572 auto instanceId = Container::CurrentId();
2573 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2574 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2575 const BaseEventInfo* info) {
2576 ContainerScope scope(instanceId);
2577 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2578 auto pipelineContext = PipelineContext::GetCurrentContext();
2579 CHECK_NULL_VOID(pipelineContext);
2580 pipelineContext->UpdateCurrentActiveNode(node);
2581 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebPageFinishEvent>(info);
2582 func->Execute(*eventInfo);
2583 };
2584 WebModel::GetInstance()->SetOnPageFinish(jsCallback);
2585 }
2586
OnProgressChange(const JSCallbackInfo & args)2587 void JSWeb::OnProgressChange(const JSCallbackInfo& args)
2588 {
2589 if (args.Length() < 1 || !args[0]->IsFunction()) {
2590 return;
2591 }
2592 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebProgressChangeEvent, 1>>(
2593 JSRef<JSFunc>::Cast(args[0]), LoadWebProgressChangeEventToJSValue);
2594
2595 auto instanceId = Container::CurrentId();
2596 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2597 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2598 const BaseEventInfo* info) {
2599 ContainerScope scope(instanceId);
2600 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2601 auto pipelineContext = PipelineContext::GetCurrentContext();
2602 CHECK_NULL_VOID(pipelineContext);
2603 pipelineContext->UpdateCurrentActiveNode(node);
2604 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebProgressChangeEvent>(info);
2605 func->ExecuteWithValue(*eventInfo);
2606 };
2607 WebModel::GetInstance()->SetOnProgressChange(jsCallback);
2608 }
2609
OnTitleReceive(const JSCallbackInfo & args)2610 void JSWeb::OnTitleReceive(const JSCallbackInfo& args)
2611 {
2612 if (!args[0]->IsFunction()) {
2613 return;
2614 }
2615 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2616 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebTitleReceiveEvent, 1>>(
2617 JSRef<JSFunc>::Cast(args[0]), LoadWebTitleReceiveEventToJSValue);
2618 auto instanceId = Container::CurrentId();
2619 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2620 const BaseEventInfo* info) {
2621 ContainerScope scope(instanceId);
2622 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2623 auto pipelineContext = PipelineContext::GetCurrentContext();
2624 CHECK_NULL_VOID(pipelineContext);
2625 pipelineContext->UpdateCurrentActiveNode(node);
2626 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebTitleReceiveEvent>(info);
2627 func->Execute(*eventInfo);
2628 };
2629 WebModel::GetInstance()->SetOnTitleReceive(jsCallback);
2630 }
2631
OnFullScreenExit(const JSCallbackInfo & args)2632 void JSWeb::OnFullScreenExit(const JSCallbackInfo& args)
2633 {
2634 if (!args[0]->IsFunction()) {
2635 return;
2636 }
2637 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2638 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FullScreenExitEvent, 1>>(
2639 JSRef<JSFunc>::Cast(args[0]), FullScreenExitEventToJSValue);
2640 auto instanceId = Container::CurrentId();
2641 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2642 const BaseEventInfo* info) {
2643 ContainerScope scope(instanceId);
2644 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2645 auto pipelineContext = PipelineContext::GetCurrentContext();
2646 CHECK_NULL_VOID(pipelineContext);
2647 pipelineContext->UpdateCurrentActiveNode(node);
2648 auto* eventInfo = TypeInfoHelper::DynamicCast<FullScreenExitEvent>(info);
2649 func->Execute(*eventInfo);
2650 };
2651 WebModel::GetInstance()->SetOnFullScreenExit(jsCallback);
2652 }
2653
OnFullScreenEnter(const JSCallbackInfo & args)2654 void JSWeb::OnFullScreenEnter(const JSCallbackInfo& args)
2655 {
2656 if (args.Length() < 1 || !args[0]->IsFunction()) {
2657 return;
2658 }
2659 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2660 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FullScreenEnterEvent, 1>>(
2661 JSRef<JSFunc>::Cast(args[0]), FullScreenEnterEventToJSValue);
2662 auto instanceId = Container::CurrentId();
2663 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2664 const BaseEventInfo* info) {
2665 ContainerScope scope(instanceId);
2666 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2667 CHECK_NULL_VOID(func);
2668 auto pipelineContext = PipelineContext::GetCurrentContext();
2669 CHECK_NULL_VOID(pipelineContext);
2670 pipelineContext->UpdateCurrentActiveNode(node);
2671 auto* eventInfo = TypeInfoHelper::DynamicCast<FullScreenEnterEvent>(info);
2672 CHECK_NULL_VOID(eventInfo);
2673 func->Execute(*eventInfo);
2674 };
2675 WebModel::GetInstance()->SetOnFullScreenEnter(jsCallback);
2676 }
2677
OnGeolocationHide(const JSCallbackInfo & args)2678 void JSWeb::OnGeolocationHide(const JSCallbackInfo& args)
2679 {
2680 if (!args[0]->IsFunction()) {
2681 return;
2682 }
2683 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2684 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebGeolocationHideEvent, 1>>(
2685 JSRef<JSFunc>::Cast(args[0]), LoadWebGeolocationHideEventToJSValue);
2686 auto instanceId = Container::CurrentId();
2687 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2688 const BaseEventInfo* info) {
2689 ContainerScope scope(instanceId);
2690 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2691 auto pipelineContext = PipelineContext::GetCurrentContext();
2692 CHECK_NULL_VOID(pipelineContext);
2693 pipelineContext->UpdateCurrentActiveNode(node);
2694 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebGeolocationHideEvent>(info);
2695 func->Execute(*eventInfo);
2696 };
2697 WebModel::GetInstance()->SetOnGeolocationHide(jsCallback);
2698 }
2699
OnGeolocationShow(const JSCallbackInfo & args)2700 void JSWeb::OnGeolocationShow(const JSCallbackInfo& args)
2701 {
2702 if (!args[0]->IsFunction()) {
2703 return;
2704 }
2705 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2706 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebGeolocationShowEvent, 1>>(
2707 JSRef<JSFunc>::Cast(args[0]), LoadWebGeolocationShowEventToJSValue);
2708 auto instanceId = Container::CurrentId();
2709 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2710 const BaseEventInfo* info) {
2711 ContainerScope scope(instanceId);
2712 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2713 auto pipelineContext = PipelineContext::GetCurrentContext();
2714 CHECK_NULL_VOID(pipelineContext);
2715 pipelineContext->UpdateCurrentActiveNode(node);
2716 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebGeolocationShowEvent>(info);
2717 func->Execute(*eventInfo);
2718 };
2719 WebModel::GetInstance()->SetOnGeolocationShow(jsCallback);
2720 }
2721
OnRequestFocus(const JSCallbackInfo & args)2722 void JSWeb::OnRequestFocus(const JSCallbackInfo& args)
2723 {
2724 if (!args[0]->IsFunction()) {
2725 return;
2726 }
2727 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2728 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadWebRequestFocusEvent, 1>>(
2729 JSRef<JSFunc>::Cast(args[0]), LoadWebRequestFocusEventToJSValue);
2730 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
2731 const BaseEventInfo* info) {
2732 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2733 auto pipelineContext = PipelineContext::GetCurrentContext();
2734 CHECK_NULL_VOID(pipelineContext);
2735 pipelineContext->UpdateCurrentActiveNode(node);
2736 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadWebRequestFocusEvent>(info);
2737 func->Execute(*eventInfo);
2738 };
2739 WebModel::GetInstance()->SetOnRequestFocus(jsCallback);
2740 }
2741
OnDownloadStart(const JSCallbackInfo & args)2742 void JSWeb::OnDownloadStart(const JSCallbackInfo& args)
2743 {
2744 if (!args[0]->IsFunction()) {
2745 return;
2746 }
2747 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2748 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<DownloadStartEvent, 1>>(
2749 JSRef<JSFunc>::Cast(args[0]), DownloadStartEventToJSValue);
2750 auto instanceId = Container::CurrentId();
2751 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2752 const BaseEventInfo* info) {
2753 ContainerScope scope(instanceId);
2754 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2755 auto pipelineContext = PipelineContext::GetCurrentContext();
2756 CHECK_NULL_VOID(pipelineContext);
2757 pipelineContext->UpdateCurrentActiveNode(node);
2758 auto* eventInfo = TypeInfoHelper::DynamicCast<DownloadStartEvent>(info);
2759 func->Execute(*eventInfo);
2760 };
2761 WebModel::GetInstance()->SetOnDownloadStart(jsCallback);
2762 }
2763
OnHttpAuthRequest(const JSCallbackInfo & args)2764 void JSWeb::OnHttpAuthRequest(const JSCallbackInfo& args)
2765 {
2766 if (args.Length() < 1 || !args[0]->IsFunction()) {
2767 return;
2768 }
2769 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2770 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebHttpAuthEvent, 1>>(
2771 JSRef<JSFunc>::Cast(args[0]), WebHttpAuthEventToJSValue);
2772 auto instanceId = Container::CurrentId();
2773 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2774 const BaseEventInfo* info) -> bool {
2775 ContainerScope scope(instanceId);
2776 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
2777 auto pipelineContext = PipelineContext::GetCurrentContext();
2778 CHECK_NULL_RETURN(pipelineContext, false);
2779 pipelineContext->UpdateCurrentActiveNode(node);
2780 auto* eventInfo = TypeInfoHelper::DynamicCast<WebHttpAuthEvent>(info);
2781 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
2782 if (message->IsBoolean()) {
2783 return message->ToBoolean();
2784 }
2785 return false;
2786 };
2787 WebModel::GetInstance()->SetOnHttpAuthRequest(jsCallback);
2788 }
2789
OnSslErrRequest(const JSCallbackInfo & args)2790 void JSWeb::OnSslErrRequest(const JSCallbackInfo& args)
2791 {
2792 return;
2793 }
2794
OnSslErrorRequest(const JSCallbackInfo & args)2795 void JSWeb::OnSslErrorRequest(const JSCallbackInfo& args)
2796 {
2797 if (args.Length() < 1 || !args[0]->IsFunction()) {
2798 return;
2799 }
2800 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2801 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebSslErrorEvent, 1>>(
2802 JSRef<JSFunc>::Cast(args[0]), WebSslErrorEventToJSValue);
2803 auto instanceId = Container::CurrentId();
2804 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2805 const BaseEventInfo* info) -> bool {
2806 ContainerScope scope(instanceId);
2807 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
2808 auto pipelineContext = PipelineContext::GetCurrentContext();
2809 CHECK_NULL_RETURN(pipelineContext, false);
2810 pipelineContext->UpdateCurrentActiveNode(node);
2811 auto* eventInfo = TypeInfoHelper::DynamicCast<WebSslErrorEvent>(info);
2812 func->Execute(*eventInfo);
2813 return true;
2814 };
2815 WebModel::GetInstance()->SetOnSslErrorRequest(jsCallback);
2816 }
2817
OnAllSslErrorRequest(const JSCallbackInfo & args)2818 void JSWeb::OnAllSslErrorRequest(const JSCallbackInfo& args)
2819 {
2820 if (args.Length() < 1 || !args[0]->IsFunction()) {
2821 return;
2822 }
2823 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2824 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebAllSslErrorEvent, 1>>(
2825 JSRef<JSFunc>::Cast(args[0]), WebAllSslErrorEventToJSValue);
2826 auto instanceId = Container::CurrentId();
2827 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2828 const BaseEventInfo* info) -> bool {
2829 ContainerScope scope(instanceId);
2830 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
2831 auto pipelineContext = PipelineContext::GetCurrentContext();
2832 CHECK_NULL_RETURN(pipelineContext, false);
2833 pipelineContext->UpdateCurrentActiveNode(node);
2834 auto* eventInfo = TypeInfoHelper::DynamicCast<WebAllSslErrorEvent>(info);
2835 func->Execute(*eventInfo);
2836 return true;
2837 };
2838 WebModel::GetInstance()->SetOnAllSslErrorRequest(jsCallback);
2839 }
2840
OnSslSelectCertRequest(const JSCallbackInfo & args)2841 void JSWeb::OnSslSelectCertRequest(const JSCallbackInfo& args)
2842 {
2843 if (args.Length() < 1 || !args[0]->IsFunction()) {
2844 return;
2845 }
2846 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2847 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebSslSelectCertEvent, 1>>(
2848 JSRef<JSFunc>::Cast(args[0]), WebSslSelectCertEventToJSValue);
2849 auto instanceId = Container::CurrentId();
2850 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2851 const BaseEventInfo* info) -> bool {
2852 ContainerScope scope(instanceId);
2853 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
2854 auto pipelineContext = PipelineContext::GetCurrentContext();
2855 CHECK_NULL_RETURN(pipelineContext, false);
2856 pipelineContext->UpdateCurrentActiveNode(node);
2857 auto* eventInfo = TypeInfoHelper::DynamicCast<WebSslSelectCertEvent>(info);
2858 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
2859 if (message->IsBoolean()) {
2860 return message->ToBoolean();
2861 }
2862 return false;
2863 };
2864 WebModel::GetInstance()->SetOnSslSelectCertRequest(jsCallback);
2865 }
2866
MediaPlayGestureAccess(bool isNeedGestureAccess)2867 void JSWeb::MediaPlayGestureAccess(bool isNeedGestureAccess)
2868 {
2869 WebModel::GetInstance()->SetMediaPlayGestureAccess(isNeedGestureAccess);
2870 }
2871
OnKeyEvent(const JSCallbackInfo & args)2872 void JSWeb::OnKeyEvent(const JSCallbackInfo& args)
2873 {
2874 if (args.Length() < 1 || !args[0]->IsFunction()) {
2875 return;
2876 }
2877
2878 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2879 RefPtr<JsKeyFunction> jsOnKeyEventFunc = AceType::MakeRefPtr<JsKeyFunction>(JSRef<JSFunc>::Cast(args[0]));
2880 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsOnKeyEventFunc), node = frameNode](
2881 KeyEventInfo& keyEventInfo) {
2882 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2883 auto pipelineContext = PipelineContext::GetCurrentContext();
2884 CHECK_NULL_VOID(pipelineContext);
2885 pipelineContext->UpdateCurrentActiveNode(node);
2886 func->Execute(keyEventInfo);
2887 };
2888 WebModel::GetInstance()->SetOnKeyEvent(jsCallback);
2889 }
2890
ReceivedErrorEventToJSValue(const ReceivedErrorEvent & eventInfo)2891 JSRef<JSVal> ReceivedErrorEventToJSValue(const ReceivedErrorEvent& eventInfo)
2892 {
2893 JSRef<JSObject> obj = JSRef<JSObject>::New();
2894
2895 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
2896 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
2897 requestEvent->SetErrorEvent(eventInfo);
2898
2899 JSRef<JSObject> errorObj = JSClass<JSWebResourceError>::NewInstance();
2900 auto errorEvent = Referenced::Claim(errorObj->Unwrap<JSWebResourceError>());
2901 errorEvent->SetEvent(eventInfo);
2902
2903 obj->SetPropertyObject("request", requestObj);
2904 obj->SetPropertyObject("error", errorObj);
2905
2906 return JSRef<JSVal>::Cast(obj);
2907 }
2908
ReceivedHttpErrorEventToJSValue(const ReceivedHttpErrorEvent & eventInfo)2909 JSRef<JSVal> ReceivedHttpErrorEventToJSValue(const ReceivedHttpErrorEvent& eventInfo)
2910 {
2911 JSRef<JSObject> obj = JSRef<JSObject>::New();
2912
2913 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
2914 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
2915 requestEvent->SetHttpErrorEvent(eventInfo);
2916
2917 JSRef<JSObject> responseObj = JSClass<JSWebResourceResponse>::NewInstance();
2918 auto responseEvent = Referenced::Claim(responseObj->Unwrap<JSWebResourceResponse>());
2919 responseEvent->SetEvent(eventInfo);
2920
2921 obj->SetPropertyObject("request", requestObj);
2922 obj->SetPropertyObject("response", responseObj);
2923
2924 return JSRef<JSVal>::Cast(obj);
2925 }
2926
OnErrorReceive(const JSCallbackInfo & args)2927 void JSWeb::OnErrorReceive(const JSCallbackInfo& args)
2928 {
2929 if (!args[0]->IsFunction()) {
2930 return;
2931 }
2932 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2933 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ReceivedErrorEvent, 1>>(
2934 JSRef<JSFunc>::Cast(args[0]), ReceivedErrorEventToJSValue);
2935 auto instanceId = Container::CurrentId();
2936 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2937 const BaseEventInfo* info) {
2938 ContainerScope scope(instanceId);
2939 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2940 auto pipelineContext = PipelineContext::GetCurrentContext();
2941 CHECK_NULL_VOID(pipelineContext);
2942 pipelineContext->UpdateCurrentActiveNode(node);
2943 auto* eventInfo = TypeInfoHelper::DynamicCast<ReceivedErrorEvent>(info);
2944 func->Execute(*eventInfo);
2945 };
2946 WebModel::GetInstance()->SetOnErrorReceive(jsCallback);
2947 }
2948
OnHttpErrorReceive(const JSCallbackInfo & args)2949 void JSWeb::OnHttpErrorReceive(const JSCallbackInfo& args)
2950 {
2951 if (!args[0]->IsFunction()) {
2952 return;
2953 }
2954 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2955 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ReceivedHttpErrorEvent, 1>>(
2956 JSRef<JSFunc>::Cast(args[0]), ReceivedHttpErrorEventToJSValue);
2957 auto instanceId = Container::CurrentId();
2958 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2959 const BaseEventInfo* info) {
2960 ContainerScope scope(instanceId);
2961 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
2962 auto pipelineContext = PipelineContext::GetCurrentContext();
2963 CHECK_NULL_VOID(pipelineContext);
2964 pipelineContext->UpdateCurrentActiveNode(node);
2965 auto* eventInfo = TypeInfoHelper::DynamicCast<ReceivedHttpErrorEvent>(info);
2966 func->Execute(*eventInfo);
2967 };
2968 WebModel::GetInstance()->SetOnHttpErrorReceive(jsCallback);
2969 }
2970
OnInterceptRequestEventToJSValue(const OnInterceptRequestEvent & eventInfo)2971 JSRef<JSVal> OnInterceptRequestEventToJSValue(const OnInterceptRequestEvent& eventInfo)
2972 {
2973 JSRef<JSObject> obj = JSRef<JSObject>::New();
2974 JSRef<JSObject> requestObj = JSClass<JSWebResourceRequest>::NewInstance();
2975 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSWebResourceRequest>());
2976 requestEvent->SetOnInterceptRequestEvent(eventInfo);
2977 obj->SetPropertyObject("request", requestObj);
2978 return JSRef<JSVal>::Cast(obj);
2979 }
2980
OnInterceptRequest(const JSCallbackInfo & args)2981 void JSWeb::OnInterceptRequest(const JSCallbackInfo& args)
2982 {
2983 if ((args.Length() <= 0) || !args[0]->IsFunction()) {
2984 return;
2985 }
2986 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2987 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<OnInterceptRequestEvent, 1>>(
2988 JSRef<JSFunc>::Cast(args[0]), OnInterceptRequestEventToJSValue);
2989 auto instanceId = Container::CurrentId();
2990 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
2991 const BaseEventInfo* info) -> RefPtr<WebResponse> {
2992 ContainerScope scope(instanceId);
2993 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, nullptr);
2994 auto pipelineContext = PipelineContext::GetCurrentContext();
2995 CHECK_NULL_RETURN(pipelineContext, nullptr);
2996 pipelineContext->UpdateCurrentActiveNode(node);
2997 auto* eventInfo = TypeInfoHelper::DynamicCast<OnInterceptRequestEvent>(info);
2998 JSRef<JSVal> obj = func->ExecuteWithValue(*eventInfo);
2999 if (!obj->IsObject()) {
3000 return nullptr;
3001 }
3002 auto jsResponse = JSRef<JSObject>::Cast(obj)->Unwrap<JSWebResourceResponse>();
3003 if (jsResponse) {
3004 return jsResponse->GetResponseObj();
3005 }
3006 return nullptr;
3007 };
3008 WebModel::GetInstance()->SetOnInterceptRequest(jsCallback);
3009 }
3010
OnUrlLoadIntercept(const JSCallbackInfo & args)3011 void JSWeb::OnUrlLoadIntercept(const JSCallbackInfo& args)
3012 {
3013 if (!args[0]->IsFunction()) {
3014 return;
3015 }
3016 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3017 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<UrlLoadInterceptEvent, 1>>(
3018 JSRef<JSFunc>::Cast(args[0]), UrlLoadInterceptEventToJSValue);
3019 auto instanceId = Container::CurrentId();
3020 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3021 const BaseEventInfo* info) -> bool {
3022 ContainerScope scope(instanceId);
3023 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3024 auto pipelineContext = PipelineContext::GetCurrentContext();
3025 CHECK_NULL_RETURN(pipelineContext, false);
3026 pipelineContext->UpdateCurrentActiveNode(node);
3027 auto* eventInfo = TypeInfoHelper::DynamicCast<UrlLoadInterceptEvent>(info);
3028 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3029 if (message->IsBoolean()) {
3030 return message->ToBoolean();
3031 }
3032 return false;
3033 };
3034 WebModel::GetInstance()->SetOnUrlLoadIntercept(jsCallback);
3035 }
3036
OnLoadIntercept(const JSCallbackInfo & args)3037 void JSWeb::OnLoadIntercept(const JSCallbackInfo& args)
3038 {
3039 if (!args[0]->IsFunction()) {
3040 return;
3041 }
3042 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadInterceptEvent, 1>>(
3043 JSRef<JSFunc>::Cast(args[0]), LoadInterceptEventToJSValue);
3044 auto instanceId = Container::CurrentId();
3045
3046 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3047 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3048 const BaseEventInfo* info) -> bool {
3049 ContainerScope scope(instanceId);
3050 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3051 auto pipelineContext = PipelineContext::GetCurrentContext();
3052 CHECK_NULL_RETURN(pipelineContext, false);
3053 pipelineContext->UpdateCurrentActiveNode(node);
3054 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadInterceptEvent>(info);
3055 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3056 if (message->IsBoolean()) {
3057 return message->ToBoolean();
3058 }
3059 return false;
3060 };
3061 WebModel::GetInstance()->SetOnLoadIntercept(std::move(uiCallback));
3062 }
3063
FileSelectorEventToJSValue(const FileSelectorEvent & eventInfo)3064 JSRef<JSVal> FileSelectorEventToJSValue(const FileSelectorEvent& eventInfo)
3065 {
3066 JSRef<JSObject> obj = JSRef<JSObject>::New();
3067
3068 JSRef<JSObject> paramObj = JSClass<JSFileSelectorParam>::NewInstance();
3069 auto fileSelectorParam = Referenced::Claim(paramObj->Unwrap<JSFileSelectorParam>());
3070 fileSelectorParam->SetParam(eventInfo);
3071
3072 JSRef<JSObject> resultObj = JSClass<JSFileSelectorResult>::NewInstance();
3073 auto fileSelectorResult = Referenced::Claim(resultObj->Unwrap<JSFileSelectorResult>());
3074 fileSelectorResult->SetResult(eventInfo);
3075
3076 obj->SetPropertyObject("result", resultObj);
3077 obj->SetPropertyObject("fileSelector", paramObj);
3078 return JSRef<JSVal>::Cast(obj);
3079 }
3080
OnFileSelectorShow(const JSCallbackInfo & args)3081 void JSWeb::OnFileSelectorShow(const JSCallbackInfo& args)
3082 {
3083 if (!args[0]->IsFunction()) {
3084 return;
3085 }
3086
3087 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3088 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FileSelectorEvent, 1>>(
3089 JSRef<JSFunc>::Cast(args[0]), FileSelectorEventToJSValue);
3090 auto instanceId = Container::CurrentId();
3091 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3092 const BaseEventInfo* info) -> bool {
3093 ContainerScope scope(instanceId);
3094 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3095 auto pipelineContext = PipelineContext::GetCurrentContext();
3096 CHECK_NULL_RETURN(pipelineContext, false);
3097 pipelineContext->UpdateCurrentActiveNode(node);
3098 auto* eventInfo = TypeInfoHelper::DynamicCast<FileSelectorEvent>(info);
3099 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3100 if (message->IsBoolean()) {
3101 return message->ToBoolean();
3102 }
3103 return false;
3104 };
3105 WebModel::GetInstance()->SetOnFileSelectorShow(jsCallback);
3106 }
3107
ContextMenuEventToJSValue(const ContextMenuEvent & eventInfo)3108 JSRef<JSVal> ContextMenuEventToJSValue(const ContextMenuEvent& eventInfo)
3109 {
3110 JSRef<JSObject> obj = JSRef<JSObject>::New();
3111
3112 JSRef<JSObject> paramObj = JSClass<JSContextMenuParam>::NewInstance();
3113 auto contextMenuParam = Referenced::Claim(paramObj->Unwrap<JSContextMenuParam>());
3114 contextMenuParam->SetParam(eventInfo);
3115
3116 JSRef<JSObject> resultObj = JSClass<JSContextMenuResult>::NewInstance();
3117 auto contextMenuResult = Referenced::Claim(resultObj->Unwrap<JSContextMenuResult>());
3118 contextMenuResult->SetResult(eventInfo);
3119
3120 obj->SetPropertyObject("result", resultObj);
3121 obj->SetPropertyObject("param", paramObj);
3122 return JSRef<JSVal>::Cast(obj);
3123 }
3124
OnContextMenuShow(const JSCallbackInfo & args)3125 void JSWeb::OnContextMenuShow(const JSCallbackInfo& args)
3126 {
3127 if (args.Length() < 1 || !args[0]->IsFunction()) {
3128 return;
3129 }
3130 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3131 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ContextMenuEvent, 1>>(
3132 JSRef<JSFunc>::Cast(args[0]), ContextMenuEventToJSValue);
3133 auto instanceId = Container::CurrentId();
3134 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3135 const BaseEventInfo* info) -> bool {
3136 ContainerScope scope(instanceId);
3137 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
3138 auto pipelineContext = PipelineContext::GetCurrentContext();
3139 CHECK_NULL_RETURN(pipelineContext, false);
3140 pipelineContext->UpdateCurrentActiveNode(node);
3141 auto* eventInfo = TypeInfoHelper::DynamicCast<ContextMenuEvent>(info);
3142 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
3143 if (message->IsBoolean()) {
3144 return message->ToBoolean();
3145 }
3146 return false;
3147 };
3148 WebModel::GetInstance()->SetOnContextMenuShow(jsCallback);
3149 }
3150
ParseBindSelectionMenuParam(const JSCallbackInfo & info,const JSRef<JSObject> & menuOptions,NG::MenuParam & menuParam)3151 void ParseBindSelectionMenuParam(
3152 const JSCallbackInfo& info, const JSRef<JSObject>& menuOptions, NG::MenuParam& menuParam)
3153 {
3154 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3155 auto onDisappearValue = menuOptions->GetProperty("onDisappear");
3156 if (onDisappearValue->IsFunction()) {
3157 RefPtr<JsFunction> jsOnDisAppearFunc =
3158 AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(onDisappearValue));
3159 auto onDisappear = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDisAppearFunc),
3160 node = frameNode]() {
3161 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3162 ACE_SCORING_EVENT("onDisappear");
3163 PipelineContext::SetCallBackNode(node);
3164 func->Execute();
3165 };
3166 menuParam.onDisappear = std::move(onDisappear);
3167 }
3168
3169 auto onAppearValue = menuOptions->GetProperty("onAppear");
3170 if (onAppearValue->IsFunction()) {
3171 RefPtr<JsFunction> jsOnAppearFunc =
3172 AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(onAppearValue));
3173 auto onAppear = [execCtx = info.GetExecutionContext(), func = std::move(jsOnAppearFunc),
3174 node = frameNode]() {
3175 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3176 ACE_SCORING_EVENT("onAppear");
3177 PipelineContext::SetCallBackNode(node);
3178 func->Execute();
3179 };
3180 menuParam.onAppear = std::move(onAppear);
3181 }
3182 }
3183
ParseBindSelectionMenuOptionParam(const JSCallbackInfo & info,const JSRef<JSVal> & args,NG::MenuParam & menuParam,std::function<void ()> & previewBuildFunc)3184 void ParseBindSelectionMenuOptionParam(const JSCallbackInfo& info, const JSRef<JSVal>& args,
3185 NG::MenuParam& menuParam, std::function<void()>& previewBuildFunc)
3186 {
3187 auto menuOptions = JSRef<JSObject>::Cast(args);
3188 ParseBindSelectionMenuParam(info, menuOptions, menuParam);
3189
3190 auto preview = menuOptions->GetProperty("preview");
3191 if (!preview->IsFunction()) {
3192 return;
3193 }
3194 auto menuType = menuOptions->GetProperty("menuType");
3195 bool isPreviewMenu = menuType->IsNumber() && menuType->ToNumber<int32_t>() == 1;
3196 if (isPreviewMenu) {
3197 menuParam.previewMode = MenuPreviewMode::CUSTOM;
3198 RefPtr<JsFunction> previewBuilderFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(preview));
3199 CHECK_NULL_VOID(previewBuilderFunc);
3200 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3201 previewBuildFunc = [execCtx = info.GetExecutionContext(), func = std::move(previewBuilderFunc),
3202 node = frameNode]() {
3203 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3204 ACE_SCORING_EVENT("BindSelectionMenuPreviwer");
3205 PipelineContext::SetCallBackNode(node);
3206 func->Execute();
3207 };
3208 }
3209 }
3210
BindSelectionMenu(const JSCallbackInfo & info)3211 void JSWeb::BindSelectionMenu(const JSCallbackInfo& info)
3212 {
3213 if (info.Length() < SELECTION_MENU_OPTION_PARAM_INDEX || !info[0]->IsNumber() || !info[1]->IsObject() ||
3214 !info[SELECTION_MENU_CONTENT_PARAM_INDEX]->IsNumber()) {
3215 return;
3216 }
3217 if (info[0]->ToNumber<int32_t>() != static_cast<int32_t>(WebElementType::IMAGE) ||
3218 info[SELECTION_MENU_CONTENT_PARAM_INDEX]->ToNumber<int32_t>() !=
3219 static_cast<int32_t>(ResponseType::LONG_PRESS)) {
3220 TAG_LOGW(AceLogTag::ACE_WEB, "WebElementType or WebResponseType param err");
3221 return;
3222 }
3223 WebElementType elementType = static_cast<WebElementType>(info[0]->ToNumber<int32_t>());
3224 ResponseType responseType =
3225 static_cast<ResponseType>(info[SELECTION_MENU_CONTENT_PARAM_INDEX]->ToNumber<int32_t>());
3226
3227 // Builder
3228 JSRef<JSObject> menuObj = JSRef<JSObject>::Cast(info[1]);
3229 auto builder = menuObj->GetProperty("builder");
3230 if (!builder->IsFunction()) {
3231 TAG_LOGW(AceLogTag::ACE_WEB, "BindSelectionMenu menu builder param err");
3232 return;
3233 }
3234 auto builderFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(builder));
3235 CHECK_NULL_VOID(builderFunc);
3236 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3237 std::function<void()> menuBuilder = [execCtx = info.GetExecutionContext(), func = std::move(builderFunc),
3238 node = frameNode]() {
3239 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3240 ACE_SCORING_EVENT("BindSelectionMenu");
3241 PipelineContext::SetCallBackNode(node);
3242 func->Execute();
3243 };
3244
3245 std::function<void()> previewBuilder = nullptr;
3246 NG::MenuParam menuParam;
3247 if (info.Length() > SELECTION_MENU_OPTION_PARAM_INDEX && info[SELECTION_MENU_OPTION_PARAM_INDEX]->IsObject()) {
3248 ParseBindSelectionMenuOptionParam(info, info[SELECTION_MENU_OPTION_PARAM_INDEX], menuParam, previewBuilder);
3249 }
3250
3251 if (responseType != ResponseType::LONG_PRESS) {
3252 menuParam.previewMode = MenuPreviewMode::NONE;
3253 menuParam.menuBindType = MenuBindingType::RIGHT_CLICK;
3254 }
3255 menuParam.contextMenuRegisterType = NG::ContextMenuRegisterType::CUSTOM_TYPE;
3256 menuParam.type = NG::MenuType::CONTEXT_MENU;
3257 menuParam.isPreviewContainScale = true;
3258 menuParam.isShow = true;
3259 WebModel::GetInstance()->SetNewDragStyle(true);
3260 auto previewSelectionMenuParam = std::make_shared<WebPreviewSelectionMenuParam>(
3261 elementType, responseType, menuBuilder, previewBuilder, menuParam);
3262 WebModel::GetInstance()->SetPreviewSelectionMenu(previewSelectionMenuParam);
3263 }
3264
OnContextMenuHide(const JSCallbackInfo & args)3265 void JSWeb::OnContextMenuHide(const JSCallbackInfo& args)
3266 {
3267 if (!args[0]->IsFunction()) {
3268 return;
3269 }
3270 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3271 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ContextMenuHideEvent, 1>>(
3272 JSRef<JSFunc>::Cast(args[0]), ContextMenuHideEventToJSValue);
3273
3274 auto instanceId = Container::CurrentId();
3275 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3276 const BaseEventInfo* info) {
3277 ContainerScope scope(instanceId);
3278 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3279 auto pipelineContext = PipelineContext::GetCurrentContext();
3280 CHECK_NULL_VOID(pipelineContext);
3281 pipelineContext->UpdateCurrentActiveNode(node);
3282 auto* eventInfo = TypeInfoHelper::DynamicCast<ContextMenuHideEvent>(info);
3283 func->Execute(*eventInfo);
3284 };
3285 WebModel::GetInstance()->SetOnContextMenuHide(jsCallback);
3286 }
3287
JsEnabled(bool isJsEnabled)3288 void JSWeb::JsEnabled(bool isJsEnabled)
3289 {
3290 WebModel::GetInstance()->SetJsEnabled(isJsEnabled);
3291 }
3292
ContentAccessEnabled(bool isContentAccessEnabled)3293 void JSWeb::ContentAccessEnabled(bool isContentAccessEnabled)
3294 {
3295 #if !defined(NG_BUILD) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
3296 auto stack = ViewStackProcessor::GetInstance();
3297 auto webComponent = AceType::DynamicCast<WebComponent>(stack->GetMainComponent());
3298 if (!webComponent) {
3299 return;
3300 }
3301 webComponent->SetContentAccessEnabled(isContentAccessEnabled);
3302 #else
3303 TAG_LOGW(AceLogTag::ACE_WEB, "do not support components in new pipeline mode");
3304 #endif
3305 }
3306
FileAccessEnabled(bool isFileAccessEnabled)3307 void JSWeb::FileAccessEnabled(bool isFileAccessEnabled)
3308 {
3309 WebModel::GetInstance()->SetFileAccessEnabled(isFileAccessEnabled);
3310 }
3311
OnLineImageAccessEnabled(bool isOnLineImageAccessEnabled)3312 void JSWeb::OnLineImageAccessEnabled(bool isOnLineImageAccessEnabled)
3313 {
3314 WebModel::GetInstance()->SetOnLineImageAccessEnabled(isOnLineImageAccessEnabled);
3315 }
3316
DomStorageAccessEnabled(bool isDomStorageAccessEnabled)3317 void JSWeb::DomStorageAccessEnabled(bool isDomStorageAccessEnabled)
3318 {
3319 WebModel::GetInstance()->SetDomStorageAccessEnabled(isDomStorageAccessEnabled);
3320 }
3321
ImageAccessEnabled(bool isImageAccessEnabled)3322 void JSWeb::ImageAccessEnabled(bool isImageAccessEnabled)
3323 {
3324 WebModel::GetInstance()->SetImageAccessEnabled(isImageAccessEnabled);
3325 }
3326
MixedMode(int32_t mixedMode)3327 void JSWeb::MixedMode(int32_t mixedMode)
3328 {
3329 auto mixedContentMode = MixedModeContent::MIXED_CONTENT_NEVER_ALLOW;
3330 switch (mixedMode) {
3331 case 0:
3332 mixedContentMode = MixedModeContent::MIXED_CONTENT_ALWAYS_ALLOW;
3333 break;
3334 case 1:
3335 mixedContentMode = MixedModeContent::MIXED_CONTENT_COMPATIBILITY_MODE;
3336 break;
3337 default:
3338 mixedContentMode = MixedModeContent::MIXED_CONTENT_NEVER_ALLOW;
3339 break;
3340 }
3341 WebModel::GetInstance()->SetMixedMode(mixedContentMode);
3342 }
3343
ZoomAccessEnabled(bool isZoomAccessEnabled)3344 void JSWeb::ZoomAccessEnabled(bool isZoomAccessEnabled)
3345 {
3346 WebModel::GetInstance()->SetZoomAccessEnabled(isZoomAccessEnabled);
3347 }
3348
EnableNativeEmbedMode(bool isEmbedModeEnabled)3349 void JSWeb::EnableNativeEmbedMode(bool isEmbedModeEnabled)
3350 {
3351 WebModel::GetInstance()->SetNativeEmbedModeEnabled(isEmbedModeEnabled);
3352 }
3353
RegisterNativeEmbedRule(const std::string & tag,const std::string & type)3354 void JSWeb::RegisterNativeEmbedRule(const std::string& tag, const std::string& type)
3355 {
3356 WebModel::GetInstance()->RegisterNativeEmbedRule(tag, type);
3357 }
3358
GeolocationAccessEnabled(bool isGeolocationAccessEnabled)3359 void JSWeb::GeolocationAccessEnabled(bool isGeolocationAccessEnabled)
3360 {
3361 WebModel::GetInstance()->SetGeolocationAccessEnabled(isGeolocationAccessEnabled);
3362 }
3363
JavaScriptProxy(const JSCallbackInfo & args)3364 void JSWeb::JavaScriptProxy(const JSCallbackInfo& args)
3365 {
3366 #if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
3367 if (args.Length() < 1 || !args[0]->IsObject()) {
3368 return;
3369 }
3370 auto paramObject = JSRef<JSObject>::Cast(args[0]);
3371 auto controllerObj = paramObject->GetProperty("controller");
3372 auto object = JSRef<JSVal>::Cast(paramObject->GetProperty("object"));
3373 auto name = JSRef<JSVal>::Cast(paramObject->GetProperty("name"));
3374 auto methodList = JSRef<JSVal>::Cast(paramObject->GetProperty("methodList"));
3375 auto asyncMethodList = JSRef<JSVal>::Cast(paramObject->GetProperty("asyncMethodList"));
3376 auto permission = JSRef<JSVal>::Cast(paramObject->GetProperty("permission"));
3377 if (!controllerObj->IsObject()) {
3378 return;
3379 }
3380 auto controller = JSRef<JSObject>::Cast(controllerObj);
3381 auto jsProxyFunction = controller->GetProperty("jsProxy");
3382 if (jsProxyFunction->IsFunction()) {
3383 auto jsProxyCallback = [webviewController = controller, func = JSRef<JSFunc>::Cast(jsProxyFunction), object,
3384 name, methodList, asyncMethodList, permission]() {
3385 JSRef<JSVal> argv[] = { object, name, methodList, asyncMethodList, permission };
3386 func->Call(webviewController, 5, argv);
3387 };
3388
3389 WebModel::GetInstance()->SetJsProxyCallback(jsProxyCallback);
3390 }
3391 auto jsWebController = controller->Unwrap<JSWebController>();
3392 if (jsWebController) {
3393 jsWebController->SetJavascriptInterface(args);
3394 }
3395 #endif
3396 }
3397
UserAgent(const std::string & userAgent)3398 void JSWeb::UserAgent(const std::string& userAgent)
3399 {
3400 WebModel::GetInstance()->SetUserAgent(userAgent);
3401 }
3402
RenderExitedEventToJSValue(const RenderExitedEvent & eventInfo)3403 JSRef<JSVal> RenderExitedEventToJSValue(const RenderExitedEvent& eventInfo)
3404 {
3405 JSRef<JSObject> obj = JSRef<JSObject>::New();
3406 obj->SetProperty("renderExitReason", eventInfo.GetExitedReason());
3407 return JSRef<JSVal>::Cast(obj);
3408 }
3409
RefreshAccessedHistoryEventToJSValue(const RefreshAccessedHistoryEvent & eventInfo)3410 JSRef<JSVal> RefreshAccessedHistoryEventToJSValue(const RefreshAccessedHistoryEvent& eventInfo)
3411 {
3412 JSRef<JSObject> obj = JSRef<JSObject>::New();
3413 obj->SetProperty("url", eventInfo.GetVisitedUrl());
3414 obj->SetProperty("isRefreshed", eventInfo.IsRefreshed());
3415 return JSRef<JSVal>::Cast(obj);
3416 }
3417
OnRenderExited(const JSCallbackInfo & args)3418 void JSWeb::OnRenderExited(const JSCallbackInfo& args)
3419 {
3420 if (!args[0]->IsFunction()) {
3421 return;
3422 }
3423 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3424 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<RenderExitedEvent, 1>>(
3425 JSRef<JSFunc>::Cast(args[0]), RenderExitedEventToJSValue);
3426 auto instanceId = Container::CurrentId();
3427 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3428 const BaseEventInfo* info) {
3429 ContainerScope scope(instanceId);
3430 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3431 auto pipelineContext = PipelineContext::GetCurrentContext();
3432 CHECK_NULL_VOID(pipelineContext);
3433 pipelineContext->UpdateCurrentActiveNode(node);
3434 auto* eventInfo = TypeInfoHelper::DynamicCast<RenderExitedEvent>(info);
3435 func->Execute(*eventInfo);
3436 };
3437 WebModel::GetInstance()->SetRenderExitedId(jsCallback);
3438 }
3439
OnRefreshAccessedHistory(const JSCallbackInfo & args)3440 void JSWeb::OnRefreshAccessedHistory(const JSCallbackInfo& args)
3441 {
3442 if (!args[0]->IsFunction()) {
3443 return;
3444 }
3445 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3446 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<RefreshAccessedHistoryEvent, 1>>(
3447 JSRef<JSFunc>::Cast(args[0]), RefreshAccessedHistoryEventToJSValue);
3448 auto instanceId = Container::CurrentId();
3449 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3450 const BaseEventInfo* info) {
3451 ContainerScope scope(instanceId);
3452 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3453 auto pipelineContext = PipelineContext::GetCurrentContext();
3454 CHECK_NULL_VOID(pipelineContext);
3455 pipelineContext->UpdateCurrentActiveNode(node);
3456 auto* eventInfo = TypeInfoHelper::DynamicCast<RefreshAccessedHistoryEvent>(info);
3457 func->Execute(*eventInfo);
3458 };
3459 WebModel::GetInstance()->SetRefreshAccessedHistoryId(jsCallback);
3460 }
3461
CacheMode(int32_t cacheMode)3462 void JSWeb::CacheMode(int32_t cacheMode)
3463 {
3464 auto mode = WebCacheMode::DEFAULT;
3465 switch (cacheMode) {
3466 case 0:
3467 mode = WebCacheMode::DEFAULT;
3468 break;
3469 case 1:
3470 mode = WebCacheMode::USE_CACHE_ELSE_NETWORK;
3471 break;
3472 case 2:
3473 mode = WebCacheMode::USE_NO_CACHE;
3474 break;
3475 case 3:
3476 mode = WebCacheMode::USE_CACHE_ONLY;
3477 break;
3478 default:
3479 mode = WebCacheMode::DEFAULT;
3480 break;
3481 }
3482 WebModel::GetInstance()->SetCacheMode(mode);
3483 }
3484
OverScrollMode(int overScrollMode)3485 void JSWeb::OverScrollMode(int overScrollMode)
3486 {
3487 auto mode = OverScrollMode::NEVER;
3488 switch (overScrollMode) {
3489 case 0:
3490 mode = OverScrollMode::NEVER;
3491 break;
3492 case 1:
3493 mode = OverScrollMode::ALWAYS;
3494 break;
3495 default:
3496 mode = OverScrollMode::NEVER;
3497 break;
3498 }
3499 WebModel::GetInstance()->SetOverScrollMode(mode);
3500 }
3501
OverviewModeAccess(bool isOverviewModeAccessEnabled)3502 void JSWeb::OverviewModeAccess(bool isOverviewModeAccessEnabled)
3503 {
3504 WebModel::GetInstance()->SetOverviewModeAccessEnabled(isOverviewModeAccessEnabled);
3505 }
3506
FileFromUrlAccess(bool isFileFromUrlAccessEnabled)3507 void JSWeb::FileFromUrlAccess(bool isFileFromUrlAccessEnabled)
3508 {
3509 WebModel::GetInstance()->SetFileFromUrlAccessEnabled(isFileFromUrlAccessEnabled);
3510 }
3511
DatabaseAccess(bool isDatabaseAccessEnabled)3512 void JSWeb::DatabaseAccess(bool isDatabaseAccessEnabled)
3513 {
3514 WebModel::GetInstance()->SetDatabaseAccessEnabled(isDatabaseAccessEnabled);
3515 }
3516
TextZoomRatio(int32_t textZoomRatioNum)3517 void JSWeb::TextZoomRatio(int32_t textZoomRatioNum)
3518 {
3519 WebModel::GetInstance()->SetTextZoomRatio(textZoomRatioNum);
3520 }
3521
WebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled)3522 void JSWeb::WebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled)
3523 {
3524 WebModel::GetInstance()->SetWebDebuggingAccessEnabled(isWebDebuggingAccessEnabled);
3525 }
3526
OnMouse(const JSCallbackInfo & args)3527 void JSWeb::OnMouse(const JSCallbackInfo& args)
3528 {
3529 if (args.Length() < 1 || !args[0]->IsFunction()) {
3530 return;
3531 }
3532
3533 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3534 RefPtr<JsClickFunction> jsOnMouseFunc = AceType::MakeRefPtr<JsClickFunction>(JSRef<JSFunc>::Cast(args[0]));
3535 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsOnMouseFunc), node = frameNode](
3536 MouseInfo& info) {
3537 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3538 auto pipelineContext = PipelineContext::GetCurrentContext();
3539 CHECK_NULL_VOID(pipelineContext);
3540 pipelineContext->UpdateCurrentActiveNode(node);
3541 func->Execute(info);
3542 };
3543 WebModel::GetInstance()->SetOnMouseEvent(jsCallback);
3544 }
3545
ResourceLoadEventToJSValue(const ResourceLoadEvent & eventInfo)3546 JSRef<JSVal> ResourceLoadEventToJSValue(const ResourceLoadEvent& eventInfo)
3547 {
3548 JSRef<JSObject> obj = JSRef<JSObject>::New();
3549 obj->SetProperty("url", eventInfo.GetOnResourceLoadUrl());
3550 return JSRef<JSVal>::Cast(obj);
3551 }
3552
OnResourceLoad(const JSCallbackInfo & args)3553 void JSWeb::OnResourceLoad(const JSCallbackInfo& args)
3554 {
3555 if (args.Length() < 1 || !args[0]->IsFunction()) {
3556 return;
3557 }
3558 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3559 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ResourceLoadEvent, 1>>(
3560 JSRef<JSFunc>::Cast(args[0]), ResourceLoadEventToJSValue);
3561 auto instanceId = Container::CurrentId();
3562 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3563 const BaseEventInfo* info) {
3564 ContainerScope scope(instanceId);
3565 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3566 auto pipelineContext = PipelineContext::GetCurrentContext();
3567 CHECK_NULL_VOID(pipelineContext);
3568 pipelineContext->UpdateCurrentActiveNode(node);
3569 auto* eventInfo = TypeInfoHelper::DynamicCast<ResourceLoadEvent>(info);
3570 func->Execute(*eventInfo);
3571 };
3572 WebModel::GetInstance()->SetResourceLoadId(jsCallback);
3573 }
3574
ScaleChangeEventToJSValue(const ScaleChangeEvent & eventInfo)3575 JSRef<JSVal> ScaleChangeEventToJSValue(const ScaleChangeEvent& eventInfo)
3576 {
3577 JSRef<JSObject> obj = JSRef<JSObject>::New();
3578 obj->SetProperty("oldScale", eventInfo.GetOnScaleChangeOldScale());
3579 obj->SetProperty("newScale", eventInfo.GetOnScaleChangeNewScale());
3580 return JSRef<JSVal>::Cast(obj);
3581 }
3582
OnScaleChange(const JSCallbackInfo & args)3583 void JSWeb::OnScaleChange(const JSCallbackInfo& args)
3584 {
3585 if (args.Length() < 1 || !args[0]->IsFunction()) {
3586 return;
3587 }
3588 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3589 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ScaleChangeEvent, 1>>(
3590 JSRef<JSFunc>::Cast(args[0]), ScaleChangeEventToJSValue);
3591 auto instanceId = Container::CurrentId();
3592 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3593 const BaseEventInfo* info) {
3594 ContainerScope scope(instanceId);
3595 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3596 auto pipelineContext = PipelineContext::GetCurrentContext();
3597 CHECK_NULL_VOID(pipelineContext);
3598 pipelineContext->UpdateCurrentActiveNode(node);
3599 auto* eventInfo = TypeInfoHelper::DynamicCast<ScaleChangeEvent>(info);
3600 func->Execute(*eventInfo);
3601 };
3602 WebModel::GetInstance()->SetScaleChangeId(jsCallback);
3603 }
3604
ScrollEventToJSValue(const WebOnScrollEvent & eventInfo)3605 JSRef<JSVal> ScrollEventToJSValue(const WebOnScrollEvent& eventInfo)
3606 {
3607 JSRef<JSObject> obj = JSRef<JSObject>::New();
3608 obj->SetProperty("xOffset", eventInfo.GetX());
3609 obj->SetProperty("yOffset", eventInfo.GetY());
3610 return JSRef<JSVal>::Cast(obj);
3611 }
3612
OnScroll(const JSCallbackInfo & args)3613 void JSWeb::OnScroll(const JSCallbackInfo& args)
3614 {
3615 if (args.Length() < 1 || !args[0]->IsFunction()) {
3616 return;
3617 }
3618
3619 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3620 auto jsFunc =
3621 AceType::MakeRefPtr<JsEventFunction<WebOnScrollEvent, 1>>(JSRef<JSFunc>::Cast(args[0]), ScrollEventToJSValue);
3622 auto instanceId = Container::CurrentId();
3623 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3624 const BaseEventInfo* info) {
3625 ContainerScope scope(instanceId);
3626 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3627 auto pipelineContext = PipelineContext::GetCurrentContext();
3628 CHECK_NULL_VOID(pipelineContext);
3629 pipelineContext->UpdateCurrentActiveNode(node);
3630 auto* eventInfo = TypeInfoHelper::DynamicCast<WebOnScrollEvent>(info);
3631 func->Execute(*eventInfo);
3632 };
3633 WebModel::GetInstance()->SetScrollId(jsCallback);
3634 }
3635
PermissionRequestEventToJSValue(const WebPermissionRequestEvent & eventInfo)3636 JSRef<JSVal> PermissionRequestEventToJSValue(const WebPermissionRequestEvent& eventInfo)
3637 {
3638 JSRef<JSObject> obj = JSRef<JSObject>::New();
3639 JSRef<JSObject> permissionObj = JSClass<JSWebPermissionRequest>::NewInstance();
3640 auto permissionEvent = Referenced::Claim(permissionObj->Unwrap<JSWebPermissionRequest>());
3641 permissionEvent->SetEvent(eventInfo);
3642 obj->SetPropertyObject("request", permissionObj);
3643 return JSRef<JSVal>::Cast(obj);
3644 }
3645
OnPermissionRequest(const JSCallbackInfo & args)3646 void JSWeb::OnPermissionRequest(const JSCallbackInfo& args)
3647 {
3648 if (args.Length() < 1 || !args[0]->IsFunction()) {
3649 return;
3650 }
3651 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3652 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebPermissionRequestEvent, 1>>(
3653 JSRef<JSFunc>::Cast(args[0]), PermissionRequestEventToJSValue);
3654 auto instanceId = Container::CurrentId();
3655 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3656 const BaseEventInfo* info) {
3657 ContainerScope scope(instanceId);
3658 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3659 auto pipelineContext = PipelineContext::GetCurrentContext();
3660 CHECK_NULL_VOID(pipelineContext);
3661 pipelineContext->UpdateCurrentActiveNode(node);
3662 auto* eventInfo = TypeInfoHelper::DynamicCast<WebPermissionRequestEvent>(info);
3663 func->Execute(*eventInfo);
3664 };
3665 WebModel::GetInstance()->SetPermissionRequestEventId(jsCallback);
3666 }
3667
ScreenCaptureRequestEventToJSValue(const WebScreenCaptureRequestEvent & eventInfo)3668 JSRef<JSVal> ScreenCaptureRequestEventToJSValue(const WebScreenCaptureRequestEvent& eventInfo)
3669 {
3670 JSRef<JSObject> obj = JSRef<JSObject>::New();
3671 JSRef<JSObject> requestObj = JSClass<JSScreenCaptureRequest>::NewInstance();
3672 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSScreenCaptureRequest>());
3673 requestEvent->SetEvent(eventInfo);
3674 obj->SetPropertyObject("handler", requestObj);
3675 return JSRef<JSVal>::Cast(obj);
3676 }
3677
OnScreenCaptureRequest(const JSCallbackInfo & args)3678 void JSWeb::OnScreenCaptureRequest(const JSCallbackInfo& args)
3679 {
3680 if (args.Length() < 1 || !args[0]->IsFunction()) {
3681 return;
3682 }
3683 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3684 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebScreenCaptureRequestEvent, 1>>(
3685 JSRef<JSFunc>::Cast(args[0]), ScreenCaptureRequestEventToJSValue);
3686 auto instanceId = Container::CurrentId();
3687 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3688 const BaseEventInfo* info) {
3689 ContainerScope scope(instanceId);
3690 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3691 auto pipelineContext = PipelineContext::GetCurrentContext();
3692 CHECK_NULL_VOID(pipelineContext);
3693 pipelineContext->UpdateCurrentActiveNode(node);
3694 auto* eventInfo = TypeInfoHelper::DynamicCast<WebScreenCaptureRequestEvent>(info);
3695 func->Execute(*eventInfo);
3696 };
3697 WebModel::GetInstance()->SetScreenCaptureRequestEventId(jsCallback);
3698 }
3699
BackgroundColor(const JSCallbackInfo & info)3700 void JSWeb::BackgroundColor(const JSCallbackInfo& info)
3701 {
3702 if (info.Length() < 1) {
3703 return;
3704 }
3705 Color backgroundColor;
3706 if (!ParseJsColor(info[0], backgroundColor)) {
3707 backgroundColor = WebModel::GetInstance()->GetDefaultBackgroundColor();
3708 }
3709 WebModel::GetInstance()->SetBackgroundColor(backgroundColor);
3710 }
3711
InitialScale(float scale)3712 void JSWeb::InitialScale(float scale)
3713 {
3714 WebModel::GetInstance()->InitialScale(scale);
3715 }
3716
Password(bool password)3717 void JSWeb::Password(bool password) {}
3718
TableData(bool tableData)3719 void JSWeb::TableData(bool tableData) {}
3720
OnFileSelectorShowAbandoned(const JSCallbackInfo & args)3721 void JSWeb::OnFileSelectorShowAbandoned(const JSCallbackInfo& args) {}
3722
WideViewModeAccess(const JSCallbackInfo & args)3723 void JSWeb::WideViewModeAccess(const JSCallbackInfo& args) {}
3724
WebDebuggingAccess(const JSCallbackInfo & args)3725 void JSWeb::WebDebuggingAccess(const JSCallbackInfo& args) {}
3726
OnSearchResultReceive(const JSCallbackInfo & args)3727 void JSWeb::OnSearchResultReceive(const JSCallbackInfo& args)
3728 {
3729 if (!args[0]->IsFunction()) {
3730 return;
3731 }
3732 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3733 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<SearchResultReceiveEvent, 1>>(
3734 JSRef<JSFunc>::Cast(args[0]), SearchResultReceiveEventToJSValue);
3735 auto instanceId = Container::CurrentId();
3736 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3737 const BaseEventInfo* info) {
3738 ContainerScope scope(instanceId);
3739 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3740 auto pipelineContext = PipelineContext::GetCurrentContext();
3741 CHECK_NULL_VOID(pipelineContext);
3742 pipelineContext->UpdateCurrentActiveNode(node);
3743 auto* eventInfo = TypeInfoHelper::DynamicCast<SearchResultReceiveEvent>(info);
3744 func->Execute(*eventInfo);
3745 };
3746 WebModel::GetInstance()->SetSearchResultReceiveEventId(jsCallback);
3747 }
3748
JsOnDragStart(const JSCallbackInfo & info)3749 void JSWeb::JsOnDragStart(const JSCallbackInfo& info)
3750 {
3751 if (info.Length() < 1 || !info[0]->IsFunction()) {
3752 return;
3753 }
3754
3755 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3756 RefPtr<JsDragFunction> jsOnDragStartFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(info[0]));
3757 auto onDragStartId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragStartFunc), node = frameNode](
3758 const RefPtr<DragEvent>& info, const std::string& extraParams) -> NG::DragDropBaseInfo {
3759 NG::DragDropBaseInfo itemInfo;
3760 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, itemInfo);
3761 auto pipelineContext = PipelineContext::GetCurrentContext();
3762 CHECK_NULL_RETURN(pipelineContext, itemInfo);
3763 pipelineContext->UpdateCurrentActiveNode(node);
3764 auto ret = func->Execute(info, extraParams);
3765 if (!ret->IsObject()) {
3766 return itemInfo;
3767 }
3768 auto component = ParseDragNode(ret);
3769 if (component) {
3770 itemInfo.node = component;
3771 return itemInfo;
3772 }
3773
3774 auto builderObj = JSRef<JSObject>::Cast(ret);
3775 #if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM)
3776 auto pixmap_impl = builderObj->GetProperty("pixelMap");
3777 itemInfo.pixelMap = CreatePixelMapFromNapiValue(pixmap_impl);
3778 #endif
3779
3780 #if defined(PIXEL_MAP_SUPPORTED)
3781 auto pixmap_ng = builderObj->GetProperty("pixelMap");
3782 itemInfo.pixelMap = CreatePixelMapFromNapiValue(pixmap_ng);
3783 #endif
3784 auto extraInfo = builderObj->GetProperty("extraInfo");
3785 ParseJsString(extraInfo, itemInfo.extraInfo);
3786 component = ParseDragNode(builderObj->GetProperty("builder"));
3787 itemInfo.node = component;
3788 return itemInfo;
3789 };
3790
3791 WebModel::GetInstance()->SetOnDragStart(std::move(onDragStartId));
3792 }
3793
JsOnDragEnter(const JSCallbackInfo & info)3794 void JSWeb::JsOnDragEnter(const JSCallbackInfo& info)
3795 {
3796 if (info.Length() < 1 || !info[0]->IsFunction()) {
3797 return;
3798 }
3799
3800 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3801 RefPtr<JsDragFunction> jsOnDragEnterFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(info[0]));
3802 auto onDragEnterId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragEnterFunc), node = frameNode](
3803 const RefPtr<DragEvent>& info, const std::string& extraParams) {
3804 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3805 ACE_SCORING_EVENT("onDragEnter");
3806 auto pipelineContext = PipelineContext::GetCurrentContext();
3807 CHECK_NULL_VOID(pipelineContext);
3808 pipelineContext->UpdateCurrentActiveNode(node);
3809 func->Execute(info, extraParams);
3810 };
3811
3812 WebModel::GetInstance()->SetOnDragEnter(onDragEnterId);
3813 }
3814
JsOnDragMove(const JSCallbackInfo & info)3815 void JSWeb::JsOnDragMove(const JSCallbackInfo& info)
3816 {
3817 if (info.Length() < 1 || !info[0]->IsFunction()) {
3818 return;
3819 }
3820
3821 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3822 RefPtr<JsDragFunction> jsOnDragMoveFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(info[0]));
3823 auto onDragMoveId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragMoveFunc), node = frameNode](
3824 const RefPtr<DragEvent>& info, const std::string& extraParams) {
3825 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3826 ACE_SCORING_EVENT("onDragMove");
3827 auto pipelineContext = PipelineContext::GetCurrentContext();
3828 CHECK_NULL_VOID(pipelineContext);
3829 pipelineContext->UpdateCurrentActiveNode(node);
3830 func->Execute(info, extraParams);
3831 };
3832
3833 WebModel::GetInstance()->SetOnDragMove(onDragMoveId);
3834 }
3835
JsOnDragLeave(const JSCallbackInfo & info)3836 void JSWeb::JsOnDragLeave(const JSCallbackInfo& info)
3837 {
3838 if (info.Length() < 1 || !info[0]->IsFunction()) {
3839 return;
3840 }
3841
3842 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3843 RefPtr<JsDragFunction> jsOnDragLeaveFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(info[0]));
3844 auto onDragLeaveId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragLeaveFunc), node = frameNode](
3845 const RefPtr<DragEvent>& info, const std::string& extraParams) {
3846 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3847 ACE_SCORING_EVENT("onDragLeave");
3848 auto pipelineContext = PipelineContext::GetCurrentContext();
3849 CHECK_NULL_VOID(pipelineContext);
3850 pipelineContext->UpdateCurrentActiveNode(node);
3851 func->Execute(info, extraParams);
3852 };
3853
3854 WebModel::GetInstance()->SetOnDragLeave(onDragLeaveId);
3855 }
3856
JsOnDrop(const JSCallbackInfo & info)3857 void JSWeb::JsOnDrop(const JSCallbackInfo& info)
3858 {
3859 if (info.Length() < 1 || !info[0]->IsFunction()) {
3860 return;
3861 }
3862
3863 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3864 RefPtr<JsDragFunction> jsOnDropFunc = AceType::MakeRefPtr<JsDragFunction>(JSRef<JSFunc>::Cast(info[0]));
3865 auto onDropId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDropFunc), node = frameNode](
3866 const RefPtr<DragEvent>& info, const std::string& extraParams) {
3867 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3868 ACE_SCORING_EVENT("onDrop");
3869 auto pipelineContext = PipelineContext::GetCurrentContext();
3870 CHECK_NULL_VOID(pipelineContext);
3871 pipelineContext->UpdateCurrentActiveNode(node);
3872 func->Execute(info, extraParams);
3873 };
3874
3875 WebModel::GetInstance()->SetOnDrop(onDropId);
3876 }
3877
PinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)3878 void JSWeb::PinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)
3879 {
3880 WebModel::GetInstance()->SetPinchSmoothModeEnabled(isPinchSmoothModeEnabled);
3881 }
3882
WindowNewEventToJSValue(const WebWindowNewEvent & eventInfo)3883 JSRef<JSVal> WindowNewEventToJSValue(const WebWindowNewEvent& eventInfo)
3884 {
3885 JSRef<JSObject> obj = JSRef<JSObject>::New();
3886 obj->SetProperty("isAlert", eventInfo.IsAlert());
3887 obj->SetProperty("isUserTrigger", eventInfo.IsUserTrigger());
3888 obj->SetProperty("targetUrl", eventInfo.GetTargetUrl());
3889 JSRef<JSObject> handlerObj = JSClass<JSWebWindowNewHandler>::NewInstance();
3890 auto handler = Referenced::Claim(handlerObj->Unwrap<JSWebWindowNewHandler>());
3891 handler->SetEvent(eventInfo);
3892 obj->SetPropertyObject("handler", handlerObj);
3893 return JSRef<JSVal>::Cast(obj);
3894 }
3895
HandleWindowNewEvent(const WebWindowNewEvent * eventInfo)3896 bool HandleWindowNewEvent(const WebWindowNewEvent* eventInfo)
3897 {
3898 if (eventInfo == nullptr) {
3899 return false;
3900 }
3901 auto handler = eventInfo->GetWebWindowNewHandler();
3902 if (handler && !handler->IsFrist()) {
3903 int32_t parentId = -1;
3904 auto controller = JSWebWindowNewHandler::PopController(handler->GetId(), &parentId);
3905 if (!controller.IsEmpty()) {
3906 auto getWebIdFunction = controller->GetProperty("innerGetWebId");
3907 if (getWebIdFunction->IsFunction()) {
3908 auto func = JSRef<JSFunc>::Cast(getWebIdFunction);
3909 auto webId = func->Call(controller, 0, {});
3910 handler->SetWebController(webId->ToNumber<int32_t>());
3911 }
3912 auto completeWindowNewFunction = controller->GetProperty("innerCompleteWindowNew");
3913 if (completeWindowNewFunction->IsFunction()) {
3914 auto func = JSRef<JSFunc>::Cast(completeWindowNewFunction);
3915 JSRef<JSVal> argv[] = { JSRef<JSVal>::Make(ToJSValue(parentId)) };
3916 func->Call(controller, 1, argv);
3917 }
3918 }
3919 return false;
3920 }
3921 return true;
3922 }
3923
OnWindowNew(const JSCallbackInfo & args)3924 void JSWeb::OnWindowNew(const JSCallbackInfo& args)
3925 {
3926 if (args.Length() < 1 || !args[0]->IsFunction()) {
3927 return;
3928 }
3929
3930 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3931 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebWindowNewEvent, 1>>(
3932 JSRef<JSFunc>::Cast(args[0]), WindowNewEventToJSValue);
3933 auto instanceId = Container::CurrentId();
3934 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3935 const std::shared_ptr<BaseEventInfo>& info) {
3936 ContainerScope scope(instanceId);
3937 ACE_SCORING_EVENT("OnWindowNew CallBack");
3938 auto pipelineContext = PipelineContext::GetCurrentContext();
3939 CHECK_NULL_VOID(pipelineContext);
3940 pipelineContext->UpdateCurrentActiveNode(node);
3941 auto* eventInfo = TypeInfoHelper::DynamicCast<WebWindowNewEvent>(info.get());
3942 if (!func || !HandleWindowNewEvent(eventInfo)) {
3943 return;
3944 }
3945 func->Execute(*eventInfo);
3946 };
3947 WebModel::GetInstance()->SetWindowNewEvent(jsCallback);
3948 }
3949
WindowExitEventToJSValue(const WebWindowExitEvent & eventInfo)3950 JSRef<JSVal> WindowExitEventToJSValue(const WebWindowExitEvent& eventInfo)
3951 {
3952 JSRef<JSObject> obj = JSRef<JSObject>::New();
3953 return JSRef<JSVal>::Cast(obj);
3954 }
3955
OnWindowExit(const JSCallbackInfo & args)3956 void JSWeb::OnWindowExit(const JSCallbackInfo& args)
3957 {
3958 if (args.Length() < 1 || !args[0]->IsFunction()) {
3959 return;
3960 }
3961 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
3962 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebWindowExitEvent, 1>>(
3963 JSRef<JSFunc>::Cast(args[0]), WindowExitEventToJSValue);
3964 auto instanceId = Container::CurrentId();
3965 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
3966 const BaseEventInfo* info) {
3967 ContainerScope scope(instanceId);
3968 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
3969 auto pipelineContext = PipelineContext::GetCurrentContext();
3970 CHECK_NULL_VOID(pipelineContext);
3971 pipelineContext->UpdateCurrentActiveNode(node);
3972 auto* eventInfo = TypeInfoHelper::DynamicCast<WebWindowExitEvent>(info);
3973 func->Execute(*eventInfo);
3974 };
3975 WebModel::GetInstance()->SetWindowExitEventId(jsCallback);
3976 }
3977
MultiWindowAccessEnabled(bool isMultiWindowAccessEnable)3978 void JSWeb::MultiWindowAccessEnabled(bool isMultiWindowAccessEnable)
3979 {
3980 WebModel::GetInstance()->SetMultiWindowAccessEnabled(isMultiWindowAccessEnable);
3981 }
3982
AllowWindowOpenMethod(bool isAllowWindowOpenMethod)3983 void JSWeb::AllowWindowOpenMethod(bool isAllowWindowOpenMethod)
3984 {
3985 WebModel::GetInstance()->SetAllowWindowOpenMethod(isAllowWindowOpenMethod);
3986 }
3987
WebCursiveFont(const std::string & cursiveFontFamily)3988 void JSWeb::WebCursiveFont(const std::string& cursiveFontFamily)
3989 {
3990 WebModel::GetInstance()->SetWebCursiveFont(cursiveFontFamily);
3991 }
3992
WebFantasyFont(const std::string & fantasyFontFamily)3993 void JSWeb::WebFantasyFont(const std::string& fantasyFontFamily)
3994 {
3995 WebModel::GetInstance()->SetWebFantasyFont(fantasyFontFamily);
3996 }
3997
WebFixedFont(const std::string & fixedFontFamily)3998 void JSWeb::WebFixedFont(const std::string& fixedFontFamily)
3999 {
4000 WebModel::GetInstance()->SetWebFixedFont(fixedFontFamily);
4001 }
4002
WebSansSerifFont(const std::string & sansSerifFontFamily)4003 void JSWeb::WebSansSerifFont(const std::string& sansSerifFontFamily)
4004 {
4005 WebModel::GetInstance()->SetWebSansSerifFont(sansSerifFontFamily);
4006 }
4007
WebSerifFont(const std::string & serifFontFamily)4008 void JSWeb::WebSerifFont(const std::string& serifFontFamily)
4009 {
4010 WebModel::GetInstance()->SetWebSerifFont(serifFontFamily);
4011 }
4012
WebStandardFont(const std::string & standardFontFamily)4013 void JSWeb::WebStandardFont(const std::string& standardFontFamily)
4014 {
4015 WebModel::GetInstance()->SetWebStandardFont(standardFontFamily);
4016 }
4017
DefaultFixedFontSize(int32_t defaultFixedFontSize)4018 void JSWeb::DefaultFixedFontSize(int32_t defaultFixedFontSize)
4019 {
4020 WebModel::GetInstance()->SetDefaultFixedFontSize(defaultFixedFontSize);
4021 }
4022
DefaultFontSize(int32_t defaultFontSize)4023 void JSWeb::DefaultFontSize(int32_t defaultFontSize)
4024 {
4025 WebModel::GetInstance()->SetDefaultFontSize(defaultFontSize);
4026 }
4027
DefaultTextEncodingFormat(const JSCallbackInfo & args)4028 void JSWeb::DefaultTextEncodingFormat(const JSCallbackInfo& args)
4029 {
4030 if (args.Length() < 1 || !args[0]->IsString()) {
4031 return;
4032 }
4033 std::string textEncodingFormat = args[0]->ToString();
4034 EraseSpace(textEncodingFormat);
4035 if (textEncodingFormat.empty()) {
4036 WebModel::GetInstance()->SetDefaultTextEncodingFormat("UTF-8");
4037 return;
4038 }
4039 WebModel::GetInstance()->SetDefaultTextEncodingFormat(textEncodingFormat);
4040 }
4041
MinFontSize(int32_t minFontSize)4042 void JSWeb::MinFontSize(int32_t minFontSize)
4043 {
4044 WebModel::GetInstance()->SetMinFontSize(minFontSize);
4045 }
4046
MinLogicalFontSize(int32_t minLogicalFontSize)4047 void JSWeb::MinLogicalFontSize(int32_t minLogicalFontSize)
4048 {
4049 WebModel::GetInstance()->SetMinLogicalFontSize(minLogicalFontSize);
4050 }
4051
BlockNetwork(bool isNetworkBlocked)4052 void JSWeb::BlockNetwork(bool isNetworkBlocked)
4053 {
4054 WebModel::GetInstance()->SetBlockNetwork(isNetworkBlocked);
4055 }
4056
PageVisibleEventToJSValue(const PageVisibleEvent & eventInfo)4057 JSRef<JSVal> PageVisibleEventToJSValue(const PageVisibleEvent& eventInfo)
4058 {
4059 JSRef<JSObject> obj = JSRef<JSObject>::New();
4060 obj->SetProperty("url", eventInfo.GetUrl());
4061 return JSRef<JSVal>::Cast(obj);
4062 }
4063
OnPageVisible(const JSCallbackInfo & args)4064 void JSWeb::OnPageVisible(const JSCallbackInfo& args)
4065 {
4066 TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::OnPageVisible init by developer");
4067 if (!args[0]->IsFunction()) {
4068 return;
4069 }
4070 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4071 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<PageVisibleEvent, 1>>(
4072 JSRef<JSFunc>::Cast(args[0]), PageVisibleEventToJSValue);
4073
4074 auto instanceId = Container::CurrentId();
4075 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4076 const std::shared_ptr<BaseEventInfo>& info) {
4077 TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::OnPageVisible uiCallback enter");
4078 ContainerScope scope(instanceId);
4079 auto context = PipelineBase::GetCurrentContext();
4080 CHECK_NULL_VOID(context);
4081 context->UpdateCurrentActiveNode(node);
4082 context->PostAsyncEvent([execCtx, postFunc = func, info]() {
4083 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4084 TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::OnPageVisible async event execute");
4085 auto* eventInfo = TypeInfoHelper::DynamicCast<PageVisibleEvent>(info.get());
4086 postFunc->Execute(*eventInfo);
4087 }, "ArkUIWebPageVisible");
4088 };
4089 WebModel::GetInstance()->SetPageVisibleId(std::move(uiCallback));
4090 }
4091
OnInterceptKeyEvent(const JSCallbackInfo & args)4092 void JSWeb::OnInterceptKeyEvent(const JSCallbackInfo& args)
4093 {
4094 if (args.Length() < 1 || !args[0]->IsFunction()) {
4095 return;
4096 }
4097
4098 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4099 RefPtr<JsKeyFunction> jsOnPreKeyEventFunc = AceType::MakeRefPtr<JsKeyFunction>(JSRef<JSFunc>::Cast(args[0]));
4100 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsOnPreKeyEventFunc), node = frameNode](
4101 KeyEventInfo& keyEventInfo) -> bool {
4102 bool result = false;
4103 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, result);
4104 ACE_SCORING_EVENT("onPreKeyEvent");
4105 auto pipelineContext = PipelineContext::GetCurrentContext();
4106 CHECK_NULL_RETURN(pipelineContext, result);
4107 pipelineContext->UpdateCurrentActiveNode(node);
4108 JSRef<JSVal> obj = func->ExecuteWithValue(keyEventInfo);
4109 if (obj->IsBoolean()) {
4110 result = obj->ToBoolean();
4111 }
4112 return result;
4113 };
4114 WebModel::GetInstance()->SetOnInterceptKeyEventCallback(uiCallback);
4115 }
4116
DataResubmittedEventToJSValue(const DataResubmittedEvent & eventInfo)4117 JSRef<JSVal> DataResubmittedEventToJSValue(const DataResubmittedEvent& eventInfo)
4118 {
4119 JSRef<JSObject> obj = JSRef<JSObject>::New();
4120 JSRef<JSObject> resultObj = JSClass<JSDataResubmitted>::NewInstance();
4121 auto jsDataResubmitted = Referenced::Claim(resultObj->Unwrap<JSDataResubmitted>());
4122 if (!jsDataResubmitted) {
4123 return JSRef<JSVal>::Cast(obj);
4124 }
4125 jsDataResubmitted->SetHandler(eventInfo.GetHandler());
4126 obj->SetPropertyObject("handler", resultObj);
4127 return JSRef<JSVal>::Cast(obj);
4128 }
4129
OnDataResubmitted(const JSCallbackInfo & args)4130 void JSWeb::OnDataResubmitted(const JSCallbackInfo& args)
4131 {
4132 if (args.Length() < 1 || !args[0]->IsFunction()) {
4133 return;
4134 }
4135 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<DataResubmittedEvent, 1>>(
4136 JSRef<JSFunc>::Cast(args[0]), DataResubmittedEventToJSValue);
4137
4138 auto instanceId = Container::CurrentId();
4139 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4140 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4141 const std::shared_ptr<BaseEventInfo>& info) {
4142 ContainerScope scope(instanceId);
4143 auto context = PipelineBase::GetCurrentContext();
4144 CHECK_NULL_VOID(context);
4145 context->UpdateCurrentActiveNode(node);
4146 context->PostSyncEvent([execCtx, postFunc = func, info]() {
4147 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4148 auto* eventInfo = TypeInfoHelper::DynamicCast<DataResubmittedEvent>(info.get());
4149 postFunc->Execute(*eventInfo);
4150 }, "ArkUIWebDataResubmitted");
4151 };
4152 WebModel::GetInstance()->SetOnDataResubmitted(uiCallback);
4153 }
4154
GetPixelFormat(NWeb::ImageColorType colorType)4155 Media::PixelFormat GetPixelFormat(NWeb::ImageColorType colorType)
4156 {
4157 Media::PixelFormat pixelFormat;
4158 switch (colorType) {
4159 case NWeb::ImageColorType::COLOR_TYPE_UNKNOWN:
4160 pixelFormat = Media::PixelFormat::UNKNOWN;
4161 break;
4162 case NWeb::ImageColorType::COLOR_TYPE_RGBA_8888:
4163 pixelFormat = Media::PixelFormat::RGBA_8888;
4164 break;
4165 case NWeb::ImageColorType::COLOR_TYPE_BGRA_8888:
4166 pixelFormat = Media::PixelFormat::BGRA_8888;
4167 break;
4168 default:
4169 pixelFormat = Media::PixelFormat::UNKNOWN;
4170 break;
4171 }
4172 return pixelFormat;
4173 }
4174
GetAlphaType(NWeb::ImageAlphaType alphaType)4175 Media::AlphaType GetAlphaType(NWeb::ImageAlphaType alphaType)
4176 {
4177 Media::AlphaType imageAlphaType;
4178 switch (alphaType) {
4179 case NWeb::ImageAlphaType::ALPHA_TYPE_UNKNOWN:
4180 imageAlphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
4181 break;
4182 case NWeb::ImageAlphaType::ALPHA_TYPE_OPAQUE:
4183 imageAlphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
4184 break;
4185 case NWeb::ImageAlphaType::ALPHA_TYPE_PREMULTIPLIED:
4186 imageAlphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
4187 break;
4188 case NWeb::ImageAlphaType::ALPHA_TYPE_POSTMULTIPLIED:
4189 imageAlphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL;
4190 break;
4191 default:
4192 imageAlphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
4193 break;
4194 }
4195 return imageAlphaType;
4196 }
4197
FaviconReceivedEventToJSValue(const FaviconReceivedEvent & eventInfo)4198 JSRef<JSObject> FaviconReceivedEventToJSValue(const FaviconReceivedEvent& eventInfo)
4199 {
4200 JSRef<JSObject> obj = JSRef<JSObject>::New();
4201 auto data = eventInfo.GetHandler()->GetData();
4202 size_t width = eventInfo.GetHandler()->GetWidth();
4203 size_t height = eventInfo.GetHandler()->GetHeight();
4204 int colorType = eventInfo.GetHandler()->GetColorType();
4205 int alphaType = eventInfo.GetHandler()->GetAlphaType();
4206
4207 Media::InitializationOptions opt;
4208 opt.size.width = static_cast<int32_t>(width);
4209 opt.size.height = static_cast<int32_t>(height);
4210 opt.pixelFormat = GetPixelFormat(NWeb::ImageColorType(colorType));
4211 opt.alphaType = GetAlphaType(NWeb::ImageAlphaType(alphaType));
4212 opt.editable = true;
4213 auto pixelMap = Media::PixelMap::Create(opt);
4214 if (pixelMap == nullptr) {
4215 return JSRef<JSVal>::Cast(obj);
4216 }
4217 uint32_t stride = width << 2;
4218 uint64_t bufferSize = stride * height;
4219 pixelMap->WritePixels(static_cast<const uint8_t*>(data), bufferSize);
4220 std::shared_ptr<Media::PixelMap> pixelMapToJs(pixelMap.release());
4221 auto engine = EngineHelper::GetCurrentEngine();
4222 if (!engine) {
4223 return JSRef<JSVal>::Cast(obj);
4224 }
4225 NativeEngine* nativeEngine = engine->GetNativeEngine();
4226 napi_env env = reinterpret_cast<napi_env>(nativeEngine);
4227 napi_value napiValue = OHOS::Media::PixelMapNapi::CreatePixelMap(env, pixelMapToJs);
4228 auto jsPixelMap = JsConverter::ConvertNapiValueToJsVal(napiValue);
4229 obj->SetPropertyObject("favicon", jsPixelMap);
4230 return JSRef<JSObject>::Cast(obj);
4231 }
4232
OnFaviconReceived(const JSCallbackInfo & args)4233 void JSWeb::OnFaviconReceived(const JSCallbackInfo& args)
4234 {
4235 if (args.Length() < 1 || !args[0]->IsFunction()) {
4236 return;
4237 }
4238 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4239 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FaviconReceivedEvent, 1>>(
4240 JSRef<JSFunc>::Cast(args[0]), FaviconReceivedEventToJSValue);
4241
4242 auto instanceId = Container::CurrentId();
4243 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4244 const std::shared_ptr<BaseEventInfo>& info) {
4245 ContainerScope scope(instanceId);
4246 auto context = PipelineBase::GetCurrentContext();
4247 CHECK_NULL_VOID(context);
4248 context->UpdateCurrentActiveNode(node);
4249 context->PostAsyncEvent([execCtx, postFunc = func, info]() {
4250 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4251 auto* eventInfo = TypeInfoHelper::DynamicCast<FaviconReceivedEvent>(info.get());
4252 postFunc->Execute(*eventInfo);
4253 }, "ArkUIWebFaviconReceived");
4254 };
4255 WebModel::GetInstance()->SetFaviconReceivedId(uiCallback);
4256 }
4257
TouchIconUrlEventToJSValue(const TouchIconUrlEvent & eventInfo)4258 JSRef<JSVal> TouchIconUrlEventToJSValue(const TouchIconUrlEvent& eventInfo)
4259 {
4260 JSRef<JSObject> obj = JSRef<JSObject>::New();
4261 obj->SetProperty("url", eventInfo.GetUrl());
4262 obj->SetProperty("precomposed", eventInfo.GetPreComposed());
4263 return JSRef<JSVal>::Cast(obj);
4264 }
4265
OnTouchIconUrlReceived(const JSCallbackInfo & args)4266 void JSWeb::OnTouchIconUrlReceived(const JSCallbackInfo& args)
4267 {
4268 if (!args[0]->IsFunction()) {
4269 return;
4270 }
4271 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4272 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<TouchIconUrlEvent, 1>>(
4273 JSRef<JSFunc>::Cast(args[0]), TouchIconUrlEventToJSValue);
4274
4275 auto instanceId = Container::CurrentId();
4276 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4277 const std::shared_ptr<BaseEventInfo>& info) {
4278 ContainerScope scope(instanceId);
4279 auto context = PipelineBase::GetCurrentContext();
4280 CHECK_NULL_VOID(context);
4281 context->UpdateCurrentActiveNode(node);
4282 context->PostAsyncEvent([execCtx, postFunc = func, info]() {
4283 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4284 auto* eventInfo = TypeInfoHelper::DynamicCast<TouchIconUrlEvent>(info.get());
4285 postFunc->Execute(*eventInfo);
4286 }, "ArkUIWebTouchIconUrlReceived");
4287 };
4288 WebModel::GetInstance()->SetTouchIconUrlId(uiCallback);
4289 }
4290
DarkMode(int32_t darkMode)4291 void JSWeb::DarkMode(int32_t darkMode)
4292 {
4293 auto mode = WebDarkMode::Off;
4294 switch (darkMode) {
4295 case 0:
4296 mode = WebDarkMode::Off;
4297 break;
4298 case 1:
4299 mode = WebDarkMode::On;
4300 break;
4301 case 2:
4302 mode = WebDarkMode::Auto;
4303 break;
4304 default:
4305 mode = WebDarkMode::Off;
4306 break;
4307 }
4308 WebModel::GetInstance()->SetDarkMode(mode);
4309 }
4310
ForceDarkAccess(bool access)4311 void JSWeb::ForceDarkAccess(bool access)
4312 {
4313 WebModel::GetInstance()->SetForceDarkAccess(access);
4314 }
4315
HorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled)4316 void JSWeb::HorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled)
4317 {
4318 WebModel::GetInstance()->SetHorizontalScrollBarAccessEnabled(isHorizontalScrollBarAccessEnabled);
4319 }
4320
VerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled)4321 void JSWeb::VerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled)
4322 {
4323 WebModel::GetInstance()->SetVerticalScrollBarAccessEnabled(isVerticalScrollBarAccessEnabled);
4324 }
4325
AudioStateChangedEventToJSValue(const AudioStateChangedEvent & eventInfo)4326 JSRef<JSVal> AudioStateChangedEventToJSValue(const AudioStateChangedEvent& eventInfo)
4327 {
4328 JSRef<JSObject> obj = JSRef<JSObject>::New();
4329 obj->SetProperty("playing", eventInfo.IsPlaying());
4330 return JSRef<JSVal>::Cast(obj);
4331 }
4332
OnAudioStateChanged(const JSCallbackInfo & args)4333 void JSWeb::OnAudioStateChanged(const JSCallbackInfo& args)
4334 {
4335 if (!args[0]->IsFunction()) {
4336 return;
4337 }
4338
4339 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4340 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<AudioStateChangedEvent, 1>>(
4341 JSRef<JSFunc>::Cast(args[0]), AudioStateChangedEventToJSValue);
4342
4343 auto instanceId = Container::CurrentId();
4344 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4345 const std::shared_ptr<BaseEventInfo>& info) {
4346 ContainerScope scope(instanceId);
4347 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4348 auto pipelineContext = PipelineContext::GetCurrentContext();
4349 CHECK_NULL_VOID(pipelineContext);
4350 pipelineContext->UpdateCurrentActiveNode(node);
4351 auto* eventInfo = TypeInfoHelper::DynamicCast<AudioStateChangedEvent>(info.get());
4352 func->Execute(*eventInfo);
4353 };
4354 WebModel::GetInstance()->SetAudioStateChangedId(std::move(uiCallback));
4355 }
4356
MediaOptions(const JSCallbackInfo & args)4357 void JSWeb::MediaOptions(const JSCallbackInfo& args)
4358 {
4359 if (!args[0]->IsObject()) {
4360 return;
4361 }
4362 auto paramObject = JSRef<JSObject>::Cast(args[0]);
4363 auto resumeIntervalObj = paramObject->GetProperty("resumeInterval");
4364 if (resumeIntervalObj->IsNumber()) {
4365 int32_t resumeInterval = resumeIntervalObj->ToNumber<int32_t>();
4366 WebModel::GetInstance()->SetAudioResumeInterval(resumeInterval);
4367 }
4368
4369 auto audioExclusiveObj = paramObject->GetProperty("audioExclusive");
4370 if (audioExclusiveObj->IsBoolean()) {
4371 bool audioExclusive = audioExclusiveObj->ToBoolean();
4372 WebModel::GetInstance()->SetAudioExclusive(audioExclusive);
4373 }
4374 }
4375
FirstContentfulPaintEventToJSValue(const FirstContentfulPaintEvent & eventInfo)4376 JSRef<JSVal> FirstContentfulPaintEventToJSValue(const FirstContentfulPaintEvent& eventInfo)
4377 {
4378 JSRef<JSObject> obj = JSRef<JSObject>::New();
4379 obj->SetProperty<int64_t>("navigationStartTick", eventInfo.GetNavigationStartTick());
4380 obj->SetProperty<int64_t>("firstContentfulPaintMs", eventInfo.GetFirstContentfulPaintMs());
4381 return JSRef<JSVal>::Cast(obj);
4382 }
4383
OnFirstContentfulPaint(const JSCallbackInfo & args)4384 void JSWeb::OnFirstContentfulPaint(const JSCallbackInfo& args)
4385 {
4386 if (!args[0]->IsFunction()) {
4387 return;
4388 }
4389 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4390 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FirstContentfulPaintEvent, 1>>(
4391 JSRef<JSFunc>::Cast(args[0]), FirstContentfulPaintEventToJSValue);
4392
4393 auto instanceId = Container::CurrentId();
4394 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4395 const std::shared_ptr<BaseEventInfo>& info) {
4396 ContainerScope scope(instanceId);
4397 auto context = PipelineBase::GetCurrentContext();
4398 CHECK_NULL_VOID(context);
4399 context->UpdateCurrentActiveNode(node);
4400 context->PostAsyncEvent([execCtx, postFunc = func, info]() {
4401 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4402 auto* eventInfo = TypeInfoHelper::DynamicCast<FirstContentfulPaintEvent>(info.get());
4403 postFunc->Execute(*eventInfo);
4404 }, "ArkUIWebFirstContentfulPaint");
4405 };
4406 WebModel::GetInstance()->SetFirstContentfulPaintId(std::move(uiCallback));
4407 }
4408
FirstMeaningfulPaintEventToJSValue(const FirstMeaningfulPaintEvent & eventInfo)4409 JSRef<JSVal> FirstMeaningfulPaintEventToJSValue(const FirstMeaningfulPaintEvent& eventInfo)
4410 {
4411 JSRef<JSObject> obj = JSRef<JSObject>::New();
4412 obj->SetProperty("navigationStartTime", eventInfo.GetNavigationStartTime());
4413 obj->SetProperty("firstMeaningfulPaintTime", eventInfo.GetFirstMeaningfulPaintTime());
4414 return JSRef<JSVal>::Cast(obj);
4415 }
4416
OnFirstMeaningfulPaint(const JSCallbackInfo & args)4417 void JSWeb::OnFirstMeaningfulPaint(const JSCallbackInfo& args)
4418 {
4419 if (args.Length() < 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsFunction()) {
4420 return;
4421 }
4422 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4423 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<FirstMeaningfulPaintEvent, 1>>(
4424 JSRef<JSFunc>::Cast(args[0]), FirstMeaningfulPaintEventToJSValue);
4425 auto instanceId = Container::CurrentId();
4426 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4427 const std::shared_ptr<BaseEventInfo>& info) {
4428 ContainerScope scope(instanceId);
4429 auto context = PipelineBase::GetCurrentContext();
4430 CHECK_NULL_VOID(context);
4431 context->UpdateCurrentActiveNode(node);
4432 context->PostAsyncEvent([execCtx, postFunc = func, info]() {
4433 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4434 auto* eventInfo = TypeInfoHelper::DynamicCast<FirstMeaningfulPaintEvent>(info.get());
4435 postFunc->Execute(*eventInfo);
4436 }, "ArkUIWebFirstMeaningfulPaint");
4437 };
4438 WebModel::GetInstance()->SetFirstMeaningfulPaintId(std::move(uiCallback));
4439 }
4440
LargestContentfulPaintEventToJSValue(const LargestContentfulPaintEvent & eventInfo)4441 JSRef<JSVal> LargestContentfulPaintEventToJSValue(const LargestContentfulPaintEvent& eventInfo)
4442 {
4443 JSRef<JSObject> obj = JSRef<JSObject>::New();
4444 obj->SetProperty("navigationStartTime", eventInfo.GetNavigationStartTime());
4445 obj->SetProperty("largestImagePaintTime", eventInfo.GetLargestImagePaintTime());
4446 obj->SetProperty("largestTextPaintTime", eventInfo.GetLargestTextPaintTime());
4447 obj->SetProperty("largestImageLoadStartTime", eventInfo.GetLargestImageLoadStartTime());
4448 obj->SetProperty("largestImageLoadEndTime", eventInfo.GetLargestImageLoadEndTime());
4449 obj->SetProperty("imageBPP", eventInfo.GetImageBPP());
4450 return JSRef<JSVal>::Cast(obj);
4451 }
4452
OnLargestContentfulPaint(const JSCallbackInfo & args)4453 void JSWeb::OnLargestContentfulPaint(const JSCallbackInfo& args)
4454 {
4455 if (args.Length() < 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsFunction()) {
4456 return;
4457 }
4458 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4459 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LargestContentfulPaintEvent, 1>>(
4460 JSRef<JSFunc>::Cast(args[0]), LargestContentfulPaintEventToJSValue);
4461 auto instanceId = Container::CurrentId();
4462 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4463 const std::shared_ptr<BaseEventInfo>& info) {
4464 ContainerScope scope(instanceId);
4465 auto context = PipelineBase::GetCurrentContext();
4466 CHECK_NULL_VOID(context);
4467 context->UpdateCurrentActiveNode(node);
4468 context->PostAsyncEvent([execCtx, postFunc = func, info]() {
4469 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4470 auto* eventInfo = TypeInfoHelper::DynamicCast<LargestContentfulPaintEvent>(info.get());
4471 postFunc->Execute(*eventInfo);
4472 }, "ArkUIWebLargestContentfulPaint");
4473 };
4474 WebModel::GetInstance()->SetLargestContentfulPaintId(std::move(uiCallback));
4475 }
4476
SafeBrowsingCheckResultEventToJSValue(const SafeBrowsingCheckResultEvent & eventInfo)4477 JSRef<JSVal> SafeBrowsingCheckResultEventToJSValue(const SafeBrowsingCheckResultEvent& eventInfo)
4478 {
4479 JSRef<JSObject> obj = JSRef<JSObject>::New();
4480 obj->SetProperty("threatType", eventInfo.GetThreatType());
4481 return JSRef<JSVal>::Cast(obj);
4482 }
4483
OnSafeBrowsingCheckResult(const JSCallbackInfo & args)4484 void JSWeb::OnSafeBrowsingCheckResult(const JSCallbackInfo& args)
4485 {
4486 if (args.Length() < 1 || !args[0]->IsFunction()) {
4487 return;
4488 }
4489 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4490 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<SafeBrowsingCheckResultEvent, 1>>(
4491 JSRef<JSFunc>::Cast(args[0]), SafeBrowsingCheckResultEventToJSValue);
4492
4493 auto instanceId = Container::CurrentId();
4494 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4495 const std::shared_ptr<BaseEventInfo>& info) {
4496 ContainerScope scope(instanceId);
4497 auto context = PipelineBase::GetCurrentContext();
4498 CHECK_NULL_VOID(context);
4499 context->UpdateCurrentActiveNode(node);
4500 context->PostAsyncEvent([execCtx, postFunc = func, info]() {
4501 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4502 auto* eventInfo = TypeInfoHelper::DynamicCast<SafeBrowsingCheckResultEvent>(info.get());
4503 postFunc->Execute(*eventInfo);
4504 }, "ArkUIWebSafeBrowsingCheckResult");
4505 };
4506 WebModel::GetInstance()->SetSafeBrowsingCheckResultId(std::move(uiCallback));
4507 }
4508
NavigationEntryCommittedEventToJSValue(const NavigationEntryCommittedEvent & eventInfo)4509 JSRef<JSVal> NavigationEntryCommittedEventToJSValue(const NavigationEntryCommittedEvent& eventInfo)
4510 {
4511 JSRef<JSObject> obj = JSRef<JSObject>::New();
4512 obj->SetProperty("isMainFrame", eventInfo.IsMainFrame());
4513 obj->SetProperty("isSameDocument", eventInfo.IsSameDocument());
4514 obj->SetProperty("didReplaceEntry", eventInfo.DidReplaceEntry());
4515 obj->SetProperty("navigationType", static_cast<int>(eventInfo.GetNavigationType()));
4516 obj->SetProperty("url", eventInfo.GetUrl());
4517 return JSRef<JSVal>::Cast(obj);
4518 }
4519
OnNavigationEntryCommitted(const JSCallbackInfo & args)4520 void JSWeb::OnNavigationEntryCommitted(const JSCallbackInfo& args)
4521 {
4522 if (!args[0]->IsFunction()) {
4523 return;
4524 }
4525 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4526 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<NavigationEntryCommittedEvent, 1>>(
4527 JSRef<JSFunc>::Cast(args[0]), NavigationEntryCommittedEventToJSValue);
4528
4529 auto instanceId = Container::CurrentId();
4530 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4531 const std::shared_ptr<BaseEventInfo>& info) {
4532 ContainerScope scope(instanceId);
4533 auto context = PipelineBase::GetCurrentContext();
4534 CHECK_NULL_VOID(context);
4535 context->UpdateCurrentActiveNode(node);
4536 context->PostAsyncEvent([execCtx, postFunc = func, info]() {
4537 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4538 auto* eventInfo = TypeInfoHelper::DynamicCast<NavigationEntryCommittedEvent>(info.get());
4539 postFunc->Execute(*eventInfo);
4540 }, "ArkUIWebNavigationEntryCommitted");
4541 };
4542 WebModel::GetInstance()->SetNavigationEntryCommittedId(std::move(uiCallback));
4543 }
4544
IntelligentTrackingPreventionResultEventToJSValue(const IntelligentTrackingPreventionResultEvent & eventInfo)4545 JSRef<JSVal> IntelligentTrackingPreventionResultEventToJSValue(
4546 const IntelligentTrackingPreventionResultEvent& eventInfo)
4547 {
4548 JSRef<JSObject> obj = JSRef<JSObject>::New();
4549 obj->SetProperty("host", eventInfo.GetHost());
4550 obj->SetProperty("trackerHost", eventInfo.GetTrackerHost());
4551 return JSRef<JSVal>::Cast(obj);
4552 }
4553
OnIntelligentTrackingPreventionResult(const JSCallbackInfo & args)4554 void JSWeb::OnIntelligentTrackingPreventionResult(const JSCallbackInfo& args)
4555 {
4556 if (args.Length() < 1 || !args[0]->IsFunction()) {
4557 return;
4558 }
4559 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4560 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<IntelligentTrackingPreventionResultEvent, 1>>(
4561 JSRef<JSFunc>::Cast(args[0]), IntelligentTrackingPreventionResultEventToJSValue);
4562
4563 auto instanceId = Container::CurrentId();
4564 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4565 const std::shared_ptr<BaseEventInfo>& info) {
4566 ContainerScope scope(instanceId);
4567 auto context = PipelineBase::GetCurrentContext();
4568 CHECK_NULL_VOID(context);
4569 context->UpdateCurrentActiveNode(node);
4570 context->PostAsyncEvent([execCtx, postFunc = func, info]() {
4571 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4572 auto* eventInfo = TypeInfoHelper::DynamicCast<IntelligentTrackingPreventionResultEvent>(info.get());
4573 postFunc->Execute(*eventInfo);
4574 }, "ArkUIWebIntelligentTrackingPreventionResult");
4575 };
4576 WebModel::GetInstance()->SetIntelligentTrackingPreventionResultId(std::move(uiCallback));
4577 }
4578
OnControllerAttached(const JSCallbackInfo & args)4579 void JSWeb::OnControllerAttached(const JSCallbackInfo& args)
4580 {
4581 if (!args[0]->IsFunction()) {
4582 return;
4583 }
4584 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4585 auto jsFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(args[0]));
4586 auto instanceId = Container::CurrentId();
4587 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]() {
4588 ContainerScope scope(instanceId);
4589 auto context = PipelineBase::GetCurrentContext();
4590 CHECK_NULL_VOID(context);
4591 context->UpdateCurrentActiveNode(node);
4592 context->PostSyncEvent([execCtx, postFunc = func]() {
4593 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4594 postFunc->Execute();
4595 }, "ArkUIWebControllerAttached");
4596 };
4597 WebModel::GetInstance()->SetOnControllerAttached(std::move(uiCallback));
4598 }
4599
EmbedLifecycleChangeToJSValue(const NativeEmbedDataInfo & eventInfo)4600 JSRef<JSVal> EmbedLifecycleChangeToJSValue(const NativeEmbedDataInfo& eventInfo)
4601 {
4602 JSRef<JSObject> obj = JSRef<JSObject>::New();
4603 obj->SetProperty("status", static_cast<int32_t>(eventInfo.GetStatus()));
4604 obj->SetProperty("surfaceId", eventInfo.GetSurfaceId());
4605 obj->SetProperty("embedId", eventInfo.GetEmbedId());
4606
4607 JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
4608 JSRef<JSObject> requestObj = objectTemplate->NewInstance();
4609 requestObj->SetProperty("id", eventInfo.GetEmebdInfo().id);
4610 requestObj->SetProperty("type", eventInfo.GetEmebdInfo().type);
4611 requestObj->SetProperty("src", eventInfo.GetEmebdInfo().src);
4612 requestObj->SetProperty("tag", eventInfo.GetEmebdInfo().tag);
4613 requestObj->SetProperty("width", eventInfo.GetEmebdInfo().width);
4614 requestObj->SetProperty("height", eventInfo.GetEmebdInfo().height);
4615 requestObj->SetProperty("url", eventInfo.GetEmebdInfo().url);
4616
4617 JSRef<JSObject> positionObj = objectTemplate->NewInstance();
4618 positionObj->SetProperty("x", eventInfo.GetEmebdInfo().x);
4619 positionObj->SetProperty("y", eventInfo.GetEmebdInfo().y);
4620 requestObj->SetPropertyObject("position", positionObj);
4621
4622 auto params = eventInfo.GetEmebdInfo().params;
4623 JSRef<JSObject> paramsObj = objectTemplate->NewInstance();
4624 for (const auto& item : params) {
4625 paramsObj->SetProperty(item.first.c_str(), item.second.c_str());
4626 }
4627 requestObj->SetPropertyObject("params", paramsObj);
4628
4629 obj->SetPropertyObject("info", requestObj);
4630
4631 return JSRef<JSVal>::Cast(obj);
4632 }
4633
EmbedVisibilityChangeToJSValue(const NativeEmbedVisibilityInfo & visibilityInfo)4634 JSRef<JSVal> EmbedVisibilityChangeToJSValue(const NativeEmbedVisibilityInfo& visibilityInfo)
4635 {
4636 JSRef<JSObject> obj = JSRef<JSObject>::New();
4637 obj->SetProperty("visibility", visibilityInfo.GetVisibility());
4638 obj->SetProperty("embedId", visibilityInfo.GetEmbedId());
4639
4640 return JSRef<JSVal>::Cast(obj);
4641 }
4642
OnNativeEmbedLifecycleChange(const JSCallbackInfo & args)4643 void JSWeb::OnNativeEmbedLifecycleChange(const JSCallbackInfo& args)
4644 {
4645 if (args.Length() < 1 || !args[0]->IsFunction()) {
4646 return;
4647 }
4648 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<NativeEmbedDataInfo, 1>>(
4649 JSRef<JSFunc>::Cast(args[0]), EmbedLifecycleChangeToJSValue);
4650 auto instanceId = Container::CurrentId();
4651 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId](
4652 const BaseEventInfo* info) {
4653 ContainerScope scope(instanceId);
4654 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4655 auto* eventInfo = TypeInfoHelper::DynamicCast<NativeEmbedDataInfo>(info);
4656 func->Execute(*eventInfo);
4657 };
4658 WebModel::GetInstance()->SetNativeEmbedLifecycleChangeId(jsCallback);
4659 }
4660
OnNativeEmbedVisibilityChange(const JSCallbackInfo & args)4661 void JSWeb::OnNativeEmbedVisibilityChange(const JSCallbackInfo& args)
4662 {
4663 if (args.Length() < 1 || !args[0]->IsFunction()) {
4664 return;
4665 }
4666 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<NativeEmbedVisibilityInfo, 1>>(
4667 JSRef<JSFunc>::Cast(args[0]), EmbedVisibilityChangeToJSValue);
4668 auto instanceId = Container::CurrentId();
4669 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId](
4670 const BaseEventInfo* info) {
4671 ContainerScope scope(instanceId);
4672 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4673 auto* eventInfo = TypeInfoHelper::DynamicCast<NativeEmbedVisibilityInfo>(info);
4674 func->Execute(*eventInfo);
4675 };
4676 WebModel::GetInstance()->SetNativeEmbedVisibilityChangeId(jsCallback);
4677 }
4678
CreateTouchInfo(const TouchLocationInfo & touchInfo,TouchEventInfo & info)4679 JSRef<JSObject> CreateTouchInfo(const TouchLocationInfo& touchInfo, TouchEventInfo& info)
4680 {
4681 JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
4682 objectTemplate->SetInternalFieldCount(1);
4683 JSRef<JSObject> touchInfoObj = objectTemplate->NewInstance();
4684 const OHOS::Ace::Offset& globalLocation = touchInfo.GetGlobalLocation();
4685 const OHOS::Ace::Offset& localLocation = touchInfo.GetLocalLocation();
4686 const OHOS::Ace::Offset& screenLocation = touchInfo.GetScreenLocation();
4687 touchInfoObj->SetProperty<int32_t>("type", static_cast<int32_t>(touchInfo.GetTouchType()));
4688 touchInfoObj->SetProperty<int32_t>("id", touchInfo.GetFingerId());
4689 touchInfoObj->SetProperty<double>("displayX", screenLocation.GetX());
4690 touchInfoObj->SetProperty<double>("displayY", screenLocation.GetY());
4691 touchInfoObj->SetProperty<double>("windowX", globalLocation.GetX());
4692 touchInfoObj->SetProperty<double>("windowY", globalLocation.GetY());
4693 touchInfoObj->SetProperty<double>("screenX", globalLocation.GetX());
4694 touchInfoObj->SetProperty<double>("screenY", globalLocation.GetY());
4695 touchInfoObj->SetProperty<double>("x", localLocation.GetX());
4696 touchInfoObj->SetProperty<double>("y", localLocation.GetY());
4697 touchInfoObj->Wrap<TouchEventInfo>(&info);
4698 return touchInfoObj;
4699 }
4700
NativeEmbeadTouchToJSValue(const NativeEmbeadTouchInfo & eventInfo)4701 JSRef<JSVal> NativeEmbeadTouchToJSValue(const NativeEmbeadTouchInfo& eventInfo)
4702 {
4703 JSRef<JSObject> obj = JSRef<JSObject>::New();
4704 obj->SetProperty("embedId", eventInfo.GetEmbedId());
4705 auto info = eventInfo.GetTouchEventInfo();
4706 JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
4707 JSRef<JSObject> eventObj = objectTemplate->NewInstance();
4708 JSRef<JSArray> touchArr = JSRef<JSArray>::New();
4709 JSRef<JSArray> changeTouchArr = JSRef<JSArray>::New();
4710 eventObj->SetProperty("source", static_cast<int32_t>(info.GetSourceDevice()));
4711 eventObj->SetProperty("timestamp", static_cast<double>(GetSysTimestamp()));
4712 auto target = CreateEventTargetObject(info);
4713 eventObj->SetPropertyObject("target", target);
4714 eventObj->SetProperty("pressure", info.GetForce());
4715 eventObj->SetProperty("sourceTool", static_cast<int32_t>(info.GetSourceTool()));
4716 eventObj->SetProperty("targetDisplayId", static_cast<int32_t>(info.GetTargetDisplayId()));
4717 eventObj->SetProperty("deviceId", static_cast<int64_t>(info.GetDeviceId()));
4718
4719 if (info.GetChangedTouches().empty()) {
4720 return JSRef<JSVal>::Cast(obj);
4721 }
4722 uint32_t index = 0;
4723 TouchLocationInfo changeTouch = info.GetChangedTouches().back();
4724 JSRef<JSObject> changeTouchElement = CreateTouchInfo(changeTouch, info);
4725 changeTouchArr->SetValueAt(index, changeTouchElement);
4726 if (info.GetChangedTouches().size() > 0) {
4727 eventObj->SetProperty("type", static_cast<int32_t>(changeTouch.GetTouchType()));
4728 }
4729
4730 const std::list<TouchLocationInfo>& touchList = info.GetTouches();
4731 for (const TouchLocationInfo& location : touchList) {
4732 if (location.GetFingerId() == changeTouch.GetFingerId()) {
4733 JSRef<JSObject> touchElement = CreateTouchInfo(changeTouch, info);
4734 touchArr->SetValueAt(index++, touchElement);
4735 } else {
4736 JSRef<JSObject> touchElement = CreateTouchInfo(location, info);
4737 touchArr->SetValueAt(index++, touchElement);
4738 }
4739 }
4740 eventObj->SetPropertyObject("touches", touchArr);
4741 eventObj->SetPropertyObject("changedTouches", changeTouchArr);
4742 obj->SetPropertyObject("touchEvent", eventObj);
4743 JSRef<JSObject> requestObj = JSClass<JSNativeEmbedGestureRequest>::NewInstance();
4744 auto requestEvent = Referenced::Claim(requestObj->Unwrap<JSNativeEmbedGestureRequest>());
4745 requestEvent->SetResult(eventInfo.GetResult());
4746 obj->SetPropertyObject("result", requestObj);
4747 return JSRef<JSVal>::Cast(obj);
4748 }
4749
OnNativeEmbedGestureEvent(const JSCallbackInfo & args)4750 void JSWeb::OnNativeEmbedGestureEvent(const JSCallbackInfo& args)
4751 {
4752 if (args.Length() < 1 || !args[0]->IsFunction()) {
4753 return;
4754 }
4755 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<NativeEmbeadTouchInfo, 1>>(
4756 JSRef<JSFunc>::Cast(args[0]), NativeEmbeadTouchToJSValue);
4757 auto instanceId = Container::CurrentId();
4758 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId](
4759 const BaseEventInfo* info) {
4760 ContainerScope scope(instanceId);
4761 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4762 auto* eventInfo = TypeInfoHelper::DynamicCast<NativeEmbeadTouchInfo>(info);
4763 func->Execute(*eventInfo);
4764 };
4765 WebModel::GetInstance()->SetNativeEmbedGestureEventId(jsCallback);
4766 }
4767
4768
OverScrollEventToJSValue(const WebOnOverScrollEvent & eventInfo)4769 JSRef<JSVal> OverScrollEventToJSValue(const WebOnOverScrollEvent& eventInfo)
4770 {
4771 JSRef<JSObject> obj = JSRef<JSObject>::New();
4772 obj->SetProperty("xOffset", eventInfo.GetX());
4773 obj->SetProperty("yOffset", eventInfo.GetY());
4774 return JSRef<JSVal>::Cast(obj);
4775 }
4776
OnOverScroll(const JSCallbackInfo & args)4777 void JSWeb::OnOverScroll(const JSCallbackInfo& args)
4778 {
4779 if (args.Length() < 1 || !args[0]->IsFunction()) {
4780 return;
4781 }
4782 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4783 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<WebOnOverScrollEvent, 1>>(
4784 JSRef<JSFunc>::Cast(args[0]), OverScrollEventToJSValue);
4785 auto instanceId = Container::CurrentId();
4786 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4787 const BaseEventInfo* info) {
4788 ContainerScope scope(instanceId);
4789 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
4790 auto pipelineContext = PipelineContext::GetCurrentContext();
4791 CHECK_NULL_VOID(pipelineContext);
4792 pipelineContext->UpdateCurrentActiveNode(node);
4793 auto* eventInfo = TypeInfoHelper::DynamicCast<WebOnOverScrollEvent>(info);
4794 func->Execute(*eventInfo);
4795 };
4796 WebModel::GetInstance()->SetOverScrollId(jsCallback);
4797 }
4798
SetLayoutMode(int32_t layoutMode)4799 void JSWeb::SetLayoutMode(int32_t layoutMode)
4800 {
4801 auto mode = WebLayoutMode::NONE;
4802 switch (layoutMode) {
4803 case 0:
4804 mode = WebLayoutMode::NONE;
4805 break;
4806 case 1:
4807 mode = WebLayoutMode::FIT_CONTENT;
4808 break;
4809 default:
4810 mode = WebLayoutMode::NONE;
4811 break;
4812 }
4813 WebModel::GetInstance()->SetLayoutMode(mode);
4814 }
4815
SetNestedScroll(const JSCallbackInfo & args)4816 void JSWeb::SetNestedScroll(const JSCallbackInfo& args)
4817 {
4818 NestedScrollOptions nestedOpt = {
4819 .forward = NestedScrollMode::SELF_ONLY,
4820 .backward = NestedScrollMode::SELF_ONLY,
4821 };
4822 if (args.Length() < 1 || !args[0]->IsObject()) {
4823 WebModel::GetInstance()->SetNestedScroll(nestedOpt);
4824 return;
4825 }
4826 JSRef<JSObject> obj = JSRef<JSObject>::Cast(args[0]);
4827 int32_t froward = 0;
4828 JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollForward"), froward);
4829 if (froward < static_cast<int32_t>(NestedScrollMode::SELF_ONLY) ||
4830 froward > static_cast<int32_t>(NestedScrollMode::PARALLEL)) {
4831 froward = 0;
4832 }
4833 int32_t backward = 0;
4834 JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollBackward"), backward);
4835 if (backward < static_cast<int32_t>(NestedScrollMode::SELF_ONLY) ||
4836 backward > static_cast<int32_t>(NestedScrollMode::PARALLEL)) {
4837 backward = 0;
4838 }
4839 nestedOpt.forward = static_cast<NestedScrollMode>(froward);
4840 nestedOpt.backward = static_cast<NestedScrollMode>(backward);
4841 WebModel::GetInstance()->SetNestedScroll(nestedOpt);
4842 args.ReturnSelf();
4843 }
4844
SetMetaViewport(const JSCallbackInfo & args)4845 void JSWeb::SetMetaViewport(const JSCallbackInfo& args)
4846 {
4847 if (args.Length() < 1 || !args[0]->IsBoolean()) {
4848 return;
4849 }
4850 bool enabled = args[0]->ToBoolean();
4851 WebModel::GetInstance()->SetMetaViewport(enabled);
4852 }
4853
ParseScriptItems(const JSCallbackInfo & args,ScriptItems & scriptItems)4854 void JSWeb::ParseScriptItems(const JSCallbackInfo& args, ScriptItems& scriptItems)
4855 {
4856 if (args.Length() != 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsArray()) {
4857 return;
4858 }
4859 auto paramArray = JSRef<JSArray>::Cast(args[0]);
4860 size_t length = paramArray->Length();
4861 if (length == 0) {
4862 return;
4863 }
4864 std::string script;
4865 std::vector<std::string> scriptRules;
4866 for (size_t i = 0; i < length; i++) {
4867 auto item = paramArray->GetValueAt(i);
4868 if (!item->IsObject()) {
4869 return;
4870 }
4871 auto itemObject = JSRef<JSObject>::Cast(item);
4872 JSRef<JSVal> jsScript = itemObject->GetProperty("script");
4873 JSRef<JSVal> jsScriptRules = itemObject->GetProperty("scriptRules");
4874 if (!jsScriptRules->IsArray() || JSRef<JSArray>::Cast(jsScriptRules)->Length() == 0) {
4875 return;
4876 }
4877 if (!JSViewAbstract::ParseJsString(jsScript, script)) {
4878 return;
4879 }
4880 scriptRules.clear();
4881 if (!JSViewAbstract::ParseJsStrArray(jsScriptRules, scriptRules)) {
4882 return;
4883 }
4884 if (scriptItems.find(script) == scriptItems.end()) {
4885 scriptItems.insert(std::make_pair(script, scriptRules));
4886 }
4887 }
4888 }
4889
JavaScriptOnDocumentStart(const JSCallbackInfo & args)4890 void JSWeb::JavaScriptOnDocumentStart(const JSCallbackInfo& args)
4891 {
4892 ScriptItems scriptItems;
4893 ParseScriptItems(args, scriptItems);
4894 WebModel::GetInstance()->JavaScriptOnDocumentStart(scriptItems);
4895 }
4896
JavaScriptOnDocumentEnd(const JSCallbackInfo & args)4897 void JSWeb::JavaScriptOnDocumentEnd(const JSCallbackInfo& args)
4898 {
4899 ScriptItems scriptItems;
4900 ParseScriptItems(args, scriptItems);
4901 WebModel::GetInstance()->JavaScriptOnDocumentEnd(scriptItems);
4902 }
4903
OnOverrideUrlLoading(const JSCallbackInfo & args)4904 void JSWeb::OnOverrideUrlLoading(const JSCallbackInfo& args)
4905 {
4906 if (args.Length() < 1 || !args[0]->IsFunction()) {
4907 return;
4908 }
4909 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<LoadOverrideEvent, 1>>(
4910 JSRef<JSFunc>::Cast(args[0]), LoadOverrideEventToJSValue);
4911 auto instanceId = Container::CurrentId();
4912
4913 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
4914 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
4915 const BaseEventInfo* info) -> bool {
4916 ContainerScope scope(instanceId);
4917 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
4918 auto pipelineContext = PipelineContext::GetCurrentContext();
4919 CHECK_NULL_RETURN(pipelineContext, false);
4920 pipelineContext->UpdateCurrentActiveNode(node);
4921 auto* eventInfo = TypeInfoHelper::DynamicCast<LoadOverrideEvent>(info);
4922 JSRef<JSVal> message = func->ExecuteWithValue(*eventInfo);
4923 if (message->IsBoolean()) {
4924 return message->ToBoolean();
4925 }
4926 return false;
4927 };
4928 WebModel::GetInstance()->SetOnOverrideUrlLoading(std::move(uiCallback));
4929 }
4930
CopyOption(int32_t copyOption)4931 void JSWeb::CopyOption(int32_t copyOption)
4932 {
4933 auto mode = CopyOptions::Local;
4934 switch (copyOption) {
4935 case static_cast<int32_t>(CopyOptions::None):
4936 mode = CopyOptions::None;
4937 break;
4938 case static_cast<int32_t>(CopyOptions::InApp):
4939 mode = CopyOptions::InApp;
4940 break;
4941 case static_cast<int32_t>(CopyOptions::Local):
4942 mode = CopyOptions::Local;
4943 break;
4944 case static_cast<int32_t>(CopyOptions::Distributed):
4945 mode = CopyOptions::Distributed;
4946 break;
4947 default:
4948 mode = CopyOptions::Local;
4949 break;
4950 }
4951 WebModel::GetInstance()->SetCopyOptionMode(mode);
4952 }
4953
TextAutosizing(const JSCallbackInfo & args)4954 void JSWeb::TextAutosizing(const JSCallbackInfo& args)
4955 {
4956 if (args.Length() < 1 || !args[0]->IsBoolean()) {
4957 return;
4958 }
4959 bool isTextAutosizing = args[0]->ToBoolean();
4960 WebModel::GetInstance()->SetTextAutosizing(isTextAutosizing);
4961 }
4962
EnableNativeVideoPlayer(const JSCallbackInfo & args)4963 void JSWeb::EnableNativeVideoPlayer(const JSCallbackInfo& args)
4964 {
4965 if (args.Length() < 1 || !args[0]->IsObject()) {
4966 return;
4967 }
4968 auto paramObject = JSRef<JSObject>::Cast(args[0]);
4969 std::optional<bool> enable;
4970 std::optional<bool> shouldOverlay;
4971 JSRef<JSVal> enableJsValue = paramObject->GetProperty("enable");
4972 if (enableJsValue->IsBoolean()) {
4973 enable = enableJsValue->ToBoolean();
4974 }
4975 JSRef<JSVal> shouldOverlayJsValue = paramObject->GetProperty("shouldOverlay");
4976 if (shouldOverlayJsValue->IsBoolean()) {
4977 shouldOverlay = shouldOverlayJsValue->ToBoolean();
4978 }
4979 if (!enable || !shouldOverlay) {
4980 // invalid NativeVideoPlayerConfig
4981 return;
4982 }
4983 WebModel::GetInstance()->SetNativeVideoPlayerConfig(*enable, *shouldOverlay);
4984 }
4985
RenderProcessNotRespondingToJSValue(const RenderProcessNotRespondingEvent & eventInfo)4986 JSRef<JSVal> RenderProcessNotRespondingToJSValue(const RenderProcessNotRespondingEvent& eventInfo)
4987 {
4988 JSRef<JSObject> obj = JSRef<JSObject>::New();
4989 obj->SetProperty("jsStack", eventInfo.GetJsStack());
4990 obj->SetProperty("pid", eventInfo.GetPid());
4991 obj->SetProperty("reason", eventInfo.GetReason());
4992 return JSRef<JSVal>::Cast(obj);
4993 }
4994
OnRenderProcessNotResponding(const JSCallbackInfo & args)4995 void JSWeb::OnRenderProcessNotResponding(const JSCallbackInfo& args)
4996 {
4997 if (args.Length() < 1 || !args[0]->IsFunction()) {
4998 return;
4999 }
5000 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5001 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<RenderProcessNotRespondingEvent, 1>>(
5002 JSRef<JSFunc>::Cast(args[0]), RenderProcessNotRespondingToJSValue);
5003 auto instanceId = Container::CurrentId();
5004 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
5005 const BaseEventInfo* info) {
5006 ContainerScope scope(instanceId);
5007 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5008 auto pipelineContext = PipelineContext::GetCurrentContext();
5009 CHECK_NULL_VOID(pipelineContext);
5010 pipelineContext->UpdateCurrentActiveNode(node);
5011 auto* eventInfo = TypeInfoHelper::DynamicCast<RenderProcessNotRespondingEvent>(info);
5012 func->Execute(*eventInfo);
5013 };
5014 WebModel::GetInstance()->SetRenderProcessNotRespondingId(jsCallback);
5015 }
5016
RenderProcessRespondingEventToJSValue(const RenderProcessRespondingEvent & eventInfo)5017 JSRef<JSVal> RenderProcessRespondingEventToJSValue(const RenderProcessRespondingEvent& eventInfo)
5018 {
5019 JSRef<JSObject> obj = JSRef<JSObject>::New();
5020 return JSRef<JSVal>::Cast(obj);
5021 }
5022
OnRenderProcessResponding(const JSCallbackInfo & args)5023 void JSWeb::OnRenderProcessResponding(const JSCallbackInfo& args)
5024 {
5025 if (args.Length() < 1 || !args[0]->IsFunction()) {
5026 return;
5027 }
5028 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5029 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<RenderProcessRespondingEvent, 1>>(
5030 JSRef<JSFunc>::Cast(args[0]), RenderProcessRespondingEventToJSValue);
5031 auto instanceId = Container::CurrentId();
5032 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
5033 const BaseEventInfo* info) {
5034 ContainerScope scope(instanceId);
5035 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5036 auto pipelineContext = PipelineContext::GetCurrentContext();
5037 CHECK_NULL_VOID(pipelineContext);
5038 pipelineContext->UpdateCurrentActiveNode(node);
5039 auto* eventInfo = TypeInfoHelper::DynamicCast<RenderProcessRespondingEvent>(info);
5040 func->Execute(*eventInfo);
5041 };
5042 WebModel::GetInstance()->SetRenderProcessRespondingId(jsCallback);
5043 }
5044
ViewportFitChangedToJSValue(const ViewportFitChangedEvent & eventInfo)5045 JSRef<JSVal> ViewportFitChangedToJSValue(const ViewportFitChangedEvent& eventInfo)
5046 {
5047 JSRef<JSObject> obj = JSRef<JSObject>::New();
5048 obj->SetProperty("viewportFit", eventInfo.GetViewportFit());
5049 return JSRef<JSVal>::Cast(obj);
5050 }
5051
OnViewportFitChanged(const JSCallbackInfo & args)5052 void JSWeb::OnViewportFitChanged(const JSCallbackInfo& args)
5053 {
5054 if (args.Length() < 1 || !args[0]->IsFunction()) {
5055 return;
5056 }
5057 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5058 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<ViewportFitChangedEvent, 1>>(
5059 JSRef<JSFunc>::Cast(args[0]), ViewportFitChangedToJSValue);
5060 auto instanceId = Container::CurrentId();
5061 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
5062 const BaseEventInfo* info) {
5063 ContainerScope scope(instanceId);
5064 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5065 auto pipelineContext = PipelineContext::GetCurrentContext();
5066 CHECK_NULL_VOID(pipelineContext);
5067 pipelineContext->UpdateCurrentActiveNode(node);
5068 auto* eventInfo = TypeInfoHelper::DynamicCast<ViewportFitChangedEvent>(info);
5069 func->Execute(*eventInfo);
5070 };
5071 WebModel::GetInstance()->SetViewportFitChangedId(jsCallback);
5072 }
5073
SelectionMenuOptions(const JSCallbackInfo & args)5074 void JSWeb::SelectionMenuOptions(const JSCallbackInfo& args)
5075 {
5076 if (args.Length() != 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsArray()) {
5077 return;
5078 }
5079 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5080 auto instanceId = Container::CurrentId();
5081 auto menuItamArray = JSRef<JSArray>::Cast(args[0]);
5082 WebMenuOptionsParam optionParam;
5083 NG::MenuOptionsParam menuOption;
5084 for (size_t i = 0; i < menuItamArray->Length(); i++) {
5085 auto menuItem = menuItamArray->GetValueAt(i);
5086 if (!menuItem->IsObject()) {
5087 return;
5088 }
5089 auto menuItemObject = JSRef<JSObject>::Cast(menuItem);
5090 auto jsContent = menuItemObject->GetProperty("content");
5091 auto jsStartIcon = menuItemObject->GetProperty("startIcon");
5092 std::string content;
5093 if (!ParseJsMedia(jsContent, content)) {
5094 return;
5095 }
5096 menuOption.content = content;
5097 std::string icon;
5098 menuOption.icon.reset();
5099 if (ParseJsMedia(jsStartIcon, icon)) {
5100 menuOption.icon = icon;
5101 }
5102 auto jsAction = menuItemObject->GetProperty("action");
5103 if (jsAction.IsEmpty() || !jsAction->IsFunction()) {
5104 return;
5105 }
5106 auto jsFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(jsAction));
5107 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc),
5108 instanceId, node = frameNode](const std::string selectInfo) {
5109 ContainerScope scope(instanceId);
5110 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5111 auto pipelineContext = PipelineContext::GetCurrentContext();
5112 CHECK_NULL_VOID(pipelineContext);
5113 pipelineContext->UpdateCurrentActiveNode(node);
5114 pipelineContext->SetCallBackNode(node);
5115 auto newSelectInfo = JSRef<JSVal>::Make(ToJSValue(selectInfo));
5116 func->ExecuteJS(1, &newSelectInfo);
5117 };
5118 menuOption.action = std::move(jsCallback);
5119 optionParam.menuOption.push_back(menuOption);
5120 }
5121 WebModel::GetInstance()->SetSelectionMenuOptions(std::move(optionParam));
5122 }
5123
OnAdsBlocked(const JSCallbackInfo & args)5124 void JSWeb::OnAdsBlocked(const JSCallbackInfo& args)
5125 {
5126 if (args.Length() < 1 || !args[0]->IsFunction()) {
5127 return;
5128 }
5129
5130 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5131 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<AdsBlockedEvent, 1>>(
5132 JSRef<JSFunc>::Cast(args[0]), AdsBlockedEventToJSValue);
5133 auto instanceId = Container::CurrentId();
5134 auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
5135 const BaseEventInfo* info) {
5136 ContainerScope scope(instanceId);
5137 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5138 auto pipelineContext = PipelineContext::GetCurrentContext();
5139 CHECK_NULL_VOID(pipelineContext);
5140 pipelineContext->UpdateCurrentActiveNode(node);
5141 auto* eventInfo = TypeInfoHelper::DynamicCast<AdsBlockedEvent>(info);
5142 func->Execute(*eventInfo);
5143 };
5144 WebModel::GetInstance()->SetAdsBlockedEventId(jsCallback);
5145 }
5146
InterceptKeyboardEventToJSValue(const InterceptKeyboardEvent & eventInfo)5147 JSRef<JSVal> InterceptKeyboardEventToJSValue(const InterceptKeyboardEvent& eventInfo)
5148 {
5149 JSRef<JSObject> obj = JSRef<JSObject>::New();
5150 JSRef<JSObject> webKeyboardControllerObj = JSClass<JSWebKeyboardController>::NewInstance();
5151 auto webKeyboardController = Referenced::Claim(webKeyboardControllerObj->Unwrap<JSWebKeyboardController>());
5152 webKeyboardController->SeWebKeyboardController(eventInfo.GetCustomKeyboardHandler());
5153 obj->SetPropertyObject("controller", webKeyboardControllerObj);
5154
5155 JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
5156 JSRef<JSObject> attributesObj = objectTemplate->NewInstance();
5157 for (const auto& item : eventInfo.GetAttributesMap()) {
5158 attributesObj->SetProperty(item.first.c_str(), item.second.c_str());
5159 }
5160 obj->SetPropertyObject("attributes", attributesObj);
5161 return JSRef<JSVal>::Cast(obj);
5162 }
5163
ParseJsCustomKeyboardOption(const JsiExecutionContext & context,const JSRef<JSVal> & keyboardOpt,WebKeyboardOption & keyboardOption)5164 void JSWeb::ParseJsCustomKeyboardOption(const JsiExecutionContext& context, const JSRef<JSVal>& keyboardOpt,
5165 WebKeyboardOption& keyboardOption)
5166 {
5167 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption enter");
5168 if (!keyboardOpt->IsObject()) {
5169 return;
5170 }
5171
5172 JSRef<JSObject> keyboradOptObj = JSRef<JSObject>::Cast(keyboardOpt);
5173 auto useSystemKeyboardObj = keyboradOptObj->GetProperty("useSystemKeyboard");
5174 if (useSystemKeyboardObj->IsNull() || !useSystemKeyboardObj->IsBoolean()) {
5175 return;
5176 }
5177
5178 bool isSystemKeyboard = useSystemKeyboardObj->ToBoolean();
5179 keyboardOption.isSystemKeyboard_ = isSystemKeyboard;
5180 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption isSystemKeyboard is %{public}d",
5181 isSystemKeyboard);
5182 if (isSystemKeyboard) {
5183 auto enterKeyTypeObj = keyboradOptObj->GetProperty("enterKeyType");
5184 if (enterKeyTypeObj->IsNull() || !enterKeyTypeObj->IsNumber()) {
5185 return;
5186 }
5187 int32_t enterKeyType = enterKeyTypeObj->ToNumber<int32_t>();
5188 keyboardOption.enterKeyTpye_ = enterKeyType;
5189 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption \
5190 isSystemKeyboard is %{public}d, enterKeyType is %{public}d", isSystemKeyboard, enterKeyType);
5191 } else {
5192 auto builder = keyboradOptObj->GetProperty("customKeyboard");
5193 if (builder->IsNull()) {
5194 TAG_LOGE(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption" \
5195 ", parse customKeyboard, builder is null");
5196 return;
5197 }
5198
5199 if (!builder->IsFunction()) {
5200 TAG_LOGE(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption" \
5201 ", parse customKeyboard, builder is invalid");
5202 return;
5203 }
5204
5205 auto builderFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(builder));
5206 CHECK_NULL_VOID(builderFunc);
5207 WeakPtr<NG::FrameNode> targetNode =
5208 AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5209 auto buildFunc = [execCtx = context, func = std::move(builderFunc), node = targetNode]() {
5210 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
5211 ACE_SCORING_EVENT("WebCustomKeyboard");
5212 PipelineContext::SetCallBackNode(node);
5213 func->Execute();
5214 };
5215 keyboardOption.customKeyboardBuilder_ = buildFunc;
5216 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption" \
5217 ", isSystemKeyboard is %{public}d, parseCustomBuilder end", isSystemKeyboard);
5218 }
5219 }
5220
OnInterceptKeyboardAttach(const JSCallbackInfo & args)5221 void JSWeb::OnInterceptKeyboardAttach(const JSCallbackInfo& args)
5222 {
5223 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard OnInterceptKeyboardAttach register enter");
5224 if (args.Length() < 1 || !args[0]->IsFunction()) {
5225 return;
5226 }
5227 auto jsFunc = AceType::MakeRefPtr<JsEventFunction<InterceptKeyboardEvent, 1>>(
5228 JSRef<JSFunc>::Cast(args[0]), InterceptKeyboardEventToJSValue);
5229 auto instanceId = Container::CurrentId();
5230
5231 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
5232 auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](
5233 const BaseEventInfo* info) -> WebKeyboardOption {
5234 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard OnInterceptKeyboardAttach invoke enter");
5235 ContainerScope scope(instanceId);
5236 WebKeyboardOption opt;
5237 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, opt);
5238 auto pipelineContext = PipelineContext::GetCurrentContext();
5239 CHECK_NULL_RETURN(pipelineContext, opt);
5240 pipelineContext->UpdateCurrentActiveNode(node);
5241 auto* eventInfo = TypeInfoHelper::DynamicCast<InterceptKeyboardEvent>(info);
5242 JSRef<JSVal> keyboardOpt = func->ExecuteWithValue(*eventInfo);
5243 ParseJsCustomKeyboardOption(execCtx, keyboardOpt, opt);
5244 return opt;
5245 };
5246 WebModel::GetInstance()->SetOnInterceptKeyboardAttach(std::move(uiCallback));
5247 }
5248
ForceDisplayScrollBar(const JSCallbackInfo & args)5249 void JSWeb::ForceDisplayScrollBar(const JSCallbackInfo& args)
5250 {
5251 if (args.Length() < 1 || !args[0]->IsBoolean()) {
5252 return;
5253 }
5254 bool isEnabled = args[0]->ToBoolean();
5255 WebModel::GetInstance()->SetOverlayScrollbarEnabled(isEnabled);
5256 }
5257
KeyboardAvoidMode(int32_t mode)5258 void JSWeb::KeyboardAvoidMode(int32_t mode)
5259 {
5260 if (mode < static_cast<int32_t>(WebKeyboardAvoidMode::RESIZE_VISUAL) ||
5261 mode > static_cast<int32_t>(WebKeyboardAvoidMode::DEFAULT)) {
5262 TAG_LOGE(AceLogTag::ACE_WEB, "KeyboardAvoidMode param err");
5263 return;
5264 }
5265 WebKeyboardAvoidMode avoidMode = static_cast<WebKeyboardAvoidMode>(mode);
5266 WebModel::GetInstance()->SetKeyboardAvoidMode(avoidMode);
5267 }
5268
EditMenuOptions(const JSCallbackInfo & info)5269 void JSWeb::EditMenuOptions(const JSCallbackInfo& info)
5270 {
5271 NG::OnCreateMenuCallback onCreateMenuCallback;
5272 NG::OnMenuItemClickCallback onMenuItemClick;
5273 JSViewAbstract::ParseEditMenuOptions(info, onCreateMenuCallback, onMenuItemClick);
5274 WebModel::GetInstance()->SetEditMenuOptions(std::move(onCreateMenuCallback), std::move(onMenuItemClick));
5275 }
5276
EnableHapticFeedback(const JSCallbackInfo & args)5277 void JSWeb::EnableHapticFeedback(const JSCallbackInfo& args)
5278 {
5279 if (args.Length() < 1 || !args[0]->IsBoolean()) {
5280 return;
5281 }
5282 bool isEnabled = args[0]->ToBoolean();
5283 WebModel::GetInstance()->SetEnabledHapticFeedback(isEnabled);
5284 }
5285
5286 } // namespace OHOS::Ace::Framework
5287