1 /*
2 * Copyright (c) 2022-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 "core/components/web/resource/web_client_impl.h"
17
18 #include "core/common/container.h"
19 #include "core/components/web/resource/web_delegate.h"
20
21 namespace OHOS::Ace {
22 class NWebResponseAsyncHandle : public WebResponseAsyncHandle {
23 DECLARE_ACE_TYPE(NWebResponseAsyncHandle, WebResponseAsyncHandle);
24 public:
NWebResponseAsyncHandle(std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> nwebResponse)25 explicit NWebResponseAsyncHandle(std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> nwebResponse)
26 :nwebResponse_(nwebResponse) {}
27 ~NWebResponseAsyncHandle() = default;
HandleFileFd(int32_t fd)28 void HandleFileFd(int32_t fd) override
29 {
30 if (nwebResponse_ == nullptr) {
31 return;
32 }
33 nwebResponse_->PutResponseFileHandle(fd);
34 }
35
HandleData(std::string & data)36 void HandleData(std::string& data) override
37 {
38 if (nwebResponse_ == nullptr) {
39 return;
40 }
41 nwebResponse_->PutResponseData(data);
42 }
43
HandleResourceUrl(std::string & url)44 void HandleResourceUrl(std::string& url) override
45 {
46 CHECK_NULL_VOID(nwebResponse_);
47 nwebResponse_->PutResponseResourceUrl(url);
48 }
49
HandleHeadersVal(const std::map<std::string,std::string> & response_headers)50 void HandleHeadersVal(const std::map<std::string, std::string>& response_headers) override
51 {
52 if (nwebResponse_ == nullptr) {
53 return;
54 }
55 nwebResponse_->PutResponseHeaders(response_headers);
56 }
57
HandleEncoding(std::string & encoding)58 void HandleEncoding(std::string& encoding) override
59 {
60 if (nwebResponse_ == nullptr) {
61 return;
62 }
63 nwebResponse_->PutResponseEncoding(encoding);
64 }
65
HandleMimeType(std::string & mimeType)66 void HandleMimeType(std::string& mimeType) override
67 {
68 if (nwebResponse_ == nullptr) {
69 return;
70 }
71 nwebResponse_->PutResponseMimeType(mimeType);
72 }
73
HandleStatusCodeAndReason(int32_t statusCode,std::string & reason)74 void HandleStatusCodeAndReason(int32_t statusCode, std::string& reason) override
75 {
76 if (nwebResponse_ == nullptr) {
77 return;
78 }
79 nwebResponse_->PutResponseStateAndStatuscode(statusCode, reason);
80 }
81
HandleResponseStatus(bool isReady)82 void HandleResponseStatus(bool isReady) override
83 {
84 if (nwebResponse_ == nullptr) {
85 return;
86 }
87 nwebResponse_->PutResponseDataStatus(isReady);
88 }
89
90 private:
91 std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> nwebResponse_;
92 };
93
OnJsCommonDialog(const WebClientImpl * webClientImpl,DialogEventType dialogEventType,std::shared_ptr<NWeb::NWebJSDialogResult> result,const std::string & url,const std::string & message,const std::string & value="")94 bool OnJsCommonDialog(
95 const WebClientImpl* webClientImpl,
96 DialogEventType dialogEventType,
97 std::shared_ptr<NWeb::NWebJSDialogResult> result,
98 const std::string &url,
99 const std::string &message,
100 const std::string &value = "")
101 {
102 bool jsResult = false;
103 auto param = std::make_shared<WebDialogEvent>(url, message, value, dialogEventType,
104 AceType::MakeRefPtr<ResultOhos>(result));
105 auto task = Container::CurrentTaskExecutor();
106 if (task == nullptr) {
107 return false;
108 }
109 task->PostSyncTask(
110 [&webClientImpl, dialogEventType, ¶m, &jsResult] {
111 if (webClientImpl == nullptr) {
112 return;
113 }
114 auto delegate = webClientImpl->GetWebDelegate();
115 if (delegate) {
116 jsResult = delegate->OnCommonDialog(param, dialogEventType);
117 }
118 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientCommonDialogEvent");
119 return jsResult;
120 }
121
OnDownloadStart(const std::string & url,const std::string & userAgent,const std::string & contentDisposition,const std::string & mimetype,long contentLength)122 void DownloadListenerImpl::OnDownloadStart(const std::string& url, const std::string& userAgent,
123 const std::string& contentDisposition, const std::string& mimetype, long contentLength)
124 {
125 auto delegate = webDelegate_.Upgrade();
126 if (!delegate) {
127 return;
128 }
129 ContainerScope scope(delegate->GetInstanceId());
130 delegate->OnDownloadStart(url, userAgent, contentDisposition, mimetype, contentLength);
131 }
132
OnFindResultReceived(const int activeMatchOrdinal,const int numberOfMatches,const bool isDoneCounting)133 void FindListenerImpl::OnFindResultReceived(
134 const int activeMatchOrdinal, const int numberOfMatches, const bool isDoneCounting)
135 {
136 auto delegate = webDelegate_.Upgrade();
137 if (!delegate) {
138 return;
139 }
140 ContainerScope scope(delegate->GetInstanceId());
141 delegate->OnSearchResultReceive(activeMatchOrdinal, numberOfMatches, isDoneCounting);
142 }
143
SpanstringConvertHtml(const std::vector<uint8_t> & content)144 std::string SpanstringConvertHtmlImpl::SpanstringConvertHtml(const std::vector<uint8_t> &content)
145 {
146 ContainerScope scope(instanceId_);
147 auto delegate = webDelegate_.Upgrade();
148 if (!delegate) {
149 return "";
150 }
151 return delegate->SpanstringConvertHtml(content);
152 }
153
OnPageLoadEnd(int httpStatusCode,const std::string & url)154 void WebClientImpl::OnPageLoadEnd(int httpStatusCode, const std::string& url)
155 {
156 auto delegate = webDelegate_.Upgrade();
157 if (!delegate) {
158 return;
159 }
160 ContainerScope scope(delegate->GetInstanceId());
161 delegate->OnPageFinished(url);
162 }
163
OnFocus()164 bool WebClientImpl::OnFocus()
165 {
166 auto delegate = webDelegate_.Upgrade();
167 CHECK_NULL_RETURN(delegate, false);
168 ContainerScope scope(delegate->GetInstanceId());
169 bool isFocused = delegate->RequestFocus();
170 delegate->OnRequestFocus();
171
172 delegate->SetToken();
173 return isFocused;
174 }
175
OnFocus(OHOS::NWeb::NWebFocusSource source)176 bool WebClientImpl::OnFocus(OHOS::NWeb::NWebFocusSource source)
177 {
178 auto delegate = webDelegate_.Upgrade();
179 CHECK_NULL_RETURN(delegate, false);
180 ContainerScope scope(delegate->GetInstanceId());
181 bool isFocused = delegate->RequestFocus(source);
182 delegate->OnRequestFocus();
183
184 delegate->SetToken();
185 return isFocused;
186 }
187
OnConsoleLog(const std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message)188 bool WebClientImpl::OnConsoleLog(const std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message)
189 {
190 auto delegate = webDelegate_.Upgrade();
191 CHECK_NULL_RETURN(delegate, false);
192 ContainerScope scope(delegate->GetInstanceId());
193 bool jsMessage = false;
194 auto task = Container::CurrentTaskExecutor();
195 if (!task) {
196 return false;
197 }
198 task->PostSyncTask(
199 [webClient = this, message, &jsMessage] {
200 if (!webClient) {
201 return;
202 }
203 auto delegate = webClient->webDelegate_.Upgrade();
204 if (delegate) {
205 jsMessage = delegate->OnConsoleLog(message);
206 }
207 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientConsoleLog");
208
209 return jsMessage;
210 }
211
OnPageLoadBegin(const std::string & url)212 void WebClientImpl::OnPageLoadBegin(const std::string& url)
213 {
214 auto delegate = webDelegate_.Upgrade();
215 if (!delegate) {
216 return;
217 }
218 ContainerScope scope(delegate->GetInstanceId());
219 delegate->OnPageStarted(url);
220 }
221
OnLoadingProgress(int newProgress)222 void WebClientImpl::OnLoadingProgress(int newProgress)
223 {
224 auto delegate = webDelegate_.Upgrade();
225 if (!delegate) {
226 return;
227 }
228 ContainerScope scope(delegate->GetInstanceId());
229 delegate->OnProgressChanged(newProgress);
230 }
231
OnPageTitle(const std::string & title)232 void WebClientImpl::OnPageTitle(const std::string &title)
233 {
234 auto delegate = webDelegate_.Upgrade();
235 if (!delegate) {
236 return;
237 }
238 ContainerScope scope(delegate->GetInstanceId());
239 delegate->OnReceivedTitle(title);
240 }
241
OnFullScreenExit()242 void WebClientImpl::OnFullScreenExit()
243 {
244 auto delegate = webDelegate_.Upgrade();
245 CHECK_NULL_VOID(delegate);
246 ContainerScope scope(delegate->GetInstanceId());
247 delegate->OnFullScreenExit();
248 }
249
OnFullScreenEnter(std::shared_ptr<NWeb::NWebFullScreenExitHandler> handler)250 void WebClientImpl::OnFullScreenEnter(std::shared_ptr<NWeb::NWebFullScreenExitHandler> handler)
251 {
252 auto delegate = webDelegate_.Upgrade();
253 CHECK_NULL_VOID(delegate);
254 CHECK_NULL_VOID(handler);
255 ContainerScope scope(delegate->GetInstanceId());
256 delegate->OnFullScreenEnter(handler, 0, 0);
257 }
258
OnFullScreenEnterWithVideoSize(std::shared_ptr<NWeb::NWebFullScreenExitHandler> handler,int videoNaturalWidth,int videoNaturalHeight)259 void WebClientImpl::OnFullScreenEnterWithVideoSize(
260 std::shared_ptr<NWeb::NWebFullScreenExitHandler> handler, int videoNaturalWidth, int videoNaturalHeight)
261 {
262 auto delegate = webDelegate_.Upgrade();
263 CHECK_NULL_VOID(delegate);
264 CHECK_NULL_VOID(handler);
265 ContainerScope scope(delegate->GetInstanceId());
266 delegate->OnFullScreenEnter(handler, videoNaturalWidth, videoNaturalHeight);
267 }
268
OnGeolocationHide()269 void WebClientImpl::OnGeolocationHide()
270 {
271 auto delegate = webDelegate_.Upgrade();
272 if (!delegate) {
273 return;
274 }
275 ContainerScope scope(delegate->GetInstanceId());
276 delegate->OnGeolocationPermissionsHidePrompt();
277 }
278
OnGeolocationShow(const std::string & origin,std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface> callback)279 void WebClientImpl::OnGeolocationShow(const std::string& origin,
280 std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface> callback)
281 {
282 auto delegate = webDelegate_.Upgrade();
283 if (!delegate) {
284 return;
285 }
286 ContainerScope scope(delegate->GetInstanceId());
287 delegate->OnGeolocationPermissionsShowPrompt(origin, callback);
288 }
289
SetNWeb(std::shared_ptr<OHOS::NWeb::NWeb> nweb)290 void WebClientImpl::SetNWeb(std::shared_ptr<OHOS::NWeb::NWeb> nweb)
291 {
292 webviewWeak_ = nweb;
293 }
294
OnProxyDied()295 void WebClientImpl::OnProxyDied()
296 {
297 auto delegate = webDelegate_.Upgrade();
298 if (!delegate) {
299 return;
300 }
301 }
302
OnResourceLoadError(std::shared_ptr<NWeb::NWebUrlResourceRequest> request,std::shared_ptr<NWeb::NWebUrlResourceError> error)303 void WebClientImpl::OnResourceLoadError(
304 std::shared_ptr<NWeb::NWebUrlResourceRequest> request, std::shared_ptr<NWeb::NWebUrlResourceError> error)
305 {
306 auto delegate = webDelegate_.Upgrade();
307 if (!delegate) {
308 return;
309 }
310 ContainerScope scope(delegate->GetInstanceId());
311 delegate->OnErrorReceive(request, error);
312 }
313
OnHttpError(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request,std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> response)314 void WebClientImpl::OnHttpError(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request,
315 std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> response)
316 {
317 auto delegate = webDelegate_.Upgrade();
318 CHECK_NULL_VOID(delegate);
319 ContainerScope scope(delegate->GetInstanceId());
320 auto task = Container::CurrentTaskExecutor();
321 if (task == nullptr) {
322 return;
323 }
324 std::weak_ptr<WebClientImpl> webClientWeak = shared_from_this();
325 task->PostTask(
326 [webClient = webClientWeak, request, response] {
327 auto webClientUpgrade = webClient.lock();
328 if (webClientUpgrade == nullptr) {
329 return;
330 }
331 auto delegate = webClientUpgrade->GetWebDelegate();
332 if (delegate) {
333 delegate->OnHttpErrorReceive(request, response);
334 }
335 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientHttpError");
336 }
337
OnMessage(const std::string & param)338 void WebClientImpl::OnMessage(const std::string& param)
339 {
340 auto delegate = webDelegate_.Upgrade();
341 if (!delegate) {
342 return;
343 }
344 ContainerScope scope(delegate->GetInstanceId());
345 delegate->OnMessage(param);
346 }
347
OnRouterPush(const std::string & param)348 void WebClientImpl::OnRouterPush(const std::string& param)
349 {
350 auto delegate = webDelegate_.Upgrade();
351 if (!delegate) {
352 return;
353 }
354 ContainerScope scope(delegate->GetInstanceId());
355 delegate->OnRouterPush(param);
356 }
357
OnHandleInterceptUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request)358 bool WebClientImpl::OnHandleInterceptUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request)
359 {
360 auto delegate = webDelegate_.Upgrade();
361 if (!delegate) {
362 return false;
363 }
364 ContainerScope scope(delegate->GetInstanceId());
365
366 bool result = delegate->OnHandleInterceptUrlLoading(request->Url());
367 if (!result) {
368 result = delegate->OnHandleInterceptLoading(request);
369 }
370 return result;
371 }
372
OnHandleInterceptRequest(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request,std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> response)373 bool WebClientImpl::OnHandleInterceptRequest(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request,
374 std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> response)
375 {
376 auto delegate = webDelegate_.Upgrade();
377 if (!delegate || (delegate->IsEmptyOnInterceptRequest())) {
378 return false;
379 }
380 ContainerScope scope(delegate->GetInstanceId());
381
382 auto webRequest = AceType::MakeRefPtr<WebRequest>(request->RequestHeaders(), request->Method(), request->Url(),
383 request->FromGesture(), request->IsAboutMainFrame(), request->IsRequestRedirect());
384 auto param = std::make_shared<OnInterceptRequestEvent>(webRequest);
385 RefPtr<WebResponse> webResponse = nullptr;
386 auto task = Container::CurrentTaskExecutor();
387 if (task == nullptr) {
388 return false;
389 }
390 task->PostSyncTask(
391 [&delegate, &webResponse, ¶m] {
392 webResponse = delegate->OnInterceptRequest(param);
393 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientInterceptRequest");
394 if (webResponse == nullptr) {
395 return false;
396 }
397 std::string data = webResponse->GetData();
398 response->PutResponseData(data);
399 response->PutResponseHeaders(webResponse->GetHeaders());
400 response->PutResponseMimeType(webResponse->GetMimeType());
401 response->PutResponseEncoding(webResponse->GetEncoding());
402 response->PutResponseStateAndStatuscode(webResponse->GetStatusCode(), webResponse->GetReason());
403 switch (webResponse->GetDataType()) {
404 case WebResponseDataType::FILE_TYPE:
405 response->PutResponseFileHandle(webResponse->GetFileHandle());
406 break;
407 case WebResponseDataType::RESOURCE_URL_TYPE:
408 response->PutResponseResourceUrl(webResponse->GetResourceUrl());
409 break;
410 case WebResponseDataType::BUFFER_TYPE:
411 response->PutResponseDataBuffer(webResponse->GetBuffer(), webResponse->GetBufferSize());
412 break;
413 default:
414 response->PutResponseData(data);
415 break;
416 }
417 if (webResponse->GetResponseStatus() == false) {
418 std::shared_ptr<NWebResponseAsyncHandle> asyncHandle = std::make_shared<NWebResponseAsyncHandle>(response);
419 webResponse->SetAsyncHandle(asyncHandle);
420 response->PutResponseDataStatus(false);
421 }
422 return true;
423 }
424
OnAlertDialogByJS(const std::string & url,const std::string & message,std::shared_ptr<NWeb::NWebJSDialogResult> result)425 bool WebClientImpl::OnAlertDialogByJS(
426 const std::string &url, const std::string &message, std::shared_ptr<NWeb::NWebJSDialogResult> result)
427 {
428 auto delegate = webDelegate_.Upgrade();
429 CHECK_NULL_RETURN(delegate, false);
430 ContainerScope scope(delegate->GetInstanceId());
431 return OnJsCommonDialog(this, DialogEventType::DIALOG_EVENT_ALERT, result, url, message);
432 }
433
OnBeforeUnloadByJS(const std::string & url,const std::string & message,std::shared_ptr<NWeb::NWebJSDialogResult> result)434 bool WebClientImpl::OnBeforeUnloadByJS(
435 const std::string &url, const std::string &message, std::shared_ptr<NWeb::NWebJSDialogResult> result)
436 {
437 auto delegate = webDelegate_.Upgrade();
438 CHECK_NULL_RETURN(delegate, false);
439 ContainerScope scope(delegate->GetInstanceId());
440 return OnJsCommonDialog(this, DialogEventType::DIALOG_EVENT_BEFORE_UNLOAD, result, url, message);
441 }
442
OnConfirmDialogByJS(const std::string & url,const std::string & message,std::shared_ptr<NWeb::NWebJSDialogResult> result)443 bool WebClientImpl::OnConfirmDialogByJS(
444 const std::string &url, const std::string &message, std::shared_ptr<NWeb::NWebJSDialogResult> result)
445 {
446 auto delegate = webDelegate_.Upgrade();
447 CHECK_NULL_RETURN(delegate, false);
448 ContainerScope scope(delegate->GetInstanceId());
449 return OnJsCommonDialog(this, DialogEventType::DIALOG_EVENT_CONFIRM, result, url, message);
450 }
451
OnPromptDialogByJS(const std::string & url,const std::string & message,const std::string & defaultValue,std::shared_ptr<NWeb::NWebJSDialogResult> result)452 bool WebClientImpl::OnPromptDialogByJS(const std::string &url, const std::string &message,
453 const std::string &defaultValue, std::shared_ptr<NWeb::NWebJSDialogResult> result)
454 {
455 auto delegate = webDelegate_.Upgrade();
456 CHECK_NULL_RETURN(delegate, false);
457 ContainerScope scope(delegate->GetInstanceId());
458 return OnJsCommonDialog(this, DialogEventType::DIALOG_EVENT_PROMPT, result, url, message, defaultValue);
459 }
460
OnRenderExited(OHOS::NWeb::RenderExitReason reason)461 void WebClientImpl::OnRenderExited(OHOS::NWeb::RenderExitReason reason)
462 {
463 auto delegate = webDelegate_.Upgrade();
464 if (!delegate) {
465 return;
466 }
467 ContainerScope scope(delegate->GetInstanceId());
468 delegate->OnRenderExited(reason);
469 }
470
OnRefreshAccessedHistory(const std::string & url,bool isReload)471 void WebClientImpl::OnRefreshAccessedHistory(const std::string& url, bool isReload)
472 {
473 auto delegate = webDelegate_.Upgrade();
474 if (!delegate) {
475 return;
476 }
477 ContainerScope scope(delegate->GetInstanceId());
478 delegate->OnRefreshAccessedHistory(url, isReload);
479 }
480
OnFileSelectorShow(std::shared_ptr<NWeb::NWebStringVectorValueCallback> callback,std::shared_ptr<NWeb::NWebFileSelectorParams> params)481 bool WebClientImpl::OnFileSelectorShow(
482 std::shared_ptr<NWeb::NWebStringVectorValueCallback> callback,
483 std::shared_ptr<NWeb::NWebFileSelectorParams> params)
484 {
485 auto delegate = webDelegate_.Upgrade();
486 CHECK_NULL_RETURN(delegate, false);
487 ContainerScope scope(delegate->GetInstanceId());
488 bool jsResult = false;
489 auto param = std::make_shared<FileSelectorEvent>(AceType::MakeRefPtr<FileSelectorParamOhos>(params),
490 AceType::MakeRefPtr<FileSelectorResultOhos>(callback));
491 auto task = Container::CurrentTaskExecutor();
492 if (task == nullptr) {
493 return false;
494 }
495 task->PostSyncTask(
496 [webClient = this, ¶m, &jsResult] {
497 if (webClient == nullptr) {
498 return;
499 }
500 auto delegate = webClient->GetWebDelegate();
501 if (delegate) {
502 jsResult = delegate->OnFileSelectorShow(param);
503 }
504 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientFileSelectorShow");
505 return jsResult;
506 }
507
OnResource(const std::string & url)508 void WebClientImpl::OnResource(const std::string& url)
509 {
510 auto task = Container::CurrentTaskExecutorSafely();
511 if (task == nullptr) {
512 return;
513 }
514 std::weak_ptr<WebClientImpl> webClientWeak = shared_from_this();
515 task->PostTask(
516 [webClient = webClientWeak, url] {
517 auto webClientUpgrade = webClient.lock();
518 if (webClientUpgrade == nullptr) {
519 return;
520 }
521 auto delegate = webClientUpgrade->GetWebDelegate();
522 if (delegate) {
523 delegate->OnResourceLoad(url);
524 }
525 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientResourceLoad");
526 }
527
OnScaleChanged(float oldScaleFactor,float newScaleFactor)528 void WebClientImpl::OnScaleChanged(float oldScaleFactor, float newScaleFactor)
529 {
530 auto delegate = webDelegate_.Upgrade();
531 if (!delegate) {
532 return;
533 }
534 ContainerScope scope(delegate->GetInstanceId());
535 delegate->OnScaleChange(oldScaleFactor, newScaleFactor);
536 }
537
OnScroll(double xOffset,double yOffset)538 void WebClientImpl::OnScroll(double xOffset, double yOffset)
539 {
540 auto delegate = webDelegate_.Upgrade();
541 if (!delegate) {
542 return;
543 }
544 ContainerScope scope(delegate->GetInstanceId());
545 delegate->OnScroll(xOffset, yOffset);
546 }
547
OnHttpAuthRequestByJS(std::shared_ptr<NWeb::NWebJSHttpAuthResult> result,const std::string & host,const std::string & realm)548 bool WebClientImpl::OnHttpAuthRequestByJS(std::shared_ptr<NWeb::NWebJSHttpAuthResult> result, const std::string &host,
549 const std::string &realm)
550 {
551 auto delegate = webDelegate_.Upgrade();
552 CHECK_NULL_RETURN(delegate, false);
553 ContainerScope scope(delegate->GetInstanceId());
554
555 bool jsResult = false;
556 auto param = std::make_shared<WebHttpAuthEvent>(AceType::MakeRefPtr<AuthResultOhos>(result), host, realm);
557 auto task = Container::CurrentTaskExecutor();
558 if (task == nullptr) {
559 return false;
560 }
561 task->PostSyncTask(
562 [webClient = this, ¶m, &jsResult] {
563 if (!webClient) {
564 return;
565 }
566 auto delegate = webClient->webDelegate_.Upgrade();
567 if (delegate) {
568 jsResult = delegate->OnHttpAuthRequest(param);
569 }
570 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientHttpAuthRequest");
571 return jsResult;
572 }
573
OnSslErrorRequestByJS(std::shared_ptr<NWeb::NWebJSSslErrorResult> result,OHOS::NWeb::SslError error)574 bool WebClientImpl::OnSslErrorRequestByJS(std::shared_ptr<NWeb::NWebJSSslErrorResult> result,
575 OHOS::NWeb::SslError error)
576 {
577 auto delegate = webDelegate_.Upgrade();
578 CHECK_NULL_RETURN(delegate, false);
579 ContainerScope scope(delegate->GetInstanceId());
580
581 bool jsResult = false;
582 auto param = std::make_shared<WebSslErrorEvent>(AceType::MakeRefPtr<SslErrorResultOhos>(result),
583 static_cast<int32_t>(error));
584 auto task = Container::CurrentTaskExecutor();
585 if (task == nullptr) {
586 return false;
587 }
588 task->PostSyncTask(
589 [webClient = this, ¶m, &jsResult] {
590 if (!webClient) {
591 return;
592 }
593 auto delegate = webClient->webDelegate_.Upgrade();
594 if (delegate) {
595 jsResult = delegate->OnSslErrorRequest(param);
596 }
597 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientSslErrorRequest");
598 return jsResult;
599 }
600
OnAllSslErrorRequestByJS(std::shared_ptr<NWeb::NWebJSAllSslErrorResult> result,OHOS::NWeb::SslError error,const std::string & url,const std::string & originalUrl,const std::string & referrer,bool isFatalError,bool isMainFrame)601 bool WebClientImpl::OnAllSslErrorRequestByJS(std::shared_ptr<NWeb::NWebJSAllSslErrorResult> result,
602 OHOS::NWeb::SslError error,
603 const std::string& url,
604 const std::string& originalUrl,
605 const std::string& referrer,
606 bool isFatalError,
607 bool isMainFrame)
608 {
609 auto delegate = webDelegate_.Upgrade();
610 CHECK_NULL_RETURN(delegate, false);
611 ContainerScope scope(delegate->GetInstanceId());
612
613 bool jsResult = false;
614 auto param = std::make_shared<WebAllSslErrorEvent>(AceType::MakeRefPtr<AllSslErrorResultOhos>(result),
615 static_cast<int32_t>(error), url, originalUrl, referrer, isFatalError, isMainFrame);
616 auto task = Container::CurrentTaskExecutor();
617 if (task == nullptr) {
618 return false;
619 }
620 task->PostSyncTask(
621 [webClient = this, ¶m, &jsResult] {
622 if (!webClient) {
623 return;
624 }
625 auto delegate = webClient->webDelegate_.Upgrade();
626 if (delegate) {
627 jsResult = delegate->OnAllSslErrorRequest(param);
628 }
629 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientAllSslErrorRequest");
630 return jsResult;
631 }
632
OnSslSelectCertRequestByJS(std::shared_ptr<NWeb::NWebJSSslSelectCertResult> result,const std::string & host,int port,const std::vector<std::string> & keyTypes,const std::vector<std::string> & issuers)633 bool WebClientImpl::OnSslSelectCertRequestByJS(
634 std::shared_ptr<NWeb::NWebJSSslSelectCertResult> result,
635 const std::string& host,
636 int port,
637 const std::vector<std::string>& keyTypes,
638 const std::vector<std::string>& issuers)
639 {
640 auto delegate = webDelegate_.Upgrade();
641 CHECK_NULL_RETURN(delegate, false);
642 ContainerScope scope(delegate->GetInstanceId());
643
644 bool jsResult = false;
645 auto param = std::make_shared<WebSslSelectCertEvent>(AceType::MakeRefPtr<SslSelectCertResultOhos>(result),
646 host, port, keyTypes, issuers);
647 auto task = Container::CurrentTaskExecutor();
648 if (task == nullptr) {
649 return false;
650 }
651
652 task->PostSyncTask(
653 [webClient = this, ¶m, &jsResult] {
654 if (!webClient) {
655 return;
656 }
657 auto delegate = webClient->webDelegate_.Upgrade();
658 if (delegate) {
659 jsResult = delegate->OnSslSelectCertRequest(param);
660 }
661 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientSslSelectCertRequest");
662
663 return jsResult;
664 }
665
OnPermissionRequest(std::shared_ptr<NWeb::NWebAccessRequest> request)666 void WebClientImpl::OnPermissionRequest(std::shared_ptr<NWeb::NWebAccessRequest> request)
667 {
668 auto delegate = webDelegate_.Upgrade();
669 CHECK_NULL_VOID(delegate);
670 ContainerScope scope(delegate->GetInstanceId());
671 delegate->OnPermissionRequestPrompt(request);
672 }
673
OnScreenCaptureRequest(std::shared_ptr<NWeb::NWebScreenCaptureAccessRequest> request)674 void WebClientImpl::OnScreenCaptureRequest(std::shared_ptr<NWeb::NWebScreenCaptureAccessRequest> request)
675 {
676 auto delegate = webDelegate_.Upgrade();
677 CHECK_NULL_VOID(delegate);
678 ContainerScope scope(delegate->GetInstanceId());
679 delegate->OnScreenCaptureRequest(request);
680 }
681
RunContextMenu(std::shared_ptr<NWeb::NWebContextMenuParams> params,std::shared_ptr<NWeb::NWebContextMenuCallback> callback)682 bool WebClientImpl::RunContextMenu(
683 std::shared_ptr<NWeb::NWebContextMenuParams> params,
684 std::shared_ptr<NWeb::NWebContextMenuCallback> callback)
685 {
686 auto delegate = webDelegate_.Upgrade();
687 CHECK_NULL_RETURN(delegate, false);
688 ContainerScope scope(delegate->GetInstanceId());
689 bool jsResult = false;
690 auto param = std::make_shared<ContextMenuEvent>(AceType::MakeRefPtr<ContextMenuParamOhos>(params),
691 AceType::MakeRefPtr<ContextMenuResultOhos>(callback));
692 auto task = Container::CurrentTaskExecutor();
693 if (task == nullptr) {
694 return false;
695 }
696 task->PostSyncTask(
697 [webClient = this, ¶m, &jsResult] {
698 if (webClient == nullptr) {
699 return;
700 }
701 auto delegate = webClient->GetWebDelegate();
702 if (delegate) {
703 jsResult = delegate->OnContextMenuShow(param);
704 }
705 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebRunContextMenu");
706 return jsResult;
707 }
708
UpdateClippedSelectionBounds(int x,int y,int w,int h)709 void WebClientImpl::UpdateClippedSelectionBounds(int x, int y, int w, int h)
710 {
711 auto delegate = webDelegate_.Upgrade();
712 CHECK_NULL_VOID(delegate);
713 ContainerScope scope(delegate->GetInstanceId());
714 delegate->UpdateClippedSelectionBounds(x, y, w, h);
715 }
716
RunQuickMenu(std::shared_ptr<NWeb::NWebQuickMenuParams> params,std::shared_ptr<NWeb::NWebQuickMenuCallback> callback)717 bool WebClientImpl::RunQuickMenu(std::shared_ptr<NWeb::NWebQuickMenuParams> params,
718 std::shared_ptr<NWeb::NWebQuickMenuCallback> callback)
719 {
720 if (!params || !callback) {
721 return false;
722 }
723 auto delegate = webDelegate_.Upgrade();
724 if (!delegate) {
725 return false;
726 }
727 ContainerScope scope(delegate->GetInstanceId());
728 return delegate->RunQuickMenu(params, callback);
729 }
730
HideHandleAndQuickMenuIfNecessary(bool hide)731 void WebClientImpl::HideHandleAndQuickMenuIfNecessary(bool hide)
732 {
733 auto delegate = webDelegate_.Upgrade();
734 CHECK_NULL_VOID(delegate);
735 ContainerScope scope(delegate->GetInstanceId());
736 delegate->HideHandleAndQuickMenuIfNecessary(hide);
737 }
738
ChangeVisibilityOfQuickMenu()739 void WebClientImpl::ChangeVisibilityOfQuickMenu()
740 {
741 auto delegate = webDelegate_.Upgrade();
742 CHECK_NULL_VOID(delegate);
743 ContainerScope scope(delegate->GetInstanceId());
744 delegate->ChangeVisibilityOfQuickMenu();
745 }
746
OnQuickMenuDismissed()747 void WebClientImpl::OnQuickMenuDismissed()
748 {
749 auto delegate = webDelegate_.Upgrade();
750 if (!delegate) {
751 return;
752 }
753 ContainerScope scope(delegate->GetInstanceId());
754 delegate->OnQuickMenuDismissed();
755 }
756
OnTouchSelectionChanged(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle,std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle,std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle)757 void WebClientImpl::OnTouchSelectionChanged(
758 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle,
759 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle,
760 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle)
761 {
762 auto delegate = webDelegate_.Upgrade();
763 if (!delegate) {
764 return;
765 }
766 ContainerScope scope(delegate->GetInstanceId());
767 delegate->OnTouchSelectionChanged(
768 insertHandle, startSelectionHandle, endSelectionHandle);
769 }
770
OnDragAndDropData(const void * data,size_t len,std::shared_ptr<NWeb::NWebImageOptions> opt)771 bool WebClientImpl::OnDragAndDropData(const void* data, size_t len, std::shared_ptr<NWeb::NWebImageOptions> opt)
772 {
773 auto delegate = webDelegate_.Upgrade();
774 if (!delegate) {
775 return false;
776 }
777 ContainerScope scope(delegate->GetInstanceId());
778 if (opt) {
779 return delegate->OnDragAndDropData(data, len, opt->GetWidth(), opt->GetHeight());
780 }
781 return delegate->OnDragAndDropData(data, len, 0, 0);
782 }
783
OnDragAndDropDataUdmf(std::shared_ptr<NWeb::NWebDragData> dragData)784 bool WebClientImpl::OnDragAndDropDataUdmf(std::shared_ptr<NWeb::NWebDragData> dragData)
785 {
786 auto delegate = webDelegate_.Upgrade();
787 if (!delegate) {
788 return false;
789 }
790 ContainerScope scope(delegate->GetInstanceId());
791 return delegate->OnDragAndDropDataUdmf(dragData);
792 }
793
UpdateDragCursor(NWeb::NWebDragData::DragOperation op)794 void WebClientImpl::UpdateDragCursor(NWeb::NWebDragData::DragOperation op)
795 {
796 auto delegate = webDelegate_.Upgrade();
797 CHECK_NULL_VOID(delegate);
798 ContainerScope scope(delegate->GetInstanceId());
799 delegate->UpdateDragCursor(op);
800 }
801
OnWindowNewByJS(const std::string & targetUrl,bool isAlert,bool isUserTrigger,std::shared_ptr<NWeb::NWebControllerHandler> handler)802 void WebClientImpl::OnWindowNewByJS(
803 const std::string& targetUrl,
804 bool isAlert,
805 bool isUserTrigger,
806 std::shared_ptr<NWeb::NWebControllerHandler> handler)
807 {
808 auto delegate = webDelegate_.Upgrade();
809 CHECK_NULL_VOID(delegate);
810 ContainerScope scope(delegate->GetInstanceId());
811 delegate->OnWindowNew(targetUrl, isAlert, isUserTrigger, handler);
812 }
813
OnWindowExitByJS()814 void WebClientImpl::OnWindowExitByJS()
815 {
816 auto delegate = webDelegate_.Upgrade();
817 CHECK_NULL_VOID(delegate);
818 ContainerScope scope(delegate->GetInstanceId());
819 delegate->OnWindowExit();
820 }
821
OnPageVisible(const std::string & url)822 void WebClientImpl::OnPageVisible(const std::string& url)
823 {
824 TAG_LOGI(AceLogTag::ACE_WEB, "WebClientImpl::OnPageVisible override enter");
825 auto delegate = webDelegate_.Upgrade();
826 CHECK_NULL_VOID(delegate);
827 ContainerScope scope(delegate->GetInstanceId());
828 delegate->OnPageVisible(url);
829 }
830
OnDataResubmission(std::shared_ptr<NWeb::NWebDataResubmissionCallback> handler)831 void WebClientImpl::OnDataResubmission(std::shared_ptr<NWeb::NWebDataResubmissionCallback> handler)
832 {
833 auto delegate = webDelegate_.Upgrade();
834 CHECK_NULL_VOID(delegate);
835 CHECK_NULL_VOID(handler);
836 ContainerScope scope(delegate->GetInstanceId());
837 delegate->OnDataResubmitted(handler);
838 }
839
OnNavigationEntryCommitted(std::shared_ptr<NWeb::NWebLoadCommittedDetails> details)840 void WebClientImpl::OnNavigationEntryCommitted(
841 std::shared_ptr<NWeb::NWebLoadCommittedDetails> details)
842 {
843 auto delegate = webDelegate_.Upgrade();
844 CHECK_NULL_VOID(delegate);
845 CHECK_NULL_VOID(details);
846 ContainerScope scope(delegate->GetInstanceId());
847 delegate->OnNavigationEntryCommitted(details);
848 }
849
OnPageIcon(const void * data,size_t width,size_t height,NWeb::ImageColorType colorType,NWeb::ImageAlphaType alphaType)850 void WebClientImpl::OnPageIcon(const void* data,
851 size_t width,
852 size_t height,
853 NWeb::ImageColorType colorType,
854 NWeb::ImageAlphaType alphaType)
855 {
856 auto delegate = webDelegate_.Upgrade();
857 CHECK_NULL_VOID(delegate);
858 ContainerScope scope(delegate->GetInstanceId());
859 delegate->OnFaviconReceived(data, width, height, colorType, alphaType);
860 }
861
OnDesktopIconUrl(const std::string & icon_url,bool precomposed)862 void WebClientImpl::OnDesktopIconUrl(const std::string& icon_url, bool precomposed)
863 {
864 auto delegate = webDelegate_.Upgrade();
865 CHECK_NULL_VOID(delegate);
866 ContainerScope scope(delegate->GetInstanceId());
867 delegate->OnTouchIconUrl(icon_url, precomposed);
868 }
869
OnCursorChange(const NWeb::CursorType & type,std::shared_ptr<NWeb::NWebCursorInfo> info)870 bool WebClientImpl::OnCursorChange(const NWeb::CursorType& type, std::shared_ptr<NWeb::NWebCursorInfo> info)
871 {
872 auto delegate = webDelegate_.Upgrade();
873 CHECK_NULL_RETURN(delegate, false);
874 ContainerScope scope(delegate->GetInstanceId());
875 return delegate->OnCursorChange(type, info);
876 }
877
OnSelectPopupMenu(std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params,std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback)878 void WebClientImpl::OnSelectPopupMenu(
879 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params,
880 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback)
881 {
882 auto delegate = webDelegate_.Upgrade();
883 CHECK_NULL_VOID(delegate);
884 ContainerScope scope(delegate->GetInstanceId());
885 delegate->OnSelectPopupMenu(params, callback);
886 }
887
ReleaseSurface()888 void ReleaseSurfaceImpl::ReleaseSurface()
889 {
890 auto delegate = webDelegate_.Upgrade();
891 CHECK_NULL_VOID(delegate);
892 ContainerScope scope(delegate->GetInstanceId());
893 if (!surfaceDelegate_) {
894 return;
895 }
896 surfaceDelegate_->ReleaseSurface();
897 }
898
OnAudioStateChanged(bool playing)899 void WebClientImpl::OnAudioStateChanged(bool playing)
900 {
901 auto delegate = webDelegate_.Upgrade();
902 CHECK_NULL_VOID(delegate);
903 ContainerScope scope(delegate->GetInstanceId());
904 delegate->OnAudioStateChanged(playing);
905 }
906
OnFirstContentfulPaint(int64_t navigationStartTick,int64_t firstContentfulPaintMs)907 void WebClientImpl::OnFirstContentfulPaint(int64_t navigationStartTick, int64_t firstContentfulPaintMs)
908 {
909 auto delegate = webDelegate_.Upgrade();
910 CHECK_NULL_VOID(delegate);
911 ContainerScope scope(delegate->GetInstanceId());
912 delegate->OnFirstContentfulPaint(navigationStartTick, firstContentfulPaintMs);
913 }
914
OnFirstMeaningfulPaint(std::shared_ptr<NWeb::NWebFirstMeaningfulPaintDetails> details)915 void WebClientImpl::OnFirstMeaningfulPaint(
916 std::shared_ptr<NWeb::NWebFirstMeaningfulPaintDetails> details)
917 {
918 auto delegate = webDelegate_.Upgrade();
919 CHECK_NULL_VOID(delegate);
920 CHECK_NULL_VOID(details);
921 ContainerScope scope(delegate->GetInstanceId());
922 delegate->OnFirstMeaningfulPaint(details);
923 }
924
OnLargestContentfulPaint(std::shared_ptr<NWeb::NWebLargestContentfulPaintDetails> details)925 void WebClientImpl::OnLargestContentfulPaint(
926 std::shared_ptr<NWeb::NWebLargestContentfulPaintDetails> details)
927 {
928 auto delegate = webDelegate_.Upgrade();
929 CHECK_NULL_VOID(delegate);
930 CHECK_NULL_VOID(details);
931 ContainerScope scope(delegate->GetInstanceId());
932 delegate->OnLargestContentfulPaint(details);
933 }
934
935
OnSafeBrowsingCheckResult(int threat_type)936 void WebClientImpl::OnSafeBrowsingCheckResult(int threat_type)
937 {
938 auto delegate = webDelegate_.Upgrade();
939 CHECK_NULL_VOID(delegate);
940 ContainerScope scope(delegate->GetInstanceId());
941 delegate->OnSafeBrowsingCheckResult(threat_type);
942 }
943
OnCompleteSwapWithNewSize()944 void WebClientImpl::OnCompleteSwapWithNewSize()
945 {
946 auto delegate = webDelegate_.Upgrade();
947 CHECK_NULL_VOID(delegate);
948 ContainerScope scope(delegate->GetInstanceId());
949 delegate->OnCompleteSwapWithNewSize();
950 }
951
OnResizeNotWork()952 void WebClientImpl::OnResizeNotWork()
953 {
954 auto delegate = webDelegate_.Upgrade();
955 CHECK_NULL_VOID(delegate);
956 ContainerScope scope(delegate->GetInstanceId());
957 delegate->OnResizeNotWork();
958 }
959
OnGetTouchHandleHotZone(std::shared_ptr<NWeb::NWebTouchHandleHotZone> hotZone)960 void WebClientImpl::OnGetTouchHandleHotZone(std::shared_ptr<NWeb::NWebTouchHandleHotZone> hotZone)
961 {
962 auto delegate = webDelegate_.Upgrade();
963 CHECK_NULL_VOID(delegate);
964 ContainerScope scope(delegate->GetInstanceId());
965 delegate->OnGetTouchHandleHotZone(hotZone);
966 }
967
OnDateTimeChooserPopup(std::shared_ptr<NWeb::NWebDateTimeChooser> chooser,const std::vector<std::shared_ptr<NWeb::NWebDateTimeSuggestion>> & suggestions,std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback)968 void WebClientImpl::OnDateTimeChooserPopup(
969 std::shared_ptr<NWeb::NWebDateTimeChooser> chooser,
970 const std::vector<std::shared_ptr<NWeb::NWebDateTimeSuggestion>>& suggestions,
971 std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback)
972 {
973 auto delegate = webDelegate_.Upgrade();
974 CHECK_NULL_VOID(delegate);
975 ContainerScope scope(delegate->GetInstanceId());
976 delegate->OnDateTimeChooserPopup(chooser, suggestions, callback);
977 }
978
OnDateTimeChooserClose()979 void WebClientImpl::OnDateTimeChooserClose()
980 {
981 auto delegate = webDelegate_.Upgrade();
982 CHECK_NULL_VOID(delegate);
983 ContainerScope scope(delegate->GetInstanceId());
984 delegate->OnDateTimeChooserClose();
985 }
986
OnOverScroll(float xOffset,float yOffset)987 void WebClientImpl::OnOverScroll(float xOffset, float yOffset)
988 {
989 auto delegate = webDelegate_.Upgrade();
990 CHECK_NULL_VOID(delegate);
991 ContainerScope scope(delegate->GetInstanceId());
992 delegate->OnOverScroll(xOffset, yOffset);
993 }
994
OnOverScrollFlingVelocity(float xVelocity,float yVelocity,bool isFling)995 void WebClientImpl::OnOverScrollFlingVelocity(float xVelocity, float yVelocity, bool isFling)
996 {
997 auto delegate = webDelegate_.Upgrade();
998 CHECK_NULL_VOID(delegate);
999 ContainerScope scope(delegate->GetInstanceId());
1000 delegate->OnOverScrollFlingVelocity(xVelocity, yVelocity, isFling);
1001 }
1002
OnOverScrollFlingEnd()1003 void WebClientImpl::OnOverScrollFlingEnd() {}
1004
OnScrollState(bool scrollState)1005 void WebClientImpl::OnScrollState(bool scrollState)
1006 {
1007 auto delegate = webDelegate_.Upgrade();
1008 CHECK_NULL_VOID(delegate);
1009 ContainerScope scope(delegate->GetInstanceId());
1010 delegate->OnScrollState(scrollState);
1011 }
OnNativeEmbedLifecycleChange(std::shared_ptr<NWeb::NWebNativeEmbedDataInfo> dataInfo)1012 void WebClientImpl::OnNativeEmbedLifecycleChange(std::shared_ptr<NWeb::NWebNativeEmbedDataInfo> dataInfo)
1013 {
1014 auto delegate = webDelegate_.Upgrade();
1015 CHECK_NULL_VOID(delegate);
1016 ContainerScope scope(delegate->GetInstanceId());
1017 delegate->OnNativeEmbedLifecycleChange(dataInfo);
1018 }
OnNativeEmbedGestureEvent(std::shared_ptr<NWeb::NWebNativeEmbedTouchEvent> event)1019 void WebClientImpl::OnNativeEmbedGestureEvent(std::shared_ptr<NWeb::NWebNativeEmbedTouchEvent> event)
1020 {
1021 auto delegate = webDelegate_.Upgrade();
1022 CHECK_NULL_VOID(delegate);
1023 ContainerScope scope(delegate->GetInstanceId());
1024 delegate->OnNativeEmbedGestureEvent(event);
1025 }
1026
OnRootLayerChanged(int width,int height)1027 void WebClientImpl::OnRootLayerChanged(int width, int height)
1028 {
1029 auto delegate = webDelegate_.Upgrade();
1030 CHECK_NULL_VOID(delegate);
1031 ContainerScope scope(delegate->GetInstanceId());
1032 delegate->OnRootLayerChanged(width, height);
1033 }
1034
ReleaseResizeHold()1035 void WebClientImpl::ReleaseResizeHold()
1036 {
1037 auto delegate = webDelegate_.Upgrade();
1038 CHECK_NULL_VOID(delegate);
1039 ContainerScope scope(delegate->GetInstanceId());
1040 delegate->ReleaseResizeHold();
1041 }
1042
FilterScrollEvent(const float x,const float y,const float xVelocity,const float yVelocity)1043 bool WebClientImpl::FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity)
1044 {
1045 auto delegate = webDelegate_.Upgrade();
1046 CHECK_NULL_RETURN(delegate, false);
1047 ContainerScope scope(delegate->GetInstanceId());
1048 return delegate->FilterScrollEvent(x, y, xVelocity, yVelocity);
1049 }
1050
OnIntelligentTrackingPreventionResult(const std::string & websiteHost,const std::string & trackerHost)1051 void WebClientImpl::OnIntelligentTrackingPreventionResult(
1052 const std::string& websiteHost, const std::string& trackerHost)
1053 {
1054 auto delegate = webDelegate_.Upgrade();
1055 CHECK_NULL_VOID(delegate);
1056 ContainerScope scope(delegate->GetInstanceId());
1057 delegate->OnIntelligentTrackingPreventionResult(websiteHost, trackerHost);
1058 }
1059
OnTooltip(const std::string & tooltip)1060 void WebClientImpl::OnTooltip(const std::string& tooltip)
1061 {
1062 auto delegate = webDelegate_.Upgrade();
1063 CHECK_NULL_VOID(delegate);
1064 ContainerScope scope(delegate->GetInstanceId());
1065 delegate->OnTooltip(tooltip);
1066 }
1067
GetVisibleRectToWeb(int & visibleX,int & visibleY,int & visibleWidth,int & visibleHeight)1068 void WebClientImpl::GetVisibleRectToWeb(int& visibleX, int& visibleY, int& visibleWidth, int& visibleHeight)
1069 {
1070 auto delegate = webDelegate_.Upgrade();
1071 CHECK_NULL_VOID(delegate);
1072 ContainerScope scope(delegate->GetInstanceId());
1073 delegate->GetVisibleRectToWeb(visibleX, visibleY, visibleWidth, visibleHeight);
1074 }
1075
RestoreRenderFit()1076 void WebClientImpl::RestoreRenderFit()
1077 {
1078 auto delegate = webDelegate_.Upgrade();
1079 CHECK_NULL_VOID(delegate);
1080 ContainerScope scope(delegate->GetInstanceId());
1081 delegate->RestoreRenderFit();
1082 }
1083
OnHandleOverrideUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request)1084 bool WebClientImpl::OnHandleOverrideUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request)
1085 {
1086 auto delegate = webDelegate_.Upgrade();
1087 if (!delegate) {
1088 return false;
1089 }
1090 ContainerScope scope(delegate->GetInstanceId());
1091
1092 bool result = delegate->OnHandleOverrideLoading(request);
1093
1094 return result;
1095 }
1096
GetWordSelection(const std::string & text,int8_t offset)1097 std::vector<int8_t> WebClientImpl::GetWordSelection(const std::string& text, int8_t offset)
1098 {
1099 auto delegate = webDelegate_.Upgrade();
1100 std::vector<int8_t> vec = { -1, -1 };
1101 CHECK_NULL_RETURN(delegate, vec);
1102 ContainerScope scope(delegate->GetInstanceId());
1103 return delegate->GetWordSelection(text, offset);
1104 }
1105
OnRenderProcessNotResponding(const std::string & jsStack,int pid,OHOS::NWeb::RenderProcessNotRespondingReason reason)1106 void WebClientImpl::OnRenderProcessNotResponding(
1107 const std::string& jsStack, int pid, OHOS::NWeb::RenderProcessNotRespondingReason reason)
1108 {
1109 auto delegate = webDelegate_.Upgrade();
1110 if (!delegate) {
1111 return;
1112 }
1113 ContainerScope scope(delegate->GetInstanceId());
1114 delegate->OnRenderProcessNotResponding(jsStack, pid, reason);
1115 }
1116
OnRenderProcessResponding()1117 void WebClientImpl::OnRenderProcessResponding()
1118 {
1119 auto delegate = webDelegate_.Upgrade();
1120 if (!delegate) {
1121 return;
1122 }
1123 ContainerScope scope(delegate->GetInstanceId());
1124 delegate->OnRenderProcessResponding();
1125 }
1126
OnOpenAppLink(const std::string & url,std::shared_ptr<OHOS::NWeb::NWebAppLinkCallback> callback)1127 bool WebClientImpl::OnOpenAppLink(
1128 const std::string& url, std::shared_ptr<OHOS::NWeb::NWebAppLinkCallback> callback)
1129 {
1130 auto delegate = webDelegate_.Upgrade();
1131 if (!delegate) {
1132 return false;
1133 }
1134
1135 ContainerScope scope(delegate->GetInstanceId());
1136 return delegate->OnOpenAppLink(url, callback);
1137 }
1138
OnInterceptKeyboardAttach(const std::shared_ptr<OHOS::NWeb::NWebCustomKeyboardHandler> keyboardHandler,const std::map<std::string,std::string> & attributes,bool & useSystemKeyboard,int32_t & enterKeyType)1139 void WebClientImpl::OnInterceptKeyboardAttach(
1140 const std::shared_ptr<OHOS::NWeb::NWebCustomKeyboardHandler> keyboardHandler,
1141 const std::map<std::string, std::string> &attributes, bool &useSystemKeyboard, int32_t &enterKeyType)
1142 {
1143 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard OnInterceptKeyboardAttach override enter");
1144 auto delegate = webDelegate_.Upgrade();
1145 if (!delegate) {
1146 return;
1147 }
1148 ContainerScope scope(delegate->GetInstanceId());
1149 delegate->OnInterceptKeyboardAttach(keyboardHandler, attributes, useSystemKeyboard, enterKeyType);
1150 }
1151
OnCustomKeyboardAttach()1152 void WebClientImpl::OnCustomKeyboardAttach()
1153 {
1154 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard OnCustomKeyboardAttach override enter");
1155 auto delegate = webDelegate_.Upgrade();
1156 if (!delegate) {
1157 return;
1158 }
1159 ContainerScope scope(delegate->GetInstanceId());
1160 delegate->OnCustomKeyboardAttach();
1161 }
1162
OnCustomKeyboardClose()1163 void WebClientImpl::OnCustomKeyboardClose()
1164 {
1165 TAG_LOGI(AceLogTag::ACE_WEB, "WebCustomKeyboard OnCustomKeyboardClose override enter");
1166 auto delegate = webDelegate_.Upgrade();
1167 if (!delegate) {
1168 return;
1169 }
1170 ContainerScope scope(delegate->GetInstanceId());
1171 delegate->OnCustomKeyboardClose();
1172 }
1173
OnShowAutofillPopup(const float offsetX,const float offsetY,const std::vector<std::string> & menu_items)1174 void WebClientImpl::OnShowAutofillPopup(
1175 const float offsetX, const float offsetY, const std::vector<std::string>& menu_items)
1176 {
1177 auto delegate = webDelegate_.Upgrade();
1178 CHECK_NULL_VOID(delegate);
1179 ContainerScope scope(delegate->GetInstanceId());
1180 delegate->OnShowAutofillPopup(offsetX, offsetY, menu_items);
1181 }
1182
OnHideAutofillPopup()1183 void WebClientImpl::OnHideAutofillPopup()
1184 {
1185 auto delegate = webDelegate_.Upgrade();
1186 CHECK_NULL_VOID(delegate);
1187 ContainerScope scope(delegate->GetInstanceId());
1188 delegate->OnHideAutofillPopup();
1189 }
1190
OnViewportFitChange(OHOS::NWeb::ViewportFit viewportFit)1191 void WebClientImpl::OnViewportFitChange(OHOS::NWeb::ViewportFit viewportFit)
1192 {
1193 auto delegate = webDelegate_.Upgrade();
1194 CHECK_NULL_VOID(delegate);
1195 ContainerScope scope(delegate->GetInstanceId());
1196 delegate->OnViewportFitChange(viewportFit);
1197 }
1198
CreateOverlay(void * data,size_t len,int width,int height,int offsetX,int offsetY,int rectWidth,int rectHeight,int pointX,int pointY)1199 void WebClientImpl::CreateOverlay(void* data, size_t len, int width, int height, int offsetX, int offsetY,
1200 int rectWidth, int rectHeight, int pointX, int pointY)
1201 {
1202 auto delegate = webDelegate_.Upgrade();
1203 CHECK_NULL_VOID(delegate);
1204 ContainerScope scope(delegate->GetInstanceId());
1205 delegate->CreateOverlay(data, len, width, height, offsetX, offsetY, rectWidth, rectHeight, pointX, pointY);
1206 }
1207
OnOverlayStateChanged(int offsetX,int offsetY,int rectWidth,int rectHeight)1208 void WebClientImpl::OnOverlayStateChanged(int offsetX, int offsetY, int rectWidth, int rectHeight)
1209 {
1210 auto delegate = webDelegate_.Upgrade();
1211 CHECK_NULL_VOID(delegate);
1212 ContainerScope scope(delegate->GetInstanceId());
1213 delegate->OnOverlayStateChanged(offsetX, offsetY, rectWidth, rectHeight);
1214 }
1215
OnAdsBlocked(const std::string & url,const std::vector<std::string> & adsBlocked)1216 void WebClientImpl::OnAdsBlocked(const std::string& url, const std::vector<std::string>& adsBlocked)
1217 {
1218 auto delegate = webDelegate_.Upgrade();
1219 if (!delegate) {
1220 return;
1221 }
1222 ContainerScope scope(delegate->GetInstanceId());
1223 delegate->OnAdsBlocked(url, adsBlocked);
1224 }
1225
KeyboardReDispatch(std::shared_ptr<OHOS::NWeb::NWebKeyEvent> event,bool isUsed)1226 void WebClientImpl::KeyboardReDispatch(
1227 std::shared_ptr<OHOS::NWeb::NWebKeyEvent> event, bool isUsed)
1228 {
1229 auto delegate = webDelegate_.Upgrade();
1230 CHECK_NULL_VOID(delegate);
1231 ContainerScope scope(delegate->GetInstanceId());
1232 delegate->KeyboardReDispatch(event, isUsed);
1233 }
1234
OnCursorUpdate(double x,double y,double width,double height)1235 void WebClientImpl::OnCursorUpdate(double x, double y, double width, double height)
1236 {
1237 auto delegate = webDelegate_.Upgrade();
1238 CHECK_NULL_VOID(delegate);
1239 ContainerScope scope(delegate->GetInstanceId());
1240 delegate->OnCursorUpdate(x, y, width, height);
1241 }
1242
OnNativeEmbedVisibilityChange(const std::string & embed_id,bool visibility)1243 void WebClientImpl::OnNativeEmbedVisibilityChange(const std::string& embed_id, bool visibility)
1244 {
1245 auto delegate = webDelegate_.Upgrade();
1246 CHECK_NULL_VOID(delegate);
1247 ContainerScope scope(delegate->GetInstanceId());
1248 delegate->OnNativeEmbedVisibilityChange(embed_id, visibility);
1249 }
1250
StartVibraFeedback(const std::string & vibratorType)1251 void WebClientImpl::StartVibraFeedback(const std::string& vibratorType)
1252 {
1253 auto delegate = webDelegate_.Upgrade();
1254 CHECK_NULL_VOID(delegate);
1255 ContainerScope scope(delegate->GetInstanceId());
1256 delegate->StartVibraFeedback(vibratorType);
1257 }
1258
CloseImageOverlaySelection()1259 bool WebClientImpl::CloseImageOverlaySelection()
1260 {
1261 auto delegate = webDelegate_.Upgrade();
1262 CHECK_NULL_RETURN(delegate, false);
1263 ContainerScope scope(delegate->GetInstanceId());
1264 return delegate->CloseImageOverlaySelection();
1265 }
1266
OnScrollStart(const float x,const float y)1267 void WebClientImpl::OnScrollStart(const float x, const float y)
1268 {
1269 auto delegate = webDelegate_.Upgrade();
1270 CHECK_NULL_VOID(delegate);
1271 ContainerScope scope(delegate->GetInstanceId());
1272 delegate->OnScrollStart(x, y);
1273 }
1274
OnSslErrorRequestByJSV2(std::shared_ptr<NWeb::NWebJSSslErrorResult> result,OHOS::NWeb::SslError error,const std::vector<std::string> & certChainData)1275 bool WebClientImpl::OnSslErrorRequestByJSV2(std::shared_ptr<NWeb::NWebJSSslErrorResult> result,
1276 OHOS::NWeb::SslError error, const std::vector<std::string>& certChainData)
1277 {
1278 auto delegate = webDelegate_.Upgrade();
1279 CHECK_NULL_RETURN(delegate, false);
1280 ContainerScope scope(delegate->GetInstanceId());
1281
1282 bool jsResult = false;
1283 auto param = std::make_shared<WebSslErrorEvent>(AceType::MakeRefPtr<SslErrorResultOhos>(result),
1284 static_cast<int32_t>(error), certChainData);
1285 auto task = Container::CurrentTaskExecutor();
1286 CHECK_NULL_RETURN(task, false);
1287 task->PostSyncTask(
1288 [webClient = this, ¶m, &jsResult] {
1289 if (!webClient) {
1290 return;
1291 }
1292 auto delegate = webClient->webDelegate_.Upgrade();
1293 if (delegate) {
1294 jsResult = delegate->OnSslErrorRequest(param);
1295 }
1296 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientSslErrorRequest");
1297 return jsResult;
1298 }
1299
OnAccessibilityEvent(int64_t accessibilityId,int32_t eventType)1300 void WebClientImpl::OnAccessibilityEvent(int64_t accessibilityId, int32_t eventType)
1301 {
1302 TAG_LOGI(AceLogTag::ACE_WEB, "OnAccessibilityEvent accessibilityId: %{public}" PRId64 ", eventType: %{public}d",
1303 accessibilityId, eventType);
1304 auto delegate = webDelegate_.Upgrade();
1305 CHECK_NULL_VOID(delegate);
1306 ContainerScope scope(delegate->GetInstanceId());
1307 delegate->OnAccessibilityEvent(accessibilityId, static_cast<AccessibilityEventType>(eventType));
1308 }
1309 } // namespace OHOS::Ace
1310