/* * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "frameworks/bridge/declarative_frontend/jsview/js_web.h" #include #include #include "pixel_map.h" #include "pixel_map_napi.h" #include "base/log/ace_scoring_log.h" #include "base/memory/ace_type.h" #include "base/memory/referenced.h" #include "base/utils/utils.h" #if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) #include "base/web/webview/ohos_nweb/include/nweb.h" #else #include "base/web/webview/ohos_interface/include/ohos_nweb/nweb.h" #endif #include "bridge/common/utils/engine_helper.h" #include "bridge/declarative_frontend/engine/functions/js_click_function.h" #include "bridge/declarative_frontend/engine/functions/js_drag_function.h" #include "bridge/declarative_frontend/engine/functions/js_key_function.h" #include "bridge/declarative_frontend/engine/js_converter.h" #include "bridge/declarative_frontend/engine/js_ref_ptr.h" #include "bridge/declarative_frontend/jsview/js_utils.h" #include "bridge/declarative_frontend/jsview/js_web_controller.h" #include "bridge/declarative_frontend/jsview/models/web_model_impl.h" #include "bridge/declarative_frontend/view_stack_processor.h" #include "core/common/ace_application_info.h" #include "core/common/container.h" #include "core/common/container_scope.h" #include "core/components/web/web_event.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/pattern/web/web_model_ng.h" #include "core/pipeline/pipeline_base.h" namespace OHOS::Ace { namespace { const std::string RAWFILE_PREFIX = "resource://RAWFILE/"; const std::string BUNDLE_NAME_PREFIX = "bundleName:"; const std::string MODULE_NAME_PREFIX = "moduleName:"; const int32_t SELECTION_MENU_OPTION_PARAM_INDEX = 3; const int32_t SELECTION_MENU_CONTENT_PARAM_INDEX = 2; const int32_t PARAM_ZERO = 0; const int32_t PARAM_ONE = 1; const int32_t PARAM_TWO = 2; void EraseSpace(std::string& data) { auto iter = data.begin(); while (iter != data.end()) { if (isspace(*iter)) { iter = data.erase(iter); } else { ++iter; } } } } std::unique_ptr WebModel::instance_ = nullptr; std::mutex WebModel::mutex_; WebModel* WebModel::GetInstance() { if (!instance_) { std::lock_guard lock(mutex_); if (!instance_) { #ifdef NG_BUILD instance_.reset(new NG::WebModelNG()); #else if (Container::IsCurrentUseNewPipeline()) { instance_.reset(new NG::WebModelNG()); } else { instance_.reset(new Framework::WebModelImpl()); } #endif } } return instance_.get(); } } // namespace OHOS::Ace namespace OHOS::Ace::Framework { bool JSWeb::webDebuggingAccess_ = false; class JSWebDialog : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebDialog"); JSClass::CustomMethod("handleConfirm", &JSWebDialog::Confirm); JSClass::CustomMethod("handleCancel", &JSWebDialog::Cancel); JSClass::CustomMethod("handlePromptConfirm", &JSWebDialog::PromptConfirm); JSClass::Bind(globalObj, &JSWebDialog::Constructor, &JSWebDialog::Destructor); } void SetResult(const RefPtr& result) { result_ = result; } void Confirm(const JSCallbackInfo& args) { if (result_) { result_->Confirm(); } } void PromptConfirm(const JSCallbackInfo& args) { std::string message; if (!result_) { return; } if (args.Length() == 1 && args[0]->IsString()) { message = args[0]->ToString(); result_->Confirm(message); } } void Cancel(const JSCallbackInfo& args) { if (result_) { result_->Cancel(); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsWebDialog = Referenced::MakeRefPtr(); jsWebDialog->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsWebDialog)); } static void Destructor(JSWebDialog* jsWebDialog) { if (jsWebDialog != nullptr) { jsWebDialog->DecRefCount(); } } RefPtr result_; }; class JSFullScreenExitHandler : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("FullScreenExitHandler"); JSClass::CustomMethod("exitFullScreen", &JSFullScreenExitHandler::ExitFullScreen); JSClass::Bind( globalObj, &JSFullScreenExitHandler::Constructor, &JSFullScreenExitHandler::Destructor); } void SetHandler(const RefPtr& handler) { fullScreenExitHandler_ = handler; } void ExitFullScreen(const JSCallbackInfo& args) { if (fullScreenExitHandler_) { fullScreenExitHandler_->ExitFullScreen(); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsFullScreenExitHandler = Referenced::MakeRefPtr(); jsFullScreenExitHandler->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsFullScreenExitHandler)); } static void Destructor(JSFullScreenExitHandler* jsFullScreenExitHandler) { if (jsFullScreenExitHandler != nullptr) { jsFullScreenExitHandler->DecRefCount(); } } RefPtr fullScreenExitHandler_; }; class JSWebKeyboardController : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebKeyboardController"); JSClass::CustomMethod("insertText", &JSWebKeyboardController::InsertText); JSClass::CustomMethod("deleteForward", &JSWebKeyboardController::DeleteForward); JSClass::CustomMethod("deleteBackward", &JSWebKeyboardController::DeleteBackward); JSClass::CustomMethod("sendFunctionKey", &JSWebKeyboardController::SendFunctionKey); JSClass::CustomMethod("close", &JSWebKeyboardController::Close); JSClass::Bind( globalObj, &JSWebKeyboardController::Constructor, &JSWebKeyboardController::Destructor); } void SeWebKeyboardController(const RefPtr& controller) { webKeyboardController_ = controller; } void InsertText(const JSCallbackInfo& args) { if (!webKeyboardController_) { return; } if (args.Length() < 1 || !(args[0]->IsString())) { return; } webKeyboardController_->InsertText(args[0]->ToString()); } void DeleteForward(const JSCallbackInfo& args) { if (!webKeyboardController_) { return; } if (args.Length() < 1 || !(args[0]->IsNumber())) { return; } webKeyboardController_->DeleteForward(args[0]->ToNumber()); } void DeleteBackward(const JSCallbackInfo& args) { if (!webKeyboardController_) { return; } if (args.Length() < 1 || !(args[0]->IsNumber())) { return; } webKeyboardController_->DeleteBackward(args[0]->ToNumber()); } void SendFunctionKey(const JSCallbackInfo& args) { if (!webKeyboardController_) { return; } if (args.Length() < 1 || !(args[0]->IsNumber())) { return; } webKeyboardController_->SendFunctionKey(args[0]->ToNumber()); } void Close(const JSCallbackInfo& args) { webKeyboardController_->Close(); } private: static void Constructor(const JSCallbackInfo& args) { auto jSWebKeyboardController = Referenced::MakeRefPtr(); jSWebKeyboardController->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jSWebKeyboardController)); } static void Destructor(JSWebKeyboardController* jSWebKeyboardController) { if (jSWebKeyboardController != nullptr) { jSWebKeyboardController->DecRefCount(); } } RefPtr webKeyboardController_; }; class JSWebHttpAuth : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebHttpAuthResult"); JSClass::CustomMethod("confirm", &JSWebHttpAuth::Confirm); JSClass::CustomMethod("cancel", &JSWebHttpAuth::Cancel); JSClass::CustomMethod("isHttpAuthInfoSaved", &JSWebHttpAuth::IsHttpAuthInfoSaved); JSClass::Bind(globalObj, &JSWebHttpAuth::Constructor, &JSWebHttpAuth::Destructor); } void SetResult(const RefPtr& result) { result_ = result; } void Confirm(const JSCallbackInfo& args) { if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) { auto code = JSVal(ToJSValue(false)); auto descriptionRef = JSRef::Make(code); args.SetReturnValue(descriptionRef); return; } std::string userName = args[0]->ToString(); std::string password = args[1]->ToString(); bool ret = false; if (result_) { result_->Confirm(userName, password); ret = true; } auto code = JSVal(ToJSValue(ret)); auto descriptionRef = JSRef::Make(code); args.SetReturnValue(descriptionRef); } void Cancel(const JSCallbackInfo& args) { if (result_) { result_->Cancel(); } } void IsHttpAuthInfoSaved(const JSCallbackInfo& args) { bool ret = false; if (result_) { ret = result_->IsHttpAuthInfoSaved(); } auto code = JSVal(ToJSValue(ret)); auto descriptionRef = JSRef::Make(code); args.SetReturnValue(descriptionRef); } private: static void Constructor(const JSCallbackInfo& args) { auto jsWebHttpAuth = Referenced::MakeRefPtr(); jsWebHttpAuth->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsWebHttpAuth)); } static void Destructor(JSWebHttpAuth* jsWebHttpAuth) { if (jsWebHttpAuth != nullptr) { jsWebHttpAuth->DecRefCount(); } } RefPtr result_; }; class JSWebSslError : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebSslErrorResult"); JSClass::CustomMethod("handleConfirm", &JSWebSslError::HandleConfirm); JSClass::CustomMethod("handleCancel", &JSWebSslError::HandleCancel); JSClass::Bind(globalObj, &JSWebSslError::Constructor, &JSWebSslError::Destructor); } void SetResult(const RefPtr& result) { result_ = result; } void HandleConfirm(const JSCallbackInfo& args) { if (result_) { result_->HandleConfirm(); } } void HandleCancel(const JSCallbackInfo& args) { if (result_) { result_->HandleCancel(); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsWebSslError = Referenced::MakeRefPtr(); jsWebSslError->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsWebSslError)); } static void Destructor(JSWebSslError* jsWebSslError) { if (jsWebSslError != nullptr) { jsWebSslError->DecRefCount(); } } RefPtr result_; }; class JSWebAllSslError : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebAllSslErrorResult"); JSClass::CustomMethod("handleConfirm", &JSWebAllSslError::HandleConfirm); JSClass::CustomMethod("handleCancel", &JSWebAllSslError::HandleCancel); JSClass::Bind(globalObj, &JSWebAllSslError::Constructor, &JSWebAllSslError::Destructor); } void SetResult(const RefPtr& result) { result_ = result; } void HandleConfirm(const JSCallbackInfo& args) { if (result_) { result_->HandleConfirm(); } } void HandleCancel(const JSCallbackInfo& args) { if (result_) { result_->HandleCancel(); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsWebAllSslError = Referenced::MakeRefPtr(); jsWebAllSslError->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsWebAllSslError)); } static void Destructor(JSWebAllSslError* jsWebAllSslError) { if (jsWebAllSslError != nullptr) { jsWebAllSslError->DecRefCount(); } } RefPtr result_; }; class JSWebSslSelectCert : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebSslSelectCertResult"); JSClass::CustomMethod("confirm", &JSWebSslSelectCert::HandleConfirm); JSClass::CustomMethod("cancel", &JSWebSslSelectCert::HandleCancel); JSClass::CustomMethod("ignore", &JSWebSslSelectCert::HandleIgnore); JSClass::Bind(globalObj, &JSWebSslSelectCert::Constructor, &JSWebSslSelectCert::Destructor); } void SetResult(const RefPtr& result) { result_ = result; } void HandleConfirm(const JSCallbackInfo& args) { std::string privateKeyFile; std::string certChainFile; if (args.Length() == 1 && args[0]->IsString()) { privateKeyFile = args[0]->ToString(); } else if (args.Length() == 2 && args[0]->IsString() && args[1]->IsString()) { privateKeyFile = args[0]->ToString(); certChainFile = args[1]->ToString(); } else { return; } if (result_) { result_->HandleConfirm(privateKeyFile, certChainFile); } } void HandleCancel(const JSCallbackInfo& args) { if (result_) { result_->HandleCancel(); } } void HandleIgnore(const JSCallbackInfo& args) { if (result_) { result_->HandleIgnore(); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsWebSslSelectCert = Referenced::MakeRefPtr(); jsWebSslSelectCert->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsWebSslSelectCert)); } static void Destructor(JSWebSslSelectCert* jsWebSslSelectCert) { if (jsWebSslSelectCert != nullptr) { jsWebSslSelectCert->DecRefCount(); } } RefPtr result_; }; class JSWebConsoleLog : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("ConsoleMessage"); JSClass::CustomMethod("getLineNumber", &JSWebConsoleLog::GetLineNumber); JSClass::CustomMethod("getMessage", &JSWebConsoleLog::GetLog); JSClass::CustomMethod("getMessageLevel", &JSWebConsoleLog::GetLogLevel); JSClass::CustomMethod("getSourceId", &JSWebConsoleLog::GetSourceId); JSClass::Bind(globalObj, &JSWebConsoleLog::Constructor, &JSWebConsoleLog::Destructor); } void SetMessage(const RefPtr& message) { message_ = message; } void GetLineNumber(const JSCallbackInfo& args) { auto code = JSVal(ToJSValue(message_->GetLineNumber())); auto descriptionRef = JSRef::Make(code); args.SetReturnValue(descriptionRef); } void GetLog(const JSCallbackInfo& args) { auto code = JSVal(ToJSValue(message_->GetLog())); auto descriptionRef = JSRef::Make(code); args.SetReturnValue(descriptionRef); } void GetLogLevel(const JSCallbackInfo& args) { auto code = JSVal(ToJSValue(message_->GetLogLevel())); auto descriptionRef = JSRef::Make(code); args.SetReturnValue(descriptionRef); } void GetSourceId(const JSCallbackInfo& args) { auto code = JSVal(ToJSValue(message_->GetSourceId())); auto descriptionRef = JSRef::Make(code); args.SetReturnValue(descriptionRef); } private: static void Constructor(const JSCallbackInfo& args) { auto jsWebConsoleLog = Referenced::MakeRefPtr(); jsWebConsoleLog->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsWebConsoleLog)); } static void Destructor(JSWebConsoleLog* jsWebConsoleLog) { if (jsWebConsoleLog != nullptr) { jsWebConsoleLog->DecRefCount(); } } RefPtr message_; }; class JSWebGeolocation : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebGeolocation"); JSClass::CustomMethod("invoke", &JSWebGeolocation::Invoke); JSClass::Bind(globalObj, &JSWebGeolocation::Constructor, &JSWebGeolocation::Destructor); } void SetEvent(const LoadWebGeolocationShowEvent& eventInfo) { webGeolocation_ = eventInfo.GetWebGeolocation(); } void Invoke(const JSCallbackInfo& args) { std::string origin; bool allow = false; bool retain = false; if (args[0]->IsString()) { origin = args[0]->ToString(); } if (args[1]->IsBoolean()) { allow = args[1]->ToBoolean(); } if (args[2]->IsBoolean()) { retain = args[2]->ToBoolean(); } if (webGeolocation_) { webGeolocation_->Invoke(origin, allow, retain); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsWebGeolocation = Referenced::MakeRefPtr(); jsWebGeolocation->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsWebGeolocation)); } static void Destructor(JSWebGeolocation* jsWebGeolocation) { if (jsWebGeolocation != nullptr) { jsWebGeolocation->DecRefCount(); } } RefPtr webGeolocation_; }; class JSWebPermissionRequest : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebPermissionRequest"); JSClass::CustomMethod("deny", &JSWebPermissionRequest::Deny); JSClass::CustomMethod("getOrigin", &JSWebPermissionRequest::GetOrigin); JSClass::CustomMethod("getAccessibleResource", &JSWebPermissionRequest::GetResources); JSClass::CustomMethod("grant", &JSWebPermissionRequest::Grant); JSClass::Bind( globalObj, &JSWebPermissionRequest::Constructor, &JSWebPermissionRequest::Destructor); } void SetEvent(const WebPermissionRequestEvent& eventInfo) { webPermissionRequest_ = eventInfo.GetWebPermissionRequest(); } void Deny(const JSCallbackInfo& args) { if (webPermissionRequest_) { webPermissionRequest_->Deny(); } } void GetOrigin(const JSCallbackInfo& args) { std::string origin; if (webPermissionRequest_) { origin = webPermissionRequest_->GetOrigin(); } auto originJs = JSVal(ToJSValue(origin)); auto originJsRef = JSRef::Make(originJs); args.SetReturnValue(originJsRef); } void GetResources(const JSCallbackInfo& args) { JSRef result = JSRef::New(); if (webPermissionRequest_) { std::vector resources = webPermissionRequest_->GetResources(); uint32_t index = 0; for (auto iterator = resources.begin(); iterator != resources.end(); ++iterator) { auto valueStr = JSVal(ToJSValue(*iterator)); auto value = JSRef::Make(valueStr); result->SetValueAt(index++, value); } } args.SetReturnValue(result); } void Grant(const JSCallbackInfo& args) { if (args.Length() < 1) { if (webPermissionRequest_) { webPermissionRequest_->Deny(); } } std::vector resources; if (args[0]->IsArray()) { JSRef array = JSRef::Cast(args[0]); for (size_t i = 0; i < array->Length(); i++) { JSRef val = array->GetValueAt(i); if (!val->IsString()) { continue; } std::string res; if (!ConvertFromJSValue(val, res)) { continue; } resources.push_back(res); } } if (webPermissionRequest_) { webPermissionRequest_->Grant(resources); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsWebPermissionRequest = Referenced::MakeRefPtr(); jsWebPermissionRequest->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsWebPermissionRequest)); } static void Destructor(JSWebPermissionRequest* jsWebPermissionRequest) { if (jsWebPermissionRequest != nullptr) { jsWebPermissionRequest->DecRefCount(); } } RefPtr webPermissionRequest_; }; class JSScreenCaptureRequest : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("ScreenCaptureRequest"); JSClass::CustomMethod("deny", &JSScreenCaptureRequest::Deny); JSClass::CustomMethod("getOrigin", &JSScreenCaptureRequest::GetOrigin); JSClass::CustomMethod("grant", &JSScreenCaptureRequest::Grant); JSClass::Bind( globalObj, &JSScreenCaptureRequest::Constructor, &JSScreenCaptureRequest::Destructor); } void SetEvent(const WebScreenCaptureRequestEvent& eventInfo) { request_ = eventInfo.GetWebScreenCaptureRequest(); } void Deny(const JSCallbackInfo& args) { if (request_) { request_->Deny(); } } void GetOrigin(const JSCallbackInfo& args) { std::string origin; if (request_) { origin = request_->GetOrigin(); } auto originJs = JSVal(ToJSValue(origin)); auto originJsRef = JSRef::Make(originJs); args.SetReturnValue(originJsRef); } void Grant(const JSCallbackInfo& args) { if (!request_) { return; } if (args.Length() < 1 || !args[0]->IsObject()) { request_->Deny(); return; } JSRef paramObject = JSRef::Cast(args[0]); auto captureModeObj = paramObject->GetProperty("captureMode"); if (!captureModeObj->IsNumber()) { request_->Deny(); return; } int32_t captureMode = captureModeObj->ToNumber(); request_->SetCaptureMode(captureMode); request_->SetSourceId(-1); request_->Grant(); } private: static void Constructor(const JSCallbackInfo& args) { auto jsScreenCaptureRequest = Referenced::MakeRefPtr(); jsScreenCaptureRequest->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsScreenCaptureRequest)); } static void Destructor(JSScreenCaptureRequest* jsScreenCaptureRequest) { if (jsScreenCaptureRequest != nullptr) { jsScreenCaptureRequest->DecRefCount(); } } RefPtr request_; }; class JSNativeEmbedGestureRequest : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("NativeEmbedGesture"); JSClass::CustomMethod( "setGestureEventResult", &JSNativeEmbedGestureRequest::SetGestureEventResult); JSClass::Bind( globalObj, &JSNativeEmbedGestureRequest::Constructor, &JSNativeEmbedGestureRequest::Destructor); } void SetResult(const RefPtr& result) { eventResult_ = result; } void SetGestureEventResult(const JSCallbackInfo& args) { if (eventResult_) { bool result = true; bool stopPropagation = true; if (args.Length() == PARAM_ONE && args[PARAM_ZERO]->IsBoolean()) { result = args[PARAM_ZERO]->ToBoolean(); eventResult_->SetGestureEventResult(result); } else if (args.Length() == PARAM_TWO && args[PARAM_ZERO]->IsBoolean() && args[PARAM_ONE]->IsBoolean()) { result = args[PARAM_ZERO]->ToBoolean(); stopPropagation = args[PARAM_ONE]->ToBoolean(); eventResult_->SetGestureEventResult(result, stopPropagation); } } } private: static void Constructor(const JSCallbackInfo& args) { auto jSNativeEmbedGestureRequest = Referenced::MakeRefPtr(); jSNativeEmbedGestureRequest->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jSNativeEmbedGestureRequest)); } static void Destructor(JSNativeEmbedGestureRequest* jSNativeEmbedGestureRequest) { if (jSNativeEmbedGestureRequest != nullptr) { jSNativeEmbedGestureRequest->DecRefCount(); } } RefPtr eventResult_; }; class JSWebWindowNewHandler : public Referenced { public: struct ChildWindowInfo { int32_t parentWebId_ = -1; JSRef controller_; }; static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebWindowNewHandler"); JSClass::CustomMethod("setWebController", &JSWebWindowNewHandler::SetWebController); JSClass::Bind( globalObj, &JSWebWindowNewHandler::Constructor, &JSWebWindowNewHandler::Destructor); } void SetEvent(const WebWindowNewEvent& eventInfo) { handler_ = eventInfo.GetWebWindowNewHandler(); } static JSRef PopController(int32_t id, int32_t* parentId = nullptr) { auto iter = controller_map_.find(id); if (iter == controller_map_.end()) { return JSRef::Make(); } auto controller = iter->second.controller_; if (parentId) { *parentId = iter->second.parentWebId_; } controller_map_.erase(iter); return controller; } static bool ExistController(JSRef& controller, int32_t& parentWebId) { auto getThisVarFunction = controller->GetProperty("innerGetThisVar"); if (!getThisVarFunction->IsFunction()) { parentWebId = -1; return false; } auto func = JSRef::Cast(getThisVarFunction); auto thisVar = func->Call(controller, 0, {}); int64_t thisPtr = thisVar->ToNumber(); for (auto iter = controller_map_.begin(); iter != controller_map_.end(); iter++) { auto getThisVarFunction1 = iter->second.controller_->GetProperty("innerGetThisVar"); if (getThisVarFunction1->IsFunction()) { auto func1 = JSRef::Cast(getThisVarFunction1); auto thisVar1 = func1->Call(iter->second.controller_, 0, {}); if (thisPtr == thisVar1->ToNumber()) { parentWebId = iter->second.parentWebId_; return true; } } } parentWebId = -1; return false; } void SetWebController(const JSCallbackInfo& args) { if (handler_) { int32_t parentNWebId = handler_->GetParentNWebId(); if (parentNWebId == -1) { return; } if (args.Length() < 1 || !args[0]->IsObject()) { WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false); return; } auto controller = JSRef::Cast(args[0]); if (controller.IsEmpty()) { WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false); return; } auto getWebIdFunction = controller->GetProperty("innerGetWebId"); if (!getWebIdFunction->IsFunction()) { WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false); return; } auto func = JSRef::Cast(getWebIdFunction); auto webId = func->Call(controller, 0, {}); int32_t childWebId = webId->ToNumber(); if (childWebId == parentNWebId || childWebId != -1) { WebModel::GetInstance()->NotifyPopupWindowResult(parentNWebId, false); return; } controller_map_.insert( std::pair(handler_->GetId(), { parentNWebId, controller })); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsWebWindowNewHandler = Referenced::MakeRefPtr(); jsWebWindowNewHandler->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsWebWindowNewHandler)); } static void Destructor(JSWebWindowNewHandler* jsWebWindowNewHandler) { if (jsWebWindowNewHandler != nullptr) { jsWebWindowNewHandler->DecRefCount(); } } RefPtr handler_; static std::unordered_map controller_map_; }; std::unordered_map JSWebWindowNewHandler::controller_map_; class JSDataResubmitted : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("DataResubmissionHandler"); JSClass::CustomMethod("resend", &JSDataResubmitted::Resend); JSClass::CustomMethod("cancel", &JSDataResubmitted::Cancel); JSClass::Bind(globalObj, &JSDataResubmitted::Constructor, &JSDataResubmitted::Destructor); } void SetHandler(const RefPtr& handler) { dataResubmitted_ = handler; } void Resend(const JSCallbackInfo& args) { if (dataResubmitted_) { dataResubmitted_->Resend(); } } void Cancel(const JSCallbackInfo& args) { if (dataResubmitted_) { dataResubmitted_->Cancel(); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsDataResubmitted = Referenced::MakeRefPtr(); jsDataResubmitted->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsDataResubmitted)); } static void Destructor(JSDataResubmitted* jsDataResubmitted) { if (jsDataResubmitted != nullptr) { jsDataResubmitted->DecRefCount(); } } RefPtr dataResubmitted_; }; class JSWebResourceError : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebResourceError"); JSClass::CustomMethod("getErrorCode", &JSWebResourceError::GetErrorCode); JSClass::CustomMethod("getErrorInfo", &JSWebResourceError::GetErrorInfo); JSClass::Bind(globalObj, &JSWebResourceError::Constructor, &JSWebResourceError::Destructor); } void SetEvent(const ReceivedErrorEvent& eventInfo) { error_ = eventInfo.GetError(); } void GetErrorCode(const JSCallbackInfo& args) { auto code = JSVal(ToJSValue(error_->GetCode())); auto descriptionRef = JSRef::Make(code); args.SetReturnValue(descriptionRef); } void GetErrorInfo(const JSCallbackInfo& args) { auto info = JSVal(ToJSValue(error_->GetInfo())); auto descriptionRef = JSRef::Make(info); args.SetReturnValue(descriptionRef); } private: static void Constructor(const JSCallbackInfo& args) { auto jSWebResourceError = Referenced::MakeRefPtr(); jSWebResourceError->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jSWebResourceError)); } static void Destructor(JSWebResourceError* jSWebResourceError) { if (jSWebResourceError != nullptr) { jSWebResourceError->DecRefCount(); } } RefPtr error_; }; class JSWebResourceResponse : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebResourceResponse"); JSClass::CustomMethod("getResponseData", &JSWebResourceResponse::GetResponseData); JSClass::CustomMethod("getResponseDataEx", &JSWebResourceResponse::GetResponseDataEx); JSClass::CustomMethod( "getResponseEncoding", &JSWebResourceResponse::GetResponseEncoding); JSClass::CustomMethod( "getResponseMimeType", &JSWebResourceResponse::GetResponseMimeType); JSClass::CustomMethod("getReasonMessage", &JSWebResourceResponse::GetReasonMessage); JSClass::CustomMethod("getResponseCode", &JSWebResourceResponse::GetResponseCode); JSClass::CustomMethod("getResponseHeader", &JSWebResourceResponse::GetResponseHeader); JSClass::CustomMethod("setResponseData", &JSWebResourceResponse::SetResponseData); JSClass::CustomMethod( "setResponseEncoding", &JSWebResourceResponse::SetResponseEncoding); JSClass::CustomMethod( "setResponseMimeType", &JSWebResourceResponse::SetResponseMimeType); JSClass::CustomMethod("setReasonMessage", &JSWebResourceResponse::SetReasonMessage); JSClass::CustomMethod("setResponseCode", &JSWebResourceResponse::SetResponseCode); JSClass::CustomMethod("setResponseHeader", &JSWebResourceResponse::SetResponseHeader); JSClass::CustomMethod("setResponseIsReady", &JSWebResourceResponse::SetResponseIsReady); JSClass::CustomMethod("getResponseIsReady", &JSWebResourceResponse::GetResponseIsReady); JSClass::Bind( globalObj, &JSWebResourceResponse::Constructor, &JSWebResourceResponse::Destructor); } JSWebResourceResponse() : response_(AceType::MakeRefPtr()) {} void SetEvent(const ReceivedHttpErrorEvent& eventInfo) { response_ = eventInfo.GetResponse(); } void GetResponseData(const JSCallbackInfo& args) { auto data = JSVal(ToJSValue(response_->GetData())); auto descriptionRef = JSRef::Make(data); args.SetReturnValue(descriptionRef); } void GetResponseDataEx(const JSCallbackInfo& args) { args.SetReturnValue(responseData_); } void GetResponseIsReady(const JSCallbackInfo& args) { auto status = JSVal(ToJSValue(response_->GetResponseStatus())); auto descriptionRef = JSRef::Make(status); args.SetReturnValue(descriptionRef); } void GetResponseEncoding(const JSCallbackInfo& args) { auto encoding = JSVal(ToJSValue(response_->GetEncoding())); auto descriptionRef = JSRef::Make(encoding); args.SetReturnValue(descriptionRef); } void GetResponseMimeType(const JSCallbackInfo& args) { auto mimeType = JSVal(ToJSValue(response_->GetMimeType())); auto descriptionRef = JSRef::Make(mimeType); args.SetReturnValue(descriptionRef); } void GetReasonMessage(const JSCallbackInfo& args) { auto reason = JSVal(ToJSValue(response_->GetReason())); auto descriptionRef = JSRef::Make(reason); args.SetReturnValue(descriptionRef); } void GetResponseCode(const JSCallbackInfo& args) { auto code = JSVal(ToJSValue(response_->GetStatusCode())); auto descriptionRef = JSRef::Make(code); args.SetReturnValue(descriptionRef); } void GetResponseHeader(const JSCallbackInfo& args) { auto map = response_->GetHeaders(); std::map::iterator iterator; uint32_t index = 0; JSRef headers = JSRef::New(); for (iterator = map.begin(); iterator != map.end(); ++iterator) { JSRef header = JSRef::New(); header->SetProperty("headerKey", iterator->first); header->SetProperty("headerValue", iterator->second); headers->SetValueAt(index++, header); } args.SetReturnValue(headers); } RefPtr GetResponseObj() const { return response_; } void SetResponseData(const JSCallbackInfo& args) { if (args.Length() <= 0) { return; } responseData_ = args[0]; if (args[0]->IsNumber()) { auto fd = args[0]->ToNumber(); response_->SetFileHandle(fd); return; } if (args[0]->IsString()) { auto data = args[0]->ToString(); response_->SetData(data); return; } if (args[0]->IsArrayBuffer()) { JsiRef arrayBuffer = JsiRef::Cast(args[0]); int32_t bufferSize = arrayBuffer->ByteLength(); void* buffer = arrayBuffer->GetBuffer(); const char* charPtr = static_cast(buffer); std::string data(charPtr, bufferSize); response_->SetData(data); response_->SetBuffer(static_cast(buffer), bufferSize); return; } if (args[0]->IsObject()) { std::string resourceUrl; std::string url; if (!JSViewAbstract::ParseJsMedia(args[0], resourceUrl)) { return; } auto np = resourceUrl.find_first_of("/"); url = (np == std::string::npos) ? resourceUrl : resourceUrl.erase(np, 1); response_->SetResourceUrl(url); return; } } void SetResponseEncoding(const JSCallbackInfo& args) { if ((args.Length() <= 0) || !(args[0]->IsString())) { return; } auto encode = args[0]->ToString(); response_->SetEncoding(encode); } void SetResponseMimeType(const JSCallbackInfo& args) { if ((args.Length() <= 0) || !(args[0]->IsString())) { return; } auto mineType = args[0]->ToString(); response_->SetMimeType(mineType); } void SetReasonMessage(const JSCallbackInfo& args) { if ((args.Length() <= 0) || !(args[0]->IsString())) { return; } auto reason = args[0]->ToString(); response_->SetReason(reason); } void SetResponseCode(const JSCallbackInfo& args) { if ((args.Length() <= 0) || !(args[0]->IsNumber())) { return; } auto statusCode = args[0]->ToNumber(); response_->SetStatusCode(statusCode); } void SetResponseHeader(const JSCallbackInfo& args) { if ((args.Length() <= 0) || !(args[0]->IsArray())) { return; } JSRef array = JSRef::Cast(args[0]); for (size_t i = 0; i < array->Length(); i++) { if (!(array->GetValueAt(i)->IsObject())) { return; } auto obj = JSRef::Cast(array->GetValueAt(i)); auto headerKey = obj->GetProperty("headerKey"); auto headerValue = obj->GetProperty("headerValue"); if (!headerKey->IsString() || !headerValue->IsString()) { return; } auto keystr = headerKey->ToString(); auto valstr = headerValue->ToString(); response_->SetHeadersVal(keystr, valstr); } } void SetResponseIsReady(const JSCallbackInfo& args) { if ((args.Length() <= 0) || !(args[0]->IsBoolean())) { return; } bool isReady = false; if (!ConvertFromJSValue(args[0], isReady)) { return; } response_->SetResponseStatus(isReady); } private: static void Constructor(const JSCallbackInfo& args) { auto jSWebResourceResponse = Referenced::MakeRefPtr(); jSWebResourceResponse->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jSWebResourceResponse)); } static void Destructor(JSWebResourceResponse* jSWebResourceResponse) { if (jSWebResourceResponse != nullptr) { jSWebResourceResponse->DecRefCount(); } } RefPtr response_; JSRef responseData_; }; class JSWebResourceRequest : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebResourceRequest"); JSClass::CustomMethod("getRequestUrl", &JSWebResourceRequest::GetRequestUrl); JSClass::CustomMethod("getRequestHeader", &JSWebResourceRequest::GetRequestHeader); JSClass::CustomMethod("getRequestMethod", &JSWebResourceRequest::GetRequestMethod); JSClass::CustomMethod("isRequestGesture", &JSWebResourceRequest::IsRequestGesture); JSClass::CustomMethod("isMainFrame", &JSWebResourceRequest::IsMainFrame); JSClass::CustomMethod("isRedirect", &JSWebResourceRequest::IsRedirect); JSClass::Bind( globalObj, &JSWebResourceRequest::Constructor, &JSWebResourceRequest::Destructor); } void SetErrorEvent(const ReceivedErrorEvent& eventInfo) { request_ = eventInfo.GetRequest(); } void SetHttpErrorEvent(const ReceivedHttpErrorEvent& eventInfo) { request_ = eventInfo.GetRequest(); } void SetOnInterceptRequestEvent(const OnInterceptRequestEvent& eventInfo) { request_ = eventInfo.GetRequest(); } void SetLoadInterceptEvent(const LoadInterceptEvent& eventInfo) { request_ = eventInfo.GetRequest(); } void IsRedirect(const JSCallbackInfo& args) { auto isRedirect = JSVal(ToJSValue(request_->IsRedirect())); auto descriptionRef = JSRef::Make(isRedirect); args.SetReturnValue(descriptionRef); } void GetRequestUrl(const JSCallbackInfo& args) { auto url = JSVal(ToJSValue(request_->GetUrl())); auto descriptionRef = JSRef::Make(url); args.SetReturnValue(descriptionRef); } void GetRequestMethod(const JSCallbackInfo& args) { auto method = JSVal(ToJSValue(request_->GetMethod())); auto descriptionRef = JSRef::Make(method); args.SetReturnValue(descriptionRef); } void IsRequestGesture(const JSCallbackInfo& args) { auto isRequestGesture = JSVal(ToJSValue(request_->HasGesture())); auto descriptionRef = JSRef::Make(isRequestGesture); args.SetReturnValue(descriptionRef); } void IsMainFrame(const JSCallbackInfo& args) { auto isMainFrame = JSVal(ToJSValue(request_->IsMainFrame())); auto descriptionRef = JSRef::Make(isMainFrame); args.SetReturnValue(descriptionRef); } void GetRequestHeader(const JSCallbackInfo& args) { auto map = request_->GetHeaders(); std::map::iterator iterator; uint32_t index = 0; JSRef headers = JSRef::New(); for (iterator = map.begin(); iterator != map.end(); ++iterator) { JSRef header = JSRef::New(); header->SetProperty("headerKey", iterator->first); header->SetProperty("headerValue", iterator->second); headers->SetValueAt(index++, header); } args.SetReturnValue(headers); } void SetLoadOverrideEvent(const LoadOverrideEvent& eventInfo) { request_ = eventInfo.GetRequest(); } private: static void Constructor(const JSCallbackInfo& args) { auto jSWebResourceRequest = Referenced::MakeRefPtr(); jSWebResourceRequest->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jSWebResourceRequest)); } static void Destructor(JSWebResourceRequest* jSWebResourceRequest) { if (jSWebResourceRequest != nullptr) { jSWebResourceRequest->DecRefCount(); } } RefPtr request_; }; class JSFileSelectorParam : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("FileSelectorParam"); JSClass::CustomMethod("getTitle", &JSFileSelectorParam::GetTitle); JSClass::CustomMethod("getMode", &JSFileSelectorParam::GetMode); JSClass::CustomMethod("getAcceptType", &JSFileSelectorParam::GetAcceptType); JSClass::CustomMethod("isCapture", &JSFileSelectorParam::IsCapture); JSClass::Bind( globalObj, &JSFileSelectorParam::Constructor, &JSFileSelectorParam::Destructor); } void SetParam(const FileSelectorEvent& eventInfo) { param_ = eventInfo.GetParam(); } void GetTitle(const JSCallbackInfo& args) { auto title = JSVal(ToJSValue(param_->GetTitle())); auto descriptionRef = JSRef::Make(title); args.SetReturnValue(descriptionRef); } void GetMode(const JSCallbackInfo& args) { auto mode = JSVal(ToJSValue(param_->GetMode())); auto descriptionRef = JSRef::Make(mode); args.SetReturnValue(descriptionRef); } void IsCapture(const JSCallbackInfo& args) { auto isCapture = JSVal(ToJSValue(param_->IsCapture())); auto descriptionRef = JSRef::Make(isCapture); args.SetReturnValue(descriptionRef); } void GetAcceptType(const JSCallbackInfo& args) { auto acceptTypes = param_->GetAcceptType(); JSRef result = JSRef::New(); std::vector::iterator iterator; uint32_t index = 0; for (iterator = acceptTypes.begin(); iterator != acceptTypes.end(); ++iterator) { auto valueStr = JSVal(ToJSValue(*iterator)); auto value = JSRef::Make(valueStr); result->SetValueAt(index++, value); } args.SetReturnValue(result); } private: static void Constructor(const JSCallbackInfo& args) { auto jSFilerSelectorParam = Referenced::MakeRefPtr(); jSFilerSelectorParam->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jSFilerSelectorParam)); } static void Destructor(JSFileSelectorParam* jSFilerSelectorParam) { if (jSFilerSelectorParam != nullptr) { jSFilerSelectorParam->DecRefCount(); } } RefPtr param_; }; class JSFileSelectorResult : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("FileSelectorResult"); JSClass::CustomMethod("handleFileList", &JSFileSelectorResult::HandleFileList); JSClass::Bind( globalObj, &JSFileSelectorResult::Constructor, &JSFileSelectorResult::Destructor); } void SetResult(const FileSelectorEvent& eventInfo) { result_ = eventInfo.GetFileSelectorResult(); } void HandleFileList(const JSCallbackInfo& args) { std::vector fileList; if (args[0]->IsArray()) { JSRef array = JSRef::Cast(args[0]); for (size_t i = 0; i < array->Length(); i++) { JSRef val = array->GetValueAt(i); if (!val->IsString()) { continue; } std::string fileName; if (!ConvertFromJSValue(val, fileName)) { continue; } fileList.push_back(fileName); } } if (result_) { result_->HandleFileList(fileList); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsFileSelectorResult = Referenced::MakeRefPtr(); jsFileSelectorResult->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsFileSelectorResult)); } static void Destructor(JSFileSelectorResult* jsFileSelectorResult) { if (jsFileSelectorResult != nullptr) { jsFileSelectorResult->DecRefCount(); } } RefPtr result_; }; class JSContextMenuParam : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebContextMenuParam"); JSClass::CustomMethod("x", &JSContextMenuParam::GetXCoord); JSClass::CustomMethod("y", &JSContextMenuParam::GetYCoord); JSClass::CustomMethod("getLinkUrl", &JSContextMenuParam::GetLinkUrl); JSClass::CustomMethod("getUnfilteredLinkUrl", &JSContextMenuParam::GetUnfilteredLinkUrl); JSClass::CustomMethod("getSourceUrl", &JSContextMenuParam::GetSourceUrl); JSClass::CustomMethod("existsImageContents", &JSContextMenuParam::HasImageContents); JSClass::CustomMethod("getSelectionText", &JSContextMenuParam::GetSelectionText); JSClass::CustomMethod("isEditable", &JSContextMenuParam::IsEditable); JSClass::CustomMethod("getEditStateFlags", &JSContextMenuParam::GetEditStateFlags); JSClass::CustomMethod("getSourceType", &JSContextMenuParam::GetSourceType); JSClass::CustomMethod("getInputFieldType", &JSContextMenuParam::GetInputFieldType); JSClass::CustomMethod("getMediaType", &JSContextMenuParam::GetMediaType); JSClass::CustomMethod("getPreviewWidth", &JSContextMenuParam::GetPreviewWidth); JSClass::CustomMethod("getPreviewHeight", &JSContextMenuParam::GetPreviewHeight); JSClass::Bind(globalObj, &JSContextMenuParam::Constructor, &JSContextMenuParam::Destructor); } void UpdatePreviewSize() { if (previewWidth_ >= 0 && previewHeight_ >= 0) { return; } if (param_) { int32_t x = 0; int32_t y = 0; param_->GetImageRect(x, y, previewWidth_, previewHeight_); } } void GetPreviewWidth(const JSCallbackInfo& args) { auto ret = JSVal(ToJSValue(previewWidth_)); auto descriptionRef = JSRef::Make(ret); args.SetReturnValue(descriptionRef); } void GetPreviewHeight(const JSCallbackInfo& args) { auto ret = JSVal(ToJSValue(previewHeight_)); auto descriptionRef = JSRef::Make(ret); args.SetReturnValue(descriptionRef); } void SetParam(const ContextMenuEvent& eventInfo) { param_ = eventInfo.GetParam(); UpdatePreviewSize(); } void GetXCoord(const JSCallbackInfo& args) { int32_t ret = -1; if (param_) { ret = param_->GetXCoord(); } auto xCoord = JSVal(ToJSValue(ret)); auto descriptionRef = JSRef::Make(xCoord); args.SetReturnValue(descriptionRef); } void GetYCoord(const JSCallbackInfo& args) { int32_t ret = -1; if (param_) { ret = param_->GetYCoord(); } auto yCoord = JSVal(ToJSValue(ret)); auto descriptionRef = JSRef::Make(yCoord); args.SetReturnValue(descriptionRef); } void GetLinkUrl(const JSCallbackInfo& args) { std::string url; if (param_) { url = param_->GetLinkUrl(); } auto linkUrl = JSVal(ToJSValue(url)); auto descriptionRef = JSRef::Make(linkUrl); args.SetReturnValue(descriptionRef); } void GetUnfilteredLinkUrl(const JSCallbackInfo& args) { std::string url; if (param_) { url = param_->GetUnfilteredLinkUrl(); } auto unfilteredLinkUrl = JSVal(ToJSValue(url)); auto descriptionRef = JSRef::Make(unfilteredLinkUrl); args.SetReturnValue(descriptionRef); } void GetSourceUrl(const JSCallbackInfo& args) { std::string url; if (param_) { url = param_->GetSourceUrl(); } auto sourceUrl = JSVal(ToJSValue(url)); auto descriptionRef = JSRef::Make(sourceUrl); args.SetReturnValue(descriptionRef); } void HasImageContents(const JSCallbackInfo& args) { bool ret = false; if (param_) { ret = param_->HasImageContents(); } auto hasImageContents = JSVal(ToJSValue(ret)); auto descriptionRef = JSRef::Make(hasImageContents); args.SetReturnValue(descriptionRef); } void GetSelectionText(const JSCallbackInfo& args) { std::string text; if (param_) { text = param_->GetSelectionText(); } auto jsText = JSVal(ToJSValue(text)); auto descriptionRef = JSRef::Make(jsText); args.SetReturnValue(descriptionRef); } void IsEditable(const JSCallbackInfo& args) { bool flag = false; if (param_) { flag = param_->IsEditable(); } auto jsFlag = JSVal(ToJSValue(flag)); auto descriptionRef = JSRef::Make(jsFlag); args.SetReturnValue(descriptionRef); } void GetEditStateFlags(const JSCallbackInfo& args) { int32_t flags = 0; if (param_) { flags = param_->GetEditStateFlags(); } auto jsFlags = JSVal(ToJSValue(flags)); auto descriptionRef = JSRef::Make(jsFlags); args.SetReturnValue(descriptionRef); } void GetSourceType(const JSCallbackInfo& args) { int32_t type = 0; if (param_) { type = param_->GetSourceType(); } auto jsType = JSVal(ToJSValue(type)); auto descriptionRef = JSRef::Make(jsType); args.SetReturnValue(descriptionRef); } void GetInputFieldType(const JSCallbackInfo& args) { int32_t type = 0; if (param_) { type = param_->GetInputFieldType(); } auto jsType = JSVal(ToJSValue(type)); auto descriptionRef = JSRef::Make(jsType); args.SetReturnValue(descriptionRef); } void GetMediaType(const JSCallbackInfo& args) { int32_t type = 0; if (param_) { type = param_->GetMediaType(); } auto jsType = JSVal(ToJSValue(type)); auto descriptionRef = JSRef::Make(jsType); args.SetReturnValue(descriptionRef); } private: static void Constructor(const JSCallbackInfo& args) { auto jSContextMenuParam = Referenced::MakeRefPtr(); jSContextMenuParam->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jSContextMenuParam)); } static void Destructor(JSContextMenuParam* jSContextMenuParam) { if (jSContextMenuParam != nullptr) { jSContextMenuParam->DecRefCount(); } } RefPtr param_; int32_t previewWidth_ = -1; int32_t previewHeight_ = -1; }; class JSContextMenuResult : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebContextMenuResult"); JSClass::CustomMethod("closeContextMenu", &JSContextMenuResult::Cancel); JSClass::CustomMethod("copyImage", &JSContextMenuResult::CopyImage); JSClass::CustomMethod("copy", &JSContextMenuResult::Copy); JSClass::CustomMethod("paste", &JSContextMenuResult::Paste); JSClass::CustomMethod("cut", &JSContextMenuResult::Cut); JSClass::CustomMethod("selectAll", &JSContextMenuResult::SelectAll); JSClass::Bind( globalObj, &JSContextMenuResult::Constructor, &JSContextMenuResult::Destructor); } void SetResult(const ContextMenuEvent& eventInfo) { result_ = eventInfo.GetContextMenuResult(); } void Cancel(const JSCallbackInfo& args) { if (result_) { result_->Cancel(); } } void CopyImage(const JSCallbackInfo& args) { if (result_) { result_->CopyImage(); } } void Copy(const JSCallbackInfo& args) { if (result_) { result_->Copy(); } } void Paste(const JSCallbackInfo& args) { if (result_) { result_->Paste(); } } void Cut(const JSCallbackInfo& args) { if (result_) { result_->Cut(); } } void SelectAll(const JSCallbackInfo& args) { if (result_) { result_->SelectAll(); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsContextMenuResult = Referenced::MakeRefPtr(); jsContextMenuResult->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsContextMenuResult)); } static void Destructor(JSContextMenuResult* jsContextMenuResult) { if (jsContextMenuResult != nullptr) { jsContextMenuResult->DecRefCount(); } } RefPtr result_; }; class JSWebAppLinkCallback : public Referenced { public: static void JSBind(BindingTarget globalObj) { JSClass::Declare("WebAppLinkCallback"); JSClass::CustomMethod("continueLoad", &JSWebAppLinkCallback::ContinueLoad); JSClass::CustomMethod("cancelLoad", &JSWebAppLinkCallback::CancelLoad); JSClass::Bind( globalObj, &JSWebAppLinkCallback::Constructor, &JSWebAppLinkCallback::Destructor); } void SetEvent(const WebAppLinkEvent& eventInfo) { callback_ = eventInfo.GetCallback(); } void ContinueLoad(const JSCallbackInfo& args) { if (callback_) { callback_->ContinueLoad(); } } void CancelLoad(const JSCallbackInfo& args) { if (callback_) { callback_->CancelLoad(); } } private: static void Constructor(const JSCallbackInfo& args) { auto jsWebAppLinkCallback = Referenced::MakeRefPtr(); jsWebAppLinkCallback->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(jsWebAppLinkCallback)); } static void Destructor(JSWebAppLinkCallback* jsWebAppLinkCallback) { if (jsWebAppLinkCallback != nullptr) { jsWebAppLinkCallback->DecRefCount(); } } RefPtr callback_; }; void JSWeb::JSBind(BindingTarget globalObj) { JSClass::Declare("Web"); JSClass::StaticMethod("create", &JSWeb::Create); JSClass::StaticMethod("onAlert", &JSWeb::OnAlert); JSClass::StaticMethod("onBeforeUnload", &JSWeb::OnBeforeUnload); JSClass::StaticMethod("onConfirm", &JSWeb::OnConfirm); JSClass::StaticMethod("onPrompt", &JSWeb::OnPrompt); JSClass::StaticMethod("onConsole", &JSWeb::OnConsoleLog); JSClass::StaticMethod("onFullScreenEnter", &JSWeb::OnFullScreenEnter); JSClass::StaticMethod("onFullScreenExit", &JSWeb::OnFullScreenExit); JSClass::StaticMethod("onPageBegin", &JSWeb::OnPageStart); JSClass::StaticMethod("onPageEnd", &JSWeb::OnPageFinish); JSClass::StaticMethod("onProgressChange", &JSWeb::OnProgressChange); JSClass::StaticMethod("onTitleReceive", &JSWeb::OnTitleReceive); JSClass::StaticMethod("onGeolocationHide", &JSWeb::OnGeolocationHide); JSClass::StaticMethod("onGeolocationShow", &JSWeb::OnGeolocationShow); JSClass::StaticMethod("onRequestSelected", &JSWeb::OnRequestFocus); JSClass::StaticMethod("onShowFileSelector", &JSWeb::OnFileSelectorShow); JSClass::StaticMethod("javaScriptAccess", &JSWeb::JsEnabled); JSClass::StaticMethod("fileExtendAccess", &JSWeb::ContentAccessEnabled); JSClass::StaticMethod("fileAccess", &JSWeb::FileAccessEnabled); JSClass::StaticMethod("onDownloadStart", &JSWeb::OnDownloadStart); JSClass::StaticMethod("onErrorReceive", &JSWeb::OnErrorReceive); JSClass::StaticMethod("onHttpErrorReceive", &JSWeb::OnHttpErrorReceive); JSClass::StaticMethod("onInterceptRequest", &JSWeb::OnInterceptRequest); JSClass::StaticMethod("onUrlLoadIntercept", &JSWeb::OnUrlLoadIntercept); JSClass::StaticMethod("onLoadIntercept", &JSWeb::OnLoadIntercept); JSClass::StaticMethod("onlineImageAccess", &JSWeb::OnLineImageAccessEnabled); JSClass::StaticMethod("domStorageAccess", &JSWeb::DomStorageAccessEnabled); JSClass::StaticMethod("imageAccess", &JSWeb::ImageAccessEnabled); JSClass::StaticMethod("mixedMode", &JSWeb::MixedMode); JSClass::StaticMethod("enableNativeEmbedMode", &JSWeb::EnableNativeEmbedMode); JSClass::StaticMethod("registerNativeEmbedRule", &JSWeb::RegisterNativeEmbedRule); JSClass::StaticMethod("zoomAccess", &JSWeb::ZoomAccessEnabled); JSClass::StaticMethod("geolocationAccess", &JSWeb::GeolocationAccessEnabled); JSClass::StaticMethod("javaScriptProxy", &JSWeb::JavaScriptProxy); JSClass::StaticMethod("userAgent", &JSWeb::UserAgent); JSClass::StaticMethod("onRenderExited", &JSWeb::OnRenderExited); JSClass::StaticMethod("onRefreshAccessedHistory", &JSWeb::OnRefreshAccessedHistory); JSClass::StaticMethod("cacheMode", &JSWeb::CacheMode); JSClass::StaticMethod("overviewModeAccess", &JSWeb::OverviewModeAccess); JSClass::StaticMethod("webDebuggingAccess", &JSWeb::WebDebuggingAccess); JSClass::StaticMethod("wideViewModeAccess", &JSWeb::WideViewModeAccess); JSClass::StaticMethod("fileFromUrlAccess", &JSWeb::FileFromUrlAccess); JSClass::StaticMethod("databaseAccess", &JSWeb::DatabaseAccess); JSClass::StaticMethod("textZoomRatio", &JSWeb::TextZoomRatio); JSClass::StaticMethod("textZoomAtio", &JSWeb::TextZoomRatio); JSClass::StaticMethod("initialScale", &JSWeb::InitialScale); JSClass::StaticMethod("backgroundColor", &JSWeb::BackgroundColor); JSClass::StaticMethod("onKeyEvent", &JSWeb::OnKeyEvent); JSClass::StaticMethod("onTouch", &JSInteractableView::JsOnTouch); JSClass::StaticMethod("onMouse", &JSWeb::OnMouse); JSClass::StaticMethod("onResourceLoad", &JSWeb::OnResourceLoad); JSClass::StaticMethod("onScaleChange", &JSWeb::OnScaleChange); JSClass::StaticMethod("password", &JSWeb::Password); JSClass::StaticMethod("tableData", &JSWeb::TableData); JSClass::StaticMethod("onFileSelectorShow", &JSWeb::OnFileSelectorShowAbandoned); JSClass::StaticMethod("onHttpAuthRequest", &JSWeb::OnHttpAuthRequest); JSClass::StaticMethod("onSslErrorReceive", &JSWeb::OnSslErrRequest); JSClass::StaticMethod("onSslErrorEventReceive", &JSWeb::OnSslErrorRequest); JSClass::StaticMethod("onSslErrorEvent", &JSWeb::OnAllSslErrorRequest); JSClass::StaticMethod("onClientAuthenticationRequest", &JSWeb::OnSslSelectCertRequest); JSClass::StaticMethod("onPermissionRequest", &JSWeb::OnPermissionRequest); JSClass::StaticMethod("onContextMenuShow", &JSWeb::OnContextMenuShow); JSClass::StaticMethod("onContextMenuHide", &JSWeb::OnContextMenuHide); JSClass::StaticMethod("onSearchResultReceive", &JSWeb::OnSearchResultReceive); JSClass::StaticMethod("mediaPlayGestureAccess", &JSWeb::MediaPlayGestureAccess); JSClass::StaticMethod("onDragStart", &JSWeb::JsOnDragStart); JSClass::StaticMethod("onDragEnter", &JSWeb::JsOnDragEnter); JSClass::StaticMethod("onDragMove", &JSWeb::JsOnDragMove); JSClass::StaticMethod("onDragLeave", &JSWeb::JsOnDragLeave); JSClass::StaticMethod("onDrop", &JSWeb::JsOnDrop); JSClass::StaticMethod("onScroll", &JSWeb::OnScroll); JSClass::StaticMethod("rotate", &JSWeb::WebRotate); JSClass::StaticMethod("pinchSmooth", &JSWeb::PinchSmoothModeEnabled); JSClass::StaticMethod("onAttach", &JSInteractableView::JsOnAttach); JSClass::StaticMethod("onAppear", &JSInteractableView::JsOnAppear); JSClass::StaticMethod("onDetach", &JSInteractableView::JsOnDetach); JSClass::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear); JSClass::StaticMethod("onWindowNew", &JSWeb::OnWindowNew); JSClass::StaticMethod("onWindowExit", &JSWeb::OnWindowExit); JSClass::StaticMethod("multiWindowAccess", &JSWeb::MultiWindowAccessEnabled); JSClass::StaticMethod("allowWindowOpenMethod", &JSWeb::AllowWindowOpenMethod); JSClass::StaticMethod("webCursiveFont", &JSWeb::WebCursiveFont); JSClass::StaticMethod("webFantasyFont", &JSWeb::WebFantasyFont); JSClass::StaticMethod("webFixedFont", &JSWeb::WebFixedFont); JSClass::StaticMethod("webSansSerifFont", &JSWeb::WebSansSerifFont); JSClass::StaticMethod("webSerifFont", &JSWeb::WebSerifFont); JSClass::StaticMethod("webStandardFont", &JSWeb::WebStandardFont); JSClass::StaticMethod("defaultFixedFontSize", &JSWeb::DefaultFixedFontSize); JSClass::StaticMethod("defaultFontSize", &JSWeb::DefaultFontSize); JSClass::StaticMethod("defaultTextEncodingFormat", &JSWeb::DefaultTextEncodingFormat); JSClass::StaticMethod("minFontSize", &JSWeb::MinFontSize); JSClass::StaticMethod("minLogicalFontSize", &JSWeb::MinLogicalFontSize); JSClass::StaticMethod("blockNetwork", &JSWeb::BlockNetwork); JSClass::StaticMethod("onPageVisible", &JSWeb::OnPageVisible); JSClass::StaticMethod("onInterceptKeyEvent", &JSWeb::OnInterceptKeyEvent); JSClass::StaticMethod("onDataResubmitted", &JSWeb::OnDataResubmitted); JSClass::StaticMethod("onFaviconReceived", &JSWeb::OnFaviconReceived); JSClass::StaticMethod("onTouchIconUrlReceived", &JSWeb::OnTouchIconUrlReceived); JSClass::StaticMethod("darkMode", &JSWeb::DarkMode); JSClass::StaticMethod("forceDarkAccess", &JSWeb::ForceDarkAccess); JSClass::StaticMethod("overScrollMode", &JSWeb::OverScrollMode); JSClass::StaticMethod("blurOnKeyboardHideMode", &JSWeb::BlurOnKeyboardHideMode); JSClass::StaticMethod("horizontalScrollBarAccess", &JSWeb::HorizontalScrollBarAccess); JSClass::StaticMethod("verticalScrollBarAccess", &JSWeb::VerticalScrollBarAccess); JSClass::StaticMethod("onAudioStateChanged", &JSWeb::OnAudioStateChanged); JSClass::StaticMethod("mediaOptions", &JSWeb::MediaOptions); JSClass::StaticMethod("onFirstContentfulPaint", &JSWeb::OnFirstContentfulPaint); JSClass::StaticMethod("onFirstMeaningfulPaint", &JSWeb::OnFirstMeaningfulPaint); JSClass::StaticMethod("onLargestContentfulPaint", &JSWeb::OnLargestContentfulPaint); JSClass::StaticMethod("onSafeBrowsingCheckResult", &JSWeb::OnSafeBrowsingCheckResult); JSClass::StaticMethod("onNavigationEntryCommitted", &JSWeb::OnNavigationEntryCommitted); JSClass::StaticMethod("onIntelligentTrackingPreventionResult", &JSWeb::OnIntelligentTrackingPreventionResult); JSClass::StaticMethod("onControllerAttached", &JSWeb::OnControllerAttached); JSClass::StaticMethod("onOverScroll", &JSWeb::OnOverScroll); JSClass::StaticMethod("onNativeEmbedLifecycleChange", &JSWeb::OnNativeEmbedLifecycleChange); JSClass::StaticMethod("onNativeEmbedVisibilityChange", &JSWeb::OnNativeEmbedVisibilityChange); JSClass::StaticMethod("onNativeEmbedGestureEvent", &JSWeb::OnNativeEmbedGestureEvent); JSClass::StaticMethod("copyOptions", &JSWeb::CopyOption); JSClass::StaticMethod("onScreenCaptureRequest", &JSWeb::OnScreenCaptureRequest); JSClass::StaticMethod("layoutMode", &JSWeb::SetLayoutMode); JSClass::StaticMethod("nestedScroll", &JSWeb::SetNestedScroll); JSClass::StaticMethod("metaViewport", &JSWeb::SetMetaViewport); JSClass::StaticMethod("javaScriptOnDocumentStart", &JSWeb::JavaScriptOnDocumentStart); JSClass::StaticMethod("javaScriptOnDocumentEnd", &JSWeb::JavaScriptOnDocumentEnd); JSClass::StaticMethod("onOverrideUrlLoading", &JSWeb::OnOverrideUrlLoading); JSClass::StaticMethod("textAutosizing", &JSWeb::TextAutosizing); JSClass::StaticMethod("enableNativeMediaPlayer", &JSWeb::EnableNativeVideoPlayer); JSClass::StaticMethod("onRenderProcessNotResponding", &JSWeb::OnRenderProcessNotResponding); JSClass::StaticMethod("onRenderProcessResponding", &JSWeb::OnRenderProcessResponding); JSClass::StaticMethod("onViewportFitChanged", &JSWeb::OnViewportFitChanged); JSClass::StaticMethod("selectionMenuOptions", &JSWeb::SelectionMenuOptions); JSClass::StaticMethod("onAdsBlocked", &JSWeb::OnAdsBlocked); JSClass::StaticMethod("onInterceptKeyboardAttach", &JSWeb::OnInterceptKeyboardAttach); JSClass::StaticMethod("forceDisplayScrollBar", &JSWeb::ForceDisplayScrollBar); JSClass::StaticMethod("keyboardAvoidMode", &JSWeb::KeyboardAvoidMode); JSClass::StaticMethod("editMenuOptions", &JSWeb::EditMenuOptions); JSClass::StaticMethod("enableHapticFeedback", &JSWeb::EnableHapticFeedback); JSClass::StaticMethod("bindSelectionMenu", &JSWeb::BindSelectionMenu); JSClass::InheritAndBind(globalObj); JSWebDialog::JSBind(globalObj); JSWebGeolocation::JSBind(globalObj); JSWebResourceRequest::JSBind(globalObj); JSWebResourceError::JSBind(globalObj); JSWebResourceResponse::JSBind(globalObj); JSWebConsoleLog::JSBind(globalObj); JSFileSelectorParam::JSBind(globalObj); JSFileSelectorResult::JSBind(globalObj); JSFullScreenExitHandler::JSBind(globalObj); JSWebHttpAuth::JSBind(globalObj); JSWebSslError::JSBind(globalObj); JSWebAllSslError::JSBind(globalObj); JSWebSslSelectCert::JSBind(globalObj); JSWebPermissionRequest::JSBind(globalObj); JSContextMenuParam::JSBind(globalObj); JSContextMenuResult::JSBind(globalObj); JSWebWindowNewHandler::JSBind(globalObj); JSDataResubmitted::JSBind(globalObj); JSScreenCaptureRequest::JSBind(globalObj); JSNativeEmbedGestureRequest::JSBind(globalObj); JSWebAppLinkCallback::JSBind(globalObj); JSWebKeyboardController::JSBind(globalObj); } JSRef LoadWebConsoleLogEventToJSValue(const LoadWebConsoleLogEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef messageObj = JSClass::NewInstance(); auto jsWebConsoleLog = Referenced::Claim(messageObj->Unwrap()); jsWebConsoleLog->SetMessage(eventInfo.GetMessage()); obj->SetPropertyObject("message", messageObj); return JSRef::Cast(obj); } JSRef WebDialogEventToJSValue(const WebDialogEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef resultObj = JSClass::NewInstance(); auto jsWebDialog = Referenced::Claim(resultObj->Unwrap()); jsWebDialog->SetResult(eventInfo.GetResult()); obj->SetProperty("url", eventInfo.GetUrl()); obj->SetProperty("message", eventInfo.GetMessage()); if (eventInfo.GetType() == DialogEventType::DIALOG_EVENT_PROMPT) { obj->SetProperty("value", eventInfo.GetValue()); } obj->SetPropertyObject("result", resultObj); return JSRef::Cast(obj); } JSRef LoadWebPageFinishEventToJSValue(const LoadWebPageFinishEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("url", eventInfo.GetLoadedUrl()); return JSRef::Cast(obj); } JSRef ContextMenuHideEventToJSValue(const ContextMenuHideEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("info", eventInfo.GetInfo()); return JSRef::Cast(obj); } JSRef FullScreenEnterEventToJSValue(const FullScreenEnterEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef resultObj = JSClass::NewInstance(); auto jsFullScreenExitHandler = Referenced::Claim(resultObj->Unwrap()); if (!jsFullScreenExitHandler) { return JSRef::Cast(obj); } jsFullScreenExitHandler->SetHandler(eventInfo.GetHandler()); obj->SetPropertyObject("handler", resultObj); obj->SetProperty("videoWidth", eventInfo.GetVideoNaturalWidth()); obj->SetProperty("videoHeight", eventInfo.GetVideoNaturalHeight()); return JSRef::Cast(obj); } JSRef FullScreenExitEventToJSValue(const FullScreenExitEvent& eventInfo) { return JSRef::Make(ToJSValue(eventInfo.IsFullScreen())); } JSRef LoadWebPageStartEventToJSValue(const LoadWebPageStartEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("url", eventInfo.GetLoadedUrl()); return JSRef::Cast(obj); } JSRef LoadWebProgressChangeEventToJSValue(const LoadWebProgressChangeEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("newProgress", eventInfo.GetNewProgress()); return JSRef::Cast(obj); } JSRef LoadWebTitleReceiveEventToJSValue(const LoadWebTitleReceiveEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("title", eventInfo.GetTitle()); return JSRef::Cast(obj); } JSRef UrlLoadInterceptEventToJSValue(const UrlLoadInterceptEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("data", eventInfo.GetData()); return JSRef::Cast(obj); } JSRef LoadInterceptEventToJSValue(const LoadInterceptEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef requestObj = JSClass::NewInstance(); auto requestEvent = Referenced::Claim(requestObj->Unwrap()); requestEvent->SetLoadInterceptEvent(eventInfo); obj->SetPropertyObject("data", requestObj); return JSRef::Cast(obj); } JSRef LoadWebGeolocationHideEventToJSValue(const LoadWebGeolocationHideEvent& eventInfo) { return JSRef::Make(ToJSValue(eventInfo.GetOrigin())); } JSRef LoadWebGeolocationShowEventToJSValue(const LoadWebGeolocationShowEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("origin", eventInfo.GetOrigin()); JSRef geolocationObj = JSClass::NewInstance(); auto geolocationEvent = Referenced::Claim(geolocationObj->Unwrap()); geolocationEvent->SetEvent(eventInfo); obj->SetPropertyObject("geolocation", geolocationObj); return JSRef::Cast(obj); } JSRef DownloadStartEventToJSValue(const DownloadStartEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("url", eventInfo.GetUrl()); obj->SetProperty("userAgent", eventInfo.GetUserAgent()); obj->SetProperty("contentDisposition", eventInfo.GetContentDisposition()); obj->SetProperty("mimetype", eventInfo.GetMimetype()); obj->SetProperty("contentLength", eventInfo.GetContentLength()); return JSRef::Cast(obj); } JSRef LoadWebRequestFocusEventToJSValue(const LoadWebRequestFocusEvent& eventInfo) { return JSRef::Make(ToJSValue(eventInfo.GetRequestFocus())); } JSRef WebHttpAuthEventToJSValue(const WebHttpAuthEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef resultObj = JSClass::NewInstance(); auto jsWebHttpAuth = Referenced::Claim(resultObj->Unwrap()); if (!jsWebHttpAuth) { return JSRef::Cast(obj); } jsWebHttpAuth->SetResult(eventInfo.GetResult()); obj->SetPropertyObject("handler", resultObj); obj->SetProperty("host", eventInfo.GetHost()); obj->SetProperty("realm", eventInfo.GetRealm()); return JSRef::Cast(obj); } JSRef WebSslErrorEventToJSValue(const WebSslErrorEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef resultObj = JSClass::NewInstance(); auto jsWebSslError = Referenced::Claim(resultObj->Unwrap()); if (!jsWebSslError) { return JSRef::Cast(obj); } jsWebSslError->SetResult(eventInfo.GetResult()); obj->SetPropertyObject("handler", resultObj); obj->SetProperty("error", eventInfo.GetError()); return JSRef::Cast(obj); } JSRef WebAllSslErrorEventToJSValue(const WebAllSslErrorEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef resultObj = JSClass::NewInstance(); auto jsWebAllSslError = Referenced::Claim(resultObj->Unwrap()); if (!jsWebAllSslError) { return JSRef::Cast(obj); } jsWebAllSslError->SetResult(eventInfo.GetResult()); obj->SetPropertyObject("handler", resultObj); obj->SetProperty("error", eventInfo.GetError()); obj->SetProperty("url", eventInfo.GetUrl()); obj->SetProperty("originalUrl", eventInfo.GetOriginalUrl()); obj->SetProperty("referrer", eventInfo.GetReferrer()); obj->SetProperty("isFatalError", eventInfo.GetIsFatalError()); obj->SetProperty("isMainFrame", eventInfo.GetIsMainFrame()); return JSRef::Cast(obj); } JSRef WebSslSelectCertEventToJSValue(const WebSslSelectCertEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef resultObj = JSClass::NewInstance(); auto jsWebSslSelectCert = Referenced::Claim(resultObj->Unwrap()); if (!jsWebSslSelectCert) { return JSRef::Cast(obj); } jsWebSslSelectCert->SetResult(eventInfo.GetResult()); obj->SetPropertyObject("handler", resultObj); obj->SetProperty("host", eventInfo.GetHost()); obj->SetProperty("port", eventInfo.GetPort()); JSRef keyTypesArr = JSRef::New(); const std::vector& keyTypes = eventInfo.GetKeyTypes(); for (int32_t idx = 0; idx < static_cast(keyTypes.size()); ++idx) { JSRef keyType = JSRef::Make(ToJSValue(keyTypes[idx])); keyTypesArr->SetValueAt(idx, keyType); } obj->SetPropertyObject("keyTypes", keyTypesArr); JSRef issuersArr = JSRef::New(); const std::vector& issuers = eventInfo.GetIssuers_(); for (int32_t idx = 0; idx < static_cast(issuers.size()); ++idx) { JSRef issuer = JSRef::Make(ToJSValue(issuers[idx])); issuersArr->SetValueAt(idx, issuer); } obj->SetPropertyObject("issuers", issuersArr); return JSRef::Cast(obj); } JSRef SearchResultReceiveEventToJSValue(const SearchResultReceiveEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("activeMatchOrdinal", eventInfo.GetActiveMatchOrdinal()); obj->SetProperty("numberOfMatches", eventInfo.GetNumberOfMatches()); obj->SetProperty("isDoneCounting", eventInfo.GetIsDoneCounting()); return JSRef::Cast(obj); } JSRef LoadOverrideEventToJSValue(const LoadOverrideEvent& eventInfo) { JSRef requestObj = JSClass::NewInstance(); auto requestEvent = Referenced::Claim(requestObj->Unwrap()); requestEvent->SetLoadOverrideEvent(eventInfo); return JSRef::Cast(requestObj); } JSRef AdsBlockedEventToJSValue(const AdsBlockedEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("url", eventInfo.GetUrl()); JSRef adsBlockedArr = JSRef::New(); const std::vector& adsBlocked = eventInfo.GetAdsBlocked(); for (int32_t idx = 0; idx < static_cast(adsBlocked.size()); ++idx) { JSRef blockedUrl = JSRef::Make(ToJSValue(adsBlocked[idx])); adsBlockedArr->SetValueAt(idx, blockedUrl); } obj->SetPropertyObject("adsBlocked", adsBlockedArr); return JSRef::Cast(obj); } void JSWeb::ParseRawfileWebSrc(const JSRef& srcValue, std::string& webSrc) { if (!srcValue->IsObject() || webSrc.substr(0, RAWFILE_PREFIX.size()) != RAWFILE_PREFIX) { return; } std::string bundleName; std::string moduleName; GetJsMediaBundleInfo(srcValue, bundleName, moduleName); auto container = Container::Current(); CHECK_NULL_VOID(container); if ((!bundleName.empty() && !moduleName.empty()) && (bundleName != AceApplicationInfo::GetInstance().GetPackageName() || moduleName != container->GetModuleName())) { webSrc = RAWFILE_PREFIX + BUNDLE_NAME_PREFIX + bundleName + "/" + MODULE_NAME_PREFIX + moduleName + "/" + webSrc.substr(RAWFILE_PREFIX.size()); } } void JSWeb::Create(const JSCallbackInfo& info) { if (info.Length() < 1 || !info[0]->IsObject()) { return; } auto paramObject = JSRef::Cast(info[0]); JSRef srcValue = paramObject->GetProperty("src"); std::string webSrc; std::optional dstSrc; if (srcValue->IsString()) { dstSrc = srcValue->ToString(); } else if (ParseJsMedia(srcValue, webSrc)) { ParseRawfileWebSrc(srcValue, webSrc); int np = static_cast(webSrc.find_first_of("/")); dstSrc = np < 0 ? webSrc : webSrc.erase(np, 1); } if (!dstSrc) { return; } auto controllerObj = paramObject->GetProperty("controller"); if (!controllerObj->IsObject()) { return; } JsiRef type = JsiRef::Make(); bool isHasType = paramObject->HasProperty("type"); if (isHasType) { type = paramObject->GetProperty("type"); } else { type = paramObject->GetProperty("renderMode"); } RenderMode renderMode = RenderMode::ASYNC_RENDER; if (type->IsNumber() && (type->ToNumber() >= 0) && (type->ToNumber() <= 1)) { renderMode = static_cast(type->ToNumber()); } bool incognitoMode = false; ParseJsBool(paramObject->GetProperty("incognitoMode"), incognitoMode); std::string sharedRenderProcessToken = ""; ParseJsString(paramObject->GetProperty("sharedRenderProcessToken"), sharedRenderProcessToken); auto controller = JSRef::Cast(controllerObj); auto setWebIdFunction = controller->GetProperty("setWebId"); if (setWebIdFunction->IsFunction()) { auto setIdCallback = [webviewController = controller, func = JSRef::Cast(setWebIdFunction)]( int32_t webId) { JSRef argv[] = { JSRef::Make(ToJSValue(webId)) }; func->Call(webviewController, 1, argv); }; auto setHapPathFunction = controller->GetProperty("innerSetHapPath"); std::function setHapPathCallback = nullptr; if (setHapPathFunction->IsFunction()) { setHapPathCallback = [webviewController = controller, func = JSRef::Cast(setHapPathFunction)]( const std::string& hapPath) { JSRef argv[] = { JSRef::Make(ToJSValue(hapPath)) }; func->Call(webviewController, 1, argv); }; } auto setRequestPermissionsFromUserFunction = controller->GetProperty("requestPermissionsFromUserWeb"); std::function&)> requestPermissionsFromUserCallback = nullptr; if (setRequestPermissionsFromUserFunction->IsFunction()) { requestPermissionsFromUserCallback = [webviewController = controller, func = JSRef::Cast(setRequestPermissionsFromUserFunction)] (const std::shared_ptr& info) { auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); JSRef obj = JSRef::New(); JSRef permissionObj = JSClass::NewInstance(); auto permissionEvent = Referenced::Claim(permissionObj->Unwrap()); permissionEvent->SetEvent(*eventInfo); obj->SetPropertyObject("request", permissionObj); JSRef argv[] = { JSRef::Cast(obj) }; auto result = func->Call(webviewController, 1, argv); }; } auto setOpenAppLinkFunction = controller->GetProperty("openAppLink"); std::function&)> openAppLinkCallback = nullptr; if (setOpenAppLinkFunction->IsFunction()) { TAG_LOGI(AceLogTag::ACE_WEB, "WebDelegate::OnOpenAppLink setOpenAppLinkFunction 2"); openAppLinkCallback = [webviewController = controller, func = JSRef::Cast(setOpenAppLinkFunction)] (const std::shared_ptr& info) { auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); JSRef obj = JSRef::New(); JSRef callbackObj = JSClass::NewInstance(); auto callbackEvent = Referenced::Claim(callbackObj->Unwrap()); callbackEvent->SetEvent(*eventInfo); obj->SetPropertyObject("result", callbackObj); JSRef urlVal = JSRef::Make(ToJSValue(eventInfo->GetUrl())); obj->SetPropertyObject("url", urlVal); JSRef argv[] = { JSRef::Cast(obj) }; auto result = func->Call(webviewController, 1, argv); }; } auto fileSelectorShowFromUserFunction = controller->GetProperty("fileSelectorShowFromUserWeb"); std::function&)> fileSelectorShowFromUserCallback = nullptr; if (fileSelectorShowFromUserFunction->IsFunction()) { fileSelectorShowFromUserCallback = [webviewController = controller, func = JSRef::Cast(fileSelectorShowFromUserFunction)] (const std::shared_ptr& info) { auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); JSRef obj = JSRef::New(); JSRef paramObj = JSClass::NewInstance(); auto fileSelectorParam = Referenced::Claim(paramObj->Unwrap()); fileSelectorParam->SetParam(*eventInfo); obj->SetPropertyObject("fileparam", paramObj); JSRef resultObj = JSClass::NewInstance(); auto fileSelectorResult = Referenced::Claim(resultObj->Unwrap()); fileSelectorResult->SetResult(*eventInfo); obj->SetPropertyObject("fileresult", resultObj); JSRef argv[] = { JSRef::Cast(obj) }; auto result = func->Call(webviewController, 1, argv); }; } int32_t parentNWebId = -1; bool isPopup = JSWebWindowNewHandler::ExistController(controller, parentNWebId); WebModel::GetInstance()->Create(isPopup ? "" : dstSrc.value(), std::move(setIdCallback), std::move(setHapPathCallback), parentNWebId, isPopup, renderMode, incognitoMode, sharedRenderProcessToken); WebModel::GetInstance()->SetDefaultFileSelectorShow(std::move(fileSelectorShowFromUserCallback)); WebModel::GetInstance()->SetPermissionClipboard(std::move(requestPermissionsFromUserCallback)); WebModel::GetInstance()->SetOpenAppLinkFunction(std::move(openAppLinkCallback)); auto getCmdLineFunction = controller->GetProperty("getCustomeSchemeCmdLine"); if (!getCmdLineFunction->IsFunction()) { return; } std::string cmdLine = JSRef::Cast(getCmdLineFunction)->Call(controller, 0, {})->ToString(); if (!cmdLine.empty()) { WebModel::GetInstance()->SetCustomScheme(cmdLine); } auto updateInstanceIdFunction = controller->GetProperty("updateInstanceId"); if (updateInstanceIdFunction->IsFunction()) { std::function updateInstanceIdCallback = [webviewController = controller, func = JSRef::Cast(updateInstanceIdFunction)](int32_t newId) { auto newIdVal = JSRef::Make(ToJSValue(newId)); auto result = func->Call(webviewController, 1, &newIdVal); }; NG::WebModelNG::GetInstance()->SetUpdateInstanceIdCallback(std::move(updateInstanceIdCallback)); } auto getWebDebugingFunction = controller->GetProperty("getWebDebuggingAccess"); if (!getWebDebugingFunction->IsFunction()) { return; } bool webDebuggingAccess = JSRef::Cast(getWebDebugingFunction)->Call(controller, 0, {})->ToBoolean(); if (webDebuggingAccess == JSWeb::webDebuggingAccess_) { return; } WebModel::GetInstance()->SetWebDebuggingAccessEnabled(webDebuggingAccess); JSWeb::webDebuggingAccess_ = webDebuggingAccess; return; } else { auto* jsWebController = controller->Unwrap(); CHECK_NULL_VOID(jsWebController); WebModel::GetInstance()->Create( dstSrc.value(), jsWebController->GetController(), renderMode, incognitoMode, sharedRenderProcessToken); } WebModel::GetInstance()->SetFocusable(true); WebModel::GetInstance()->SetFocusNode(true); } void JSWeb::WebRotate(const JSCallbackInfo& args) {} void JSWeb::OnAlert(const JSCallbackInfo& args) { JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_ALERT); } void JSWeb::OnBeforeUnload(const JSCallbackInfo& args) { JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_BEFORE_UNLOAD); } void JSWeb::OnConfirm(const JSCallbackInfo& args) { JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_CONFIRM); } void JSWeb::OnPrompt(const JSCallbackInfo& args) { JSWeb::OnCommonDialog(args, DialogEventType::DIALOG_EVENT_PROMPT); } void JSWeb::OnCommonDialog(const JSCallbackInfo& args, int dialogEventType) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>(JSRef::Cast(args[0]), WebDialogEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> bool { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, false); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); JSRef message = func->ExecuteWithValue(*eventInfo); if (message->IsBoolean()) { return message->ToBoolean(); } else { return false; } }; WebModel::GetInstance()->SetOnCommonDialog(jsCallback, dialogEventType); } void JSWeb::OnConsoleLog(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), LoadWebConsoleLogEventToJSValue); WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode]( const BaseEventInfo* info) -> bool { bool result = false; JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, result); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, false); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); JSRef message = func->ExecuteWithValue(*eventInfo); if (message->IsBoolean()) { result = message->ToBoolean(); } return result; }; WebModel::GetInstance()->SetOnConsoleLog(jsCallback); } void JSWeb::OnPageStart(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), LoadWebPageStartEventToJSValue); auto instanceId = Container::CurrentId(); WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnPageStart(jsCallback); } void JSWeb::OnPageFinish(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), LoadWebPageFinishEventToJSValue); auto instanceId = Container::CurrentId(); WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnPageFinish(jsCallback); } void JSWeb::OnProgressChange(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), LoadWebProgressChangeEventToJSValue); auto instanceId = Container::CurrentId(); WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->ExecuteWithValue(*eventInfo); }; WebModel::GetInstance()->SetOnProgressChange(jsCallback); } void JSWeb::OnTitleReceive(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), LoadWebTitleReceiveEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnTitleReceive(jsCallback); } void JSWeb::OnFullScreenExit(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), FullScreenExitEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnFullScreenExit(jsCallback); } void JSWeb::OnFullScreenEnter(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), FullScreenEnterEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); CHECK_NULL_VOID(func); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); CHECK_NULL_VOID(eventInfo); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnFullScreenEnter(jsCallback); } void JSWeb::OnGeolocationHide(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), LoadWebGeolocationHideEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnGeolocationHide(jsCallback); } void JSWeb::OnGeolocationShow(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), LoadWebGeolocationShowEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnGeolocationShow(jsCallback); } void JSWeb::OnRequestFocus(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), LoadWebRequestFocusEventToJSValue); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = frameNode]( const BaseEventInfo* info) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnRequestFocus(jsCallback); } void JSWeb::OnDownloadStart(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), DownloadStartEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnDownloadStart(jsCallback); } void JSWeb::OnHttpAuthRequest(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), WebHttpAuthEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> bool { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, false); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); JSRef message = func->ExecuteWithValue(*eventInfo); if (message->IsBoolean()) { return message->ToBoolean(); } return false; }; WebModel::GetInstance()->SetOnHttpAuthRequest(jsCallback); } void JSWeb::OnSslErrRequest(const JSCallbackInfo& args) { return; } void JSWeb::OnSslErrorRequest(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), WebSslErrorEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> bool { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, false); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); return true; }; WebModel::GetInstance()->SetOnSslErrorRequest(jsCallback); } void JSWeb::OnAllSslErrorRequest(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), WebAllSslErrorEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> bool { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, false); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); return true; }; WebModel::GetInstance()->SetOnAllSslErrorRequest(jsCallback); } void JSWeb::OnSslSelectCertRequest(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), WebSslSelectCertEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> bool { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, false); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); JSRef message = func->ExecuteWithValue(*eventInfo); if (message->IsBoolean()) { return message->ToBoolean(); } return false; }; WebModel::GetInstance()->SetOnSslSelectCertRequest(jsCallback); } void JSWeb::MediaPlayGestureAccess(bool isNeedGestureAccess) { WebModel::GetInstance()->SetMediaPlayGestureAccess(isNeedGestureAccess); } void JSWeb::OnKeyEvent(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); RefPtr jsOnKeyEventFunc = AceType::MakeRefPtr(JSRef::Cast(args[0])); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsOnKeyEventFunc), node = frameNode]( KeyEventInfo& keyEventInfo) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); func->Execute(keyEventInfo); }; WebModel::GetInstance()->SetOnKeyEvent(jsCallback); } JSRef ReceivedErrorEventToJSValue(const ReceivedErrorEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef requestObj = JSClass::NewInstance(); auto requestEvent = Referenced::Claim(requestObj->Unwrap()); requestEvent->SetErrorEvent(eventInfo); JSRef errorObj = JSClass::NewInstance(); auto errorEvent = Referenced::Claim(errorObj->Unwrap()); errorEvent->SetEvent(eventInfo); obj->SetPropertyObject("request", requestObj); obj->SetPropertyObject("error", errorObj); return JSRef::Cast(obj); } JSRef ReceivedHttpErrorEventToJSValue(const ReceivedHttpErrorEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef requestObj = JSClass::NewInstance(); auto requestEvent = Referenced::Claim(requestObj->Unwrap()); requestEvent->SetHttpErrorEvent(eventInfo); JSRef responseObj = JSClass::NewInstance(); auto responseEvent = Referenced::Claim(responseObj->Unwrap()); responseEvent->SetEvent(eventInfo); obj->SetPropertyObject("request", requestObj); obj->SetPropertyObject("response", responseObj); return JSRef::Cast(obj); } void JSWeb::OnErrorReceive(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), ReceivedErrorEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnErrorReceive(jsCallback); } void JSWeb::OnHttpErrorReceive(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), ReceivedHttpErrorEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnHttpErrorReceive(jsCallback); } JSRef OnInterceptRequestEventToJSValue(const OnInterceptRequestEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef requestObj = JSClass::NewInstance(); auto requestEvent = Referenced::Claim(requestObj->Unwrap()); requestEvent->SetOnInterceptRequestEvent(eventInfo); obj->SetPropertyObject("request", requestObj); return JSRef::Cast(obj); } void JSWeb::OnInterceptRequest(const JSCallbackInfo& args) { if ((args.Length() <= 0) || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), OnInterceptRequestEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> RefPtr { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, nullptr); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, nullptr); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); JSRef obj = func->ExecuteWithValue(*eventInfo); if (!obj->IsObject()) { return nullptr; } auto jsResponse = JSRef::Cast(obj)->Unwrap(); if (jsResponse) { return jsResponse->GetResponseObj(); } return nullptr; }; WebModel::GetInstance()->SetOnInterceptRequest(jsCallback); } void JSWeb::OnUrlLoadIntercept(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), UrlLoadInterceptEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> bool { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, false); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); JSRef message = func->ExecuteWithValue(*eventInfo); if (message->IsBoolean()) { return message->ToBoolean(); } return false; }; WebModel::GetInstance()->SetOnUrlLoadIntercept(jsCallback); } void JSWeb::OnLoadIntercept(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), LoadInterceptEventToJSValue); auto instanceId = Container::CurrentId(); WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> bool { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, false); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); JSRef message = func->ExecuteWithValue(*eventInfo); if (message->IsBoolean()) { return message->ToBoolean(); } return false; }; WebModel::GetInstance()->SetOnLoadIntercept(std::move(uiCallback)); } JSRef FileSelectorEventToJSValue(const FileSelectorEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef paramObj = JSClass::NewInstance(); auto fileSelectorParam = Referenced::Claim(paramObj->Unwrap()); fileSelectorParam->SetParam(eventInfo); JSRef resultObj = JSClass::NewInstance(); auto fileSelectorResult = Referenced::Claim(resultObj->Unwrap()); fileSelectorResult->SetResult(eventInfo); obj->SetPropertyObject("result", resultObj); obj->SetPropertyObject("fileSelector", paramObj); return JSRef::Cast(obj); } void JSWeb::OnFileSelectorShow(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), FileSelectorEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> bool { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, false); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); JSRef message = func->ExecuteWithValue(*eventInfo); if (message->IsBoolean()) { return message->ToBoolean(); } return false; }; WebModel::GetInstance()->SetOnFileSelectorShow(jsCallback); } JSRef ContextMenuEventToJSValue(const ContextMenuEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef paramObj = JSClass::NewInstance(); auto contextMenuParam = Referenced::Claim(paramObj->Unwrap()); contextMenuParam->SetParam(eventInfo); JSRef resultObj = JSClass::NewInstance(); auto contextMenuResult = Referenced::Claim(resultObj->Unwrap()); contextMenuResult->SetResult(eventInfo); obj->SetPropertyObject("result", resultObj); obj->SetPropertyObject("param", paramObj); return JSRef::Cast(obj); } void JSWeb::OnContextMenuShow(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), ContextMenuEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> bool { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, false); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); JSRef message = func->ExecuteWithValue(*eventInfo); if (message->IsBoolean()) { return message->ToBoolean(); } return false; }; WebModel::GetInstance()->SetOnContextMenuShow(jsCallback); } void ParseBindSelectionMenuParam( const JSCallbackInfo& info, const JSRef& menuOptions, NG::MenuParam& menuParam) { auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto onDisappearValue = menuOptions->GetProperty("onDisappear"); if (onDisappearValue->IsFunction()) { RefPtr jsOnDisAppearFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(onDisappearValue)); auto onDisappear = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDisAppearFunc), node = frameNode]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("onDisappear"); PipelineContext::SetCallBackNode(node); func->Execute(); }; menuParam.onDisappear = std::move(onDisappear); } auto onAppearValue = menuOptions->GetProperty("onAppear"); if (onAppearValue->IsFunction()) { RefPtr jsOnAppearFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(onAppearValue)); auto onAppear = [execCtx = info.GetExecutionContext(), func = std::move(jsOnAppearFunc), node = frameNode]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("onAppear"); PipelineContext::SetCallBackNode(node); func->Execute(); }; menuParam.onAppear = std::move(onAppear); } } void ParseBindSelectionMenuOptionParam(const JSCallbackInfo& info, const JSRef& args, NG::MenuParam& menuParam, std::function& previewBuildFunc) { auto menuOptions = JSRef::Cast(args); ParseBindSelectionMenuParam(info, menuOptions, menuParam); auto preview = menuOptions->GetProperty("preview"); if (!preview->IsFunction()) { return; } auto menuType = menuOptions->GetProperty("menuType"); bool isPreviewMenu = menuType->IsNumber() && menuType->ToNumber() == 1; if (isPreviewMenu) { menuParam.previewMode = MenuPreviewMode::CUSTOM; RefPtr previewBuilderFunc = AceType::MakeRefPtr(JSRef::Cast(preview)); CHECK_NULL_VOID(previewBuilderFunc); auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); previewBuildFunc = [execCtx = info.GetExecutionContext(), func = std::move(previewBuilderFunc), node = frameNode]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("BindSelectionMenuPreviwer"); PipelineContext::SetCallBackNode(node); func->Execute(); }; } } void JSWeb::BindSelectionMenu(const JSCallbackInfo& info) { if (info.Length() < SELECTION_MENU_OPTION_PARAM_INDEX || !info[0]->IsNumber() || !info[1]->IsObject() || !info[SELECTION_MENU_CONTENT_PARAM_INDEX]->IsNumber()) { return; } if (info[0]->ToNumber() != static_cast(WebElementType::IMAGE) || info[SELECTION_MENU_CONTENT_PARAM_INDEX]->ToNumber() != static_cast(ResponseType::LONG_PRESS)) { TAG_LOGW(AceLogTag::ACE_WEB, "WebElementType or WebResponseType param err"); return; } WebElementType elementType = static_cast(info[0]->ToNumber()); ResponseType responseType = static_cast(info[SELECTION_MENU_CONTENT_PARAM_INDEX]->ToNumber()); // Builder JSRef menuObj = JSRef::Cast(info[1]); auto builder = menuObj->GetProperty("builder"); if (!builder->IsFunction()) { TAG_LOGW(AceLogTag::ACE_WEB, "BindSelectionMenu menu builder param err"); return; } auto builderFunc = AceType::MakeRefPtr(JSRef::Cast(builder)); CHECK_NULL_VOID(builderFunc); WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); std::function menuBuilder = [execCtx = info.GetExecutionContext(), func = std::move(builderFunc), node = frameNode]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("BindSelectionMenu"); PipelineContext::SetCallBackNode(node); func->Execute(); }; std::function previewBuilder = nullptr; NG::MenuParam menuParam; if (info.Length() > SELECTION_MENU_OPTION_PARAM_INDEX && info[SELECTION_MENU_OPTION_PARAM_INDEX]->IsObject()) { ParseBindSelectionMenuOptionParam(info, info[SELECTION_MENU_OPTION_PARAM_INDEX], menuParam, previewBuilder); } if (responseType != ResponseType::LONG_PRESS) { menuParam.previewMode = MenuPreviewMode::NONE; menuParam.menuBindType = MenuBindingType::RIGHT_CLICK; } menuParam.contextMenuRegisterType = NG::ContextMenuRegisterType::CUSTOM_TYPE; menuParam.type = NG::MenuType::CONTEXT_MENU; menuParam.isPreviewContainScale = true; menuParam.isShow = true; WebModel::GetInstance()->SetNewDragStyle(true); auto previewSelectionMenuParam = std::make_shared( elementType, responseType, menuBuilder, previewBuilder, menuParam); WebModel::GetInstance()->SetPreviewSelectionMenu(previewSelectionMenuParam); } void JSWeb::OnContextMenuHide(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), ContextMenuHideEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOnContextMenuHide(jsCallback); } void JSWeb::JsEnabled(bool isJsEnabled) { WebModel::GetInstance()->SetJsEnabled(isJsEnabled); } void JSWeb::ContentAccessEnabled(bool isContentAccessEnabled) { #if !defined(NG_BUILD) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) auto stack = ViewStackProcessor::GetInstance(); auto webComponent = AceType::DynamicCast(stack->GetMainComponent()); if (!webComponent) { return; } webComponent->SetContentAccessEnabled(isContentAccessEnabled); #else TAG_LOGW(AceLogTag::ACE_WEB, "do not support components in new pipeline mode"); #endif } void JSWeb::FileAccessEnabled(bool isFileAccessEnabled) { WebModel::GetInstance()->SetFileAccessEnabled(isFileAccessEnabled); } void JSWeb::OnLineImageAccessEnabled(bool isOnLineImageAccessEnabled) { WebModel::GetInstance()->SetOnLineImageAccessEnabled(isOnLineImageAccessEnabled); } void JSWeb::DomStorageAccessEnabled(bool isDomStorageAccessEnabled) { WebModel::GetInstance()->SetDomStorageAccessEnabled(isDomStorageAccessEnabled); } void JSWeb::ImageAccessEnabled(bool isImageAccessEnabled) { WebModel::GetInstance()->SetImageAccessEnabled(isImageAccessEnabled); } void JSWeb::MixedMode(int32_t mixedMode) { auto mixedContentMode = MixedModeContent::MIXED_CONTENT_NEVER_ALLOW; switch (mixedMode) { case 0: mixedContentMode = MixedModeContent::MIXED_CONTENT_ALWAYS_ALLOW; break; case 1: mixedContentMode = MixedModeContent::MIXED_CONTENT_COMPATIBILITY_MODE; break; default: mixedContentMode = MixedModeContent::MIXED_CONTENT_NEVER_ALLOW; break; } WebModel::GetInstance()->SetMixedMode(mixedContentMode); } void JSWeb::ZoomAccessEnabled(bool isZoomAccessEnabled) { WebModel::GetInstance()->SetZoomAccessEnabled(isZoomAccessEnabled); } void JSWeb::EnableNativeEmbedMode(bool isEmbedModeEnabled) { WebModel::GetInstance()->SetNativeEmbedModeEnabled(isEmbedModeEnabled); } void JSWeb::RegisterNativeEmbedRule(const std::string& tag, const std::string& type) { WebModel::GetInstance()->RegisterNativeEmbedRule(tag, type); } void JSWeb::GeolocationAccessEnabled(bool isGeolocationAccessEnabled) { WebModel::GetInstance()->SetGeolocationAccessEnabled(isGeolocationAccessEnabled); } void JSWeb::JavaScriptProxy(const JSCallbackInfo& args) { #if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) if (args.Length() < 1 || !args[0]->IsObject()) { return; } auto paramObject = JSRef::Cast(args[0]); auto controllerObj = paramObject->GetProperty("controller"); auto object = JSRef::Cast(paramObject->GetProperty("object")); auto name = JSRef::Cast(paramObject->GetProperty("name")); auto methodList = JSRef::Cast(paramObject->GetProperty("methodList")); auto asyncMethodList = JSRef::Cast(paramObject->GetProperty("asyncMethodList")); auto permission = JSRef::Cast(paramObject->GetProperty("permission")); if (!controllerObj->IsObject()) { return; } auto controller = JSRef::Cast(controllerObj); auto jsProxyFunction = controller->GetProperty("jsProxy"); if (jsProxyFunction->IsFunction()) { auto jsProxyCallback = [webviewController = controller, func = JSRef::Cast(jsProxyFunction), object, name, methodList, asyncMethodList, permission]() { JSRef argv[] = { object, name, methodList, asyncMethodList, permission }; func->Call(webviewController, 5, argv); }; WebModel::GetInstance()->SetJsProxyCallback(jsProxyCallback); } auto jsWebController = controller->Unwrap(); if (jsWebController) { jsWebController->SetJavascriptInterface(args); } #endif } void JSWeb::UserAgent(const std::string& userAgent) { WebModel::GetInstance()->SetUserAgent(userAgent); } JSRef RenderExitedEventToJSValue(const RenderExitedEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("renderExitReason", eventInfo.GetExitedReason()); return JSRef::Cast(obj); } JSRef RefreshAccessedHistoryEventToJSValue(const RefreshAccessedHistoryEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("url", eventInfo.GetVisitedUrl()); obj->SetProperty("isRefreshed", eventInfo.IsRefreshed()); return JSRef::Cast(obj); } void JSWeb::OnRenderExited(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), RenderExitedEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetRenderExitedId(jsCallback); } void JSWeb::OnRefreshAccessedHistory(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), RefreshAccessedHistoryEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetRefreshAccessedHistoryId(jsCallback); } void JSWeb::CacheMode(int32_t cacheMode) { auto mode = WebCacheMode::DEFAULT; switch (cacheMode) { case 0: mode = WebCacheMode::DEFAULT; break; case 1: mode = WebCacheMode::USE_CACHE_ELSE_NETWORK; break; case 2: mode = WebCacheMode::USE_NO_CACHE; break; case 3: mode = WebCacheMode::USE_CACHE_ONLY; break; default: mode = WebCacheMode::DEFAULT; break; } WebModel::GetInstance()->SetCacheMode(mode); } void JSWeb::OverScrollMode(int overScrollMode) { auto mode = OverScrollMode::NEVER; switch (overScrollMode) { case 0: mode = OverScrollMode::NEVER; break; case 1: mode = OverScrollMode::ALWAYS; break; default: mode = OverScrollMode::NEVER; break; } WebModel::GetInstance()->SetOverScrollMode(mode); } void JSWeb::BlurOnKeyboardHideMode(int blurOnKeyboardHideMode) { auto mode = BlurOnKeyboardHideMode::SILENT; switch (blurOnKeyboardHideMode) { case 0: mode = BlurOnKeyboardHideMode::SILENT; break; case 1: mode = BlurOnKeyboardHideMode::BLUR; break; default: mode = BlurOnKeyboardHideMode::SILENT; break; } WebModel::GetInstance()->SetBlurOnKeyboardHideMode(mode); } void JSWeb::OverviewModeAccess(bool isOverviewModeAccessEnabled) { WebModel::GetInstance()->SetOverviewModeAccessEnabled(isOverviewModeAccessEnabled); } void JSWeb::FileFromUrlAccess(bool isFileFromUrlAccessEnabled) { WebModel::GetInstance()->SetFileFromUrlAccessEnabled(isFileFromUrlAccessEnabled); } void JSWeb::DatabaseAccess(bool isDatabaseAccessEnabled) { WebModel::GetInstance()->SetDatabaseAccessEnabled(isDatabaseAccessEnabled); } void JSWeb::TextZoomRatio(int32_t textZoomRatioNum) { WebModel::GetInstance()->SetTextZoomRatio(textZoomRatioNum); } void JSWeb::WebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled) { WebModel::GetInstance()->SetWebDebuggingAccessEnabled(isWebDebuggingAccessEnabled); } void JSWeb::OnMouse(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); RefPtr jsOnMouseFunc = AceType::MakeRefPtr(JSRef::Cast(args[0])); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsOnMouseFunc), node = frameNode]( MouseInfo& info) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); func->Execute(info); }; WebModel::GetInstance()->SetOnMouseEvent(jsCallback); } JSRef ResourceLoadEventToJSValue(const ResourceLoadEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("url", eventInfo.GetOnResourceLoadUrl()); return JSRef::Cast(obj); } void JSWeb::OnResourceLoad(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), ResourceLoadEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetResourceLoadId(jsCallback); } JSRef ScaleChangeEventToJSValue(const ScaleChangeEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("oldScale", eventInfo.GetOnScaleChangeOldScale()); obj->SetProperty("newScale", eventInfo.GetOnScaleChangeNewScale()); return JSRef::Cast(obj); } void JSWeb::OnScaleChange(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), ScaleChangeEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetScaleChangeId(jsCallback); } JSRef ScrollEventToJSValue(const WebOnScrollEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("xOffset", eventInfo.GetX()); obj->SetProperty("yOffset", eventInfo.GetY()); return JSRef::Cast(obj); } void JSWeb::OnScroll(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>(JSRef::Cast(args[0]), ScrollEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetScrollId(jsCallback); } JSRef PermissionRequestEventToJSValue(const WebPermissionRequestEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef permissionObj = JSClass::NewInstance(); auto permissionEvent = Referenced::Claim(permissionObj->Unwrap()); permissionEvent->SetEvent(eventInfo); obj->SetPropertyObject("request", permissionObj); return JSRef::Cast(obj); } void JSWeb::OnPermissionRequest(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), PermissionRequestEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetPermissionRequestEventId(jsCallback); } JSRef ScreenCaptureRequestEventToJSValue(const WebScreenCaptureRequestEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef requestObj = JSClass::NewInstance(); auto requestEvent = Referenced::Claim(requestObj->Unwrap()); requestEvent->SetEvent(eventInfo); obj->SetPropertyObject("handler", requestObj); return JSRef::Cast(obj); } void JSWeb::OnScreenCaptureRequest(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), ScreenCaptureRequestEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetScreenCaptureRequestEventId(jsCallback); } void JSWeb::BackgroundColor(const JSCallbackInfo& info) { if (info.Length() < 1) { return; } Color backgroundColor; if (!ParseJsColor(info[0], backgroundColor)) { backgroundColor = WebModel::GetInstance()->GetDefaultBackgroundColor(); } WebModel::GetInstance()->SetBackgroundColor(backgroundColor); } void JSWeb::InitialScale(float scale) { WebModel::GetInstance()->InitialScale(scale); } void JSWeb::Password(bool password) {} void JSWeb::TableData(bool tableData) {} void JSWeb::OnFileSelectorShowAbandoned(const JSCallbackInfo& args) {} void JSWeb::WideViewModeAccess(const JSCallbackInfo& args) {} void JSWeb::WebDebuggingAccess(const JSCallbackInfo& args) {} void JSWeb::OnSearchResultReceive(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), SearchResultReceiveEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetSearchResultReceiveEventId(jsCallback); } void JSWeb::JsOnDragStart(const JSCallbackInfo& info) { if (info.Length() < 1 || !info[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); RefPtr jsOnDragStartFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); auto onDragStartId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragStartFunc), node = frameNode]( const RefPtr& info, const std::string& extraParams) -> NG::DragDropBaseInfo { NG::DragDropBaseInfo itemInfo; JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, itemInfo); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, itemInfo); pipelineContext->UpdateCurrentActiveNode(node); auto ret = func->Execute(info, extraParams); if (!ret->IsObject()) { return itemInfo; } auto component = ParseDragNode(ret); if (component) { itemInfo.node = component; return itemInfo; } auto builderObj = JSRef::Cast(ret); #if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM) auto pixmap_impl = builderObj->GetProperty("pixelMap"); itemInfo.pixelMap = CreatePixelMapFromNapiValue(pixmap_impl); #endif #if defined(PIXEL_MAP_SUPPORTED) auto pixmap_ng = builderObj->GetProperty("pixelMap"); itemInfo.pixelMap = CreatePixelMapFromNapiValue(pixmap_ng); #endif auto extraInfo = builderObj->GetProperty("extraInfo"); ParseJsString(extraInfo, itemInfo.extraInfo); component = ParseDragNode(builderObj->GetProperty("builder")); itemInfo.node = component; return itemInfo; }; WebModel::GetInstance()->SetOnDragStart(std::move(onDragStartId)); } void JSWeb::JsOnDragEnter(const JSCallbackInfo& info) { if (info.Length() < 1 || !info[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); RefPtr jsOnDragEnterFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); auto onDragEnterId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragEnterFunc), node = frameNode]( const RefPtr& info, const std::string& extraParams) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("onDragEnter"); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); func->Execute(info, extraParams); }; WebModel::GetInstance()->SetOnDragEnter(onDragEnterId); } void JSWeb::JsOnDragMove(const JSCallbackInfo& info) { if (info.Length() < 1 || !info[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); RefPtr jsOnDragMoveFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); auto onDragMoveId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragMoveFunc), node = frameNode]( const RefPtr& info, const std::string& extraParams) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("onDragMove"); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); func->Execute(info, extraParams); }; WebModel::GetInstance()->SetOnDragMove(onDragMoveId); } void JSWeb::JsOnDragLeave(const JSCallbackInfo& info) { if (info.Length() < 1 || !info[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); RefPtr jsOnDragLeaveFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); auto onDragLeaveId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDragLeaveFunc), node = frameNode]( const RefPtr& info, const std::string& extraParams) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("onDragLeave"); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); func->Execute(info, extraParams); }; WebModel::GetInstance()->SetOnDragLeave(onDragLeaveId); } void JSWeb::JsOnDrop(const JSCallbackInfo& info) { if (info.Length() < 1 || !info[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); RefPtr jsOnDropFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); auto onDropId = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDropFunc), node = frameNode]( const RefPtr& info, const std::string& extraParams) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("onDrop"); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); func->Execute(info, extraParams); }; WebModel::GetInstance()->SetOnDrop(onDropId); } void JSWeb::PinchSmoothModeEnabled(bool isPinchSmoothModeEnabled) { WebModel::GetInstance()->SetPinchSmoothModeEnabled(isPinchSmoothModeEnabled); } JSRef WindowNewEventToJSValue(const WebWindowNewEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("isAlert", eventInfo.IsAlert()); obj->SetProperty("isUserTrigger", eventInfo.IsUserTrigger()); obj->SetProperty("targetUrl", eventInfo.GetTargetUrl()); JSRef handlerObj = JSClass::NewInstance(); auto handler = Referenced::Claim(handlerObj->Unwrap()); handler->SetEvent(eventInfo); obj->SetPropertyObject("handler", handlerObj); return JSRef::Cast(obj); } bool HandleWindowNewEvent(const WebWindowNewEvent* eventInfo) { if (eventInfo == nullptr) { return false; } auto handler = eventInfo->GetWebWindowNewHandler(); if (handler && !handler->IsFrist()) { int32_t parentId = -1; auto controller = JSWebWindowNewHandler::PopController(handler->GetId(), &parentId); if (!controller.IsEmpty()) { auto getWebIdFunction = controller->GetProperty("innerGetWebId"); if (getWebIdFunction->IsFunction()) { auto func = JSRef::Cast(getWebIdFunction); auto webId = func->Call(controller, 0, {}); handler->SetWebController(webId->ToNumber()); } auto completeWindowNewFunction = controller->GetProperty("innerCompleteWindowNew"); if (completeWindowNewFunction->IsFunction()) { auto func = JSRef::Cast(completeWindowNewFunction); JSRef argv[] = { JSRef::Make(ToJSValue(parentId)) }; func->Call(controller, 1, argv); } } return false; } return true; } void JSWeb::OnWindowNew(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), WindowNewEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { ContainerScope scope(instanceId); ACE_SCORING_EVENT("OnWindowNew CallBack"); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); if (!func || !HandleWindowNewEvent(eventInfo)) { return; } func->Execute(*eventInfo); }; WebModel::GetInstance()->SetWindowNewEvent(jsCallback); } JSRef WindowExitEventToJSValue(const WebWindowExitEvent& eventInfo) { JSRef obj = JSRef::New(); return JSRef::Cast(obj); } void JSWeb::OnWindowExit(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), WindowExitEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetWindowExitEventId(jsCallback); } void JSWeb::MultiWindowAccessEnabled(bool isMultiWindowAccessEnable) { WebModel::GetInstance()->SetMultiWindowAccessEnabled(isMultiWindowAccessEnable); } void JSWeb::AllowWindowOpenMethod(bool isAllowWindowOpenMethod) { WebModel::GetInstance()->SetAllowWindowOpenMethod(isAllowWindowOpenMethod); } void JSWeb::WebCursiveFont(const std::string& cursiveFontFamily) { WebModel::GetInstance()->SetWebCursiveFont(cursiveFontFamily); } void JSWeb::WebFantasyFont(const std::string& fantasyFontFamily) { WebModel::GetInstance()->SetWebFantasyFont(fantasyFontFamily); } void JSWeb::WebFixedFont(const std::string& fixedFontFamily) { WebModel::GetInstance()->SetWebFixedFont(fixedFontFamily); } void JSWeb::WebSansSerifFont(const std::string& sansSerifFontFamily) { WebModel::GetInstance()->SetWebSansSerifFont(sansSerifFontFamily); } void JSWeb::WebSerifFont(const std::string& serifFontFamily) { WebModel::GetInstance()->SetWebSerifFont(serifFontFamily); } void JSWeb::WebStandardFont(const std::string& standardFontFamily) { WebModel::GetInstance()->SetWebStandardFont(standardFontFamily); } void JSWeb::DefaultFixedFontSize(int32_t defaultFixedFontSize) { WebModel::GetInstance()->SetDefaultFixedFontSize(defaultFixedFontSize); } void JSWeb::DefaultFontSize(int32_t defaultFontSize) { WebModel::GetInstance()->SetDefaultFontSize(defaultFontSize); } void JSWeb::DefaultTextEncodingFormat(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsString()) { return; } std::string textEncodingFormat = args[0]->ToString(); EraseSpace(textEncodingFormat); if (textEncodingFormat.empty()) { WebModel::GetInstance()->SetDefaultTextEncodingFormat("UTF-8"); return; } WebModel::GetInstance()->SetDefaultTextEncodingFormat(textEncodingFormat); } void JSWeb::MinFontSize(int32_t minFontSize) { WebModel::GetInstance()->SetMinFontSize(minFontSize); } void JSWeb::MinLogicalFontSize(int32_t minLogicalFontSize) { WebModel::GetInstance()->SetMinLogicalFontSize(minLogicalFontSize); } void JSWeb::BlockNetwork(bool isNetworkBlocked) { WebModel::GetInstance()->SetBlockNetwork(isNetworkBlocked); } JSRef PageVisibleEventToJSValue(const PageVisibleEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("url", eventInfo.GetUrl()); return JSRef::Cast(obj); } void JSWeb::OnPageVisible(const JSCallbackInfo& args) { TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::OnPageVisible init by developer"); if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), PageVisibleEventToJSValue); auto instanceId = Container::CurrentId(); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::OnPageVisible uiCallback enter"); ContainerScope scope(instanceId); auto context = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(context); context->UpdateCurrentActiveNode(node); context->PostAsyncEvent([execCtx, postFunc = func, info]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); TAG_LOGI(AceLogTag::ACE_WEB, "JSWeb::OnPageVisible async event execute"); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); postFunc->Execute(*eventInfo); }, "ArkUIWebPageVisible"); }; WebModel::GetInstance()->SetPageVisibleId(std::move(uiCallback)); } void JSWeb::OnInterceptKeyEvent(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); RefPtr jsOnPreKeyEventFunc = AceType::MakeRefPtr(JSRef::Cast(args[0])); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsOnPreKeyEventFunc), node = frameNode]( KeyEventInfo& keyEventInfo) -> bool { bool result = false; JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, result); ACE_SCORING_EVENT("onPreKeyEvent"); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, result); pipelineContext->UpdateCurrentActiveNode(node); JSRef obj = func->ExecuteWithValue(keyEventInfo); if (obj->IsBoolean()) { result = obj->ToBoolean(); } return result; }; WebModel::GetInstance()->SetOnInterceptKeyEventCallback(uiCallback); } JSRef DataResubmittedEventToJSValue(const DataResubmittedEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef resultObj = JSClass::NewInstance(); auto jsDataResubmitted = Referenced::Claim(resultObj->Unwrap()); if (!jsDataResubmitted) { return JSRef::Cast(obj); } jsDataResubmitted->SetHandler(eventInfo.GetHandler()); obj->SetPropertyObject("handler", resultObj); return JSRef::Cast(obj); } void JSWeb::OnDataResubmitted(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), DataResubmittedEventToJSValue); auto instanceId = Container::CurrentId(); WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { ContainerScope scope(instanceId); auto context = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(context); context->UpdateCurrentActiveNode(node); context->PostSyncEvent([execCtx, postFunc = func, info]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); postFunc->Execute(*eventInfo); }, "ArkUIWebDataResubmitted"); }; WebModel::GetInstance()->SetOnDataResubmitted(uiCallback); } Media::PixelFormat GetPixelFormat(NWeb::ImageColorType colorType) { Media::PixelFormat pixelFormat; switch (colorType) { case NWeb::ImageColorType::COLOR_TYPE_UNKNOWN: pixelFormat = Media::PixelFormat::UNKNOWN; break; case NWeb::ImageColorType::COLOR_TYPE_RGBA_8888: pixelFormat = Media::PixelFormat::RGBA_8888; break; case NWeb::ImageColorType::COLOR_TYPE_BGRA_8888: pixelFormat = Media::PixelFormat::BGRA_8888; break; default: pixelFormat = Media::PixelFormat::UNKNOWN; break; } return pixelFormat; } Media::AlphaType GetAlphaType(NWeb::ImageAlphaType alphaType) { Media::AlphaType imageAlphaType; switch (alphaType) { case NWeb::ImageAlphaType::ALPHA_TYPE_UNKNOWN: imageAlphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN; break; case NWeb::ImageAlphaType::ALPHA_TYPE_OPAQUE: imageAlphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE; break; case NWeb::ImageAlphaType::ALPHA_TYPE_PREMULTIPLIED: imageAlphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL; break; case NWeb::ImageAlphaType::ALPHA_TYPE_POSTMULTIPLIED: imageAlphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL; break; default: imageAlphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN; break; } return imageAlphaType; } JSRef FaviconReceivedEventToJSValue(const FaviconReceivedEvent& eventInfo) { JSRef obj = JSRef::New(); auto data = eventInfo.GetHandler()->GetData(); size_t width = eventInfo.GetHandler()->GetWidth(); size_t height = eventInfo.GetHandler()->GetHeight(); int colorType = eventInfo.GetHandler()->GetColorType(); int alphaType = eventInfo.GetHandler()->GetAlphaType(); Media::InitializationOptions opt; opt.size.width = static_cast(width); opt.size.height = static_cast(height); opt.pixelFormat = GetPixelFormat(NWeb::ImageColorType(colorType)); opt.alphaType = GetAlphaType(NWeb::ImageAlphaType(alphaType)); opt.editable = true; auto pixelMap = Media::PixelMap::Create(opt); if (pixelMap == nullptr) { return JSRef::Cast(obj); } uint32_t stride = width << 2; uint64_t bufferSize = stride * height; pixelMap->WritePixels(static_cast(data), bufferSize); std::shared_ptr pixelMapToJs(pixelMap.release()); auto engine = EngineHelper::GetCurrentEngine(); if (!engine) { return JSRef::Cast(obj); } NativeEngine* nativeEngine = engine->GetNativeEngine(); napi_env env = reinterpret_cast(nativeEngine); napi_value napiValue = OHOS::Media::PixelMapNapi::CreatePixelMap(env, pixelMapToJs); auto jsPixelMap = JsConverter::ConvertNapiValueToJsVal(napiValue); obj->SetPropertyObject("favicon", jsPixelMap); return JSRef::Cast(obj); } void JSWeb::OnFaviconReceived(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), FaviconReceivedEventToJSValue); auto instanceId = Container::CurrentId(); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { ContainerScope scope(instanceId); auto context = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(context); context->UpdateCurrentActiveNode(node); context->PostAsyncEvent([execCtx, postFunc = func, info]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); postFunc->Execute(*eventInfo); }, "ArkUIWebFaviconReceived"); }; WebModel::GetInstance()->SetFaviconReceivedId(uiCallback); } JSRef TouchIconUrlEventToJSValue(const TouchIconUrlEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("url", eventInfo.GetUrl()); obj->SetProperty("precomposed", eventInfo.GetPreComposed()); return JSRef::Cast(obj); } void JSWeb::OnTouchIconUrlReceived(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), TouchIconUrlEventToJSValue); auto instanceId = Container::CurrentId(); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { ContainerScope scope(instanceId); auto context = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(context); context->UpdateCurrentActiveNode(node); context->PostAsyncEvent([execCtx, postFunc = func, info]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); postFunc->Execute(*eventInfo); }, "ArkUIWebTouchIconUrlReceived"); }; WebModel::GetInstance()->SetTouchIconUrlId(uiCallback); } void JSWeb::DarkMode(int32_t darkMode) { auto mode = WebDarkMode::Off; switch (darkMode) { case 0: mode = WebDarkMode::Off; break; case 1: mode = WebDarkMode::On; break; case 2: mode = WebDarkMode::Auto; break; default: mode = WebDarkMode::Off; break; } WebModel::GetInstance()->SetDarkMode(mode); } void JSWeb::ForceDarkAccess(bool access) { WebModel::GetInstance()->SetForceDarkAccess(access); } void JSWeb::HorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled) { WebModel::GetInstance()->SetHorizontalScrollBarAccessEnabled(isHorizontalScrollBarAccessEnabled); } void JSWeb::VerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled) { WebModel::GetInstance()->SetVerticalScrollBarAccessEnabled(isVerticalScrollBarAccessEnabled); } JSRef AudioStateChangedEventToJSValue(const AudioStateChangedEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("playing", eventInfo.IsPlaying()); return JSRef::Cast(obj); } void JSWeb::OnAudioStateChanged(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), AudioStateChangedEventToJSValue); auto instanceId = Container::CurrentId(); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetAudioStateChangedId(std::move(uiCallback)); } void JSWeb::MediaOptions(const JSCallbackInfo& args) { if (!args[0]->IsObject()) { return; } auto paramObject = JSRef::Cast(args[0]); auto resumeIntervalObj = paramObject->GetProperty("resumeInterval"); if (resumeIntervalObj->IsNumber()) { int32_t resumeInterval = resumeIntervalObj->ToNumber(); WebModel::GetInstance()->SetAudioResumeInterval(resumeInterval); } auto audioExclusiveObj = paramObject->GetProperty("audioExclusive"); if (audioExclusiveObj->IsBoolean()) { bool audioExclusive = audioExclusiveObj->ToBoolean(); WebModel::GetInstance()->SetAudioExclusive(audioExclusive); } } JSRef FirstContentfulPaintEventToJSValue(const FirstContentfulPaintEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("navigationStartTick", eventInfo.GetNavigationStartTick()); obj->SetProperty("firstContentfulPaintMs", eventInfo.GetFirstContentfulPaintMs()); return JSRef::Cast(obj); } void JSWeb::OnFirstContentfulPaint(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), FirstContentfulPaintEventToJSValue); auto instanceId = Container::CurrentId(); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { ContainerScope scope(instanceId); auto context = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(context); context->UpdateCurrentActiveNode(node); context->PostAsyncEvent([execCtx, postFunc = func, info]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); postFunc->Execute(*eventInfo); }, "ArkUIWebFirstContentfulPaint"); }; WebModel::GetInstance()->SetFirstContentfulPaintId(std::move(uiCallback)); } JSRef FirstMeaningfulPaintEventToJSValue(const FirstMeaningfulPaintEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("navigationStartTime", eventInfo.GetNavigationStartTime()); obj->SetProperty("firstMeaningfulPaintTime", eventInfo.GetFirstMeaningfulPaintTime()); return JSRef::Cast(obj); } void JSWeb::OnFirstMeaningfulPaint(const JSCallbackInfo& args) { if (args.Length() < 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsFunction()) { return; } auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), FirstMeaningfulPaintEventToJSValue); auto instanceId = Container::CurrentId(); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { ContainerScope scope(instanceId); auto context = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(context); context->UpdateCurrentActiveNode(node); context->PostAsyncEvent([execCtx, postFunc = func, info]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); postFunc->Execute(*eventInfo); }, "ArkUIWebFirstMeaningfulPaint"); }; WebModel::GetInstance()->SetFirstMeaningfulPaintId(std::move(uiCallback)); } JSRef LargestContentfulPaintEventToJSValue(const LargestContentfulPaintEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("navigationStartTime", eventInfo.GetNavigationStartTime()); obj->SetProperty("largestImagePaintTime", eventInfo.GetLargestImagePaintTime()); obj->SetProperty("largestTextPaintTime", eventInfo.GetLargestTextPaintTime()); obj->SetProperty("largestImageLoadStartTime", eventInfo.GetLargestImageLoadStartTime()); obj->SetProperty("largestImageLoadEndTime", eventInfo.GetLargestImageLoadEndTime()); obj->SetProperty("imageBPP", eventInfo.GetImageBPP()); return JSRef::Cast(obj); } void JSWeb::OnLargestContentfulPaint(const JSCallbackInfo& args) { if (args.Length() < 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsFunction()) { return; } auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), LargestContentfulPaintEventToJSValue); auto instanceId = Container::CurrentId(); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { ContainerScope scope(instanceId); auto context = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(context); context->UpdateCurrentActiveNode(node); context->PostAsyncEvent([execCtx, postFunc = func, info]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); postFunc->Execute(*eventInfo); }, "ArkUIWebLargestContentfulPaint"); }; WebModel::GetInstance()->SetLargestContentfulPaintId(std::move(uiCallback)); } JSRef SafeBrowsingCheckResultEventToJSValue(const SafeBrowsingCheckResultEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("threatType", eventInfo.GetThreatType()); return JSRef::Cast(obj); } void JSWeb::OnSafeBrowsingCheckResult(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), SafeBrowsingCheckResultEventToJSValue); auto instanceId = Container::CurrentId(); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { ContainerScope scope(instanceId); auto context = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(context); context->UpdateCurrentActiveNode(node); context->PostAsyncEvent([execCtx, postFunc = func, info]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); postFunc->Execute(*eventInfo); }, "ArkUIWebSafeBrowsingCheckResult"); }; WebModel::GetInstance()->SetSafeBrowsingCheckResultId(std::move(uiCallback)); } JSRef NavigationEntryCommittedEventToJSValue(const NavigationEntryCommittedEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("isMainFrame", eventInfo.IsMainFrame()); obj->SetProperty("isSameDocument", eventInfo.IsSameDocument()); obj->SetProperty("didReplaceEntry", eventInfo.DidReplaceEntry()); obj->SetProperty("navigationType", static_cast(eventInfo.GetNavigationType())); obj->SetProperty("url", eventInfo.GetUrl()); return JSRef::Cast(obj); } void JSWeb::OnNavigationEntryCommitted(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), NavigationEntryCommittedEventToJSValue); auto instanceId = Container::CurrentId(); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { ContainerScope scope(instanceId); auto context = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(context); context->UpdateCurrentActiveNode(node); context->PostAsyncEvent([execCtx, postFunc = func, info]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); postFunc->Execute(*eventInfo); }, "ArkUIWebNavigationEntryCommitted"); }; WebModel::GetInstance()->SetNavigationEntryCommittedId(std::move(uiCallback)); } JSRef IntelligentTrackingPreventionResultEventToJSValue( const IntelligentTrackingPreventionResultEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("host", eventInfo.GetHost()); obj->SetProperty("trackerHost", eventInfo.GetTrackerHost()); return JSRef::Cast(obj); } void JSWeb::OnIntelligentTrackingPreventionResult(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), IntelligentTrackingPreventionResultEventToJSValue); auto instanceId = Container::CurrentId(); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const std::shared_ptr& info) { ContainerScope scope(instanceId); auto context = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(context); context->UpdateCurrentActiveNode(node); context->PostAsyncEvent([execCtx, postFunc = func, info]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info.get()); postFunc->Execute(*eventInfo); }, "ArkUIWebIntelligentTrackingPreventionResult"); }; WebModel::GetInstance()->SetIntelligentTrackingPreventionResultId(std::move(uiCallback)); } void JSWeb::OnControllerAttached(const JSCallbackInfo& args) { if (!args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr(JSRef::Cast(args[0])); auto instanceId = Container::CurrentId(); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]() { ContainerScope scope(instanceId); auto context = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(context); context->UpdateCurrentActiveNode(node); context->PostSyncEvent([execCtx, postFunc = func]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); postFunc->Execute(); }, "ArkUIWebControllerAttached"); }; WebModel::GetInstance()->SetOnControllerAttached(std::move(uiCallback)); } JSRef EmbedLifecycleChangeToJSValue(const NativeEmbedDataInfo& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("status", static_cast(eventInfo.GetStatus())); obj->SetProperty("surfaceId", eventInfo.GetSurfaceId()); obj->SetProperty("embedId", eventInfo.GetEmbedId()); JSRef objectTemplate = JSRef::New(); JSRef requestObj = objectTemplate->NewInstance(); requestObj->SetProperty("id", eventInfo.GetEmebdInfo().id); requestObj->SetProperty("type", eventInfo.GetEmebdInfo().type); requestObj->SetProperty("src", eventInfo.GetEmebdInfo().src); requestObj->SetProperty("tag", eventInfo.GetEmebdInfo().tag); requestObj->SetProperty("width", eventInfo.GetEmebdInfo().width); requestObj->SetProperty("height", eventInfo.GetEmebdInfo().height); requestObj->SetProperty("url", eventInfo.GetEmebdInfo().url); JSRef positionObj = objectTemplate->NewInstance(); positionObj->SetProperty("x", eventInfo.GetEmebdInfo().x); positionObj->SetProperty("y", eventInfo.GetEmebdInfo().y); requestObj->SetPropertyObject("position", positionObj); auto params = eventInfo.GetEmebdInfo().params; JSRef paramsObj = objectTemplate->NewInstance(); for (const auto& item : params) { paramsObj->SetProperty(item.first.c_str(), item.second.c_str()); } requestObj->SetPropertyObject("params", paramsObj); obj->SetPropertyObject("info", requestObj); return JSRef::Cast(obj); } JSRef EmbedVisibilityChangeToJSValue(const NativeEmbedVisibilityInfo& visibilityInfo) { JSRef obj = JSRef::New(); obj->SetProperty("visibility", visibilityInfo.GetVisibility()); obj->SetProperty("embedId", visibilityInfo.GetEmbedId()); return JSRef::Cast(obj); } void JSWeb::OnNativeEmbedLifecycleChange(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), EmbedLifecycleChangeToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetNativeEmbedLifecycleChangeId(jsCallback); } void JSWeb::OnNativeEmbedVisibilityChange(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), EmbedVisibilityChangeToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetNativeEmbedVisibilityChangeId(jsCallback); } JSRef CreateTouchInfo(const TouchLocationInfo& touchInfo, TouchEventInfo& info) { JSRef objectTemplate = JSRef::New(); objectTemplate->SetInternalFieldCount(1); JSRef touchInfoObj = objectTemplate->NewInstance(); const OHOS::Ace::Offset& globalLocation = touchInfo.GetGlobalLocation(); const OHOS::Ace::Offset& localLocation = touchInfo.GetLocalLocation(); const OHOS::Ace::Offset& screenLocation = touchInfo.GetScreenLocation(); touchInfoObj->SetProperty("type", static_cast(touchInfo.GetTouchType())); touchInfoObj->SetProperty("id", touchInfo.GetFingerId()); touchInfoObj->SetProperty("displayX", screenLocation.GetX()); touchInfoObj->SetProperty("displayY", screenLocation.GetY()); touchInfoObj->SetProperty("windowX", globalLocation.GetX()); touchInfoObj->SetProperty("windowY", globalLocation.GetY()); touchInfoObj->SetProperty("screenX", globalLocation.GetX()); touchInfoObj->SetProperty("screenY", globalLocation.GetY()); touchInfoObj->SetProperty("x", localLocation.GetX()); touchInfoObj->SetProperty("y", localLocation.GetY()); touchInfoObj->Wrap(&info); return touchInfoObj; } JSRef NativeEmbeadTouchToJSValue(const NativeEmbeadTouchInfo& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("embedId", eventInfo.GetEmbedId()); auto info = eventInfo.GetTouchEventInfo(); JSRef objectTemplate = JSRef::New(); JSRef eventObj = objectTemplate->NewInstance(); JSRef touchArr = JSRef::New(); JSRef changeTouchArr = JSRef::New(); eventObj->SetProperty("source", static_cast(info.GetSourceDevice())); eventObj->SetProperty("timestamp", static_cast(GetSysTimestamp())); auto target = CreateEventTargetObject(info); eventObj->SetPropertyObject("target", target); eventObj->SetProperty("pressure", info.GetForce()); eventObj->SetProperty("sourceTool", static_cast(info.GetSourceTool())); eventObj->SetProperty("targetDisplayId", static_cast(info.GetTargetDisplayId())); eventObj->SetProperty("deviceId", static_cast(info.GetDeviceId())); if (info.GetChangedTouches().empty()) { return JSRef::Cast(obj); } uint32_t index = 0; TouchLocationInfo changeTouch = info.GetChangedTouches().back(); JSRef changeTouchElement = CreateTouchInfo(changeTouch, info); changeTouchArr->SetValueAt(index, changeTouchElement); if (info.GetChangedTouches().size() > 0) { eventObj->SetProperty("type", static_cast(changeTouch.GetTouchType())); } const std::list& touchList = info.GetTouches(); for (const TouchLocationInfo& location : touchList) { if (location.GetFingerId() == changeTouch.GetFingerId()) { JSRef touchElement = CreateTouchInfo(changeTouch, info); touchArr->SetValueAt(index++, touchElement); } else { JSRef touchElement = CreateTouchInfo(location, info); touchArr->SetValueAt(index++, touchElement); } } eventObj->SetPropertyObject("touches", touchArr); eventObj->SetPropertyObject("changedTouches", changeTouchArr); obj->SetPropertyObject("touchEvent", eventObj); JSRef requestObj = JSClass::NewInstance(); auto requestEvent = Referenced::Claim(requestObj->Unwrap()); requestEvent->SetResult(eventInfo.GetResult()); obj->SetPropertyObject("result", requestObj); return JSRef::Cast(obj); } void JSWeb::OnNativeEmbedGestureEvent(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), NativeEmbeadTouchToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetNativeEmbedGestureEventId(jsCallback); } JSRef OverScrollEventToJSValue(const WebOnOverScrollEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("xOffset", eventInfo.GetX()); obj->SetProperty("yOffset", eventInfo.GetY()); return JSRef::Cast(obj); } void JSWeb::OnOverScroll(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), OverScrollEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetOverScrollId(jsCallback); } void JSWeb::SetLayoutMode(int32_t layoutMode) { auto mode = WebLayoutMode::NONE; switch (layoutMode) { case 0: mode = WebLayoutMode::NONE; break; case 1: mode = WebLayoutMode::FIT_CONTENT; break; default: mode = WebLayoutMode::NONE; break; } WebModel::GetInstance()->SetLayoutMode(mode); } void JSWeb::SetNestedScroll(const JSCallbackInfo& args) { NestedScrollOptionsExt nestedOpt = { .scrollUp = NestedScrollMode::SELF_FIRST, .scrollDown = NestedScrollMode::SELF_FIRST, .scrollLeft = NestedScrollMode::SELF_FIRST, .scrollRight = NestedScrollMode::SELF_FIRST, }; if (args.Length() < 1 || !args[0]->IsObject()) { WebModel::GetInstance()->SetNestedScrollExt(nestedOpt); return; } JSRef obj = JSRef::Cast(args[0]); int32_t froward = -1; JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollForward"), froward); if (CheckNestedScrollMode(froward)) { nestedOpt.scrollDown = static_cast(froward); nestedOpt.scrollRight = static_cast(froward); } int32_t backward = -1; JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollBackward"), backward); if (CheckNestedScrollMode(backward)) { nestedOpt.scrollUp = static_cast(backward); nestedOpt.scrollLeft = static_cast(backward); } int32_t scrollUp = -1; JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollUp"), scrollUp); if (CheckNestedScrollMode(scrollUp)) { nestedOpt.scrollUp = static_cast(scrollUp); } int32_t scrollDown = -1; JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollDown"), scrollDown); if (CheckNestedScrollMode(scrollDown)) { nestedOpt.scrollDown = static_cast(scrollDown); } int32_t scrollLeft = -1; JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollLeft"), scrollLeft); if (CheckNestedScrollMode(scrollLeft)) { nestedOpt.scrollLeft = static_cast(scrollLeft); } int32_t scrollRight = -1; JSViewAbstract::ParseJsInt32(obj->GetProperty("scrollRight"), scrollRight); if (CheckNestedScrollMode(scrollRight)) { nestedOpt.scrollRight = static_cast(scrollRight); } WebModel::GetInstance()->SetNestedScrollExt(nestedOpt); args.ReturnSelf(); } bool JSWeb::CheckNestedScrollMode(const int32_t& modeValue) { return modeValue >= static_cast(NestedScrollMode::SELF_ONLY) && modeValue <= static_cast(NestedScrollMode::PARALLEL); } void JSWeb::SetMetaViewport(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsBoolean()) { return; } bool enabled = args[0]->ToBoolean(); WebModel::GetInstance()->SetMetaViewport(enabled); } void JSWeb::ParseScriptItems(const JSCallbackInfo& args, ScriptItems& scriptItems) { if (args.Length() != 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsArray()) { return; } auto paramArray = JSRef::Cast(args[0]); size_t length = paramArray->Length(); if (length == 0) { return; } std::string script; std::vector scriptRules; for (size_t i = 0; i < length; i++) { auto item = paramArray->GetValueAt(i); if (!item->IsObject()) { return; } auto itemObject = JSRef::Cast(item); JSRef jsScript = itemObject->GetProperty("script"); JSRef jsScriptRules = itemObject->GetProperty("scriptRules"); if (!jsScriptRules->IsArray() || JSRef::Cast(jsScriptRules)->Length() == 0) { return; } if (!JSViewAbstract::ParseJsString(jsScript, script)) { return; } scriptRules.clear(); if (!JSViewAbstract::ParseJsStrArray(jsScriptRules, scriptRules)) { return; } if (scriptItems.find(script) == scriptItems.end()) { scriptItems.insert(std::make_pair(script, scriptRules)); } } } void JSWeb::JavaScriptOnDocumentStart(const JSCallbackInfo& args) { ScriptItems scriptItems; ParseScriptItems(args, scriptItems); WebModel::GetInstance()->JavaScriptOnDocumentStart(scriptItems); } void JSWeb::JavaScriptOnDocumentEnd(const JSCallbackInfo& args) { ScriptItems scriptItems; ParseScriptItems(args, scriptItems); WebModel::GetInstance()->JavaScriptOnDocumentEnd(scriptItems); } void JSWeb::OnOverrideUrlLoading(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), LoadOverrideEventToJSValue); auto instanceId = Container::CurrentId(); auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> bool { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, false); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); JSRef message = func->ExecuteWithValue(*eventInfo); if (message->IsBoolean()) { return message->ToBoolean(); } return false; }; WebModel::GetInstance()->SetOnOverrideUrlLoading(std::move(uiCallback)); } void JSWeb::CopyOption(int32_t copyOption) { auto mode = CopyOptions::Local; switch (copyOption) { case static_cast(CopyOptions::None): mode = CopyOptions::None; break; case static_cast(CopyOptions::InApp): mode = CopyOptions::InApp; break; case static_cast(CopyOptions::Local): mode = CopyOptions::Local; break; case static_cast(CopyOptions::Distributed): mode = CopyOptions::Distributed; break; default: mode = CopyOptions::Local; break; } WebModel::GetInstance()->SetCopyOptionMode(mode); } void JSWeb::TextAutosizing(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsBoolean()) { return; } bool isTextAutosizing = args[0]->ToBoolean(); WebModel::GetInstance()->SetTextAutosizing(isTextAutosizing); } void JSWeb::EnableNativeVideoPlayer(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsObject()) { return; } auto paramObject = JSRef::Cast(args[0]); std::optional enable; std::optional shouldOverlay; JSRef enableJsValue = paramObject->GetProperty("enable"); if (enableJsValue->IsBoolean()) { enable = enableJsValue->ToBoolean(); } JSRef shouldOverlayJsValue = paramObject->GetProperty("shouldOverlay"); if (shouldOverlayJsValue->IsBoolean()) { shouldOverlay = shouldOverlayJsValue->ToBoolean(); } if (!enable || !shouldOverlay) { // invalid NativeVideoPlayerConfig return; } WebModel::GetInstance()->SetNativeVideoPlayerConfig(*enable, *shouldOverlay); } JSRef RenderProcessNotRespondingToJSValue(const RenderProcessNotRespondingEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("jsStack", eventInfo.GetJsStack()); obj->SetProperty("pid", eventInfo.GetPid()); obj->SetProperty("reason", eventInfo.GetReason()); return JSRef::Cast(obj); } void JSWeb::OnRenderProcessNotResponding(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), RenderProcessNotRespondingToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetRenderProcessNotRespondingId(jsCallback); } JSRef RenderProcessRespondingEventToJSValue(const RenderProcessRespondingEvent& eventInfo) { JSRef obj = JSRef::New(); return JSRef::Cast(obj); } void JSWeb::OnRenderProcessResponding(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), RenderProcessRespondingEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetRenderProcessRespondingId(jsCallback); } JSRef ViewportFitChangedToJSValue(const ViewportFitChangedEvent& eventInfo) { JSRef obj = JSRef::New(); obj->SetProperty("viewportFit", eventInfo.GetViewportFit()); return JSRef::Cast(obj); } void JSWeb::OnViewportFitChanged(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), ViewportFitChangedToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetViewportFitChangedId(jsCallback); } void JSWeb::SelectionMenuOptions(const JSCallbackInfo& args) { if (args.Length() != 1 || args[0]->IsUndefined() || args[0]->IsNull() || !args[0]->IsArray()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto instanceId = Container::CurrentId(); auto menuItamArray = JSRef::Cast(args[0]); WebMenuOptionsParam optionParam; NG::MenuOptionsParam menuOption; for (size_t i = 0; i < menuItamArray->Length(); i++) { auto menuItem = menuItamArray->GetValueAt(i); if (!menuItem->IsObject()) { return; } auto menuItemObject = JSRef::Cast(menuItem); auto jsContent = menuItemObject->GetProperty("content"); auto jsStartIcon = menuItemObject->GetProperty("startIcon"); std::string content; if (!ParseJsMedia(jsContent, content)) { return; } menuOption.content = content; std::string icon; menuOption.icon.reset(); if (ParseJsMedia(jsStartIcon, icon)) { menuOption.icon = icon; } auto jsAction = menuItemObject->GetProperty("action"); if (jsAction.IsEmpty() || !jsAction->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr(JSRef::Cast(jsAction)); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode](const std::string selectInfo) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); pipelineContext->SetCallBackNode(node); auto newSelectInfo = JSRef::Make(ToJSValue(selectInfo)); func->ExecuteJS(1, &newSelectInfo); }; menuOption.action = std::move(jsCallback); optionParam.menuOption.push_back(menuOption); } WebModel::GetInstance()->SetSelectionMenuOptions(std::move(optionParam)); } void JSWeb::OnAdsBlocked(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { return; } WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), AdsBlockedEventToJSValue); auto instanceId = Container::CurrentId(); auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) { ContainerScope scope(instanceId); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*eventInfo); }; WebModel::GetInstance()->SetAdsBlockedEventId(jsCallback); } JSRef InterceptKeyboardEventToJSValue(const InterceptKeyboardEvent& eventInfo) { JSRef obj = JSRef::New(); JSRef webKeyboardControllerObj = JSClass::NewInstance(); auto webKeyboardController = Referenced::Claim(webKeyboardControllerObj->Unwrap()); webKeyboardController->SeWebKeyboardController(eventInfo.GetCustomKeyboardHandler()); obj->SetPropertyObject("controller", webKeyboardControllerObj); JSRef objectTemplate = JSRef::New(); JSRef attributesObj = objectTemplate->NewInstance(); for (const auto& item : eventInfo.GetAttributesMap()) { attributesObj->SetProperty(item.first.c_str(), item.second.c_str()); } obj->SetPropertyObject("attributes", attributesObj); return JSRef::Cast(obj); } void JSWeb::ParseJsCustomKeyboardOption(const JsiExecutionContext& context, const JSRef& keyboardOpt, WebKeyboardOption& keyboardOption) { TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption enter"); if (!keyboardOpt->IsObject()) { return; } JSRef keyboradOptObj = JSRef::Cast(keyboardOpt); auto useSystemKeyboardObj = keyboradOptObj->GetProperty("useSystemKeyboard"); if (useSystemKeyboardObj->IsNull() || !useSystemKeyboardObj->IsBoolean()) { return; } bool isSystemKeyboard = useSystemKeyboardObj->ToBoolean(); keyboardOption.isSystemKeyboard_ = isSystemKeyboard; TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption isSystemKeyboard is %{public}d", isSystemKeyboard); if (isSystemKeyboard) { auto enterKeyTypeObj = keyboradOptObj->GetProperty("enterKeyType"); if (enterKeyTypeObj->IsNull() || !enterKeyTypeObj->IsNumber()) { return; } int32_t enterKeyType = enterKeyTypeObj->ToNumber(); keyboardOption.enterKeyTpye_ = enterKeyType; TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption \ isSystemKeyboard is %{public}d, enterKeyType is %{public}d", isSystemKeyboard, enterKeyType); } else { auto builder = keyboradOptObj->GetProperty("customKeyboard"); if (builder->IsNull()) { TAG_LOGE(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption" \ ", parse customKeyboard, builder is null"); return; } if (!builder->IsFunction()) { TAG_LOGE(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption" \ ", parse customKeyboard, builder is invalid"); return; } auto builderFunc = AceType::MakeRefPtr(JSRef::Cast(builder)); CHECK_NULL_VOID(builderFunc); WeakPtr targetNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto buildFunc = [execCtx = context, func = std::move(builderFunc), node = targetNode]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("WebCustomKeyboard"); PipelineContext::SetCallBackNode(node); func->Execute(); }; keyboardOption.customKeyboardBuilder_ = buildFunc; TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard ParseJsCustomKeyboardOption" \ ", isSystemKeyboard is %{public}d, parseCustomBuilder end", isSystemKeyboard); } } void JSWeb::OnInterceptKeyboardAttach(const JSCallbackInfo& args) { TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard OnInterceptKeyboardAttach register enter"); if (args.Length() < 1 || !args[0]->IsFunction()) { return; } auto jsFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), InterceptKeyboardEventToJSValue); auto instanceId = Container::CurrentId(); auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto uiCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( const BaseEventInfo* info) -> WebKeyboardOption { TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard OnInterceptKeyboardAttach invoke enter"); ContainerScope scope(instanceId); WebKeyboardOption opt; JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, opt); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineContext, opt); pipelineContext->UpdateCurrentActiveNode(node); auto* eventInfo = TypeInfoHelper::DynamicCast(info); JSRef keyboardOpt = func->ExecuteWithValue(*eventInfo); ParseJsCustomKeyboardOption(execCtx, keyboardOpt, opt); return opt; }; WebModel::GetInstance()->SetOnInterceptKeyboardAttach(std::move(uiCallback)); } void JSWeb::ForceDisplayScrollBar(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsBoolean()) { return; } bool isEnabled = args[0]->ToBoolean(); WebModel::GetInstance()->SetOverlayScrollbarEnabled(isEnabled); } void JSWeb::KeyboardAvoidMode(int32_t mode) { if (mode < static_cast(WebKeyboardAvoidMode::RESIZE_VISUAL) || mode > static_cast(WebKeyboardAvoidMode::DEFAULT)) { TAG_LOGE(AceLogTag::ACE_WEB, "KeyboardAvoidMode param err"); return; } WebKeyboardAvoidMode avoidMode = static_cast(mode); WebModel::GetInstance()->SetKeyboardAvoidMode(avoidMode); } void JSWeb::EditMenuOptions(const JSCallbackInfo& info) { NG::OnCreateMenuCallback onCreateMenuCallback; NG::OnMenuItemClickCallback onMenuItemClick; JSViewAbstract::ParseEditMenuOptions(info, onCreateMenuCallback, onMenuItemClick); WebModel::GetInstance()->SetEditMenuOptions(std::move(onCreateMenuCallback), std::move(onMenuItemClick)); } void JSWeb::EnableHapticFeedback(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsBoolean()) { return; } bool isEnabled = args[0]->ToBoolean(); WebModel::GetInstance()->SetEnabledHapticFeedback(isEnabled); } } // namespace OHOS::Ace::Framework