• 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 WEBVIEW_UTILS_H
17 #define WEBVIEW_UTILS_H
18 
19 #include <cstdint>
20 #include <map>
21 #include <memory>
22 #include <string>
23 
24 #include "cj_common_ffi.h"
25 
26 namespace OHOS {
27 namespace Webview {
28 struct RetWebHeader {
29     char* headerKey;
30     char* headerValue;
31 };
32 
33 struct ArrWebHeader {
34     RetWebHeader* head;
35     int64_t size;
36 };
37 
38 struct CHistoryItem {
39     int64_t icon;
40     char* historyUrl;
41     char* historyRawUrl;
42     char* title;
43 };
44 
45 struct LoadDatas {
46     const char* cData;
47     const char* cMimeType;
48     const char* cEncoding;
49     const char* cBaseUrl;
50     const char* cHistoryUrl;
51 };
52 
53 struct RetWebMessage {
54     char* messageStr;
55     CArrUI8 messageArr;
56 };
57 
58 struct CError {
59     char* errorName;
60     char* errorMsg;
61 };
62 
63 struct RetNumber {
64     int64_t numberInt;
65     double numberDouble;
66 };
67 
68 struct CArrDouble {
69     double* head;
70     int64_t size;
71 };
72 
73 struct CArrBool {
74     bool* head;
75     int64_t size;
76 };
77 
78 struct CArrValue {
79     char** strHead;
80     int64_t* intHead;
81     double* doubleHead;
82     bool* boolHead;
83     int64_t size;
84 };
85 
86 struct CWebStorageOrigin {
87     char* origin;
88     int64_t quota;
89     int64_t usage;
90 };
91 
92 struct CArrWebStorageOrigin {
93     CWebStorageOrigin* cWebStorageOrigin;
94     int64_t size;
95 };
96 
97 struct CScheme {
98     char* name;
99     bool isSupportCORS;
100     bool isSupportFetch;
101     bool isStandard;
102     bool isLocal;
103     bool isDisplayIsolated;
104     bool isSecure;
105     bool isCspBypassing;
106     bool isCodeCacheSupported;
107 };
108 
109 struct Scheme {
110     std::string name;
111     bool isSupportCORS;
112     bool isSupportFetch;
113     bool isStandard;
114     bool isLocal;
115     bool isDisplayIsolated;
116     bool isSecure;
117     bool isCspBypassing;
118     bool isCodeCacheSupported;
119     int32_t option = 0;
120 };
121 
122 struct CArrScheme {
123     CScheme* head;
124     int64_t size;
125 };
126 
127 struct CacheOptions {
128     ArrWebHeader arrHead;
129 };
130 
131 struct COfflineResourceMap {
132     CArrString urlList;
133     uint8_t* resource;
134     int64_t resourceCSize;
135     ArrWebHeader responseHeaders;
136     int32_t type;
137 };
138 
139 struct CArrOfflineResourceMap {
140     COfflineResourceMap* head;
141     int64_t size;
142 };
143 
144 struct CRequestInfo {
145     char* url;
146     char* method;
147     char* formData;
148 };
149 
150 struct CMediaSourceInfo {
151     const char* format;
152     const char* source;
153     int32_t type;
154 };
155 
156 struct CArrMediaSourceInfo {
157     CMediaSourceInfo* head;
158     int64_t size;
159 };
160 
161 struct MapItem {
162     char* key;
163     char* value;
164 };
165 
166 struct ArrMapItem {
167     MapItem* head;
168     int64_t size;
169 };
170 
171 struct CRectEvent {
172     double x;
173     double y;
174     double width;
175     double height;
176 };
177 
178 struct CNativeMediaPlayerSurfaceInfo {
179     CRectEvent rect;
180     const char* id;
181 };
182 
183 struct CMediaInfo {
184     const char* embedID;
185     int32_t mediaType;
186     CArrMediaSourceInfo mediaSrcList;
187     CNativeMediaPlayerSurfaceInfo surfaceInfo;
188     bool controlsShown;
189     CArrString controlList;
190     bool muted;
191     const char* posterUrl;
192     int32_t preload;
193     ArrMapItem headers;
194     ArrMapItem attributes;
195 };
196 
197 struct CSnapshotInfo {
198     char* id;
199     int32_t width;
200     int32_t height;
201     int32_t widthType;
202     int32_t heightType;
203 };
204 
205 struct CSnapshotResult {
206     char* id;
207     int64_t imageId;
208     bool status;
209     int32_t width;
210     int32_t height;
211     int32_t widthType;
212     int32_t heightType;
213 };
214 
215 struct RetDataCSnapshotResult {
216     int32_t code;
217     CSnapshotResult data;
218 };
219 
220 struct CScrollOffset {
221     int32_t x;
222     int32_t y;
223 };
224 
225 struct CCertByteData {
226     CArrUI8* head;
227     int64_t size;
228 };
229 
230 char* MallocCString(const std::string& origin);
231 uint8_t* MallocUInt8(const std::string& origin);
232 char** VectorToCArrString(const std::vector<std::string>& vec);
233 uint8_t* VectorToCArrUI8(const std::vector<uint8_t> vec);
234 std::vector<std::string> CArrStringToVector(CArrString cArrStr);
235 } // namespace Webview
236 } // namespace OHOS
237 
238 #endif // WEBVIEW_UTILS_H