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