1 /* 2 * Copyright (c) 2023-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 16 #ifndef OHOS_JS_EXTENSION_WINDOW_REGISTER_MANAGER_H 17 #define OHOS_JS_EXTENSION_WINDOW_REGISTER_MANAGER_H 18 19 #include <map> 20 #include <mutex> 21 #include "js_extension_window_listener.h" 22 #include "native_engine/native_engine.h" 23 #include "native_engine/native_reference.h" 24 #include "native_engine/native_value.h" 25 #include "refbase.h" 26 #include "window.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 class JsExtensionWindowRegisterManager { 31 public: 32 JsExtensionWindowRegisterManager(); 33 ~JsExtensionWindowRegisterManager(); 34 WmErrorCode RegisterListener(sptr<Window> window, std::string type, 35 CaseType caseType, napi_env env, napi_value value); 36 WmErrorCode UnregisterListener(sptr<Window> window, std::string type, 37 CaseType caseType, napi_env env, napi_value value); 38 39 private: 40 enum class ListenerType : uint32_t { 41 WINDOW_SIZE_CHANGE_CB, 42 WINDOW_RECT_CHANGE_CB, 43 AVOID_AREA_CHANGE_CB, 44 WINDOW_EVENT_CB, 45 WINDOW_STAGE_EVENT_CB, 46 }; 47 48 bool IsCallbackRegistered(napi_env env, std::string type, napi_value jsListenerObject); 49 WmErrorCode ProcessWindowChangeRegister(sptr<JsExtensionWindowListener> listener, 50 sptr<Window> window, bool isRegister); 51 WmErrorCode ProcessWindowRectChangeRegister(const sptr<JsExtensionWindowListener>& listener, 52 const sptr<Window>& window, bool isRegister); 53 WmErrorCode ProcessAvoidAreaChangeRegister(sptr<JsExtensionWindowListener> listener, 54 sptr<Window> window, bool isRegister); 55 WmErrorCode ProcessLifeCycleEventRegister(sptr<JsExtensionWindowListener> listener, 56 sptr<Window> window, bool isRegister); 57 WmErrorCode ProcessRegister(CaseType caseType, const sptr<JsExtensionWindowListener>& listener, 58 const sptr<Window>& window, const std::string& type, bool isRegister); 59 std::map<std::string, std::map<std::shared_ptr<NativeReference>, sptr<JsExtensionWindowListener>>> jsCbMap_; 60 std::mutex mtx_; 61 std::map<CaseType, std::map<std::string, ListenerType>> listenerCodeMap_; 62 }; 63 } // namespace Rosen 64 } // namespace OHOS 65 #endif // OHOS_JS_EXTENSION_WINDOW_REGISTER_MANAGER_H 66