1 /* 2 * Copyright (c) 2024 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_ABILITY_RUNTIME_UI_SERVICE_EXTENSION_H 17 #define OHOS_ABILITY_RUNTIME_UI_SERVICE_EXTENSION_H 18 19 #include "extension_base.h" 20 #include "js_runtime.h" 21 #include "context/context.h" 22 #ifdef SUPPORT_GRAPHICS 23 #include "js_extension_window_config.h" 24 #include "js_window_utils.h" 25 #include "window_helper.h" 26 #include "window_scene.h" 27 #include "js_window_stage.h" 28 #include "session_info.h" 29 #endif 30 31 32 namespace OHOS { 33 namespace AbilityRuntime { 34 class UIServiceExtensionContext; 35 class Runtime; 36 using AbilityHandler = AppExecFwk::AbilityHandler; 37 using OHOSApplication = AppExecFwk::OHOSApplication; 38 39 /** 40 * @brief Basic ui extension components. 41 */ 42 class UIServiceExtension : public ExtensionBase<UIServiceExtensionContext> { 43 public: 44 UIServiceExtension() = default; 45 virtual ~UIServiceExtension() = default; 46 47 /** 48 * @brief Create and init context. 49 * 50 * @param record the ui service extension record. 51 * @param application the application info. 52 * @param handler the ui service extension handler. 53 * @param token the remote token. 54 * @return The created context. 55 */ 56 virtual std::shared_ptr<UIServiceExtensionContext> CreateAndInitContext( 57 const std::shared_ptr<AbilityLocalRecord> &record, 58 const std::shared_ptr<OHOSApplication> &application, 59 std::shared_ptr<AbilityHandler> &handler, 60 const sptr<IRemoteObject> &token) override; 61 62 /** 63 * @brief Init the ui service extension. 64 * 65 * @param record the ui service extension record. 66 * @param application the application info. 67 * @param handler the ui service extension handler. 68 * @param token the remote token. 69 */ 70 virtual void Init(const std::shared_ptr<AbilityLocalRecord> &record, 71 const std::shared_ptr<OHOSApplication> &application, 72 std::shared_ptr<AbilityHandler> &handler, 73 const sptr<IRemoteObject> &token) override; 74 75 /** 76 * @brief Create ui service extension. 77 * 78 * @param runtime The runtime. 79 * @return The ui service extension instance. 80 */ 81 static UIServiceExtension* Create(const std::unique_ptr<Runtime>& runtime); 82 83 #ifdef SUPPORT_GRAPHICS 84 /** 85 * @brief get the window option. 86 * @return Returns a window option object pointer. 87 */ 88 sptr<Rosen::WindowOption> GetWindowOption( 89 const std::shared_ptr< Rosen::ExtensionWindowConfig>& extensionWindowConfig, const int32_t hostWindowId); 90 #endif 91 }; 92 } // namespace AbilityRuntime 93 } // namespace OHOS 94 #endif // OHOS_ABILITY_RUNTIME_UI_SERVICE_EXTENSION_H 95