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 #include "geolocation_permission_ffi.h"
17
18 #include "geolocation_permission.h"
19 #include "nweb_helper.h"
20 #include "nweb_init_params.h"
21 #include "web_errors.h"
22 #include "webview_utils.h"
23
24 using namespace OHOS::FFI;
25 using namespace OHOS::NWeb;
26
27 namespace OHOS {
28 namespace Webview {
29 extern "C" {
30 // GeolocationPermissions
FfiOHOSGeolocationAllowGeolocation(char * origin,bool incognito,int32_t * errCode)31 void FfiOHOSGeolocationAllowGeolocation(char* origin, bool incognito, int32_t* errCode)
32 {
33 std::string originStr = std::string(origin);
34 GeolocationPermission::CjAllowGeolocation(originStr, incognito, errCode);
35 }
36
FfiOHOSGeolocationDeleteGeolocation(char * origin,bool incognito,int32_t * errCode)37 void FfiOHOSGeolocationDeleteGeolocation(char* origin, bool incognito, int32_t* errCode)
38 {
39 std::string originStr = std::string(origin);
40 GeolocationPermission::CjDeleteGeolocation(originStr, incognito, errCode);
41 }
42
FfiOHOSGeolocationGetAccessibleGeolocation(char * origin,bool incognito,int32_t * errCode)43 bool FfiOHOSGeolocationGetAccessibleGeolocation(char* origin, bool incognito, int32_t* errCode)
44 {
45 std::string originStr = std::string(origin);
46 return GeolocationPermission::CjGetAccessibleGeolocation(originStr, incognito, errCode);
47 }
48
FfiOHOSGeolocationGetStoredGeolocation(bool incognito,int32_t * errCode)49 CArrString FfiOHOSGeolocationGetStoredGeolocation(bool incognito, int32_t* errCode)
50 {
51 std::vector<std::string> origins = GeolocationPermission::CjGetStoredGeolocation(incognito, errCode);
52 CArrString arrOrigins = { .head = nullptr, .size = 0 };
53 if (errCode && *errCode != 0) {
54 return arrOrigins;
55 }
56 arrOrigins.size = static_cast<int64_t>(origins.size());
57 arrOrigins.head = OHOS::Webview::VectorToCArrString(origins);
58 return arrOrigins;
59 }
60
FfiOHOSGeolocationDeleteAllGeolocation(bool incognito,int32_t * errCode)61 void FfiOHOSGeolocationDeleteAllGeolocation(bool incognito, int32_t* errCode)
62 {
63 GeolocationPermission::CjDeleteAllGeolocation(incognito, errCode);
64 }
65 }
66 } // namespace Webview
67 } // namespace OHOS