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 "bridge/declarative_frontend/jsview/models/web_model_impl.h"
17
18 #include "bridge/declarative_frontend/view_stack_processor.h"
19 #include "core/event/ace_event_handler.h"
20
21 namespace OHOS::Ace::Framework {
Create(const std::string & src,const RefPtr<WebController> & webController)22 void WebModelImpl::Create(const std::string& src, const RefPtr<WebController>& webController)
23 {
24 RefPtr<WebComponent> webComponent;
25 webComponent = AceType::MakeRefPtr<WebComponent>(src);
26 CHECK_NULL_VOID(webComponent);
27
28 webComponent->SetSrc(src);
29 webComponent->SetWebController(webController);
30 ViewStackProcessor::GetInstance()->Push(webComponent);
31 }
32
Create(const std::string & src,std::function<void (int32_t)> && setWebIdCallback,std::function<void (const std::string &)> && setHapPathCallback,int32_t parentWebId,bool popup)33 void WebModelImpl::Create(const std::string& src, std::function<void(int32_t)>&& setWebIdCallback,
34 std::function<void(const std::string&)>&& setHapPathCallback, int32_t parentWebId, bool popup)
35 {
36 RefPtr<WebComponent> webComponent;
37 webComponent = AceType::MakeRefPtr<WebComponent>(src);
38 CHECK_NULL_VOID(webComponent);
39
40 webComponent->SetSrc(src);
41 webComponent->SetPopup(popup);
42 webComponent->SetParentNWebId(parentWebId);
43 webComponent->SetSetWebIdCallback(std::move(setWebIdCallback));
44 webComponent->SetSetHapPathCallback(std::move(setHapPathCallback));
45 ViewStackProcessor::GetInstance()->Push(webComponent);
46 }
47
SetCustomScheme(const std::string & cmdLine)48 void WebModelImpl::SetCustomScheme(const std::string& cmdLine)
49 {
50 if (!cmdLine.empty()) {
51 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
52 CHECK_NULL_VOID(webComponent);
53 webComponent->SetCustomScheme(cmdLine);
54 }
55 }
56
SetFocusable(bool focusable)57 void WebModelImpl::SetFocusable(bool focusable)
58 {
59 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
60 CHECK_NULL_VOID(webComponent);
61 ViewStackProcessor::GetInstance()->Push(webComponent);
62
63 auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent();
64 CHECK_NULL_VOID(focusableComponent);
65 focusableComponent->SetFocusable(focusable);
66 }
67
SetFocusNode(bool isFocusNode)68 void WebModelImpl::SetFocusNode(bool isFocusNode)
69 {
70 auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent();
71 CHECK_NULL_VOID(focusableComponent);
72 focusableComponent->SetFocusNode(isFocusNode);
73 }
74
SetOnCommonDialog(std::function<bool (const BaseEventInfo * info)> && jsCallback,int dialogEventType)75 void WebModelImpl::SetOnCommonDialog(std::function<bool(const BaseEventInfo* info)>&& jsCallback, int dialogEventType)
76 {
77 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
78 CHECK_NULL_VOID(webComponent);
79 webComponent->SetOnCommonDialogImpl(std::move(jsCallback), static_cast<DialogEventType>(dialogEventType));
80 }
81
SetOnConsoleLog(std::function<bool (const BaseEventInfo * info)> && jsCallback)82 void WebModelImpl::SetOnConsoleLog(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
83 {
84 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
85 CHECK_NULL_VOID(webComponent);
86 webComponent->SetOnConsoleImpl(std::move(jsCallback));
87 }
88
SetOnPageStart(std::function<void (const BaseEventInfo * info)> && jsCallback)89 void WebModelImpl::SetOnPageStart(std::function<void(const BaseEventInfo* info)>&& jsCallback)
90 {
91 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
92 CHECK_NULL_VOID(webComponent);
93 auto eventMarker = EventMarker(std::move(jsCallback));
94 webComponent->SetPageStartedEventId(eventMarker);
95 }
96
SetOnPageFinish(std::function<void (const BaseEventInfo * info)> && jsCallback)97 void WebModelImpl::SetOnPageFinish(std::function<void(const BaseEventInfo* info)>&& jsCallback)
98 {
99 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
100 CHECK_NULL_VOID(webComponent);
101 auto eventMarker = EventMarker(std::move(jsCallback));
102 webComponent->SetPageFinishedEventId(eventMarker);
103 }
104
SetOnProgressChange(std::function<void (const BaseEventInfo * info)> && jsCallback)105 void WebModelImpl::SetOnProgressChange(std::function<void(const BaseEventInfo* info)>&& jsCallback)
106 {
107 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
108 CHECK_NULL_VOID(webComponent);
109 webComponent->SetProgressChangeImpl(std::move(jsCallback));
110 }
111
SetOnTitleReceive(std::function<void (const BaseEventInfo * info)> && jsCallback)112 void WebModelImpl::SetOnTitleReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback)
113 {
114 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
115 CHECK_NULL_VOID(webComponent);
116 auto eventMarker = EventMarker(std::move(jsCallback));
117 webComponent->SetTitleReceiveEventId(eventMarker);
118 }
119
SetOnFullScreenExit(std::function<void (const BaseEventInfo * info)> && jsCallback)120 void WebModelImpl::SetOnFullScreenExit(std::function<void(const BaseEventInfo* info)>&& jsCallback)
121 {
122 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
123 CHECK_NULL_VOID(webComponent);
124 auto eventMarker = EventMarker(std::move(jsCallback));
125 webComponent->SetOnFullScreenExitEventId(eventMarker);
126 }
127
SetOnFullScreenEnter(std::function<void (const BaseEventInfo * info)> && jsCallback)128 void WebModelImpl::SetOnFullScreenEnter(std::function<void(const BaseEventInfo* info)>&& jsCallback)
129 {
130 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
131 CHECK_NULL_VOID(webComponent);
132 webComponent->SetOnFullScreenEnterImpl(std::move(jsCallback));
133 }
134
SetOnGeolocationHide(std::function<void (const BaseEventInfo * info)> && jsCallback)135 void WebModelImpl::SetOnGeolocationHide(std::function<void(const BaseEventInfo* info)>&& jsCallback)
136 {
137 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
138 CHECK_NULL_VOID(webComponent);
139 auto eventMarker = EventMarker(std::move(jsCallback));
140 webComponent->SetGeolocationHideEventId(eventMarker);
141 }
142
SetOnGeolocationShow(std::function<void (const BaseEventInfo * info)> && jsCallback)143 void WebModelImpl::SetOnGeolocationShow(std::function<void(const BaseEventInfo* info)>&& jsCallback)
144 {
145 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
146 CHECK_NULL_VOID(webComponent);
147 auto eventMarker = EventMarker(std::move(jsCallback));
148 webComponent->SetGeolocationShowEventId(eventMarker);
149 }
150
SetOnRequestFocus(std::function<void (const BaseEventInfo * info)> && jsCallback)151 void WebModelImpl::SetOnRequestFocus(std::function<void(const BaseEventInfo* info)>&& jsCallback)
152 {
153 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
154 CHECK_NULL_VOID(webComponent);
155 auto eventMarker = EventMarker(std::move(jsCallback));
156 webComponent->SetRequestFocusEventId(eventMarker);
157 }
158
SetOnDownloadStart(std::function<void (const BaseEventInfo * info)> && jsCallback)159 void WebModelImpl::SetOnDownloadStart(std::function<void(const BaseEventInfo* info)>&& jsCallback)
160 {
161 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
162 CHECK_NULL_VOID(webComponent);
163 auto eventMarker = EventMarker(std::move(jsCallback));
164 webComponent->SetDownloadStartEventId(eventMarker);
165 }
166
SetOnHttpAuthRequest(std::function<bool (const BaseEventInfo * info)> && jsCallback)167 void WebModelImpl::SetOnHttpAuthRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
168 {
169 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
170 CHECK_NULL_VOID(webComponent);
171 webComponent->SetOnHttpAuthRequestImpl(std::move(jsCallback));
172 }
173
SetOnSslErrorRequest(std::function<bool (const BaseEventInfo * info)> && jsCallback)174 void WebModelImpl::SetOnSslErrorRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
175 {
176 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
177 CHECK_NULL_VOID(webComponent);
178 webComponent->SetOnSslErrorRequestImpl(std::move(jsCallback));
179 }
180
SetOnSslSelectCertRequest(std::function<bool (const BaseEventInfo * info)> && jsCallback)181 void WebModelImpl::SetOnSslSelectCertRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
182 {
183 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
184 CHECK_NULL_VOID(webComponent);
185 webComponent->SetOnSslSelectCertRequestImpl(std::move(jsCallback));
186 }
187
SetMediaPlayGestureAccess(bool isNeedGestureAccess)188 void WebModelImpl::SetMediaPlayGestureAccess(bool isNeedGestureAccess)
189 {
190 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
191 CHECK_NULL_VOID(webComponent);
192 webComponent->SetMediaPlayGestureAccess(isNeedGestureAccess);
193 }
194
SetOnKeyEvent(std::function<void (KeyEventInfo & keyEventInfo)> && jsCallback)195 void WebModelImpl::SetOnKeyEvent(std::function<void(KeyEventInfo& keyEventInfo)>&& jsCallback)
196 {
197 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
198 CHECK_NULL_VOID(webComponent);
199 webComponent->SetOnKeyEventCallback(std::move(jsCallback));
200 }
201
SetOnErrorReceive(std::function<void (const BaseEventInfo * info)> && jsCallback)202 void WebModelImpl::SetOnErrorReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback)
203 {
204 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
205 CHECK_NULL_VOID(webComponent);
206 auto eventMarker = EventMarker(std::move(jsCallback));
207
208 webComponent->SetPageErrorEventId(eventMarker);
209 }
210
SetOnHttpErrorReceive(std::function<void (const BaseEventInfo * info)> && jsCallback)211 void WebModelImpl::SetOnHttpErrorReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback)
212 {
213 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
214 CHECK_NULL_VOID(webComponent);
215 auto eventMarker = EventMarker(std::move(jsCallback));
216
217 webComponent->SetHttpErrorEventId(eventMarker);
218 }
219
SetOnInterceptRequest(std::function<RefPtr<WebResponse> (const BaseEventInfo * info)> && jsCallback)220 void WebModelImpl::SetOnInterceptRequest(std::function<RefPtr<WebResponse>(const BaseEventInfo* info)>&& jsCallback)
221 {
222 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
223 CHECK_NULL_VOID(webComponent);
224 webComponent->SetOnInterceptRequest(std::move(jsCallback));
225 }
226
SetOnUrlLoadIntercept(std::function<bool (const BaseEventInfo * info)> && jsCallback)227 void WebModelImpl::SetOnUrlLoadIntercept(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
228 {
229 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
230 CHECK_NULL_VOID(webComponent);
231 webComponent->SetOnUrlLoadIntercept(std::move(jsCallback));
232 }
233
SetOnLoadIntercept(std::function<bool (const BaseEventInfo * info)> && jsCallback)234 void WebModelImpl::SetOnLoadIntercept(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
235 {
236 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
237 CHECK_NULL_VOID(webComponent);
238 webComponent->SetOnLoadIntercept(std::move(jsCallback));
239 }
240
SetOnFileSelectorShow(std::function<bool (const BaseEventInfo * info)> && jsCallback)241 void WebModelImpl::SetOnFileSelectorShow(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
242 {
243 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
244 CHECK_NULL_VOID(webComponent);
245 webComponent->SetOnFileSelectorShow(std::move(jsCallback));
246 }
247
SetOnContextMenuShow(std::function<bool (const BaseEventInfo * info)> && jsCallback)248 void WebModelImpl::SetOnContextMenuShow(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
249 {
250 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
251 CHECK_NULL_VOID(webComponent);
252 webComponent->SetOnContextMenuShow(std::move(jsCallback));
253 }
254
SetOnContextMenuHide(std::function<void (const BaseEventInfo * info)> && jsCallback)255 void WebModelImpl::SetOnContextMenuHide(std::function<void(const BaseEventInfo* info)>&& jsCallback)
256 {
257 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
258 CHECK_NULL_VOID(webComponent);
259 webComponent->SetOnContextMenuHide(std::move(jsCallback));
260 }
261
SetJsEnabled(bool isJsEnabled)262 void WebModelImpl::SetJsEnabled(bool isJsEnabled)
263 {
264 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
265 CHECK_NULL_VOID(webComponent);
266 webComponent->SetJsEnabled(isJsEnabled);
267 }
268
SetFileAccessEnabled(bool isJsEnabled)269 void WebModelImpl::SetFileAccessEnabled(bool isJsEnabled)
270 {
271 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
272 CHECK_NULL_VOID(webComponent);
273 webComponent->SetFileAccessEnabled(isJsEnabled);
274 }
275
SetOnLineImageAccessEnabled(bool isOnLineImageAccessEnabled)276 void WebModelImpl::SetOnLineImageAccessEnabled(bool isOnLineImageAccessEnabled)
277 {
278 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
279 CHECK_NULL_VOID(webComponent);
280 webComponent->SetOnLineImageAccessEnabled(!isOnLineImageAccessEnabled);
281 }
282
SetDomStorageAccessEnabled(bool isDomStorageAccessEnabled)283 void WebModelImpl::SetDomStorageAccessEnabled(bool isDomStorageAccessEnabled)
284 {
285 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
286 CHECK_NULL_VOID(webComponent);
287 webComponent->SetDomStorageAccessEnabled(isDomStorageAccessEnabled);
288 }
289
SetImageAccessEnabled(bool isImageAccessEnabled)290 void WebModelImpl::SetImageAccessEnabled(bool isImageAccessEnabled)
291 {
292 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
293 CHECK_NULL_VOID(webComponent);
294 webComponent->SetImageAccessEnabled(isImageAccessEnabled);
295 }
296
SetMixedMode(MixedModeContent mixedMode)297 void WebModelImpl::SetMixedMode(MixedModeContent mixedMode)
298 {
299 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
300 CHECK_NULL_VOID(webComponent);
301 webComponent->SetMixedMode(mixedMode);
302 }
303
SetZoomAccessEnabled(bool isZoomAccessEnabled)304 void WebModelImpl::SetZoomAccessEnabled(bool isZoomAccessEnabled)
305 {
306 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
307 CHECK_NULL_VOID(webComponent);
308 webComponent->SetZoomAccessEnabled(isZoomAccessEnabled);
309 }
310
SetGeolocationAccessEnabled(bool isGeolocationAccessEnabled)311 void WebModelImpl::SetGeolocationAccessEnabled(bool isGeolocationAccessEnabled)
312 {
313 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
314 CHECK_NULL_VOID(webComponent);
315 webComponent->SetGeolocationAccessEnabled(isGeolocationAccessEnabled);
316 }
317
SetJsProxyCallback(std::function<void ()> && jsProxyCallback)318 void WebModelImpl::SetJsProxyCallback(std::function<void()>&& jsProxyCallback)
319 {
320 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
321 CHECK_NULL_VOID(webComponent);
322 webComponent->SetJsProxyCallback(std::move(jsProxyCallback));
323 }
324
SetUserAgent(const std::string & userAgent)325 void WebModelImpl::SetUserAgent(const std::string& userAgent)
326 {
327 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
328 CHECK_NULL_VOID(webComponent);
329 webComponent->SetUserAgent(userAgent);
330 }
331
SetRenderExitedId(std::function<void (const BaseEventInfo * info)> && jsCallback)332 void WebModelImpl::SetRenderExitedId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
333 {
334 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
335 CHECK_NULL_VOID(webComponent);
336 auto eventMarker = EventMarker(std::move(jsCallback));
337
338 webComponent->SetRenderExitedId(eventMarker);
339 }
340
SetRefreshAccessedHistoryId(std::function<void (const BaseEventInfo * info)> && jsCallback)341 void WebModelImpl::SetRefreshAccessedHistoryId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
342 {
343 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
344 CHECK_NULL_VOID(webComponent);
345 auto eventMarker = EventMarker(std::move(jsCallback));
346
347 webComponent->SetRefreshAccessedHistoryId(eventMarker);
348 }
349
SetCacheMode(WebCacheMode cacheMode)350 void WebModelImpl::SetCacheMode(WebCacheMode cacheMode)
351 {
352 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
353 CHECK_NULL_VOID(webComponent);
354 webComponent->SetCacheMode(cacheMode);
355 }
356
SetOverviewModeAccessEnabled(bool isOverviewModeAccessEnabled)357 void WebModelImpl::SetOverviewModeAccessEnabled(bool isOverviewModeAccessEnabled)
358 {
359 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
360 CHECK_NULL_VOID(webComponent);
361 webComponent->SetOverviewModeAccessEnabled(isOverviewModeAccessEnabled);
362 }
363
SetFileFromUrlAccessEnabled(bool isFileFromUrlAccessEnabled)364 void WebModelImpl::SetFileFromUrlAccessEnabled(bool isFileFromUrlAccessEnabled)
365 {
366 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
367 CHECK_NULL_VOID(webComponent);
368 webComponent->SetFileFromUrlAccessEnabled(isFileFromUrlAccessEnabled);
369 }
370
SetDatabaseAccessEnabled(bool isDatabaseAccessEnabled)371 void WebModelImpl::SetDatabaseAccessEnabled(bool isDatabaseAccessEnabled)
372 {
373 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
374 CHECK_NULL_VOID(webComponent);
375 webComponent->SetDatabaseAccessEnabled(isDatabaseAccessEnabled);
376 }
377
SetTextZoomRatio(int32_t textZoomRatioNum)378 void WebModelImpl::SetTextZoomRatio(int32_t textZoomRatioNum)
379 {
380 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
381 CHECK_NULL_VOID(webComponent);
382 webComponent->SetTextZoomRatio(textZoomRatioNum);
383 }
384
SetWebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled)385 void WebModelImpl::SetWebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled)
386 {
387 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
388 CHECK_NULL_VOID(webComponent);
389 webComponent->SetWebDebuggingAccessEnabled(isWebDebuggingAccessEnabled);
390 }
391
SetOnMouseEvent(std::function<void (MouseInfo & info)> && jsCallback)392 void WebModelImpl::SetOnMouseEvent(std::function<void(MouseInfo& info)>&& jsCallback)
393 {
394 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
395 CHECK_NULL_VOID(webComponent);
396 webComponent->SetOnMouseEventCallback(std::move(jsCallback));
397 }
398
SetResourceLoadId(std::function<void (const BaseEventInfo * info)> && jsCallback)399 void WebModelImpl::SetResourceLoadId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
400 {
401 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
402 CHECK_NULL_VOID(webComponent);
403 auto eventMarker = EventMarker(std::move(jsCallback));
404
405 webComponent->SetResourceLoadId(eventMarker);
406 }
407
SetScaleChangeId(std::function<void (const BaseEventInfo * info)> && jsCallback)408 void WebModelImpl::SetScaleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
409 {
410 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
411 CHECK_NULL_VOID(webComponent);
412 auto eventMarker = EventMarker(std::move(jsCallback));
413
414 webComponent->SetScaleChangeId(eventMarker);
415 }
416
SetScrollId(std::function<void (const BaseEventInfo * info)> && jsCallback)417 void WebModelImpl::SetScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
418 {
419 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
420 CHECK_NULL_VOID(webComponent);
421 auto eventMarker = EventMarker(std::move(jsCallback));
422
423 webComponent->SetScrollId(eventMarker);
424 }
425
SetPermissionRequestEventId(std::function<void (const BaseEventInfo * info)> && jsCallback)426 void WebModelImpl::SetPermissionRequestEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
427 {
428 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
429 CHECK_NULL_VOID(webComponent);
430 auto eventMarker = EventMarker(std::move(jsCallback));
431
432 webComponent->SetPermissionRequestEventId(eventMarker);
433 }
434
SetBackgroundColor(Color backgroundColor)435 void WebModelImpl::SetBackgroundColor(Color backgroundColor)
436 {
437 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
438 CHECK_NULL_VOID(webComponent);
439 webComponent->SetBackgroundColor(backgroundColor.GetValue());
440 }
441
InitialScale(float scale)442 void WebModelImpl::InitialScale(float scale)
443 {
444 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
445 CHECK_NULL_VOID(webComponent);
446 webComponent->SetInitialScale(scale);
447 }
448
SetSearchResultReceiveEventId(std::function<void (const BaseEventInfo * info)> && jsCallback)449 void WebModelImpl::SetSearchResultReceiveEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
450 {
451 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
452 CHECK_NULL_VOID(webComponent);
453 auto eventMarker = EventMarker(std::move(jsCallback));
454
455 webComponent->SetSearchResultReceiveEventId(eventMarker);
456 }
457
SetOnDragStart(std::function<NG::DragDropBaseInfo (const RefPtr<OHOS::Ace::DragEvent> & event,const std::string & extraParams)> && onDragStart)458 void WebModelImpl::SetOnDragStart(
459 std::function<NG::DragDropBaseInfo(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams)>&&
460 onDragStart)
461 {
462 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
463 CHECK_NULL_VOID(webComponent);
464 auto onDragStartId = [dragStartFunc = std::move(onDragStart)](
465 const RefPtr<DragEvent>& event, const std::string& extraParams) -> DragItemInfo {
466 auto dragInfo = dragStartFunc(event, extraParams);
467 DragItemInfo info;
468 info.extraInfo = dragInfo.extraInfo;
469 info.pixelMap = dragInfo.pixelMap;
470 info.customComponent = AceType::DynamicCast<Component>(dragInfo.node);
471 return info;
472 };
473 webComponent->SetOnDragStartId(onDragStartId);
474 }
475
SetOnDragEnter(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragStart)476 void WebModelImpl::SetOnDragEnter(
477 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragStart)
478 {
479 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
480 CHECK_NULL_VOID(webComponent);
481 webComponent->SetOnDragEnterId(onDragStart);
482 }
483
SetOnDragMove(std::function<void (const RefPtr<DragEvent> &,const std::string &)> && onDragMoveId)484 void WebModelImpl::SetOnDragMove(std::function<void(const RefPtr<DragEvent>&, const std::string&)>&& onDragMoveId)
485 {
486 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
487 CHECK_NULL_VOID(webComponent);
488 webComponent->SetOnDragMoveId(onDragMoveId);
489 }
490
SetOnDragLeave(std::function<void (const RefPtr<DragEvent> &,const std::string &)> && onDragLeave)491 void WebModelImpl::SetOnDragLeave(std::function<void(const RefPtr<DragEvent>&, const std::string&)>&& onDragLeave)
492 {
493 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
494 CHECK_NULL_VOID(webComponent);
495 webComponent->SetOnDragLeaveId(onDragLeave);
496 }
497
SetOnDrop(std::function<void (const RefPtr<DragEvent> &,const std::string &)> && onDropId)498 void WebModelImpl::SetOnDrop(std::function<void(const RefPtr<DragEvent>&, const std::string&)>&& onDropId)
499 {
500 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
501 CHECK_NULL_VOID(webComponent);
502 webComponent->SetOnDropId(onDropId);
503 }
504
SetPinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)505 void WebModelImpl::SetPinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)
506 {
507 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
508 CHECK_NULL_VOID(webComponent);
509 webComponent->SetPinchSmoothModeEnabled(isPinchSmoothModeEnabled);
510 }
511
SetWindowNewEvent(std::function<void (const std::shared_ptr<BaseEventInfo> & info)> && jsCallback)512 void WebModelImpl::SetWindowNewEvent(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& jsCallback)
513 {
514 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
515 CHECK_NULL_VOID(webComponent);
516 webComponent->SetWindowNewEvent(std::move(jsCallback));
517 }
518
SetWindowExitEventId(std::function<void (const BaseEventInfo * info)> && jsCallback)519 void WebModelImpl::SetWindowExitEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
520 {
521 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
522 CHECK_NULL_VOID(webComponent);
523 auto eventMarker = EventMarker(std::move(jsCallback));
524 webComponent->SetWindowExitEventId(eventMarker);
525 }
526
SetMultiWindowAccessEnabled(bool isMultiWindowAccessEnable)527 void WebModelImpl::SetMultiWindowAccessEnabled(bool isMultiWindowAccessEnable)
528 {
529 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
530 CHECK_NULL_VOID(webComponent);
531 webComponent->SetMultiWindowAccessEnabled(isMultiWindowAccessEnable);
532 }
533
SetAllowWindowOpenMethod(bool isAllowWindowOpenMethod)534 void WebModelImpl::SetAllowWindowOpenMethod(bool isAllowWindowOpenMethod)
535 {
536 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
537 CHECK_NULL_VOID(webComponent);
538 webComponent->SetAllowWindowOpenMethod(isAllowWindowOpenMethod);
539 }
540
SetOnInterceptKeyEventCallback(std::function<bool (KeyEventInfo & keyEventInfo)> && keyEventInfo)541 void WebModelImpl::SetOnInterceptKeyEventCallback(std::function<bool(KeyEventInfo& keyEventInfo)>&& keyEventInfo)
542 {
543 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
544 CHECK_NULL_VOID(webComponent);
545 webComponent->SetOnInterceptKeyEventCallback(keyEventInfo);
546 }
547
SetOverScrollId(std::function<void (const BaseEventInfo * info)> && jsCallback)548 void WebModelImpl::SetOverScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
549 {
550 auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
551 CHECK_NULL_VOID(webComponent);
552 auto eventMarker = EventMarker(std::move(jsCallback));
553
554 webComponent->SetOverScrollId(eventMarker);
555 }
556 } // namespace OHOS::Ace::Framework
557