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
OnAccessibilityEvent(int64_t accessibilityId,uint32_t eventType)133 void AccessibilityEventListenerImpl::OnAccessibilityEvent(int64_t accessibilityId, uint32_t eventType)
134 {
135 auto delegate = webDelegate_.Upgrade();
136 CHECK_NULL_VOID(delegate);
137 ContainerScope scope(delegate->GetInstanceId());
138 delegate->OnAccessibilityEvent(accessibilityId, static_cast<AccessibilityEventType>(eventType));
139 }
140
OnFindResultReceived(const int activeMatchOrdinal,const int numberOfMatches,const bool isDoneCounting)141 void FindListenerImpl::OnFindResultReceived(
142 const int activeMatchOrdinal, const int numberOfMatches, const bool isDoneCounting)
143 {
144 auto delegate = webDelegate_.Upgrade();
145 if (!delegate) {
146 return;
147 }
148 ContainerScope scope(delegate->GetInstanceId());
149 delegate->OnSearchResultReceive(activeMatchOrdinal, numberOfMatches, isDoneCounting);
150 }
151
SpanstringConvertHtml(const std::vector<uint8_t> & content)152 std::string SpanstringConvertHtmlImpl::SpanstringConvertHtml(const std::vector<uint8_t> &content)
153 {
154 ContainerScope scope(instanceId_);
155 auto delegate = webDelegate_.Upgrade();
156 if (!delegate) {
157 return "";
158 }
159 return delegate->SpanstringConvertHtml(content);
160 }
161
OnPageLoadEnd(int httpStatusCode,const std::string & url)162 void WebClientImpl::OnPageLoadEnd(int httpStatusCode, const std::string& url)
163 {
164 auto delegate = webDelegate_.Upgrade();
165 if (!delegate) {
166 return;
167 }
168 ContainerScope scope(delegate->GetInstanceId());
169 delegate->OnPageFinished(url);
170 }
171
OnFocus()172 bool WebClientImpl::OnFocus()
173 {
174 auto delegate = webDelegate_.Upgrade();
175 CHECK_NULL_RETURN(delegate, false);
176 ContainerScope scope(delegate->GetInstanceId());
177 bool isFocused = delegate->RequestFocus();
178 delegate->OnRequestFocus();
179
180 delegate->SetToken();
181 return isFocused;
182 }
183
OnFocus(OHOS::NWeb::NWebFocusSource source)184 bool WebClientImpl::OnFocus(OHOS::NWeb::NWebFocusSource source)
185 {
186 auto delegate = webDelegate_.Upgrade();
187 CHECK_NULL_RETURN(delegate, false);
188 ContainerScope scope(delegate->GetInstanceId());
189 bool isFocused = delegate->RequestFocus(source);
190 delegate->OnRequestFocus();
191
192 delegate->SetToken();
193 return isFocused;
194 }
195
OnConsoleLog(const std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message)196 bool WebClientImpl::OnConsoleLog(const std::shared_ptr<OHOS::NWeb::NWebConsoleLog> message)
197 {
198 auto delegate = webDelegate_.Upgrade();
199 CHECK_NULL_RETURN(delegate, false);
200 ContainerScope scope(delegate->GetInstanceId());
201 bool jsMessage = false;
202 auto task = Container::CurrentTaskExecutor();
203 if (!task) {
204 return false;
205 }
206 task->PostSyncTask(
207 [webClient = this, message, &jsMessage] {
208 if (!webClient) {
209 return;
210 }
211 auto delegate = webClient->webDelegate_.Upgrade();
212 if (delegate) {
213 jsMessage = delegate->OnConsoleLog(message);
214 }
215 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientConsoleLog");
216
217 return jsMessage;
218 }
219
OnPageLoadBegin(const std::string & url)220 void WebClientImpl::OnPageLoadBegin(const std::string& url)
221 {
222 auto delegate = webDelegate_.Upgrade();
223 if (!delegate) {
224 return;
225 }
226 ContainerScope scope(delegate->GetInstanceId());
227 delegate->OnPageStarted(url);
228 }
229
OnLoadingProgress(int newProgress)230 void WebClientImpl::OnLoadingProgress(int newProgress)
231 {
232 auto delegate = webDelegate_.Upgrade();
233 if (!delegate) {
234 return;
235 }
236 ContainerScope scope(delegate->GetInstanceId());
237 delegate->OnProgressChanged(newProgress);
238 }
239
OnPageTitle(const std::string & title)240 void WebClientImpl::OnPageTitle(const std::string &title)
241 {
242 auto delegate = webDelegate_.Upgrade();
243 if (!delegate) {
244 return;
245 }
246 ContainerScope scope(delegate->GetInstanceId());
247 delegate->OnReceivedTitle(title);
248 }
249
OnFullScreenExit()250 void WebClientImpl::OnFullScreenExit()
251 {
252 auto delegate = webDelegate_.Upgrade();
253 CHECK_NULL_VOID(delegate);
254 ContainerScope scope(delegate->GetInstanceId());
255 delegate->OnFullScreenExit();
256 }
257
OnFullScreenEnter(std::shared_ptr<NWeb::NWebFullScreenExitHandler> handler)258 void WebClientImpl::OnFullScreenEnter(std::shared_ptr<NWeb::NWebFullScreenExitHandler> handler)
259 {
260 auto delegate = webDelegate_.Upgrade();
261 CHECK_NULL_VOID(delegate);
262 CHECK_NULL_VOID(handler);
263 ContainerScope scope(delegate->GetInstanceId());
264 delegate->OnFullScreenEnter(handler, 0, 0);
265 }
266
OnFullScreenEnterWithVideoSize(std::shared_ptr<NWeb::NWebFullScreenExitHandler> handler,int videoNaturalWidth,int videoNaturalHeight)267 void WebClientImpl::OnFullScreenEnterWithVideoSize(
268 std::shared_ptr<NWeb::NWebFullScreenExitHandler> handler, int videoNaturalWidth, int videoNaturalHeight)
269 {
270 auto delegate = webDelegate_.Upgrade();
271 CHECK_NULL_VOID(delegate);
272 CHECK_NULL_VOID(handler);
273 ContainerScope scope(delegate->GetInstanceId());
274 delegate->OnFullScreenEnter(handler, videoNaturalWidth, videoNaturalHeight);
275 }
276
OnGeolocationHide()277 void WebClientImpl::OnGeolocationHide()
278 {
279 auto delegate = webDelegate_.Upgrade();
280 if (!delegate) {
281 return;
282 }
283 ContainerScope scope(delegate->GetInstanceId());
284 delegate->OnGeolocationPermissionsHidePrompt();
285 }
286
OnGeolocationShow(const std::string & origin,std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface> callback)287 void WebClientImpl::OnGeolocationShow(const std::string& origin,
288 std::shared_ptr<OHOS::NWeb::NWebGeolocationCallbackInterface> callback)
289 {
290 auto delegate = webDelegate_.Upgrade();
291 if (!delegate) {
292 return;
293 }
294 ContainerScope scope(delegate->GetInstanceId());
295 delegate->OnGeolocationPermissionsShowPrompt(origin, callback);
296 }
297
SetNWeb(std::shared_ptr<OHOS::NWeb::NWeb> nweb)298 void WebClientImpl::SetNWeb(std::shared_ptr<OHOS::NWeb::NWeb> nweb)
299 {
300 webviewWeak_ = nweb;
301 }
302
OnProxyDied()303 void WebClientImpl::OnProxyDied()
304 {
305 auto delegate = webDelegate_.Upgrade();
306 if (!delegate) {
307 return;
308 }
309 }
310
OnResourceLoadError(std::shared_ptr<NWeb::NWebUrlResourceRequest> request,std::shared_ptr<NWeb::NWebUrlResourceError> error)311 void WebClientImpl::OnResourceLoadError(
312 std::shared_ptr<NWeb::NWebUrlResourceRequest> request, std::shared_ptr<NWeb::NWebUrlResourceError> error)
313 {
314 auto delegate = webDelegate_.Upgrade();
315 if (!delegate) {
316 return;
317 }
318 ContainerScope scope(delegate->GetInstanceId());
319 delegate->OnErrorReceive(request, error);
320 }
321
OnHttpError(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request,std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> response)322 void WebClientImpl::OnHttpError(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request,
323 std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> response)
324 {
325 auto delegate = webDelegate_.Upgrade();
326 CHECK_NULL_VOID(delegate);
327 ContainerScope scope(delegate->GetInstanceId());
328 auto task = Container::CurrentTaskExecutor();
329 if (task == nullptr) {
330 return;
331 }
332 std::weak_ptr<WebClientImpl> webClientWeak = shared_from_this();
333 task->PostTask(
334 [webClient = webClientWeak, request, response] {
335 auto webClientUpgrade = webClient.lock();
336 if (webClientUpgrade == nullptr) {
337 return;
338 }
339 auto delegate = webClientUpgrade->GetWebDelegate();
340 if (delegate) {
341 delegate->OnHttpErrorReceive(request, response);
342 }
343 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientHttpError");
344 }
345
OnMessage(const std::string & param)346 void WebClientImpl::OnMessage(const std::string& param)
347 {
348 auto delegate = webDelegate_.Upgrade();
349 if (!delegate) {
350 return;
351 }
352 ContainerScope scope(delegate->GetInstanceId());
353 delegate->OnMessage(param);
354 }
355
OnRouterPush(const std::string & param)356 void WebClientImpl::OnRouterPush(const std::string& param)
357 {
358 auto delegate = webDelegate_.Upgrade();
359 if (!delegate) {
360 return;
361 }
362 ContainerScope scope(delegate->GetInstanceId());
363 delegate->OnRouterPush(param);
364 }
365
OnHandleInterceptUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request)366 bool WebClientImpl::OnHandleInterceptUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request)
367 {
368 auto delegate = webDelegate_.Upgrade();
369 if (!delegate) {
370 return false;
371 }
372 ContainerScope scope(delegate->GetInstanceId());
373
374 bool result = delegate->OnHandleInterceptUrlLoading(request->Url());
375 if (!result) {
376 result = delegate->OnHandleInterceptLoading(request);
377 }
378 return result;
379 }
380
OnHandleInterceptRequest(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request,std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> response)381 bool WebClientImpl::OnHandleInterceptRequest(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request,
382 std::shared_ptr<OHOS::NWeb::NWebUrlResourceResponse> response)
383 {
384 auto delegate = webDelegate_.Upgrade();
385 if (!delegate || (delegate->IsEmptyOnInterceptRequest())) {
386 return false;
387 }
388 ContainerScope scope(delegate->GetInstanceId());
389
390 auto webRequest = AceType::MakeRefPtr<WebRequest>(request->RequestHeaders(), request->Method(), request->Url(),
391 request->FromGesture(), request->IsAboutMainFrame(), request->IsRequestRedirect());
392 auto param = std::make_shared<OnInterceptRequestEvent>(webRequest);
393 RefPtr<WebResponse> webResponse = nullptr;
394 auto task = Container::CurrentTaskExecutor();
395 if (task == nullptr) {
396 return false;
397 }
398 task->PostSyncTask(
399 [&delegate, &webResponse, ¶m] {
400 webResponse = delegate->OnInterceptRequest(param);
401 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientInterceptRequest");
402 if (webResponse == nullptr) {
403 return false;
404 }
405 std::string data = webResponse->GetData();
406 response->PutResponseData(data);
407 response->PutResponseHeaders(webResponse->GetHeaders());
408 response->PutResponseMimeType(webResponse->GetMimeType());
409 response->PutResponseEncoding(webResponse->GetEncoding());
410 response->PutResponseStateAndStatuscode(webResponse->GetStatusCode(), webResponse->GetReason());
411 switch (webResponse->GetDataType()) {
412 case WebResponseDataType::FILE_TYPE:
413 response->PutResponseFileHandle(webResponse->GetFileHandle());
414 break;
415 case WebResponseDataType::RESOURCE_URL_TYPE:
416 response->PutResponseResourceUrl(webResponse->GetResourceUrl());
417 break;
418 case WebResponseDataType::BUFFER_TYPE:
419 response->PutResponseDataBuffer(webResponse->GetBuffer(), webResponse->GetBufferSize());
420 break;
421 default:
422 response->PutResponseData(data);
423 break;
424 }
425 if (webResponse->GetResponseStatus() == false) {
426 std::shared_ptr<NWebResponseAsyncHandle> asyncHandle = std::make_shared<NWebResponseAsyncHandle>(response);
427 webResponse->SetAsyncHandle(asyncHandle);
428 response->PutResponseDataStatus(false);
429 }
430 return true;
431 }
432
OnAlertDialogByJS(const std::string & url,const std::string & message,std::shared_ptr<NWeb::NWebJSDialogResult> result)433 bool WebClientImpl::OnAlertDialogByJS(
434 const std::string &url, const std::string &message, std::shared_ptr<NWeb::NWebJSDialogResult> result)
435 {
436 auto delegate = webDelegate_.Upgrade();
437 CHECK_NULL_RETURN(delegate, false);
438 ContainerScope scope(delegate->GetInstanceId());
439 return OnJsCommonDialog(this, DialogEventType::DIALOG_EVENT_ALERT, result, url, message);
440 }
441
OnBeforeUnloadByJS(const std::string & url,const std::string & message,std::shared_ptr<NWeb::NWebJSDialogResult> result)442 bool WebClientImpl::OnBeforeUnloadByJS(
443 const std::string &url, const std::string &message, std::shared_ptr<NWeb::NWebJSDialogResult> result)
444 {
445 auto delegate = webDelegate_.Upgrade();
446 CHECK_NULL_RETURN(delegate, false);
447 ContainerScope scope(delegate->GetInstanceId());
448 return OnJsCommonDialog(this, DialogEventType::DIALOG_EVENT_BEFORE_UNLOAD, result, url, message);
449 }
450
OnConfirmDialogByJS(const std::string & url,const std::string & message,std::shared_ptr<NWeb::NWebJSDialogResult> result)451 bool WebClientImpl::OnConfirmDialogByJS(
452 const std::string &url, const std::string &message, std::shared_ptr<NWeb::NWebJSDialogResult> result)
453 {
454 auto delegate = webDelegate_.Upgrade();
455 CHECK_NULL_RETURN(delegate, false);
456 ContainerScope scope(delegate->GetInstanceId());
457 return OnJsCommonDialog(this, DialogEventType::DIALOG_EVENT_CONFIRM, result, url, message);
458 }
459
OnPromptDialogByJS(const std::string & url,const std::string & message,const std::string & defaultValue,std::shared_ptr<NWeb::NWebJSDialogResult> result)460 bool WebClientImpl::OnPromptDialogByJS(const std::string &url, const std::string &message,
461 const std::string &defaultValue, std::shared_ptr<NWeb::NWebJSDialogResult> result)
462 {
463 auto delegate = webDelegate_.Upgrade();
464 CHECK_NULL_RETURN(delegate, false);
465 ContainerScope scope(delegate->GetInstanceId());
466 return OnJsCommonDialog(this, DialogEventType::DIALOG_EVENT_PROMPT, result, url, message, defaultValue);
467 }
468
OnRenderExited(OHOS::NWeb::RenderExitReason reason)469 void WebClientImpl::OnRenderExited(OHOS::NWeb::RenderExitReason reason)
470 {
471 auto delegate = webDelegate_.Upgrade();
472 if (!delegate) {
473 return;
474 }
475 ContainerScope scope(delegate->GetInstanceId());
476 delegate->OnRenderExited(reason);
477 }
478
OnRefreshAccessedHistory(const std::string & url,bool isReload)479 void WebClientImpl::OnRefreshAccessedHistory(const std::string& url, bool isReload)
480 {
481 auto delegate = webDelegate_.Upgrade();
482 if (!delegate) {
483 return;
484 }
485 ContainerScope scope(delegate->GetInstanceId());
486 delegate->OnRefreshAccessedHistory(url, isReload);
487 }
488
OnFileSelectorShow(std::shared_ptr<NWeb::NWebStringVectorValueCallback> callback,std::shared_ptr<NWeb::NWebFileSelectorParams> params)489 bool WebClientImpl::OnFileSelectorShow(
490 std::shared_ptr<NWeb::NWebStringVectorValueCallback> callback,
491 std::shared_ptr<NWeb::NWebFileSelectorParams> params)
492 {
493 auto delegate = webDelegate_.Upgrade();
494 CHECK_NULL_RETURN(delegate, false);
495 ContainerScope scope(delegate->GetInstanceId());
496 bool jsResult = false;
497 auto param = std::make_shared<FileSelectorEvent>(AceType::MakeRefPtr<FileSelectorParamOhos>(params),
498 AceType::MakeRefPtr<FileSelectorResultOhos>(callback));
499 auto task = Container::CurrentTaskExecutor();
500 if (task == nullptr) {
501 return false;
502 }
503 task->PostSyncTask(
504 [webClient = this, ¶m, &jsResult] {
505 if (webClient == nullptr) {
506 return;
507 }
508 auto delegate = webClient->GetWebDelegate();
509 if (delegate) {
510 jsResult = delegate->OnFileSelectorShow(param);
511 }
512 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientFileSelectorShow");
513 return jsResult;
514 }
515
OnResource(const std::string & url)516 void WebClientImpl::OnResource(const std::string& url)
517 {
518 auto task = Container::CurrentTaskExecutorSafely();
519 if (task == nullptr) {
520 return;
521 }
522 std::weak_ptr<WebClientImpl> webClientWeak = shared_from_this();
523 task->PostTask(
524 [webClient = webClientWeak, url] {
525 auto webClientUpgrade = webClient.lock();
526 if (webClientUpgrade == nullptr) {
527 return;
528 }
529 auto delegate = webClientUpgrade->GetWebDelegate();
530 if (delegate) {
531 delegate->OnResourceLoad(url);
532 }
533 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientResourceLoad");
534 }
535
OnScaleChanged(float oldScaleFactor,float newScaleFactor)536 void WebClientImpl::OnScaleChanged(float oldScaleFactor, float newScaleFactor)
537 {
538 auto delegate = webDelegate_.Upgrade();
539 if (!delegate) {
540 return;
541 }
542 ContainerScope scope(delegate->GetInstanceId());
543 delegate->OnScaleChange(oldScaleFactor, newScaleFactor);
544 }
545
OnScroll(double xOffset,double yOffset)546 void WebClientImpl::OnScroll(double xOffset, double yOffset)
547 {
548 auto delegate = webDelegate_.Upgrade();
549 if (!delegate) {
550 return;
551 }
552 ContainerScope scope(delegate->GetInstanceId());
553 delegate->OnScroll(xOffset, yOffset);
554 }
555
OnHttpAuthRequestByJS(std::shared_ptr<NWeb::NWebJSHttpAuthResult> result,const std::string & host,const std::string & realm)556 bool WebClientImpl::OnHttpAuthRequestByJS(std::shared_ptr<NWeb::NWebJSHttpAuthResult> result, const std::string &host,
557 const std::string &realm)
558 {
559 auto delegate = webDelegate_.Upgrade();
560 CHECK_NULL_RETURN(delegate, false);
561 ContainerScope scope(delegate->GetInstanceId());
562
563 bool jsResult = false;
564 auto param = std::make_shared<WebHttpAuthEvent>(AceType::MakeRefPtr<AuthResultOhos>(result), host, realm);
565 auto task = Container::CurrentTaskExecutor();
566 if (task == nullptr) {
567 return false;
568 }
569 task->PostSyncTask(
570 [webClient = this, ¶m, &jsResult] {
571 if (!webClient) {
572 return;
573 }
574 auto delegate = webClient->webDelegate_.Upgrade();
575 if (delegate) {
576 jsResult = delegate->OnHttpAuthRequest(param);
577 }
578 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientHttpAuthRequest");
579 return jsResult;
580 }
581
OnSslErrorRequestByJS(std::shared_ptr<NWeb::NWebJSSslErrorResult> result,OHOS::NWeb::SslError error)582 bool WebClientImpl::OnSslErrorRequestByJS(std::shared_ptr<NWeb::NWebJSSslErrorResult> result,
583 OHOS::NWeb::SslError error)
584 {
585 auto delegate = webDelegate_.Upgrade();
586 CHECK_NULL_RETURN(delegate, false);
587 ContainerScope scope(delegate->GetInstanceId());
588
589 bool jsResult = false;
590 auto param = std::make_shared<WebSslErrorEvent>(AceType::MakeRefPtr<SslErrorResultOhos>(result),
591 static_cast<int32_t>(error));
592 auto task = Container::CurrentTaskExecutor();
593 if (task == nullptr) {
594 return false;
595 }
596 task->PostSyncTask(
597 [webClient = this, ¶m, &jsResult] {
598 if (!webClient) {
599 return;
600 }
601 auto delegate = webClient->webDelegate_.Upgrade();
602 if (delegate) {
603 jsResult = delegate->OnSslErrorRequest(param);
604 }
605 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientSslErrorRequest");
606 return jsResult;
607 }
608
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)609 bool WebClientImpl::OnAllSslErrorRequestByJS(std::shared_ptr<NWeb::NWebJSAllSslErrorResult> result,
610 OHOS::NWeb::SslError error,
611 const std::string& url,
612 const std::string& originalUrl,
613 const std::string& referrer,
614 bool isFatalError,
615 bool isMainFrame)
616 {
617 auto delegate = webDelegate_.Upgrade();
618 CHECK_NULL_RETURN(delegate, false);
619 ContainerScope scope(delegate->GetInstanceId());
620
621 bool jsResult = false;
622 auto param = std::make_shared<WebAllSslErrorEvent>(AceType::MakeRefPtr<AllSslErrorResultOhos>(result),
623 static_cast<int32_t>(error), url, originalUrl, referrer, isFatalError, isMainFrame);
624 auto task = Container::CurrentTaskExecutor();
625 if (task == nullptr) {
626 return false;
627 }
628 task->PostSyncTask(
629 [webClient = this, ¶m, &jsResult] {
630 if (!webClient) {
631 return;
632 }
633 auto delegate = webClient->webDelegate_.Upgrade();
634 if (delegate) {
635 jsResult = delegate->OnAllSslErrorRequest(param);
636 }
637 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientAllSslErrorRequest");
638 return jsResult;
639 }
640
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)641 bool WebClientImpl::OnSslSelectCertRequestByJS(
642 std::shared_ptr<NWeb::NWebJSSslSelectCertResult> result,
643 const std::string& host,
644 int port,
645 const std::vector<std::string>& keyTypes,
646 const std::vector<std::string>& issuers)
647 {
648 auto delegate = webDelegate_.Upgrade();
649 CHECK_NULL_RETURN(delegate, false);
650 ContainerScope scope(delegate->GetInstanceId());
651
652 bool jsResult = false;
653 auto param = std::make_shared<WebSslSelectCertEvent>(AceType::MakeRefPtr<SslSelectCertResultOhos>(result),
654 host, port, keyTypes, issuers);
655 auto task = Container::CurrentTaskExecutor();
656 if (task == nullptr) {
657 return false;
658 }
659
660 task->PostSyncTask(
661 [webClient = this, ¶m, &jsResult] {
662 if (!webClient) {
663 return;
664 }
665 auto delegate = webClient->webDelegate_.Upgrade();
666 if (delegate) {
667 jsResult = delegate->OnSslSelectCertRequest(param);
668 }
669 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebClientSslSelectCertRequest");
670
671 return jsResult;
672 }
673
OnPermissionRequest(std::shared_ptr<NWeb::NWebAccessRequest> request)674 void WebClientImpl::OnPermissionRequest(std::shared_ptr<NWeb::NWebAccessRequest> request)
675 {
676 auto delegate = webDelegate_.Upgrade();
677 CHECK_NULL_VOID(delegate);
678 ContainerScope scope(delegate->GetInstanceId());
679 delegate->OnPermissionRequestPrompt(request);
680 }
681
OnScreenCaptureRequest(std::shared_ptr<NWeb::NWebScreenCaptureAccessRequest> request)682 void WebClientImpl::OnScreenCaptureRequest(std::shared_ptr<NWeb::NWebScreenCaptureAccessRequest> request)
683 {
684 auto delegate = webDelegate_.Upgrade();
685 CHECK_NULL_VOID(delegate);
686 ContainerScope scope(delegate->GetInstanceId());
687 delegate->OnScreenCaptureRequest(request);
688 }
689
RunContextMenu(std::shared_ptr<NWeb::NWebContextMenuParams> params,std::shared_ptr<NWeb::NWebContextMenuCallback> callback)690 bool WebClientImpl::RunContextMenu(
691 std::shared_ptr<NWeb::NWebContextMenuParams> params,
692 std::shared_ptr<NWeb::NWebContextMenuCallback> callback)
693 {
694 auto delegate = webDelegate_.Upgrade();
695 CHECK_NULL_RETURN(delegate, false);
696 ContainerScope scope(delegate->GetInstanceId());
697 bool jsResult = false;
698 auto param = std::make_shared<ContextMenuEvent>(AceType::MakeRefPtr<ContextMenuParamOhos>(params),
699 AceType::MakeRefPtr<ContextMenuResultOhos>(callback));
700 auto task = Container::CurrentTaskExecutor();
701 if (task == nullptr) {
702 return false;
703 }
704 task->PostSyncTask(
705 [webClient = this, ¶m, &jsResult] {
706 if (webClient == nullptr) {
707 return;
708 }
709 auto delegate = webClient->GetWebDelegate();
710 if (delegate) {
711 jsResult = delegate->OnContextMenuShow(param);
712 }
713 }, OHOS::Ace::TaskExecutor::TaskType::JS, "ArkUIWebRunContextMenu");
714 return jsResult;
715 }
716
UpdateClippedSelectionBounds(int x,int y,int w,int h)717 void WebClientImpl::UpdateClippedSelectionBounds(int x, int y, int w, int h)
718 {
719 auto delegate = webDelegate_.Upgrade();
720 CHECK_NULL_VOID(delegate);
721 ContainerScope scope(delegate->GetInstanceId());
722 delegate->UpdateClippedSelectionBounds(x, y, w, h);
723 }
724
RunQuickMenu(std::shared_ptr<NWeb::NWebQuickMenuParams> params,std::shared_ptr<NWeb::NWebQuickMenuCallback> callback)725 bool WebClientImpl::RunQuickMenu(std::shared_ptr<NWeb::NWebQuickMenuParams> params,
726 std::shared_ptr<NWeb::NWebQuickMenuCallback> callback)
727 {
728 if (!params || !callback) {
729 return false;
730 }
731 auto delegate = webDelegate_.Upgrade();
732 if (!delegate) {
733 return false;
734 }
735 ContainerScope scope(delegate->GetInstanceId());
736 return delegate->RunQuickMenu(params, callback);
737 }
738
HideHandleAndQuickMenuIfNecessary(bool hide)739 void WebClientImpl::HideHandleAndQuickMenuIfNecessary(bool hide)
740 {
741 auto delegate = webDelegate_.Upgrade();
742 CHECK_NULL_VOID(delegate);
743 ContainerScope scope(delegate->GetInstanceId());
744 delegate->HideHandleAndQuickMenuIfNecessary(hide);
745 }
746
ChangeVisibilityOfQuickMenu()747 void WebClientImpl::ChangeVisibilityOfQuickMenu()
748 {
749 auto delegate = webDelegate_.Upgrade();
750 CHECK_NULL_VOID(delegate);
751 ContainerScope scope(delegate->GetInstanceId());
752 delegate->ChangeVisibilityOfQuickMenu();
753 }
754
OnQuickMenuDismissed()755 void WebClientImpl::OnQuickMenuDismissed()
756 {
757 auto delegate = webDelegate_.Upgrade();
758 if (!delegate) {
759 return;
760 }
761 ContainerScope scope(delegate->GetInstanceId());
762 delegate->OnQuickMenuDismissed();
763 }
764
OnTouchSelectionChanged(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle,std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle,std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle)765 void WebClientImpl::OnTouchSelectionChanged(
766 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle,
767 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle,
768 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle)
769 {
770 auto delegate = webDelegate_.Upgrade();
771 if (!delegate) {
772 return;
773 }
774 ContainerScope scope(delegate->GetInstanceId());
775 delegate->OnTouchSelectionChanged(
776 insertHandle, startSelectionHandle, endSelectionHandle);
777 }
778
OnDragAndDropData(const void * data,size_t len,std::shared_ptr<NWeb::NWebImageOptions> opt)779 bool WebClientImpl::OnDragAndDropData(const void* data, size_t len, std::shared_ptr<NWeb::NWebImageOptions> opt)
780 {
781 auto delegate = webDelegate_.Upgrade();
782 if (!delegate) {
783 return false;
784 }
785 ContainerScope scope(delegate->GetInstanceId());
786 if (opt) {
787 return delegate->OnDragAndDropData(data, len, opt->GetWidth(), opt->GetHeight());
788 }
789 return delegate->OnDragAndDropData(data, len, 0, 0);
790 }
791
OnDragAndDropDataUdmf(std::shared_ptr<NWeb::NWebDragData> dragData)792 bool WebClientImpl::OnDragAndDropDataUdmf(std::shared_ptr<NWeb::NWebDragData> dragData)
793 {
794 auto delegate = webDelegate_.Upgrade();
795 if (!delegate) {
796 return false;
797 }
798 ContainerScope scope(delegate->GetInstanceId());
799 return delegate->OnDragAndDropDataUdmf(dragData);
800 }
801
UpdateDragCursor(NWeb::NWebDragData::DragOperation op)802 void WebClientImpl::UpdateDragCursor(NWeb::NWebDragData::DragOperation op)
803 {
804 auto delegate = webDelegate_.Upgrade();
805 CHECK_NULL_VOID(delegate);
806 ContainerScope scope(delegate->GetInstanceId());
807 delegate->UpdateDragCursor(op);
808 }
809
OnWindowNewByJS(const std::string & targetUrl,bool isAlert,bool isUserTrigger,std::shared_ptr<NWeb::NWebControllerHandler> handler)810 void WebClientImpl::OnWindowNewByJS(
811 const std::string& targetUrl,
812 bool isAlert,
813 bool isUserTrigger,
814 std::shared_ptr<NWeb::NWebControllerHandler> handler)
815 {
816 auto delegate = webDelegate_.Upgrade();
817 CHECK_NULL_VOID(delegate);
818 ContainerScope scope(delegate->GetInstanceId());
819 delegate->OnWindowNew(targetUrl, isAlert, isUserTrigger, handler);
820 }
821
OnWindowExitByJS()822 void WebClientImpl::OnWindowExitByJS()
823 {
824 auto delegate = webDelegate_.Upgrade();
825 CHECK_NULL_VOID(delegate);
826 ContainerScope scope(delegate->GetInstanceId());
827 delegate->OnWindowExit();
828 }
829
OnPageVisible(const std::string & url)830 void WebClientImpl::OnPageVisible(const std::string& url)
831 {
832 TAG_LOGI(AceLogTag::ACE_WEB, "WebClientImpl::OnPageVisible override enter");
833 auto delegate = webDelegate_.Upgrade();
834 CHECK_NULL_VOID(delegate);
835 ContainerScope scope(delegate->GetInstanceId());
836 delegate->OnPageVisible(url);
837 }
838
OnDataResubmission(std::shared_ptr<NWeb::NWebDataResubmissionCallback> handler)839 void WebClientImpl::OnDataResubmission(std::shared_ptr<NWeb::NWebDataResubmissionCallback> handler)
840 {
841 auto delegate = webDelegate_.Upgrade();
842 CHECK_NULL_VOID(delegate);
843 CHECK_NULL_VOID(handler);
844 ContainerScope scope(delegate->GetInstanceId());
845 delegate->OnDataResubmitted(handler);
846 }
847
OnNavigationEntryCommitted(std::shared_ptr<NWeb::NWebLoadCommittedDetails> details)848 void WebClientImpl::OnNavigationEntryCommitted(
849 std::shared_ptr<NWeb::NWebLoadCommittedDetails> details)
850 {
851 auto delegate = webDelegate_.Upgrade();
852 CHECK_NULL_VOID(delegate);
853 CHECK_NULL_VOID(details);
854 ContainerScope scope(delegate->GetInstanceId());
855 delegate->OnNavigationEntryCommitted(details);
856 }
857
OnPageIcon(const void * data,size_t width,size_t height,NWeb::ImageColorType colorType,NWeb::ImageAlphaType alphaType)858 void WebClientImpl::OnPageIcon(const void* data,
859 size_t width,
860 size_t height,
861 NWeb::ImageColorType colorType,
862 NWeb::ImageAlphaType alphaType)
863 {
864 auto delegate = webDelegate_.Upgrade();
865 CHECK_NULL_VOID(delegate);
866 ContainerScope scope(delegate->GetInstanceId());
867 delegate->OnFaviconReceived(data, width, height, colorType, alphaType);
868 }
869
OnDesktopIconUrl(const std::string & icon_url,bool precomposed)870 void WebClientImpl::OnDesktopIconUrl(const std::string& icon_url, bool precomposed)
871 {
872 auto delegate = webDelegate_.Upgrade();
873 CHECK_NULL_VOID(delegate);
874 ContainerScope scope(delegate->GetInstanceId());
875 delegate->OnTouchIconUrl(icon_url, precomposed);
876 }
877
OnCursorChange(const NWeb::CursorType & type,std::shared_ptr<NWeb::NWebCursorInfo> info)878 bool WebClientImpl::OnCursorChange(const NWeb::CursorType& type, std::shared_ptr<NWeb::NWebCursorInfo> info)
879 {
880 auto delegate = webDelegate_.Upgrade();
881 CHECK_NULL_RETURN(delegate, false);
882 ContainerScope scope(delegate->GetInstanceId());
883 return delegate->OnCursorChange(type, info);
884 }
885
OnSelectPopupMenu(std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params,std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback)886 void WebClientImpl::OnSelectPopupMenu(
887 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params,
888 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback)
889 {
890 auto delegate = webDelegate_.Upgrade();
891 CHECK_NULL_VOID(delegate);
892 ContainerScope scope(delegate->GetInstanceId());
893 delegate->OnSelectPopupMenu(params, callback);
894 }
895
ReleaseSurface()896 void ReleaseSurfaceImpl::ReleaseSurface()
897 {
898 auto delegate = webDelegate_.Upgrade();
899 CHECK_NULL_VOID(delegate);
900 ContainerScope scope(delegate->GetInstanceId());
901 if (!surfaceDelegate_) {
902 return;
903 }
904 surfaceDelegate_->ReleaseSurface();
905 }
906
OnAudioStateChanged(bool playing)907 void WebClientImpl::OnAudioStateChanged(bool playing)
908 {
909 auto delegate = webDelegate_.Upgrade();
910 CHECK_NULL_VOID(delegate);
911 ContainerScope scope(delegate->GetInstanceId());
912 delegate->OnAudioStateChanged(playing);
913 }
914
OnFirstContentfulPaint(int64_t navigationStartTick,int64_t firstContentfulPaintMs)915 void WebClientImpl::OnFirstContentfulPaint(int64_t navigationStartTick, int64_t firstContentfulPaintMs)
916 {
917 auto delegate = webDelegate_.Upgrade();
918 CHECK_NULL_VOID(delegate);
919 ContainerScope scope(delegate->GetInstanceId());
920 delegate->OnFirstContentfulPaint(navigationStartTick, firstContentfulPaintMs);
921 }
922
OnFirstMeaningfulPaint(std::shared_ptr<NWeb::NWebFirstMeaningfulPaintDetails> details)923 void WebClientImpl::OnFirstMeaningfulPaint(
924 std::shared_ptr<NWeb::NWebFirstMeaningfulPaintDetails> details)
925 {
926 auto delegate = webDelegate_.Upgrade();
927 CHECK_NULL_VOID(delegate);
928 CHECK_NULL_VOID(details);
929 ContainerScope scope(delegate->GetInstanceId());
930 delegate->OnFirstMeaningfulPaint(details);
931 }
932
OnLargestContentfulPaint(std::shared_ptr<NWeb::NWebLargestContentfulPaintDetails> details)933 void WebClientImpl::OnLargestContentfulPaint(
934 std::shared_ptr<NWeb::NWebLargestContentfulPaintDetails> details)
935 {
936 auto delegate = webDelegate_.Upgrade();
937 CHECK_NULL_VOID(delegate);
938 CHECK_NULL_VOID(details);
939 ContainerScope scope(delegate->GetInstanceId());
940 delegate->OnLargestContentfulPaint(details);
941 }
942
943
OnSafeBrowsingCheckResult(int threat_type)944 void WebClientImpl::OnSafeBrowsingCheckResult(int threat_type)
945 {
946 auto delegate = webDelegate_.Upgrade();
947 CHECK_NULL_VOID(delegate);
948 ContainerScope scope(delegate->GetInstanceId());
949 delegate->OnSafeBrowsingCheckResult(threat_type);
950 }
951
OnCompleteSwapWithNewSize()952 void WebClientImpl::OnCompleteSwapWithNewSize()
953 {
954 auto delegate = webDelegate_.Upgrade();
955 CHECK_NULL_VOID(delegate);
956 ContainerScope scope(delegate->GetInstanceId());
957 delegate->OnCompleteSwapWithNewSize();
958 }
959
OnResizeNotWork()960 void WebClientImpl::OnResizeNotWork()
961 {
962 auto delegate = webDelegate_.Upgrade();
963 CHECK_NULL_VOID(delegate);
964 ContainerScope scope(delegate->GetInstanceId());
965 delegate->OnResizeNotWork();
966 }
967
OnGetTouchHandleHotZone(std::shared_ptr<NWeb::NWebTouchHandleHotZone> hotZone)968 void WebClientImpl::OnGetTouchHandleHotZone(std::shared_ptr<NWeb::NWebTouchHandleHotZone> hotZone)
969 {
970 auto delegate = webDelegate_.Upgrade();
971 CHECK_NULL_VOID(delegate);
972 ContainerScope scope(delegate->GetInstanceId());
973 delegate->OnGetTouchHandleHotZone(hotZone);
974 }
975
OnDateTimeChooserPopup(std::shared_ptr<NWeb::NWebDateTimeChooser> chooser,const std::vector<std::shared_ptr<NWeb::NWebDateTimeSuggestion>> & suggestions,std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback)976 void WebClientImpl::OnDateTimeChooserPopup(
977 std::shared_ptr<NWeb::NWebDateTimeChooser> chooser,
978 const std::vector<std::shared_ptr<NWeb::NWebDateTimeSuggestion>>& suggestions,
979 std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback)
980 {
981 auto delegate = webDelegate_.Upgrade();
982 CHECK_NULL_VOID(delegate);
983 ContainerScope scope(delegate->GetInstanceId());
984 delegate->OnDateTimeChooserPopup(chooser, suggestions, callback);
985 }
986
OnDateTimeChooserClose()987 void WebClientImpl::OnDateTimeChooserClose()
988 {
989 auto delegate = webDelegate_.Upgrade();
990 CHECK_NULL_VOID(delegate);
991 ContainerScope scope(delegate->GetInstanceId());
992 delegate->OnDateTimeChooserClose();
993 }
994
OnOverScroll(float xOffset,float yOffset)995 void WebClientImpl::OnOverScroll(float xOffset, float yOffset)
996 {
997 auto delegate = webDelegate_.Upgrade();
998 CHECK_NULL_VOID(delegate);
999 ContainerScope scope(delegate->GetInstanceId());
1000 delegate->OnOverScroll(xOffset, yOffset);
1001 }
1002
OnOverScrollFlingVelocity(float xVelocity,float yVelocity,bool isFling)1003 void WebClientImpl::OnOverScrollFlingVelocity(float xVelocity, float yVelocity, bool isFling)
1004 {
1005 auto delegate = webDelegate_.Upgrade();
1006 CHECK_NULL_VOID(delegate);
1007 ContainerScope scope(delegate->GetInstanceId());
1008 delegate->OnOverScrollFlingVelocity(xVelocity, yVelocity, isFling);
1009 }
1010
OnOverScrollFlingEnd()1011 void WebClientImpl::OnOverScrollFlingEnd() {}
1012
OnScrollState(bool scrollState)1013 void WebClientImpl::OnScrollState(bool scrollState)
1014 {
1015 auto delegate = webDelegate_.Upgrade();
1016 CHECK_NULL_VOID(delegate);
1017 ContainerScope scope(delegate->GetInstanceId());
1018 delegate->OnScrollState(scrollState);
1019 }
OnNativeEmbedLifecycleChange(std::shared_ptr<NWeb::NWebNativeEmbedDataInfo> dataInfo)1020 void WebClientImpl::OnNativeEmbedLifecycleChange(std::shared_ptr<NWeb::NWebNativeEmbedDataInfo> dataInfo)
1021 {
1022 auto delegate = webDelegate_.Upgrade();
1023 CHECK_NULL_VOID(delegate);
1024 ContainerScope scope(delegate->GetInstanceId());
1025 delegate->OnNativeEmbedLifecycleChange(dataInfo);
1026 }
OnNativeEmbedGestureEvent(std::shared_ptr<NWeb::NWebNativeEmbedTouchEvent> event)1027 void WebClientImpl::OnNativeEmbedGestureEvent(std::shared_ptr<NWeb::NWebNativeEmbedTouchEvent> event)
1028 {
1029 auto delegate = webDelegate_.Upgrade();
1030 CHECK_NULL_VOID(delegate);
1031 ContainerScope scope(delegate->GetInstanceId());
1032 delegate->OnNativeEmbedGestureEvent(event);
1033 }
1034
OnRootLayerChanged(int width,int height)1035 void WebClientImpl::OnRootLayerChanged(int width, int height)
1036 {
1037 auto delegate = webDelegate_.Upgrade();
1038 CHECK_NULL_VOID(delegate);
1039 ContainerScope scope(delegate->GetInstanceId());
1040 delegate->OnRootLayerChanged(width, height);
1041 }
1042
ReleaseResizeHold()1043 void WebClientImpl::ReleaseResizeHold()
1044 {
1045 auto delegate = webDelegate_.Upgrade();
1046 CHECK_NULL_VOID(delegate);
1047 ContainerScope scope(delegate->GetInstanceId());
1048 delegate->ReleaseResizeHold();
1049 }
1050
FilterScrollEvent(const float x,const float y,const float xVelocity,const float yVelocity)1051 bool WebClientImpl::FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity)
1052 {
1053 auto delegate = webDelegate_.Upgrade();
1054 CHECK_NULL_RETURN(delegate, false);
1055 ContainerScope scope(delegate->GetInstanceId());
1056 return delegate->FilterScrollEvent(x, y, xVelocity, yVelocity);
1057 }
1058
OnIntelligentTrackingPreventionResult(const std::string & websiteHost,const std::string & trackerHost)1059 void WebClientImpl::OnIntelligentTrackingPreventionResult(
1060 const std::string& websiteHost, const std::string& trackerHost)
1061 {
1062 auto delegate = webDelegate_.Upgrade();
1063 CHECK_NULL_VOID(delegate);
1064 ContainerScope scope(delegate->GetInstanceId());
1065 delegate->OnIntelligentTrackingPreventionResult(websiteHost, trackerHost);
1066 }
1067
OnTooltip(const std::string & tooltip)1068 void WebClientImpl::OnTooltip(const std::string& tooltip)
1069 {
1070 auto delegate = webDelegate_.Upgrade();
1071 CHECK_NULL_VOID(delegate);
1072 ContainerScope scope(delegate->GetInstanceId());
1073 delegate->OnTooltip(tooltip);
1074 }
1075
GetVisibleRectToWeb(int & visibleX,int & visibleY,int & visibleWidth,int & visibleHeight)1076 void WebClientImpl::GetVisibleRectToWeb(int& visibleX, int& visibleY, int& visibleWidth, int& visibleHeight)
1077 {
1078 auto delegate = webDelegate_.Upgrade();
1079 CHECK_NULL_VOID(delegate);
1080 ContainerScope scope(delegate->GetInstanceId());
1081 delegate->GetVisibleRectToWeb(visibleX, visibleY, visibleWidth, visibleHeight);
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 } // namespace OHOS::Ace
1267