1 /*
2  * Copyright (c) 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 "web_delegate_cross.h"
17 
18 #include "bridge/js_frontend/frontend_delegate_impl.h"
19 
20 namespace OHOS::Ace {
21 namespace {
22 constexpr char WEB_METHOD_RELOAD[] = "reload";
23 constexpr char WEB_METHOD_ROUTER_BACK[] = "routerBack";
24 constexpr char WEB_METHOD_UPDATEURL[] = "updateUrl";
25 constexpr char WEB_METHOD_CHANGE_PAGE_URL[] = "changePageUrl";
26 constexpr char WEB_METHOD_PAGE_PATH_INVALID[] = "pagePathInvalid";
27 
28 // The function name in Java and C++ must be same.
29 constexpr char WEB_METHOD_BACKWARD[] = "backward";
30 constexpr char WEB_METHOD_FORWARD[] = "forward";
31 constexpr char WEB_METHOD_ACCESSBACKWARD[] = "accessBackward";
32 constexpr char WEB_METHOD_ACCESSFORWARD[] = "accessForward";
33 constexpr char WEB_METHOD_ACCESS_STEP[] = "accessStep";
34 constexpr char WEB_METHOD_CLEAR_HISTORY[] = "clearHistory";
35 constexpr char WEB_METHOD_GET_HIT_TEST[] = "getHitTest";
36 constexpr char WEB_METHOD_ON_ACTIVE[] = "onActive";
37 constexpr char WEB_METHOD_ON_INACTIVE[] = "onInactive";
38 constexpr char WEB_METHOD_REQUEST_FOCUS[] = "requestFocus";
39 constexpr char WEB_METHOD_STOP[] = "stop";
40 constexpr char WEB_METHOD_REFRESH[] = "refresh";
41 constexpr char WEB_METHOD_LOAD_URL[] = "loadUrl";
42 constexpr char WEB_METHOD_LOAD_DATA[] = "loadData";
43 constexpr char WEB_METHOD_ADD_JAVASCRIPT[] = "registerJavaScriptProxy";
44 constexpr char WEB_METHOD_RUN_JAVASCRIPT[] = "runJavaScript";
45 constexpr char WEB_METHOD_REMOVE_JAVASCRIPT[] = "deleteJavaScriptRegister";
46 constexpr char WEB_METHOD_UPDATE_ATTRIBUTE[] = "updateAttribute";
47 constexpr char WEB_METHOD_SETCOOKIE[] = "setcookie";
48 constexpr char WEB_METHOD_SAVECOOKIESYNC[] = "savecookiesync";
49 constexpr char WEB_METHOD_TOUCH_DOWN[] = "touchDown";
50 constexpr char WEB_METHOD_TOUCH_UP[] = "touchUp";
51 constexpr char WEB_METHOD_TOUCH_MOVE[] = "touchMove";
52 constexpr char WEB_METHOD_TOUCH_CANCEL[] = "touchCancel";
53 constexpr char WEB_METHOD_UPDATE_LAYOUT[] = "updateLayout";
54 constexpr char WEB_METHOD_ZOOM[] = "zoom";
55 constexpr char WEB_METHOD_UPDATE_CONTENT[] = "updateWebContent";
56 
57 // The parameters in Java and C++ must be same.
58 constexpr char NTC_PARAM_ACCESS_STEP[] = "accessStep";
59 constexpr char NTC_PARAM_RUN_JS_CODE[] = "runJavaScriptCode";
60 constexpr char NTC_PARAM_COOKIE_URL[] = "cookie_url";
61 constexpr char NTC_PARAM_COOKIE_VALUE[] = "cookie_value";
62 constexpr char NTC_PARAM_REGISTER_JS_NAME[] = "jsInterfaceName";
63 constexpr char NTC_PARAM_REGISTER_JS_METHODLIST[] = "jsInterfaceMethodList";
64 constexpr char NTC_PARAM_DEL_INTERFACE[] = "javaScriptInterfaceName";
65 constexpr char NTC_PARAM_LOAD_URL[] = "load_url";
66 constexpr char NTC_PARAM_LOADDATA_BASEURL[] = "load_data_base_url";
67 constexpr char NTC_PARAM_LOADDATA_DATA[] = "load_data_data";
68 constexpr char NTC_PARAM_LOADDATA_MIMETYPE[] = "load_data_mimetype";
69 constexpr char NTC_PARAM_LOADDATA_ENCODING[] = "load_data_encoding";
70 constexpr char NTC_PARAM_LOADDATA_HISTORY[] = "load_data_history_url";
71 constexpr char NTC_PARAM_ZOOM_FACTOR[] = "zoom";
72 
73 constexpr char WEB_EVENT_PAGESTART[] = "onPageStarted";
74 constexpr char WEB_EVENT_PAGEFINISH[] = "onPageFinished";
75 constexpr char WEB_EVENT_DOWNLOADSTART[] = "onDownloadStart";
76 constexpr char WEB_EVENT_LOADINTERCEPT[] = "onLoadIntercept";
77 constexpr char WEB_EVENT_RUNJSCODE_RECVVALUE[] = "onRunJSRecvValue";
78 constexpr char WEB_EVENT_SCROLL[] = "onScroll";
79 constexpr char WEB_EVENT_SCALECHANGE[] = "onScaleChange";
80 constexpr char WEB_EVENT_JS_INVOKE_METHOD[] = "onJSInvokeMethod";
81 constexpr char WEB_EVENT_REFRESH_HISTORY[] = "onRefreshAccessedHistory";
82 constexpr char WEB_EVENT_RENDER_EXITED[] = "onRenderExited";
83 constexpr char WEB_EVENT_URL_LOAD_INTERCEPT[] = "onUrlLoadIntercept";
84 constexpr char WEB_EVENT_PAGECHANGED[] = "onProgressChanged";
85 constexpr char WEB_EVENT_RECVTITLE[] = "onReceivedTitle";
86 constexpr char WEB_EVENT_PAGEERROR[] = "onPageError";
87 constexpr char WEB_EVENT_ONMESSAGE[] = "onMessage";
88 constexpr char WEB_EVENT_ROUTERPUSH[] = "routerPush";
89 constexpr char WEB_EVENT_GEOHIDEPERMISSION[] = "onGeoHidePermission";
90 constexpr char WEB_EVENT_GEOPERMISSION[] = "onGeoPermission";
91 constexpr char WEB_EVENT_COMMONDIALOG[] = "onCommonDialog";
92 constexpr char WEB_EVENT_ONALERT[] = "onAlert";
93 constexpr char WEB_EVENT_ONCONFIRM[] = "onConfirm";
94 constexpr char WEB_EVENT_ONPROMPT[] = "onPrompt";
95 constexpr char WEB_EVENT_CONSOLEMESSAGE[] = "onConsoleMessage";
96 constexpr char WEB_EVENT_ERRORRECEIVE[] = "onErrorReceive";
97 constexpr char WEB_EVENT_ONSHOWFILECHOOSER[] = "onShowFileChooser";
98 constexpr char WEB_EVENT_ONHTTPERRORRECEIVE[] = "onHttpErrorReceive";
99 constexpr char WEB_EVENT_ONPAGEVISIBLE[] = "onPageVisible";
100 constexpr char WEB_EVENT_ONHTTPAUTHREQUEST[] = "onHttpAuthRequest";
101 constexpr char WEB_EVENT_ONPERMISSIONREQUEST[] = "onPermissionRequest";
102 
103 constexpr char WEB_CREATE[] = "web";
104 constexpr char NTC_PARAM_WEB[] = "web";
105 constexpr char NTC_PARAM_WIDTH[] = "width";
106 constexpr char NTC_PARAM_HEIGHT[] = "height";
107 constexpr char NTC_PARAM_LEFT[] = "left";
108 constexpr char NTC_PARAM_TOP[] = "top";
109 constexpr char NTC_ERROR[] = "create error";
110 constexpr char NTC_PARAM_SRC[] = "src";
111 constexpr char NTC_PARAM_ERROR_CODE[] = "errorCode";
112 constexpr char NTC_PARAM_URL[] = "url";
113 constexpr char NTC_PARAM_PAGE_URL[] = "pageUrl";
114 constexpr char NTC_PARAM_PAGE_INVALID[] = "pageInvalid";
115 constexpr char NTC_PARAM_DESCRIPTION[] = "description";
116 constexpr char NTC_PARAM_RICH_TEXT_INIT[] = "richTextInit";
117 constexpr char WEB_ERROR_CODE_CREATEFAIL[] = "error-web-delegate-000001";
118 constexpr char WEB_ERROR_MSG_CREATEFAIL[] = "create web_delegate failed.";
119 
120 constexpr char NTC_PARAM_X[] = "x";
121 constexpr char NTC_PARAM_Y[] = "y";
122 
123 constexpr char WEB_ATTRIBUTE_ZOOM_ACCESS[] = "zoomAccess";
124 constexpr char NTC_ZOOM_ACCESS[] = "zoomAccess";
125 constexpr char WEB_ATTRIBUTE_JAVASCRIPT_ACCESS[] = "javascriptAccess";
126 constexpr char NTC_JAVASCRIPT_ACCESS[] = "javascriptAccess";
127 constexpr char WEB_ATTRIBUTE_MIN_FONT_SIZE[] = "minFontSize";
128 constexpr char NTC_MIN_FONT_SIZE[] = "minFontSize";
129 constexpr char WEB_ATTRIBUTE_HORIZONTAL_SCROLLBAR_ACCESS[] = "horizontalScrollBarAccess";
130 constexpr char NTC_HORIZONTAL_SCROLLBAR_ACCESS[] = "horizontalScrollBarAccess";
131 constexpr char WEB_ATTRIBUTE_VERTICAL_SCROLLBAR_ACCESS[] = "verticalScrollBarAccess";
132 constexpr char NTC_VERTICAL_SCROLLBAR_ACCESS[] = "verticalScrollBarAccess";
133 constexpr char WEB_ATTRIBUTE_BACKGROUND_COLOR[] = "backgroundColor";
134 constexpr char NTC_BACKGROUND_COLOR[] = "backgroundColor";
135 constexpr char WEB_ATTRIBUTE_MEDIA_PLAY_GESTURE_ACCESS[] = "mediaPlayGestureAccess";
136 constexpr char NTC_MEDIA_PLAY_GESTURE_ACCESS[] = "mediaPlayGestureAccess";
137 
138 const char WEB_PARAM_NONE[] = "";
139 const char WEB_PARAM_AND[] = "#HWJS-&-#";
140 const char WEB_PARAM_VALUE[] = "value";
141 const char WEB_PARAM_EQUALS[] = "#HWJS-=-#";
142 const char WEB_PARAM_BEGIN[] = "#HWJS-?-#";
143 const char WEB_METHOD[] = "method";
144 const char WEB_EVENT[] = "event";
145 const char WEB_RESULT_FAIL[] = "fail";
146 constexpr char MIMETYPE[] = "text/html";
147 constexpr char ENCODING[] = "UTF-8";
148 
149 constexpr int FONT_MIN_SIZE = 1;
150 constexpr int FONT_MAX_SIZE = 72;
151 constexpr int RESOURCESID_ONE = 1;
152 constexpr int RESOURCESID_TWO = 2;
153 constexpr int RESOURCESID_THREE = 3;
154 
155 const std::string RESOURCE_VIDEO_CAPTURE = "TYPE_VIDEO_CAPTURE";
156 const std::string RESOURCE_AUDIO_CAPTURE = "TYPE_AUDIO_CAPTURE";
157 }
158 
GetRequestHeader() const159 std::map<std::string, std::string> WebResourceRequsetImpl::GetRequestHeader() const
160 {
161     return std::map<std::string, std::string>();
162 }
163 
GetRequestUrl() const164 std::string WebResourceRequsetImpl::GetRequestUrl() const
165 {
166     auto obj = WebObjectEventManager::GetInstance().GetResourceRequestObject();
167     if (!obj) {
168         return std::string();
169     }
170     return obj->GetRequestUrl(object_);
171 }
172 
GetMethod() const173 std::string WebResourceRequsetImpl::GetMethod() const
174 {
175     return "GET";
176 }
177 
IsRequestGesture() const178 bool WebResourceRequsetImpl::IsRequestGesture() const
179 {
180     return true;
181 }
182 
IsMainFrame() const183 bool WebResourceRequsetImpl::IsMainFrame() const
184 {
185     return true;
186 }
187 
IsRedirect() const188 bool WebResourceRequsetImpl::IsRedirect() const
189 {
190     return false;
191 }
192 
GetResponseHeader() const193 std::map<std::string, std::string> WebResourceResponseImpl::GetResponseHeader() const
194 {
195     return std::map<std::string, std::string>();
196 }
197 
GetResponseData() const198 std::string WebResourceResponseImpl::GetResponseData() const
199 {
200     return "ResponseData";
201 }
202 
GetEncoding() const203 std::string WebResourceResponseImpl::GetEncoding() const
204 {
205     auto obj = WebObjectEventManager::GetInstance().GetResourceResponseObject();
206     if (!obj) {
207         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceResponseImpl encoding failed");
208         return std::string();
209     }
210     return obj->GetEncoding(object_);
211 }
212 
GetMimeType() const213 std::string WebResourceResponseImpl::GetMimeType() const
214 {
215     auto obj = WebObjectEventManager::GetInstance().GetResourceResponseObject();
216     if (!obj) {
217         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceResponseImpl mimeType failed");
218         return std::string();
219     }
220     return obj->GetMimeType(object_);
221 }
222 
GetReason() const223 std::string WebResourceResponseImpl::GetReason() const
224 {
225     return "ResponseReason";
226 }
227 
GetStatusCode() const228 int WebResourceResponseImpl::GetStatusCode() const
229 {
230     auto obj = WebObjectEventManager::GetInstance().GetResourceResponseObject();
231     if (!obj) {
232         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceResponseImpl statusCode failed");
233         return 0;
234     }
235     return obj->GetStatusCode(object_);
236 }
237 
GetErrorInfo() const238 std::string WebResourceErrorImpl::GetErrorInfo() const
239 {
240     auto obj = WebObjectEventManager::GetInstance().GetResourceErrorObject();
241     if (!obj) {
242         return std::string();
243     }
244     return obj->GetErrorInfo(object_);
245 }
246 
GetErrorCode() const247 int WebResourceErrorImpl::GetErrorCode() const
248 {
249     auto obj = WebObjectEventManager::GetInstance().GetResourceErrorObject();
250     if (!obj) {
251         return 0;
252     }
253     return obj->GetErrorCode(object_);
254 }
255 
GetX() const256 double WebOffsetImpl::GetX() const
257 {
258     auto obj = WebObjectEventManager::GetInstance().GetScrollObject();
259     if (!obj) {
260         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebOffsetImpl X failed");
261         return 0.0;
262     }
263     return obj->GetX(object_);
264 }
265 
GetY() const266 double WebOffsetImpl::GetY() const
267 {
268     auto obj = WebObjectEventManager::GetInstance().GetScrollObject();
269     if (!obj) {
270         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebOffsetImpl Y failed");
271         return 0.0;
272     }
273     return obj->GetY(object_);
274 }
275 
GetMessage() const276 std::string WebConsoleMessage::GetMessage() const
277 {
278     auto obj = WebObjectEventManager::GetInstance().GetConsoleMessageObject();
279     if (!obj) {
280         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebConsoleMessage Message failed");
281         return std::string();
282     }
283     return obj->GetMessage(object_);
284 }
285 
GetMessageLevel() const286 int WebConsoleMessage::GetMessageLevel() const
287 {
288     auto obj = WebObjectEventManager::GetInstance().GetConsoleMessageObject();
289     if (!obj) {
290         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebConsoleMessage MessageLevel failed");
291         return 0;
292     }
293     return obj->GetMessageLevel(object_);
294 }
295 
GetSourceId() const296 std::string WebConsoleMessage::GetSourceId() const
297 {
298     return "SourceId";
299 }
300 
GetLineNumber() const301 int WebConsoleMessage::GetLineNumber() const
302 {
303     return 0;
304 }
305 
GetNewScale() const306 float WebScaleChangeImpl::GetNewScale() const
307 {
308     auto obj = WebObjectEventManager::GetInstance().GetScaleChangeObject();
309     if (!obj) {
310         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebScaleChangeImpl newScale failed");
311         return 0.0f;
312     }
313     return obj->GetNewScale(object_);
314 }
315 
GetOldScale() const316 float WebScaleChangeImpl::GetOldScale() const
317 {
318     auto obj = WebObjectEventManager::GetInstance().GetScaleChangeObject();
319     if (!obj) {
320         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebScaleChangeImpl oldScale failed");
321         return 0.0f;
322     }
323     return obj->GetOldScale(object_);
324 }
325 
GetUrl() const326 std::string WebCommonDialogImpl::GetUrl() const
327 {
328     auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
329     if (!obj) {
330         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebCommonDialogImpl url failed");
331         return std::string();
332     }
333     return obj->GetUrl(object_);
334 }
335 
GetMessage() const336 std::string WebCommonDialogImpl::GetMessage() const
337 {
338     auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
339     if (!obj) {
340         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebCommonDialogImpl message failed");
341         return std::string();
342     }
343     return obj->GetMessage(object_);
344 }
345 
GetValue() const346 std::string WebCommonDialogImpl::GetValue() const
347 {
348     auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
349     if (!obj) {
350         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebCommonDialogImpl value failed");
351         return std::string();
352     }
353     return obj->GetValue(object_);
354 }
355 
SetOrigin()356 void PermissionRequestImpl::SetOrigin()
357 {
358     auto obj = WebObjectEventManager::GetInstance().GetPermissionRequestObject();
359     if (!obj) {
360         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get PermissionRequestImpl origin failed");
361         return;
362     }
363     origin_ = obj->GetOrigin(object_);
364 }
365 
SetResources()366 void PermissionRequestImpl::SetResources()
367 {
368     auto obj = WebObjectEventManager::GetInstance().GetPermissionRequestObject();
369     if (!obj) {
370         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get PermissionRequestImpl resources failed");
371         return;
372     }
373     int resourcesId = obj->GetResourcesId(object_);
374     if (resourcesId == RESOURCESID_ONE) {
375         resources_.push_back(RESOURCE_VIDEO_CAPTURE);
376     } else if (resourcesId == RESOURCESID_TWO) {
377         resources_.push_back(RESOURCE_AUDIO_CAPTURE);
378     } else if (resourcesId == RESOURCESID_THREE) {
379         resources_.push_back(RESOURCE_VIDEO_CAPTURE);
380         resources_.push_back(RESOURCE_AUDIO_CAPTURE);
381     } else {
382         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get error type");
383     }
384 }
385 
GetOrigin() const386 std::string PermissionRequestImpl::GetOrigin() const
387 {
388     return origin_;
389 }
390 
GetResources() const391 std::vector<std::string> PermissionRequestImpl::GetResources() const
392 {
393     return resources_;
394 }
395 
Grant(std::vector<std::string> & resources) const396 void PermissionRequestImpl::Grant(std::vector<std::string>& resources) const
397 {
398     auto obj = WebObjectEventManager::GetInstance().GetPermissionRequestObject();
399     if (!obj) {
400         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager PermissionRequestObject grant failed");
401         return;
402     }
403     int resourcesId = 0;
404     for (auto res : resources) {
405         if (res == RESOURCE_VIDEO_CAPTURE) {
406             resourcesId |= RESOURCESID_ONE;
407         } else if (res == RESOURCE_AUDIO_CAPTURE) {
408             resourcesId |= RESOURCESID_TWO;
409         }
410     }
411     if (resourcesId != 0) {
412         obj->Grant(object_, resourcesId, index_);
413     }
414 }
415 
Deny() const416 void PermissionRequestImpl::Deny() const
417 {
418     auto obj = WebObjectEventManager::GetInstance().GetPermissionRequestObject();
419     if (!obj) {
420         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager PermissionRequestObject Deny failed");
421         return;
422     }
423     obj->Deny(object_, index_);
424 }
425 
GetHost() const426 std::string WebAuthRequestImpl::GetHost() const
427 {
428     auto obj = WebObjectEventManager::GetInstance().GetHttpAuthRequestObject();
429     if (!obj) {
430         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebAuthRequestImpl host failed");
431         return std::string();
432     }
433     return obj->GetHost(object_);
434 }
435 
GetRealm() const436 std::string WebAuthRequestImpl::GetRealm() const
437 {
438     auto obj = WebObjectEventManager::GetInstance().GetHttpAuthRequestObject();
439     if (!obj) {
440         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebAuthRequestImpl realm failed");
441         return std::string();
442     }
443     return obj->GetRealm(object_);
444 }
445 
GetUrl() const446 std::string WebDownloadResponseImpl::GetUrl() const
447 {
448     auto obj = WebObjectEventManager::GetInstance().GetDownloadResponseObject();
449     if (!obj) {
450         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebDownloadResponseImpl Url failed");
451         return std::string();
452     }
453     return obj->GetUrl(object_);
454 }
455 
GetMimetype() const456 std::string WebDownloadResponseImpl::GetMimetype() const
457 {
458     auto obj = WebObjectEventManager::GetInstance().GetDownloadResponseObject();
459     if (!obj) {
460         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebDownloadResponseImpl mimetype failed");
461         return std::string();
462     }
463     return obj->GetMimetype(object_);
464 }
465 
GetContentLength() const466 long WebDownloadResponseImpl::GetContentLength() const
467 {
468     auto obj = WebObjectEventManager::GetInstance().GetDownloadResponseObject();
469     if (!obj) {
470         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebDownloadResponseImpl contentLength failed");
471         return 0;
472     }
473     return obj->GetContentLength(object_);
474 }
475 
GetUserAgent() const476 std::string WebDownloadResponseImpl::GetUserAgent() const
477 {
478     auto obj = WebObjectEventManager::GetInstance().GetDownloadResponseObject();
479     if (!obj) {
480         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebDownloadResponseImpl userAgent failed");
481         return std::string();
482     }
483     return obj->GetUserAgent(object_);
484 }
485 
GetContentDisposition() const486 std::string WebDownloadResponseImpl::GetContentDisposition() const
487 {
488     return "ContentDisposition";
489 }
490 
Confirm(const std::string & promptResult)491 void DialogResult::Confirm(const std::string& promptResult)
492 {
493     auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
494     if (!obj) {
495         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager DialogResult prompt Confirm failed");
496         return;
497     }
498     if (dialogEventType_ == DialogEventType::DIALOG_EVENT_PROMPT) {
499         obj->Confirm(object_, promptResult, index_);
500     }
501 }
502 
Confirm()503 void DialogResult::Confirm()
504 {
505     auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
506     if (!obj) {
507         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager DialogResult Confirm failed");
508         return;
509     }
510     obj->Confirm(object_, index_);
511 }
512 
Cancel()513 void DialogResult::Cancel()
514 {
515     auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
516     if (!obj) {
517         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager DialogResult Cancel failed");
518         return;
519     }
520     obj->Cancel(object_, index_);
521 }
522 
Confirm(std::string & userName,std::string & pwd)523 bool WebAuthResult::Confirm(std::string& userName, std::string& pwd)
524 {
525     auto obj = WebObjectEventManager::GetInstance().GetHttpAuthRequestObject();
526     if (!obj) {
527         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager WebAuthResult confirm failed");
528         return false;
529     }
530     return obj->Confirm(object_, userName, pwd, index_);
531 }
532 
IsHttpAuthInfoSaved()533 bool WebAuthResult::IsHttpAuthInfoSaved()
534 {
535     auto obj = WebObjectEventManager::GetInstance().GetHttpAuthRequestObject();
536     if (!obj) {
537         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager WebAuthResult isHttpAuthInfoSaved failed");
538         return false;
539     }
540     return obj->IsHttpAuthInfoSaved(object_, index_);
541 }
542 
Cancel()543 void WebAuthResult::Cancel()
544 {
545     auto obj = WebObjectEventManager::GetInstance().GetHttpAuthRequestObject();
546     if (!obj) {
547         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager WebAuthResult cancel failed");
548         return;
549     }
550     obj->Cancel(object_, index_);
551 }
552 
GetTitle() const553 std::string WebFileChooserImpl::GetTitle() const
554 {
555     auto obj = WebObjectEventManager::GetInstance().GetFileChooserObject();
556     if (!obj) {
557         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileChooserImpl title failed");
558         return std::string();
559     }
560     return obj->GetTitle(object_);
561 }
562 
GetMode() const563 int WebFileChooserImpl::GetMode() const
564 {
565     auto obj = WebObjectEventManager::GetInstance().GetFileChooserObject();
566     if (!obj) {
567         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileChooserImpl title failed");
568         return 0;
569     }
570     return obj->GetMode(object_);
571 }
572 
GetDefaultFileName() const573 std::string WebFileChooserImpl::GetDefaultFileName() const
574 {
575     return "DefaultFileName";
576 }
577 
GetAcceptType() const578 std::vector<std::string> WebFileChooserImpl::GetAcceptType() const
579 {
580     auto obj = WebObjectEventManager::GetInstance().GetFileChooserObject();
581     if (!obj) {
582         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileChooserImpl acceptType failed");
583         return std::vector<std::string>();
584     }
585     return obj->GetAcceptType(object_);
586 }
587 
IsCapture() const588 bool WebFileChooserImpl::IsCapture() const
589 {
590     auto obj = WebObjectEventManager::GetInstance().GetFileChooserObject();
591     if (!obj) {
592         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileChooserImpl title failed");
593         return false;
594     }
595     return obj->IsCapture(object_);
596 }
597 
HandleFileList(std::vector<std::string> & fileList)598 void WebFileSelectorResult::HandleFileList(std::vector<std::string>& fileList)
599 {
600     auto obj = WebObjectEventManager::GetInstance().GetFileChooserObject();
601     if (!obj) {
602         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileChooserImpl FileSelectorResultCallback failed");
603         return;
604     }
605     obj->HandleFileList(object_, fileList, index_);
606 }
607 
GetOrigin() const608 std::string WebGeolocationImpl::GetOrigin() const
609 {
610     auto obj = WebObjectEventManager::GetInstance().GetGeolocationObject();
611     if (!obj) {
612         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileChooserImpl FileSelectorResultCallback failed");
613         return nullptr;
614     }
615     return obj->GetOrigin(object_);
616 }
617 
Invoke(const std::string & origin,const bool & allow,const bool & retain)618 void Geolocation::Invoke(const std::string& origin, const bool& allow, const bool& retain)
619 {
620     auto obj = WebObjectEventManager::GetInstance().GetGeolocationObject();
621     if (!obj) {
622         TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileChooserImpl FileSelectorResultCallback failed");
623         return;
624     }
625     obj->Invoke(index_, origin, allow, retain);
626 }
627 
~WebDelegateCross()628 WebDelegateCross::~WebDelegateCross()
629 {
630     ReleasePlatformResource();
631 }
632 
CreatePlatformResource(const Size & size,const Offset & position,const WeakPtr<NG::PipelineContext> & context)633 void WebDelegateCross::CreatePlatformResource(
634     const Size& size, const Offset& position, const WeakPtr<NG::PipelineContext>& context)
635 {
636     ReleasePlatformResource();
637     context_ = context;
638     CreatePluginResource(size, position, context);
639 }
640 
ReleasePlatformResource()641 void WebDelegateCross::ReleasePlatformResource()
642 {
643     Release();
644 }
645 
CreatePluginResource(const Size & size,const Offset & position,const WeakPtr<NG::PipelineContext> & context)646 void WebDelegateCross::CreatePluginResource(
647     const Size& size, const Offset& position, const WeakPtr<NG::PipelineContext>& context)
648 {
649     state_ = State::CREATING;
650     auto pipelineContext = context.Upgrade();
651     if (!pipelineContext) {
652         state_ = State::CREATEFAILED;
653         return;
654     }
655     context_ = context;
656     auto platformTaskExecutor =
657         SingleTaskExecutor::Make(pipelineContext->GetTaskExecutor(), TaskExecutor::TaskType::PLATFORM);
658     auto resRegister = pipelineContext->GetPlatformResRegister();
659     auto weakRes = AceType::WeakClaim(AceType::RawPtr(resRegister));
660     platformTaskExecutor.PostSyncTask([weakWeb = AceType::WeakClaim(this), weakRes, size, position] {
661         auto webDelegate = weakWeb.Upgrade();
662         if (webDelegate == nullptr) {
663             return;
664         }
665         auto webPattern = webDelegate->webPattern_.Upgrade();
666         if (!webPattern) {
667             webDelegate->OnError(WEB_ERROR_CODE_CREATEFAIL, WEB_ERROR_MSG_CREATEFAIL);
668             return;
669         }
670         auto resRegister = weakRes.Upgrade();
671         if (!resRegister) {
672             webDelegate->OnError(WEB_ERROR_CODE_CREATEFAIL, WEB_ERROR_MSG_CREATEFAIL);
673             return;
674         }
675         auto context = webDelegate->context_.Upgrade();
676         if (!context) {
677             return;
678         }
679 
680         std::string pageUrl;
681         int32_t pageId;
682         OHOS::Ace::Framework::DelegateClient::GetInstance().GetWebPageUrl(pageUrl, pageId);
683 
684         std::stringstream paramStream;
685         paramStream << NTC_PARAM_WEB << WEB_PARAM_EQUALS << webDelegate->id_ << WEB_PARAM_AND << NTC_PARAM_WIDTH
686                     << WEB_PARAM_EQUALS << size.Width() * context->GetViewScale() << WEB_PARAM_AND << NTC_PARAM_HEIGHT
687                     << WEB_PARAM_EQUALS << size.Height() * context->GetViewScale() << WEB_PARAM_AND << NTC_PARAM_LEFT
688                     << WEB_PARAM_EQUALS << position.GetX() * context->GetViewScale() << WEB_PARAM_AND << NTC_PARAM_TOP
689                     << WEB_PARAM_EQUALS << position.GetY() * context->GetViewScale() << WEB_PARAM_AND << NTC_PARAM_SRC
690                     << WEB_PARAM_EQUALS << webPattern->GetWebSrc().value_or("") << WEB_PARAM_AND << NTC_PARAM_PAGE_URL
691                     << WEB_PARAM_EQUALS << pageUrl << WEB_PARAM_AND << NTC_PARAM_RICH_TEXT_INIT << WEB_PARAM_EQUALS
692                     << webPattern->GetRichTextInit();
693 
694         std::string param = paramStream.str();
695         webDelegate->id_ = resRegister->CreateResource(WEB_CREATE, param);
696 
697         if (webDelegate->id_ == INVALID_ID) {
698             webDelegate->OnError(WEB_ERROR_CODE_CREATEFAIL, WEB_ERROR_MSG_CREATEFAIL);
699             return;
700         }
701         webDelegate->state_ = State::CREATED;
702         webDelegate->hash_ = webDelegate->MakeResourceHash();
703         webDelegate->RegisterWebEvent();
704         webDelegate->RegisterWebObjectEvent();
705         }, "ArkUIWebCreatePluginResource");
706 }
707 
GetWebId()708 int WebDelegateCross::GetWebId()
709 {
710     return id_;
711 }
712 
RegisterWebEvent()713 void WebDelegateCross::RegisterWebEvent()
714 {
715     auto context = DynamicCast<NG::PipelineContext>(context_.Upgrade());
716     CHECK_NULL_VOID(context);
717     auto resRegister = context->GetPlatformResRegister();
718     if (resRegister == nullptr) {
719         return;
720     }
721     resRegister->RegisterEvent(MakeEventHash(WEB_EVENT_PAGESTART), [weak = WeakClaim(this)](const std::string& param) {
722         auto delegate = weak.Upgrade();
723         if (delegate) {
724             delegate->OnPageStarted(param);
725         }
726     });
727     resRegister->RegisterEvent(MakeEventHash(WEB_EVENT_PAGEFINISH), [weak = WeakClaim(this)](const std::string& param) {
728         auto delegate = weak.Upgrade();
729         if (delegate) {
730             delegate->OnPageFinished(param);
731         }
732     });
733     resRegister->RegisterEvent(
734         MakeEventHash(WEB_EVENT_PAGECHANGED), [weak = WeakClaim(this)](const std::string& param) {
735             auto delegate = weak.Upgrade();
736             if (delegate) {
737                 delegate->OnProgressChanged(param);
738             }
739         });
740     resRegister->RegisterEvent(MakeEventHash(WEB_EVENT_RECVTITLE), [weak = WeakClaim(this)](const std::string& param) {
741         auto delegate = weak.Upgrade();
742         if (delegate) {
743             delegate->OnReceivedTitle(param);
744         }
745     });
746     resRegister->RegisterEvent(
747         MakeEventHash(WEB_EVENT_ONPAGEVISIBLE), [weak = WeakClaim(this)](const std::string& param) {
748             auto delegate = weak.Upgrade();
749             if (delegate) {
750                 delegate->OnPageVisible(param);
751             }
752         });
753     resRegister->RegisterEvent(
754         MakeEventHash(WEB_EVENT_GEOHIDEPERMISSION), [weak = WeakClaim(this)](const std::string& param) {
755             auto delegate = weak.Upgrade();
756             if (delegate) {
757                 delegate->OnGeolocationPermissionsHidePrompt();
758             }
759         });
760 }
761 
RegisterWebObjectEvent()762 void WebDelegateCross::RegisterWebObjectEvent()
763 {
764     WebObjectEventManager::GetInstance().RegisterObjectEvent(MakeEventHash(WEB_EVENT_ERRORRECEIVE),
765         [weak = WeakClaim(this)](const std::string& param, void* object) {
766         auto delegate = weak.Upgrade();
767         if (delegate) {
768             delegate->OnErrorReceive(object);
769         }
770     });
771     WebObjectEventManager::GetInstance().RegisterObjectEvent(
772         MakeEventHash(WEB_EVENT_SCROLL), [weak = WeakClaim(this)](const std::string& param, void* object) {
773             auto delegate = weak.Upgrade();
774             if (delegate) {
775                 delegate->OnScroll(object);
776             }
777         });
778     WebObjectEventManager::GetInstance().RegisterObjectEvent(
779         MakeEventHash(WEB_EVENT_SCALECHANGE), [weak = WeakClaim(this)](const std::string& param, void* object) {
780             auto delegate = weak.Upgrade();
781             if (delegate) {
782                 delegate->OnScaleChange(object);
783             }
784         });
785     WebObjectEventManager::GetInstance().RegisterObjectEvent(
786         MakeEventHash(WEB_EVENT_ONHTTPERRORRECEIVE), [weak = WeakClaim(this)](const std::string& param, void* object) {
787             auto delegate = weak.Upgrade();
788             if (delegate) {
789                 delegate->OnHttpErrorReceive(object);
790             }
791         });
792     WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(MakeEventHash(WEB_EVENT_CONSOLEMESSAGE),
793         [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
794             auto delegate = weak.Upgrade();
795             if (delegate) {
796                 return delegate->OnConsoleMessage(object);
797             }
798             return false;
799         });
800     WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(MakeEventHash(WEB_EVENT_LOADINTERCEPT),
801         [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
802             auto delegate = weak.Upgrade();
803             if (delegate) {
804                 return delegate->OnLoadIntercept(object);
805             }
806             return false;
807         });
808     WebObjectEventManager::GetInstance().RegisterObjectEvent(
809         MakeEventHash(WEB_EVENT_DOWNLOADSTART), [weak = WeakClaim(this)](const std::string& param, void* object) {
810             auto delegate = weak.Upgrade();
811             if (delegate) {
812                 delegate->OnDownloadStart(object);
813             }
814         });
815     WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(MakeEventHash(WEB_EVENT_ONSHOWFILECHOOSER),
816         [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
817             auto delegate = weak.Upgrade();
818             if (delegate) {
819                 return delegate->OnShowFileChooser(object);
820             }
821             return false;
822         });
823     WebObjectEventManager::GetInstance().RegisterObjectEvent(
824         MakeEventHash(WEB_EVENT_GEOPERMISSION), [weak = WeakClaim(this)](const std::string& param, void* object) {
825             auto delegate = weak.Upgrade();
826             if (delegate) {
827                 delegate->OnGeolocationPermissionsShowPrompt(object);
828             }
829         });
830     WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(
831         MakeEventHash(WEB_EVENT_ONALERT), [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
832             auto delegate = weak.Upgrade();
833             if (delegate) {
834                 return delegate->OnCommonDialog(object, DialogEventType::DIALOG_EVENT_ALERT);
835             }
836             return false;
837         });
838     WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(
839         MakeEventHash(WEB_EVENT_ONCONFIRM), [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
840             auto delegate = weak.Upgrade();
841             if (delegate) {
842                 return delegate->OnCommonDialog(object, DialogEventType::DIALOG_EVENT_CONFIRM);
843             }
844             return false;
845         });
846     WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(
847         MakeEventHash(WEB_EVENT_ONPROMPT), [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
848             auto delegate = weak.Upgrade();
849             if (delegate) {
850                 return delegate->OnCommonDialog(object, DialogEventType::DIALOG_EVENT_PROMPT);
851             }
852             return false;
853         });
854     WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(MakeEventHash(WEB_EVENT_ONPERMISSIONREQUEST),
855         [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
856             auto delegate = weak.Upgrade();
857             if (delegate) {
858                 return delegate->OnPermissionRequest(object);
859             }
860             return false;
861         });
862     WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(MakeEventHash(WEB_EVENT_ONHTTPAUTHREQUEST),
863         [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
864             auto delegate = weak.Upgrade();
865             if (delegate) {
866                 return delegate->OnHttpAuthRequest(object);
867             }
868             return false;
869         });
870 }
871 
HandleTouchDown(const int32_t & id,const double & x,const double & y,bool from_overlay)872 void WebDelegateCross::HandleTouchDown(
873     const int32_t& id, const double& x, const double& y, bool from_overlay)
874 {
875     hash_ = MakeResourceHash();
876     touchDownMethod_ = MakeMethodHash(WEB_METHOD_TOUCH_DOWN);
877     CallResRegisterMethod(touchDownMethod_, "", nullptr);
878 }
879 
HandleTouchUp(const int32_t & id,const double & x,const double & y,bool from_overlay)880 void WebDelegateCross::HandleTouchUp(
881     const int32_t& id, const double& x, const double& y, bool from_overlay)
882 {
883     hash_ = MakeResourceHash();
884     touchUpMethod_ = MakeMethodHash(WEB_METHOD_TOUCH_UP);
885     CallResRegisterMethod(touchUpMethod_, "", nullptr);
886 }
887 
HandleTouchMove(const int32_t & id,const double & x,const double & y,bool from_overlay)888 void WebDelegateCross::HandleTouchMove(
889     const int32_t& id, const double& x, const double& y, bool from_overlay)
890 {
891     hash_ = MakeResourceHash();
892     touchMoveMethod_ = MakeMethodHash(WEB_METHOD_TOUCH_MOVE);
893     CallResRegisterMethod(touchMoveMethod_, "", nullptr);
894 }
895 
HandleTouchCancel()896 void WebDelegateCross::HandleTouchCancel()
897 {
898     hash_ = MakeResourceHash();
899     touchCancelMethod_ = MakeMethodHash(WEB_METHOD_TOUCH_CANCEL);
900     CallResRegisterMethod(touchCancelMethod_, "", nullptr);
901 }
902 
HandleAxisEvent(const double & x,const double & y,const double & deltaX,const double & deltaY)903 void WebDelegateCross::HandleAxisEvent(const double& x, const double& y, const double& deltaX, const double& deltaY)
904 {
905     // cross platform is not support now;
906 }
907 
OnKeyEvent(int32_t keyCode,int32_t keyAction)908 bool WebDelegateCross::OnKeyEvent(int32_t keyCode, int32_t keyAction)
909 {
910     return true;
911 }
912 
OnMouseEvent(int32_t x,int32_t y,const MouseButton button,const MouseAction action,int count)913 void WebDelegateCross::OnMouseEvent(
914     int32_t x, int32_t y, const MouseButton button, const MouseAction action, int count)
915 {}
916 
OnFocus()917 void WebDelegateCross::OnFocus()
918 {}
919 
OnBlur()920 void WebDelegateCross::OnBlur()
921 {}
922 
UpdateLocale()923 void WebDelegateCross::UpdateLocale()
924 {}
925 
OnInactive()926 void WebDelegateCross::OnInactive()
927 {}
928 
OnActive()929 void WebDelegateCross::OnActive()
930 {}
931 
ShowWebView()932 void WebDelegateCross::ShowWebView()
933 {}
934 
HideWebView()935 void WebDelegateCross::HideWebView()
936 {}
937 
RecordWebEvent(Recorder::EventType eventType,const std::string & param) const938 void WebDelegateCross::RecordWebEvent(Recorder::EventType eventType, const std::string& param) const
939 {
940     if (!Recorder::EventRecorder::Get().IsComponentRecordEnable()) {
941         return;
942     }
943     auto pattern = webPattern_.Upgrade();
944     CHECK_NULL_VOID(pattern);
945     auto host = pattern->GetHost();
946     CHECK_NULL_VOID(host);
947     Recorder::EventParamsBuilder builder;
948     builder.SetId(host->GetInspectorIdValue(""))
949         .SetType(host->GetHostTag())
950         .SetEventType(eventType)
951         .SetText(param)
952         .SetDescription(host->GetAutoEventParamValue(""));
953     Recorder::EventRecorder::Get().OnEvent(std::move(builder));
954 }
955 
OnPageStarted(const std::string & param)956 void WebDelegateCross::OnPageStarted(const std::string& param)
957 {
958     ContainerScope scope(instanceId_);
959     auto context = context_.Upgrade();
960     CHECK_NULL_VOID(context);
961     context->GetTaskExecutor()->PostTask(
962         [weak = WeakClaim(this), param]() {
963             auto delegate = weak.Upgrade();
964             CHECK_NULL_VOID(delegate);
965             delegate->RecordWebEvent(Recorder::EventType::WEB_PAGE_BEGIN, param);
966             if (Container::IsCurrentUseNewPipeline()) {
967                 auto webPattern = delegate->webPattern_.Upgrade();
968                 CHECK_NULL_VOID(webPattern);
969                 auto webEventHub = webPattern->GetWebEventHub();
970                 CHECK_NULL_VOID(webEventHub);
971                 auto propOnPageStarted = webEventHub->GetOnPageStartedEvent();
972                 CHECK_NULL_VOID(propOnPageStarted);
973                 auto eventParam = std::make_shared<LoadWebPageStartEvent>(param);
974                 propOnPageStarted(eventParam);
975                 return;
976             }
977         },
978         TaskExecutor::TaskType::JS, "ArkUIWebPageStartEvent");
979 }
980 
OnPageFinished(const std::string & param)981 void WebDelegateCross::OnPageFinished(const std::string& param)
982 {
983     ContainerScope scope(instanceId_);
984     auto context = context_.Upgrade();
985     CHECK_NULL_VOID(context);
986     context->GetTaskExecutor()->PostTask(
987         [weak = WeakClaim(this), param]() {
988             auto delegate = weak.Upgrade();
989             CHECK_NULL_VOID(delegate);
990             delegate->RecordWebEvent(Recorder::EventType::WEB_PAGE_END, param);
991             if (Container::IsCurrentUseNewPipeline()) {
992                 auto webPattern = delegate->webPattern_.Upgrade();
993                 CHECK_NULL_VOID(webPattern);
994                 auto webEventHub = webPattern->GetWebEventHub();
995                 CHECK_NULL_VOID(webEventHub);
996                 auto propOnPageFinished = webEventHub->GetOnPageFinishedEvent();
997                 CHECK_NULL_VOID(propOnPageFinished);
998                 auto eventParam = std::make_shared<LoadWebPageFinishEvent>(param);
999                 propOnPageFinished(eventParam);
1000                 return;
1001             }
1002         },
1003         TaskExecutor::TaskType::JS, "ArkUIWebPageFinishEvent");
1004 }
1005 
OnPageError(const std::string & param)1006 void WebDelegateCross::OnPageError(const std::string& param)
1007 {}
1008 
OnProgressChanged(const std::string & param)1009 void WebDelegateCross::OnProgressChanged(const std::string& param)
1010 {
1011     ContainerScope scope(instanceId_);
1012     auto context = context_.Upgrade();
1013     CHECK_NULL_VOID(context);
1014     context->GetTaskExecutor()->PostTask(
1015         [weak = WeakClaim(this), param]() {
1016             auto delegate = weak.Upgrade();
1017             CHECK_NULL_VOID(delegate);
1018             if (Container::IsCurrentUseNewPipeline()) {
1019                 auto webPattern = delegate->webPattern_.Upgrade();
1020                 CHECK_NULL_VOID(webPattern);
1021                 auto webEventHub = webPattern->GetWebEventHub();
1022                 CHECK_NULL_VOID(webEventHub);
1023                 auto propOnProgressChange = webEventHub->GetOnProgressChangeEvent();
1024                 CHECK_NULL_VOID(propOnProgressChange);
1025                 auto eventParam = std::make_shared<LoadWebProgressChangeEvent>(atoi(param.c_str()));
1026                 propOnProgressChange(eventParam);
1027                 return;
1028             }
1029         },
1030         TaskExecutor::TaskType::JS, "ArkUIWebProgressChangeEvent");
1031 }
1032 
OnReceivedTitle(const std::string & param)1033 void WebDelegateCross::OnReceivedTitle(const std::string& param)
1034 {
1035     ContainerScope scope(instanceId_);
1036     auto context = context_.Upgrade();
1037     CHECK_NULL_VOID(context);
1038     context->GetTaskExecutor()->PostTask(
1039         [weak = WeakClaim(this), param]() {
1040             auto delegate = weak.Upgrade();
1041             CHECK_NULL_VOID(delegate);
1042             if (Container::IsCurrentUseNewPipeline()) {
1043                 auto webPattern = delegate->webPattern_.Upgrade();
1044                 CHECK_NULL_VOID(webPattern);
1045                 auto webEventHub = webPattern->GetWebEventHub();
1046                 CHECK_NULL_VOID(webEventHub);
1047                 auto propOnTitleReceive = webEventHub->GetOnTitleReceiveEvent();
1048                 CHECK_NULL_VOID(propOnTitleReceive);
1049                 auto eventParam = std::make_shared<LoadWebTitleReceiveEvent>(param);
1050                 propOnTitleReceive(eventParam);
1051                 return;
1052             }
1053         },
1054         TaskExecutor::TaskType::JS, "ArkUIWebTitleReceiveEvent");
1055 }
1056 
OnErrorReceive(void * object)1057 void WebDelegateCross::OnErrorReceive(void* object)
1058 {
1059     ContainerScope scope(instanceId_);
1060     CHECK_NULL_VOID(object);
1061     auto context = context_.Upgrade();
1062     CHECK_NULL_VOID(context);
1063     auto webResourceRequest = AceType::MakeRefPtr<WebResourceRequsetImpl>(object);
1064     CHECK_NULL_VOID(webResourceRequest);
1065     auto webResourceError = AceType::MakeRefPtr<WebResourceErrorImpl>(object);
1066     CHECK_NULL_VOID(webResourceError);
1067     auto requestHeader = webResourceRequest->GetRequestHeader();
1068     auto method = webResourceRequest->GetMethod();
1069     auto url = webResourceRequest->GetRequestUrl();
1070     auto hasGesture = webResourceRequest->IsRequestGesture();
1071     auto isMainFrame = webResourceRequest->IsMainFrame();
1072     auto isRedirect = webResourceRequest->IsRedirect();
1073     auto request = AceType::MakeRefPtr<WebRequest>(requestHeader, method, url, hasGesture, isMainFrame, isRedirect);
1074     auto errorInfo = webResourceError->GetErrorInfo();
1075     auto errorCode = webResourceError->GetErrorCode();
1076     auto error = AceType::MakeRefPtr<WebError>(errorInfo, errorCode);
1077     context->GetTaskExecutor()->PostTask(
1078         [weak = WeakClaim(this), request, error]() {
1079             auto delegate = weak.Upgrade();
1080             CHECK_NULL_VOID(delegate);
1081             if (Container::IsCurrentUseNewPipeline()) {
1082                 auto webPattern = delegate->webPattern_.Upgrade();
1083                 CHECK_NULL_VOID(webPattern);
1084                 auto webEventHub = webPattern->GetWebEventHub();
1085                 CHECK_NULL_VOID(webEventHub);
1086                 auto propOnErrorReceive = webEventHub->GetOnErrorReceiveEvent();
1087                 CHECK_NULL_VOID(propOnErrorReceive);
1088                 auto eventParam = std::make_shared<ReceivedErrorEvent>(request, error);
1089                 propOnErrorReceive(eventParam);
1090                 return;
1091             }
1092         },
1093         TaskExecutor::TaskType::JS, "ArkUIWebReceivedErrorEvent");
1094 }
1095 
OnScroll(void * object)1096 void WebDelegateCross::OnScroll(void* object)
1097 {
1098     ContainerScope scope(instanceId_);
1099     CHECK_NULL_VOID(object);
1100     auto context = context_.Upgrade();
1101     CHECK_NULL_VOID(context);
1102     auto webScrollOffset = AceType::MakeRefPtr<WebOffsetImpl>(object);
1103     CHECK_NULL_VOID(webScrollOffset);
1104     auto offsetX = webScrollOffset->GetX();
1105     auto offsetY = webScrollOffset->GetY();
1106     context->GetTaskExecutor()->PostTask(
1107         [weak = WeakClaim(this), offsetX, offsetY]() {
1108             auto delegate = weak.Upgrade();
1109             CHECK_NULL_VOID(delegate);
1110             if (Container::IsCurrentUseNewPipeline()) {
1111                 auto webPattern = delegate->webPattern_.Upgrade();
1112                 CHECK_NULL_VOID(webPattern);
1113                 auto webEventHub = webPattern->GetWebEventHub();
1114                 CHECK_NULL_VOID(webEventHub);
1115                 auto propOnScroll = webEventHub->GetOnScrollEvent();
1116                 CHECK_NULL_VOID(propOnScroll);
1117                 auto eventParam = std::make_shared<WebOnScrollEvent>(offsetX, offsetY);
1118                 propOnScroll(eventParam);
1119                 return;
1120             }
1121         },
1122         TaskExecutor::TaskType::JS, "ArkUIWebScrollEvent");
1123 }
1124 
OnScaleChange(void * object)1125 void WebDelegateCross::OnScaleChange(void* object)
1126 {
1127     ContainerScope scope(instanceId_);
1128     CHECK_NULL_VOID(object);
1129     auto context = context_.Upgrade();
1130     CHECK_NULL_VOID(context);
1131     auto webScaleChange = AceType::MakeRefPtr<WebScaleChangeImpl>(object);
1132     CHECK_NULL_VOID(webScaleChange);
1133     auto newScale = webScaleChange->GetNewScale();
1134     auto oldScale = webScaleChange->GetOldScale();
1135     context->GetTaskExecutor()->PostTask(
1136         [weak = WeakClaim(this), newScale, oldScale]() {
1137             auto delegate = weak.Upgrade();
1138             CHECK_NULL_VOID(delegate);
1139             if (Container::IsCurrentUseNewPipeline()) {
1140                 auto webPattern = delegate->webPattern_.Upgrade();
1141                 CHECK_NULL_VOID(webPattern);
1142                 auto webEventHub = webPattern->GetWebEventHub();
1143                 CHECK_NULL_VOID(webEventHub);
1144                 auto propOnScaleChange = webEventHub->GetOnScaleChangeEvent();
1145                 CHECK_NULL_VOID(propOnScaleChange);
1146                 auto eventParam = std::make_shared<ScaleChangeEvent>(oldScale, newScale);
1147                 propOnScaleChange(eventParam);
1148                 return;
1149             }
1150         },
1151         TaskExecutor::TaskType::JS, "ArkUIWebScaleChangeEvent");
1152 }
1153 
OnHttpErrorReceive(void * object)1154 void WebDelegateCross::OnHttpErrorReceive(void* object)
1155 {
1156     ContainerScope scope(instanceId_);
1157     CHECK_NULL_VOID(object);
1158     auto context = context_.Upgrade();
1159     CHECK_NULL_VOID(context);
1160     auto webResourceRequest = AceType::MakeRefPtr<WebResourceRequsetImpl>(object);
1161     CHECK_NULL_VOID(webResourceRequest);
1162     auto webResourceResponse = AceType::MakeRefPtr<WebResourceResponseImpl>(object);
1163     CHECK_NULL_VOID(webResourceResponse);
1164     auto requestHeader = webResourceRequest->GetRequestHeader();
1165     auto method = webResourceRequest->GetMethod();
1166     auto url = webResourceRequest->GetRequestUrl();
1167     auto hasGesture = webResourceRequest->IsRequestGesture();
1168     auto isMainFrame = webResourceRequest->IsMainFrame();
1169     auto isRedirect = webResourceRequest->IsRedirect();
1170     auto request = AceType::MakeRefPtr<WebRequest>(requestHeader, method, url, hasGesture, isMainFrame, isRedirect);
1171     auto responseHeader = webResourceResponse->GetResponseHeader();
1172     auto responseDate = webResourceResponse->GetResponseData();
1173     auto encoding = webResourceResponse->GetEncoding();
1174     auto mimeType = webResourceResponse->GetMimeType();
1175     auto reason = webResourceResponse->GetReason();
1176     auto statusCode = webResourceResponse->GetStatusCode();
1177     auto response =
1178         AceType::MakeRefPtr<WebResponse>(responseHeader, responseDate, encoding, mimeType, reason, statusCode);
1179 
1180     context->GetTaskExecutor()->PostTask(
1181         [weak = WeakClaim(this), request, response]() {
1182             auto delegate = weak.Upgrade();
1183             CHECK_NULL_VOID(delegate);
1184             if (Container::IsCurrentUseNewPipeline()) {
1185                 auto webPattern = delegate->webPattern_.Upgrade();
1186                 CHECK_NULL_VOID(webPattern);
1187                 auto webEventHub = webPattern->GetWebEventHub();
1188                 CHECK_NULL_VOID(webEventHub);
1189                 auto propOnHttpErrorReceive = webEventHub->GetOnHttpErrorReceiveEvent();
1190                 CHECK_NULL_VOID(propOnHttpErrorReceive);
1191                 auto eventParam = std::make_shared<ReceivedHttpErrorEvent>(request, response);
1192                 propOnHttpErrorReceive(eventParam);
1193                 return;
1194             }
1195         },
1196         TaskExecutor::TaskType::JS, "ArkUIWebHttpErrorReceiveEvent");
1197 }
1198 
OnConsoleMessage(void * object)1199 bool WebDelegateCross::OnConsoleMessage(void* object)
1200 {
1201     ContainerScope scope(instanceId_);
1202     CHECK_NULL_RETURN(object, false);
1203     auto context = context_.Upgrade();
1204     CHECK_NULL_RETURN(context, false);
1205     bool result = false;
1206     auto webConsoleMessage = AceType::MakeRefPtr<WebConsoleMessage>(object);
1207     CHECK_NULL_RETURN(webConsoleMessage, false);
1208     auto message = webConsoleMessage->GetMessage();
1209     auto sourceId = webConsoleMessage->GetSourceId();
1210     auto lineNumber = webConsoleMessage->GetLineNumber();
1211     auto messageLevel = webConsoleMessage->GetMessageLevel();
1212     auto consoleMessageParam = AceType::MakeRefPtr<WebConsoleMessageParam>(message, sourceId, lineNumber, messageLevel);
1213 
1214     context->GetTaskExecutor()->PostSyncTask(
1215         [weak = WeakClaim(this), consoleMessageParam, &result]() {
1216             auto delegate = weak.Upgrade();
1217             CHECK_NULL_VOID(delegate);
1218             if (Container::IsCurrentUseNewPipeline()) {
1219                 auto webPattern = delegate->webPattern_.Upgrade();
1220                 CHECK_NULL_VOID(webPattern);
1221                 auto webEventHub = webPattern->GetWebEventHub();
1222                 CHECK_NULL_VOID(webEventHub);
1223                 auto propOnConsole = webEventHub->GetOnConsoleEvent();
1224                 CHECK_NULL_VOID(propOnConsole);
1225                 auto eventParam = std::make_shared<LoadWebConsoleLogEvent>(consoleMessageParam);
1226                 result = propOnConsole(eventParam);
1227                 return;
1228             }
1229         },
1230         TaskExecutor::TaskType::JS, "ArkUIWebConsoleMessageEvent");
1231     return result;
1232 }
1233 
OnLoadIntercept(void * object)1234 bool WebDelegateCross::OnLoadIntercept(void* object)
1235 {
1236     ContainerScope scope(instanceId_);
1237     CHECK_NULL_RETURN(object, false);
1238     auto context = context_.Upgrade();
1239     CHECK_NULL_RETURN(context, false);
1240     bool result = false;
1241     auto webResourceRequest = AceType::MakeRefPtr<WebResourceRequsetImpl>(object);
1242     CHECK_NULL_RETURN(webResourceRequest, false);
1243     auto requestHeader = webResourceRequest->GetRequestHeader();
1244     auto method = webResourceRequest->GetMethod();
1245     auto url = webResourceRequest->GetRequestUrl();
1246     auto hasGesture = webResourceRequest->IsRequestGesture();
1247     auto isMainFrame = webResourceRequest->IsMainFrame();
1248     auto isRedirect = webResourceRequest->IsRedirect();
1249     auto request = AceType::MakeRefPtr<WebRequest>(requestHeader, method, url, hasGesture, isMainFrame, isRedirect);
1250 
1251     context->GetTaskExecutor()->PostSyncTask(
1252         [weak = WeakClaim(this), request, &result]() {
1253             auto delegate = weak.Upgrade();
1254             CHECK_NULL_VOID(delegate);
1255             if (Container::IsCurrentUseNewPipeline()) {
1256                 auto webPattern = delegate->webPattern_.Upgrade();
1257                 CHECK_NULL_VOID(webPattern);
1258                 auto webEventHub = webPattern->GetWebEventHub();
1259                 CHECK_NULL_VOID(webEventHub);
1260                 auto propOnLoadIntercept = webEventHub->GetOnLoadInterceptEvent();
1261                 CHECK_NULL_VOID(propOnLoadIntercept);
1262                 auto eventParam = std::make_shared<LoadInterceptEvent>(request);
1263                 result = propOnLoadIntercept(eventParam);
1264                 return;
1265             }
1266         },
1267         TaskExecutor::TaskType::JS, "ArkUIWebLoadInterceptEvent");
1268     return result;
1269 }
1270 
OnPageVisible(const std::string & param)1271 void WebDelegateCross::OnPageVisible(const std::string& param)
1272 {
1273     ContainerScope scope(instanceId_);
1274     auto context = context_.Upgrade();
1275     CHECK_NULL_VOID(context);
1276     context->GetTaskExecutor()->PostTask(
1277         [weak = WeakClaim(this), param]() {
1278             auto delegate = weak.Upgrade();
1279             CHECK_NULL_VOID(delegate);
1280             if (Container::IsCurrentUseNewPipeline()) {
1281                 auto webPattern = delegate->webPattern_.Upgrade();
1282                 CHECK_NULL_VOID(webPattern);
1283                 auto webEventHub = webPattern->GetWebEventHub();
1284                 CHECK_NULL_VOID(webEventHub);
1285                 auto propOnPageVisible = webEventHub->GetOnPageVisibleEvent();
1286                 CHECK_NULL_VOID(propOnPageVisible);
1287                 auto eventParam = std::make_shared<PageVisibleEvent>(param);
1288                 propOnPageVisible(eventParam);
1289                 return;
1290             }
1291         },
1292         TaskExecutor::TaskType::JS, "ArkUIWebPageVisibleEvent");
1293 }
1294 
OnDownloadStart(void * object)1295 void WebDelegateCross::OnDownloadStart(void* object)
1296 {
1297     ContainerScope scope(instanceId_);
1298     CHECK_NULL_VOID(object);
1299     auto context = context_.Upgrade();
1300     CHECK_NULL_VOID(context);
1301     auto webDownloadResponse = AceType::MakeRefPtr<WebDownloadResponseImpl>(object);
1302     CHECK_NULL_VOID(webDownloadResponse);
1303     auto url = webDownloadResponse->GetUrl();
1304     auto userAgent = webDownloadResponse->GetUserAgent();
1305     auto contentDisposition = webDownloadResponse->GetContentDisposition();
1306     auto mimetype = webDownloadResponse->GetMimetype();
1307     auto contentLength = webDownloadResponse->GetContentLength();
1308     context->GetTaskExecutor()->PostTask(
1309         [weak = WeakClaim(this), url, userAgent, contentDisposition, mimetype, contentLength]() {
1310             auto delegate = weak.Upgrade();
1311             CHECK_NULL_VOID(delegate);
1312             if (Container::IsCurrentUseNewPipeline()) {
1313                 auto webPattern = delegate->webPattern_.Upgrade();
1314                 CHECK_NULL_VOID(webPattern);
1315                 auto webEventHub = webPattern->GetWebEventHub();
1316                 CHECK_NULL_VOID(webEventHub);
1317                 auto propOnDownloadStart = webEventHub->GetOnDownloadStartEvent();
1318                 CHECK_NULL_VOID(propOnDownloadStart);
1319                 auto eventParam =
1320                     std::make_shared<DownloadStartEvent>(url, userAgent, contentDisposition, mimetype, contentLength);
1321                 propOnDownloadStart(eventParam);
1322                 return;
1323             }
1324         },
1325         TaskExecutor::TaskType::JS, "ArkUIWebDownloadStartEvent");
1326 }
1327 
OnCommonDialog(void * object,DialogEventType dialogEventType)1328 bool WebDelegateCross::OnCommonDialog(void* object, DialogEventType dialogEventType)
1329 {
1330     ContainerScope scope(instanceId_);
1331     CHECK_NULL_RETURN(object, false);
1332     auto context = context_.Upgrade();
1333     CHECK_NULL_RETURN(context, false);
1334     bool result = false;
1335     auto webCommonDialog = AceType::MakeRefPtr<WebCommonDialogImpl>(object);
1336     CHECK_NULL_RETURN(webCommonDialog, false);
1337     auto url = webCommonDialog->GetUrl();
1338     auto message = webCommonDialog->GetMessage();
1339     auto value = dialogEventType == DialogEventType::DIALOG_EVENT_PROMPT ? webCommonDialog->GetValue() : "";
1340     auto dialogResult = AceType::MakeRefPtr<DialogResult>(object, dialogEventType);
1341     context->GetTaskExecutor()->PostSyncTask(
1342         [weak = WeakClaim(this), url, message, value, dialogResult, dialogEventType, &result]() {
1343             auto delegate = weak.Upgrade();
1344             CHECK_NULL_VOID(delegate);
1345             if (Container::IsCurrentUseNewPipeline()) {
1346                 auto webPattern = delegate->webPattern_.Upgrade();
1347                 CHECK_NULL_VOID(webPattern);
1348                 auto webEventHub = webPattern->GetWebEventHub();
1349                 CHECK_NULL_VOID(webEventHub);
1350                 auto eventParam = std::make_shared<WebDialogEvent>(url, message, value, dialogEventType, dialogResult);
1351                 result = webEventHub->FireOnCommonDialogEvent(eventParam, dialogEventType);
1352                 return;
1353             }
1354         },
1355         TaskExecutor::TaskType::JS, "ArkUIWebFireOnCommonDialogEvent");
1356     return result;
1357 }
1358 
OnPermissionRequest(void * object)1359 bool WebDelegateCross::OnPermissionRequest(void* object)
1360 {
1361     ContainerScope scope(instanceId_);
1362     CHECK_NULL_RETURN(object, false);
1363     auto context = context_.Upgrade();
1364     CHECK_NULL_RETURN(context, false);
1365     bool result = false;
1366     auto webPermissionRequest = AceType::MakeRefPtr<PermissionRequestImpl>(object);
1367     webPermissionRequest->SetOrigin();
1368     webPermissionRequest->SetResources();
1369     CHECK_NULL_RETURN(webPermissionRequest, false);
1370     context->GetTaskExecutor()->PostSyncTask(
1371         [weak = WeakClaim(this), webPermissionRequest, &result]() {
1372             auto delegate = weak.Upgrade();
1373             CHECK_NULL_VOID(delegate);
1374             if (Container::IsCurrentUseNewPipeline()) {
1375                 auto webPattern = delegate->webPattern_.Upgrade();
1376                 CHECK_NULL_VOID(webPattern);
1377                 auto webEventHub = webPattern->GetWebEventHub();
1378                 CHECK_NULL_VOID(webEventHub);
1379                 auto propOnPermissionRequest = webEventHub->GetOnPermissionRequestEvent();
1380                 CHECK_NULL_VOID(propOnPermissionRequest);
1381                 auto eventParam = std::make_shared<WebPermissionRequestEvent>(webPermissionRequest);
1382                 propOnPermissionRequest(eventParam);
1383                 result = true;
1384                 return;
1385             }
1386         },
1387         TaskExecutor::TaskType::JS, "ArkUIWebPermissionRequestEvent");
1388     return result;
1389 }
1390 
OnHttpAuthRequest(void * object)1391 bool WebDelegateCross::OnHttpAuthRequest(void* object)
1392 {
1393     ContainerScope scope(instanceId_);
1394     CHECK_NULL_RETURN(object, false);
1395     auto context = context_.Upgrade();
1396     CHECK_NULL_RETURN(context, false);
1397     bool result = false;
1398     auto webHttpAuthRequest = AceType::MakeRefPtr<WebAuthRequestImpl>(object);
1399     CHECK_NULL_RETURN(webHttpAuthRequest, false);
1400     auto host = webHttpAuthRequest->GetHost();
1401     auto realm = webHttpAuthRequest->GetRealm();
1402     auto authResult = AceType::MakeRefPtr<WebAuthResult>(object);
1403     context->GetTaskExecutor()->PostSyncTask(
1404         [weak = WeakClaim(this), host, realm, authResult, &result]() {
1405             auto delegate = weak.Upgrade();
1406             CHECK_NULL_VOID(delegate);
1407             if (Container::IsCurrentUseNewPipeline()) {
1408                 auto webPattern = delegate->webPattern_.Upgrade();
1409                 CHECK_NULL_VOID(webPattern);
1410                 auto webEventHub = webPattern->GetWebEventHub();
1411                 CHECK_NULL_VOID(webEventHub);
1412                 auto propOnHttpAuthRequest = webEventHub->GetOnHttpAuthRequestEvent();
1413                 CHECK_NULL_VOID(propOnHttpAuthRequest);
1414                 auto eventParam = std::make_shared<WebHttpAuthEvent>(authResult, host, realm);
1415                 result = propOnHttpAuthRequest(eventParam);
1416                 return;
1417             }
1418         },
1419         TaskExecutor::TaskType::JS, "ArkUIWebHttpAuthRequestEvent");
1420     return result;
1421 }
1422 
OnShowFileChooser(void * object)1423 bool WebDelegateCross::OnShowFileChooser(void* object)
1424 {
1425     ContainerScope scope(instanceId_);
1426     CHECK_NULL_RETURN(object, false);
1427     auto context = context_.Upgrade();
1428     CHECK_NULL_RETURN(context, false);
1429     bool isAllowed = false;
1430     auto webFileChooser = AceType::MakeRefPtr<WebFileChooserImpl>(object);
1431     CHECK_NULL_RETURN(webFileChooser, false);
1432     auto title = webFileChooser->GetTitle();
1433     auto mode = webFileChooser->GetMode();
1434     auto defaultFileName = webFileChooser->GetDefaultFileName();
1435     auto acceptType = webFileChooser->GetAcceptType();
1436     auto isCapture = webFileChooser->IsCapture();
1437     auto param = AceType::MakeRefPtr<FileSelectorParam>(title, mode, defaultFileName, acceptType, isCapture);
1438     auto result = AceType::MakeRefPtr<WebFileSelectorResult>(object);
1439     bool postTask = context->GetTaskExecutor()->PostSyncTask(
1440         [weak = WeakClaim(this), param, result, &isAllowed]() {
1441             auto delegate = weak.Upgrade();
1442             CHECK_NULL_VOID(delegate);
1443             if (Container::IsCurrentUseNewPipeline()) {
1444                 auto webPattern = delegate->webPattern_.Upgrade();
1445                 CHECK_NULL_VOID(webPattern);
1446                 auto webEventHub = webPattern->GetWebEventHub();
1447                 CHECK_NULL_VOID(webEventHub);
1448                 auto propOnFileSelectorShow = webEventHub->GetOnFileSelectorShowEvent();
1449                 CHECK_NULL_VOID(propOnFileSelectorShow);
1450                 auto eventParam = std::make_shared<FileSelectorEvent>(param, result);
1451                 CHECK_NULL_VOID(eventParam);
1452                 isAllowed = propOnFileSelectorShow(eventParam);
1453                 return;
1454             }
1455         },
1456         TaskExecutor::TaskType::JS, "ArkUIWebFileSelectorShowEvent");
1457     return isAllowed;
1458 }
1459 
OnGeolocationPermissionsShowPrompt(void * object)1460 void WebDelegateCross::OnGeolocationPermissionsShowPrompt(void* object)
1461 {
1462     ContainerScope scope(instanceId_);
1463     CHECK_NULL_VOID(object);
1464     auto context = context_.Upgrade();
1465     CHECK_NULL_VOID(context);
1466     auto webGeolocationImpl = AceType::MakeRefPtr<WebGeolocationImpl>(object);
1467     CHECK_NULL_VOID(webGeolocationImpl);
1468     auto origin = webGeolocationImpl->GetOrigin();
1469     auto callback = AceType::MakeRefPtr<Geolocation>(object);
1470     context->GetTaskExecutor()->PostTask(
1471         [weak = WeakClaim(this), origin, callback]() {
1472             auto delegate = weak.Upgrade();
1473             CHECK_NULL_VOID(delegate);
1474             if (Container::IsCurrentUseNewPipeline()) {
1475                 auto webPattern = delegate->webPattern_.Upgrade();
1476                 CHECK_NULL_VOID(webPattern);
1477                 auto webEventHub = webPattern->GetWebEventHub();
1478                 CHECK_NULL_VOID(webEventHub);
1479                 auto propOnGeolocationShow = webEventHub->GetOnGeolocationShowEvent();
1480                 CHECK_NULL_VOID(propOnGeolocationShow);
1481                 auto eventParam = std::make_shared<LoadWebGeolocationShowEvent>(origin, callback);
1482                 propOnGeolocationShow(eventParam);
1483                 return;
1484             }
1485         },
1486         TaskExecutor::TaskType::JS, "ArkUIWebGeolocationShowEvent");
1487 }
1488 
OnGeolocationPermissionsHidePrompt()1489 void WebDelegateCross::OnGeolocationPermissionsHidePrompt()
1490 {
1491     ContainerScope scope(instanceId_);
1492     auto context = context_.Upgrade();
1493     CHECK_NULL_VOID(context);
1494     context->GetTaskExecutor()->PostTask(
1495         [weak = WeakClaim(this)]() {
1496             auto delegate = weak.Upgrade();
1497             CHECK_NULL_VOID(delegate);
1498             if (Container::IsCurrentUseNewPipeline()) {
1499                 auto webPattern = delegate->webPattern_.Upgrade();
1500                 CHECK_NULL_VOID(webPattern);
1501                 auto webEventHub = webPattern->GetWebEventHub();
1502                 CHECK_NULL_VOID(webEventHub);
1503                 auto propOnGeolocationHide = webEventHub->GetOnGeolocationHideEvent();
1504                 CHECK_NULL_VOID(propOnGeolocationHide);
1505                 auto eventParam = std::make_shared<LoadWebGeolocationHideEvent>("");
1506                 propOnGeolocationHide(eventParam);
1507                 return;
1508             }
1509         },
1510         TaskExecutor::TaskType::JS, "ArkUIWebGeolocationHideEvent");
1511 }
1512 
UpdateUserAgent(const std::string & userAgent)1513 void WebDelegateCross::UpdateUserAgent(const std::string& userAgent) {}
1514 
UpdateBackgroundColor(const int backgroundColor)1515 void WebDelegateCross::UpdateBackgroundColor(const int backgroundColor)
1516 {
1517     hash_ = MakeResourceHash();
1518     updateBackgroundColor_ = MakeMethodHash(WEB_ATTRIBUTE_BACKGROUND_COLOR);
1519     std::stringstream paramStream;
1520     paramStream << NTC_BACKGROUND_COLOR << WEB_PARAM_EQUALS << backgroundColor;
1521     std::string param = paramStream.str();
1522     CallResRegisterMethod(updateBackgroundColor_, param, nullptr);
1523 }
1524 
UpdateInitialScale(float scale)1525 void WebDelegateCross::UpdateInitialScale(float scale) {}
UpdateJavaScriptEnabled(const bool & isJsEnabled)1526 void WebDelegateCross::UpdateJavaScriptEnabled(const bool& isJsEnabled)
1527 {
1528     hash_ = MakeResourceHash();
1529     updateJavaScriptEnabled_ = MakeMethodHash(WEB_ATTRIBUTE_JAVASCRIPT_ACCESS);
1530     std::stringstream paramStream;
1531     paramStream << NTC_JAVASCRIPT_ACCESS << WEB_PARAM_EQUALS << isJsEnabled;
1532     std::string param = paramStream.str();
1533     CallResRegisterMethod(updateJavaScriptEnabled_, param, nullptr);
1534 }
1535 
UpdateAllowFileAccess(const bool & isFileAccessEnabled)1536 void WebDelegateCross::UpdateAllowFileAccess(const bool& isFileAccessEnabled) {}
UpdateBlockNetworkImage(const bool & onLineImageAccessEnabled)1537 void WebDelegateCross::UpdateBlockNetworkImage(const bool& onLineImageAccessEnabled) {}
UpdateLoadsImagesAutomatically(const bool & isImageAccessEnabled)1538 void WebDelegateCross::UpdateLoadsImagesAutomatically(const bool& isImageAccessEnabled) {}
UpdateMixedContentMode(const MixedModeContent & mixedMode)1539 void WebDelegateCross::UpdateMixedContentMode(const MixedModeContent& mixedMode) {}
1540 
UpdateSupportZoom(const bool & isZoomAccessEnabled)1541 void WebDelegateCross::UpdateSupportZoom(const bool& isZoomAccessEnabled)
1542 {
1543     hash_ = MakeResourceHash();
1544     updateZoomAccess_ = MakeMethodHash(WEB_ATTRIBUTE_ZOOM_ACCESS);
1545     std::stringstream paramStream;
1546     paramStream << NTC_ZOOM_ACCESS << WEB_PARAM_EQUALS << isZoomAccessEnabled;
1547     std::string param = paramStream.str();
1548     CallResRegisterMethod(updateZoomAccess_, param, nullptr);
1549 }
1550 
UpdateDomStorageEnabled(const bool & isDomStorageAccessEnabled)1551 void WebDelegateCross::UpdateDomStorageEnabled(const bool& isDomStorageAccessEnabled)
1552 {}
1553 
UpdateGeolocationEnabled(const bool & isGeolocationAccessEnabled)1554 void WebDelegateCross::UpdateGeolocationEnabled(const bool& isGeolocationAccessEnabled)
1555 {}
1556 
UpdateCacheMode(const WebCacheMode & mode)1557 void WebDelegateCross::UpdateCacheMode(const WebCacheMode& mode)
1558 {}
1559 
UpdateDarkMode(const WebDarkMode & mode)1560 void WebDelegateCross::UpdateDarkMode(const WebDarkMode& mode)
1561 {}
1562 
UpdateForceDarkAccess(const bool & access)1563 void WebDelegateCross::UpdateForceDarkAccess(const bool& access)
1564 {}
1565 
UpdateAudioResumeInterval(const int32_t & resumeInterval)1566 void WebDelegateCross::UpdateAudioResumeInterval(const int32_t& resumeInterval)
1567 {}
1568 
UpdateAudioExclusive(const bool & audioExclusive)1569 void WebDelegateCross::UpdateAudioExclusive(const bool& audioExclusive)
1570 {}
1571 
UpdateOverviewModeEnabled(const bool & isOverviewModeAccessEnabled)1572 void WebDelegateCross::UpdateOverviewModeEnabled(const bool& isOverviewModeAccessEnabled)
1573 {}
1574 
UpdateFileFromUrlEnabled(const bool & isFileFromUrlAccessEnabled)1575 void WebDelegateCross::UpdateFileFromUrlEnabled(const bool& isFileFromUrlAccessEnabled)
1576 {}
1577 
UpdateDatabaseEnabled(const bool & isDatabaseAccessEnabled)1578 void WebDelegateCross::UpdateDatabaseEnabled(const bool& isDatabaseAccessEnabled)
1579 {}
1580 
UpdateTextZoomRatio(const int32_t & textZoomRatioNum)1581 void WebDelegateCross::UpdateTextZoomRatio(const int32_t& textZoomRatioNum)
1582 {}
1583 
UpdateWebDebuggingAccess(bool isWebDebuggingAccessEnabled)1584 void WebDelegateCross::UpdateWebDebuggingAccess(bool isWebDebuggingAccessEnabled)
1585 {}
1586 
UpdatePinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)1587 void WebDelegateCross::UpdatePinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)
1588 {}
1589 
UpdateMediaPlayGestureAccess(bool isNeedGestureAccess)1590 void WebDelegateCross::UpdateMediaPlayGestureAccess(bool isNeedGestureAccess)
1591 {
1592     hash_ = MakeResourceHash();
1593     updateMediaPlayGestureAccess_ = MakeMethodHash(WEB_ATTRIBUTE_MEDIA_PLAY_GESTURE_ACCESS);
1594     std::stringstream paramStream;
1595     paramStream << NTC_MEDIA_PLAY_GESTURE_ACCESS << WEB_PARAM_EQUALS << isNeedGestureAccess;
1596     std::string param = paramStream.str();
1597     CallResRegisterMethod(updateMediaPlayGestureAccess_, param, nullptr);
1598 }
1599 
UpdateMultiWindowAccess(bool isMultiWindowAccessEnabled)1600 void WebDelegateCross::UpdateMultiWindowAccess(bool isMultiWindowAccessEnabled)
1601 {}
1602 
UpdateAllowWindowOpenMethod(bool isAllowWindowOpenMethod)1603 void WebDelegateCross::UpdateAllowWindowOpenMethod(bool isAllowWindowOpenMethod)
1604 {}
1605 
UpdateWebCursiveFont(const std::string & cursiveFontFamily)1606 void WebDelegateCross::UpdateWebCursiveFont(const std::string& cursiveFontFamily)
1607 {}
1608 
UpdateWebFantasyFont(const std::string & fantasyFontFamily)1609 void WebDelegateCross::UpdateWebFantasyFont(const std::string& fantasyFontFamily)
1610 {}
1611 
UpdateWebFixedFont(const std::string & fixedFontFamily)1612 void WebDelegateCross::UpdateWebFixedFont(const std::string& fixedFontFamily)
1613 {}
1614 
UpdateWebSansSerifFont(const std::string & sansSerifFontFamily)1615 void WebDelegateCross::UpdateWebSansSerifFont(const std::string& sansSerifFontFamily)
1616 {}
1617 
UpdateWebSerifFont(const std::string & serifFontFamily)1618 void WebDelegateCross::UpdateWebSerifFont(const std::string& serifFontFamily)
1619 {}
1620 
UpdateWebStandardFont(const std::string & standardFontFamily)1621 void WebDelegateCross::UpdateWebStandardFont(const std::string& standardFontFamily)
1622 {}
1623 
UpdateDefaultFixedFontSize(int32_t size)1624 void WebDelegateCross::UpdateDefaultFixedFontSize(int32_t size)
1625 {}
1626 
UpdateDefaultFontSize(int32_t defaultFontSize)1627 void WebDelegateCross::UpdateDefaultFontSize(int32_t defaultFontSize)
1628 {}
1629 
UpdateMinFontSize(int32_t minFontSize)1630 void WebDelegateCross::UpdateMinFontSize(int32_t minFontSize)
1631 {
1632     hash_ = MakeResourceHash();
1633     updateMinFontSize_ = MakeMethodHash(WEB_ATTRIBUTE_MIN_FONT_SIZE);
1634     std::stringstream paramStream;
1635     paramStream << NTC_MIN_FONT_SIZE << WEB_PARAM_EQUALS << std::clamp(minFontSize, FONT_MIN_SIZE, FONT_MAX_SIZE);
1636     std::string param = paramStream.str();
1637     CallResRegisterMethod(updateMinFontSize_, param, nullptr);
1638 }
1639 
UpdateMinLogicalFontSize(int32_t minLogicalFontSize)1640 void WebDelegateCross::UpdateMinLogicalFontSize(int32_t minLogicalFontSize)
1641 {}
1642 
UpdateBlockNetwork(bool isNetworkBlocked)1643 void WebDelegateCross::UpdateBlockNetwork(bool isNetworkBlocked)
1644 {}
1645 
UpdateHorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled)1646 void WebDelegateCross::UpdateHorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled)
1647 {
1648     hash_ = MakeResourceHash();
1649     updateHorizontalScrollBarAccess_ = MakeMethodHash(WEB_ATTRIBUTE_HORIZONTAL_SCROLLBAR_ACCESS);
1650     std::stringstream paramStream;
1651     paramStream << NTC_HORIZONTAL_SCROLLBAR_ACCESS << WEB_PARAM_EQUALS << isHorizontalScrollBarAccessEnabled;
1652     std::string param = paramStream.str();
1653     CallResRegisterMethod(updateHorizontalScrollBarAccess_, param, nullptr);
1654 }
1655 
UpdateVerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled)1656 void WebDelegateCross::UpdateVerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled)
1657 {
1658     hash_ = MakeResourceHash();
1659     updateVerticalScrollBarAccess_ = MakeMethodHash(WEB_ATTRIBUTE_VERTICAL_SCROLLBAR_ACCESS);
1660     std::stringstream paramStream;
1661     paramStream << NTC_VERTICAL_SCROLLBAR_ACCESS << WEB_PARAM_EQUALS << isVerticalScrollBarAccessEnabled;
1662     std::string param = paramStream.str();
1663     CallResRegisterMethod(updateVerticalScrollBarAccess_, param, nullptr);
1664 }
1665 
UpdateScrollBarColor(const std::string & colorValue)1666 void WebDelegateCross::UpdateScrollBarColor(const std::string& colorValue)
1667 {}
1668 
LoadUrl()1669 void WebDelegateCross::LoadUrl()
1670 {}
1671 
LoadDataWithRichText()1672 bool WebDelegateCross::LoadDataWithRichText()
1673 {
1674     auto webPattern = webPattern_.Upgrade();
1675     CHECK_NULL_RETURN(webPattern, false);
1676     auto webData = webPattern->GetWebData();
1677     CHECK_NULL_RETURN(webData, false);
1678     const std::string& data = webData.value();
1679     if (data.empty()) {
1680         return false;
1681     }
1682     hash_ = MakeResourceHash();
1683     loadDataMethod_ = MakeMethodHash(WEB_METHOD_LOAD_DATA);
1684     std::stringstream paramStream;
1685     paramStream << NTC_PARAM_LOADDATA_DATA << WEB_PARAM_EQUALS
1686                 << data.c_str() << WEB_PARAM_AND
1687                 << NTC_PARAM_LOADDATA_MIMETYPE << WEB_PARAM_EQUALS
1688                 << MIMETYPE << WEB_PARAM_AND
1689                 << NTC_PARAM_LOADDATA_ENCODING << WEB_PARAM_EQUALS
1690                 << ENCODING;
1691     std::string param = paramStream.str();
1692     CallResRegisterMethod(loadDataMethod_, param, nullptr);
1693     return true;
1694 }
1695 
SetBackgroundColor(int32_t backgroundColor)1696 void WebDelegateCross::SetBackgroundColor(int32_t backgroundColor)
1697 {}
1698 
SetBoundsOrResize(const Size & drawSize,const Offset & offset)1699 void WebDelegateCross::SetBoundsOrResize(const Size& drawSize, const Offset& offset)
1700 {
1701     hash_ = MakeResourceHash();
1702     updateLayoutMethod_ = MakeMethodHash(WEB_METHOD_UPDATE_LAYOUT);
1703     auto context = context_.Upgrade();
1704     if (!context) {
1705         return;
1706     }
1707     std::stringstream paramStream;
1708     float viewScale = context->GetViewScale();
1709     paramStream << NTC_PARAM_WIDTH << WEB_PARAM_EQUALS
1710                 << drawSize.Width() * viewScale << WEB_PARAM_AND
1711                 << NTC_PARAM_HEIGHT << WEB_PARAM_EQUALS
1712                 << drawSize.Height() * viewScale << WEB_PARAM_AND
1713                 << NTC_PARAM_LEFT << WEB_PARAM_EQUALS
1714                 << offset.GetX() * viewScale << WEB_PARAM_AND
1715                 << NTC_PARAM_TOP << WEB_PARAM_EQUALS
1716                 << offset.GetY() * viewScale;
1717     std::string param = paramStream.str();
1718     CallResRegisterMethod(updateLayoutMethod_, param, nullptr);
1719 }
1720 
SetDrawRect(int32_t x,int32_t y,int32_t width,int32_t height)1721 void WebDelegateCross::SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height)
1722 {
1723     // cross platform is not support now;
1724 }
1725 }
1726