• 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_CALLER_UID = "appUid";
37 const std::string CERT_MANAGER_CERT_URI = "certUri";
38 const std::string CERT_MANAGER_OPERATION_TYPE = "operationType";
39 const std::string CERT_MANAGER_SHOW_INSTALL_BUTTON = "showInstallButton";
40 
41 constexpr int32_t PARAM0 = 0;
42 constexpr int32_t PARAM1 = 1;
43 constexpr int32_t PARAM2 = 2;
44 constexpr int32_t PARAM3 = 3;
45 constexpr int32_t PARAM_SIZE_ONE = 1;
46 constexpr int32_t PARAM_SIZE_TWO = 2;
47 constexpr int32_t PARAM_SIZE_THREE = 3;
48 constexpr int32_t PARAM_SIZE_FOUR = 4;
49 
50 napi_value CMNapiOpenCertManagerDialog(napi_env env, napi_callback_info info);
51 
52 struct CommonAsyncContext {
53     explicit CommonAsyncContext(napi_env env);
54     virtual ~CommonAsyncContext();
55     napi_env env = nullptr;
56     napi_status status = napi_invalid_arg;
57     int32_t errCode = 0;
58     napi_deferred deferred = nullptr;  // promise handle
59     std::string uri = "";
60     int32_t opType = 0;
61 };
62 
63 struct CmUIExtensionRequestContext : public CommonAsyncContext {
CmUIExtensionRequestContextCmUIExtensionRequestContext64     explicit CmUIExtensionRequestContext(napi_env env) : CommonAsyncContext(env) {};
65     std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> context = nullptr;
66     uint32_t pageType = 0;
67     uint32_t certificateType = 0;
68     uint32_t certificateScope = 0;
69     int32_t appUid = -1;
70     std::string certStr = "";
71     std::string labelName = "";
72     CmBlob *certUri = nullptr;
73     bool showInstallButton = false;
74 };
75 
76 class CmUIExtensionCallback {
77 public:
78     explicit CmUIExtensionCallback(std::shared_ptr<CmUIExtensionRequestContext>& reqContext);
79     virtual ~CmUIExtensionCallback();
80     virtual void SetSessionId(const int32_t sessionId);
81     virtual void OnRelease(const int32_t releaseCode);
82     virtual void OnResult(const int32_t resultCode, const OHOS::AAFwk::Want& result);
83     virtual void OnReceive(const OHOS::AAFwk::WantParams& request);
84     virtual void OnError(const int32_t code, const std::string& name, const std::string& message);
85     virtual void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy>& uiProxy);
86     virtual void OnDestroy();
87     virtual void SendMessageBack();
88     virtual void ProcessCallback(napi_env env, const CommonAsyncContext* asyncContext);
89 
90 private:
91     bool SetErrorCode(int32_t errCode);
92     int32_t sessionId_ = 0;
93     int32_t resultCode_ = 0;
94     OHOS::AAFwk::Want resultWant_;
95     std::shared_ptr<CmUIExtensionRequestContext> reqContext_ = nullptr;
96     bool alreadyCallback_ = false;
97 };
98 
99 }  // namespace CertManagerNapi
100 #endif  // CM_NAPI_OPEN_DIALOG_H
101