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 #include "ffi_remote_data.h"
21 #include "webview_utils.h"
22 #include "cj_common_ffi.h"
23 
24 extern "C" {
25     FFI_EXPORT int64_t FfiOHOSWebviewCtlConstructor();
26     FFI_EXPORT int64_t FfiOHOSWebviewCtlConstructorWithWebTag(char *webTag);
27     FFI_EXPORT void FfiOHOSWebviewCtlInitializeWebEngine();
28     FFI_EXPORT void FfiOHOSWebviewCtlSetHttpDns(int32_t secureDnsMode, char* secureDnsConfig);
29     FFI_EXPORT void FfiOHOSWebviewCtlSetWebDebuggingAccess(bool webDebuggingAccess);
30     FFI_EXPORT int32_t FfiOHOSWebviewCtlLoadUrl(int64_t id, char *url);
31     FFI_EXPORT int32_t FfiOHOSWebviewCtlLoadUrlWithHeaders(int64_t id, char *url, OHOS::Webview::ArrWebHeader headers);
32     FFI_EXPORT int32_t FfiOHOSWebviewCtlLoadData(int64_t id, OHOS::Webview::LoadDatas loadDatas);
33     FFI_EXPORT int32_t FfiOHOSWebviewCtlRefresh(int64_t id);
34     FFI_EXPORT char *FfiOHOSWebviewCtlGetUserAgent(int64_t id, int32_t *errCode);
35     FFI_EXPORT bool FfiOHOSWebviewCtlAccessForward(int64_t id, int32_t *errCode);
36     FFI_EXPORT bool FfiOHOSWebviewCtlAccessBackward(int64_t id, int32_t *errCode);
37     FFI_EXPORT int32_t FfiOHOSWebviewCtlSetCustomUserAgent(int64_t id, char *cUserAgent);
38     FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetCustomUserAgent(int64_t id);
39     FFI_EXPORT int32_t FfiOHOSWebviewCtlRunJavaScript(int64_t id, char* cScript,
40         void (*callbackRef)(RetDataCString infoRef));
41     FFI_EXPORT int32_t FfiOHOSWebviewCtlRegisterJavaScriptProxy(int64_t id,
42         CArrI64 cFuncIds,  const char* cName, CArrString cMethodList);
43     FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetUrl(int64_t id);
44     FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetOriginalUrl(int64_t id);
45     FFI_EXPORT int32_t FfiOHOSWebviewCtlPageUp(int64_t id, bool top);
46     FFI_EXPORT int32_t FfiOHOSWebviewCtlPageDown(int64_t id, bool bottom);
47     FFI_EXPORT int32_t FfiOHOSWebviewCtlScrollTo(int64_t id, float x, float y);
48     FFI_EXPORT int32_t FfiOHOSWebviewCtlScrollBy(int64_t id, float deltaX, float deltaY);
49     FFI_EXPORT int32_t FfiOHOSWebviewCtlForward(int64_t id);
50     FFI_EXPORT int32_t FfiOHOSWebviewCtlBackward(int64_t id);
51     FFI_EXPORT int32_t FfiOHOSWebviewCtlBackOrForward(int64_t id, int32_t step);
52     FFI_EXPORT int32_t FfiOHOSWebviewCtlGetPageHeight(int64_t id, int32_t *errCode);
53     FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetTitle(int64_t id);
54     FFI_EXPORT int32_t FfiOHOSWebviewCtlZoom(int64_t id, float factor);
55     FFI_EXPORT int32_t FfiOHOSWebviewCtlZoomIn(int64_t id);
56     FFI_EXPORT int32_t FfiOHOSWebviewCtlZoomOut(int64_t id);
57     FFI_EXPORT int32_t FfiOHOSWebviewCtlClearHistory(int64_t id);
58     FFI_EXPORT bool FfiOHOSWebviewCtlAccessStep(int64_t id, int32_t *errCode, int32_t step);
59     FFI_EXPORT int32_t FfiOHOSWebviewCtlOnActive(int64_t id);
60     FFI_EXPORT int32_t FfiOHOSWebviewCtlOnInactive(int64_t id);
61     FFI_EXPORT int32_t FfiOHOSWebviewCtlGetHitTest(int64_t id, int32_t *errCode);
62     FFI_EXPORT RetDataCString FfiOHOSWebviewCtlGetHitTestValue(int64_t id, int32_t *errCode);
63     FFI_EXPORT int32_t FfiOHOSWebviewCtlStoreWebArchive(int64_t id, const char* cBaseName,
64         bool autoName, void (*callbackRef)(RetDataCString infoRef));
65     FFI_EXPORT int32_t FfiOHOSWebviewCtlEnableSafeBrowsing(int64_t id, bool enable);
66     FFI_EXPORT bool FfiOHOSWebviewCtlIsSafeBrowsingEnabled(int64_t id, int32_t *errCode);
67     FFI_EXPORT int32_t FfiOHOSWebviewCtlGetSecurityLevel(int64_t id, int32_t *errCode);
68     FFI_EXPORT bool FfiOHOSWebviewCtlIsIncognitoMode(int64_t id, int32_t *errCode);
69     FFI_EXPORT int32_t FfiOHOSWebviewCtlRemoveCache(int64_t id, bool clearRom);
70     FFI_EXPORT int64_t FfiOHOSWebviewCtlGetBackForwardEntries(int64_t id, int32_t *errCode);
71     FFI_EXPORT int32_t FfiOHOSWebviewCtlStop(int64_t id);
72 
73     // BackForwardList
74     FFI_EXPORT int32_t FfiOHOSBackForwardListCurrentIndex(int64_t id, int32_t *errCode);
75     FFI_EXPORT int32_t FfiOHOSBackForwardListSize(int64_t id, int32_t *errCode);
76     FFI_EXPORT OHOS::Webview::CHistoryItem FfiOHOSGetItemAtIndex(int64_t id, int32_t index, int32_t *errCode);
77 
78     // cookie_manager
79     FFI_EXPORT const char* FfiOHOSCookieMgrFetchCookieSync(const char *url, bool incognitoMode, int32_t* errCode);
80     FFI_EXPORT int32_t FfiOHOSCookieMgrConfigCookieSync(const char* url, const char* value, bool incognitoMode);
81     FFI_EXPORT void FfiOHOSCookieMgrPutAcceptCookieEnabled(bool accept);
82     FFI_EXPORT bool FfiOHOSCookieMgrIsCookieAllowed();
83     FFI_EXPORT void FfiOHOSCookieMgrPutAcceptThirdPartyCookieEnabled(bool accept);
84     FFI_EXPORT bool FfiOHOSCookieMgrIsThirdPartyCookieAllowed();
85     FFI_EXPORT bool FfiOHOSCookieMgrExistCookie(bool incognitoMode);
86     FFI_EXPORT void FfiOHOSCookieMgrClearAllCookiesSync(bool incognitoMode);
87     FFI_EXPORT void FfiOHOSCookieMgrClearSessionCookieSync();
88 }
89 
90 #endif // WEBVIEW_FFI_H