1 /* 2 * Copyright (c) 2021-2022 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 FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_JSI_JSI_XCOMPONENT_BRIDGE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_JSI_JSI_XCOMPONENT_BRIDGE_H 18 19 #include <unordered_map> 20 21 #include "base/memory/ace_type.h" 22 #include "frameworks/bridge/common/dom/dom_xcomponent.h" 23 #include "frameworks/bridge/js_frontend/engine/common/base_xcomponent_bridge.h" 24 #include "frameworks/bridge/js_frontend/engine/jsi/jsi_engine.h" 25 #include "frameworks/core/components/common/properties/decoration.h" 26 #include "frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h" 27 28 namespace OHOS::Ace::Framework { 29 class JsiXComponentBridge : public BaseXComponentBridge { 30 DECLARE_ACE_TYPE(JsiXComponentBridge, BaseXComponentBridge) 31 32 public: 33 JsiXComponentBridge(); 34 ~JsiXComponentBridge() override; 35 void HandleContext(const shared_ptr<JsRuntime>& runtime, NodeId id, const std::string& args); 36 OnJsEngineDestroy()37 void OnJsEngineDestroy() override 38 { 39 renderContext_.reset(); 40 } 41 GetRenderContext()42 const shared_ptr<JsValue>& GetRenderContext() const 43 { 44 return renderContext_; 45 } 46 47 static shared_ptr<JsValue> JsGetXComponentSurfaceId(const shared_ptr<JsRuntime>& runtime, NodeId nodeId); 48 static void JsSetXComponentSurfaceSize( 49 const shared_ptr<JsRuntime>& runtime, const std::string& arguments, NodeId nodeId); 50 51 private: 52 shared_ptr<JsValue> renderContext_; 53 OH_NativeXComponent *nativeXComponent_ = nullptr; 54 RefPtr<NativeXComponentImpl> nativeXcomponentImpl_; 55 56 bool hasPluginLoaded_ = false; 57 }; 58 } // namespace OHOS::Ace::Framework 59 60 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_JSI_JSI_XCOMPONENT_BRIDGE_H 61