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 WEBVIEW_UTILS_H
17 #define WEBVIEW_UTILS_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 #include "cj_common_ffi.h"
23 
24 namespace OHOS {
25 namespace Webview {
26     struct RetWebHeader {
27         char *headerKey;
28         char *headerValue;
29     };
30 
31     struct ArrWebHeader {
32         RetWebHeader *head;
33         int64_t size;
34     };
35 
36     struct CHistoryItem {
37         int64_t icon;
38         char* historyUrl;
39         char* historyRawUrl;
40         char* title;
41     };
42 
43     struct LoadDatas {
44         const char* cData;
45         const char* cMimeType;
46         const char* cEncoding;
47         const char* cBaseUrl;
48         const char* cHistoryUrl;
49     };
50 
51     struct RetWebMessage {
52         char* messageStr;
53         CArrUI8 messageArr;
54     };
55 
56     struct CError {
57         char *errorName;
58         char *errorMsg;
59     };
60 
61     struct RetNumber {
62         int64_t numberInt;
63         double numberDouble;
64     };
65 
66     struct CArrDouble {
67         double *head;
68         int64_t size;
69     };
70 
71     struct CArrBool {
72         bool *head;
73         int64_t size;
74     };
75 
76     struct CArrValue {
77         char** strHead;
78         int64_t* intHead;
79         double* doubleHead;
80         bool* boolHead;
81         int64_t size;
82     };
83 
84     struct CWebStorageOrigin {
85         char* origin;
86         int64_t quota;
87         int64_t usage;
88     };
89 
90     struct CArrWebStorageOrigin {
91         CWebStorageOrigin* cWebStorageOrigin;
92         int64_t size;
93     };
94 
95     struct CScheme {
96         char* name;
97         bool isSupportCORS;
98         bool isSupportFetch;
99         bool isStandard;
100         bool isLocal;
101         bool isDisplayIsolated;
102         bool isSecure;
103         bool isCspBypassing;
104         bool isCodeCacheSupported;
105     };
106 
107     struct Scheme {
108         std::string name;
109         bool isSupportCORS;
110         bool isSupportFetch;
111         bool isStandard;
112         bool isLocal;
113         bool isDisplayIsolated;
114         bool isSecure;
115         bool isCspBypassing;
116         bool isCodeCacheSupported;
117         int32_t option = 0;
118     };
119 
120     struct CArrScheme {
121         CScheme* cScheme;
122         int64_t size;
123     };
124 
125     char* MallocCString(const std::string& origin);
126     uint8_t* MallocUInt8(const std::string& origin);
127     char** VectorToCArrString(const std::vector<std::string>& vec);
128     uint8_t* VectorToCArrUI8(const std::vector<uint8_t> vec);
129 }
130 }
131 
132 #endif // WEBVIEW_UTILS_H