1 /*
2 * Copyright (c) 2022 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_paste_data_record_adapter_wrapper.h"
17
18 #include "ohos_adapter/bridge/ark_clip_board_image_data_adapter_impl.h"
19
20 namespace OHOS::NWeb {
21
NewRecord(const std::string & mimeType)22 std::shared_ptr<PasteDataRecordAdapter> PasteDataRecordAdapter::NewRecord(const std::string& mimeType)
23 {
24 ArkWebString str = ArkWebStringClassToStruct(mimeType);
25 ArkWebRefPtr<ArkWeb::ArkPasteDataRecordAdapter> arkPasteDataRecordAdapter =
26 ArkWeb::ArkPasteDataRecordAdapter::NewRecord(str);
27 ArkWebStringStructRelease(str);
28 return std::make_shared<ArkWeb::ArkPasteDataRecordAdapterWrapper>(arkPasteDataRecordAdapter);
29 }
30
NewRecord(const std::string & mimeType,std::shared_ptr<std::string> htmlText,std::shared_ptr<std::string> plainText)31 std::shared_ptr<PasteDataRecordAdapter> PasteDataRecordAdapter::NewRecord(
32 const std::string& mimeType, std::shared_ptr<std::string> htmlText, std::shared_ptr<std::string> plainText)
33 {
34 ArkWebString str = ArkWebStringClassToStruct(mimeType);
35 ArkWebRefPtr<ArkWeb::ArkPasteDataRecordAdapter> arkPasteDataRecordAdapter =
36 ArkWeb::ArkPasteDataRecordAdapter::NewRecord(str, (void*)(&htmlText), (void*)(&plainText));
37 ArkWebStringStructRelease(str);
38 return std::make_shared<ArkWeb::ArkPasteDataRecordAdapterWrapper>(arkPasteDataRecordAdapter);
39 }
40
41 } // namespace OHOS::NWeb
42
43 namespace OHOS::ArkWeb {
44
ArkPasteDataRecordAdapterWrapper(ArkWebRefPtr<ArkPasteDataRecordAdapter> ref)45 ArkPasteDataRecordAdapterWrapper::ArkPasteDataRecordAdapterWrapper(ArkWebRefPtr<ArkPasteDataRecordAdapter> ref)
46 : ctocpp_(ref)
47 {}
48
SetHtmlText(std::shared_ptr<std::string> htmlText)49 bool ArkPasteDataRecordAdapterWrapper::SetHtmlText(std::shared_ptr<std::string> htmlText)
50 {
51 return ctocpp_->SetHtmlText((void*)(&htmlText));
52 }
53
SetHtmlTextV2(std::shared_ptr<std::string> htmlText)54 bool ArkPasteDataRecordAdapterWrapper::SetHtmlTextV2(std::shared_ptr<std::string> htmlText)
55 {
56 std::string& tmpHtml = *htmlText.get();
57 ArkWebString str = ArkWebStringClassToStruct(tmpHtml);
58 bool result = ctocpp_->SetHtmlTextV2(str);
59 ArkWebStringStructRelease(str);
60 return result;
61 }
62
SetPlainText(std::shared_ptr<std::string> plainText)63 bool ArkPasteDataRecordAdapterWrapper::SetPlainText(std::shared_ptr<std::string> plainText)
64 {
65 return ctocpp_->SetPlainText((void*)(&plainText));
66 }
67
SetPlainTextV2(std::shared_ptr<std::string> plainText)68 bool ArkPasteDataRecordAdapterWrapper::SetPlainTextV2(std::shared_ptr<std::string> plainText)
69 {
70 std::string& tmpText = *plainText.get();
71 ArkWebString str = ArkWebStringClassToStruct(tmpText);
72 bool result = ctocpp_->SetPlainTextV2(str);
73 ArkWebStringStructRelease(str);
74 return result;
75 }
76
SetImgData(std::shared_ptr<NWeb::ClipBoardImageDataAdapter> imageData)77 bool ArkPasteDataRecordAdapterWrapper::SetImgData(std::shared_ptr<NWeb::ClipBoardImageDataAdapter> imageData)
78 {
79 if (!imageData) {
80 return ctocpp_->SetImgData(nullptr);
81 }
82 return ctocpp_->SetImgData(new ArkClipBoardImageDataAdapterImpl(imageData));
83 }
84
GetMimeType()85 std::string ArkPasteDataRecordAdapterWrapper::GetMimeType()
86 {
87 ArkWebString str = ctocpp_->GetMimeType();
88 std::string result = ArkWebStringStructToClass(str);
89 ArkWebStringStructRelease(str);
90 return result;
91 }
92
GetHtmlText()93 std::shared_ptr<std::string> ArkPasteDataRecordAdapterWrapper::GetHtmlText()
94 {
95 std::shared_ptr<std::string> result;
96 ctocpp_->GetHtmlText((void*)&result);
97 return result;
98 }
99
GetHtmlTextV2()100 std::shared_ptr<std::string> ArkPasteDataRecordAdapterWrapper::GetHtmlTextV2()
101 {
102 ArkWebString str;
103 std::shared_ptr<std::string> result = nullptr;
104 if (ctocpp_->GetHtmlTextV2(str)) {
105 result = std::make_shared<std::string>(ArkWebStringStructToClass(str));
106 }
107 ArkWebStringStructRelease(str);
108 return result;
109 }
110
GetPlainText()111 std::shared_ptr<std::string> ArkPasteDataRecordAdapterWrapper::GetPlainText()
112 {
113 std::shared_ptr<std::string> result;
114 ctocpp_->GetPlainText((void*)&result);
115 return result;
116 }
117
GetPlainTextV2()118 std::shared_ptr<std::string> ArkPasteDataRecordAdapterWrapper::GetPlainTextV2()
119 {
120 ArkWebString str;
121 std::shared_ptr<std::string> result = nullptr;
122 if (ctocpp_->GetPlainTextV2(str)) {
123 result = std::make_shared<std::string>(ArkWebStringStructToClass(str));
124 }
125 ArkWebStringStructRelease(str);
126 return result;
127 }
128
GetImgData(std::shared_ptr<NWeb::ClipBoardImageDataAdapter> imageData)129 bool ArkPasteDataRecordAdapterWrapper::GetImgData(std::shared_ptr<NWeb::ClipBoardImageDataAdapter> imageData)
130 {
131 if (!imageData) {
132 return ctocpp_->GetImgData(nullptr);
133 }
134 return ctocpp_->GetImgData(new ArkClipBoardImageDataAdapterImpl(imageData));
135 }
136
SetUri(const std::string & uriString)137 bool ArkPasteDataRecordAdapterWrapper::SetUri(const std::string& uriString)
138 {
139 ArkWebString str = ArkWebStringClassToStruct(uriString);
140 bool result = ctocpp_->SetUri(str);
141 ArkWebStringStructRelease(str);
142 return result;
143 }
144
SetCustomData(NWeb::PasteCustomData & data)145 bool ArkPasteDataRecordAdapterWrapper::SetCustomData(NWeb::PasteCustomData& data)
146 {
147 return ctocpp_->SetCustomData((void*)(&data));
148 }
149
SetCustomDataV2(NWeb::PasteCustomData & data)150 bool ArkPasteDataRecordAdapterWrapper::SetCustomDataV2(NWeb::PasteCustomData& data)
151 {
152 ArkWebUInt8VectorMap mapData = ArkWebUInt8VectorMapClassToStruct(data);
153 bool result = ctocpp_->SetCustomDataV2(mapData);
154 ArkWebUInt8VectorMapStructRelease(mapData);
155 return result;
156 }
157
GetUri()158 std::shared_ptr<std::string> ArkPasteDataRecordAdapterWrapper::GetUri()
159 {
160 std::shared_ptr<std::string> result;
161 ctocpp_->GetUri((void*)&result);
162 return result;
163 }
164
GetUriV2()165 std::shared_ptr<std::string> ArkPasteDataRecordAdapterWrapper::GetUriV2()
166 {
167 ArkWebString str;
168 std::shared_ptr<std::string> result = nullptr;
169 if (ctocpp_->GetUriV2(str)) {
170 result = std::make_shared<std::string>(ArkWebStringStructToClass(str));
171 }
172 ArkWebStringStructRelease(str);
173 return result;
174 }
175
GetCustomData()176 std::shared_ptr<NWeb::PasteCustomData> ArkPasteDataRecordAdapterWrapper::GetCustomData()
177 {
178 std::shared_ptr<NWeb::PasteCustomData> result;
179 ctocpp_->GetCustomData((void*)&result);
180 return result;
181 }
182
GetCustomDataV2()183 std::shared_ptr<NWeb::PasteCustomData> ArkPasteDataRecordAdapterWrapper::GetCustomDataV2()
184 {
185 ArkWebUInt8VectorMap mapData;
186 std::shared_ptr<NWeb::PasteCustomData> result = nullptr;
187 if (ctocpp_->GetCustomDataV2(mapData)) {
188 result = std::make_shared<NWeb::PasteCustomData>(ArkWebUInt8VectorMapStructToClass(mapData));
189 }
190 ArkWebUInt8VectorMapStructRelease(mapData);
191 return result;
192 }
193
194 } // namespace OHOS::ArkWeb
195