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_nweb_wrapper.h"
17 
18 #include "ohos_nweb/bridge/ark_web_accessibility_event_callback_impl.h"
19 #include "ohos_nweb/bridge/ark_web_accessibility_node_info_wrapper.h"
20 #include "ohos_nweb/bridge/ark_web_array_buffer_value_callback_impl.h"
21 #include "ohos_nweb/bridge/ark_web_bool_value_callback_impl.h"
22 #include "ohos_nweb/bridge/ark_web_cache_options_impl.h"
23 #include "ohos_nweb/bridge/ark_web_create_native_media_player_callback_impl.h"
24 #include "ohos_nweb/bridge/ark_web_download_callback_impl.h"
25 #include "ohos_nweb/bridge/ark_web_drag_data_wrapper.h"
26 #include "ohos_nweb/bridge/ark_web_drag_event_impl.h"
27 #include "ohos_nweb/bridge/ark_web_find_callback_impl.h"
28 #include "ohos_nweb/bridge/ark_web_handler_impl.h"
29 #include "ohos_nweb/bridge/ark_web_history_list_wrapper.h"
30 #include "ohos_nweb/bridge/ark_web_hit_test_result_wrapper.h"
31 #include "ohos_nweb/bridge/ark_web_js_result_callback_impl.h"
32 #include "ohos_nweb/bridge/ark_web_message_value_callback_impl.h"
33 #include "ohos_nweb/bridge/ark_web_pdfconfig_args_impl.h"
34 #include "ohos_nweb/bridge/ark_web_preference_wrapper.h"
35 #include "ohos_nweb/bridge/ark_web_release_surface_callback_impl.h"
36 #include "ohos_nweb/bridge/ark_web_screen_lock_callback_impl.h"
37 #include "ohos_nweb/bridge/ark_web_spanstring_convert_html_callback_impl.h"
38 #include "ohos_nweb/bridge/ark_web_string_value_callback_impl.h"
39 #include "ohos_nweb/bridge/ark_web_system_configuration_impl.h"
40 #include "ohos_nweb/bridge/ark_web_view_struct_utils.h"
41 #include "ohos_nweb/cpptoc/ark_web_js_proxy_callback_vector_cpptoc.h"
42 #include "ohos_nweb/cpptoc/ark_web_touch_point_info_vector_cpptoc.h"
43 #include "ohos_nweb/cpptoc/ark_web_value_vector_cpptoc.h"
44 
45 #include "base/bridge/ark_web_bridge_macros.h"
46 
47 namespace OHOS::ArkWeb {
48 
ArkWebNWebWrapper(ArkWebRefPtr<ArkWebNWeb> ark_web_nweb)49 ArkWebNWebWrapper::ArkWebNWebWrapper(ArkWebRefPtr<ArkWebNWeb> ark_web_nweb) : ark_web_nweb_(ark_web_nweb) {}
50 
Resize(uint32_t width,uint32_t height,bool is_keyboard)51 void ArkWebNWebWrapper::Resize(uint32_t width, uint32_t height, bool is_keyboard)
52 {
53     ark_web_nweb_->Resize(width, height, is_keyboard);
54 }
55 
OnPause()56 void ArkWebNWebWrapper::OnPause()
57 {
58     ark_web_nweb_->OnPause();
59 }
60 
OnContinue()61 void ArkWebNWebWrapper::OnContinue()
62 {
63     ark_web_nweb_->OnContinue();
64 }
65 
OnDestroy()66 void ArkWebNWebWrapper::OnDestroy()
67 {
68     ark_web_nweb_->OnDestroy();
69 }
70 
OnFocus(const ArkWebFocusReason & focus_reason)71 void ArkWebNWebWrapper::OnFocus(const ArkWebFocusReason& focus_reason)
72 {
73     ark_web_nweb_->OnFocus(static_cast<int32_t>(focus_reason));
74 }
75 
OnBlur(const ArkWebBlurReason & blur_reason)76 void ArkWebNWebWrapper::OnBlur(const ArkWebBlurReason& blur_reason)
77 {
78     ark_web_nweb_->OnBlur(static_cast<int32_t>(blur_reason));
79 }
80 
OnTouchPress(int32_t id,double x,double y,bool from_overlay)81 void ArkWebNWebWrapper::OnTouchPress(int32_t id, double x, double y, bool from_overlay)
82 {
83     ark_web_nweb_->OnTouchPress(id, x, y, from_overlay);
84 }
85 
OnTouchRelease(int32_t id,double x,double y,bool from_overlay)86 void ArkWebNWebWrapper::OnTouchRelease(int32_t id, double x, double y, bool from_overlay)
87 {
88     ark_web_nweb_->OnTouchRelease(id, x, y, from_overlay);
89 }
90 
OnTouchMove(int32_t id,double x,double y,bool from_overlay)91 void ArkWebNWebWrapper::OnTouchMove(int32_t id, double x, double y, bool from_overlay)
92 {
93     ark_web_nweb_->OnTouchMove(id, x, y, from_overlay);
94 }
95 
OnTouchMove(const std::vector<std::shared_ptr<OHOS::NWeb::NWebTouchPointInfo>> & touch_point_infos,bool from_overlay)96 void ArkWebNWebWrapper::OnTouchMove(
97     const std::vector<std::shared_ptr<OHOS::NWeb::NWebTouchPointInfo>>& touch_point_infos, bool from_overlay)
98 {
99     ArkWebTouchPointInfoVector st_touch_point_infos = ArkWebTouchPointInfoVectorClassToStruct(touch_point_infos);
100 
101     ark_web_nweb_->OnTouchMove(st_touch_point_infos, from_overlay);
102 
103     ArkWebTouchPointInfoVectorStructRelease(st_touch_point_infos);
104 }
105 
OnTouchCancel()106 void ArkWebNWebWrapper::OnTouchCancel()
107 {
108     ark_web_nweb_->OnTouchCancel();
109 }
110 
OnNavigateBack()111 void ArkWebNWebWrapper::OnNavigateBack()
112 {
113     ark_web_nweb_->OnNavigateBack();
114 }
115 
SendKeyEvent(int32_t key_code,int32_t key_action)116 bool ArkWebNWebWrapper::SendKeyEvent(int32_t key_code, int32_t key_action)
117 {
118     return ark_web_nweb_->SendKeyEvent(key_code, key_action);
119 }
120 
SendMouseWheelEvent(double x,double y,double delta_x,double delta_y)121 void ArkWebNWebWrapper::SendMouseWheelEvent(double x, double y, double delta_x, double delta_y)
122 {
123     ark_web_nweb_->SendMouseWheelEvent(x, y, delta_x, delta_y);
124 }
125 
SendMouseEvent(int x,int y,int button,int action,int count)126 void ArkWebNWebWrapper::SendMouseEvent(int x, int y, int button, int action, int count)
127 {
128     ark_web_nweb_->SendMouseEvent(x, y, button, action, count);
129 }
130 
Load(const std::string & url)131 int ArkWebNWebWrapper::Load(const std::string& url)
132 {
133     ArkWebString stUrl = ArkWebStringClassToStruct(url);
134 
135     int code = ark_web_nweb_->Load(stUrl);
136 
137     ArkWebStringStructRelease(stUrl);
138     return code;
139 }
140 
IsNavigatebackwardAllowed()141 bool ArkWebNWebWrapper::IsNavigatebackwardAllowed()
142 {
143     return ark_web_nweb_->IsNavigatebackwardAllowed();
144 }
145 
IsNavigateForwardAllowed()146 bool ArkWebNWebWrapper::IsNavigateForwardAllowed()
147 {
148     return ark_web_nweb_->IsNavigateForwardAllowed();
149 }
150 
CanNavigateBackOrForward(int num_steps)151 bool ArkWebNWebWrapper::CanNavigateBackOrForward(int num_steps)
152 {
153     return ark_web_nweb_->CanNavigateBackOrForward(num_steps);
154 }
155 
NavigateBack()156 void ArkWebNWebWrapper::NavigateBack()
157 {
158     ark_web_nweb_->NavigateBack();
159 }
160 
NavigateForward()161 void ArkWebNWebWrapper::NavigateForward()
162 {
163     ark_web_nweb_->NavigateForward();
164 }
165 
NavigateBackOrForward(int step)166 void ArkWebNWebWrapper::NavigateBackOrForward(int step)
167 {
168     ark_web_nweb_->NavigateBackOrForward(step);
169 }
170 
DeleteNavigateHistory()171 void ArkWebNWebWrapper::DeleteNavigateHistory()
172 {
173     ark_web_nweb_->DeleteNavigateHistory();
174 }
175 
Reload()176 void ArkWebNWebWrapper::Reload()
177 {
178     ark_web_nweb_->Reload();
179 }
180 
Zoom(float zoom_factor)181 int ArkWebNWebWrapper::Zoom(float zoom_factor)
182 {
183     return ark_web_nweb_->Zoom(zoom_factor);
184 }
185 
ZoomIn()186 int ArkWebNWebWrapper::ZoomIn()
187 {
188     return ark_web_nweb_->ZoomIn();
189 }
190 
ZoomOut()191 int ArkWebNWebWrapper::ZoomOut()
192 {
193     return ark_web_nweb_->ZoomOut();
194 }
195 
Stop()196 void ArkWebNWebWrapper::Stop()
197 {
198     ark_web_nweb_->Stop();
199 }
200 
ExecuteJavaScript(const std::string & code)201 void ArkWebNWebWrapper::ExecuteJavaScript(const std::string& code)
202 {
203     ArkWebString stCode = ArkWebStringClassToStruct(code);
204 
205     ark_web_nweb_->ExecuteJavaScript(stCode);
206 
207     ArkWebStringStructRelease(stCode);
208 }
209 
ExecuteJavaScript(const std::string & code,std::shared_ptr<OHOS::NWeb::NWebMessageValueCallback> callback,bool extention)210 void ArkWebNWebWrapper::ExecuteJavaScript(
211     const std::string& code, std::shared_ptr<OHOS::NWeb::NWebMessageValueCallback> callback, bool extention)
212 {
213     ArkWebString stCode = ArkWebStringClassToStruct(code);
214 
215     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
216         ark_web_nweb_->ExecuteJavaScript(stCode, nullptr, extention);
217     } else {
218         ark_web_nweb_->ExecuteJavaScript(stCode, new ArkWebMessageValueCallbackImpl(callback), extention);
219     }
220 
221     ArkWebStringStructRelease(stCode);
222 }
223 
GetPreference()224 std::shared_ptr<OHOS::NWeb::NWebPreference> ArkWebNWebWrapper::GetPreference()
225 {
226     ArkWebRefPtr<ArkWebPreference> ark_web_preference = ark_web_nweb_->GetPreference();
227     if (CHECK_REF_PTR_IS_NULL(ark_web_preference)) {
228         return nullptr;
229     }
230 
231     return std::make_shared<ArkWebPreferenceWrapper>(ark_web_preference);
232 }
233 
GetWebId()234 unsigned int ArkWebNWebWrapper::GetWebId()
235 {
236     return ark_web_nweb_->GetWebId();
237 }
238 
GetHitTestResult()239 std::shared_ptr<OHOS::NWeb::HitTestResult> ArkWebNWebWrapper::GetHitTestResult()
240 {
241     ArkWebRefPtr<ArkWebHitTestResult> ark_web_hit_test_result = ark_web_nweb_->GetHitTestResult();
242     if (CHECK_REF_PTR_IS_NULL(ark_web_hit_test_result)) {
243         return nullptr;
244     }
245 
246     return std::make_shared<ArkWebHitTestResultWrapper>(ark_web_hit_test_result);
247 }
248 
PutBackgroundColor(int color)249 void ArkWebNWebWrapper::PutBackgroundColor(int color)
250 {
251     ark_web_nweb_->PutBackgroundColor(color);
252 }
253 
InitialScale(float scale)254 void ArkWebNWebWrapper::InitialScale(float scale)
255 {
256     ark_web_nweb_->InitialScale(scale);
257 }
258 
PutDownloadCallback(std::shared_ptr<OHOS::NWeb::NWebDownloadCallback> download_listener)259 void ArkWebNWebWrapper::PutDownloadCallback(std::shared_ptr<OHOS::NWeb::NWebDownloadCallback> download_listener)
260 {
261     if (CHECK_SHARED_PTR_IS_NULL(download_listener)) {
262         ark_web_nweb_->PutDownloadCallback(nullptr);
263         return;
264     }
265 
266     ark_web_nweb_->PutDownloadCallback(new ArkWebDownloadCallbackImpl(download_listener));
267 }
268 
PutAccessibilityEventCallback(std::shared_ptr<OHOS::NWeb::NWebAccessibilityEventCallback> accessibility_event_listener)269 void ArkWebNWebWrapper::PutAccessibilityEventCallback(
270     std::shared_ptr<OHOS::NWeb::NWebAccessibilityEventCallback> accessibility_event_listener)
271 {
272     if (CHECK_SHARED_PTR_IS_NULL(accessibility_event_listener)) {
273         ark_web_nweb_->PutAccessibilityEventCallback(nullptr);
274         return;
275     }
276 
277     ark_web_nweb_->PutAccessibilityEventCallback(
278         new ArkWebAccessibilityEventCallbackImpl(accessibility_event_listener));
279 }
280 
PutAccessibilityIdGenerator(const AccessibilityIdGenerateFunc accessibility_id_generator)281 void ArkWebNWebWrapper::PutAccessibilityIdGenerator(const AccessibilityIdGenerateFunc accessibility_id_generator)
282 {
283     ark_web_nweb_->PutAccessibilityIdGenerator(accessibility_id_generator);
284 }
285 
SetNWebHandler(std::shared_ptr<OHOS::NWeb::NWebHandler> handler)286 void ArkWebNWebWrapper::SetNWebHandler(std::shared_ptr<OHOS::NWeb::NWebHandler> handler)
287 {
288     if (CHECK_SHARED_PTR_IS_NULL(handler)) {
289         ark_web_nweb_->SetNWebHandler(nullptr);
290         return;
291     }
292 
293     ark_web_nweb_->SetNWebHandler(new ArkWebHandlerImpl(handler));
294 }
295 
Title()296 std::string ArkWebNWebWrapper::Title()
297 {
298     return ArkWebStringStructToClass(ark_web_nweb_->Title());
299 }
300 
PageLoadProgress()301 int ArkWebNWebWrapper::PageLoadProgress()
302 {
303     return ark_web_nweb_->PageLoadProgress();
304 }
305 
ContentHeight()306 int ArkWebNWebWrapper::ContentHeight()
307 {
308     return ark_web_nweb_->ContentHeight();
309 }
310 
Scale()311 float ArkWebNWebWrapper::Scale()
312 {
313     return ark_web_nweb_->Scale();
314 }
315 
Load(const std::string & url,const std::map<std::string,std::string> & additional_http_headers)316 int ArkWebNWebWrapper::Load(const std::string& url, const std::map<std::string, std::string>& additional_http_headers)
317 {
318     ArkWebString stUrl = ArkWebStringClassToStruct(url);
319     ArkWebStringMap stHeaders = ArkWebStringMapClassToStruct(additional_http_headers);
320 
321     int code = ark_web_nweb_->Load(stUrl, stHeaders);
322 
323     ArkWebStringStructRelease(stUrl);
324     ArkWebStringMapStructRelease(stHeaders);
325     return code;
326 }
327 
LoadWithDataAndBaseUrl(const std::string & base_url,const std::string & data,const std::string & mime_type,const std::string & encoding,const std::string & history_url)328 int ArkWebNWebWrapper::LoadWithDataAndBaseUrl(const std::string& base_url, const std::string& data,
329     const std::string& mime_type, const std::string& encoding, const std::string& history_url)
330 {
331     ArkWebString stData = ArkWebStringClassToStruct(data);
332     ArkWebString stBaseUrl = ArkWebStringClassToStruct(base_url);
333     ArkWebString stEncoding = ArkWebStringClassToStruct(encoding);
334     ArkWebString stMimeType = ArkWebStringClassToStruct(mime_type);
335     ArkWebString stHistoryUrl = ArkWebStringClassToStruct(history_url);
336 
337     int code = ark_web_nweb_->LoadWithDataAndBaseUrl(stBaseUrl, stData, stMimeType, stEncoding, stHistoryUrl);
338 
339     ArkWebStringStructRelease(stData);
340     ArkWebStringStructRelease(stBaseUrl);
341     ArkWebStringStructRelease(stEncoding);
342     ArkWebStringStructRelease(stMimeType);
343     ArkWebStringStructRelease(stHistoryUrl);
344     return code;
345 }
346 
LoadWithData(const std::string & data,const std::string & mime_type,const std::string & encoding)347 int ArkWebNWebWrapper::LoadWithData(const std::string& data, const std::string& mime_type, const std::string& encoding)
348 {
349     ArkWebString stData = ArkWebStringClassToStruct(data);
350     ArkWebString stEncoding = ArkWebStringClassToStruct(encoding);
351     ArkWebString stMimeType = ArkWebStringClassToStruct(mime_type);
352 
353     int code = ark_web_nweb_->LoadWithData(stData, stMimeType, stEncoding);
354 
355     ArkWebStringStructRelease(stData);
356     ArkWebStringStructRelease(stEncoding);
357     ArkWebStringStructRelease(stMimeType);
358     return code;
359 }
360 
RegisterArkJSfunction(const std::string & object_name,const std::vector<std::string> & method_list,const int32_t object_id)361 void ArkWebNWebWrapper::RegisterArkJSfunction(
362     const std::string& object_name, const std::vector<std::string>& method_list, const int32_t object_id)
363 {
364     ArkWebString stName = ArkWebStringClassToStruct(object_name);
365     ArkWebStringVector stMethods = ArkWebStringVectorClassToStruct(method_list);
366 
367     ark_web_nweb_->RegisterArkJSfunction(stName, stMethods, object_id);
368 
369     ArkWebStringStructRelease(stName);
370     ArkWebStringVectorStructRelease(stMethods);
371 }
372 
UnregisterArkJSfunction(const std::string & object_name,const std::vector<std::string> & method_list)373 void ArkWebNWebWrapper::UnregisterArkJSfunction(
374     const std::string& object_name, const std::vector<std::string>& method_list)
375 {
376     ArkWebString stName = ArkWebStringClassToStruct(object_name);
377     ArkWebStringVector stMethods = ArkWebStringVectorClassToStruct(method_list);
378 
379     ark_web_nweb_->UnregisterArkJSfunction(stName, stMethods);
380 
381     ArkWebStringStructRelease(stName);
382     ArkWebStringVectorStructRelease(stMethods);
383 }
384 
SetNWebJavaScriptResultCallBack(std::shared_ptr<OHOS::NWeb::NWebJavaScriptResultCallBack> callback)385 void ArkWebNWebWrapper::SetNWebJavaScriptResultCallBack(
386     std::shared_ptr<OHOS::NWeb::NWebJavaScriptResultCallBack> callback)
387 {
388     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
389         ark_web_nweb_->SetNWebJavaScriptResultCallBack(nullptr);
390         return;
391     }
392 
393     ark_web_nweb_->SetNWebJavaScriptResultCallBack(new ArkWebJsResultCallbackImpl(callback));
394 }
395 
PutFindCallback(std::shared_ptr<OHOS::NWeb::NWebFindCallback> find_listener)396 void ArkWebNWebWrapper::PutFindCallback(std::shared_ptr<OHOS::NWeb::NWebFindCallback> find_listener)
397 {
398     if (CHECK_SHARED_PTR_IS_NULL(find_listener)) {
399         ark_web_nweb_->PutFindCallback(nullptr);
400         return;
401     }
402 
403     ark_web_nweb_->PutFindCallback(new ArkWebFindCallbackImpl(find_listener));
404 }
405 
FindAllAsync(const std::string & search_str)406 void ArkWebNWebWrapper::FindAllAsync(const std::string& search_str)
407 {
408     ArkWebString stSearchStr = ArkWebStringClassToStruct(search_str);
409 
410     ark_web_nweb_->FindAllAsync(stSearchStr);
411 
412     ArkWebStringStructRelease(stSearchStr);
413 }
414 
ClearMatches()415 void ArkWebNWebWrapper::ClearMatches()
416 {
417     ark_web_nweb_->ClearMatches();
418 }
419 
FindNext(const bool forward)420 void ArkWebNWebWrapper::FindNext(const bool forward)
421 {
422     ark_web_nweb_->FindNext(forward);
423 }
424 
StoreWebArchive(const std::string & base_name,bool auto_name,std::shared_ptr<OHOS::NWeb::NWebStringValueCallback> callback)425 void ArkWebNWebWrapper::StoreWebArchive(
426     const std::string& base_name, bool auto_name, std::shared_ptr<OHOS::NWeb::NWebStringValueCallback> callback)
427 {
428     ArkWebString stName = ArkWebStringClassToStruct(base_name);
429 
430     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
431         ark_web_nweb_->StoreWebArchive(stName, auto_name, nullptr);
432     } else {
433         ark_web_nweb_->StoreWebArchive(stName, auto_name, new ArkWebStringValueCallbackImpl(callback));
434     }
435 
436     ArkWebStringStructRelease(stName);
437 }
438 
CreateWebMessagePorts()439 std::vector<std::string> ArkWebNWebWrapper::CreateWebMessagePorts()
440 {
441     ArkWebStringVector stPorts = ark_web_nweb_->CreateWebMessagePorts();
442 
443     std::vector<std::string> objPorts = ArkWebStringVectorStructToClass(stPorts);
444 
445     ArkWebStringVectorStructRelease(stPorts);
446     return objPorts;
447 }
448 
PostWebMessage(const std::string & message,const std::vector<std::string> & ports,const std::string & target_uri)449 void ArkWebNWebWrapper::PostWebMessage(
450     const std::string& message, const std::vector<std::string>& ports, const std::string& target_uri)
451 {
452     ArkWebString stMessage = ArkWebStringClassToStruct(message);
453     ArkWebString stTargetUrl = ArkWebStringClassToStruct(target_uri);
454     ArkWebStringVector stPorts = ArkWebStringVectorClassToStruct(ports);
455 
456     ark_web_nweb_->PostWebMessage(stMessage, stPorts, stTargetUrl);
457 
458     ArkWebStringStructRelease(stMessage);
459     ArkWebStringStructRelease(stTargetUrl);
460     ArkWebStringVectorStructRelease(stPorts);
461 }
462 
ClosePort(const std::string & port_handle)463 void ArkWebNWebWrapper::ClosePort(const std::string& port_handle)
464 {
465     ArkWebString stPort = ArkWebStringClassToStruct(port_handle);
466 
467     ark_web_nweb_->ClosePort(stPort);
468 
469     ArkWebStringStructRelease(stPort);
470 }
471 
PostPortMessage(const std::string & port_handle,std::shared_ptr<OHOS::NWeb::NWebMessage> data)472 void ArkWebNWebWrapper::PostPortMessage(const std::string& port_handle, std::shared_ptr<OHOS::NWeb::NWebMessage> data)
473 {
474     ArkWebString stPort = ArkWebStringClassToStruct(port_handle);
475 
476     ArkWebMessage ark_web_message;
477     ark_web_message.nweb_message = data;
478     ark_web_nweb_->PostPortMessage(stPort, ark_web_message);
479 
480     ArkWebStringStructRelease(stPort);
481 }
482 
SetPortMessageCallback(const std::string & port_handle,std::shared_ptr<OHOS::NWeb::NWebMessageValueCallback> callback)483 void ArkWebNWebWrapper::SetPortMessageCallback(
484     const std::string& port_handle, std::shared_ptr<OHOS::NWeb::NWebMessageValueCallback> callback)
485 {
486     ArkWebString stPort = ArkWebStringClassToStruct(port_handle);
487 
488     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
489         ark_web_nweb_->SetPortMessageCallback(stPort, nullptr);
490     } else {
491         ark_web_nweb_->SetPortMessageCallback(stPort, new ArkWebMessageValueCallbackImpl(callback));
492     }
493 
494     ArkWebStringStructRelease(stPort);
495 }
496 
SendDragEvent(std::shared_ptr<OHOS::NWeb::NWebDragEvent> drag_event)497 void ArkWebNWebWrapper::SendDragEvent(std::shared_ptr<OHOS::NWeb::NWebDragEvent> drag_event)
498 {
499     if (CHECK_SHARED_PTR_IS_NULL(drag_event)) {
500         ark_web_nweb_->SendDragEvent(nullptr);
501         return;
502     }
503 
504     ark_web_nweb_->SendDragEvent(new ArkWebDragEventImpl(drag_event));
505 }
506 
ClearSslCache()507 void ArkWebNWebWrapper::ClearSslCache()
508 {
509     ark_web_nweb_->ClearSslCache();
510 }
511 
GetUrl()512 std::string ArkWebNWebWrapper::GetUrl()
513 {
514     ArkWebString stUrl = ark_web_nweb_->GetUrl();
515 
516     std::string objUrl = ArkWebStringStructToClass(stUrl);
517     ArkWebStringStructRelease(stUrl);
518     return objUrl;
519 }
520 
ClearClientAuthenticationCache()521 void ArkWebNWebWrapper::ClearClientAuthenticationCache()
522 {
523     ark_web_nweb_->ClearClientAuthenticationCache();
524 }
525 
UpdateLocale(const std::string & language,const std::string & region)526 void ArkWebNWebWrapper::UpdateLocale(const std::string& language, const std::string& region)
527 {
528     ArkWebString stRegion = ArkWebStringClassToStruct(region);
529     ArkWebString stLanguage = ArkWebStringClassToStruct(language);
530 
531     ark_web_nweb_->UpdateLocale(stLanguage, stRegion);
532 
533     ArkWebStringStructRelease(stRegion);
534     ArkWebStringStructRelease(stLanguage);
535 }
536 
GetOriginalUrl()537 const std::string ArkWebNWebWrapper::GetOriginalUrl()
538 {
539     ArkWebString stUrl = ark_web_nweb_->GetOriginalUrl();
540 
541     std::string objUrl = ArkWebStringStructToClass(stUrl);
542     ArkWebStringStructRelease(stUrl);
543     return objUrl;
544 }
545 
GetFavicon(const void ** data,size_t & width,size_t & height,ArkWebImageColorType & color_type,ArkWebImageAlphaType & alpha_type)546 bool ArkWebNWebWrapper::GetFavicon(const void** data, size_t& width, size_t& height, ArkWebImageColorType& color_type,
547     ArkWebImageAlphaType& alpha_type)
548 {
549     int enum_color_type = static_cast<int>(ArkWebImageColorType::COLOR_TYPE_UNKNOWN);
550     int enum_alpha_type = static_cast<int>(ArkWebImageAlphaType::ALPHA_TYPE_UNKNOWN);
551     bool result = ark_web_nweb_->GetFavicon(data, width, height, enum_color_type, enum_alpha_type);
552     color_type = static_cast<ArkWebImageColorType>(enum_color_type);
553     alpha_type = static_cast<ArkWebImageAlphaType>(enum_alpha_type);
554     return result;
555 }
556 
PutNetworkAvailable(bool available)557 void ArkWebNWebWrapper::PutNetworkAvailable(bool available)
558 {
559     ark_web_nweb_->PutNetworkAvailable(available);
560 }
561 
HasImages(std::shared_ptr<OHOS::NWeb::NWebBoolValueCallback> callback)562 void ArkWebNWebWrapper::HasImages(std::shared_ptr<OHOS::NWeb::NWebBoolValueCallback> callback)
563 {
564     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
565         ark_web_nweb_->HasImages(nullptr);
566         return;
567     }
568 
569     ark_web_nweb_->HasImages(new ArkWebBoolValueCallbackImpl(callback));
570 }
571 
RemoveCache(bool include_disk_files)572 void ArkWebNWebWrapper::RemoveCache(bool include_disk_files)
573 {
574     ark_web_nweb_->RemoveCache(include_disk_files);
575 }
576 
GetHistoryList()577 std::shared_ptr<OHOS::NWeb::NWebHistoryList> ArkWebNWebWrapper::GetHistoryList()
578 {
579     ArkWebRefPtr<ArkWebHistoryList> ark_web_history_list = ark_web_nweb_->GetHistoryList();
580     if (CHECK_REF_PTR_IS_NULL(ark_web_history_list)) {
581         return nullptr;
582     }
583 
584     return std::make_shared<ArkWebHistoryListWrapper>(ark_web_history_list);
585 }
586 
PutReleaseSurfaceCallback(std::shared_ptr<OHOS::NWeb::NWebReleaseSurfaceCallback> release_surface_listener)587 void ArkWebNWebWrapper::PutReleaseSurfaceCallback(
588     std::shared_ptr<OHOS::NWeb::NWebReleaseSurfaceCallback> release_surface_listener)
589 {
590     if (CHECK_SHARED_PTR_IS_NULL(release_surface_listener)) {
591         ark_web_nweb_->PutReleaseSurfaceCallback(nullptr);
592         return;
593     }
594 
595     ark_web_nweb_->PutReleaseSurfaceCallback(new ArkWebReleaseSurfaceCallbackImpl(release_surface_listener));
596 }
597 
SerializeWebState()598 std::vector<uint8_t> ArkWebNWebWrapper::SerializeWebState()
599 {
600     ArkWebUint8Vector stState = ark_web_nweb_->SerializeWebState();
601 
602     std::vector<uint8_t> objState = ArkWebBasicVectorStructToClass<uint8_t, ArkWebUint8Vector>(stState);
603     ArkWebBasicVectorStructRelease<ArkWebUint8Vector>(stState);
604     return objState;
605 }
606 
RestoreWebState(const std::vector<uint8_t> & state)607 bool ArkWebNWebWrapper::RestoreWebState(const std::vector<uint8_t>& state)
608 {
609     ArkWebUint8Vector stState = ArkWebBasicVectorClassToStruct<uint8_t, ArkWebUint8Vector>(state);
610 
611     bool flag = ark_web_nweb_->RestoreWebState(stState);
612 
613     ArkWebBasicVectorStructRelease<ArkWebUint8Vector>(stState);
614     return flag;
615 }
616 
PageUp(bool top)617 void ArkWebNWebWrapper::PageUp(bool top)
618 {
619     ark_web_nweb_->PageUp(top);
620 }
621 
PageDown(bool bottom)622 void ArkWebNWebWrapper::PageDown(bool bottom)
623 {
624     ark_web_nweb_->PageDown(bottom);
625 }
626 
ScrollTo(float x,float y)627 void ArkWebNWebWrapper::ScrollTo(float x, float y)
628 {
629     ark_web_nweb_->ScrollTo(x, y);
630 }
631 
ScrollBy(float delta_x,float delta_y)632 void ArkWebNWebWrapper::ScrollBy(float delta_x, float delta_y)
633 {
634     ark_web_nweb_->ScrollBy(delta_x, delta_y);
635 }
636 
SlideScroll(float vx,float vy)637 void ArkWebNWebWrapper::SlideScroll(float vx, float vy)
638 {
639     ark_web_nweb_->SlideScroll(vx, vy);
640 }
641 
GetCertChainDerData(std::vector<std::string> & cert_chain_data,bool is_single_cert)642 bool ArkWebNWebWrapper::GetCertChainDerData(std::vector<std::string>& cert_chain_data, bool is_single_cert)
643 {
644     ArkWebStringVector cert_chain_data_vector;
645     bool result = ark_web_nweb_->GetCertChainDerData(cert_chain_data_vector, is_single_cert);
646     cert_chain_data = ArkWebStringVectorStructToClass(cert_chain_data_vector);
647 
648     ArkWebStringVectorStructRelease(cert_chain_data_vector);
649     return result;
650 }
651 
SetScreenOffSet(double x,double y)652 void ArkWebNWebWrapper::SetScreenOffSet(double x, double y)
653 {
654     ark_web_nweb_->SetScreenOffSet(x, y);
655 }
656 
SetAudioMuted(bool muted)657 void ArkWebNWebWrapper::SetAudioMuted(bool muted)
658 {
659     ark_web_nweb_->SetAudioMuted(muted);
660 }
661 
SetShouldFrameSubmissionBeforeDraw(bool should)662 void ArkWebNWebWrapper::SetShouldFrameSubmissionBeforeDraw(bool should)
663 {
664     ark_web_nweb_->SetShouldFrameSubmissionBeforeDraw(should);
665 }
666 
NotifyPopupWindowResult(bool result)667 void ArkWebNWebWrapper::NotifyPopupWindowResult(bool result)
668 {
669     ark_web_nweb_->NotifyPopupWindowResult(result);
670 }
671 
SetAudioResumeInterval(int32_t resume_interval)672 void ArkWebNWebWrapper::SetAudioResumeInterval(int32_t resume_interval)
673 {
674     ark_web_nweb_->SetAudioResumeInterval(resume_interval);
675 }
676 
SetAudioExclusive(bool audio_exclusive)677 void ArkWebNWebWrapper::SetAudioExclusive(bool audio_exclusive)
678 {
679     ark_web_nweb_->SetAudioExclusive(audio_exclusive);
680 }
681 
RegisterScreenLockFunction(int32_t window_id,std::shared_ptr<OHOS::NWeb::NWebScreenLockCallback> callback)682 void ArkWebNWebWrapper::RegisterScreenLockFunction(
683     int32_t window_id, std::shared_ptr<OHOS::NWeb::NWebScreenLockCallback> callback)
684 {
685     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
686         ark_web_nweb_->RegisterScreenLockFunction(window_id, nullptr);
687         return;
688     }
689 
690     ark_web_nweb_->RegisterScreenLockFunction(window_id, new ArkWebScreenLockCallbackImpl(callback));
691 }
692 
UnRegisterScreenLockFunction(int32_t window_id)693 void ArkWebNWebWrapper::UnRegisterScreenLockFunction(int32_t window_id)
694 {
695     ark_web_nweb_->UnRegisterScreenLockFunction(window_id);
696 }
697 
NotifyMemoryLevel(int32_t level)698 void ArkWebNWebWrapper::NotifyMemoryLevel(int32_t level)
699 {
700     ark_web_nweb_->NotifyMemoryLevel(level);
701 }
702 
OnWebviewHide()703 void ArkWebNWebWrapper::OnWebviewHide()
704 {
705     ark_web_nweb_->OnWebviewHide();
706 }
707 
OnWebviewShow()708 void ArkWebNWebWrapper::OnWebviewShow()
709 {
710     ark_web_nweb_->OnWebviewShow();
711 }
712 
GetOrCreateDragData()713 std::shared_ptr<OHOS::NWeb::NWebDragData> ArkWebNWebWrapper::GetOrCreateDragData()
714 {
715     ArkWebRefPtr<ArkWebDragData> ark_web_drag_data = ark_web_nweb_->GetOrCreateDragData();
716     if (CHECK_REF_PTR_IS_NULL(ark_web_drag_data)) {
717         return nullptr;
718     }
719 
720     return std::make_shared<ArkWebDragDataWrapper>(ark_web_drag_data);
721 }
722 
PrefetchPage(const std::string & url,const std::map<std::string,std::string> & additional_http_headers)723 void ArkWebNWebWrapper::PrefetchPage(
724     const std::string& url, const std::map<std::string, std::string>& additional_http_headers)
725 {
726     ArkWebString stUrl = ArkWebStringClassToStruct(url);
727     ArkWebStringMap stHeaders = ArkWebStringMapClassToStruct(additional_http_headers);
728 
729     ark_web_nweb_->PrefetchPage(stUrl, stHeaders);
730 
731     ArkWebStringStructRelease(stUrl);
732     ArkWebStringMapStructRelease(stHeaders);
733 }
734 
SetWindowId(uint32_t window_id)735 void ArkWebNWebWrapper::SetWindowId(uint32_t window_id)
736 {
737     ark_web_nweb_->SetWindowId(window_id);
738 }
739 
OnOccluded()740 void ArkWebNWebWrapper::OnOccluded()
741 {
742     ark_web_nweb_->OnOccluded();
743 }
744 
OnUnoccluded()745 void ArkWebNWebWrapper::OnUnoccluded()
746 {
747     ark_web_nweb_->OnUnoccluded();
748 }
749 
SetToken(void * token)750 void ArkWebNWebWrapper::SetToken(void* token)
751 {
752     ark_web_nweb_->SetToken(token);
753 }
754 
SetNestedScrollMode(const ArkWebNestedScrollMode & nested_scroll_mode)755 void ArkWebNWebWrapper::SetNestedScrollMode(const ArkWebNestedScrollMode& nested_scroll_mode)
756 {
757     ark_web_nweb_->SetNestedScrollMode(static_cast<int32_t>(nested_scroll_mode));
758 }
759 
SetEnableLowerFrameRate(bool enabled)760 void ArkWebNWebWrapper::SetEnableLowerFrameRate(bool enabled)
761 {
762     ark_web_nweb_->SetEnableLowerFrameRate(enabled);
763 }
764 
SetVirtualKeyBoardArg(int32_t width,int32_t height,double keyboard)765 void ArkWebNWebWrapper::SetVirtualKeyBoardArg(int32_t width, int32_t height, double keyboard)
766 {
767     ark_web_nweb_->SetVirtualKeyBoardArg(width, height, keyboard);
768 }
769 
ShouldVirtualKeyboardOverlay()770 bool ArkWebNWebWrapper::ShouldVirtualKeyboardOverlay()
771 {
772     return ark_web_nweb_->ShouldVirtualKeyboardOverlay();
773 }
774 
SetDrawRect(int32_t x,int32_t y,int32_t width,int32_t height)775 void ArkWebNWebWrapper::SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height)
776 {
777     ark_web_nweb_->SetDrawRect(x, y, width, height);
778 }
779 
SetDrawMode(int32_t mode)780 void ArkWebNWebWrapper::SetDrawMode(int32_t mode)
781 {
782     ark_web_nweb_->SetDrawMode(mode);
783 }
784 
CreateWebPrintDocumentAdapter(const std::string & job_name)785 void* ArkWebNWebWrapper::CreateWebPrintDocumentAdapter(const std::string& job_name)
786 {
787     ArkWebString stObjName = ArkWebStringClassToStruct(job_name);
788 
789     void* adapter = ark_web_nweb_->CreateWebPrintDocumentAdapter(stObjName);
790 
791     ArkWebStringStructRelease(stObjName);
792     return adapter;
793 }
794 
PostUrl(const std::string & url,const std::vector<char> & post_data)795 int ArkWebNWebWrapper::PostUrl(const std::string& url, const std::vector<char>& post_data)
796 {
797     ArkWebString stUrl = ArkWebStringClassToStruct(url);
798     ArkWebCharVector stPostData = ArkWebBasicVectorClassToStruct<char, ArkWebCharVector>(post_data);
799 
800     int code = ark_web_nweb_->PostUrl(stUrl, stPostData);
801 
802     ArkWebStringStructRelease(stUrl);
803     ArkWebBasicVectorStructRelease<ArkWebCharVector>(stPostData);
804     return code;
805 }
806 
JavaScriptOnDocumentStart(const std::map<std::string,std::vector<std::string>> & script_items)807 void ArkWebNWebWrapper::JavaScriptOnDocumentStart(const std::map<std::string, std::vector<std::string>>& script_items)
808 {
809     ArkWebStringVectorMap stScriptItems = ArkWebStringVectorMapClassToStruct(script_items);
810 
811     ark_web_nweb_->JavaScriptOnDocumentStart(stScriptItems);
812 
813     ArkWebStringVectorMapStructRelease(stScriptItems);
814 }
815 
ExecuteAction(int64_t accessibility_id,uint32_t action)816 void ArkWebNWebWrapper::ExecuteAction(int64_t accessibility_id, uint32_t action)
817 {
818     ark_web_nweb_->ExecuteAction(accessibility_id, action);
819 }
820 
GetFocusedAccessibilityNodeInfo(int64_t accessibility_id,bool is_accessibility_focus)821 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> ArkWebNWebWrapper::GetFocusedAccessibilityNodeInfo(
822     int64_t accessibility_id, bool is_accessibility_focus)
823 {
824     ArkWebRefPtr<ArkWebAccessibilityNodeInfo> ark_web_accessibility_node_info =
825         ark_web_nweb_->GetFocusedAccessibilityNodeInfo(accessibility_id, is_accessibility_focus);
826     if (CHECK_REF_PTR_IS_NULL(ark_web_accessibility_node_info)) {
827         return nullptr;
828     }
829 
830     return std::make_shared<ArkWebAccessibilityNodeInfoWrapper>(ark_web_accessibility_node_info);
831 }
832 
GetAccessibilityNodeInfoById(int64_t accessibility_id)833 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> ArkWebNWebWrapper::GetAccessibilityNodeInfoById(
834     int64_t accessibility_id)
835 {
836     ArkWebRefPtr<ArkWebAccessibilityNodeInfo> ark_web_accessibility_node_info =
837         ark_web_nweb_->GetAccessibilityNodeInfoById(accessibility_id);
838     if (CHECK_REF_PTR_IS_NULL(ark_web_accessibility_node_info)) {
839         return nullptr;
840     }
841 
842     return std::make_shared<ArkWebAccessibilityNodeInfoWrapper>(ark_web_accessibility_node_info);
843 }
844 
GetAccessibilityNodeInfoByFocusMove(int64_t accessibility_id,int32_t direction)845 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> ArkWebNWebWrapper::GetAccessibilityNodeInfoByFocusMove(
846     int64_t accessibility_id, int32_t direction)
847 {
848     ArkWebRefPtr<ArkWebAccessibilityNodeInfo> ark_web_accessibility_node_info =
849         ark_web_nweb_->GetAccessibilityNodeInfoByFocusMove(accessibility_id, direction);
850     if (CHECK_REF_PTR_IS_NULL(ark_web_accessibility_node_info)) {
851         return nullptr;
852     }
853 
854     return std::make_shared<ArkWebAccessibilityNodeInfoWrapper>(ark_web_accessibility_node_info);
855 }
856 
SetAccessibilityState(bool state)857 void ArkWebNWebWrapper::SetAccessibilityState(bool state)
858 {
859     ark_web_nweb_->SetAccessibilityState(state);
860 }
861 
NeedSoftKeyboard()862 bool ArkWebNWebWrapper::NeedSoftKeyboard()
863 {
864     return ark_web_nweb_->NeedSoftKeyboard();
865 }
866 
Discard()867 bool ArkWebNWebWrapper::Discard()
868 {
869     return ark_web_nweb_->Discard();
870 }
871 
Restore()872 bool ArkWebNWebWrapper::Restore()
873 {
874     return ark_web_nweb_->Restore();
875 }
876 
GetSecurityLevel()877 int ArkWebNWebWrapper::GetSecurityLevel()
878 {
879     return ark_web_nweb_->GetSecurityLevel();
880 }
881 
CallH5Function(int32_t routingId,int32_t h5ObjectId,const std::string & h5MethodName,const std::vector<std::shared_ptr<OHOS::NWeb::NWebValue>> & args)882 void ArkWebNWebWrapper::CallH5Function(int32_t routingId, int32_t h5ObjectId, const std::string& h5MethodName,
883     const std::vector<std::shared_ptr<OHOS::NWeb::NWebValue>>& args)
884 {
885     ArkWebString stName = ArkWebStringClassToStruct(h5MethodName);
886     ArkWebValueVector stArgs = ArkWebValueVectorClassToStruct(args);
887 
888     ark_web_nweb_->CallH5Function(routingId, h5ObjectId, stName, stArgs);
889 
890     ArkWebStringStructRelease(stName);
891     ArkWebValueVectorStructRelease(stArgs);
892 }
893 
IsIncognitoMode()894 bool ArkWebNWebWrapper::IsIncognitoMode()
895 {
896     return ark_web_nweb_->IsIncognitoMode();
897 }
898 
RegisterNativeArkJSFunction(const char * objName,const std::vector<std::shared_ptr<OHOS::NWeb::NWebJsProxyCallback>> & callbacks)899 void ArkWebNWebWrapper::RegisterNativeArkJSFunction(
900     const char* objName, const std::vector<std::shared_ptr<OHOS::NWeb::NWebJsProxyCallback>>& callbacks)
901 {
902     ArkWebJsProxyCallbackVector stJsProxyCallbackVector = ArkWebJsProxyCallbackVectorClassToStruct(callbacks);
903 
904     ark_web_nweb_->RegisterNativeArkJSFunction(objName, stJsProxyCallbackVector);
905 
906     ArkWebJsProxyCallbackVectorStructRelease(stJsProxyCallbackVector);
907 }
908 
UnRegisterNativeArkJSFunction(const char * objName)909 void ArkWebNWebWrapper::UnRegisterNativeArkJSFunction(const char* objName)
910 {
911     ark_web_nweb_->UnRegisterNativeArkJSFunction(objName);
912 }
913 
RegisterNativeValideCallback(const char * webName,const NativeArkWebOnValidCallback callback)914 void ArkWebNWebWrapper::RegisterNativeValideCallback(const char* webName, const NativeArkWebOnValidCallback callback)
915 {
916     ark_web_nweb_->RegisterNativeValideCallback(webName, callback);
917 }
918 
RegisterNativeDestroyCallback(const char * webName,const NativeArkWebOnValidCallback callback)919 void ArkWebNWebWrapper::RegisterNativeDestroyCallback(const char* webName, const NativeArkWebOnValidCallback callback)
920 {
921     ark_web_nweb_->RegisterNativeDestroyCallback(webName, callback);
922 }
923 
JavaScriptOnDocumentEnd(const std::map<std::string,std::vector<std::string>> & script_items)924 void ArkWebNWebWrapper::JavaScriptOnDocumentEnd(const std::map<std::string, std::vector<std::string>>& script_items)
925 {
926     ArkWebStringVectorMap stScriptItems = ArkWebStringVectorMapClassToStruct(script_items);
927 
928     ark_web_nweb_->JavaScriptOnDocumentEnd(stScriptItems);
929 
930     ArkWebStringVectorMapStructRelease(stScriptItems);
931 }
932 
EnableSafeBrowsing(bool enable)933 void ArkWebNWebWrapper::EnableSafeBrowsing(bool enable)
934 {
935     ark_web_nweb_->EnableSafeBrowsing(enable);
936 }
937 
IsSafeBrowsingEnabled()938 bool ArkWebNWebWrapper::IsSafeBrowsingEnabled()
939 {
940     return ark_web_nweb_->IsSafeBrowsingEnabled();
941 }
942 
SetPrintBackground(bool enable)943 void ArkWebNWebWrapper::SetPrintBackground(bool enable)
944 {
945     ark_web_nweb_->SetPrintBackground(enable);
946 }
947 
GetPrintBackground()948 bool ArkWebNWebWrapper::GetPrintBackground()
949 {
950     return ark_web_nweb_->GetPrintBackground();
951 }
952 
CloseAllMediaPresentations()953 void ArkWebNWebWrapper::CloseAllMediaPresentations()
954 {
955     ark_web_nweb_->CloseAllMediaPresentations();
956 }
957 
StopAllMedia()958 void ArkWebNWebWrapper::StopAllMedia()
959 {
960     ark_web_nweb_->StopAllMedia();
961 }
962 
ResumeAllMedia()963 void ArkWebNWebWrapper::ResumeAllMedia()
964 {
965     ark_web_nweb_->ResumeAllMedia();
966 }
967 
PauseAllMedia()968 void ArkWebNWebWrapper::PauseAllMedia()
969 {
970     ark_web_nweb_->PauseAllMedia();
971 }
972 
GetMediaPlaybackState()973 int ArkWebNWebWrapper::GetMediaPlaybackState()
974 {
975     return ark_web_nweb_->GetMediaPlaybackState();
976 }
977 
EnableIntelligentTrackingPrevention(bool enable)978 void ArkWebNWebWrapper::EnableIntelligentTrackingPrevention(bool enable)
979 {
980     ark_web_nweb_->EnableIntelligentTrackingPrevention(enable);
981 }
982 
IsIntelligentTrackingPreventionEnabled() const983 bool ArkWebNWebWrapper::IsIntelligentTrackingPreventionEnabled() const
984 {
985     return ark_web_nweb_->IsIntelligentTrackingPreventionEnabled();
986 }
987 
StartCamera()988 void ArkWebNWebWrapper::StartCamera()
989 {
990     ark_web_nweb_->StartCamera();
991 }
992 
StopCamera()993 void ArkWebNWebWrapper::StopCamera()
994 {
995     ark_web_nweb_->StopCamera();
996 }
997 
CloseCamera()998 void ArkWebNWebWrapper::CloseCamera()
999 {
1000     ark_web_nweb_->CloseCamera();
1001 }
1002 
GetLastJavascriptProxyCallingFrameUrl()1003 std::string ArkWebNWebWrapper::GetLastJavascriptProxyCallingFrameUrl()
1004 {
1005     return ArkWebStringStructToClass(ark_web_nweb_->GetLastJavascriptProxyCallingFrameUrl());
1006 }
1007 
GetPendingSizeStatus()1008 bool ArkWebNWebWrapper::GetPendingSizeStatus()
1009 {
1010     return ark_web_nweb_->GetPendingSizeStatus();
1011 }
1012 
ScrollByRefScreen(float delta_x,float delta_y,float vx,float vy)1013 void ArkWebNWebWrapper::ScrollByRefScreen(float delta_x, float delta_y, float vx, float vy)
1014 {
1015     ark_web_nweb_->ScrollByRefScreen(delta_x, delta_y, vx, vy);
1016 }
1017 
ExecuteJavaScriptExt(const int fd,const size_t scriptLength,std::shared_ptr<OHOS::NWeb::NWebMessageValueCallback> callback,bool extention)1018 void ArkWebNWebWrapper::ExecuteJavaScriptExt(const int fd, const size_t scriptLength,
1019     std::shared_ptr<OHOS::NWeb::NWebMessageValueCallback> callback, bool extention)
1020 {
1021     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
1022         ark_web_nweb_->ExecuteJavaScriptExt(fd, scriptLength, nullptr, extention);
1023     } else {
1024         ark_web_nweb_->ExecuteJavaScriptExt(fd, scriptLength, new ArkWebMessageValueCallbackImpl(callback), extention);
1025     }
1026 }
1027 
OnRenderToBackground()1028 void ArkWebNWebWrapper::OnRenderToBackground()
1029 {
1030     ark_web_nweb_->OnRenderToBackground();
1031 }
1032 
OnRenderToForeground()1033 void ArkWebNWebWrapper::OnRenderToForeground()
1034 {
1035     ark_web_nweb_->OnRenderToForeground();
1036 }
1037 
PrecompileJavaScript(const std::string & url,const std::string & script,std::shared_ptr<OHOS::NWeb::CacheOptions> & cacheOptions,std::shared_ptr<OHOS::NWeb::NWebMessageValueCallback> callback)1038 void ArkWebNWebWrapper::PrecompileJavaScript(const std::string& url, const std::string& script,
1039     std::shared_ptr<OHOS::NWeb::CacheOptions>& cacheOptions,
1040     std::shared_ptr<OHOS::NWeb::NWebMessageValueCallback> callback)
1041 {
1042     ArkWebString ark_url = ArkWebStringClassToStruct(url);
1043     ArkWebString ark_script = ArkWebStringClassToStruct(script);
1044     ArkWebRefPtr<ArkWebCacheOptions> options = new ArkWebCacheOptionsImpl(cacheOptions);
1045     ark_web_nweb_->PrecompileJavaScript(ark_url, ark_script, options, new ArkWebMessageValueCallbackImpl(callback));
1046     ArkWebStringStructRelease(ark_url);
1047     ArkWebStringStructRelease(ark_script);
1048 }
1049 
OnCreateNativeMediaPlayer(std::shared_ptr<OHOS::NWeb::NWebCreateNativeMediaPlayerCallback> callback)1050 void ArkWebNWebWrapper::OnCreateNativeMediaPlayer(
1051     std::shared_ptr<OHOS::NWeb::NWebCreateNativeMediaPlayerCallback> callback)
1052 {
1053     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
1054         return;
1055     }
1056 
1057     ark_web_nweb_->OnCreateNativeMediaPlayer(new ArkWebCreateNativeMediaPlayerCallbackImpl(callback));
1058 }
1059 
SendTouchpadFlingEvent(double x,double y,double vx,double vy)1060 void ArkWebNWebWrapper::SendTouchpadFlingEvent(double x, double y, double vx, double vy)
1061 {
1062     ark_web_nweb_->SendTouchpadFlingEvent(x, y, vx, vy);
1063 }
1064 
InjectOfflineResource(const std::string & url,const std::string & origin,const std::vector<uint8_t> & resource,const std::map<std::string,std::string> & responseHeaders,const int type)1065 void ArkWebNWebWrapper::InjectOfflineResource(const std::string& url, const std::string& origin,
1066     const std::vector<uint8_t>& resource, const std::map<std::string, std::string>& responseHeaders, const int type)
1067 {
1068     ArkWebString arkUrl = ArkWebStringClassToStruct(url);
1069     ArkWebString arkOrigin = ArkWebStringClassToStruct(origin);
1070 
1071     auto responseHeadersMap = ArkWebStringMapClassToStruct(responseHeaders);
1072 
1073     ArkWebUint8Vector arkResource = ArkWebBasicVectorClassToStruct<uint8_t, ArkWebUint8Vector>(resource);
1074 
1075     ark_web_nweb_->InjectOfflineResource(arkUrl, arkOrigin, arkResource, responseHeadersMap, type);
1076 
1077     ArkWebStringStructRelease(arkUrl);
1078     ArkWebStringStructRelease(arkOrigin);
1079     ArkWebBasicVectorStructRelease<ArkWebUint8Vector>(arkResource);
1080     ArkWebStringMapStructRelease(responseHeadersMap);
1081 }
1082 
RegisterArkJSfunction(const std::string & object_name,const std::vector<std::string> & method_list,const std::vector<std::string> & async_method_list,const int32_t object_id)1083 void ArkWebNWebWrapper::RegisterArkJSfunction(const std::string& object_name,
1084     const std::vector<std::string>& method_list, const std::vector<std::string>& async_method_list,
1085     const int32_t object_id)
1086 {
1087     ArkWebString stName = ArkWebStringClassToStruct(object_name);
1088     ArkWebStringVector stMethods = ArkWebStringVectorClassToStruct(method_list);
1089     ArkWebStringVector stAsyncMethods = ArkWebStringVectorClassToStruct(async_method_list);
1090 
1091     ark_web_nweb_->RegisterArkJSfunction(stName, stMethods, stAsyncMethods, object_id);
1092 
1093     ArkWebStringStructRelease(stName);
1094     ArkWebStringVectorStructRelease(stMethods);
1095     ArkWebStringVectorStructRelease(stAsyncMethods);
1096 }
1097 
SetFitContentMode(int32_t mode)1098 void ArkWebNWebWrapper::SetFitContentMode(int32_t mode)
1099 {
1100     ark_web_nweb_->SetFitContentMode(mode);
1101 }
1102 
TerminateRenderProcess()1103 bool ArkWebNWebWrapper::TerminateRenderProcess()
1104 {
1105     return ark_web_nweb_->TerminateRenderProcess();
1106 }
1107 
GetSelectInfo()1108 std::string ArkWebNWebWrapper::GetSelectInfo()
1109 {
1110     return ArkWebStringStructToClass(ark_web_nweb_->GetSelectInfo());
1111 }
1112 
OnOnlineRenderToForeground()1113 void ArkWebNWebWrapper::OnOnlineRenderToForeground()
1114 {
1115     ark_web_nweb_->OnOnlineRenderToForeground();
1116 }
1117 
ScaleGestureChange(double scale,double centerX,double centerY)1118 int ArkWebNWebWrapper::ScaleGestureChange(double scale, double centerX, double centerY)
1119 {
1120     return ark_web_nweb_->ScaleGestureChange(scale, centerX, centerY);
1121 }
1122 
SuggestionSelected(int32_t index)1123 void ArkWebNWebWrapper::SuggestionSelected(int32_t index)
1124 {
1125     ark_web_nweb_->SuggestionSelected(index);
1126 }
1127 
OnSafeInsetsChange(int left,int top,int right,int bottom)1128 void ArkWebNWebWrapper::OnSafeInsetsChange(int left, int top, int right, int bottom)
1129 {
1130     ark_web_nweb_->OnSafeInsetsChange(left, top, right, bottom);
1131 }
1132 
OnTextSelected()1133 void ArkWebNWebWrapper::OnTextSelected()
1134 {
1135     ark_web_nweb_->OnTextSelected();
1136 }
1137 
NotifyForNextTouchEvent()1138 void ArkWebNWebWrapper::NotifyForNextTouchEvent()
1139 {
1140     ark_web_nweb_->NotifyForNextTouchEvent();
1141 }
1142 
EnableAdsBlock(bool enable)1143 void ArkWebNWebWrapper::EnableAdsBlock(bool enable)
1144 {
1145     ark_web_nweb_->EnableAdsBlock(enable);
1146 }
1147 
IsAdsBlockEnabled()1148 bool ArkWebNWebWrapper::IsAdsBlockEnabled()
1149 {
1150     return ark_web_nweb_->IsAdsBlockEnabled();
1151 }
1152 
IsAdsBlockEnabledForCurPage()1153 bool ArkWebNWebWrapper::IsAdsBlockEnabledForCurPage()
1154 {
1155     return ark_web_nweb_->IsAdsBlockEnabledForCurPage();
1156 }
1157 
WebPageSnapshot(const char * id,ArkPixelUnit type,int width,int height,const WebSnapshotCallback callback)1158 bool ArkWebNWebWrapper::WebPageSnapshot(const char* id,
1159                                         ArkPixelUnit type,
1160                                         int width,
1161                                         int height,
1162                                         const WebSnapshotCallback callback)
1163 {
1164     return ark_web_nweb_->WebPageSnapshot(id, static_cast<int>(type), width, height, callback);
1165 }
1166 
OnConfigurationUpdated(std::shared_ptr<OHOS::NWeb::NWebSystemConfiguration> configuration)1167 void ArkWebNWebWrapper::OnConfigurationUpdated(std::shared_ptr<OHOS::NWeb::NWebSystemConfiguration> configuration)
1168 {
1169     if (CHECK_SHARED_PTR_IS_NULL(configuration)) {
1170         ark_web_nweb_->OnConfigurationUpdated(nullptr);
1171         return;
1172     }
1173 
1174     ark_web_nweb_->OnConfigurationUpdated(new ArkWebSystemConfigurationImpl(configuration));
1175 }
1176 
SetUrlTrustListWithErrMsg(const std::string & urlTrustList,std::string & detailErrMsg)1177 int ArkWebNWebWrapper::SetUrlTrustListWithErrMsg(
1178     const std::string& urlTrustList, std::string& detailErrMsg)
1179 {
1180     ArkWebString stUrlTrustList = ArkWebStringClassToStruct(urlTrustList);
1181     ArkWebString stDetailErrMsg = ark_web_string_default;
1182     int res = ark_web_nweb_->SetUrlTrustListWithErrMsg(stUrlTrustList, stDetailErrMsg);
1183     detailErrMsg = ArkWebStringStructToClass(stDetailErrMsg);
1184     ArkWebStringStructRelease(stUrlTrustList);
1185     ArkWebStringStructRelease(stDetailErrMsg);
1186     return res;
1187 }
1188 
PutSpanstringConvertHtmlCallback(std::shared_ptr<OHOS::NWeb::NWebSpanstringConvertHtmlCallback> callback)1189 void ArkWebNWebWrapper::PutSpanstringConvertHtmlCallback(
1190     std::shared_ptr<OHOS::NWeb::NWebSpanstringConvertHtmlCallback> callback)
1191 {
1192     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
1193         ark_web_nweb_->PutSpanstringConvertHtmlCallback(nullptr);
1194         return;
1195     }
1196 
1197     ark_web_nweb_->PutSpanstringConvertHtmlCallback(
1198         new ArkWebSpanstringConvertHtmlCallbackImpl(callback));
1199 }
1200 
SetUrlTrustList(const std::string & urlTrustList)1201 int ArkWebNWebWrapper::SetUrlTrustList(const std::string& urlTrustList)
1202 {
1203     ArkWebString stUrlTrustList = ArkWebStringClassToStruct(urlTrustList);
1204     int res = ark_web_nweb_->SetUrlTrustList(stUrlTrustList);
1205     ArkWebStringStructRelease(stUrlTrustList);
1206     return res;
1207 }
1208 
WebSendKeyEvent(int32_t key_code,int32_t key_action,const std::vector<int32_t> & pressedCodes)1209 bool ArkWebNWebWrapper::WebSendKeyEvent(int32_t key_code, int32_t key_action, const std::vector<int32_t>& pressedCodes)
1210 {
1211     ArkWebInt32Vector pCodes = ArkWebBasicVectorClassToStruct<int32_t, ArkWebInt32Vector>(pressedCodes);
1212 
1213     bool result = ark_web_nweb_->WebSendKeyEvent(key_code, key_action, pCodes);
1214 
1215     ArkWebBasicVectorStructRelease<ArkWebInt32Vector>(pCodes);
1216     return result;
1217 }
1218 
SetPathAllowingUniversalAccess(const std::vector<std::string> & dirs,const std::vector<std::string> & moduleName,std::string & errorPath)1219 void ArkWebNWebWrapper::SetPathAllowingUniversalAccess(
1220     const std::vector<std::string>& dirs,
1221     const std::vector<std::string>& moduleName,
1222     std::string& errorPath)
1223 {
1224     ArkWebStringVector stDirs = ArkWebStringVectorClassToStruct(dirs);
1225     ArkWebStringVector stModuleName = ArkWebStringVectorClassToStruct(moduleName);
1226     ArkWebString stErrorPath = ark_web_string_default;
1227 
1228     ark_web_nweb_->SetPathAllowingUniversalAccess(stDirs, stModuleName, stErrorPath);
1229 
1230     errorPath = ArkWebStringStructToClass(stErrorPath);
1231     ArkWebStringVectorStructRelease(stDirs);
1232     ArkWebStringVectorStructRelease(stModuleName);
1233     ArkWebStringStructRelease(stErrorPath);
1234 }
1235 
WebSendMouseWheelEvent(double x,double y,double delta_x,double delta_y,const std::vector<int32_t> & pressedCodes)1236 void ArkWebNWebWrapper::WebSendMouseWheelEvent(double x,
1237                                                double y,
1238                                                double delta_x,
1239                                                double delta_y,
1240                                                const std::vector<int32_t>& pressedCodes)
1241 {
1242     ArkWebInt32Vector pCodes = ArkWebBasicVectorClassToStruct<int32_t, ArkWebInt32Vector>(pressedCodes);
1243 
1244     ark_web_nweb_->WebSendMouseWheelEvent(x, y, delta_x, delta_y, pCodes);
1245 
1246     ArkWebBasicVectorStructRelease<ArkWebInt32Vector>(pCodes);
1247 }
1248 
WebSendTouchpadFlingEvent(double x,double y,double vx,double vy,const std::vector<int32_t> & pressedCodes)1249 void ArkWebNWebWrapper::WebSendTouchpadFlingEvent(double x,
1250                                                   double y,
1251                                                   double vx,
1252                                                   double vy,
1253                                                   const std::vector<int32_t>& pressedCodes)
1254 {
1255     ArkWebInt32Vector pCodes = ArkWebBasicVectorClassToStruct<int32_t, ArkWebInt32Vector>(pressedCodes);
1256 
1257     ark_web_nweb_->WebSendTouchpadFlingEvent(x, y, vx, vy, pCodes);
1258 
1259     ArkWebBasicVectorStructRelease<ArkWebInt32Vector>(pCodes);
1260 }
1261 
ResizeVisibleViewport(uint32_t width,uint32_t height,bool isKeyboard)1262 void ArkWebNWebWrapper::ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard)
1263 {
1264     ark_web_nweb_->ResizeVisibleViewport(width, height, isKeyboard);
1265 }
1266 
SetBackForwardCacheOptions(int32_t size,int32_t timeToLive)1267 void ArkWebNWebWrapper::SetBackForwardCacheOptions(int32_t size, int32_t timeToLive)
1268 {
1269     ark_web_nweb_->SetBackForwardCacheOptions(size, timeToLive);
1270 }
1271 
RegisterArkJSfunctionV2(const std::string & object_name,const std::vector<std::string> & method_list,const std::vector<std::string> & async_method_list,const int32_t object_id,const std::string & permission)1272 void ArkWebNWebWrapper::RegisterArkJSfunctionV2(const std::string& object_name,
1273     const std::vector<std::string>& method_list, const std::vector<std::string>& async_method_list,
1274     const int32_t object_id,
1275     const std::string& permission)
1276 {
1277     ArkWebString stName = ArkWebStringClassToStruct(object_name);
1278     ArkWebStringVector stMethods = ArkWebStringVectorClassToStruct(method_list);
1279     ArkWebStringVector stAsyncMethods = ArkWebStringVectorClassToStruct(async_method_list);
1280     ArkWebString stPermission = ArkWebStringClassToStruct(permission);
1281 
1282     ark_web_nweb_->RegisterArkJSfunctionV2(stName, stMethods, stAsyncMethods, object_id, stPermission);
1283 
1284     ArkWebStringStructRelease(stName);
1285     ArkWebStringVectorStructRelease(stMethods);
1286     ArkWebStringVectorStructRelease(stAsyncMethods);
1287     ArkWebStringStructRelease(stPermission);
1288 }
1289 
SetAutofillCallback(std::shared_ptr<OHOS::NWeb::NWebMessageValueCallback> callback)1290 void ArkWebNWebWrapper::SetAutofillCallback(std::shared_ptr<OHOS::NWeb::NWebMessageValueCallback> callback)
1291 {
1292     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
1293         ark_web_nweb_->SetAutofillCallback(nullptr);
1294     } else {
1295         ark_web_nweb_->SetAutofillCallback(new ArkWebMessageValueCallbackImpl(callback));
1296     }
1297 }
1298 
FillAutofillData(std::shared_ptr<OHOS::NWeb::NWebMessage> data)1299 void ArkWebNWebWrapper::FillAutofillData(std::shared_ptr<OHOS::NWeb::NWebMessage> data)
1300 {
1301     ArkWebMessage ark_web_message;
1302     ark_web_message.nweb_message = data;
1303     ark_web_nweb_->FillAutofillData(ark_web_message);
1304 }
1305 
OnAutofillCancel(const std::string & fillContent)1306 void ArkWebNWebWrapper::OnAutofillCancel(const std::string& fillContent)
1307 {
1308     ArkWebString stFillContent = ArkWebStringClassToStruct(fillContent);
1309 
1310     ark_web_nweb_->OnAutofillCancel(stFillContent);
1311 
1312     ArkWebStringStructRelease(stFillContent);
1313 }
1314 
PerformAction(int64_t accessibility_id,uint32_t action,const std::map<std::string,std::string> & actionArguments)1315 void ArkWebNWebWrapper::PerformAction(int64_t accessibility_id, uint32_t action,
1316     const std::map<std::string, std::string>& actionArguments)
1317 {
1318     ArkWebStringMap stArguments = ArkWebStringMapClassToStruct(actionArguments);
1319     ark_web_nweb_->PerformAction(accessibility_id, action, stArguments);
1320 
1321     ArkWebStringMapStructRelease(stArguments);
1322 }
1323 
SendAccessibilityHoverEvent(int32_t x,int32_t y)1324 void ArkWebNWebWrapper::SendAccessibilityHoverEvent(int32_t x, int32_t y)
1325 {
1326     ark_web_nweb_->SendAccessibilityHoverEvent(x, y);
1327 }
1328 
ScrollByWithResult(float delta_x,float delta_y)1329 bool ArkWebNWebWrapper::ScrollByWithResult(float delta_x, float delta_y)
1330 {
1331     return ark_web_nweb_->ScrollByWithResult(delta_x, delta_y);
1332 }
1333 
OnDestroyImageAnalyzerOverlay()1334 void ArkWebNWebWrapper::OnDestroyImageAnalyzerOverlay()
1335 {
1336     ark_web_nweb_->OnDestroyImageAnalyzerOverlay();
1337 }
1338 
GetScrollOffset(float * offset_x,float * offset_y)1339 void ArkWebNWebWrapper::GetScrollOffset(float* offset_x, float* offset_y)
1340 {
1341     ark_web_nweb_->GetScrollOffset(offset_x, offset_y);
1342 }
1343 
SetSurfaceDensity(const double & density)1344 void ArkWebNWebWrapper::SetSurfaceDensity(const double& density)
1345 {
1346     ark_web_nweb_->SetSurfaceDensity(density);
1347 }
1348 
GetAccessibilityVisible(int64_t accessibility_id)1349 bool ArkWebNWebWrapper::GetAccessibilityVisible(int64_t accessibility_id)
1350 {
1351     return ark_web_nweb_->GetAccessibilityVisible(accessibility_id);
1352 }
1353 
WebComponentsBlur()1354 void ArkWebNWebWrapper::WebComponentsBlur()
1355 {
1356     ark_web_nweb_->WebComponentsBlur();
1357 }
1358 
ScrollToWithAnime(float x,float y,int32_t duration)1359 void ArkWebNWebWrapper::ScrollToWithAnime(float x, float y, int32_t duration)
1360 {
1361     ark_web_nweb_->ScrollToWithAnime(x, y, duration);
1362 }
1363 
ScrollByWithAnime(float delta_x,float delta_y,int32_t duration)1364 void ArkWebNWebWrapper::ScrollByWithAnime(float delta_x, float delta_y, int32_t duration)
1365 {
1366     ark_web_nweb_->ScrollByWithAnime(delta_x, delta_y, duration);
1367 }
1368 
ExecuteCreatePDFExt(std::shared_ptr<OHOS::NWeb::NWebPDFConfigArgs> pdfConfig,std::shared_ptr<OHOS::NWeb::NWebArrayBufferValueCallback> callback)1369 void ArkWebNWebWrapper::ExecuteCreatePDFExt(std::shared_ptr<OHOS::NWeb::NWebPDFConfigArgs> pdfConfig,
1370     std::shared_ptr<OHOS::NWeb::NWebArrayBufferValueCallback> callback)
1371 {
1372     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
1373         ark_web_nweb_->ExecuteCreatePDFExt(
1374             new ArkWebPDFConfigArgsImpl(CHECK_SHARED_PTR_IS_NULL(pdfConfig) ? nullptr : pdfConfig), nullptr);
1375     } else {
1376         ark_web_nweb_->ExecuteCreatePDFExt(
1377             new ArkWebPDFConfigArgsImpl(CHECK_SHARED_PTR_IS_NULL(pdfConfig) ? nullptr : pdfConfig),
1378             new ArkWebArrayBufferValueCallbackImpl(callback));
1379     }
1380 }
1381 } // namespace OHOS::ArkWeb
1382