10826e83eSopenharmony_ci/*
20826e83eSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
30826e83eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40826e83eSopenharmony_ci * you may not use this file except in compliance with the License.
50826e83eSopenharmony_ci * You may obtain a copy of the License at
60826e83eSopenharmony_ci *
70826e83eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
80826e83eSopenharmony_ci *
90826e83eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100826e83eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110826e83eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120826e83eSopenharmony_ci * See the License for the specific language governing permissions and
130826e83eSopenharmony_ci * limitations under the License.
140826e83eSopenharmony_ci */
150826e83eSopenharmony_ci
160826e83eSopenharmony_ci#ifndef WEBVIEW_FFI_H
170826e83eSopenharmony_ci#define WEBVIEW_FFI_H
180826e83eSopenharmony_ci
190826e83eSopenharmony_ci#include <cstdint>
200826e83eSopenharmony_ci#include "ffi_remote_data.h"
210826e83eSopenharmony_ci#include "webview_utils.h"
220826e83eSopenharmony_ci#include "cj_common_ffi.h"
230826e83eSopenharmony_ci
240826e83eSopenharmony_ciextern "C" {
250826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewOnce(char* type, void (*callbackRef)(void));
260826e83eSopenharmony_ci
270826e83eSopenharmony_ci    // WebMessagePortImpl
280826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiOHOSWebviewCtlConstructor();
290826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiOHOSWebviewCtlConstructorWithWebTag(char *webTag);
300826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSWebviewCtlInitializeWebEngine();
310826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSWebviewCtlSetHttpDns(int32_t secureDnsMode, char* secureDnsConfig);
320826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSWebviewCtlSetWebDebuggingAccess(bool webDebuggingAccess);
330826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlLoadUrl(int64_t id, char *url);
340826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlLoadUrlWithHeaders(int64_t id, char *url, OHOS::Webview::ArrWebHeader headers);
350826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlLoadData(int64_t id, OHOS::Webview::LoadDatas loadDatas);
360826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlRefresh(int64_t id);
370826e83eSopenharmony_ci    FFI_EXPORT int32_t FFiOHOSWebviewCtlPreFetchPage(int64_t id, char* url);
380826e83eSopenharmony_ci    FFI_EXPORT int32_t FFiOHOSWebviewCtlPreFetchPageWithHeaders(int64_t id, char* url,
390826e83eSopenharmony_ci        OHOS::Webview::ArrWebHeader headers);
400826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlSetAudioMuted(int64_t id, bool mute);
410826e83eSopenharmony_ci    FFI_EXPORT char *FfiOHOSWebviewCtlGetUserAgent(int64_t id, int32_t *errCode);
420826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlSetConnectionTimeout(int32_t timeout);
430826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlGetWebId(int64_t id, int32_t *errCode);
440826e83eSopenharmony_ci    FFI_EXPORT bool FfiOHOSWebviewCtlAccessForward(int64_t id, int32_t *errCode);
450826e83eSopenharmony_ci    FFI_EXPORT bool FfiOHOSWebviewCtlAccessBackward(int64_t id, int32_t *errCode);
460826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlSetCustomUserAgent(int64_t id, char *cUserAgent);
470826e83eSopenharmony_ci    FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetCustomUserAgent(int64_t id);
480826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlRunJavaScript(int64_t id, char* cScript,
490826e83eSopenharmony_ci        void (*callbackRef)(RetDataCString infoRef));
500826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlRunJavaScriptExt(int64_t id, char* cScript,
510826e83eSopenharmony_ci        void (*callbackRef)(RetDataI64));
520826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlRunJavaScriptExtArr(int64_t id, CArrUI8 cScript,
530826e83eSopenharmony_ci        void (*callbackRef)(RetDataI64));
540826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlRegisterJavaScriptProxy(int64_t id,
550826e83eSopenharmony_ci        CArrI64 cFuncIds,  const char* cName, CArrString cMethodList);
560826e83eSopenharmony_ci    FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetUrl(int64_t id);
570826e83eSopenharmony_ci    FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetOriginalUrl(int64_t id);
580826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlPageUp(int64_t id, bool top);
590826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlPageDown(int64_t id, bool bottom);
600826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlScrollTo(int64_t id, float x, float y);
610826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlScrollBy(int64_t id, float deltaX, float deltaY);
620826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlScrollToWithAnime(int64_t id, float x, float y, int32_t duration);
630826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlScrollByWithAnime(int64_t id, float deltaX, float deltaY, int32_t duration);
640826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlForward(int64_t id);
650826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlBackward(int64_t id);
660826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlBackOrForward(int64_t id, int32_t step);
670826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlGetPageHeight(int64_t id, int32_t *errCode);
680826e83eSopenharmony_ci    FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetTitle(int64_t id);
690826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlZoom(int64_t id, float factor);
700826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlZoomIn(int64_t id);
710826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlZoomOut(int64_t id);
720826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlRequestFocus(int64_t id);
730826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlClearHistory(int64_t id);
740826e83eSopenharmony_ci    FFI_EXPORT bool FfiOHOSWebviewCtlAccessStep(int64_t id, int32_t *errCode, int32_t step);
750826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlOnActive(int64_t id);
760826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlOnInactive(int64_t id);
770826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlGetHitTest(int64_t id, int32_t *errCode);
780826e83eSopenharmony_ci    FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetHitTestValue(int64_t id, int32_t *errCode);
790826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlStoreWebArchive(int64_t id, const char* cBaseName,
800826e83eSopenharmony_ci        bool autoName, void (*callbackRef)(RetDataCString infoRef));
810826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlEnableSafeBrowsing(int64_t id, bool enable);
820826e83eSopenharmony_ci    FFI_EXPORT bool FfiOHOSWebviewCtlIsSafeBrowsingEnabled(int64_t id, int32_t *errCode);
830826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlGetSecurityLevel(int64_t id, int32_t *errCode);
840826e83eSopenharmony_ci    FFI_EXPORT bool FfiOHOSWebviewCtlIsIncognitoMode(int64_t id, int32_t *errCode);
850826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlRemoveCache(int64_t id, bool clearRom);
860826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiOHOSWebviewCtlGetBackForwardEntries(int64_t id, int32_t *errCode);
870826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlStop(int64_t id);
880826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiOHOSWebviewCtlGetFavicon(int64_t id, int32_t *errCode);
890826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlPrepareForPageLoad(char *url, bool preconnectable, int32_t numSockets);
900826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlSlideScroll(int64_t id, float vx, float vy);
910826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlSetNetworkAvailable(int64_t id, bool enable);
920826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlClearClientAuthenticationCache(int64_t id);
930826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlClearSslChache(int64_t id);
940826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlSearchNext(int64_t id, bool forward);
950826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlClearMatches(int64_t id);
960826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlSearchAllAsync(int64_t id, char *searchString);
970826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlDeleteJavaScriptRegister(int64_t id, char *name);
980826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlPostUrl(int64_t id, char *url, CArrUI8 buffer);
990826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlSetDownloadDelegate(int64_t id, int64_t delegateId);
1000826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlStartDownload(int64_t id, char *url);
1010826e83eSopenharmony_ci    FFI_EXPORT CArrI64 FfiOHOSWebviewCtlCreateWebMessagePorts(int64_t id, bool isExtentionType, int32_t *errCode);
1020826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlPostMessage(int64_t id, char* name, CArrI64 ports, char* uri);
1030826e83eSopenharmony_ci    FFI_EXPORT CArrUI8 FfiOHOSWebviewCtlSerializeWebState(int64_t id, int32_t *errCode);
1040826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlRestoreWebState(int64_t id, CArrUI8 cState);
1050826e83eSopenharmony_ci    FFI_EXPORT CArrString FfiOHOSWebviewCtlGetCertificate(int64_t id, int32_t *errCode);
1060826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebviewCtlHasImage(int64_t id, void (*callbackRef)(RetDataBool));
1070826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiWebviewCtlCustomizeSchemes(OHOS::Webview::CArrScheme schemes);
1080826e83eSopenharmony_ci
1090826e83eSopenharmony_ci    // BackForwardList
1100826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSBackForwardListCurrentIndex(int64_t id, int32_t *errCode);
1110826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSBackForwardListSize(int64_t id, int32_t *errCode);
1120826e83eSopenharmony_ci    FFI_EXPORT OHOS::Webview::CHistoryItem FfiOHOSGetItemAtIndex(int64_t id, int32_t index, int32_t *errCode);
1130826e83eSopenharmony_ci
1140826e83eSopenharmony_ci    // cookie_manager
1150826e83eSopenharmony_ci    FFI_EXPORT const char* FfiOHOSCookieMgrFetchCookieSync(const char *url, bool incognitoMode, int32_t* errCode);
1160826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSCookieMgrConfigCookieSync(const char* url, const char* value, bool incognitoMode);
1170826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSCookieMgrPutAcceptCookieEnabled(bool accept);
1180826e83eSopenharmony_ci    FFI_EXPORT bool FfiOHOSCookieMgrIsCookieAllowed();
1190826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSCookieMgrPutAcceptThirdPartyCookieEnabled(bool accept);
1200826e83eSopenharmony_ci    FFI_EXPORT bool FfiOHOSCookieMgrIsThirdPartyCookieAllowed();
1210826e83eSopenharmony_ci    FFI_EXPORT bool FfiOHOSCookieMgrExistCookie(bool incognitoMode);
1220826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSCookieMgrClearAllCookiesSync(bool incognitoMode);
1230826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSCookieMgrClearSessionCookieSync();
1240826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSCookieMgrSaveCookieAsync(void (*callbackRef)(void));
1250826e83eSopenharmony_ci
1260826e83eSopenharmony_ci    // data_base
1270826e83eSopenharmony_ci    FFI_EXPORT RetDataCArrString FfiOHOSDBGetHttpAuthCredentials(const char *host,
1280826e83eSopenharmony_ci        const char *realm);
1290826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSDBSaveHttpAuthCredentials(const char *host, const char *realm,
1300826e83eSopenharmony_ci        const char *username, const char *password);
1310826e83eSopenharmony_ci    FFI_EXPORT bool FfiOHOSDBExistHttpAuthCredentials();
1320826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSDBDeleteHttpAuthCredentials();
1330826e83eSopenharmony_ci
1340826e83eSopenharmony_ci    // WebDownloadItemImpl
1350826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiOHOSWebDownloadItemImplConstructor();
1360826e83eSopenharmony_ci    FFI_EXPORT RetDataCString FfiOHOSWebDownloadItemImplGetGuid(int64_t id);
1370826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiOHOSWebDownloadItemImplGetCurrentSpeed(int64_t id, int32_t *errCode);
1380826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiOHOSWebDownloadItemImplGetPercentComplete(int64_t id, int32_t *errCode);
1390826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiOHOSWebDownloadItemImplGetTotalBytes(int64_t id, int32_t *errCode);
1400826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiOHOSWebDownloadItemImplGetReceivedBytes(int64_t id, int32_t *errCode);
1410826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebDownloadItemImplGetState(int64_t id, int32_t *errCode);
1420826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebDownloadItemImplGetLastErrorCode(int64_t id, int32_t *errCode);
1430826e83eSopenharmony_ci    FFI_EXPORT RetDataCString FfiOHOSWebDownloadItemImplGetMethod(int64_t id);
1440826e83eSopenharmony_ci    FFI_EXPORT RetDataCString FfiOHOSWebDownloadItemImplGetMimeType(int64_t id);
1450826e83eSopenharmony_ci    FFI_EXPORT RetDataCString FfiOHOSWebDownloadItemImplGetUrl(int64_t id);
1460826e83eSopenharmony_ci    FFI_EXPORT RetDataCString FfiOHOSWebDownloadItemImplGetSuggestedFileName(int64_t id);
1470826e83eSopenharmony_ci    FFI_EXPORT RetDataCString FfiOHOSWebDownloadItemImplGetFullPath(int64_t id);
1480826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebDownloadItemImplStart(int64_t id, char *downloadPath);
1490826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebDownloadItemImplCancel(int64_t id);
1500826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebDownloadItemImplPause(int64_t id);
1510826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebDownloadItemImplResume(int64_t id);
1520826e83eSopenharmony_ci    FFI_EXPORT CArrUI8 FfiOHOSWebDownloadItemImplSerialize(int64_t id, int32_t *errCode);
1530826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiOHOSWebDownloadItemImplDeserialize(CArrUI8 serializedData, int32_t *errCode);
1540826e83eSopenharmony_ci
1550826e83eSopenharmony_ci    // WebDownloadDelegateImpl
1560826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiOHOSWebDownloadDelegateImplConstructor();
1570826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSWebDownloadDelegateImplOnBeforeDownload(int64_t id, void (*callback)(int64_t));
1580826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSWebDownloadDelegateImplOnDownloadUpdated(int64_t id, void (*callback)(int64_t));
1590826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSWebDownloadDelegateImplOnDownloadFinish(int64_t id, void (*callback)(int64_t));
1600826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSWebDownloadDelegateImplOnDownloadFailed(int64_t id, void (*callback)(int64_t));
1610826e83eSopenharmony_ci
1620826e83eSopenharmony_ci    // WebDownloadManagerImpl
1630826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSWebDownloadManagerImplSetDownloadDelegate(int64_t delegateId);
1640826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiOHOSWebDownloadManagerImplResumeDownload(int64_t itemId);
1650826e83eSopenharmony_ci
1660826e83eSopenharmony_ci    // GeolocationPermissions
1670826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSGeolocationAllowGeolocation(char* origin, bool incognito, int32_t *errCode);
1680826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSGeolocationDeleteGeolocation(char* origin, bool incognito, int32_t *errCode);
1690826e83eSopenharmony_ci    FFI_EXPORT bool FfiOHOSGeolocationGetAccessibleGeolocation(char* origin, bool incognito, int32_t *errCode);
1700826e83eSopenharmony_ci    FFI_EXPORT CArrString FfiOHOSGeolocationGetStoredGeolocation(bool incognito, int32_t *errCode);
1710826e83eSopenharmony_ci    FFI_EXPORT void FfiOHOSGeolocationDeleteAllGeolocation(bool incognito, int32_t *errCode);
1720826e83eSopenharmony_ci
1730826e83eSopenharmony_ci    // web_storage
1740826e83eSopenharmony_ci    FFI_EXPORT int32_t FfiWebStorageDeleteOrigin(char* corigin);
1750826e83eSopenharmony_ci    FFI_EXPORT void FfiWebStorageDeleteAllData(bool incognito = false);
1760826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiWebStorageGetOriginQuota(char* corigin, int32_t *errCode);
1770826e83eSopenharmony_ci    FFI_EXPORT int64_t FfiWebStorageGetOriginUsage(char* corigin, int32_t *errCode);
1780826e83eSopenharmony_ci    FFI_EXPORT OHOS::Webview::CArrWebStorageOrigin FfiWebStorageGetOrigins(int32_t *errCode);
1790826e83eSopenharmony_ci}
1800826e83eSopenharmony_ci
1810826e83eSopenharmony_ci#endif // WEBVIEW_FFI_H