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 #ifndef INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_CONFIRM_CALLBACK_H
16 #define INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_CONFIRM_CALLBACK_H
17 
18 #include <js_native_api.h>
19 #include <napi/native_api.h>
20 #include <node_api.h>
21 #include <string>
22 #include <vector>
23 #include <uv.h>
24 
25 #include "want.h"
26 #ifdef HAS_ACE_ENGINE_PART
27 #include "ui_content.h"
28 #endif
29 #include "medialibrary_client_errno.h"
30 
31 namespace OHOS {
32 namespace Media {
33 struct PhotoCreationConfig {
34     std::string title;
35     std::string fileNameExtension;
36     int32_t photoType;
37     int32_t subtype;
38 };
39 
40 class ConfirmCallback {
41 public:
42 #ifdef HAS_ACE_ENGINE_PART
43     explicit ConfirmCallback(napi_env env, Ace::UIContent *uiContent);
44 #else
45     explicit ConfirmCallback(napi_env env);
46 #endif
47     virtual ~ConfirmCallback() = default;
48     void OnRelease(int32_t releaseCode);
49     void OnResult(int32_t resultCode, const OHOS::AAFwk::Want &want);
50     void OnReceive(const OHOS::AAFwk::WantParams &request);
51     void OnError(int32_t code, const std::string &name, const std::string &message);
52     void SetSessionId(int32_t sessionId);
53     void SetUris(const std::vector<std::string> &uris);
54     void SetFunc(napi_value func);
55 
56 private:
57     int32_t sessionId_ = 0;
58     int32_t resultCode_ = JS_ERR_PERMISSION_DENIED;
59     napi_env env_ = nullptr;
60     napi_ref callbackRef = nullptr;
61 #ifdef HAS_ACE_ENGINE_PART
62     Ace::UIContent *uiContent = nullptr;
63 #endif
64 
65     void SendMessageBack(const std::vector<std::string> &desFileUris);
66     void CloseModalUIExtension();
67 };
68 }
69 }
70 #endif
71