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