• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 /**
17  * @addtogroup Web
18  * @{
19  *
20  * @brief Provides APIs to intercept the request from ArkWeb.
21  * @since 12
22  */
23 /**
24  * @file arkweb_scheme_handler.h
25  *
26  * @brief Declares the APIs to intercept the request from ArkWeb.
27  * @kit ArkWeb
28  * @library libohweb.so
29  * @syscap SystemCapability.Web.Webview.Core
30  * @since 12
31  */
32 #ifndef ARKWEB_SCHEME_HANDLER_H
33 #define ARKWEB_SCHEME_HANDLER_H
34 
35 #include <stdbool.h>
36 #include "stdint.h"
37 
38 #include "arkweb_error_code.h"
39 #include "arkweb_net_error_list.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /**
46  * @brief Configuration information for custom schemes.
47  *
48  * @syscap SystemCapability.Web.Webview.Core
49  * @since 12
50  */
51 typedef enum ArkWeb_CustomSchemeOption {
52     OH_ARKWEB_SCHEME_OPTION_NONE = 0,
53 
54     /** If ARKWEB_SCHEME_OPTION_STANDARD is set, the scheme will be handled as a standard scheme. The standard
55      *  schemes need to comply with the URL normalization and parsing rules defined in Section 3.1 of RFC 1738,
56      *  which can be found in the http://www.ietf.org/rfc/rfc1738.txt.
57      */
58     ARKWEB_SCHEME_OPTION_STANDARD = 1 << 0,
59 
60     /** If ARKWEB_SCHEME_OPTION_LOCAL is set, the same security rules as those applied to the "file" URL will be
61      *  used to handle the scheme.
62      */
63     ARKWEB_SCHEME_OPTION_LOCAL = 1 << 1,
64 
65     /** If ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED is set, then the scheme can only be displayed from other content
66      *  hosted using the same scheme.
67      */
68     ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED = 1 << 2,
69 
70     /** If ARKWEB_SCHEME_OPTION_SECURE is set, the same security rules as those applied to the "https" URL will be
71      *  used to handle the scheme.
72      */
73     ARKWEB_SCHEME_OPTION_SECURE = 1 << 3,
74 
75     /** If ARKWEB_SCHEME_OPTION_CORS_ENABLED is set, then the scheme can be sent CORS requests. In most cases this
76      *  value should be set when ARKWEB_SCHEME_OPTION_STANDARD is set.
77      */
78     ARKWEB_SCHEME_OPTION_CORS_ENABLED = 1 << 4,
79 
80     /** If ARKWEB_SCHEME_OPTION_CSP_BYPASSING is set, then this scheme can bypass Content Security Policy (CSP)
81      *  checks. In most cases, this value should not be set when ARKWEB_SCHEME_OPTION_STANDARD is set.
82      */
83     ARKWEB_SCHEME_OPTION_CSP_BYPASSING = 1 << 5,
84 
85     /** If ARKWEB_SCHEME_OPTION_FETCH_ENABLED is set, then this scheme can perform FETCH API requests. */
86     ARKWEB_SCHEME_OPTION_FETCH_ENABLED = 1 << 6,
87 
88     /** If ARKWEB_SCHEME_OPTION_CODE_CACHE_ENABLED is set, then the js of this scheme can generate code cache. */
89     ARKWEB_SCHEME_OPTION_CODE_CACHE_ENABLED = 1 << 7,
90 } ArkWeb_CustomSchemeOption;
91 
92 /**
93  * @brief Resource type for a request.
94  *
95  * These constants match their equivalents in Chromium's ResourceType and should not be renumbered.\n
96  *
97  * @syscap SystemCapability.Web.Webview.Core
98  * @since 12
99  */
100 typedef enum ArkWeb_ResourceType {
101     /** Top level page. */
102     MAIN_FRAME = 0,
103 
104     /** Frame or Iframe. */
105     SUB_FRAME = 1,
106 
107     /** CSS stylesheet. */
108     STYLE_SHEET = 2,
109 
110     /** External script. */
111     SCRIPT = 3,
112 
113     /** Image(jpg/gif/png/etc). */
114     IMAGE = 4,
115 
116     /** Font. */
117     FONT_RESOURCE = 5,
118 
119     /** Some other subresource. This is the default type if the actual type is unknown. */
120     SUB_RESOURCE = 6,
121 
122     /** Object (or embed) tag for a plugin, or a resource that a plugin requested. */
123     OBJECT = 7,
124 
125     /** Media resource. */
126     MEDIA = 8,
127 
128     /** Main resource of a dedicated worker. */
129     WORKER = 9,
130 
131     /** Main resource of a shared worker. */
132     SHARED_WORKER = 10,
133 
134     /** Explicitly requested prefetch. */
135     PREFETCH = 11,
136 
137     /** Favicon. */
138     FAVICON = 12,
139 
140     /** XMLHttpRequest. */
141     XHR = 13,
142 
143     /** Ping request for <a ping>/sendBeacon. */
144     PING = 14,
145 
146     /** The main resource of a service worker. */
147     SERVICE_WORKER = 15,
148 
149     /** Report of Content Security Policy violations. */
150     CSP_REPORT = 16,
151 
152     /** Resource that a plugin requested. */
153     PLUGIN_RESOURCE = 17,
154 
155     /** A main-frame service worker navigation preload request. */
156     NAVIGATION_PRELOAD_MAIN_FRAME = 19,
157 
158     /** A sub-frame service worker navigation preload request. */
159     NAVIGATION_PRELOAD_SUB_FRAME = 20,
160 } ArkWeb_ResourceType;
161 
162 /**
163  * @brief This class is used to intercept requests for a specified scheme.
164  *
165  * @syscap SystemCapability.Web.Webview.Core
166  * @since 12
167  */
168 typedef struct ArkWeb_SchemeHandler_ ArkWeb_SchemeHandler;
169 
170 /**
171  * @brief Used to intercept url requests.
172  *
173  * Response headers and body can be sent through ArkWeb_ResourceHandler.\n
174  *
175  * @syscap SystemCapability.Web.Webview.Core
176  * @since 12
177  */
178 typedef struct ArkWeb_ResourceHandler_ ArkWeb_ResourceHandler;
179 
180 /**
181  * @brief The response of the intercepted request.
182  *
183  * @syscap SystemCapability.Web.Webview.Core
184  * @since 12
185  */
186 typedef struct ArkWeb_Response_ ArkWeb_Response;
187 
188 /**
189  * @brief The info of the request.
190  *
191  * You can obtain the requested URL, method, post data, and other information through OH_ArkWeb_ResourceRequest.\n
192  *
193  * @syscap SystemCapability.Web.Webview.Core
194  * @since 12
195  */
196 typedef struct ArkWeb_ResourceRequest_ ArkWeb_ResourceRequest;
197 
198 /**
199  * @brief The request headers of the request.
200  *
201  * @syscap SystemCapability.Web.Webview.Core
202  * @since 12
203  */
204 typedef struct ArkWeb_RequestHeaderList_ ArkWeb_RequestHeaderList;
205 
206 /**
207  * @brief The http body of the request.
208  *
209  * Use OH_ArkWebHttpBodyStream_* interface to read the body.\n
210  *
211  * @syscap SystemCapability.Web.Webview.Core
212  * @since 12
213  */
214 typedef struct ArkWeb_HttpBodyStream_ ArkWeb_HttpBodyStream;
215 
216 
217 /**
218  * @brief Callback for handling the request.
219  *
220  * This will be called on the IO thread.\n
221  *
222  * @param schemeHandler The ArkWeb_SchemeHandler.
223  * @param resourceRequest Obtain request's information through this.
224  * @param resourceHandler The ArkWeb_ResourceHandler for the request. It should not be used if intercept is set to
225  *                        false.
226  * @param intercept If true will intercept the request, if false otherwise.
227  *
228  * @syscap SystemCapability.Web.Webview.Core
229  * @since 12
230  */
231 typedef void (*ArkWeb_OnRequestStart)(const ArkWeb_SchemeHandler* schemeHandler,
232                                       ArkWeb_ResourceRequest* resourceRequest,
233                                       const ArkWeb_ResourceHandler* resourceHandler,
234                                       bool* intercept);
235 
236 /**
237  * @brief Callback when the request is completed.
238  *
239  * This will be called on the IO thread.\n
240  * Should destory the resourceRequest by ArkWeb_ResourceRequest_Destroy and use ArkWeb_ResourceHandler_Destroy\n
241  * destroy the ArkWeb_ResourceHandler received in ArkWeb_OnRequestStart.\n
242  *
243  * @param schemeHandler The ArkWeb_SchemeHandler.
244  * @param resourceRequest The ArkWeb_ResourceRequest.
245  *
246  * @syscap SystemCapability.Web.Webview.Core
247  * @since 12
248  */
249 typedef void (*ArkWeb_OnRequestStop)(const ArkWeb_SchemeHandler* schemeHandler,
250                                      const ArkWeb_ResourceRequest* resourceRequest);
251 
252 /**
253  * @brief Callback when the read operation done.
254  * @param httpBodyStream The ArkWeb_HttpBodyStream.
255  * @param buffer The buffer to receive data.
256  * @param bytesRead Callback after OH_ArkWebHttpBodyStream_Read. bytesRead greater than 0 means that the buffer is
257  *                  filled with data of bytesRead size. Caller can read from the buffer, and if
258  *                  OH_ArkWebHttpBodyStream_IsEOF is false, caller can continue to read the remaining data.
259  *
260  * @syscap SystemCapability.Web.Webview.Core
261  * @since 12
262  */
263 typedef void (*ArkWeb_HttpBodyStreamReadCallback)(const ArkWeb_HttpBodyStream* httpBodyStream,
264                                                   uint8_t* buffer,
265                                                   int bytesRead);
266 
267 /**
268  * @brief Callback when the read operation done.
269  * @param httpBodyStream The ArkWeb_HttpBodyStream.
270  * @param buffer The buffer to receive data.
271  * @param bytesRead Callback after OH_ArkWebHttpBodyStream_AsyncRead. bytesRead greater than 0 means that
272  *                  the buffer is filled with data of bytesRead size. Caller can read from the buffer, and if
273  *                  OH_ArkWebHttpBodyStream_IsEOF is false, caller can continue to read the remaining data.
274  *
275  * @since 20
276  */
277 typedef void (*ArkWeb_HttpBodyStreamAsyncReadCallback)(const ArkWeb_HttpBodyStream *httpBodyStream,
278                                                        uint8_t *buffer,
279                                                        int bytesRead);
280 
281 /**
282  * @brief  Callback when the init operation done.
283  * @param httpBodyStream The ArkWeb_HttpBodyStream.
284  * @param result {@link ARKWEB_NET_OK} on success otherwise refer to arkweb_net_error_list.h.
285  *
286  * @syscap SystemCapability.Web.Webview.Core
287  * @since 12
288  */
289 typedef void (*ArkWeb_HttpBodyStreamInitCallback)(const ArkWeb_HttpBodyStream* httpBodyStream, ArkWeb_NetError result);
290 
291 /**
292  * @brief Destroy the ArkWeb_RequestHeaderList.
293  * @param requestHeaderList The ArkWeb_RequestHeaderList to be destroyed.
294  *
295  * @syscap SystemCapability.Web.Webview.Core
296  * @since 12
297  */
298 void OH_ArkWebRequestHeaderList_Destroy(ArkWeb_RequestHeaderList* requestHeaderList);
299 
300 /**
301  * @brief Get the request headers size.
302  * @param requestHeaderList The list of request header.
303  * @return The size of request headers. -1 if requestHeaderList is invalid.
304  *
305  * @syscap SystemCapability.Web.Webview.Core
306  * @since 12
307  */
308 int32_t OH_ArkWebRequestHeaderList_GetSize(const ArkWeb_RequestHeaderList* requestHeaderList);
309 
310 /**
311  * @brief Get the specified request header.
312  * @param requestHeaderList The list of request header.
313  * @param index The index of request header.
314  * @param key The header key. Caller must release the string by OH_ArkWeb_ReleaseString.
315  * @param value The header value. Caller must release the string by OH_ArkWeb_ReleaseString.
316  *
317  * @syscap SystemCapability.Web.Webview.Core
318  * @since 12
319  */
320 void OH_ArkWebRequestHeaderList_GetHeader(const ArkWeb_RequestHeaderList* requestHeaderList,
321                                           int32_t index,
322                                           char** key,
323                                           char** value);
324 
325 /**
326  * @brief Set a user data to ArkWeb_ResourceRequest.
327  * @param resourceRequest The ArkWeb_ResourceRequest.
328  * @param userData The user data to set.
329  * @return {@link ARKWEB_NET_OK} 0 - Success.
330  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
331  *
332  * @syscap SystemCapability.Web.Webview.Core
333  * @since 12
334  */
335 int32_t OH_ArkWebResourceRequest_SetUserData(ArkWeb_ResourceRequest* resourceRequest, void* userData);
336 
337 /**
338  * @brief Get the user data from ArkWeb_ResourceRequest.
339  * @param resourceRequest The ArkWeb_ResourceRequest.
340  * @return The set user data.
341  *
342  * @syscap SystemCapability.Web.Webview.Core
343  * @since 12
344  */
345 void* OH_ArkWebResourceRequest_GetUserData(const ArkWeb_ResourceRequest* resourceRequest);
346 
347 /**
348  * @brief Get the method of request.
349  * @param resourceRequest The ArkWeb_ResourceRequest.
350  * @param method The request's http method. This function will allocate memory for the method string and caller must
351  *               release the string by OH_ArkWeb_ReleaseString.
352  *
353  * @syscap SystemCapability.Web.Webview.Core
354  * @since 12
355  */
356 void OH_ArkWebResourceRequest_GetMethod(const ArkWeb_ResourceRequest* resourceRequest, char** method);
357 
358 /**
359  * @brief Get the url of request.
360  * @param resourceRequest The ArkWeb_ResourceRequest.
361  * @param url The request's url. This function will allocate memory for the url string and caller must release the
362  *            string by OH_ArkWeb_ReleaseString.
363  *
364  * @syscap SystemCapability.Web.Webview.Core
365  * @since 12
366  */
367 void OH_ArkWebResourceRequest_GetUrl(const ArkWeb_ResourceRequest* resourceRequest, char** url);
368 
369 /**
370  * @brief Create a ArkWeb_HttpBodyStream which used to read the http body.
371  * @param resourceRequest The ArkWeb_ResourceRequest.
372  * @param httpBodyStream The request's http body. This function will allocate memory for the http body stream and
373  *                       caller must release the httpBodyStream by OH_ArkWebResourceRequest_DestroyHttpBodyStream.
374  *
375  * @syscap SystemCapability.Web.Webview.Core
376  * @since 12
377  */
378 void OH_ArkWebResourceRequest_GetHttpBodyStream(const ArkWeb_ResourceRequest* resourceRequest,
379                                                 ArkWeb_HttpBodyStream** httpBodyStream);
380 
381 /**
382  * @brief Destroy the http body stream.
383  * @param httpBodyStream The httpBodyStream to be destroyed.
384  *
385  * @syscap SystemCapability.Web.Webview.Core
386  * @since 12
387  */
388 void OH_ArkWebResourceRequest_DestroyHttpBodyStream(ArkWeb_HttpBodyStream* httpBodyStream);
389 
390 /**
391  * @brief Get the resource type of request.
392  * @param resourceRequest The ArkWeb_ResourceRequest.
393  * @return The resource type of request. -1 if resourceRequest is invalid.
394  *
395  * @syscap SystemCapability.Web.Webview.Core
396  * @since 12
397  */
398 int32_t OH_ArkWebResourceRequest_GetResourceType(const ArkWeb_ResourceRequest* resourceRequest);
399 
400 /**
401  * @brief Get the url of frame which trigger this request.
402  * @param resourceRequest The ArkWeb_ResourceRequest.
403  * @param frameUrl The url of frame which trigger this request. This function will allocate memory for the url string
404  *            and caller must release the string by OH_ArkWeb_ReleaseString.
405  *
406  * @syscap SystemCapability.Web.Webview.Core
407  * @since 12
408  */
409 void OH_ArkWebResourceRequest_GetFrameUrl(const ArkWeb_ResourceRequest* resourceRequest, char** frameUrl);
410 
411 /**
412  * @brief Set a user data to ArkWeb_HttpBodyStream.
413  * @param httpBodyStream The ArkWeb_HttpBodyStream.
414  * @param userData The user data to set.
415  * @return {@link ARKWEB_NET_OK} 0 - Success.
416  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
417  *
418  * @syscap SystemCapability.Web.Webview.Core
419  * @since 12
420  */
421 int32_t OH_ArkWebHttpBodyStream_SetUserData(ArkWeb_HttpBodyStream* httpBodyStream, void* userData);
422 
423 /**
424  * @brief Get the user data from ArkWeb_HttpBodyStream.
425  * @param httpBodyStream The ArkWeb_HttpBodyStream.
426  * @return The set user data.
427  *
428  * @syscap SystemCapability.Web.Webview.Core
429  * @since 12
430  */
431 void* OH_ArkWebHttpBodyStream_GetUserData(const ArkWeb_HttpBodyStream* httpBodyStream);
432 
433 /**
434  * @brief Set the callback for OH_ArkWebHttpBodyStream_Read.
435  *
436  * The result of OH_ArkWebHttpBodyStream_Read will be notified to caller through the readCallback.\n
437  * The callback will run in the same thread as OH_ArkWebHttpBodyStream_Read.\n
438  *
439  * @param httpBodyStream The ArkWeb_HttpBodyStream.
440  * @param readCallback The callback of read function.
441  * @return {@link ARKWEB_NET_OK} 0 - Success.
442  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
443  *
444  * @syscap SystemCapability.Web.Webview.Core
445  * @since 12
446  */
447 int32_t OH_ArkWebHttpBodyStream_SetReadCallback(ArkWeb_HttpBodyStream* httpBodyStream,
448                                                 ArkWeb_HttpBodyStreamReadCallback readCallback);
449 
450 /**
451  * @brief Set the callback for OH_ArkWebHttpBodyStream_AsyncRead.
452  *
453  * The result of OH_ArkWebHttpBodyStream_AsyncRead will be notified to caller through the\n
454  * readCallback. The callback will runs in the ArkWeb worker thread.\n
455  *
456  * @param httpBodyStream The ArkWeb_HttpBodyStream.
457  * @param readCallback The callback of read function.
458  * @return {@link ARKWEB_NET_OK} 0 - Success.
459  * {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
460  *
461  * @since 20
462  */
463 int32_t OH_ArkWebHttpBodyStream_SetAsyncReadCallback(ArkWeb_HttpBodyStream *httpBodyStream,
464                                                      ArkWeb_HttpBodyStreamAsyncReadCallback readCallback);
465 
466 /**
467  * @brief Init the http body stream.
468  *
469  * This function must be called before calling any other functions.\n
470  *
471  * @param httpBodyStream The ArkWeb_HttpBodyStream.
472  * @param initCallback The callback of init.
473  * @return {@link ARKWEB_NET_OK} 0 - Success.
474  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
475  *
476  * @syscap SystemCapability.Web.Webview.Core
477  * @since 12
478  */
479 int32_t OH_ArkWebHttpBodyStream_Init(ArkWeb_HttpBodyStream* httpBodyStream,
480                                      ArkWeb_HttpBodyStreamInitCallback initCallback);
481 
482 /**
483  * @brief Read the http body to the buffer.
484  *
485  * The buffer must be larger than the bufLen. We will be reading data from a worker thread to the buffer,\n
486  * so should not use the buffer in other threads before the callback to avoid concurrency issues.\n
487  *
488  * @param httpBodyStream The ArkWeb_HttpBodyStream.
489  * @param buffer The buffer to receive data.
490  * @param bufLen The size of bytes to read.
491  *
492  * @syscap SystemCapability.Web.Webview.Core
493  * @since 12
494  */
495 void OH_ArkWebHttpBodyStream_Read(const ArkWeb_HttpBodyStream* httpBodyStream, uint8_t* buffer, int bufLen);
496 
497 /**
498  * @brief Read the http body to the buffer.
499  *
500  * The buffer must be larger than the bufLen. We will read data from a worker thread to the buffer,\n
501  * so should not use the buffer in other threads before the callback to avoid concurrency issues.\n
502  *
503  * @param httpBodyStream The ArkWeb_HttpBodyStream.
504  * @param buffer The buffer to receive data.
505  * @param bufLen The size of bytes to read.
506  *
507  * @since 20
508  */
509 void OH_ArkWebHttpBodyStream_AsyncRead(const ArkWeb_HttpBodyStream *httpBodyStream, uint8_t *buffer, int bufLen);
510 
511 /**
512  * @brief Get the total size of the data stream.
513  *
514  * When data is chunked or httpBodyStream is invalid, always return zero.\n
515  *
516  * @param httpBodyStream The ArkWeb_HttpBodyStream.
517  * @return The size of data stream.
518  *
519  * @syscap SystemCapability.Web.Webview.Core
520  * @since 12
521  */
522 uint64_t OH_ArkWebHttpBodyStream_GetSize(const ArkWeb_HttpBodyStream* httpBodyStream);
523 
524 /**
525  * @brief Get the current position of the data stream.
526  * @param httpBodyStream The ArkWeb_HttpBodyStream.
527  * @return The current position of data stream. 0 if httpBodyStream is invalid.
528  *
529  * @syscap SystemCapability.Web.Webview.Core
530  * @since 12
531  */
532 uint64_t OH_ArkWebHttpBodyStream_GetPosition(const ArkWeb_HttpBodyStream* httpBodyStream);
533 
534 /**
535  * @brief Get if the data stream is chunked.
536  * @param httpBodyStream The ArkWeb_HttpBodyStream.
537  * @return True if is chunked; false otherwise.
538  *
539  * @syscap SystemCapability.Web.Webview.Core
540  * @since 12
541  */
542 bool OH_ArkWebHttpBodyStream_IsChunked(const ArkWeb_HttpBodyStream* httpBodyStream);
543 
544 
545 /**
546  * @brief Returns true if all data has been consumed from this upload data stream.
547  *
548  * For chunked uploads, returns false until the first read attempt.\n
549  *
550  * @param httpBodyStream The ArkWeb_HttpBodyStream.
551  * @return True if all data has been consumed; false otherwise.
552  *
553  * @syscap SystemCapability.Web.Webview.Core
554  * @since 12
555  */
556 bool OH_ArkWebHttpBodyStream_IsEof(const ArkWeb_HttpBodyStream* httpBodyStream);
557 
558 /**
559  * @brief Returns true if the upload data in the stream is entirely in memory,
560  *        and all read requests will succeed synchronously.
561  *
562  * Expected to return false for chunked requests.\n
563  *
564  * @param httpBodyStream The ArkWeb_HttpBodyStream.
565  * @return True if the upload data is in memory; false otherwise.
566  *
567  * @syscap SystemCapability.Web.Webview.Core
568  * @since 12
569  */
570 bool OH_ArkWebHttpBodyStream_IsInMemory(const ArkWeb_HttpBodyStream* httpBodyStream);
571 
572 /**
573  * @brief Destroy the ArkWeb_ResourceRequest.
574  * @param resourceRequest The ArkWeb_ResourceRequest.
575  * @return {@link ARKWEB_NET_OK} 0 - Success.
576  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
577  *
578  * @syscap SystemCapability.Web.Webview.Core
579  * @since 12
580  */
581 int32_t OH_ArkWebResourceRequest_Destroy(const ArkWeb_ResourceRequest* resourceRequest);
582 
583 /**
584  * @brief Get the referrer of request.
585  * @param resourceRequest The ArkWeb_ResourceRequest.
586  * @param referrer The request's referrer. This function will allocate memory for the post data string and caller
587  *                 must release the string by OH_ArkWeb_ReleaseString.
588  *
589  * @syscap SystemCapability.Web.Webview.Core
590  * @since 12
591  */
592 void OH_ArkWebResourceRequest_GetReferrer(const ArkWeb_ResourceRequest* resourceRequest, char** referrer);
593 
594 /**
595  * @brief Get the OH_ArkWeb_RequestHeaderList of the request.
596  * @param resourceRequest The ArkWeb_ResourceRequest.
597  * @param requestHeaderList The RequestHeaderList of request.
598  *
599  * @syscap SystemCapability.Web.Webview.Core
600  * @since 12
601  */
602 void OH_ArkWebResourceRequest_GetRequestHeaders(const ArkWeb_ResourceRequest* resourceRequest,
603                                                 ArkWeb_RequestHeaderList** requestHeaderList);
604 
605 /**
606  * @brief Get if this is a redirect request.
607  * @param resourceRequest The ArkWeb_ResourceRequest.
608  * @return True if this is a redirect; false otherwise.
609  *
610  * @syscap SystemCapability.Web.Webview.Core
611  * @since 12
612  */
613 bool OH_ArkWebResourceRequest_IsRedirect(const ArkWeb_ResourceRequest* resourceRequest);
614 
615 /**
616  * @brief Get if this is a request from main frame.
617  * @param resourceRequest The ArkWeb_ResourceRequest.
618  * @return True if this is from main frame; false otherwise.
619  *
620  * @syscap SystemCapability.Web.Webview.Core
621  * @since 12
622  */
623 bool OH_ArkWebResourceRequest_IsMainFrame(const ArkWeb_ResourceRequest* resourceRequest);
624 
625 /**
626  * @brief Get if this is a request is triggered by user gesutre.
627  * @param resourceRequest The ArkWeb_ResourceRequest.
628  * @return True if this is triggered by user gesture; false otherwise.
629  *
630  * @syscap SystemCapability.Web.Webview.Core
631  * @since 12
632  */
633 bool OH_ArkWebResourceRequest_HasGesture(const ArkWeb_ResourceRequest* resourceRequest);
634 
635 /**
636  * @brief Register custom scheme to the ArkWeb.
637  *
638  * Should not be called for built-in HTTP, HTTPS, FILE, FTP, ABOUT and DATA schemes.\n
639  * This function should be called on main thread.\n
640  *
641  * @param scheme The scheme to regist.
642  * @param option The configuration of the scheme.
643  * @return {@link ARKWEB_NET_OK} 0 - Success.
644  *         {@link ARKWEB_ERROR_UNKNOWN} 17100100 - Unknown error.
645  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
646  *         {@link ARKWEB_SCHEME_REGISTER_FAILED} 17100102 - Register custom schemes should be called
647  *                                                          before create any ArkWeb.
648  *
649  * @syscap SystemCapability.Web.Webview.Core
650  * @since 12
651  */
652 int32_t OH_ArkWeb_RegisterCustomSchemes(const char* scheme, int32_t option);
653 
654 /**
655  * @brief Set a ArkWeb_SchemeHandler for a specific scheme to intercept requests of that scheme type.
656  *
657  * SchemeHandler should be set after the BrowserContext created.\n
658  * Use WebviewController.initializeWebEngine to initialize the BrowserContext without create a ArkWeb.\n
659  *
660  * @param scheme Scheme that need to be intercepted.
661  * @param schemeHandler The SchemeHandler for the scheme. Only requests triggered by ServiceWorker will be notified
662  *                      through this handler.
663  * @return Return true if set SchemeHandler for specific scheme successful, return false otherwise.
664  *
665  * @syscap SystemCapability.Web.Webview.Core
666  * @since 12
667  */
668 bool OH_ArkWebServiceWorker_SetSchemeHandler(const char* scheme, ArkWeb_SchemeHandler* schemeHandler);
669 
670 /**
671  * @brief Set a ArkWeb_SchemeHandler for a specific scheme to intercept requests of that scheme type.
672  *
673  * SchemeHandler should be set after the BrowserContext created.\n
674  * Use WebviewController.initializeWebEngine to initialize the BrowserContext without create a ArkWeb.\n
675  *
676  * @param scheme Scheme that need to be intercepted.
677  * @param webTag The name of the web component.
678  * @param schemeHandler The SchemeHandler for the scheme. Only requests triggered from the specified web will be
679  *                      notified through this handler.
680  * @return Return true if set SchemeHandler for specific scheme successful, return false otherwise.
681  *
682  * @syscap SystemCapability.Web.Webview.Core
683  * @since 12
684  */
685 bool OH_ArkWeb_SetSchemeHandler(const char* scheme, const char* webTag, ArkWeb_SchemeHandler* schemeHandler);
686 
687 /**
688  * @brief Clear the handler registered on the specified web for service worker.
689  * @return {@link ARKWEB_NET_OK} 0 - Success.
690  *
691  * @syscap SystemCapability.Web.Webview.Core
692  * @since 12
693  */
694 int32_t OH_ArkWebServiceWorker_ClearSchemeHandlers();
695 
696 /**
697  * @brief Clear the handler registered on the specified web.
698  * @param webTag The name of the web component.
699  * @return {@link ARKWEB_NET_OK} 0 - Success.
700  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
701  *
702  * @syscap SystemCapability.Web.Webview.Core
703  * @since 12
704  */
705 int32_t OH_ArkWeb_ClearSchemeHandlers(const char* webTag);
706 
707 /**
708  * @brief Create a SchemeHandler.
709  * @param schemeHandler Return the created SchemeHandler. Use OH_ArkWeb_DestroySchemeHandler destroy it when donn't
710  *                      need it.
711  *
712  * @syscap SystemCapability.Web.Webview.Core
713  * @since 12
714  */
715 void OH_ArkWeb_CreateSchemeHandler(ArkWeb_SchemeHandler** schemeHandler);
716 
717 /**
718  * @brief Destroy a SchemeHandler.
719  * @param schemeHandler The ArkWeb_SchemeHandler to be destroy.
720  *
721  * @syscap SystemCapability.Web.Webview.Core
722  * @since 12
723  */
724 void OH_ArkWeb_DestroySchemeHandler(ArkWeb_SchemeHandler* schemeHandler);
725 
726 /**
727  * @brief Set a user data to ArkWeb_SchemeHandler.
728  * @param schemeHandler The ArkWeb_SchemeHandler.
729  * @param userData The user data to set.
730  * @return {@link ARKWEB_NET_OK} 0 - Success.
731  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
732  *
733  * @syscap SystemCapability.Web.Webview.Core
734  * @since 12
735  */
736 int32_t OH_ArkWebSchemeHandler_SetUserData(ArkWeb_SchemeHandler* schemeHandler, void* userData);
737 
738 /**
739  * @brief Get the user data from ArkWeb_SchemeHandler.
740  * @param schemeHandler The ArkWeb_SchemeHandler.
741  * @return The set user data.
742  *
743  * @syscap SystemCapability.Web.Webview.Core
744  * @since 12
745  */
746 void* OH_ArkWebSchemeHandler_GetUserData(const ArkWeb_SchemeHandler* schemeHandler);
747 
748 /**
749  * @brief Set the OnRequestStart callback for SchemeHandler.
750  * @param schemeHandler The SchemeHandler for the scheme.
751  * @param onRequestStart The OnRequestStart callback.
752  * @return {@link ARKWEB_NET_OK} 0 - Success.
753  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
754  *
755  * @syscap SystemCapability.Web.Webview.Core
756  * @since 12
757  */
758 int32_t OH_ArkWebSchemeHandler_SetOnRequestStart(ArkWeb_SchemeHandler* schemeHandler,
759                                                  ArkWeb_OnRequestStart onRequestStart);
760 
761 /**
762  * @brief Set the OnRequestStop callback for SchemeHandler.
763  * @param schemeHandler The SchemeHandler for the scheme.
764  * @param onRequestStop The OnRequestStop callback.
765  * @return {@link ARKWEB_NET_OK} 0 - Success.
766  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
767  *
768  * @syscap SystemCapability.Web.Webview.Core
769  * @since 12
770  */
771 int32_t OH_ArkWebSchemeHandler_SetOnRequestStop(ArkWeb_SchemeHandler* schemeHandler,
772                                                 ArkWeb_OnRequestStop onRequestStop);
773 
774 /**
775  * @brief Create a Response for a request.
776  * @param response The created Response. Use OH_ArkWeb_DestroyResponse to destroy when donn't need it.
777  *
778  * @syscap SystemCapability.Web.Webview.Core
779  * @since 12
780  */
781 void OH_ArkWeb_CreateResponse(ArkWeb_Response** response);
782 
783 /**
784  * @brief Destroy the Reponse.
785  * @param response The Response needs destroy.
786  *
787  * @syscap SystemCapability.Web.Webview.Core
788  * @since 12
789  */
790 void OH_ArkWeb_DestroyResponse(ArkWeb_Response* response);
791 
792 /**
793  * @brief Set the resolved URL after redirects or changed as a result of HSTS.
794  * @param response The ArkWeb_Response.
795  * @param url The resolved URL.
796  * @return {@link ARKWEB_NET_OK} 0 - Success.
797  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
798  *
799  * @syscap SystemCapability.Web.Webview.Core
800  * @since 12
801  */
802 int32_t OH_ArkWebResponse_SetUrl(ArkWeb_Response* response, const char* url);
803 
804 /**
805  * @brief Get the resolved URL after redirects or changed as a result of HSTS.
806  * @param response The ArkWeb_Response.
807  * @param url The resolved URL.
808  *
809  * @syscap SystemCapability.Web.Webview.Core
810  * @since 12
811  */
812 void OH_ArkWebResponse_GetUrl(const ArkWeb_Response* response, char** url);
813 
814 /**
815  * @brief Set a error code to ArkWeb_Response.
816  * @param response The ArkWeb_Response.
817  * @param errorCode The error code for the failed request.
818  * @return {@link ARKWEB_NET_OK} 0 - Success.
819  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
820  *
821  * @syscap SystemCapability.Web.Webview.Core
822  * @since 12
823  */
824 int32_t OH_ArkWebResponse_SetError(ArkWeb_Response* response, ArkWeb_NetError errorCode);
825 
826 /**
827  * @brief Get the response's error code.
828  * @param response The ArkWeb_Response.
829  * @return The response's error code.
830  *
831  * @syscap SystemCapability.Web.Webview.Core
832  * @since 12
833  */
834 ArkWeb_NetError OH_ArkWebResponse_GetError(const ArkWeb_Response* response);
835 
836 /**
837  * @brief Set a status code to ArkWebResponse.
838  * @param response The ArkWeb_Response.
839  * @param status The http status code for the request.
840  * @return {@link ARKWEB_NET_OK} 0 - Success.
841  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
842  *
843  * @syscap SystemCapability.Web.Webview.Core
844  * @since 12
845  */
846 int32_t OH_ArkWebResponse_SetStatus(ArkWeb_Response* response, int status);
847 
848 /**
849  * @brief Get the response's status code.
850  * @param response The ArkWeb_Response.
851  * @return The response's http status code. -1 if response is invalid.
852  *
853  * @syscap SystemCapability.Web.Webview.Core
854  * @since 12
855  */
856 int OH_ArkWebResponse_GetStatus(const ArkWeb_Response* response);
857 
858 /**
859  * @brief Set a status text to ArkWebResponse.
860  * @param response The ArkWeb_Response.
861  * @param statusText The status text for the request.
862  * @return {@link ARKWEB_NET_OK} 0 - Success.
863  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
864  *
865  * @syscap SystemCapability.Web.Webview.Core
866  * @since 12
867  */
868 int32_t OH_ArkWebResponse_SetStatusText(ArkWeb_Response* response, const char* statusText);
869 
870 /**
871  * @brief Get the response's status text.
872  * @param response The ArkWeb_Response.
873  * @param statusText Return the response's statusText. This function will allocate memory for the statusText string and
874  *                   caller must release the string by OH_ArkWeb_ReleaseString.
875  *
876  * @syscap SystemCapability.Web.Webview.Core
877  * @since 12
878  */
879 void OH_ArkWebResponse_GetStatusText(const ArkWeb_Response* response, char** statusText);
880 
881 /**
882  * @brief Set mime type to ArkWebResponse.
883  * @param response The ArkWeb_Response.
884  * @param mimeType The mime type for the request.
885  * @return {@link ARKWEB_NET_OK} 0 - Success.
886  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
887  *
888  * @syscap SystemCapability.Web.Webview.Core
889  * @since 12
890  */
891 int32_t OH_ArkWebResponse_SetMimeType(ArkWeb_Response* response, const char* mimeType);
892 
893 /**
894  * @brief Get the response's mime type.
895  * @param response The ArkWeb_Response.
896  * @param mimeType Return the response's mime type. This function will allocate memory for the mime type string and
897  *                 caller must release the string by OH_ArkWeb_ReleaseString.
898  *
899  * @syscap SystemCapability.Web.Webview.Core
900  * @since 12
901  */
902 void OH_ArkWebResponse_GetMimeType(const ArkWeb_Response* response, char** mimeType);
903 
904 /**
905  * @brief Set charset to ArkWeb_Response.
906  * @param response The ArkWeb_Response.
907  * @param charset The charset for the request.
908  * @return {@link ARKWEB_NET_OK} 0 - Success.
909  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
910  *
911  * @syscap SystemCapability.Web.Webview.Core
912  * @since 12
913  */
914 int32_t OH_ArkWebResponse_SetCharset(ArkWeb_Response* response, const char* charset);
915 
916 /**
917  * @brief Get the response's charset.
918  * @param response The ArkWeb_Response.
919  * @param charset Return the response's charset. This function will allocate memory for the charset string and caller
920  *                must release the string by OH_ArkWeb_ReleaseString.
921  *
922  * @syscap SystemCapability.Web.Webview.Core
923  * @since 12
924  */
925 void OH_ArkWebResponse_GetCharset(const ArkWeb_Response* response, char** charset);
926 
927 /**
928  * @brief Set a header to ArkWeb_Response.
929  * @param response The ArkWeb_Response.
930  * @param name The name of the header.
931  * @param value The value of the header.
932  * @param overwirte If true will overwrite the exsits header, if false otherwise.
933  * @return {@link ARKWEB_NET_OK} 0 - Success.
934  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
935  *
936  * @syscap SystemCapability.Web.Webview.Core
937  * @since 12
938  */
939 int32_t OH_ArkWebResponse_SetHeaderByName(ArkWeb_Response* response,
940                                           const char* name,
941                                           const char* value,
942                                           bool overwrite);
943 
944 /**
945  * @brief Get the header from the response.
946  * @param response The ArkWeb_Response.
947  * @param name The name of the header.
948  * @param value Return the header's value. This function will allocate memory for the value string and caller must
949  *              release the string by OH_ArkWeb_ReleaseString.
950  *
951  * @syscap SystemCapability.Web.Webview.Core
952  * @since 12
953  */
954 void OH_ArkWebResponse_GetHeaderByName(const ArkWeb_Response* response, const char* name, char** value);
955 
956 /**
957  * @brief Destroy the ArkWeb_ResourceHandler.
958  * @param resourceHandler The ArkWeb_ResourceHandler.
959  * @return {@link ARKWEB_NET_OK} 0 - Success.
960  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
961  *
962  * @syscap SystemCapability.Web.Webview.Core
963  * @since 12
964  */
965 int32_t OH_ArkWebResourceHandler_Destroy(const ArkWeb_ResourceHandler* resourceHandler);
966 
967 /**
968  * @brief Pass response headers to intercepted requests.
969  * @param resourceHandler The ArkWeb_ResourceHandler for the request.
970  * @param response The ArkWeb_Response for the intercepting requests.
971  * @return {@link ARKWEB_NET_OK} 0 - Success.
972  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
973  *
974  * @syscap SystemCapability.Web.Webview.Core
975  * @since 12
976  */
977 int32_t OH_ArkWebResourceHandler_DidReceiveResponse(const ArkWeb_ResourceHandler* resourceHandler,
978                                                     const ArkWeb_Response* response);
979 
980 /**
981  * @brief Pass response body data to intercepted requests.
982  * @param resourceHandler The ArkWeb_ResourceHandler for the request.
983  * @param buffer Buffer data to send.
984  * @param bufLen The size of buffer.
985  * @return {@link ARKWEB_NET_OK} 0 - Success.
986  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
987  *
988  * @syscap SystemCapability.Web.Webview.Core
989  * @since 12
990  */
991 int32_t OH_ArkWebResourceHandler_DidReceiveData(const ArkWeb_ResourceHandler* resourceHandler,
992                                                 const uint8_t* buffer,
993                                                 int64_t bufLen);
994 
995 /**
996  * @brief Notify the ArkWeb that this request should be finished and there is no more data available.
997  * @param resourceHandler The ArkWeb_ResourceHandler for the request.
998  * @return {@link ARKWEB_NET_OK} 0 - Success.
999  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
1000  *
1001  * @syscap SystemCapability.Web.Webview.Core
1002  * @since 12
1003  */
1004 int32_t OH_ArkWebResourceHandler_DidFinish(const ArkWeb_ResourceHandler* resourceHandler);
1005 
1006 /**
1007  * @brief Notify the ArkWeb that this request should be failed.
1008  * @param resourceHandler The ArkWeb_ResourceHandler for the request.
1009  * @param errorCode The error code for this request. Refer to arkweb_net_error_list.h.
1010  * @return {@link ARKWEB_NET_OK} 0 - Success.
1011  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param.
1012  *
1013  * @syscap SystemCapability.Web.Webview.Core
1014  * @since 12
1015  */
1016 int32_t OH_ArkWebResourceHandler_DidFailWithError(const ArkWeb_ResourceHandler* resourceHandler,
1017                                                   ArkWeb_NetError errorCode);
1018 
1019 /**
1020  * @brief Notify the ArkWeb that this request should be failed.
1021  * @param resourceHandler The ArkWeb_ResourceHandler for the request.
1022  * @param errorCode The error code for this request. Refer to arkweb_net_error_list.h.
1023  * @param completeIfNoResponse If completeIfNoResponse is true, when DidFailWithErrorV2 is called,
1024  *        if DidReceiveResponse has not been called,
1025  *        a response is automatically constructed and the current request is terminated.
1026  * @return {@link ARKWEB_NET_OK} 0 - Success.
1027  *         {@link ARKWEB_INVALID_PARAM} 17100101 - Invalid param, the resourceHandler is nullptr.
1028  * @since 20
1029  */
1030 int32_t OH_ArkWebResourceHandler_DidFailWithErrorV2(const ArkWeb_ResourceHandler* resourceHandler,
1031                                                     ArkWeb_NetError errorCode,
1032                                                     bool completeIfNoResponse);
1033 
1034 /**
1035  * @brief Release the string acquired by native function.
1036  * @param string The string to be released.
1037  *
1038  * @syscap SystemCapability.Web.Webview.Core
1039  * @since 12
1040  */
1041 void OH_ArkWeb_ReleaseString(char* string);
1042 
1043 /**
1044  * @brief Release the byte array acquired by native function.
1045  * @param byteArray The byte array to be released.
1046  *
1047  * @syscap SystemCapability.Web.Webview.Core
1048  * @since 12
1049  */
1050 void OH_ArkWeb_ReleaseByteArray(uint8_t* byteArray);
1051 
1052 
1053 #ifdef __cplusplus
1054 };
1055 #endif
1056 #endif // ARKWEB_SCHEME_HANDLER_H
1057 /** @} */
1058