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 #include "ohos_adapter/bridge/ark_location_instance_impl.h"
17 
18 #include "ohos_adapter/bridge/ark_location_proxy_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_location_request_config_impl.h"
20 
21 #include "base/bridge/ark_web_bridge_macros.h"
22 
23 namespace OHOS::ArkWeb {
24 
GetInstance()25 ArkWebRefPtr<ArkLocationInstance> ArkLocationInstance::GetInstance()
26 {
27     static NWeb::LocationInstance& instance = NWeb::LocationInstance::GetInstance();
28     static ArkWebRefPtr<ArkLocationInstance> impl = new ArkLocationInstanceImpl(instance);
29     return impl;
30 }
31 
ArkLocationInstanceImpl(NWeb::LocationInstance & ref)32 ArkLocationInstanceImpl::ArkLocationInstanceImpl(NWeb::LocationInstance& ref) : real_(ref) {}
33 
CreateLocationProxyAdapter()34 ArkWebRefPtr<ArkLocationProxyAdapter> ArkLocationInstanceImpl::CreateLocationProxyAdapter()
35 {
36     std::shared_ptr<OHOS::NWeb::LocationProxyAdapter> adapter = real_.CreateLocationProxyAdapter();
37     if (CHECK_SHARED_PTR_IS_NULL(adapter)) {
38         return nullptr;
39     }
40     return new ArkLocationProxyAdapterImpl(adapter);
41 }
42 
CreateLocationRequestConfig()43 ArkWebRefPtr<ArkLocationRequestConfig> ArkLocationInstanceImpl::CreateLocationRequestConfig()
44 {
45     std::shared_ptr<OHOS::NWeb::LocationRequestConfig> config = real_.CreateLocationRequestConfig();
46     if (CHECK_SHARED_PTR_IS_NULL(config)) {
47         return nullptr;
48     }
49     return new ArkLocationRequestConfigImpl(config);
50 }
51 
52 } // namespace OHOS::ArkWeb
53