1 /* 2 * Copyright (c) 2023 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 #ifndef NATIVE_XCOMPONENT_PLUGIN_MANAGER_H 16 #define NATIVE_XCOMPONENT_PLUGIN_MANAGER_H 17 18 #include <ace/xcomponent/native_interface_xcomponent.h> 19 #include <js_native_api.h> 20 #include <js_native_api_types.h> 21 #include <napi/native_api.h> 22 #include <string> 23 #include <unordered_map> 24 25 #include "xcomponent_manager.h" 26 namespace NativeXComponentSample { 27 28 class AbilityInfo { 29 public: 30 napi_ref uiAbility; 31 napi_ref windowStage; 32 napi_ref window; 33 napi_env env; 34 void Init(napi_env env, napi_value uiAbility, napi_value windowStage); 35 napi_value getWindow(); 36 ~AbilityInfo(); 37 }; 38 39 class PluginManager { 40 public: 41 PluginManager(); 42 ~PluginManager(); 43 GetInstance()44 static PluginManager *GetInstance() 45 { 46 return &PluginManager::pluginManager_; 47 } 48 GetAbilityInfo()49 static AbilityInfo &GetAbilityInfo() 50 { 51 return m_abilityInfo; 52 } 53 54 55 void AttachXComponent(const std::string &id, OH_NativeXComponent *nativeXComponent, OHNativeWindow *window); 56 57 void Export(napi_env env, napi_value exports); 58 59 private: 60 static PluginManager pluginManager_; 61 62 static AbilityInfo m_abilityInfo; 63 XComponentManager *xcomponentMgr; 64 }; 65 } // namespace NativeXComponentSample 66 #endif // NATIVE_XCOMPONENT_PLUGIN_MANAGER_H 67