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 CM_NAPI_OPEN_DIALOG_H 17 #define CM_NAPI_OPEN_DIALOG_H 18 19 #include "ability_context.h" 20 #include "napi/native_api.h" 21 #include "napi/native_node_api.h" 22 #include "napi_base_context.h" 23 #include "napi_common_want.h" 24 #include "ui_content.h" 25 26 namespace CMNapi { 27 napi_value CMNapiOpenCertManagerDialog(napi_env env, napi_callback_info info); 28 29 struct CommonAsyncContext { 30 explicit CommonAsyncContext(napi_env env); 31 virtual ~CommonAsyncContext(); 32 napi_env env = nullptr; 33 napi_status status = napi_invalid_arg; 34 int32_t errCode = 0; 35 napi_deferred deferred = nullptr; // promise handle 36 }; 37 38 struct CmUIExtensionRequestContext : public CommonAsyncContext { CmUIExtensionRequestContextCmUIExtensionRequestContext39 explicit CmUIExtensionRequestContext(napi_env env) : CommonAsyncContext(env) {}; 40 std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> context = nullptr; 41 uint32_t pageType = 0; 42 }; 43 44 class CmUIExtensionCallback { 45 public: 46 explicit CmUIExtensionCallback(std::shared_ptr<CmUIExtensionRequestContext>& reqContext); 47 void SetSessionId(const int32_t sessionId); 48 void OnRelease(const int32_t releaseCode); 49 void OnResult(const int32_t resultCode, const OHOS::AAFwk::Want& result); 50 void OnReceive(const OHOS::AAFwk::WantParams& request); 51 void OnError(const int32_t code, const std::string& name, const std::string& message); 52 void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy>& uiProxy); 53 void OnDestroy(); 54 void SendMessageBack(); 55 56 private: 57 bool SetErrorCode(int32_t errCode); 58 int32_t sessionId_ = 0; 59 int32_t resultCode_ = 0; 60 OHOS::AAFwk::Want resultWant_; 61 std::shared_ptr<CmUIExtensionRequestContext> reqContext_ = nullptr; 62 bool alreadyCallback_ = false; 63 }; 64 65 } // namespace CertManagerNapi 66 #endif // CM_NAPI_OPEN_DIALOG_H 67