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
GetInt32(napi_env env,int32_t value)49 inline napi_value GetInt32(napi_env env, int32_t value)
50 {
51 napi_value result = nullptr;
52 NAPI_CALL(env, napi_create_int32(env, value, &result));
53 return result;
54 }
55
56 enum CmDialogPageType {
57 PAGE_MAIN = 1,
58 PAGE_CA_CERTIFICATE = 2,
59 PAGE_CREDENTIAL = 3,
60 PAGE_INSTALL_CERTIFICATE = 4,
61 PAGE_INSTALL_CA_GUIDE = 5
62 };
63
64 enum CmCertificateType {
65 CA_CERT = 1
66 };
67
68 enum CertificateScope {
69 CURRENT_USER = 1
70 };
71
72 enum ErrorCode {
73 SUCCESS = 0,
74 HAS_NO_PERMISSION = 201,
75 NOT_SYSTEM_APP = 202,
76 PARAM_ERROR = 401,
77 DIALOG_ERROR_GENERIC = 29700001,
78 DIALOG_ERROR_OPERATION_CANCELED = 29700002,
79 DIALOG_ERROR_INSTALL_FAILED = 29700003,
80 DIALOG_ERROR_NOT_SUPPORTED = 29700004,
81 };
82
83 } // namespace CertManagerNapi
84
85 #endif
86