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 16 #ifndef OHOS_WINDOW_SCENE_JS_ROOT_SCENE_SESSION_H 17 #define OHOS_WINDOW_SCENE_JS_ROOT_SCENE_SESSION_H 18 19 #include <native_engine/native_engine.h> 20 #include <native_engine/native_value.h> 21 #include "session/host/include/root_scene_session.h" 22 #include "js_scene_utils.h" 23 24 namespace OHOS::Rosen { 25 class JsRootSceneSession : public RefBase { 26 public: 27 JsRootSceneSession(napi_env env, const sptr<RootSceneSession>& rootSceneSession); 28 ~JsRootSceneSession() = default; 29 30 static napi_value Create(napi_env env, const sptr<RootSceneSession>& rootSceneSession); 31 static void Finalizer(napi_env env, void* data, void* hint); 32 33 static napi_value RegisterCallback(napi_env env, napi_callback_info info); 34 static napi_value LoadContent(napi_env env, napi_callback_info info); 35 36 private: 37 napi_value OnRegisterCallback(napi_env env, napi_callback_info info); 38 napi_value OnLoadContent(napi_env env, napi_callback_info info); 39 bool IsCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject); 40 void PendingSessionActivation(SessionInfo& info); 41 void PendingSessionActivationInner(std::shared_ptr<SessionInfo> sessionInfo); 42 sptr<SceneSession> GenSceneSession(SessionInfo& info); 43 std::shared_ptr<NativeReference> GetJSCallback(const std::string& functionName) const; 44 45 napi_env env_; 46 std::map<std::string, std::shared_ptr<NativeReference>> jsCbMap_; 47 mutable std::shared_mutex jsCbMapMutex_; 48 sptr<RootSceneSession> rootSceneSession_; 49 std::shared_ptr<MainThreadScheduler> taskScheduler_; 50 void VerifyCallerToken(SessionInfo& info); 51 }; 52 } // namespace OHOS::Rosen 53 54 #endif // OHOS_WINDOW_SCENE_JS_ROOT_SCENE_SESSION_H 55