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