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 "ohos_nweb/bridge/ark_web_history_item_wrapper.h"
17 
18 #include "base/bridge/ark_web_bridge_macros.h"
19 
20 namespace OHOS::ArkWeb {
21 
ArkWebHistoryItemWrapper(ArkWebRefPtr<ArkWebHistoryItem> ark_web_history_item)22 ArkWebHistoryItemWrapper::ArkWebHistoryItemWrapper(ArkWebRefPtr<ArkWebHistoryItem> ark_web_history_item)
23     : ark_web_history_item_(ark_web_history_item)
24 {}
25 
GetFavicon(void ** data,int & width,int & height,ArkWebImageColorType & color_type,ArkWebImageAlphaType & alpha_type)26 bool ArkWebHistoryItemWrapper::GetFavicon(
27     void** data, int& width, int& height, ArkWebImageColorType& color_type, ArkWebImageAlphaType& alpha_type)
28 {
29     int enum_color_type = static_cast<int>(ArkWebImageColorType::COLOR_TYPE_UNKNOWN);
30     int enum_alpha_type = static_cast<int>(ArkWebImageAlphaType::ALPHA_TYPE_UNKNOWN);
31     bool result = ark_web_history_item_->GetFavicon(data, width, height, enum_color_type, enum_alpha_type);
32     color_type = static_cast<ArkWebImageColorType>(enum_color_type);
33     alpha_type = static_cast<ArkWebImageAlphaType>(enum_alpha_type);
34     return result;
35 }
36 
GetHistoryUrl()37 std::string ArkWebHistoryItemWrapper::GetHistoryUrl()
38 {
39     ArkWebString stUrl = ark_web_history_item_->GetHistoryUrl();
40 
41     std::string objUrl = ArkWebStringStructToClass(stUrl);
42     ArkWebStringStructRelease(stUrl);
43     return objUrl;
44 }
45 
GetHistoryTitle()46 std::string ArkWebHistoryItemWrapper::GetHistoryTitle()
47 {
48     ArkWebString stTitle = ark_web_history_item_->GetHistoryTitle();
49 
50     std::string objTitle = ArkWebStringStructToClass(stTitle);
51     ArkWebStringStructRelease(stTitle);
52     return objTitle;
53 }
54 
GetHistoryRawUrl()55 std::string ArkWebHistoryItemWrapper::GetHistoryRawUrl()
56 {
57     ArkWebString stUrl = ark_web_history_item_->GetHistoryRawUrl();
58 
59     std::string objUrl = ArkWebStringStructToClass(stUrl);
60     ArkWebStringStructRelease(stUrl);
61     return objUrl;
62 }
63 
64 } // namespace OHOS::ArkWeb
65