1 /*
2 * Copyright (c) 2022-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_DIALOG_COMMON_H
17 #define CM_NAPI_DIALOG_COMMON_H
18
19 #include <string>
20
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23
24 #include "cm_napi_open_dialog.h"
25 #include "cm_mem.h"
26 #include "cm_type.h"
27
28 namespace CMNapi {
29
30 static const std::string BUSINESS_ERROR_PROPERTY_CODE = "code";
31 static const std::string BUSINESS_ERROR_PROPERTY_MESSAGE = "message";
32 static const int32_t RESULT_NUMBER = 2;
33
34 void StartUIExtensionAbility(std::shared_ptr<CmUIExtensionRequestContext> asyncContext,
35 OHOS::AAFwk::Want want, std::shared_ptr<CmUIExtensionCallback> uiExtCallback);
36 bool ParseCmUIAbilityContextReq(
37 napi_env env, const napi_value& obj, std::shared_ptr<OHOS::AbilityRuntime::AbilityContext>& abilityContext);
38 napi_value ParseUint32(napi_env env, napi_value object, uint32_t &store);
39 napi_value ParseBoolean(napi_env env, napi_value object, bool &status);
40 napi_value ParseString(napi_env env, napi_value object, CmBlob *&blob);
41 napi_value GetUint8ArrayToBase64Str(napi_env env, napi_value object, std::string &certArray);
42
43 void ThrowError(napi_env env, int32_t errorCode, const std::string errMsg);
44 napi_value GenerateBusinessError(napi_env env, int32_t errorCode);
45
46 void GeneratePromise(napi_env env, napi_deferred deferred, int32_t resultCode,
47 napi_value *result, int32_t length);
48 int32_t GetCallerLabelName(std::shared_ptr<CmUIExtensionRequestContext> asyncContext);
49
GetInt32(napi_env env,int32_t value)50 inline napi_value GetInt32(napi_env env, int32_t value)
51 {
52 napi_value result = nullptr;
53 NAPI_CALL(env, napi_create_int32(env, value, &result));
54 return result;
55 }
56
57 enum CmDialogPageType {
58 PAGE_MAIN = 1,
59 PAGE_CA_CERTIFICATE = 2,
60 PAGE_CREDENTIAL = 3,
61 PAGE_INSTALL_CERTIFICATE = 4,
62 PAGE_INSTALL_CA_GUIDE = 5,
63 PAGE_REQUEST_AUTHORIZE = 6
64 };
65
66 enum CmCertificateType {
67 CA_CERT = 1
68 };
69
70 enum CertificateScope {
71 NOT_SPECIFIED = 0,
72 CURRENT_USER = 1,
73 GLOBAL_USER = 2
74 };
75
76 enum ErrorCode {
77 SUCCESS = 0,
78 HAS_NO_PERMISSION = 201,
79 NOT_SYSTEM_APP = 202,
80 PARAM_ERROR = 401,
81 DIALOG_ERROR_GENERIC = 29700001,
82 DIALOG_ERROR_OPERATION_CANCELED = 29700002,
83 DIALOG_ERROR_INSTALL_FAILED = 29700003,
84 DIALOG_ERROR_NOT_SUPPORTED = 29700004,
85 DIALOG_ERROR_NOT_COMPLY_SECURITY_POLICY = 29700005,
86 };
87
88 enum OperationType {
89 DIALOG_OPERATION_INSTALL = 1,
90 DIALOG_OPERATION_UNINSTALL = 2,
91 DIALOG_OPERATION_DETAIL = 3,
92 DIALOG_OPERATION_AUTHORIZE = 4,
93 };
94
95 } // namespace CertManagerNapi
96
97 #endif
98