1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. 3 */ 4 /* 5 * Copyright (c) 2023 Huawei Device Co., Ltd. 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 #ifndef NATIVE_XCOMPONENT_PLUGIN_MANAGER_H 19 #define NATIVE_XCOMPONENT_PLUGIN_MANAGER_H 20 21 #include <ace/xcomponent/native_interface_xcomponent.h> 22 #include <js_native_api.h> 23 #include <js_native_api_types.h> 24 #include <napi/native_api.h> 25 #include <string> 26 #include <unordered_map> 27 #include "native_window/external_window.h" 28 29 #include "plugin_render.h" 30 31 namespace NativeXComponentSample { 32 class PluginManager { 33 public: 34 ~PluginManager(); 35 GetInstance()36 static PluginManager* GetInstance() 37 { 38 return &PluginManager::pluginManager_; 39 } 40 41 static napi_value GetContext(napi_env env, napi_callback_info info); 42 43 void SetNativeXComponent(std::string& id, OH_NativeXComponent* nativeXComponent); 44 PluginRender* GetRender(std::string& id); 45 void Export(napi_env env, napi_value exports); 46 OHNativeWindow *pluginWindow_; 47 48 private: 49 static PluginManager pluginManager_; 50 51 std::unordered_map<std::string, OH_NativeXComponent*> nativeXComponentMap_; 52 std::unordered_map<std::string, PluginRender*> pluginRenderMap_; 53 }; 54 } // namespace NativeXComponentSample 55 #endif // NATIVE_XCOMPONENT_PLUGIN_MANAGER_H 56