• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "cm_type.h"
26 
27 namespace CMNapi {
28 const std::string PARAM_UI_EXTENSION_TYPE = "ability.want.params.uiExtensionType";
29 const std::string SYS_COMMON_UI = "sys/commonUI";
30 const std::string CERT_MANAGER_BUNDLENAME = "com.ohos.certmanager";
31 const std::string CERT_MANAGER_ABILITYNAME = "CertPickerUIExtAbility";
32 const std::string CERT_MANAGER_PAGE_TYPE = "pageType";
33 const std::string CERT_MANAGER_CERTSCOPE_TYPE = "certScope";
34 const std::string CERT_MANAGER_CERTIFICATE_DATA = "cert";
35 const std::string CERT_MANAGER_CALLER_BUNDLENAME = "bundleName";
36 const std::string CERT_MANAGER_CERT_URI = "certUri";
37 const std::string CERT_MANAGER_OPERATION_TYPE = "operationType";
38 const std::string CERT_MANAGER_SHOW_INSTALL_BUTTON = "showInstallButton";
39 
40 constexpr int32_t PARAM0 = 0;
41 constexpr int32_t PARAM1 = 1;
42 constexpr int32_t PARAM2 = 2;
43 constexpr int32_t PARAM3 = 3;
44 constexpr int32_t PARAM_SIZE_TWO = 2;
45 constexpr int32_t PARAM_SIZE_THREE = 3;
46 constexpr int32_t PARAM_SIZE_FOUR = 4;
47 
48 napi_value CMNapiOpenCertManagerDialog(napi_env env, napi_callback_info info);
49 
50 struct CommonAsyncContext {
51     explicit CommonAsyncContext(napi_env env);
52     virtual ~CommonAsyncContext();
53     napi_env env = nullptr;
54     napi_status status = napi_invalid_arg;
55     int32_t errCode = 0;
56     napi_deferred deferred = nullptr;  // promise handle
57     std::string uri = "";
58     int32_t opType = 0;
59 };
60 
61 struct CmUIExtensionRequestContext : public CommonAsyncContext {
CmUIExtensionRequestContextCmUIExtensionRequestContext62     explicit CmUIExtensionRequestContext(napi_env env) : CommonAsyncContext(env) {};
63     std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> context = nullptr;
64     uint32_t pageType = 0;
65     uint32_t certificateType = 0;
66     uint32_t certificateScope = 0;
67     std::string certStr = "";
68     std::string labelName = "";
69     CmBlob *certUri = nullptr;
70     bool showInstallButton = false;
71 };
72 
73 class CmUIExtensionCallback {
74 public:
75     explicit CmUIExtensionCallback(std::shared_ptr<CmUIExtensionRequestContext>& reqContext);
76     virtual ~CmUIExtensionCallback();
77     virtual void SetSessionId(const int32_t sessionId);
78     virtual void OnRelease(const int32_t releaseCode);
79     virtual void OnResult(const int32_t resultCode, const OHOS::AAFwk::Want& result);
80     virtual void OnReceive(const OHOS::AAFwk::WantParams& request);
81     virtual void OnError(const int32_t code, const std::string& name, const std::string& message);
82     virtual void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy>& uiProxy);
83     virtual void OnDestroy();
84     virtual void SendMessageBack();
85     virtual void ProcessCallback(napi_env env, const CommonAsyncContext* asyncContext);
86 
87 private:
88     bool SetErrorCode(int32_t errCode);
89     int32_t sessionId_ = 0;
90     int32_t resultCode_ = 0;
91     OHOS::AAFwk::Want resultWant_;
92     std::shared_ptr<CmUIExtensionRequestContext> reqContext_ = nullptr;
93     bool alreadyCallback_ = false;
94 };
95 
96 }  // namespace CertManagerNapi
97 #endif  // CM_NAPI_OPEN_DIALOG_H
98