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,RenderMode,bool incognitoMode,const std::string & sharedRenderProcessToken)22 void WebModelImpl::Create(const std::string& src, const RefPtr<WebController>& webController,
23     RenderMode /* renderMode */, bool incognitoMode, const std::string& sharedRenderProcessToken)
24 {
25     RefPtr<WebComponent> webComponent;
26     webComponent = AceType::MakeRefPtr<WebComponent>(src);
27     CHECK_NULL_VOID(webComponent);
28 
29     webComponent->SetSrc(src);
30     webComponent->SetWebController(webController);
31     webComponent->SetIncognitoMode(incognitoMode);
32     webComponent->SetSharedRenderProcessToken(sharedRenderProcessToken);
33 
34     ViewStackProcessor::GetInstance()->Push(webComponent);
35 }
36 
Create(const std::string & src,std::function<void (int32_t)> && setWebIdCallback,std::function<void (const std::string &)> && setHapPathCallback,int32_t parentWebId,bool popup,RenderMode,bool incognitoMode,const std::string & sharedRenderProcessToken)37 void WebModelImpl::Create(const std::string& src, std::function<void(int32_t)>&& setWebIdCallback,
38     std::function<void(const std::string&)>&& setHapPathCallback, int32_t parentWebId, bool popup,
39     RenderMode /* renderMode */, bool incognitoMode, const std::string& sharedRenderProcessToken)
40 {
41     RefPtr<WebComponent> webComponent;
42     webComponent = AceType::MakeRefPtr<WebComponent>(src);
43     CHECK_NULL_VOID(webComponent);
44 
45     webComponent->SetSrc(src);
46     webComponent->SetPopup(popup);
47     webComponent->SetParentNWebId(parentWebId);
48     webComponent->SetSetWebIdCallback(std::move(setWebIdCallback));
49     webComponent->SetSetHapPathCallback(std::move(setHapPathCallback));
50     webComponent->SetIncognitoMode(incognitoMode);
51     webComponent->SetSharedRenderProcessToken(sharedRenderProcessToken);
52 
53     ViewStackProcessor::GetInstance()->Push(webComponent);
54 }
55 
SetCustomScheme(const std::string & cmdLine)56 void WebModelImpl::SetCustomScheme(const std::string& cmdLine)
57 {
58     if (!cmdLine.empty()) {
59         auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
60         CHECK_NULL_VOID(webComponent);
61         webComponent->SetCustomScheme(cmdLine);
62     }
63 }
64 
SetFocusable(bool focusable)65 void WebModelImpl::SetFocusable(bool focusable)
66 {
67     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
68     CHECK_NULL_VOID(webComponent);
69     ViewStackProcessor::GetInstance()->Push(webComponent);
70 
71     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent();
72     CHECK_NULL_VOID(focusableComponent);
73     focusableComponent->SetFocusable(focusable);
74 }
75 
SetFocusNode(bool isFocusNode)76 void WebModelImpl::SetFocusNode(bool isFocusNode)
77 {
78     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent();
79     CHECK_NULL_VOID(focusableComponent);
80     focusableComponent->SetFocusNode(isFocusNode);
81 }
82 
SetOnCommonDialog(std::function<bool (const BaseEventInfo * info)> && jsCallback,int dialogEventType)83 void WebModelImpl::SetOnCommonDialog(std::function<bool(const BaseEventInfo* info)>&& jsCallback, int dialogEventType)
84 {
85     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
86     CHECK_NULL_VOID(webComponent);
87     webComponent->SetOnCommonDialogImpl(std::move(jsCallback), static_cast<DialogEventType>(dialogEventType));
88 }
89 
SetOnConsoleLog(std::function<bool (const BaseEventInfo * info)> && jsCallback)90 void WebModelImpl::SetOnConsoleLog(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
91 {
92     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
93     CHECK_NULL_VOID(webComponent);
94     webComponent->SetOnConsoleImpl(std::move(jsCallback));
95 }
96 
SetOnPageStart(std::function<void (const BaseEventInfo * info)> && jsCallback)97 void WebModelImpl::SetOnPageStart(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->SetPageStartedEventId(eventMarker);
103 }
104 
SetOnPageFinish(std::function<void (const BaseEventInfo * info)> && jsCallback)105 void WebModelImpl::SetOnPageFinish(std::function<void(const BaseEventInfo* info)>&& jsCallback)
106 {
107     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
108     CHECK_NULL_VOID(webComponent);
109     auto eventMarker = EventMarker(std::move(jsCallback));
110     webComponent->SetPageFinishedEventId(eventMarker);
111 }
112 
SetOnProgressChange(std::function<void (const BaseEventInfo * info)> && jsCallback)113 void WebModelImpl::SetOnProgressChange(std::function<void(const BaseEventInfo* info)>&& jsCallback)
114 {
115     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
116     CHECK_NULL_VOID(webComponent);
117     webComponent->SetProgressChangeImpl(std::move(jsCallback));
118 }
119 
SetOnTitleReceive(std::function<void (const BaseEventInfo * info)> && jsCallback)120 void WebModelImpl::SetOnTitleReceive(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->SetTitleReceiveEventId(eventMarker);
126 }
127 
SetOnFullScreenExit(std::function<void (const BaseEventInfo * info)> && jsCallback)128 void WebModelImpl::SetOnFullScreenExit(std::function<void(const BaseEventInfo* info)>&& jsCallback)
129 {
130     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
131     CHECK_NULL_VOID(webComponent);
132     auto eventMarker = EventMarker(std::move(jsCallback));
133     webComponent->SetOnFullScreenExitEventId(eventMarker);
134 }
135 
SetOnFullScreenEnter(std::function<void (const BaseEventInfo * info)> && jsCallback)136 void WebModelImpl::SetOnFullScreenEnter(std::function<void(const BaseEventInfo* info)>&& jsCallback)
137 {
138     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
139     CHECK_NULL_VOID(webComponent);
140     webComponent->SetOnFullScreenEnterImpl(std::move(jsCallback));
141 }
142 
SetOnGeolocationHide(std::function<void (const BaseEventInfo * info)> && jsCallback)143 void WebModelImpl::SetOnGeolocationHide(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->SetGeolocationHideEventId(eventMarker);
149 }
150 
SetOnGeolocationShow(std::function<void (const BaseEventInfo * info)> && jsCallback)151 void WebModelImpl::SetOnGeolocationShow(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->SetGeolocationShowEventId(eventMarker);
157 }
158 
SetOnRequestFocus(std::function<void (const BaseEventInfo * info)> && jsCallback)159 void WebModelImpl::SetOnRequestFocus(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->SetRequestFocusEventId(eventMarker);
165 }
166 
SetOnDownloadStart(std::function<void (const BaseEventInfo * info)> && jsCallback)167 void WebModelImpl::SetOnDownloadStart(std::function<void(const BaseEventInfo* info)>&& jsCallback)
168 {
169     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
170     CHECK_NULL_VOID(webComponent);
171     auto eventMarker = EventMarker(std::move(jsCallback));
172     webComponent->SetDownloadStartEventId(eventMarker);
173 }
174 
SetOnHttpAuthRequest(std::function<bool (const BaseEventInfo * info)> && jsCallback)175 void WebModelImpl::SetOnHttpAuthRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
176 {
177     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
178     CHECK_NULL_VOID(webComponent);
179     webComponent->SetOnHttpAuthRequestImpl(std::move(jsCallback));
180 }
181 
SetOnSslErrorRequest(std::function<bool (const BaseEventInfo * info)> && jsCallback)182 void WebModelImpl::SetOnSslErrorRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
183 {
184     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
185     CHECK_NULL_VOID(webComponent);
186     webComponent->SetOnSslErrorRequestImpl(std::move(jsCallback));
187 }
188 
SetOnAllSslErrorRequest(std::function<bool (const BaseEventInfo * info)> && jsCallback)189 void WebModelImpl::SetOnAllSslErrorRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
190 {
191     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
192     CHECK_NULL_VOID(webComponent);
193     webComponent->SetOnAllSslErrorRequestImpl(std::move(jsCallback));
194 }
195 
SetOnSslSelectCertRequest(std::function<bool (const BaseEventInfo * info)> && jsCallback)196 void WebModelImpl::SetOnSslSelectCertRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
197 {
198     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
199     CHECK_NULL_VOID(webComponent);
200     webComponent->SetOnSslSelectCertRequestImpl(std::move(jsCallback));
201 }
202 
SetMediaPlayGestureAccess(bool isNeedGestureAccess)203 void WebModelImpl::SetMediaPlayGestureAccess(bool isNeedGestureAccess)
204 {
205     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
206     CHECK_NULL_VOID(webComponent);
207     webComponent->SetMediaPlayGestureAccess(isNeedGestureAccess);
208 }
209 
SetOnKeyEvent(std::function<void (KeyEventInfo & keyEventInfo)> && jsCallback)210 void WebModelImpl::SetOnKeyEvent(std::function<void(KeyEventInfo& keyEventInfo)>&& jsCallback)
211 {
212     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
213     CHECK_NULL_VOID(webComponent);
214     webComponent->SetOnKeyEventCallback(std::move(jsCallback));
215 }
216 
SetOnErrorReceive(std::function<void (const BaseEventInfo * info)> && jsCallback)217 void WebModelImpl::SetOnErrorReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback)
218 {
219     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
220     CHECK_NULL_VOID(webComponent);
221     auto eventMarker = EventMarker(std::move(jsCallback));
222 
223     webComponent->SetPageErrorEventId(eventMarker);
224 }
225 
SetOnHttpErrorReceive(std::function<void (const BaseEventInfo * info)> && jsCallback)226 void WebModelImpl::SetOnHttpErrorReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback)
227 {
228     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
229     CHECK_NULL_VOID(webComponent);
230     auto eventMarker = EventMarker(std::move(jsCallback));
231 
232     webComponent->SetHttpErrorEventId(eventMarker);
233 }
234 
SetOnInterceptRequest(std::function<RefPtr<WebResponse> (const BaseEventInfo * info)> && jsCallback)235 void WebModelImpl::SetOnInterceptRequest(std::function<RefPtr<WebResponse>(const BaseEventInfo* info)>&& jsCallback)
236 {
237     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
238     CHECK_NULL_VOID(webComponent);
239     webComponent->SetOnInterceptRequest(std::move(jsCallback));
240 }
241 
SetOnUrlLoadIntercept(std::function<bool (const BaseEventInfo * info)> && jsCallback)242 void WebModelImpl::SetOnUrlLoadIntercept(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
243 {
244     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
245     CHECK_NULL_VOID(webComponent);
246     webComponent->SetOnUrlLoadIntercept(std::move(jsCallback));
247 }
248 
SetOnLoadIntercept(std::function<bool (const BaseEventInfo * info)> && jsCallback)249 void WebModelImpl::SetOnLoadIntercept(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
250 {
251     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
252     CHECK_NULL_VOID(webComponent);
253     webComponent->SetOnLoadIntercept(std::move(jsCallback));
254 }
255 
SetOnFileSelectorShow(std::function<bool (const BaseEventInfo * info)> && jsCallback)256 void WebModelImpl::SetOnFileSelectorShow(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
257 {
258     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
259     CHECK_NULL_VOID(webComponent);
260     webComponent->SetOnFileSelectorShow(std::move(jsCallback));
261 }
262 
SetOnContextMenuShow(std::function<bool (const BaseEventInfo * info)> && jsCallback)263 void WebModelImpl::SetOnContextMenuShow(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
264 {
265     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
266     CHECK_NULL_VOID(webComponent);
267     webComponent->SetOnContextMenuShow(std::move(jsCallback));
268 }
269 
SetOnContextMenuHide(std::function<void (const BaseEventInfo * info)> && jsCallback)270 void WebModelImpl::SetOnContextMenuHide(std::function<void(const BaseEventInfo* info)>&& jsCallback)
271 {
272     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
273     CHECK_NULL_VOID(webComponent);
274     webComponent->SetOnContextMenuHide(std::move(jsCallback));
275 }
276 
SetJsEnabled(bool isJsEnabled)277 void WebModelImpl::SetJsEnabled(bool isJsEnabled)
278 {
279     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
280     CHECK_NULL_VOID(webComponent);
281     webComponent->SetJsEnabled(isJsEnabled);
282 }
283 
SetFileAccessEnabled(bool isJsEnabled)284 void WebModelImpl::SetFileAccessEnabled(bool isJsEnabled)
285 {
286     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
287     CHECK_NULL_VOID(webComponent);
288     webComponent->SetFileAccessEnabled(isJsEnabled);
289 }
290 
SetOnLineImageAccessEnabled(bool isOnLineImageAccessEnabled)291 void WebModelImpl::SetOnLineImageAccessEnabled(bool isOnLineImageAccessEnabled)
292 {
293     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
294     CHECK_NULL_VOID(webComponent);
295     webComponent->SetOnLineImageAccessEnabled(!isOnLineImageAccessEnabled);
296 }
297 
SetDomStorageAccessEnabled(bool isDomStorageAccessEnabled)298 void WebModelImpl::SetDomStorageAccessEnabled(bool isDomStorageAccessEnabled)
299 {
300     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
301     CHECK_NULL_VOID(webComponent);
302     webComponent->SetDomStorageAccessEnabled(isDomStorageAccessEnabled);
303 }
304 
SetImageAccessEnabled(bool isImageAccessEnabled)305 void WebModelImpl::SetImageAccessEnabled(bool isImageAccessEnabled)
306 {
307     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
308     CHECK_NULL_VOID(webComponent);
309     webComponent->SetImageAccessEnabled(isImageAccessEnabled);
310 }
311 
SetMixedMode(MixedModeContent mixedMode)312 void WebModelImpl::SetMixedMode(MixedModeContent mixedMode)
313 {
314     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
315     CHECK_NULL_VOID(webComponent);
316     webComponent->SetMixedMode(mixedMode);
317 }
318 
SetZoomAccessEnabled(bool isZoomAccessEnabled)319 void WebModelImpl::SetZoomAccessEnabled(bool isZoomAccessEnabled)
320 {
321     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
322     CHECK_NULL_VOID(webComponent);
323     webComponent->SetZoomAccessEnabled(isZoomAccessEnabled);
324 }
325 
SetGeolocationAccessEnabled(bool isGeolocationAccessEnabled)326 void WebModelImpl::SetGeolocationAccessEnabled(bool isGeolocationAccessEnabled)
327 {
328     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
329     CHECK_NULL_VOID(webComponent);
330     webComponent->SetGeolocationAccessEnabled(isGeolocationAccessEnabled);
331 }
332 
SetJsProxyCallback(std::function<void ()> && jsProxyCallback)333 void WebModelImpl::SetJsProxyCallback(std::function<void()>&& jsProxyCallback)
334 {
335     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
336     CHECK_NULL_VOID(webComponent);
337     webComponent->SetJsProxyCallback(std::move(jsProxyCallback));
338 }
339 
SetUserAgent(const std::string & userAgent)340 void WebModelImpl::SetUserAgent(const std::string& userAgent)
341 {
342     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
343     CHECK_NULL_VOID(webComponent);
344     webComponent->SetUserAgent(userAgent);
345 }
346 
SetRenderExitedId(std::function<void (const BaseEventInfo * info)> && jsCallback)347 void WebModelImpl::SetRenderExitedId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
348 {
349     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
350     CHECK_NULL_VOID(webComponent);
351     auto eventMarker = EventMarker(std::move(jsCallback));
352 
353     webComponent->SetRenderExitedId(eventMarker);
354 }
355 
SetRefreshAccessedHistoryId(std::function<void (const BaseEventInfo * info)> && jsCallback)356 void WebModelImpl::SetRefreshAccessedHistoryId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
357 {
358     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
359     CHECK_NULL_VOID(webComponent);
360     auto eventMarker = EventMarker(std::move(jsCallback));
361 
362     webComponent->SetRefreshAccessedHistoryId(eventMarker);
363 }
364 
SetCacheMode(WebCacheMode cacheMode)365 void WebModelImpl::SetCacheMode(WebCacheMode cacheMode)
366 {
367     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
368     CHECK_NULL_VOID(webComponent);
369     webComponent->SetCacheMode(cacheMode);
370 }
371 
SetOverScrollMode(OverScrollMode mode)372 void WebModelImpl::SetOverScrollMode(OverScrollMode mode)
373 {
374     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
375     CHECK_NULL_VOID(webComponent);
376     webComponent->SetOverScrollMode(mode);
377 }
378 
SetCopyOptionMode(CopyOptions mode)379 void WebModelImpl::SetCopyOptionMode(CopyOptions mode)
380 {
381     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
382     CHECK_NULL_VOID(webComponent);
383     webComponent->SetCopyOptionMode(mode);
384 }
385 
SetOverviewModeAccessEnabled(bool isOverviewModeAccessEnabled)386 void WebModelImpl::SetOverviewModeAccessEnabled(bool isOverviewModeAccessEnabled)
387 {
388     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
389     CHECK_NULL_VOID(webComponent);
390     webComponent->SetOverviewModeAccessEnabled(isOverviewModeAccessEnabled);
391 }
392 
SetFileFromUrlAccessEnabled(bool isFileFromUrlAccessEnabled)393 void WebModelImpl::SetFileFromUrlAccessEnabled(bool isFileFromUrlAccessEnabled)
394 {
395     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
396     CHECK_NULL_VOID(webComponent);
397     webComponent->SetFileFromUrlAccessEnabled(isFileFromUrlAccessEnabled);
398 }
399 
SetDatabaseAccessEnabled(bool isDatabaseAccessEnabled)400 void WebModelImpl::SetDatabaseAccessEnabled(bool isDatabaseAccessEnabled)
401 {
402     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
403     CHECK_NULL_VOID(webComponent);
404     webComponent->SetDatabaseAccessEnabled(isDatabaseAccessEnabled);
405 }
406 
SetTextZoomRatio(int32_t textZoomRatioNum)407 void WebModelImpl::SetTextZoomRatio(int32_t textZoomRatioNum)
408 {
409     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
410     CHECK_NULL_VOID(webComponent);
411     webComponent->SetTextZoomRatio(textZoomRatioNum);
412 }
413 
SetWebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled)414 void WebModelImpl::SetWebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled)
415 {
416     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
417     CHECK_NULL_VOID(webComponent);
418     webComponent->SetWebDebuggingAccessEnabled(isWebDebuggingAccessEnabled);
419 }
420 
SetOnMouseEvent(std::function<void (MouseInfo & info)> && jsCallback)421 void WebModelImpl::SetOnMouseEvent(std::function<void(MouseInfo& info)>&& jsCallback)
422 {
423     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
424     CHECK_NULL_VOID(webComponent);
425     webComponent->SetOnMouseEventCallback(std::move(jsCallback));
426 }
427 
SetResourceLoadId(std::function<void (const BaseEventInfo * info)> && jsCallback)428 void WebModelImpl::SetResourceLoadId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
429 {
430     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
431     CHECK_NULL_VOID(webComponent);
432     auto eventMarker = EventMarker(std::move(jsCallback));
433 
434     webComponent->SetResourceLoadId(eventMarker);
435 }
436 
SetScaleChangeId(std::function<void (const BaseEventInfo * info)> && jsCallback)437 void WebModelImpl::SetScaleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
438 {
439     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
440     CHECK_NULL_VOID(webComponent);
441     auto eventMarker = EventMarker(std::move(jsCallback));
442 
443     webComponent->SetScaleChangeId(eventMarker);
444 }
445 
SetScrollId(std::function<void (const BaseEventInfo * info)> && jsCallback)446 void WebModelImpl::SetScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
447 {
448     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
449     CHECK_NULL_VOID(webComponent);
450     auto eventMarker = EventMarker(std::move(jsCallback));
451 
452     webComponent->SetScrollId(eventMarker);
453 }
454 
SetPermissionRequestEventId(std::function<void (const BaseEventInfo * info)> && jsCallback)455 void WebModelImpl::SetPermissionRequestEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
456 {
457     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
458     CHECK_NULL_VOID(webComponent);
459     auto eventMarker = EventMarker(std::move(jsCallback));
460 
461     webComponent->SetPermissionRequestEventId(eventMarker);
462 }
463 
SetBackgroundColor(Color backgroundColor)464 void WebModelImpl::SetBackgroundColor(Color backgroundColor)
465 {
466     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
467     CHECK_NULL_VOID(webComponent);
468     webComponent->SetBackgroundColor(backgroundColor.GetValue());
469 }
470 
InitialScale(float scale)471 void WebModelImpl::InitialScale(float scale)
472 {
473     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
474     CHECK_NULL_VOID(webComponent);
475     webComponent->SetInitialScale(scale);
476 }
477 
SetSearchResultReceiveEventId(std::function<void (const BaseEventInfo * info)> && jsCallback)478 void WebModelImpl::SetSearchResultReceiveEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
479 {
480     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
481     CHECK_NULL_VOID(webComponent);
482     auto eventMarker = EventMarker(std::move(jsCallback));
483 
484     webComponent->SetSearchResultReceiveEventId(eventMarker);
485 }
486 
SetOnDragStart(std::function<NG::DragDropBaseInfo (const RefPtr<OHOS::Ace::DragEvent> & event,const std::string & extraParams)> && onDragStart)487 void WebModelImpl::SetOnDragStart(
488     std::function<NG::DragDropBaseInfo(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams)>&&
489         onDragStart)
490 {
491     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
492     CHECK_NULL_VOID(webComponent);
493     auto onDragStartId = [dragStartFunc = std::move(onDragStart)](
494                              const RefPtr<DragEvent>& event, const std::string& extraParams) -> DragItemInfo {
495         auto dragInfo = dragStartFunc(event, extraParams);
496         DragItemInfo info;
497         info.extraInfo = dragInfo.extraInfo;
498         info.pixelMap = dragInfo.pixelMap;
499         info.customComponent = AceType::DynamicCast<Component>(dragInfo.node);
500         return info;
501     };
502     webComponent->SetOnDragStartId(onDragStartId);
503 }
504 
SetOnDragEnter(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragStart)505 void WebModelImpl::SetOnDragEnter(
506     std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragStart)
507 {
508     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
509     CHECK_NULL_VOID(webComponent);
510     webComponent->SetOnDragEnterId(onDragStart);
511 }
512 
SetOnDragMove(std::function<void (const RefPtr<DragEvent> &,const std::string &)> && onDragMoveId)513 void WebModelImpl::SetOnDragMove(std::function<void(const RefPtr<DragEvent>&, const std::string&)>&& onDragMoveId)
514 {
515     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
516     CHECK_NULL_VOID(webComponent);
517     webComponent->SetOnDragMoveId(onDragMoveId);
518 }
519 
SetOnDragLeave(std::function<void (const RefPtr<DragEvent> &,const std::string &)> && onDragLeave)520 void WebModelImpl::SetOnDragLeave(std::function<void(const RefPtr<DragEvent>&, const std::string&)>&& onDragLeave)
521 {
522     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
523     CHECK_NULL_VOID(webComponent);
524     webComponent->SetOnDragLeaveId(onDragLeave);
525 }
526 
SetOnDrop(std::function<void (const RefPtr<DragEvent> &,const std::string &)> && onDropId)527 void WebModelImpl::SetOnDrop(std::function<void(const RefPtr<DragEvent>&, const std::string&)>&& onDropId)
528 {
529     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
530     CHECK_NULL_VOID(webComponent);
531     webComponent->SetOnDropId(onDropId);
532 }
533 
SetPinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)534 void WebModelImpl::SetPinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)
535 {
536     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
537     CHECK_NULL_VOID(webComponent);
538     webComponent->SetPinchSmoothModeEnabled(isPinchSmoothModeEnabled);
539 }
540 
SetWindowNewEvent(std::function<void (const std::shared_ptr<BaseEventInfo> & info)> && jsCallback)541 void WebModelImpl::SetWindowNewEvent(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& jsCallback)
542 {
543     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
544     CHECK_NULL_VOID(webComponent);
545     webComponent->SetWindowNewEvent(std::move(jsCallback));
546 }
547 
SetWindowExitEventId(std::function<void (const BaseEventInfo * info)> && jsCallback)548 void WebModelImpl::SetWindowExitEventId(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     webComponent->SetWindowExitEventId(eventMarker);
554 }
555 
SetMultiWindowAccessEnabled(bool isMultiWindowAccessEnable)556 void WebModelImpl::SetMultiWindowAccessEnabled(bool isMultiWindowAccessEnable)
557 {
558     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
559     CHECK_NULL_VOID(webComponent);
560     webComponent->SetMultiWindowAccessEnabled(isMultiWindowAccessEnable);
561 }
562 
SetAllowWindowOpenMethod(bool isAllowWindowOpenMethod)563 void WebModelImpl::SetAllowWindowOpenMethod(bool isAllowWindowOpenMethod)
564 {
565     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
566     CHECK_NULL_VOID(webComponent);
567     webComponent->SetAllowWindowOpenMethod(isAllowWindowOpenMethod);
568 }
569 
SetOnInterceptKeyEventCallback(std::function<bool (KeyEventInfo & keyEventInfo)> && keyEventInfo)570 void WebModelImpl::SetOnInterceptKeyEventCallback(std::function<bool(KeyEventInfo& keyEventInfo)>&& keyEventInfo)
571 {
572     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
573     CHECK_NULL_VOID(webComponent);
574     webComponent->SetOnInterceptKeyEventCallback(keyEventInfo);
575 }
576 
SetOverScrollId(std::function<void (const BaseEventInfo * info)> && jsCallback)577 void WebModelImpl::SetOverScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
578 {
579     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
580     CHECK_NULL_VOID(webComponent);
581     auto eventMarker = EventMarker(std::move(jsCallback));
582 
583     webComponent->SetOverScrollId(eventMarker);
584 }
585 
SetNativeEmbedModeEnabled(bool isEmbedModeEnabled)586 void WebModelImpl::SetNativeEmbedModeEnabled(bool isEmbedModeEnabled)
587 {
588     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
589     CHECK_NULL_VOID(webComponent);
590     webComponent->SetNativeEmbedModeEnabled(isEmbedModeEnabled);
591 }
592 
RegisterNativeEmbedRule(const std::string & tag,const std::string & type)593 void WebModelImpl::RegisterNativeEmbedRule(const std::string& tag, const std::string& type)
594 {
595     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
596     CHECK_NULL_VOID(webComponent);
597     webComponent->RegisterNativeEmbedRule(tag, type);
598 }
599 
SetNativeEmbedLifecycleChangeId(std::function<void (const BaseEventInfo * info)> && jsCallback)600 void WebModelImpl::SetNativeEmbedLifecycleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
601 {
602     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
603     CHECK_NULL_VOID(webComponent);
604     auto eventMarker = EventMarker(std::move(jsCallback));
605 
606     webComponent->SetNativeEmbedLifecycleChangeId(eventMarker);
607 }
608 
SetNativeEmbedVisibilityChangeId(std::function<void (const BaseEventInfo * info)> && jsCallback)609 void WebModelImpl::SetNativeEmbedVisibilityChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
610 {
611     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
612     CHECK_NULL_VOID(webComponent);
613     auto eventMarker = EventMarker(std::move(jsCallback));
614 
615     webComponent->SetNativeEmbedVisibilityChangeId(eventMarker);
616 }
617 
SetNativeEmbedGestureEventId(std::function<void (const BaseEventInfo * info)> && jsCallback)618 void WebModelImpl::SetNativeEmbedGestureEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
619 {
620     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
621     CHECK_NULL_VOID(webComponent);
622     auto eventMarker = EventMarker(std::move(jsCallback));
623 
624     webComponent->SetNativeEmbedGestureEventId(eventMarker);
625 }
626 
SetOnOverrideUrlLoading(std::function<bool (const BaseEventInfo * info)> && jsCallback)627 void WebModelImpl::SetOnOverrideUrlLoading(std::function<bool(const BaseEventInfo* info)>&& jsCallback)
628 {
629     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
630     CHECK_NULL_VOID(webComponent);
631     webComponent->SetOnOverrideUrlLoading(std::move(jsCallback));
632 }
633 
SetNativeVideoPlayerConfig(bool enable,bool shouldOverlay)634 void WebModelImpl::SetNativeVideoPlayerConfig(bool enable, bool shouldOverlay)
635 {
636     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
637     CHECK_NULL_VOID(webComponent);
638     webComponent->SetNativeVideoPlayerConfig(enable, shouldOverlay);
639 }
640 
SetRenderProcessNotRespondingId(std::function<void (const BaseEventInfo * info)> && jsCallback)641 void WebModelImpl::SetRenderProcessNotRespondingId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
642 {
643     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
644     CHECK_NULL_VOID(webComponent);
645     auto eventMarker = EventMarker(std::move(jsCallback));
646 
647     webComponent->SetRenderProcessNotRespondingId(eventMarker);
648 }
649 
SetRenderProcessRespondingId(std::function<void (const BaseEventInfo * info)> && jsCallback)650 void WebModelImpl::SetRenderProcessRespondingId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
651 {
652     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
653     CHECK_NULL_VOID(webComponent);
654     auto eventMarker = EventMarker(std::move(jsCallback));
655 
656     webComponent->SetRenderProcessRespondingId(eventMarker);
657 }
658 
SetViewportFitChangedId(std::function<void (const BaseEventInfo * info)> && jsCallback)659 void WebModelImpl::SetViewportFitChangedId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
660 {
661     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
662     CHECK_NULL_VOID(webComponent);
663     auto eventMarker = EventMarker(std::move(jsCallback));
664 
665     webComponent->SetViewportFitChangedId(eventMarker);
666 }
667 
SetAdsBlockedEventId(std::function<void (const BaseEventInfo * info)> && jsCallback)668 void WebModelImpl::SetAdsBlockedEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
669 {
670     auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
671     CHECK_NULL_VOID(webComponent);
672     auto eventMarker = EventMarker(std::move(jsCallback));
673 
674     webComponent->SetAdsBlockedEventId(eventMarker);
675 }
676 
SetUpdateInstanceIdCallback(std::function<void (int32_t)> && callback)677 void WebModelImpl::SetUpdateInstanceIdCallback(std::function<void(int32_t)>&& callback)
678 {
679 }
680 } // namespace OHOS::Ace::Framework
681