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