1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_SECURITY_UI_EXTENSION_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_SECURITY_UI_EXTENSION_H 18 19 #include "bridge/declarative_frontend/jsview/js_interactable_view.h" 20 #include "bridge/declarative_frontend/jsview/js_ui_extension.h" 21 #include "bridge/declarative_frontend/jsview/js_view_abstract.h" 22 #include "core/components_ng/pattern/ui_extension/security_ui_extension_component/security_ui_extension_proxy.h" 23 24 namespace OHOS::Ace::Framework { 25 class JSSecurityUIExtension { 26 public: 27 static void JSBind(BindingTarget globalObj); 28 static void Create(const JSCallbackInfo& info); 29 static void OnRemoteReady(const JSCallbackInfo& info); 30 static void OnReceive(const JSCallbackInfo& info); 31 static void OnError(const JSCallbackInfo& info); 32 static void OnTerminated(const JSCallbackInfo& info); 33 static void JsWidth(const JSCallbackInfo& info); 34 static void JsHeight(const JSCallbackInfo& info); 35 private: 36 static CalcDimension GetSizeValue(const JSCallbackInfo& info); 37 }; 38 39 using SecurityCallbackFuncPairList = 40 std::list<std::pair<napi_ref, std::function<void(const RefPtr<NG::SecurityUIExtensionProxy>&)>>>; 41 42 class JSSecurityUIExtensionProxy : public Referenced { 43 public: 44 JSSecurityUIExtensionProxy() = default; 45 ~JSSecurityUIExtensionProxy() override = default; 46 static void JSBind(BindingTarget globalObj); 47 void Send(const JSCallbackInfo& info); 48 void SendSync(const JSCallbackInfo& info); 49 void On(const JSCallbackInfo& info); 50 void Off(const JSCallbackInfo& info); 51 void SetProxy(const RefPtr<NG::SecurityUIExtensionProxy>& proxy); 52 void SetInstanceId(int32_t instanceId); 53 private: 54 static void Constructor(const JSCallbackInfo& info); 55 static void Destructor(JSSecurityUIExtensionProxy* uiExtensionProxy); 56 57 bool CanTurnOn(const JSCallbackInfo& info); 58 SecurityCallbackFuncPairList::const_iterator FindCbList(napi_env env, napi_value cb, 59 SecurityCallbackFuncPairList& callbackFuncPairList); 60 void AddCallbackToList(napi_env env, napi_value cb, napi_handle_scope scope, RegisterType type, 61 const std::function<void(const RefPtr<NG::SecurityUIExtensionProxy>&)>&& onFunc); 62 void DeleteCallbackFromList(uint32_t argc, napi_env env, napi_value cb, RegisterType type); 63 std::list<std::function<void(const RefPtr<NG::SecurityUIExtensionProxy>&)>> GetOnFuncList(RegisterType type); 64 RegisterType GetRegisterType(const std::string& strType); 65 66 RefPtr<NG::SecurityUIExtensionProxy> proxy_; 67 int32_t instanceId_ = INSTANCE_ID_UNDEFINED; 68 SecurityCallbackFuncPairList onSyncOnCallbackList_; 69 SecurityCallbackFuncPairList onAsyncOnCallbackList_; 70 std::mutex callbackLisLock_; 71 }; 72 73 class JSPreviewUIExtension { 74 public: 75 static void JSBind(BindingTarget globalObj); 76 static void Create(const JSCallbackInfo& info); 77 static void OnError(const JSCallbackInfo& info); 78 static void JsWidth(const JSCallbackInfo& info); 79 static void JsHeight(const JSCallbackInfo& info); 80 }; 81 } // namespace OHOS::Ace::Framework 82 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_SECURITY_UI_EXTENSION_H 83