1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef WEBVIEW_FFI_H 17 #define WEBVIEW_FFI_H 18 19 #include <cstdint> 20 21 #include "cj_common_ffi.h" 22 #include "ffi_remote_data.h" 23 #include "webview_utils.h" 24 25 extern "C" { 26 FFI_EXPORT int32_t FfiOHOSWebviewOnce(char* type, void (*callbackRef)(void)); 27 28 // WebMessagePortImpl 29 FFI_EXPORT int64_t FfiOHOSWebviewCtlConstructor(); 30 FFI_EXPORT int64_t FfiOHOSWebviewCtlConstructorWithWebTag(char* webTag); 31 FFI_EXPORT void FfiOHOSWebviewCtlInitializeWebEngine(); 32 FFI_EXPORT void FfiOHOSWebviewCtlSetHttpDns(int32_t secureDnsMode, char* secureDnsConfig); 33 FFI_EXPORT void FfiOHOSWebviewCtlSetWebDebuggingAccess(bool webDebuggingAccess); 34 FFI_EXPORT int32_t FfiOHOSWebviewCtlLoadUrl(int64_t id, char* url); 35 FFI_EXPORT int32_t FfiOHOSWebviewCtlLoadUrlWithHeaders(int64_t id, char* url, OHOS::Webview::ArrWebHeader headers); 36 FFI_EXPORT int32_t FfiOHOSWebviewCtlLoadData(int64_t id, OHOS::Webview::LoadDatas loadDatas); 37 FFI_EXPORT int32_t FfiOHOSWebviewCtlRefresh(int64_t id); 38 FFI_EXPORT int32_t FFiOHOSWebviewCtlPreFetchPage(int64_t id, char* url); 39 FFI_EXPORT int32_t FFiOHOSWebviewCtlPreFetchPageWithHeaders( 40 int64_t id, char* url, OHOS::Webview::ArrWebHeader headers); 41 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetAudioMuted(int64_t id, bool mute); 42 FFI_EXPORT char* FfiOHOSWebviewCtlGetUserAgent(int64_t id, int32_t* errCode); 43 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetConnectionTimeout(int32_t timeout); 44 FFI_EXPORT int32_t FfiOHOSWebviewCtlGetWebId(int64_t id, int32_t* errCode); 45 FFI_EXPORT bool FfiOHOSWebviewCtlAccessForward(int64_t id, int32_t* errCode); 46 FFI_EXPORT bool FfiOHOSWebviewCtlAccessBackward(int64_t id, int32_t* errCode); 47 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetCustomUserAgent(int64_t id, char* cUserAgent); 48 FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetCustomUserAgent(int64_t id); 49 FFI_EXPORT int32_t FfiOHOSWebviewCtlRunJavaScript( 50 int64_t id, char* cScript, void (*callbackRef)(RetDataCString infoRef)); 51 FFI_EXPORT int32_t FfiOHOSWebviewCtlRunJavaScriptExt(int64_t id, char* cScript, void (*callbackRef)(RetDataI64)); 52 FFI_EXPORT int32_t FfiOHOSWebviewCtlRunJavaScriptExtArr( 53 int64_t id, CArrUI8 cScript, void (*callbackRef)(RetDataI64)); 54 FFI_EXPORT int32_t FfiOHOSWebviewCtlRegisterJavaScriptProxy( 55 int64_t id, CArrI64 cFuncIds, const char* cName, CArrString cMethodList); 56 FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetUrl(int64_t id); 57 FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetOriginalUrl(int64_t id); 58 FFI_EXPORT int32_t FfiOHOSWebviewCtlPageUp(int64_t id, bool top); 59 FFI_EXPORT int32_t FfiOHOSWebviewCtlPageDown(int64_t id, bool bottom); 60 FFI_EXPORT int32_t FfiOHOSWebviewCtlScrollTo(int64_t id, float x, float y); 61 FFI_EXPORT int32_t FfiOHOSWebviewCtlScrollBy(int64_t id, float deltaX, float deltaY); 62 FFI_EXPORT int32_t FfiOHOSWebviewCtlScrollToWithAnime(int64_t id, float x, float y, int32_t duration); 63 FFI_EXPORT int32_t FfiOHOSWebviewCtlScrollByWithAnime(int64_t id, float deltaX, float deltaY, int32_t duration); 64 FFI_EXPORT int32_t FfiOHOSWebviewCtlForward(int64_t id); 65 FFI_EXPORT int32_t FfiOHOSWebviewCtlBackward(int64_t id); 66 FFI_EXPORT int32_t FfiOHOSWebviewCtlBackOrForward(int64_t id, int32_t step); 67 FFI_EXPORT int32_t FfiOHOSWebviewCtlGetPageHeight(int64_t id, int32_t* errCode); 68 FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetTitle(int64_t id); 69 FFI_EXPORT int32_t FfiOHOSWebviewCtlZoom(int64_t id, float factor); 70 FFI_EXPORT int32_t FfiOHOSWebviewCtlZoomIn(int64_t id); 71 FFI_EXPORT int32_t FfiOHOSWebviewCtlZoomOut(int64_t id); 72 FFI_EXPORT int32_t FfiOHOSWebviewCtlRequestFocus(int64_t id); 73 FFI_EXPORT int32_t FfiOHOSWebviewCtlClearHistory(int64_t id); 74 FFI_EXPORT bool FfiOHOSWebviewCtlAccessStep(int64_t id, int32_t* errCode, int32_t step); 75 FFI_EXPORT int32_t FfiOHOSWebviewCtlOnActive(int64_t id); 76 FFI_EXPORT int32_t FfiOHOSWebviewCtlOnInactive(int64_t id); 77 FFI_EXPORT int32_t FfiOHOSWebviewCtlGetHitTest(int64_t id, int32_t* errCode); 78 FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetHitTestValue(int64_t id, int32_t* errCode); 79 FFI_EXPORT int32_t FfiOHOSWebviewCtlStoreWebArchive( 80 int64_t id, const char* cBaseName, bool autoName, void (*callbackRef)(RetDataCString infoRef)); 81 FFI_EXPORT int32_t FfiOHOSWebviewCtlEnableSafeBrowsing(int64_t id, bool enable); 82 FFI_EXPORT bool FfiOHOSWebviewCtlIsSafeBrowsingEnabled(int64_t id, int32_t* errCode); 83 FFI_EXPORT int32_t FfiOHOSWebviewCtlGetSecurityLevel(int64_t id, int32_t* errCode); 84 FFI_EXPORT bool FfiOHOSWebviewCtlIsIncognitoMode(int64_t id, int32_t* errCode); 85 FFI_EXPORT int32_t FfiOHOSWebviewCtlRemoveCache(int64_t id, bool clearRom); 86 FFI_EXPORT int64_t FfiOHOSWebviewCtlGetBackForwardEntries(int64_t id, int32_t* errCode); 87 FFI_EXPORT int32_t FfiOHOSWebviewCtlStop(int64_t id); 88 FFI_EXPORT int64_t FfiOHOSWebviewCtlGetFavicon(int64_t id, int32_t* errCode); 89 FFI_EXPORT int32_t FfiOHOSWebviewCtlPrepareForPageLoad(char* url, bool preconnectable, int32_t numSockets); 90 FFI_EXPORT int32_t FfiOHOSWebviewCtlSlideScroll(int64_t id, float vx, float vy); 91 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetNetworkAvailable(int64_t id, bool enable); 92 FFI_EXPORT int32_t FfiOHOSWebviewCtlClearClientAuthenticationCache(int64_t id); 93 FFI_EXPORT int32_t FfiOHOSWebviewCtlClearSslChache(int64_t id); 94 FFI_EXPORT int32_t FfiOHOSWebviewCtlSearchNext(int64_t id, bool forward); 95 FFI_EXPORT int32_t FfiOHOSWebviewCtlClearMatches(int64_t id); 96 FFI_EXPORT int32_t FfiOHOSWebviewCtlSearchAllAsync(int64_t id, char* searchString); 97 FFI_EXPORT int32_t FfiOHOSWebviewCtlDeleteJavaScriptRegister(int64_t id, char* name); 98 FFI_EXPORT int32_t FfiOHOSWebviewCtlPostUrl(int64_t id, char* url, CArrUI8 buffer); 99 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetDownloadDelegate(int64_t id, int64_t delegateId); 100 FFI_EXPORT int32_t FfiOHOSWebviewCtlStartDownload(int64_t id, char* url); 101 FFI_EXPORT CArrI64 FfiOHOSWebviewCtlCreateWebMessagePorts(int64_t id, bool isExtentionType, int32_t* errCode); 102 FFI_EXPORT int32_t FfiOHOSWebviewCtlPostMessage(int64_t id, char* name, CArrI64 ports, char* uri); 103 FFI_EXPORT CArrUI8 FfiOHOSWebviewCtlSerializeWebState(int64_t id, int32_t* errCode); 104 FFI_EXPORT int32_t FfiOHOSWebviewCtlRestoreWebState(int64_t id, CArrUI8 cState); 105 FFI_EXPORT CArrString FfiOHOSWebviewCtlGetCertificate(int64_t id, int32_t* errCode); 106 FFI_EXPORT int32_t FfiOHOSWebviewCtlHasImage(int64_t id, void (*callbackRef)(RetDataBool)); 107 FFI_EXPORT int32_t FfiWebviewCtlCustomizeSchemes(OHOS::Webview::CArrScheme schemes); 108 FFI_EXPORT bool FfiOHOSWebviewCtlTerminateRenderProcess(int64_t id, int32_t* errCode); 109 FFI_EXPORT int32_t FfiOHOSWebviewCtlCloseAllMediaPresentations(int64_t id); 110 FFI_EXPORT int32_t FfiOHOSWebviewCtlPauseAllMedia(int64_t id); 111 FFI_EXPORT int32_t FfiOHOSWebviewCtlResumeAllMedia(int64_t id); 112 FFI_EXPORT int32_t FfiOHOSWebviewCtlStopAllMedia(int64_t id); 113 FFI_EXPORT void FfiOHOSWebviewCtlResumeAllTimers(); 114 FFI_EXPORT void FfiOHOSWebviewCtlPauseAllTimers(); 115 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetPrintBackground(int64_t id, bool enable); 116 FFI_EXPORT bool FfiOHOSWebviewCtlGetPrintBackground(int64_t id, int32_t* errCode); 117 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetScrollable(int64_t id, bool enable); 118 FFI_EXPORT bool FfiOHOSWebviewCtlGetScrollable(int64_t id, int32_t* errCode); 119 FFI_EXPORT void FfiOHOSWebviewCtlEnableAdsBlock(int64_t id, bool enable); 120 FFI_EXPORT bool FfiOHOSWebviewCtlIsAdsBlockEnabled(int64_t id); 121 FFI_EXPORT bool FfiOHOSWebviewCtlIsAdsBlockEnabledForCurPage(int64_t id); 122 FFI_EXPORT bool FfiOHOSWebviewCtlIsIntelligentTrackingPreventionEnabled(int64_t id, int32_t* errorCode); 123 FFI_EXPORT int32_t FfiOHOSWebviewCtlEnableIntelligentTrackingPrevention(int64_t id, bool enable); 124 FFI_EXPORT int32_t FfiOHOSWebviewCtlGetMediaPlaybackState(int64_t id, int32_t* errorCode); 125 FFI_EXPORT int32_t FfiOHOSWebviewCtlGetRenderProcessMode(); 126 FFI_EXPORT void FfiOHOSWebviewCtlSetRenderProcessMode(int32_t mode); 127 FFI_EXPORT int32_t FfiOHOSWebviewCtlWarmupServiceWorker(char* url); 128 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetHostIP(char* hostname, char* address, int32_t aliveTime); 129 FFI_EXPORT int32_t FfiOHOSWebviewCtlClearHostIP(char* hostname); 130 FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetLastJavascriptProxyCallingFrameUrl(int64_t id); 131 FFI_EXPORT int32_t FfiOHOSWebviewCtlEnableWholeWebPageDrawing(); 132 FFI_EXPORT int32_t FfiOHOSWebviewCtlClearPrefetchedResource(CArrString cacheKeyList); 133 FFI_EXPORT int32_t FfiOHOSWebviewCtlStartCamera(int64_t id); 134 FFI_EXPORT int32_t FfiOHOSWebviewCtlStopCamera(int64_t id); 135 FFI_EXPORT int32_t FfiOHOSWebviewCtlCloseCamera(int64_t id); 136 137 FFI_EXPORT int32_t FfiOHOSWebviewCtlAddIntelligentTrackingPreventionBypassingList(CArrString hostList); 138 FFI_EXPORT void FfiOHOSWebviewCtlClearIntelligentTrackingPreventionBypassingList(); 139 FFI_EXPORT void FfiOHOSWebviewCtlEnableBackForwardCache(bool nativeEmbed, bool mediaTakeOver); 140 FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetSurfaceId(int64_t id); 141 FFI_EXPORT int32_t FfiOHOSWebviewCtlInjectOfflineResources(int64_t id, OHOS::Webview::CArrOfflineResourceMap maps); 142 FFI_EXPORT void FfiOHOSWebviewCtlRemoveIntelligentTrackingPreventionBypassingList(CArrString hostList); 143 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetBackForwardCacheOptions(int64_t id, int32_t size, int32_t timeToLive); 144 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetPathAllowingUniversalAccess(int64_t id, CArrString pathList); 145 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetUrlTrustList(int64_t id, char* cUrl); 146 FFI_EXPORT int32_t FfiOHOSWebviewCtlPrefetchResource(OHOS::Webview::CRequestInfo request, 147 OHOS::Webview::ArrWebHeader additionalHttpHeaders, char* cKey, int32_t cacheValidTime); 148 FFI_EXPORT void FfiOHOSWebviewCtlSetWebSchemeHandler(int64_t id, char* cScheme, int64_t classId, int32_t *errCode); 149 FFI_EXPORT int32_t FfiOHOSWebviewCtlClearWebSchemeHandler(int64_t id); 150 FFI_EXPORT int32_t FfiOHOSWebviewCtlSetServiceWorkerWebSchemeHandler(char* cScheme, int64_t classId); 151 FFI_EXPORT int32_t FfiOHOSWebviewCtlClearServiceWorkerWebSchemeHandler(); 152 FFI_EXPORT void FfiOHOSWebviewCtlOnCreateNativeMediaPlayer(int64_t id, 153 int64_t (* callback)(int64_t, OHOS::Webview::CMediaInfo)); 154 FFI_EXPORT int32_t FfiOHOSWebviewCtlPrecompileJavaScript(int64_t id, 155 char* url, char* script, OHOS::Webview::CacheOptions cacheOptions); 156 FFI_EXPORT int32_t FfiOHOSWebviewCtlWebPageSnapshot(int64_t id, OHOS::Webview::CSnapshotInfo snapshot, 157 void (*callbackRef)(OHOS::Webview::RetDataCSnapshotResult infoRef)); 158 159 // BackForwardList 160 FFI_EXPORT int32_t FfiOHOSBackForwardListCurrentIndex(int64_t id, int32_t* errCode); 161 FFI_EXPORT int32_t FfiOHOSBackForwardListSize(int64_t id, int32_t* errCode); 162 FFI_EXPORT OHOS::Webview::CHistoryItem FfiOHOSGetItemAtIndex(int64_t id, int32_t index, int32_t* errCode); 163 FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetLastHitTest(int64_t id, int32_t* errCode); 164 } 165 166 #endif // WEBVIEW_FFI_H