1 /*
2 * Copyright (c) 2023-2025 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_ONINTERCEPTREQUEST[] = "onInterceptRequest";
78 constexpr char WEB_EVENT_RUNJSCODE_RECVVALUE[] = "onRunJSRecvValue";
79 constexpr char WEB_EVENT_SCROLL[] = "onScroll";
80 constexpr char WEB_EVENT_SCALECHANGE[] = "onScaleChange";
81 constexpr char WEB_EVENT_JS_INVOKE_METHOD[] = "onJSInvokeMethod";
82 constexpr char WEB_EVENT_ON_BEFORE_UNLOAD[] = "onBeforeUnload";
83 constexpr char WEB_EVENT_REFRESH_HISTORY[] = "onRefreshAccessedHistory";
84 constexpr char WEB_EVENT_RENDER_EXITED[] = "onRenderExited";
85 constexpr char WEB_EVENT_FULLSCREEN_ENTER[] = "onFullScreenEnter";
86 constexpr char WEB_EVENT_FULLSCREEN_EXIT[] = "onFullScreenExit";
87 constexpr char WEB_EVENT_URL_LOAD_INTERCEPT[] = "onUrlLoadIntercept";
88 constexpr char WEB_EVENT_PAGECHANGED[] = "onProgressChanged";
89 constexpr char WEB_EVENT_RECVTITLE[] = "onReceivedTitle";
90 constexpr char WEB_EVENT_PAGEERROR[] = "onPageError";
91 constexpr char WEB_EVENT_ONMESSAGE[] = "onMessage";
92 constexpr char WEB_EVENT_ROUTERPUSH[] = "routerPush";
93 constexpr char WEB_EVENT_GEOHIDEPERMISSION[] = "onGeoHidePermission";
94 constexpr char WEB_EVENT_GEOPERMISSION[] = "onGeoPermission";
95 constexpr char WEB_EVENT_COMMONDIALOG[] = "onCommonDialog";
96 constexpr char WEB_EVENT_ONALERT[] = "onAlert";
97 constexpr char WEB_EVENT_ONCONFIRM[] = "onConfirm";
98 constexpr char WEB_EVENT_ONPROMPT[] = "onPrompt";
99 constexpr char WEB_EVENT_CONSOLEMESSAGE[] = "onConsoleMessage";
100 constexpr char WEB_EVENT_ERRORRECEIVE[] = "onErrorReceive";
101 constexpr char WEB_EVENT_ONSHOWFILECHOOSER[] = "onShowFileChooser";
102 constexpr char WEB_EVENT_ONHTTPERRORRECEIVE[] = "onHttpErrorReceive";
103 constexpr char WEB_EVENT_ONPAGEVISIBLE[] = "onPageVisible";
104 constexpr char WEB_EVENT_ONHTTPAUTHREQUEST[] = "onHttpAuthRequest";
105 constexpr char WEB_EVENT_ONPERMISSIONREQUEST[] = "onPermissionRequest";
106
107 constexpr char WEB_CREATE[] = "web";
108 constexpr char NTC_PARAM_WEB[] = "web";
109 constexpr char NTC_PARAM_WIDTH[] = "width";
110 constexpr char NTC_PARAM_HEIGHT[] = "height";
111 constexpr char NTC_PARAM_LEFT[] = "left";
112 constexpr char NTC_PARAM_TOP[] = "top";
113 constexpr char NTC_ERROR[] = "create error";
114 constexpr char NTC_PARAM_SRC[] = "src";
115 constexpr char NTC_PARAM_ERROR_CODE[] = "errorCode";
116 constexpr char NTC_PARAM_URL[] = "url";
117 constexpr char NTC_PARAM_PAGE_URL[] = "pageUrl";
118 constexpr char NTC_PARAM_PAGE_INVALID[] = "pageInvalid";
119 constexpr char NTC_PARAM_DESCRIPTION[] = "description";
120 constexpr char NTC_PARAM_RICH_TEXT_INIT[] = "richTextInit";
121 constexpr char WEB_ERROR_CODE_CREATEFAIL[] = "error-web-delegate-000001";
122 constexpr char WEB_ERROR_MSG_CREATEFAIL[] = "create web_delegate failed.";
123
124 constexpr char NTC_PARAM_X[] = "x";
125 constexpr char NTC_PARAM_Y[] = "y";
126
127 constexpr char WEB_ATTRIBUTE_ZOOM_ACCESS[] = "zoomAccess";
128 constexpr char NTC_ZOOM_ACCESS[] = "zoomAccess";
129 constexpr char NTC_INCOGNITO_MODE[] = "incognitoMode";
130 constexpr char WEB_ATTRIBUTE_JAVASCRIPT_ACCESS[] = "javascriptAccess";
131 constexpr char NTC_JAVASCRIPT_ACCESS[] = "javascriptAccess";
132 constexpr char WEB_ATTRIBUTE_MIN_FONT_SIZE[] = "minFontSize";
133 constexpr char NTC_MIN_FONT_SIZE[] = "minFontSize";
134 constexpr char WEB_ATTRIBUTE_HORIZONTAL_SCROLLBAR_ACCESS[] = "horizontalScrollBarAccess";
135 constexpr char NTC_HORIZONTAL_SCROLLBAR_ACCESS[] = "horizontalScrollBarAccess";
136 constexpr char WEB_ATTRIBUTE_VERTICAL_SCROLLBAR_ACCESS[] = "verticalScrollBarAccess";
137 constexpr char NTC_VERTICAL_SCROLLBAR_ACCESS[] = "verticalScrollBarAccess";
138 constexpr char WEB_ATTRIBUTE_BACKGROUND_COLOR[] = "backgroundColor";
139 constexpr char NTC_BACKGROUND_COLOR[] = "backgroundColor";
140 constexpr char WEB_ATTRIBUTE_MEDIA_PLAY_GESTURE_ACCESS[] = "mediaPlayGestureAccess";
141 constexpr char NTC_MEDIA_PLAY_GESTURE_ACCESS[] = "mediaPlayGestureAccess";
142 constexpr char WEB_ATTRIBUTE_BLOCK_NETWORK[] = "blockNetwork";
143 constexpr char NTC_BLOCK_NETWORK[] = "blockNetwork";
144 constexpr char WEB_ATTRIBUTE_MIXED_MODE[] = "mixedMode";
145 constexpr char NTC_MIXED_MODE[] = "mixedMode";
146 constexpr char WEB_ATTRIBUTE_ONLINE_IMAGE_ACCESS[] = "onlineImageAccess";
147 constexpr char NTC_ONLINE_IMAGE_ACCESS[] = "onlineImageAccess";
148 constexpr char WEB_ATTRIBUTE_GEOLOCATION_ACCESS[] = "geolocationAccess";
149 constexpr char NTC_GEOLOCATION_ACCESS[] = "geolocationAccess";
150 constexpr char WEB_ATTRIBUTE_DOM_STORAGE_ACCESS[] = "domStorageAccess";
151 constexpr char NTC_DOM_STORAGE_ACCESS[] = "domStorageAccess";
152 constexpr char WEB_CACHE_MODE[] = "cacheMode";
153 constexpr char NTC_CACHE_MODE[] = "cacheMode";
154 constexpr char WEB_IMAGE_ACCESS[] = "imageAccess";
155 constexpr char NTC_IMAGE_ACCESS[] = "imageAccess";
156
157 const char WEB_PARAM_NONE[] = "";
158 const char WEB_PARAM_AND[] = "#HWJS-&-#";
159 const char WEB_PARAM_VALUE[] = "value";
160 const char WEB_PARAM_EQUALS[] = "#HWJS-=-#";
161 const char WEB_PARAM_BEGIN[] = "#HWJS-?-#";
162 const char WEB_METHOD[] = "method";
163 const char WEB_EVENT[] = "event";
164 const char WEB_RESULT_FAIL[] = "fail";
165 constexpr char MIMETYPE[] = "text/html";
166 constexpr char ENCODING[] = "UTF-8";
167
168 constexpr int FONT_MIN_SIZE = 1;
169 constexpr int FONT_MAX_SIZE = 72;
170 constexpr int RESOURCESID_ONE = 1;
171 constexpr int RESOURCESID_TWO = 2;
172 constexpr int RESOURCESID_THREE = 3;
173
174 const std::string RESOURCE_VIDEO_CAPTURE = "TYPE_VIDEO_CAPTURE";
175 const std::string RESOURCE_AUDIO_CAPTURE = "TYPE_AUDIO_CAPTURE";
176 }
177
GetRequestHeader() const178 std::map<std::string, std::string> WebResourceRequsetImpl::GetRequestHeader() const
179 {
180 auto obj = WebObjectEventManager::GetInstance().GetResourceRequestObject();
181 if (!obj) {
182 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceRequsetImpl GetRequestHeader failed");
183 return std::map<std::string, std::string>();
184 }
185 return obj->GetRequestHeader(object_);
186 }
187
GetRequestUrl() const188 std::string WebResourceRequsetImpl::GetRequestUrl() const
189 {
190 auto obj = WebObjectEventManager::GetInstance().GetResourceRequestObject();
191 if (!obj) {
192 return std::string();
193 }
194 return obj->GetRequestUrl(object_);
195 }
196
GetMethod() const197 std::string WebResourceRequsetImpl::GetMethod() const
198 {
199 auto obj = WebObjectEventManager::GetInstance().GetResourceRequestObject();
200 if (!obj) {
201 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceRequsetImpl GetMethod failed");
202 return std::string();
203 }
204 return obj->GetMethod(object_);
205 }
206
IsRequestGesture() const207 bool WebResourceRequsetImpl::IsRequestGesture() const
208 {
209 auto obj = WebObjectEventManager::GetInstance().GetResourceRequestObject();
210 if (!obj) {
211 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceRequsetImpl IsRequestGesture failed");
212 return false;
213 }
214 return obj->IsRequestGesture(object_);
215 }
216
IsMainFrame() const217 bool WebResourceRequsetImpl::IsMainFrame() const
218 {
219 auto obj = WebObjectEventManager::GetInstance().GetResourceRequestObject();
220 if (!obj) {
221 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceRequsetImpl IsMainFrame failed");
222 return true;
223 }
224 return obj->IsMainFrame(object_);
225 }
226
IsRedirect() const227 bool WebResourceRequsetImpl::IsRedirect() const
228 {
229 auto obj = WebObjectEventManager::GetInstance().GetResourceRequestObject();
230 if (!obj) {
231 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceRequsetImpl IsRedirect failed");
232 return false;
233 }
234 return obj->IsRedirect(object_);
235 }
236
GetResponseHeader() const237 std::map<std::string, std::string> WebResourceResponseImpl::GetResponseHeader() const
238 {
239 auto obj = WebObjectEventManager::GetInstance().GetResourceResponseObject();
240 if (!obj) {
241 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceResponseImpl ResponseHeader failed");
242 return std::map<std::string, std::string>();
243 }
244 return obj->GetResponseHeader(object_);
245 }
246
GetResponseData() const247 std::string WebResourceResponseImpl::GetResponseData() const
248 {
249 auto obj = WebObjectEventManager::GetInstance().GetResourceResponseObject();
250 if (!obj) {
251 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceResponseImpl ResponseData failed");
252 return std::string();
253 }
254 return obj->GetResponseData(object_);
255 }
256
GetEncoding() const257 std::string WebResourceResponseImpl::GetEncoding() const
258 {
259 auto obj = WebObjectEventManager::GetInstance().GetResourceResponseObject();
260 if (!obj) {
261 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceResponseImpl encoding failed");
262 return std::string();
263 }
264 return obj->GetEncoding(object_);
265 }
266
GetMimeType() const267 std::string WebResourceResponseImpl::GetMimeType() const
268 {
269 auto obj = WebObjectEventManager::GetInstance().GetResourceResponseObject();
270 if (!obj) {
271 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceResponseImpl mimeType failed");
272 return std::string();
273 }
274 return obj->GetMimeType(object_);
275 }
276
GetReason() const277 std::string WebResourceResponseImpl::GetReason() const
278 {
279 auto obj = WebObjectEventManager::GetInstance().GetResourceResponseObject();
280 if (!obj) {
281 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceResponseImpl Reason failed");
282 return std::string();
283 }
284 return obj->GetReason(object_);
285 }
286
GetStatusCode() const287 int WebResourceResponseImpl::GetStatusCode() const
288 {
289 auto obj = WebObjectEventManager::GetInstance().GetResourceResponseObject();
290 if (!obj) {
291 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebResourceResponseImpl statusCode failed");
292 return 0;
293 }
294 return obj->GetStatusCode(object_);
295 }
296
GetErrorInfo() const297 std::string WebResourceErrorImpl::GetErrorInfo() const
298 {
299 auto obj = WebObjectEventManager::GetInstance().GetResourceErrorObject();
300 if (!obj) {
301 return std::string();
302 }
303 return obj->GetErrorInfo(object_);
304 }
305
GetErrorCode() const306 int WebResourceErrorImpl::GetErrorCode() const
307 {
308 auto obj = WebObjectEventManager::GetInstance().GetResourceErrorObject();
309 if (!obj) {
310 return 0;
311 }
312 return obj->GetErrorCode(object_);
313 }
314
GetX() const315 double WebOffsetImpl::GetX() const
316 {
317 auto obj = WebObjectEventManager::GetInstance().GetScrollObject();
318 if (!obj) {
319 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebOffsetImpl X failed");
320 return 0.0;
321 }
322 return obj->GetX(object_);
323 }
324
GetY() const325 double WebOffsetImpl::GetY() const
326 {
327 auto obj = WebObjectEventManager::GetInstance().GetScrollObject();
328 if (!obj) {
329 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebOffsetImpl Y failed");
330 return 0.0;
331 }
332 return obj->GetY(object_);
333 }
334
GetMessage() const335 std::string WebConsoleMessage::GetMessage() const
336 {
337 auto obj = WebObjectEventManager::GetInstance().GetConsoleMessageObject();
338 if (!obj) {
339 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebConsoleMessage Message failed");
340 return std::string();
341 }
342 return obj->GetMessage(object_);
343 }
344
GetMessageLevel() const345 int WebConsoleMessage::GetMessageLevel() const
346 {
347 auto obj = WebObjectEventManager::GetInstance().GetConsoleMessageObject();
348 if (!obj) {
349 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebConsoleMessage MessageLevel failed");
350 return 0;
351 }
352 return obj->GetMessageLevel(object_);
353 }
354
GetSourceId() const355 std::string WebConsoleMessage::GetSourceId() const
356 {
357 auto obj = WebObjectEventManager::GetInstance().GetConsoleMessageObject();
358 if (!obj) {
359 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebConsoleMessage GetSourceId failed");
360 return std::string();
361 }
362 return obj->GetSourceId(object_);
363 }
364
GetLineNumber() const365 int WebConsoleMessage::GetLineNumber() const
366 {
367 auto obj = WebObjectEventManager::GetInstance().GetConsoleMessageObject();
368 if (!obj) {
369 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebConsoleMessage GetLineNumber failed");
370 return 0;
371 }
372 return obj->GetLineNumber(object_);
373 }
374
GetNewScale() const375 float WebScaleChangeImpl::GetNewScale() const
376 {
377 auto obj = WebObjectEventManager::GetInstance().GetScaleChangeObject();
378 if (!obj) {
379 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebScaleChangeImpl newScale failed");
380 return 0.0f;
381 }
382 return obj->GetNewScale(object_);
383 }
384
GetOldScale() const385 float WebScaleChangeImpl::GetOldScale() const
386 {
387 auto obj = WebObjectEventManager::GetInstance().GetScaleChangeObject();
388 if (!obj) {
389 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebScaleChangeImpl oldScale failed");
390 return 0.0f;
391 }
392 return obj->GetOldScale(object_);
393 }
394
GetUrl() const395 std::string WebCommonDialogImpl::GetUrl() const
396 {
397 auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
398 if (!obj) {
399 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebCommonDialogImpl url failed");
400 return std::string();
401 }
402 return obj->GetUrl(object_);
403 }
404
GetMessage() const405 std::string WebCommonDialogImpl::GetMessage() const
406 {
407 auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
408 if (!obj) {
409 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebCommonDialogImpl message failed");
410 return std::string();
411 }
412 return obj->GetMessage(object_);
413 }
414
GetValue() const415 std::string WebCommonDialogImpl::GetValue() const
416 {
417 auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
418 if (!obj) {
419 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebCommonDialogImpl value failed");
420 return std::string();
421 }
422 return obj->GetValue(object_);
423 }
424
SetOrigin()425 void PermissionRequestImpl::SetOrigin()
426 {
427 auto obj = WebObjectEventManager::GetInstance().GetPermissionRequestObject();
428 if (!obj) {
429 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get PermissionRequestImpl origin failed");
430 return;
431 }
432 origin_ = obj->GetOrigin(object_);
433 }
434
SetResources()435 void PermissionRequestImpl::SetResources()
436 {
437 auto obj = WebObjectEventManager::GetInstance().GetPermissionRequestObject();
438 if (!obj) {
439 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get PermissionRequestImpl resources failed");
440 return;
441 }
442 int resourcesId = obj->GetResourcesId(object_);
443 if (resourcesId == RESOURCESID_ONE) {
444 resources_.push_back(RESOURCE_VIDEO_CAPTURE);
445 } else if (resourcesId == RESOURCESID_TWO) {
446 resources_.push_back(RESOURCE_AUDIO_CAPTURE);
447 } else if (resourcesId == RESOURCESID_THREE) {
448 resources_.push_back(RESOURCE_VIDEO_CAPTURE);
449 resources_.push_back(RESOURCE_AUDIO_CAPTURE);
450 } else {
451 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get error type");
452 }
453 }
454
GetOrigin() const455 std::string PermissionRequestImpl::GetOrigin() const
456 {
457 return origin_;
458 }
459
GetResources() const460 std::vector<std::string> PermissionRequestImpl::GetResources() const
461 {
462 return resources_;
463 }
464
Grant(std::vector<std::string> & resources) const465 void PermissionRequestImpl::Grant(std::vector<std::string>& resources) const
466 {
467 auto obj = WebObjectEventManager::GetInstance().GetPermissionRequestObject();
468 if (!obj) {
469 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager PermissionRequestObject grant failed");
470 return;
471 }
472 int resourcesId = 0;
473 for (auto res : resources) {
474 if (res == RESOURCE_VIDEO_CAPTURE) {
475 resourcesId |= RESOURCESID_ONE;
476 } else if (res == RESOURCE_AUDIO_CAPTURE) {
477 resourcesId |= RESOURCESID_TWO;
478 }
479 }
480 if (resourcesId != 0) {
481 obj->Grant(object_, resourcesId, index_);
482 }
483 }
484
Deny() const485 void PermissionRequestImpl::Deny() const
486 {
487 auto obj = WebObjectEventManager::GetInstance().GetPermissionRequestObject();
488 if (!obj) {
489 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager PermissionRequestObject Deny failed");
490 return;
491 }
492 obj->Deny(object_, index_);
493 }
494
GetHost() const495 std::string WebAuthRequestImpl::GetHost() const
496 {
497 auto obj = WebObjectEventManager::GetInstance().GetHttpAuthRequestObject();
498 if (!obj) {
499 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebAuthRequestImpl host failed");
500 return std::string();
501 }
502 return obj->GetHost(object_);
503 }
504
GetRealm() const505 std::string WebAuthRequestImpl::GetRealm() const
506 {
507 auto obj = WebObjectEventManager::GetInstance().GetHttpAuthRequestObject();
508 if (!obj) {
509 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebAuthRequestImpl realm failed");
510 return std::string();
511 }
512 return obj->GetRealm(object_);
513 }
514
GetUrl() const515 std::string WebRefreshAccessedHistoryImpl::GetUrl() const
516 {
517 auto obj = WebObjectEventManager::GetInstance().GetRefreshAccessedHistoryObject();
518 if (!obj) {
519 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get RefreshAccessedHistory Url failed");
520 return std::string();
521 }
522 return obj->GetUrl(object_);
523 }
524
GetIsRefreshed() const525 bool WebRefreshAccessedHistoryImpl::GetIsRefreshed() const
526 {
527 auto obj = WebObjectEventManager::GetInstance().GetRefreshAccessedHistoryObject();
528 if (!obj) {
529 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebRefreshAccessedHistoryImpl GetIsRefreshed failed");
530 return false;
531 }
532 return obj->GetIsRefreshed(object_);
533 }
534
GetHeights() const535 int WebFullScreenEnterImpl::GetHeights() const
536 {
537 auto obj = WebObjectEventManager::GetInstance().GetFullScreenEnterObject();
538 if (!obj) {
539 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager WebFullScreenEnterImpl GetHeights failed");
540 return 0;
541 }
542 return obj->GetHeights(object_);
543 }
GetWidths() const544 int WebFullScreenEnterImpl::GetWidths() const
545 {
546 auto obj = WebObjectEventManager::GetInstance().GetFullScreenEnterObject();
547 if (!obj) {
548 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager WebFullScreenEnterImpl GetWidths failed");
549 return 0;
550 }
551 return obj->GetWidths(object_);
552 }
553
ExitFullScreen()554 void FullScreenExitHandlerImpl::ExitFullScreen()
555 {
556 auto obj = WebObjectEventManager::GetInstance().GetFullScreenEnterObject();
557 if (!obj) {
558 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager FullScreenExitHandlerImpl ExitFullScreen failed");
559 return;
560 }
561 obj->ExitFullScreen(object_, index_);
562 }
563
GetUrl() const564 std::string WebDownloadResponseImpl::GetUrl() const
565 {
566 auto obj = WebObjectEventManager::GetInstance().GetDownloadResponseObject();
567 if (!obj) {
568 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebDownloadResponseImpl Url failed");
569 return std::string();
570 }
571 return obj->GetUrl(object_);
572 }
573
GetMimetype() const574 std::string WebDownloadResponseImpl::GetMimetype() const
575 {
576 auto obj = WebObjectEventManager::GetInstance().GetDownloadResponseObject();
577 if (!obj) {
578 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebDownloadResponseImpl mimetype failed");
579 return std::string();
580 }
581 return obj->GetMimetype(object_);
582 }
583
GetContentLength() const584 long WebDownloadResponseImpl::GetContentLength() const
585 {
586 auto obj = WebObjectEventManager::GetInstance().GetDownloadResponseObject();
587 if (!obj) {
588 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebDownloadResponseImpl contentLength failed");
589 return 0;
590 }
591 return obj->GetContentLength(object_);
592 }
593
GetUserAgent() const594 std::string WebDownloadResponseImpl::GetUserAgent() const
595 {
596 auto obj = WebObjectEventManager::GetInstance().GetDownloadResponseObject();
597 if (!obj) {
598 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebDownloadResponseImpl userAgent failed");
599 return std::string();
600 }
601 return obj->GetUserAgent(object_);
602 }
603
GetContentDisposition() const604 std::string WebDownloadResponseImpl::GetContentDisposition() const
605 {
606 auto obj = WebObjectEventManager::GetInstance().GetDownloadResponseObject();
607 if (!obj) {
608 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebDownloadResponseImpl GetContentDisposition failed");
609 return std::string();
610 }
611 return obj->GetContentDisposition(object_);
612 }
613
Confirm(const std::string & promptResult)614 void DialogResult::Confirm(const std::string& promptResult)
615 {
616 auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
617 if (!obj) {
618 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager DialogResult prompt Confirm failed");
619 return;
620 }
621 if (dialogEventType_ == DialogEventType::DIALOG_EVENT_PROMPT) {
622 obj->Confirm(object_, promptResult, index_);
623 }
624 }
625
Confirm()626 void DialogResult::Confirm()
627 {
628 auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
629 if (!obj) {
630 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager DialogResult Confirm failed");
631 return;
632 }
633 obj->Confirm(object_, index_);
634 }
635
Cancel()636 void DialogResult::Cancel()
637 {
638 auto obj = WebObjectEventManager::GetInstance().GetCommonDialogObject();
639 if (!obj) {
640 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager DialogResult Cancel failed");
641 return;
642 }
643 obj->Cancel(object_, index_);
644 }
645
Confirm(std::string & userName,std::string & pwd)646 bool WebAuthResult::Confirm(std::string& userName, std::string& pwd)
647 {
648 auto obj = WebObjectEventManager::GetInstance().GetHttpAuthRequestObject();
649 if (!obj) {
650 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager WebAuthResult confirm failed");
651 return false;
652 }
653 return obj->Confirm(object_, userName, pwd, index_);
654 }
655
IsHttpAuthInfoSaved()656 bool WebAuthResult::IsHttpAuthInfoSaved()
657 {
658 auto obj = WebObjectEventManager::GetInstance().GetHttpAuthRequestObject();
659 if (!obj) {
660 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager WebAuthResult isHttpAuthInfoSaved failed");
661 return false;
662 }
663 return obj->IsHttpAuthInfoSaved(object_, index_);
664 }
665
Cancel()666 void WebAuthResult::Cancel()
667 {
668 auto obj = WebObjectEventManager::GetInstance().GetHttpAuthRequestObject();
669 if (!obj) {
670 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager WebAuthResult cancel failed");
671 return;
672 }
673 obj->Cancel(object_, index_);
674 }
675
GetTitle() const676 std::string WebFileChooserImpl::GetTitle() const
677 {
678 auto obj = WebObjectEventManager::GetInstance().GetFileChooserObject();
679 if (!obj) {
680 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileChooserImpl title failed");
681 return std::string();
682 }
683 return obj->GetTitle(object_);
684 }
685
GetMode() const686 int WebFileChooserImpl::GetMode() const
687 {
688 auto obj = WebObjectEventManager::GetInstance().GetFileChooserObject();
689 if (!obj) {
690 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileChooserImpl title failed");
691 return 0;
692 }
693 return obj->GetMode(object_);
694 }
695
GetDefaultFileName() const696 std::string WebFileChooserImpl::GetDefaultFileName() const
697 {
698 return "DefaultFileName";
699 }
700
GetAcceptType() const701 std::vector<std::string> WebFileChooserImpl::GetAcceptType() const
702 {
703 auto obj = WebObjectEventManager::GetInstance().GetFileChooserObject();
704 if (!obj) {
705 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileChooserImpl acceptType failed");
706 return std::vector<std::string>();
707 }
708 return obj->GetAcceptType(object_);
709 }
710
IsCapture() const711 bool WebFileChooserImpl::IsCapture() const
712 {
713 auto obj = WebObjectEventManager::GetInstance().GetFileChooserObject();
714 if (!obj) {
715 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileChooserImpl title failed");
716 return false;
717 }
718 return obj->IsCapture(object_);
719 }
720
HandleFileList(std::vector<std::string> & fileList)721 void WebFileSelectorResult::HandleFileList(std::vector<std::string>& fileList)
722 {
723 auto obj = WebObjectEventManager::GetInstance().GetFileChooserObject();
724 if (!obj) {
725 TAG_LOGE(
726 AceLogTag::ACE_WEB, "WebObjectEventManager get WebFileSelectorResult FileSelectorResultCallback failed");
727 return;
728 }
729 obj->HandleFileList(object_, fileList, index_);
730 }
731
GetOrigin() const732 std::string WebGeolocationImpl::GetOrigin() const
733 {
734 auto obj = WebObjectEventManager::GetInstance().GetGeolocationObject();
735 if (!obj) {
736 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get WebGeolocationImpl FileSelectorResultCallback failed");
737 return nullptr;
738 }
739 return obj->GetOrigin(object_);
740 }
741
Invoke(const std::string & origin,const bool & allow,const bool & retain)742 void Geolocation::Invoke(const std::string& origin, const bool& allow, const bool& retain)
743 {
744 auto obj = WebObjectEventManager::GetInstance().GetGeolocationObject();
745 if (!obj) {
746 TAG_LOGE(AceLogTag::ACE_WEB, "WebObjectEventManager get Geolocation FileSelectorResultCallback failed");
747 return;
748 }
749 obj->Invoke(index_, origin, allow, retain);
750 }
751
~WebDelegateCross()752 WebDelegateCross::~WebDelegateCross()
753 {
754 ReleasePlatformResource();
755 }
756
CreatePlatformResource(const Size & size,const Offset & position,const WeakPtr<NG::PipelineContext> & context)757 void WebDelegateCross::CreatePlatformResource(
758 const Size& size, const Offset& position, const WeakPtr<NG::PipelineContext>& context)
759 {
760 ReleasePlatformResource();
761 context_ = context;
762 CreatePluginResource(size, position, context);
763 }
764
ReleasePlatformResource()765 void WebDelegateCross::ReleasePlatformResource()
766 {
767 Release();
768 }
769
CreatePluginResource(const Size & size,const Offset & position,const WeakPtr<NG::PipelineContext> & context)770 void WebDelegateCross::CreatePluginResource(
771 const Size& size, const Offset& position, const WeakPtr<NG::PipelineContext>& context)
772 {
773 state_ = State::CREATING;
774 auto pipelineContext = context.Upgrade();
775 if (!pipelineContext) {
776 state_ = State::CREATEFAILED;
777 return;
778 }
779 context_ = context;
780 auto platformTaskExecutor =
781 SingleTaskExecutor::Make(pipelineContext->GetTaskExecutor(), TaskExecutor::TaskType::PLATFORM);
782 auto resRegister = pipelineContext->GetPlatformResRegister();
783 auto weakRes = AceType::WeakClaim(AceType::RawPtr(resRegister));
784 platformTaskExecutor.PostSyncTask([weakWeb = AceType::WeakClaim(this), weakRes, size, position] {
785 auto webDelegate = weakWeb.Upgrade();
786 if (webDelegate == nullptr) {
787 return;
788 }
789 auto webPattern = webDelegate->webPattern_.Upgrade();
790 if (!webPattern) {
791 webDelegate->OnError(WEB_ERROR_CODE_CREATEFAIL, WEB_ERROR_MSG_CREATEFAIL);
792 return;
793 }
794 auto resRegister = weakRes.Upgrade();
795 if (!resRegister) {
796 webDelegate->OnError(WEB_ERROR_CODE_CREATEFAIL, WEB_ERROR_MSG_CREATEFAIL);
797 return;
798 }
799 auto context = webDelegate->context_.Upgrade();
800 if (!context) {
801 return;
802 }
803
804 std::string pageUrl;
805 int32_t pageId;
806 OHOS::Ace::Framework::DelegateClient::GetInstance().GetWebPageUrl(pageUrl, pageId);
807
808 std::stringstream paramStream;
809 paramStream << NTC_PARAM_WEB << WEB_PARAM_EQUALS << webDelegate->id_ << WEB_PARAM_AND << NTC_PARAM_WIDTH
810 << WEB_PARAM_EQUALS << size.Width() * context->GetViewScale() << WEB_PARAM_AND << NTC_PARAM_HEIGHT
811 << WEB_PARAM_EQUALS << size.Height() * context->GetViewScale() << WEB_PARAM_AND << NTC_PARAM_LEFT
812 << WEB_PARAM_EQUALS << position.GetX() * context->GetViewScale() << WEB_PARAM_AND << NTC_PARAM_TOP
813 << WEB_PARAM_EQUALS << position.GetY() * context->GetViewScale() << WEB_PARAM_AND << NTC_PARAM_SRC
814 << WEB_PARAM_EQUALS << webPattern->GetWebSrc().value_or("") << WEB_PARAM_AND << NTC_PARAM_PAGE_URL
815 << WEB_PARAM_EQUALS << pageUrl << WEB_PARAM_AND << NTC_PARAM_RICH_TEXT_INIT
816 << WEB_PARAM_EQUALS << webPattern->GetRichTextInit() << WEB_PARAM_AND << NTC_INCOGNITO_MODE
817 << WEB_PARAM_EQUALS << webPattern->GetIncognitoMode();
818
819 std::string param = paramStream.str();
820 webDelegate->id_ = resRegister->CreateResource(WEB_CREATE, param);
821
822 if (webDelegate->id_ == INVALID_ID) {
823 webDelegate->OnError(WEB_ERROR_CODE_CREATEFAIL, WEB_ERROR_MSG_CREATEFAIL);
824 return;
825 }
826 webDelegate->state_ = State::CREATED;
827 webDelegate->hash_ = webDelegate->MakeResourceHash();
828 webDelegate->RegisterWebEvent();
829 webDelegate->RegisterWebObjectEvent();
830 }, "ArkUIWebCreatePluginResource");
831 }
832
GetWebId()833 int WebDelegateCross::GetWebId()
834 {
835 return id_;
836 }
837
RegisterWebEvent()838 void WebDelegateCross::RegisterWebEvent()
839 {
840 auto context = DynamicCast<NG::PipelineContext>(context_.Upgrade());
841 CHECK_NULL_VOID(context);
842 auto resRegister = context->GetPlatformResRegister();
843 if (resRegister == nullptr) {
844 return;
845 }
846 resRegister->RegisterEvent(MakeEventHash(WEB_EVENT_PAGESTART), [weak = WeakClaim(this)](const std::string& param) {
847 auto delegate = weak.Upgrade();
848 if (delegate) {
849 delegate->OnPageStarted(param);
850 delegate->RunJsProxyCallback();
851 }
852 });
853 resRegister->RegisterEvent(MakeEventHash(WEB_EVENT_PAGEFINISH), [weak = WeakClaim(this)](const std::string& param) {
854 auto delegate = weak.Upgrade();
855 if (delegate) {
856 delegate->OnPageFinished(param);
857 }
858 });
859 resRegister->RegisterEvent(
860 MakeEventHash(WEB_EVENT_PAGECHANGED), [weak = WeakClaim(this)](const std::string& param) {
861 auto delegate = weak.Upgrade();
862 if (delegate) {
863 delegate->OnProgressChanged(param);
864 }
865 });
866 resRegister->RegisterEvent(MakeEventHash(WEB_EVENT_RECVTITLE), [weak = WeakClaim(this)](const std::string& param) {
867 auto delegate = weak.Upgrade();
868 if (delegate) {
869 delegate->OnReceivedTitle(param);
870 }
871 });
872 resRegister->RegisterEvent(
873 MakeEventHash(WEB_EVENT_ONPAGEVISIBLE), [weak = WeakClaim(this)](const std::string& param) {
874 auto delegate = weak.Upgrade();
875 if (delegate) {
876 delegate->OnPageVisible(param);
877 }
878 });
879 resRegister->RegisterEvent(
880 MakeEventHash(WEB_EVENT_GEOHIDEPERMISSION), [weak = WeakClaim(this)](const std::string& param) {
881 auto delegate = weak.Upgrade();
882 if (delegate) {
883 delegate->OnGeolocationPermissionsHidePrompt();
884 }
885 });
886 }
887
RegisterWebObjectEvent()888 void WebDelegateCross::RegisterWebObjectEvent()
889 {
890 WebObjectEventManager::GetInstance().RegisterObjectEvent(MakeEventHash(WEB_EVENT_ERRORRECEIVE),
891 [weak = WeakClaim(this)](const std::string& param, void* object) {
892 auto delegate = weak.Upgrade();
893 if (delegate) {
894 delegate->OnErrorReceive(object);
895 }
896 });
897 WebObjectEventManager::GetInstance().RegisterObjectEvent(
898 MakeEventHash(WEB_EVENT_SCROLL), [weak = WeakClaim(this)](const std::string& param, void* object) {
899 auto delegate = weak.Upgrade();
900 if (delegate) {
901 delegate->OnScroll(object);
902 }
903 });
904 WebObjectEventManager::GetInstance().RegisterObjectEvent(
905 MakeEventHash(WEB_EVENT_SCALECHANGE), [weak = WeakClaim(this)](const std::string& param, void* object) {
906 auto delegate = weak.Upgrade();
907 if (delegate) {
908 delegate->OnScaleChange(object);
909 }
910 });
911 WebObjectEventManager::GetInstance().RegisterObjectEvent(
912 MakeEventHash(WEB_EVENT_ONHTTPERRORRECEIVE), [weak = WeakClaim(this)](const std::string& param, void* object) {
913 auto delegate = weak.Upgrade();
914 if (delegate) {
915 delegate->OnHttpErrorReceive(object);
916 }
917 });
918 WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(MakeEventHash(WEB_EVENT_CONSOLEMESSAGE),
919 [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
920 auto delegate = weak.Upgrade();
921 if (delegate) {
922 return delegate->OnConsoleMessage(object);
923 }
924 return false;
925 });
926 WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(MakeEventHash(WEB_EVENT_LOADINTERCEPT),
927 [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
928 auto delegate = weak.Upgrade();
929 if (delegate) {
930 return delegate->OnLoadIntercept(object);
931 }
932 return false;
933 });
934 WebObjectEventManager::GetInstance().RegisterObjectEventWithResponseReturn(
935 MakeEventHash(WEB_EVENT_ONINTERCEPTREQUEST),
936 [weak = WeakClaim(this)](const std::string& param, void* object) -> RefPtr<WebResponse> {
937 auto delegate = weak.Upgrade();
938 if (delegate) {
939 return delegate->OnInterceptRequest(object);
940 }
941 return nullptr;
942 });
943 WebObjectEventManager::GetInstance().RegisterObjectEvent(
944 MakeEventHash(WEB_EVENT_REFRESH_HISTORY),
945 [weak = WeakClaim(this)](const std::string& param, void* object) {
946 auto delegate = weak.Upgrade();
947 if (delegate) {
948 delegate->OnRefreshAccessedHistory(object);
949 }
950 });
951 WebObjectEventManager::GetInstance().RegisterObjectEvent(
952 MakeEventHash(WEB_EVENT_FULLSCREEN_ENTER), [weak = WeakClaim(this)](const std::string& param, void* object) {
953 auto delegate = weak.Upgrade();
954 if (delegate) {
955 delegate->OnFullScreenEnter(object);
956 }
957 });
958 WebObjectEventManager::GetInstance().RegisterObjectEvent(
959 MakeEventHash(WEB_EVENT_FULLSCREEN_EXIT),
960 [weak = WeakClaim(this)](const std::string& param, void* object) {
961 auto delegate = weak.Upgrade();
962 if (delegate) {
963 delegate->OnFullScreenExit(object);
964 }
965 });
966 WebObjectEventManager::GetInstance().RegisterObjectEvent(
967 MakeEventHash(WEB_EVENT_DOWNLOADSTART), [weak = WeakClaim(this)](const std::string& param, void* object) {
968 auto delegate = weak.Upgrade();
969 if (delegate) {
970 delegate->OnDownloadStart(object);
971 }
972 });
973 WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(MakeEventHash(WEB_EVENT_ONSHOWFILECHOOSER),
974 [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
975 auto delegate = weak.Upgrade();
976 if (delegate) {
977 return delegate->OnShowFileChooser(object);
978 }
979 return false;
980 });
981 WebObjectEventManager::GetInstance().RegisterObjectEvent(
982 MakeEventHash(WEB_EVENT_GEOPERMISSION), [weak = WeakClaim(this)](const std::string& param, void* object) {
983 auto delegate = weak.Upgrade();
984 if (delegate) {
985 delegate->OnGeolocationPermissionsShowPrompt(object);
986 }
987 });
988 WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(
989 MakeEventHash(WEB_EVENT_ONALERT), [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
990 auto delegate = weak.Upgrade();
991 if (delegate) {
992 return delegate->OnCommonDialog(object, DialogEventType::DIALOG_EVENT_ALERT);
993 }
994 return false;
995 });
996 WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(
997 MakeEventHash(WEB_EVENT_ONCONFIRM), [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
998 auto delegate = weak.Upgrade();
999 if (delegate) {
1000 return delegate->OnCommonDialog(object, DialogEventType::DIALOG_EVENT_CONFIRM);
1001 }
1002 return false;
1003 });
1004 WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(
1005 MakeEventHash(WEB_EVENT_ONPROMPT), [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
1006 auto delegate = weak.Upgrade();
1007 if (delegate) {
1008 return delegate->OnCommonDialog(object, DialogEventType::DIALOG_EVENT_PROMPT);
1009 }
1010 return false;
1011 });
1012 WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(MakeEventHash(WEB_EVENT_ONPERMISSIONREQUEST),
1013 [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
1014 auto delegate = weak.Upgrade();
1015 if (delegate) {
1016 return delegate->OnPermissionRequest(object);
1017 }
1018 return false;
1019 });
1020 WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(MakeEventHash(WEB_EVENT_ON_BEFORE_UNLOAD),
1021 [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
1022 auto delegate = weak.Upgrade();
1023 if (delegate) {
1024 return delegate->OnCommonDialog(object, DialogEventType::DIALOG_EVENT_BEFORE_UNLOAD);
1025 }
1026 return false;
1027 });
1028 WebObjectEventManager::GetInstance().RegisterObjectEventWithBoolReturn(MakeEventHash(WEB_EVENT_ONHTTPAUTHREQUEST),
1029 [weak = WeakClaim(this)](const std::string& param, void* object) -> bool {
1030 auto delegate = weak.Upgrade();
1031 if (delegate) {
1032 return delegate->OnHttpAuthRequest(object);
1033 }
1034 return false;
1035 });
1036 }
1037
HandleTouchDown(const int32_t & id,const double & x,const double & y,bool from_overlay)1038 void WebDelegateCross::HandleTouchDown(
1039 const int32_t& id, const double& x, const double& y, bool from_overlay)
1040 {
1041 hash_ = MakeResourceHash();
1042 touchDownMethod_ = MakeMethodHash(WEB_METHOD_TOUCH_DOWN);
1043 CallResRegisterMethod(touchDownMethod_, "", nullptr);
1044 }
1045
HandleTouchUp(const int32_t & id,const double & x,const double & y,bool from_overlay)1046 void WebDelegateCross::HandleTouchUp(
1047 const int32_t& id, const double& x, const double& y, bool from_overlay)
1048 {
1049 hash_ = MakeResourceHash();
1050 touchUpMethod_ = MakeMethodHash(WEB_METHOD_TOUCH_UP);
1051 CallResRegisterMethod(touchUpMethod_, "", nullptr);
1052 }
1053
HandleTouchMove(const int32_t & id,const double & x,const double & y,bool from_overlay)1054 void WebDelegateCross::HandleTouchMove(
1055 const int32_t& id, const double& x, const double& y, bool from_overlay)
1056 {
1057 hash_ = MakeResourceHash();
1058 touchMoveMethod_ = MakeMethodHash(WEB_METHOD_TOUCH_MOVE);
1059 CallResRegisterMethod(touchMoveMethod_, "", nullptr);
1060 }
1061
HandleTouchCancel()1062 void WebDelegateCross::HandleTouchCancel()
1063 {
1064 hash_ = MakeResourceHash();
1065 touchCancelMethod_ = MakeMethodHash(WEB_METHOD_TOUCH_CANCEL);
1066 CallResRegisterMethod(touchCancelMethod_, "", nullptr);
1067 }
1068
HandleAxisEvent(const double & x,const double & y,const double & deltaX,const double & deltaY)1069 void WebDelegateCross::HandleAxisEvent(const double& x, const double& y, const double& deltaX, const double& deltaY)
1070 {
1071 // cross platform is not support now;
1072 }
1073
OnKeyEvent(int32_t keyCode,int32_t keyAction)1074 bool WebDelegateCross::OnKeyEvent(int32_t keyCode, int32_t keyAction)
1075 {
1076 return true;
1077 }
1078
OnMouseEvent(int32_t x,int32_t y,const MouseButton button,const MouseAction action,int count)1079 void WebDelegateCross::OnMouseEvent(
1080 int32_t x, int32_t y, const MouseButton button, const MouseAction action, int count)
1081 {}
1082
OnFocus()1083 void WebDelegateCross::OnFocus()
1084 {}
1085
OnBlur()1086 void WebDelegateCross::OnBlur()
1087 {}
1088
UpdateLocale()1089 void WebDelegateCross::UpdateLocale()
1090 {}
1091
OnInactive()1092 void WebDelegateCross::OnInactive()
1093 {}
1094
OnActive()1095 void WebDelegateCross::OnActive()
1096 {}
1097
ShowWebView()1098 void WebDelegateCross::ShowWebView()
1099 {}
1100
HideWebView()1101 void WebDelegateCross::HideWebView()
1102 {}
1103
RecordWebEvent(Recorder::EventType eventType,const std::string & param) const1104 void WebDelegateCross::RecordWebEvent(Recorder::EventType eventType, const std::string& param) const
1105 {
1106 if (!Recorder::EventRecorder::Get().IsComponentRecordEnable()) {
1107 return;
1108 }
1109 auto pattern = webPattern_.Upgrade();
1110 CHECK_NULL_VOID(pattern);
1111 auto host = pattern->GetHost();
1112 CHECK_NULL_VOID(host);
1113 Recorder::EventParamsBuilder builder;
1114 builder.SetId(host->GetInspectorIdValue(""))
1115 .SetType(host->GetHostTag())
1116 .SetEventType(eventType)
1117 .SetText(param)
1118 .SetHost(host)
1119 .SetDescription(host->GetAutoEventParamValue(""));
1120 Recorder::EventRecorder::Get().OnEvent(std::move(builder));
1121 }
1122
OnPageStarted(const std::string & param)1123 void WebDelegateCross::OnPageStarted(const std::string& param)
1124 {
1125 ContainerScope scope(instanceId_);
1126 auto context = context_.Upgrade();
1127 CHECK_NULL_VOID(context);
1128 context->GetTaskExecutor()->PostTask(
1129 [weak = WeakClaim(this), param]() {
1130 auto delegate = weak.Upgrade();
1131 CHECK_NULL_VOID(delegate);
1132 delegate->RecordWebEvent(Recorder::EventType::WEB_PAGE_BEGIN, param);
1133 if (Container::IsCurrentUseNewPipeline()) {
1134 auto webPattern = delegate->webPattern_.Upgrade();
1135 CHECK_NULL_VOID(webPattern);
1136 auto webEventHub = webPattern->GetWebEventHub();
1137 CHECK_NULL_VOID(webEventHub);
1138 auto propOnPageStarted = webEventHub->GetOnPageStartedEvent();
1139 CHECK_NULL_VOID(propOnPageStarted);
1140 auto eventParam = std::make_shared<LoadWebPageStartEvent>(param);
1141 propOnPageStarted(eventParam);
1142 return;
1143 }
1144 },
1145 TaskExecutor::TaskType::JS, "ArkUIWebPageStartEvent");
1146 }
1147
OnPageFinished(const std::string & param)1148 void WebDelegateCross::OnPageFinished(const std::string& param)
1149 {
1150 ContainerScope scope(instanceId_);
1151 auto context = context_.Upgrade();
1152 CHECK_NULL_VOID(context);
1153 context->GetTaskExecutor()->PostTask(
1154 [weak = WeakClaim(this), param]() {
1155 auto delegate = weak.Upgrade();
1156 CHECK_NULL_VOID(delegate);
1157 delegate->RecordWebEvent(Recorder::EventType::WEB_PAGE_END, param);
1158 if (Container::IsCurrentUseNewPipeline()) {
1159 auto webPattern = delegate->webPattern_.Upgrade();
1160 CHECK_NULL_VOID(webPattern);
1161 auto webEventHub = webPattern->GetWebEventHub();
1162 CHECK_NULL_VOID(webEventHub);
1163 auto propOnPageFinished = webEventHub->GetOnPageFinishedEvent();
1164 CHECK_NULL_VOID(propOnPageFinished);
1165 auto eventParam = std::make_shared<LoadWebPageFinishEvent>(param);
1166 propOnPageFinished(eventParam);
1167 return;
1168 }
1169 },
1170 TaskExecutor::TaskType::JS, "ArkUIWebPageFinishEvent");
1171 }
1172
OnPageError(const std::string & param)1173 void WebDelegateCross::OnPageError(const std::string& param)
1174 {}
1175
OnProgressChanged(const std::string & param)1176 void WebDelegateCross::OnProgressChanged(const std::string& param)
1177 {
1178 ContainerScope scope(instanceId_);
1179 auto context = context_.Upgrade();
1180 CHECK_NULL_VOID(context);
1181 context->GetTaskExecutor()->PostTask(
1182 [weak = WeakClaim(this), param]() {
1183 auto delegate = weak.Upgrade();
1184 CHECK_NULL_VOID(delegate);
1185 if (Container::IsCurrentUseNewPipeline()) {
1186 auto webPattern = delegate->webPattern_.Upgrade();
1187 CHECK_NULL_VOID(webPattern);
1188 auto webEventHub = webPattern->GetWebEventHub();
1189 CHECK_NULL_VOID(webEventHub);
1190 auto propOnProgressChange = webEventHub->GetOnProgressChangeEvent();
1191 CHECK_NULL_VOID(propOnProgressChange);
1192 auto eventParam = std::make_shared<LoadWebProgressChangeEvent>(atoi(param.c_str()));
1193 propOnProgressChange(eventParam);
1194 return;
1195 }
1196 },
1197 TaskExecutor::TaskType::JS, "ArkUIWebProgressChangeEvent");
1198 }
1199
OnReceivedTitle(const std::string & param)1200 void WebDelegateCross::OnReceivedTitle(const std::string& param)
1201 {
1202 ContainerScope scope(instanceId_);
1203 auto context = context_.Upgrade();
1204 CHECK_NULL_VOID(context);
1205 context->GetTaskExecutor()->PostTask(
1206 [weak = WeakClaim(this), param]() {
1207 auto delegate = weak.Upgrade();
1208 CHECK_NULL_VOID(delegate);
1209 if (Container::IsCurrentUseNewPipeline()) {
1210 auto webPattern = delegate->webPattern_.Upgrade();
1211 CHECK_NULL_VOID(webPattern);
1212 auto webEventHub = webPattern->GetWebEventHub();
1213 CHECK_NULL_VOID(webEventHub);
1214 auto propOnTitleReceive = webEventHub->GetOnTitleReceiveEvent();
1215 CHECK_NULL_VOID(propOnTitleReceive);
1216 auto eventParam = std::make_shared<LoadWebTitleReceiveEvent>(param);
1217 propOnTitleReceive(eventParam);
1218 return;
1219 }
1220 },
1221 TaskExecutor::TaskType::JS, "ArkUIWebTitleReceiveEvent");
1222 }
1223
OnErrorReceive(void * object)1224 void WebDelegateCross::OnErrorReceive(void* object)
1225 {
1226 ContainerScope scope(instanceId_);
1227 CHECK_NULL_VOID(object);
1228 auto context = context_.Upgrade();
1229 CHECK_NULL_VOID(context);
1230 auto webResourceRequest = AceType::MakeRefPtr<WebResourceRequsetImpl>(object);
1231 CHECK_NULL_VOID(webResourceRequest);
1232 auto webResourceError = AceType::MakeRefPtr<WebResourceErrorImpl>(object);
1233 CHECK_NULL_VOID(webResourceError);
1234 auto requestHeader = webResourceRequest->GetRequestHeader();
1235 auto method = webResourceRequest->GetMethod();
1236 auto url = webResourceRequest->GetRequestUrl();
1237 auto hasGesture = webResourceRequest->IsRequestGesture();
1238 auto isMainFrame = webResourceRequest->IsMainFrame();
1239 auto isRedirect = webResourceRequest->IsRedirect();
1240 auto request = AceType::MakeRefPtr<WebRequest>(requestHeader, method, url, hasGesture, isMainFrame, isRedirect);
1241 auto errorInfo = webResourceError->GetErrorInfo();
1242 auto errorCode = webResourceError->GetErrorCode();
1243 auto error = AceType::MakeRefPtr<WebError>(errorInfo, errorCode);
1244 context->GetTaskExecutor()->PostTask(
1245 [weak = WeakClaim(this), request, error]() {
1246 auto delegate = weak.Upgrade();
1247 CHECK_NULL_VOID(delegate);
1248 if (Container::IsCurrentUseNewPipeline()) {
1249 auto webPattern = delegate->webPattern_.Upgrade();
1250 CHECK_NULL_VOID(webPattern);
1251 auto webEventHub = webPattern->GetWebEventHub();
1252 CHECK_NULL_VOID(webEventHub);
1253 auto propOnErrorReceive = webEventHub->GetOnErrorReceiveEvent();
1254 CHECK_NULL_VOID(propOnErrorReceive);
1255 auto eventParam = std::make_shared<ReceivedErrorEvent>(request, error);
1256 propOnErrorReceive(eventParam);
1257 return;
1258 }
1259 },
1260 TaskExecutor::TaskType::JS, "ArkUIWebReceivedErrorEvent");
1261 }
1262
OnScroll(void * object)1263 void WebDelegateCross::OnScroll(void* object)
1264 {
1265 ContainerScope scope(instanceId_);
1266 CHECK_NULL_VOID(object);
1267 auto context = context_.Upgrade();
1268 CHECK_NULL_VOID(context);
1269 auto webScrollOffset = AceType::MakeRefPtr<WebOffsetImpl>(object);
1270 CHECK_NULL_VOID(webScrollOffset);
1271 auto offsetX = webScrollOffset->GetX();
1272 auto offsetY = webScrollOffset->GetY();
1273 context->GetTaskExecutor()->PostTask(
1274 [weak = WeakClaim(this), offsetX, offsetY]() {
1275 auto delegate = weak.Upgrade();
1276 CHECK_NULL_VOID(delegate);
1277 if (Container::IsCurrentUseNewPipeline()) {
1278 auto webPattern = delegate->webPattern_.Upgrade();
1279 CHECK_NULL_VOID(webPattern);
1280 auto webEventHub = webPattern->GetWebEventHub();
1281 CHECK_NULL_VOID(webEventHub);
1282 auto propOnScroll = webEventHub->GetOnScrollEvent();
1283 CHECK_NULL_VOID(propOnScroll);
1284 auto eventParam = std::make_shared<WebOnScrollEvent>(offsetX, offsetY);
1285 propOnScroll(eventParam);
1286 return;
1287 }
1288 },
1289 TaskExecutor::TaskType::JS, "ArkUIWebScrollEvent");
1290 }
1291
OnScaleChange(void * object)1292 void WebDelegateCross::OnScaleChange(void* object)
1293 {
1294 ContainerScope scope(instanceId_);
1295 CHECK_NULL_VOID(object);
1296 auto context = context_.Upgrade();
1297 CHECK_NULL_VOID(context);
1298 auto webScaleChange = AceType::MakeRefPtr<WebScaleChangeImpl>(object);
1299 CHECK_NULL_VOID(webScaleChange);
1300 auto newScale = webScaleChange->GetNewScale();
1301 auto oldScale = webScaleChange->GetOldScale();
1302 context->GetTaskExecutor()->PostTask(
1303 [weak = WeakClaim(this), newScale, oldScale]() {
1304 auto delegate = weak.Upgrade();
1305 CHECK_NULL_VOID(delegate);
1306 if (Container::IsCurrentUseNewPipeline()) {
1307 auto webPattern = delegate->webPattern_.Upgrade();
1308 CHECK_NULL_VOID(webPattern);
1309 auto webEventHub = webPattern->GetWebEventHub();
1310 CHECK_NULL_VOID(webEventHub);
1311 auto propOnScaleChange = webEventHub->GetOnScaleChangeEvent();
1312 CHECK_NULL_VOID(propOnScaleChange);
1313 auto eventParam = std::make_shared<ScaleChangeEvent>(oldScale, newScale);
1314 propOnScaleChange(eventParam);
1315 return;
1316 }
1317 },
1318 TaskExecutor::TaskType::JS, "ArkUIWebScaleChangeEvent");
1319 }
1320
OnHttpErrorReceive(void * object)1321 void WebDelegateCross::OnHttpErrorReceive(void* object)
1322 {
1323 ContainerScope scope(instanceId_);
1324 CHECK_NULL_VOID(object);
1325 auto context = context_.Upgrade();
1326 CHECK_NULL_VOID(context);
1327 auto webResourceRequest = AceType::MakeRefPtr<WebResourceRequsetImpl>(object);
1328 CHECK_NULL_VOID(webResourceRequest);
1329 auto webResourceResponse = AceType::MakeRefPtr<WebResourceResponseImpl>(object);
1330 CHECK_NULL_VOID(webResourceResponse);
1331 auto requestHeader = webResourceRequest->GetRequestHeader();
1332 auto method = webResourceRequest->GetMethod();
1333 auto url = webResourceRequest->GetRequestUrl();
1334 auto hasGesture = webResourceRequest->IsRequestGesture();
1335 auto isMainFrame = webResourceRequest->IsMainFrame();
1336 auto isRedirect = webResourceRequest->IsRedirect();
1337 auto request = AceType::MakeRefPtr<WebRequest>(requestHeader, method, url, hasGesture, isMainFrame, isRedirect);
1338 auto responseHeader = webResourceResponse->GetResponseHeader();
1339 auto responseDate = webResourceResponse->GetResponseData();
1340 auto encoding = webResourceResponse->GetEncoding();
1341 auto mimeType = webResourceResponse->GetMimeType();
1342 auto reason = webResourceResponse->GetReason();
1343 auto statusCode = webResourceResponse->GetStatusCode();
1344 auto response =
1345 AceType::MakeRefPtr<WebResponse>(responseHeader, responseDate, encoding, mimeType, reason, statusCode);
1346
1347 context->GetTaskExecutor()->PostTask(
1348 [weak = WeakClaim(this), request, response]() {
1349 auto delegate = weak.Upgrade();
1350 CHECK_NULL_VOID(delegate);
1351 if (Container::IsCurrentUseNewPipeline()) {
1352 auto webPattern = delegate->webPattern_.Upgrade();
1353 CHECK_NULL_VOID(webPattern);
1354 auto webEventHub = webPattern->GetWebEventHub();
1355 CHECK_NULL_VOID(webEventHub);
1356 auto propOnHttpErrorReceive = webEventHub->GetOnHttpErrorReceiveEvent();
1357 CHECK_NULL_VOID(propOnHttpErrorReceive);
1358 auto eventParam = std::make_shared<ReceivedHttpErrorEvent>(request, response);
1359 propOnHttpErrorReceive(eventParam);
1360 return;
1361 }
1362 },
1363 TaskExecutor::TaskType::JS, "ArkUIWebHttpErrorReceiveEvent");
1364 }
1365
OnConsoleMessage(void * object)1366 bool WebDelegateCross::OnConsoleMessage(void* object)
1367 {
1368 ContainerScope scope(instanceId_);
1369 CHECK_NULL_RETURN(object, false);
1370 auto context = context_.Upgrade();
1371 CHECK_NULL_RETURN(context, false);
1372 bool result = false;
1373 auto webConsoleMessage = AceType::MakeRefPtr<WebConsoleMessage>(object);
1374 CHECK_NULL_RETURN(webConsoleMessage, false);
1375 auto message = webConsoleMessage->GetMessage();
1376 auto sourceId = webConsoleMessage->GetSourceId();
1377 auto lineNumber = webConsoleMessage->GetLineNumber();
1378 auto messageLevel = webConsoleMessage->GetMessageLevel();
1379 auto consoleMessageParam = AceType::MakeRefPtr<WebConsoleMessageParam>(message, sourceId, lineNumber, messageLevel);
1380
1381 context->GetTaskExecutor()->PostSyncTask(
1382 [weak = WeakClaim(this), consoleMessageParam, &result]() {
1383 auto delegate = weak.Upgrade();
1384 CHECK_NULL_VOID(delegate);
1385 if (Container::IsCurrentUseNewPipeline()) {
1386 auto webPattern = delegate->webPattern_.Upgrade();
1387 CHECK_NULL_VOID(webPattern);
1388 auto webEventHub = webPattern->GetWebEventHub();
1389 CHECK_NULL_VOID(webEventHub);
1390 auto propOnConsole = webEventHub->GetOnConsoleEvent();
1391 CHECK_NULL_VOID(propOnConsole);
1392 auto eventParam = std::make_shared<LoadWebConsoleLogEvent>(consoleMessageParam);
1393 result = propOnConsole(eventParam);
1394 return;
1395 }
1396 },
1397 TaskExecutor::TaskType::JS, "ArkUIWebConsoleMessageEvent");
1398 return result;
1399 }
1400
OnLoadIntercept(void * object)1401 bool WebDelegateCross::OnLoadIntercept(void* object)
1402 {
1403 ContainerScope scope(instanceId_);
1404 CHECK_NULL_RETURN(object, false);
1405 auto context = context_.Upgrade();
1406 CHECK_NULL_RETURN(context, false);
1407 bool result = false;
1408 auto webResourceRequest = AceType::MakeRefPtr<WebResourceRequsetImpl>(object);
1409 CHECK_NULL_RETURN(webResourceRequest, false);
1410 auto requestHeader = webResourceRequest->GetRequestHeader();
1411 auto method = webResourceRequest->GetMethod();
1412 auto url = webResourceRequest->GetRequestUrl();
1413 auto hasGesture = webResourceRequest->IsRequestGesture();
1414 auto isMainFrame = webResourceRequest->IsMainFrame();
1415 auto isRedirect = webResourceRequest->IsRedirect();
1416 auto request = AceType::MakeRefPtr<WebRequest>(requestHeader, method, url, hasGesture, isMainFrame, isRedirect);
1417
1418 context->GetTaskExecutor()->PostSyncTask(
1419 [weak = WeakClaim(this), request, &result]() {
1420 auto delegate = weak.Upgrade();
1421 CHECK_NULL_VOID(delegate);
1422 if (Container::IsCurrentUseNewPipeline()) {
1423 auto webPattern = delegate->webPattern_.Upgrade();
1424 CHECK_NULL_VOID(webPattern);
1425 auto webEventHub = webPattern->GetWebEventHub();
1426 CHECK_NULL_VOID(webEventHub);
1427 auto propOnLoadIntercept = webEventHub->GetOnLoadInterceptEvent();
1428 CHECK_NULL_VOID(propOnLoadIntercept);
1429 auto eventParam = std::make_shared<LoadInterceptEvent>(request);
1430 result = propOnLoadIntercept(eventParam);
1431 return;
1432 }
1433 },
1434 TaskExecutor::TaskType::JS, "ArkUIWebLoadInterceptEvent");
1435 return result;
1436 }
1437
OnInterceptRequest(void * object)1438 RefPtr<WebResponse> WebDelegateCross::OnInterceptRequest(void* object)
1439 {
1440 ContainerScope scope(instanceId_);
1441 CHECK_NULL_RETURN(object, nullptr);
1442 auto context = context_.Upgrade();
1443 CHECK_NULL_RETURN(context, nullptr);
1444 RefPtr<WebResponse> result = nullptr;
1445 auto webResourceRequest = AceType::MakeRefPtr<WebResourceRequsetImpl>(object);
1446 CHECK_NULL_RETURN(webResourceRequest, nullptr);
1447 auto requestHeader = webResourceRequest->GetRequestHeader();
1448 auto method = webResourceRequest->GetMethod();
1449 auto url = webResourceRequest->GetRequestUrl();
1450 auto hasGesture = webResourceRequest->IsRequestGesture();
1451 auto isMainFrame = webResourceRequest->IsMainFrame();
1452 auto isRedirect = webResourceRequest->IsRedirect();
1453 auto request = AceType::MakeRefPtr<WebRequest>(requestHeader, method, url, hasGesture, isMainFrame, isRedirect);
1454
1455 auto jsTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::JS);
1456 jsTaskExecutor.PostSyncTask(
1457 [weak = WeakClaim(this), request, &result]() {
1458 auto delegate = weak.Upgrade();
1459 CHECK_NULL_VOID(delegate);
1460 if (Container::IsCurrentUseNewPipeline()) {
1461 auto webPattern = delegate->webPattern_.Upgrade();
1462 CHECK_NULL_VOID(webPattern);
1463 auto webEventHub = webPattern->GetWebEventHub();
1464 CHECK_NULL_VOID(webEventHub);
1465 auto propOnInterceptRequestEvent = webEventHub->GetOnInterceptRequestEvent();
1466 CHECK_NULL_VOID(propOnInterceptRequestEvent);
1467 auto param = std::make_shared<OnInterceptRequestEvent>(request);
1468 result = propOnInterceptRequestEvent(param);
1469 }
1470 },
1471 "ArkUIWebInterceptRequest");
1472 return result;
1473 }
1474
OnPageVisible(const std::string & param)1475 void WebDelegateCross::OnPageVisible(const std::string& param)
1476 {
1477 ContainerScope scope(instanceId_);
1478 auto context = context_.Upgrade();
1479 CHECK_NULL_VOID(context);
1480 context->GetTaskExecutor()->PostTask(
1481 [weak = WeakClaim(this), param]() {
1482 auto delegate = weak.Upgrade();
1483 CHECK_NULL_VOID(delegate);
1484 if (Container::IsCurrentUseNewPipeline()) {
1485 auto webPattern = delegate->webPattern_.Upgrade();
1486 CHECK_NULL_VOID(webPattern);
1487 auto webEventHub = webPattern->GetWebEventHub();
1488 CHECK_NULL_VOID(webEventHub);
1489 auto propOnPageVisible = webEventHub->GetOnPageVisibleEvent();
1490 CHECK_NULL_VOID(propOnPageVisible);
1491 auto eventParam = std::make_shared<PageVisibleEvent>(param);
1492 propOnPageVisible(eventParam);
1493 return;
1494 }
1495 },
1496 TaskExecutor::TaskType::JS, "ArkUIWebPageVisibleEvent");
1497 }
1498
OnDownloadStart(void * object)1499 void WebDelegateCross::OnDownloadStart(void* object)
1500 {
1501 ContainerScope scope(instanceId_);
1502 CHECK_NULL_VOID(object);
1503 auto context = context_.Upgrade();
1504 CHECK_NULL_VOID(context);
1505 auto webDownloadResponse = AceType::MakeRefPtr<WebDownloadResponseImpl>(object);
1506 CHECK_NULL_VOID(webDownloadResponse);
1507 auto url = webDownloadResponse->GetUrl();
1508 auto userAgent = webDownloadResponse->GetUserAgent();
1509 auto contentDisposition = webDownloadResponse->GetContentDisposition();
1510 auto mimetype = webDownloadResponse->GetMimetype();
1511 auto contentLength = webDownloadResponse->GetContentLength();
1512 context->GetTaskExecutor()->PostTask(
1513 [weak = WeakClaim(this), url, userAgent, contentDisposition, mimetype, contentLength]() {
1514 auto delegate = weak.Upgrade();
1515 CHECK_NULL_VOID(delegate);
1516 if (Container::IsCurrentUseNewPipeline()) {
1517 auto webPattern = delegate->webPattern_.Upgrade();
1518 CHECK_NULL_VOID(webPattern);
1519 auto webEventHub = webPattern->GetWebEventHub();
1520 CHECK_NULL_VOID(webEventHub);
1521 auto propOnDownloadStart = webEventHub->GetOnDownloadStartEvent();
1522 CHECK_NULL_VOID(propOnDownloadStart);
1523 auto eventParam =
1524 std::make_shared<DownloadStartEvent>(url, userAgent, contentDisposition, mimetype, contentLength);
1525 propOnDownloadStart(eventParam);
1526 return;
1527 }
1528 },
1529 TaskExecutor::TaskType::JS, "ArkUIWebDownloadStartEvent");
1530 }
1531
OnRefreshAccessedHistory(void * object)1532 void WebDelegateCross::OnRefreshAccessedHistory(void* object)
1533 {
1534 ContainerScope scope(instanceId_);
1535 CHECK_NULL_VOID(object);
1536 auto context = context_.Upgrade();
1537 CHECK_NULL_VOID(context);
1538 auto WebRefreshAccessedHistory = AceType::MakeRefPtr<WebRefreshAccessedHistoryImpl>(object);
1539 CHECK_NULL_VOID(WebRefreshAccessedHistory);
1540 auto url = WebRefreshAccessedHistory->GetUrl();
1541 auto isRefreshed = WebRefreshAccessedHistory->GetIsRefreshed();
1542 context->GetTaskExecutor()->PostTask(
1543 [weak = WeakClaim(this), url, isRefreshed]() {
1544 auto delegate = weak.Upgrade();
1545 CHECK_NULL_VOID(delegate);
1546 if (Container::IsCurrentUseNewPipeline()) {
1547 auto webPattern = delegate->webPattern_.Upgrade();
1548 CHECK_NULL_VOID(webPattern);
1549 auto webEventHub = webPattern->GetWebEventHub();
1550 CHECK_NULL_VOID(webEventHub);
1551 auto propOnRefreshAccessedHistory = webEventHub->GetOnRefreshAccessedHistoryEvent();
1552 CHECK_NULL_VOID(propOnRefreshAccessedHistory);
1553 auto eventParam = std::make_shared<RefreshAccessedHistoryEvent>(url, isRefreshed);
1554 propOnRefreshAccessedHistory(eventParam);
1555 return;
1556 }
1557 },
1558 TaskExecutor::TaskType::JS, "ArkUIWebRefreshAccessedHistoryEvent");
1559 }
1560
OnFullScreenEnter(void * object)1561 void WebDelegateCross::OnFullScreenEnter(void* object)
1562 {
1563 ContainerScope scope(instanceId_);
1564 CHECK_NULL_VOID(object);
1565 auto context = context_.Upgrade();
1566 CHECK_NULL_VOID(context);
1567 auto webFullScreenEnter = AceType::MakeRefPtr<WebFullScreenEnterImpl>(object);
1568 CHECK_NULL_VOID(webFullScreenEnter);
1569 int heights = webFullScreenEnter->GetHeights();
1570 int widths = webFullScreenEnter->GetWidths();
1571 auto fullScreenExitHandlerResponse = AceType::MakeRefPtr<FullScreenExitHandlerImpl>(object);
1572 context->GetTaskExecutor()->PostTask(
1573 [weak = WeakClaim(this), widths, heights, fullScreenExitHandlerResponse]() {
1574 auto delegate = weak.Upgrade();
1575 CHECK_NULL_VOID(delegate);
1576 if (Container::IsCurrentUseNewPipeline()) {
1577 auto webPattern = delegate->webPattern_.Upgrade();
1578 CHECK_NULL_VOID(webPattern);
1579 auto webEventHub = webPattern->GetWebEventHub();
1580 CHECK_NULL_VOID(webEventHub);
1581 auto propOnFullScreenEnter = webEventHub->GetOnFullScreenEnterEvent();
1582 CHECK_NULL_VOID(propOnFullScreenEnter);
1583 auto eventParam = std::make_shared<FullScreenEnterEvent>(fullScreenExitHandlerResponse,
1584 widths, heights);
1585 propOnFullScreenEnter(eventParam);
1586 return;
1587 }
1588 },
1589 TaskExecutor::TaskType::JS, "ArkUIWebFullScreenEnterEvent");
1590 }
1591
OnFullScreenExit(void * object)1592 void WebDelegateCross::OnFullScreenExit(void* object)
1593 {
1594 ContainerScope scope(instanceId_);
1595 CHECK_NULL_VOID(object);
1596 auto context = context_.Upgrade();
1597 CHECK_NULL_VOID(context);
1598 auto webFullScreenExit = AceType::MakeRefPtr<WebFullScreenExitImpl>(object);
1599 CHECK_NULL_VOID(webFullScreenExit);
1600 context->GetTaskExecutor()->PostTask(
1601 [weak = WeakClaim(this)]() {
1602 auto delegate = weak.Upgrade();
1603 CHECK_NULL_VOID(delegate);
1604 if (Container::IsCurrentUseNewPipeline()) {
1605 auto webPattern = delegate->webPattern_.Upgrade();
1606 CHECK_NULL_VOID(webPattern);
1607 auto webEventHub = webPattern->GetWebEventHub();
1608 CHECK_NULL_VOID(webEventHub);
1609 auto propOnFullScreenExit = webEventHub->GetOnFullScreenExitEvent();
1610 CHECK_NULL_VOID(propOnFullScreenExit);
1611 auto eventParam = std::make_shared<FullScreenExitEvent>();
1612 propOnFullScreenExit(eventParam);
1613 return;
1614 }
1615 },
1616 TaskExecutor::TaskType::JS, "ArkUIWebFullScreenExitEvent");
1617 }
1618
OnCommonDialog(void * object,DialogEventType dialogEventType)1619 bool WebDelegateCross::OnCommonDialog(void* object, DialogEventType dialogEventType)
1620 {
1621 ContainerScope scope(instanceId_);
1622 CHECK_NULL_RETURN(object, false);
1623 auto context = context_.Upgrade();
1624 CHECK_NULL_RETURN(context, false);
1625 bool result = false;
1626 auto webCommonDialog = AceType::MakeRefPtr<WebCommonDialogImpl>(object);
1627 CHECK_NULL_RETURN(webCommonDialog, false);
1628 auto url = webCommonDialog->GetUrl();
1629 auto message = webCommonDialog->GetMessage();
1630 auto value = dialogEventType == DialogEventType::DIALOG_EVENT_PROMPT ? webCommonDialog->GetValue() : "";
1631 auto dialogResult = AceType::MakeRefPtr<DialogResult>(object, dialogEventType);
1632 context->GetTaskExecutor()->PostSyncTask(
1633 [weak = WeakClaim(this), url, message, value, dialogResult, dialogEventType, &result]() {
1634 auto delegate = weak.Upgrade();
1635 CHECK_NULL_VOID(delegate);
1636 if (Container::IsCurrentUseNewPipeline()) {
1637 auto webPattern = delegate->webPattern_.Upgrade();
1638 CHECK_NULL_VOID(webPattern);
1639 auto webEventHub = webPattern->GetWebEventHub();
1640 CHECK_NULL_VOID(webEventHub);
1641 auto eventParam = std::make_shared<WebDialogEvent>(url, message, value, dialogEventType, dialogResult);
1642 result = webEventHub->FireOnCommonDialogEvent(eventParam, dialogEventType);
1643 return;
1644 }
1645 },
1646 TaskExecutor::TaskType::JS, "ArkUIWebFireOnCommonDialogEvent");
1647 return result;
1648 }
1649
OnPermissionRequest(void * object)1650 bool WebDelegateCross::OnPermissionRequest(void* object)
1651 {
1652 ContainerScope scope(instanceId_);
1653 CHECK_NULL_RETURN(object, false);
1654 auto context = context_.Upgrade();
1655 CHECK_NULL_RETURN(context, false);
1656 bool result = false;
1657 auto webPermissionRequest = AceType::MakeRefPtr<PermissionRequestImpl>(object);
1658 webPermissionRequest->SetOrigin();
1659 webPermissionRequest->SetResources();
1660 CHECK_NULL_RETURN(webPermissionRequest, false);
1661 context->GetTaskExecutor()->PostSyncTask(
1662 [weak = WeakClaim(this), webPermissionRequest, &result]() {
1663 auto delegate = weak.Upgrade();
1664 CHECK_NULL_VOID(delegate);
1665 if (Container::IsCurrentUseNewPipeline()) {
1666 auto webPattern = delegate->webPattern_.Upgrade();
1667 CHECK_NULL_VOID(webPattern);
1668 auto webEventHub = webPattern->GetWebEventHub();
1669 CHECK_NULL_VOID(webEventHub);
1670 auto propOnPermissionRequest = webEventHub->GetOnPermissionRequestEvent();
1671 CHECK_NULL_VOID(propOnPermissionRequest);
1672 auto eventParam = std::make_shared<WebPermissionRequestEvent>(webPermissionRequest);
1673 propOnPermissionRequest(eventParam);
1674 result = true;
1675 return;
1676 }
1677 },
1678 TaskExecutor::TaskType::JS, "ArkUIWebPermissionRequestEvent");
1679 return result;
1680 }
1681
OnHttpAuthRequest(void * object)1682 bool WebDelegateCross::OnHttpAuthRequest(void* object)
1683 {
1684 ContainerScope scope(instanceId_);
1685 CHECK_NULL_RETURN(object, false);
1686 auto context = context_.Upgrade();
1687 CHECK_NULL_RETURN(context, false);
1688 bool result = false;
1689 auto webHttpAuthRequest = AceType::MakeRefPtr<WebAuthRequestImpl>(object);
1690 CHECK_NULL_RETURN(webHttpAuthRequest, false);
1691 auto host = webHttpAuthRequest->GetHost();
1692 auto realm = webHttpAuthRequest->GetRealm();
1693 auto authResult = AceType::MakeRefPtr<WebAuthResult>(object);
1694 context->GetTaskExecutor()->PostSyncTask(
1695 [weak = WeakClaim(this), host, realm, authResult, &result]() {
1696 auto delegate = weak.Upgrade();
1697 CHECK_NULL_VOID(delegate);
1698 if (Container::IsCurrentUseNewPipeline()) {
1699 auto webPattern = delegate->webPattern_.Upgrade();
1700 CHECK_NULL_VOID(webPattern);
1701 auto webEventHub = webPattern->GetWebEventHub();
1702 CHECK_NULL_VOID(webEventHub);
1703 auto propOnHttpAuthRequest = webEventHub->GetOnHttpAuthRequestEvent();
1704 CHECK_NULL_VOID(propOnHttpAuthRequest);
1705 auto eventParam = std::make_shared<WebHttpAuthEvent>(authResult, host, realm);
1706 result = propOnHttpAuthRequest(eventParam);
1707 return;
1708 }
1709 },
1710 TaskExecutor::TaskType::JS, "ArkUIWebHttpAuthRequestEvent");
1711 return result;
1712 }
1713
OnShowFileChooser(void * object)1714 bool WebDelegateCross::OnShowFileChooser(void* object)
1715 {
1716 ContainerScope scope(instanceId_);
1717 CHECK_NULL_RETURN(object, false);
1718 auto context = context_.Upgrade();
1719 CHECK_NULL_RETURN(context, false);
1720 bool isAllowed = false;
1721 auto webFileChooser = AceType::MakeRefPtr<WebFileChooserImpl>(object);
1722 CHECK_NULL_RETURN(webFileChooser, false);
1723 auto title = webFileChooser->GetTitle();
1724 auto mode = webFileChooser->GetMode();
1725 auto defaultFileName = webFileChooser->GetDefaultFileName();
1726 auto acceptType = webFileChooser->GetAcceptType();
1727 auto isCapture = webFileChooser->IsCapture();
1728 auto param = AceType::MakeRefPtr<FileSelectorParam>(title, mode, defaultFileName, acceptType, isCapture);
1729 auto result = AceType::MakeRefPtr<WebFileSelectorResult>(object);
1730 bool postTask = context->GetTaskExecutor()->PostSyncTask(
1731 [weak = WeakClaim(this), param, result, &isAllowed]() {
1732 auto delegate = weak.Upgrade();
1733 CHECK_NULL_VOID(delegate);
1734 if (Container::IsCurrentUseNewPipeline()) {
1735 auto webPattern = delegate->webPattern_.Upgrade();
1736 CHECK_NULL_VOID(webPattern);
1737 auto webEventHub = webPattern->GetWebEventHub();
1738 CHECK_NULL_VOID(webEventHub);
1739 auto propOnFileSelectorShow = webEventHub->GetOnFileSelectorShowEvent();
1740 CHECK_NULL_VOID(propOnFileSelectorShow);
1741 auto eventParam = std::make_shared<FileSelectorEvent>(param, result);
1742 CHECK_NULL_VOID(eventParam);
1743 isAllowed = propOnFileSelectorShow(eventParam);
1744 return;
1745 }
1746 },
1747 TaskExecutor::TaskType::JS, "ArkUIWebFileSelectorShowEvent");
1748 return isAllowed;
1749 }
1750
OnGeolocationPermissionsShowPrompt(void * object)1751 void WebDelegateCross::OnGeolocationPermissionsShowPrompt(void* object)
1752 {
1753 ContainerScope scope(instanceId_);
1754 CHECK_NULL_VOID(object);
1755 auto context = context_.Upgrade();
1756 CHECK_NULL_VOID(context);
1757 auto webGeolocationImpl = AceType::MakeRefPtr<WebGeolocationImpl>(object);
1758 CHECK_NULL_VOID(webGeolocationImpl);
1759 auto origin = webGeolocationImpl->GetOrigin();
1760 auto callback = AceType::MakeRefPtr<Geolocation>(object);
1761 context->GetTaskExecutor()->PostTask(
1762 [weak = WeakClaim(this), origin, callback]() {
1763 auto delegate = weak.Upgrade();
1764 CHECK_NULL_VOID(delegate);
1765 if (Container::IsCurrentUseNewPipeline()) {
1766 auto webPattern = delegate->webPattern_.Upgrade();
1767 CHECK_NULL_VOID(webPattern);
1768 auto webEventHub = webPattern->GetWebEventHub();
1769 CHECK_NULL_VOID(webEventHub);
1770 auto propOnGeolocationShow = webEventHub->GetOnGeolocationShowEvent();
1771 CHECK_NULL_VOID(propOnGeolocationShow);
1772 auto eventParam = std::make_shared<LoadWebGeolocationShowEvent>(origin, callback);
1773 propOnGeolocationShow(eventParam);
1774 return;
1775 }
1776 },
1777 TaskExecutor::TaskType::JS, "ArkUIWebGeolocationShowEvent");
1778 }
1779
OnGeolocationPermissionsHidePrompt()1780 void WebDelegateCross::OnGeolocationPermissionsHidePrompt()
1781 {
1782 ContainerScope scope(instanceId_);
1783 auto context = context_.Upgrade();
1784 CHECK_NULL_VOID(context);
1785 context->GetTaskExecutor()->PostTask(
1786 [weak = WeakClaim(this)]() {
1787 auto delegate = weak.Upgrade();
1788 CHECK_NULL_VOID(delegate);
1789 if (Container::IsCurrentUseNewPipeline()) {
1790 auto webPattern = delegate->webPattern_.Upgrade();
1791 CHECK_NULL_VOID(webPattern);
1792 auto webEventHub = webPattern->GetWebEventHub();
1793 CHECK_NULL_VOID(webEventHub);
1794 auto propOnGeolocationHide = webEventHub->GetOnGeolocationHideEvent();
1795 CHECK_NULL_VOID(propOnGeolocationHide);
1796 auto eventParam = std::make_shared<LoadWebGeolocationHideEvent>("");
1797 propOnGeolocationHide(eventParam);
1798 return;
1799 }
1800 },
1801 TaskExecutor::TaskType::JS, "ArkUIWebGeolocationHideEvent");
1802 }
1803
UpdateUserAgent(const std::string & userAgent)1804 void WebDelegateCross::UpdateUserAgent(const std::string& userAgent) {}
1805
UpdateBackgroundColor(const int backgroundColor)1806 void WebDelegateCross::UpdateBackgroundColor(const int backgroundColor)
1807 {
1808 hash_ = MakeResourceHash();
1809 updateBackgroundColor_ = MakeMethodHash(WEB_ATTRIBUTE_BACKGROUND_COLOR);
1810 std::stringstream paramStream;
1811 paramStream << NTC_BACKGROUND_COLOR << WEB_PARAM_EQUALS << backgroundColor;
1812 std::string param = paramStream.str();
1813 CallResRegisterMethod(updateBackgroundColor_, param, nullptr);
1814 }
1815
UpdateInitialScale(float scale)1816 void WebDelegateCross::UpdateInitialScale(float scale) {}
UpdateJavaScriptEnabled(const bool & isJsEnabled)1817 void WebDelegateCross::UpdateJavaScriptEnabled(const bool& isJsEnabled)
1818 {
1819 hash_ = MakeResourceHash();
1820 updateJavaScriptEnabled_ = MakeMethodHash(WEB_ATTRIBUTE_JAVASCRIPT_ACCESS);
1821 std::stringstream paramStream;
1822 paramStream << NTC_JAVASCRIPT_ACCESS << WEB_PARAM_EQUALS << isJsEnabled;
1823 std::string param = paramStream.str();
1824 CallResRegisterMethod(updateJavaScriptEnabled_, param, nullptr);
1825 }
1826
UpdateAllowFileAccess(const bool & isFileAccessEnabled)1827 void WebDelegateCross::UpdateAllowFileAccess(const bool& isFileAccessEnabled) {}
1828
UpdateBlockNetworkImage(const bool & onLineImageAccessEnabled)1829 void WebDelegateCross::UpdateBlockNetworkImage(const bool& onLineImageAccessEnabled)
1830 {
1831 hash_ = MakeResourceHash();
1832 updateBlockNetworkImageMethod_ = MakeMethodHash(WEB_ATTRIBUTE_ONLINE_IMAGE_ACCESS);
1833 std::stringstream paramStream;
1834 paramStream << NTC_ONLINE_IMAGE_ACCESS << WEB_PARAM_EQUALS << onLineImageAccessEnabled;
1835 std::string param = paramStream.str();
1836 CallResRegisterMethod(updateBlockNetworkImageMethod_, param, nullptr);
1837 }
1838
UpdateLoadsImagesAutomatically(const bool & isImageAccessEnabled)1839 void WebDelegateCross::UpdateLoadsImagesAutomatically(const bool& isImageAccessEnabled)
1840 {
1841 hash_ = MakeResourceHash();
1842 updateLoadsImagesAutomaticallyMethod_ = MakeMethodHash(WEB_IMAGE_ACCESS);
1843 std::stringstream paramStream;
1844 paramStream << NTC_IMAGE_ACCESS << WEB_PARAM_EQUALS << isImageAccessEnabled;
1845 std::string param = paramStream.str();
1846 CallResRegisterMethod(updateLoadsImagesAutomaticallyMethod_, param, nullptr);
1847 }
1848
UpdateMixedContentMode(const MixedModeContent & mixedMode)1849 void WebDelegateCross::UpdateMixedContentMode(const MixedModeContent& mixedMode)
1850 {
1851 hash_ = MakeResourceHash();
1852 onUpdateMixedContentModeMethod_ = MakeMethodHash(WEB_ATTRIBUTE_MIXED_MODE);
1853 std::stringstream paramStream;
1854 paramStream << NTC_MIXED_MODE << WEB_PARAM_EQUALS << mixedMode;
1855 std::string param = paramStream.str();
1856 CallResRegisterMethod(onUpdateMixedContentModeMethod_, param, nullptr);
1857 }
1858
UpdateSupportZoom(const bool & isZoomAccessEnabled)1859 void WebDelegateCross::UpdateSupportZoom(const bool& isZoomAccessEnabled)
1860 {
1861 hash_ = MakeResourceHash();
1862 updateZoomAccess_ = MakeMethodHash(WEB_ATTRIBUTE_ZOOM_ACCESS);
1863 std::stringstream paramStream;
1864 paramStream << NTC_ZOOM_ACCESS << WEB_PARAM_EQUALS << isZoomAccessEnabled;
1865 std::string param = paramStream.str();
1866 CallResRegisterMethod(updateZoomAccess_, param, nullptr);
1867 }
1868
UpdateDomStorageEnabled(const bool & isDomStorageAccessEnabled)1869 void WebDelegateCross::UpdateDomStorageEnabled(const bool& isDomStorageAccessEnabled)
1870 {
1871 hash_ = MakeResourceHash();
1872 updateDomStorageEnabledMethod_ = MakeMethodHash(WEB_ATTRIBUTE_DOM_STORAGE_ACCESS);
1873 std::stringstream paramStream;
1874 paramStream << NTC_DOM_STORAGE_ACCESS << WEB_PARAM_EQUALS << isDomStorageAccessEnabled;
1875 std::string param = paramStream.str();
1876 CallResRegisterMethod(updateDomStorageEnabledMethod_, param, nullptr);
1877 }
1878
UpdateGeolocationEnabled(const bool & isGeolocationAccessEnabled)1879 void WebDelegateCross::UpdateGeolocationEnabled(const bool& isGeolocationAccessEnabled)
1880 {
1881 hash_ = MakeResourceHash();
1882 UpdateGeolocationEnabledMethod_ = MakeMethodHash(WEB_ATTRIBUTE_GEOLOCATION_ACCESS);
1883 std::stringstream paramStream;
1884 paramStream << NTC_GEOLOCATION_ACCESS << WEB_PARAM_EQUALS << isGeolocationAccessEnabled;
1885 std::string param = paramStream.str();
1886 CallResRegisterMethod(UpdateGeolocationEnabledMethod_, param, nullptr);
1887 }
1888
UpdateCacheMode(const WebCacheMode & mode)1889 void WebDelegateCross::UpdateCacheMode(const WebCacheMode& mode)
1890 {
1891 hash_ = MakeResourceHash();
1892 updateCacheModeMethod_ = MakeMethodHash(WEB_CACHE_MODE);
1893 std::stringstream paramStream;
1894 paramStream << NTC_CACHE_MODE << WEB_PARAM_EQUALS << mode;
1895 std::string param = paramStream.str();
1896 CallResRegisterMethod(updateCacheModeMethod_, param, nullptr);
1897 }
1898
UpdateDarkMode(const WebDarkMode & mode)1899 void WebDelegateCross::UpdateDarkMode(const WebDarkMode& mode)
1900 {}
1901
UpdateForceDarkAccess(const bool & access)1902 void WebDelegateCross::UpdateForceDarkAccess(const bool& access)
1903 {}
1904
UpdateAudioResumeInterval(const int32_t & resumeInterval)1905 void WebDelegateCross::UpdateAudioResumeInterval(const int32_t& resumeInterval)
1906 {}
1907
UpdateAudioExclusive(const bool & audioExclusive)1908 void WebDelegateCross::UpdateAudioExclusive(const bool& audioExclusive)
1909 {}
1910
UpdateAudioSessionType(const WebAudioSessionType & audioSessionType)1911 void WebDelegateCross::UpdateAudioSessionType(const WebAudioSessionType& audioSessionType)
1912 {}
1913
UpdateOverviewModeEnabled(const bool & isOverviewModeAccessEnabled)1914 void WebDelegateCross::UpdateOverviewModeEnabled(const bool& isOverviewModeAccessEnabled)
1915 {}
1916
UpdateFileFromUrlEnabled(const bool & isFileFromUrlAccessEnabled)1917 void WebDelegateCross::UpdateFileFromUrlEnabled(const bool& isFileFromUrlAccessEnabled)
1918 {}
1919
UpdateDatabaseEnabled(const bool & isDatabaseAccessEnabled)1920 void WebDelegateCross::UpdateDatabaseEnabled(const bool& isDatabaseAccessEnabled)
1921 {}
1922
UpdateTextZoomRatio(const int32_t & textZoomRatioNum)1923 void WebDelegateCross::UpdateTextZoomRatio(const int32_t& textZoomRatioNum)
1924 {}
1925
UpdateWebDebuggingAccess(bool isWebDebuggingAccessEnabled)1926 void WebDelegateCross::UpdateWebDebuggingAccess(bool isWebDebuggingAccessEnabled)
1927 {}
1928
UpdatePinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)1929 void WebDelegateCross::UpdatePinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)
1930 {}
1931
UpdateMediaPlayGestureAccess(bool isNeedGestureAccess)1932 void WebDelegateCross::UpdateMediaPlayGestureAccess(bool isNeedGestureAccess)
1933 {
1934 hash_ = MakeResourceHash();
1935 updateMediaPlayGestureAccess_ = MakeMethodHash(WEB_ATTRIBUTE_MEDIA_PLAY_GESTURE_ACCESS);
1936 std::stringstream paramStream;
1937 paramStream << NTC_MEDIA_PLAY_GESTURE_ACCESS << WEB_PARAM_EQUALS << isNeedGestureAccess;
1938 std::string param = paramStream.str();
1939 CallResRegisterMethod(updateMediaPlayGestureAccess_, param, nullptr);
1940 }
1941
UpdateMultiWindowAccess(bool isMultiWindowAccessEnabled)1942 void WebDelegateCross::UpdateMultiWindowAccess(bool isMultiWindowAccessEnabled)
1943 {}
1944
UpdateAllowWindowOpenMethod(bool isAllowWindowOpenMethod)1945 void WebDelegateCross::UpdateAllowWindowOpenMethod(bool isAllowWindowOpenMethod)
1946 {}
1947
UpdateWebCursiveFont(const std::string & cursiveFontFamily)1948 void WebDelegateCross::UpdateWebCursiveFont(const std::string& cursiveFontFamily)
1949 {}
1950
UpdateWebFantasyFont(const std::string & fantasyFontFamily)1951 void WebDelegateCross::UpdateWebFantasyFont(const std::string& fantasyFontFamily)
1952 {}
1953
UpdateWebFixedFont(const std::string & fixedFontFamily)1954 void WebDelegateCross::UpdateWebFixedFont(const std::string& fixedFontFamily)
1955 {}
1956
UpdateWebSansSerifFont(const std::string & sansSerifFontFamily)1957 void WebDelegateCross::UpdateWebSansSerifFont(const std::string& sansSerifFontFamily)
1958 {}
1959
UpdateWebSerifFont(const std::string & serifFontFamily)1960 void WebDelegateCross::UpdateWebSerifFont(const std::string& serifFontFamily)
1961 {}
1962
UpdateWebStandardFont(const std::string & standardFontFamily)1963 void WebDelegateCross::UpdateWebStandardFont(const std::string& standardFontFamily)
1964 {}
1965
UpdateDefaultFixedFontSize(int32_t size)1966 void WebDelegateCross::UpdateDefaultFixedFontSize(int32_t size)
1967 {}
1968
UpdateDefaultFontSize(int32_t defaultFontSize)1969 void WebDelegateCross::UpdateDefaultFontSize(int32_t defaultFontSize)
1970 {}
1971
UpdateMinFontSize(int32_t minFontSize)1972 void WebDelegateCross::UpdateMinFontSize(int32_t minFontSize)
1973 {
1974 hash_ = MakeResourceHash();
1975 updateMinFontSize_ = MakeMethodHash(WEB_ATTRIBUTE_MIN_FONT_SIZE);
1976 std::stringstream paramStream;
1977 paramStream << NTC_MIN_FONT_SIZE << WEB_PARAM_EQUALS << std::clamp(minFontSize, FONT_MIN_SIZE, FONT_MAX_SIZE);
1978 std::string param = paramStream.str();
1979 CallResRegisterMethod(updateMinFontSize_, param, nullptr);
1980 }
1981
UpdateMinLogicalFontSize(int32_t minLogicalFontSize)1982 void WebDelegateCross::UpdateMinLogicalFontSize(int32_t minLogicalFontSize)
1983 {}
1984
UpdateBlockNetwork(bool isNetworkBlocked)1985 void WebDelegateCross::UpdateBlockNetwork(bool isNetworkBlocked)
1986 {
1987 hash_ = MakeResourceHash();
1988 onBlockNetworkUpdateMethod_ = MakeMethodHash(WEB_ATTRIBUTE_BLOCK_NETWORK);
1989 std::stringstream paramStream;
1990 paramStream << NTC_BLOCK_NETWORK << WEB_PARAM_EQUALS << isNetworkBlocked;
1991 std::string param = paramStream.str();
1992 CallResRegisterMethod(onBlockNetworkUpdateMethod_, param, nullptr);
1993 }
1994
UpdateHorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled)1995 void WebDelegateCross::UpdateHorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled)
1996 {
1997 hash_ = MakeResourceHash();
1998 updateHorizontalScrollBarAccess_ = MakeMethodHash(WEB_ATTRIBUTE_HORIZONTAL_SCROLLBAR_ACCESS);
1999 std::stringstream paramStream;
2000 paramStream << NTC_HORIZONTAL_SCROLLBAR_ACCESS << WEB_PARAM_EQUALS << isHorizontalScrollBarAccessEnabled;
2001 std::string param = paramStream.str();
2002 CallResRegisterMethod(updateHorizontalScrollBarAccess_, param, nullptr);
2003 }
2004
UpdateVerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled)2005 void WebDelegateCross::UpdateVerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled)
2006 {
2007 hash_ = MakeResourceHash();
2008 updateVerticalScrollBarAccess_ = MakeMethodHash(WEB_ATTRIBUTE_VERTICAL_SCROLLBAR_ACCESS);
2009 std::stringstream paramStream;
2010 paramStream << NTC_VERTICAL_SCROLLBAR_ACCESS << WEB_PARAM_EQUALS << isVerticalScrollBarAccessEnabled;
2011 std::string param = paramStream.str();
2012 CallResRegisterMethod(updateVerticalScrollBarAccess_, param, nullptr);
2013 }
2014
UpdateScrollBarColor(const std::string & colorValue)2015 void WebDelegateCross::UpdateScrollBarColor(const std::string& colorValue)
2016 {}
2017
LoadUrl()2018 void WebDelegateCross::LoadUrl()
2019 {}
2020
LoadDataWithRichText()2021 bool WebDelegateCross::LoadDataWithRichText()
2022 {
2023 auto webPattern = webPattern_.Upgrade();
2024 CHECK_NULL_RETURN(webPattern, false);
2025 auto webData = webPattern->GetWebData();
2026 CHECK_NULL_RETURN(webData, false);
2027 const std::string& data = webData.value();
2028 if (data.empty()) {
2029 return false;
2030 }
2031 hash_ = MakeResourceHash();
2032 loadDataMethod_ = MakeMethodHash(WEB_METHOD_LOAD_DATA);
2033 std::stringstream paramStream;
2034 paramStream << NTC_PARAM_LOADDATA_DATA << WEB_PARAM_EQUALS
2035 << data.c_str() << WEB_PARAM_AND
2036 << NTC_PARAM_LOADDATA_MIMETYPE << WEB_PARAM_EQUALS
2037 << MIMETYPE << WEB_PARAM_AND
2038 << NTC_PARAM_LOADDATA_ENCODING << WEB_PARAM_EQUALS
2039 << ENCODING;
2040 std::string param = paramStream.str();
2041 CallResRegisterMethod(loadDataMethod_, param, nullptr);
2042 return true;
2043 }
2044
SetBackgroundColor(int32_t backgroundColor)2045 void WebDelegateCross::SetBackgroundColor(int32_t backgroundColor)
2046 {}
2047
SetBoundsOrResize(const Size & drawSize,const Offset & offset)2048 void WebDelegateCross::SetBoundsOrResize(const Size& drawSize, const Offset& offset)
2049 {
2050 hash_ = MakeResourceHash();
2051 updateLayoutMethod_ = MakeMethodHash(WEB_METHOD_UPDATE_LAYOUT);
2052 auto context = context_.Upgrade();
2053 if (!context) {
2054 return;
2055 }
2056 std::stringstream paramStream;
2057 float viewScale = context->GetViewScale();
2058 paramStream << NTC_PARAM_WIDTH << WEB_PARAM_EQUALS
2059 << drawSize.Width() * viewScale << WEB_PARAM_AND
2060 << NTC_PARAM_HEIGHT << WEB_PARAM_EQUALS
2061 << drawSize.Height() * viewScale << WEB_PARAM_AND
2062 << NTC_PARAM_LEFT << WEB_PARAM_EQUALS
2063 << offset.GetX() * viewScale << WEB_PARAM_AND
2064 << NTC_PARAM_TOP << WEB_PARAM_EQUALS
2065 << offset.GetY() * viewScale;
2066 std::string param = paramStream.str();
2067 CallResRegisterMethod(updateLayoutMethod_, param, nullptr);
2068 }
2069
SetDrawRect(int32_t x,int32_t y,int32_t width,int32_t height)2070 void WebDelegateCross::SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height)
2071 {
2072 // cross platform is not support now;
2073 }
2074
UpdateOptimizeParserBudgetEnabled(const bool enable)2075 void WebDelegateCross::UpdateOptimizeParserBudgetEnabled(const bool enable)
2076 {
2077 // cross platform is not support now;
2078 }
2079
MaximizeResize()2080 void WebDelegateCross::MaximizeResize()
2081 {
2082 // cross platform is not support now;
2083 }
2084
RunJsProxyCallback()2085 void WebDelegateCross::RunJsProxyCallback()
2086 {
2087 auto pattern = webPattern_.Upgrade();
2088 CHECK_NULL_VOID(pattern);
2089 pattern->CallJsProxyCallback();
2090 }
2091 }
2092