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