• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "core/components_ng/pattern/web/web_view.h"
17 
18 #include "base/memory/ace_type.h"
19 #include "base/utils/utils.h"
20 #include "core/components_ng/base/view_abstract.h"
21 #include "core/components_ng/base/view_stack_processor.h"
22 #include "core/components_ng/pattern/web/web_event_hub.h"
23 #include "core/components_ng/pattern/web/web_pattern.h"
24 #include "core/components_v2/inspector/inspector_constants.h"
25 #include "core/pipeline_ng/pipeline_context.h"
26 #include "nweb_helper.h"
27 
28 namespace OHOS::Ace::NG {
Create(const std::string & webData)29 void WebView::Create(const std::string& webData)
30 {
31     auto* stack = ViewStackProcessor::GetInstance();
32     auto nodeId = stack->ClaimNodeId();
33     auto frameNode =
34         FrameNode::GetOrCreateFrameNode(V2::WEB_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<WebPattern>(); });
35     stack->Push(frameNode);
36 
37     auto webPattern = frameNode->GetPattern<WebPattern>();
38     CHECK_NULL_VOID(webPattern);
39     webPattern->SetWebData(webData);
40     RegisterPipelineCallback(nodeId);
41 }
42 
Create(const std::string & src,const RefPtr<WebController> & webController)43 void WebView::Create(const std::string& src, const RefPtr<WebController>& webController)
44 {
45     auto* stack = ViewStackProcessor::GetInstance();
46     auto nodeId = stack->ClaimNodeId();
47     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::WEB_ETS_TAG, nodeId,
48         [src, webController]() { return AceType::MakeRefPtr<WebPattern>(src, webController); });
49     stack->Push(frameNode);
50 
51     auto webPattern = frameNode->GetPattern<WebPattern>();
52     CHECK_NULL_VOID(webPattern);
53     webPattern->SetWebSrc(src);
54     webPattern->SetWebController(webController);
55     RegisterPipelineCallback(nodeId);
56 }
57 
Create(const std::string & src,SetWebIdCallback && setWebIdCallback,int32_t parentWebId,bool popup)58 void WebView::Create(const std::string& src, SetWebIdCallback&& setWebIdCallback,
59     int32_t parentWebId, bool popup)
60 {
61     auto* stack = ViewStackProcessor::GetInstance();
62     auto nodeId = stack->ClaimNodeId();
63     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::WEB_ETS_TAG, nodeId,
64         [src, setWebIdCallback]() { return AceType::MakeRefPtr<WebPattern>(src, std::move(setWebIdCallback)); });
65     stack->Push(frameNode);
66     auto webPattern = frameNode->GetPattern<WebPattern>();
67     CHECK_NULL_VOID(webPattern);
68     webPattern->SetWebSrc(src);
69     webPattern->SetPopup(popup);
70     webPattern->SetSetWebIdCallback(std::move(setWebIdCallback));
71     webPattern->SetParentNWebId(parentWebId);
72     RegisterPipelineCallback(nodeId);
73 }
74 
RegisterPipelineCallback(int32_t nodeId)75 void WebView::RegisterPipelineCallback(int32_t nodeId)
76 {
77     auto pipeline = NG::PipelineContext::GetCurrentContext();
78     CHECK_NULL_VOID(pipeline);
79     pipeline->AddWindowStateChangedCallback(nodeId);
80 }
81 
SetOnCommonDialogImpl(OnWebSyncFunc && onCommonDialogImpl,DialogEventType dialogEventType)82 void WebView::SetOnCommonDialogImpl(OnWebSyncFunc&& onCommonDialogImpl, DialogEventType dialogEventType)
83 {
84     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
85     CHECK_NULL_VOID(webEventHub);
86     webEventHub->SetOnCommonDialogEvent(std::move(onCommonDialogImpl), dialogEventType);
87 }
88 
SetOnPageStart(OnWebAsyncFunc && OnPageStart)89 void WebView::SetOnPageStart(OnWebAsyncFunc&& OnPageStart)
90 {
91     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
92     CHECK_NULL_VOID(webEventHub);
93     webEventHub->SetOnPageStartedEvent(std::move(OnPageStart));
94 }
95 
SetOnPageFinish(OnWebAsyncFunc && onPageEnd)96 void WebView::SetOnPageFinish(OnWebAsyncFunc&& onPageEnd)
97 {
98     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
99     CHECK_NULL_VOID(webEventHub);
100     webEventHub->SetOnPageFinishedEvent(std::move(onPageEnd));
101 }
102 
SetOnHttpErrorReceive(OnWebAsyncFunc && onHttpErrorReceive)103 void WebView::SetOnHttpErrorReceive(OnWebAsyncFunc&& onHttpErrorReceive)
104 {
105     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
106     CHECK_NULL_VOID(webEventHub);
107     webEventHub->SetOnHttpErrorReceiveEvent(std::move(onHttpErrorReceive));
108 }
109 
SetOnErrorReceive(OnWebAsyncFunc && onErrorReceive)110 void WebView::SetOnErrorReceive(OnWebAsyncFunc&& onErrorReceive)
111 {
112     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
113     CHECK_NULL_VOID(webEventHub);
114     webEventHub->SetOnErrorReceiveEvent(std::move(onErrorReceive));
115 }
116 
SetOnConsole(OnWebSyncFunc && onConsole)117 void WebView::SetOnConsole(OnWebSyncFunc&& onConsole)
118 {
119     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
120     CHECK_NULL_VOID(webEventHub);
121     webEventHub->SetOnConsoleEvent(std::move(onConsole));
122 }
123 
SetJsEnabled(bool isJsEnabled)124 void WebView::SetJsEnabled(bool isJsEnabled)
125 {
126     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
127     CHECK_NULL_VOID(webPattern);
128     webPattern->UpdateJsEnabled(isJsEnabled);
129 }
130 
SetProgressChangeImpl(OnWebAsyncFunc && onProgressChangeImpl)131 void WebView::SetProgressChangeImpl(OnWebAsyncFunc&& onProgressChangeImpl)
132 {
133     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
134     CHECK_NULL_VOID(webEventHub);
135     webEventHub->SetOnProgressChangeEvent(std::move(onProgressChangeImpl));
136 }
137 
SetTitleReceiveEventId(OnWebAsyncFunc && titleReceiveEventId)138 void WebView::SetTitleReceiveEventId(OnWebAsyncFunc&& titleReceiveEventId)
139 {
140     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
141     CHECK_NULL_VOID(webEventHub);
142     webEventHub->SetOnTitleReceiveEvent(std::move(titleReceiveEventId));
143 }
144 
SetFullScreenExitEventId(OnWebAsyncFunc && fullScreenExitEventId)145 void WebView::SetFullScreenExitEventId(OnWebAsyncFunc&& fullScreenExitEventId)
146 {
147     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
148     CHECK_NULL_VOID(webEventHub);
149     webEventHub->SetOnFullScreenExitEvent(std::move(fullScreenExitEventId));
150 }
151 
SetGeolocationHideEventId(OnWebAsyncFunc && geolocationHideEventId)152 void WebView::SetGeolocationHideEventId(OnWebAsyncFunc&& geolocationHideEventId)
153 {
154     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
155     CHECK_NULL_VOID(webEventHub);
156     webEventHub->SetOnGeolocationHideEvent(std::move(geolocationHideEventId));
157 }
158 
SetGeolocationShowEventId(OnWebAsyncFunc && geolocationShowEventId)159 void WebView::SetGeolocationShowEventId(OnWebAsyncFunc&& geolocationShowEventId)
160 {
161     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
162     CHECK_NULL_VOID(webEventHub);
163     webEventHub->SetOnGeolocationShowEvent(std::move(geolocationShowEventId));
164 }
165 
SetRequestFocusEventId(OnWebAsyncFunc && requestFocusEventId)166 void WebView::SetRequestFocusEventId(OnWebAsyncFunc&& requestFocusEventId)
167 {
168     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
169     CHECK_NULL_VOID(webEventHub);
170     webEventHub->SetOnRequestFocusEvent(std::move(requestFocusEventId));
171 }
172 
SetDownloadStartEventId(OnWebAsyncFunc && downloadStartEventId)173 void WebView::SetDownloadStartEventId(OnWebAsyncFunc&& downloadStartEventId)
174 {
175     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
176     CHECK_NULL_VOID(webEventHub);
177     webEventHub->SetOnDownloadStartEvent(std::move(downloadStartEventId));
178 }
179 
SetOnFullScreenEnterImpl(OnWebAsyncFunc && onFullScreenEnterImpl)180 void WebView::SetOnFullScreenEnterImpl(OnWebAsyncFunc&& onFullScreenEnterImpl)
181 {
182     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
183     CHECK_NULL_VOID(webEventHub);
184     webEventHub->SetOnFullScreenEnterEvent(std::move(onFullScreenEnterImpl));
185 }
186 
SetOnHttpAuthRequestImpl(OnWebSyncFunc && onHttpAuthRequestImpl)187 void WebView::SetOnHttpAuthRequestImpl(OnWebSyncFunc&& onHttpAuthRequestImpl)
188 {
189     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
190     CHECK_NULL_VOID(webEventHub);
191     webEventHub->SetOnHttpAuthRequestEvent(std::move(onHttpAuthRequestImpl));
192 }
193 
SetOnSslErrorRequestImpl(OnWebSyncFunc && onSslErrorRequestImpl)194 void WebView::SetOnSslErrorRequestImpl(OnWebSyncFunc&& onSslErrorRequestImpl)
195 {
196     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
197     CHECK_NULL_VOID(webEventHub);
198     webEventHub->SetOnSslErrorRequestEvent(std::move(onSslErrorRequestImpl));
199 }
200 
SetOnSslSelectCertRequestImpl(OnWebSyncFunc && onSslSelectCertRequestImpl)201 void WebView::SetOnSslSelectCertRequestImpl(OnWebSyncFunc&& onSslSelectCertRequestImpl)
202 {
203     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
204     CHECK_NULL_VOID(webEventHub);
205     webEventHub->SetOnSslSelectCertRequestEvent(std::move(onSslSelectCertRequestImpl));
206 }
207 
SetMediaPlayGestureAccess(bool isNeedGestureAccess)208 void WebView::SetMediaPlayGestureAccess(bool isNeedGestureAccess)
209 {
210     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
211     CHECK_NULL_VOID(webPattern);
212     webPattern->UpdateMediaPlayGestureAccess(isNeedGestureAccess);
213 }
214 
SetOnKeyEventCallback(std::function<void (KeyEventInfo & keyEventInfo)> && onKeyEventId)215 void WebView::SetOnKeyEventCallback(std::function<void(KeyEventInfo& keyEventInfo)>&& onKeyEventId)
216 {
217     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
218     CHECK_NULL_VOID(webEventHub);
219     webEventHub->SetOnKeyEvent(std::move(onKeyEventId));
220 }
221 
SetOnInterceptRequest(std::function<RefPtr<WebResponse> (const std::shared_ptr<BaseEventInfo> & info)> && onInterceptRequestImpl)222 void WebView::SetOnInterceptRequest(
223     std::function<RefPtr<WebResponse>(const std::shared_ptr<BaseEventInfo>& info)>&& onInterceptRequestImpl)
224 {
225     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
226     CHECK_NULL_VOID(webEventHub);
227     webEventHub->SetOnInterceptRequestEvent(std::move(onInterceptRequestImpl));
228 }
229 
SetOnUrlLoadIntercept(OnWebSyncFunc && onUrlLoadInterceptImpl)230 void WebView::SetOnUrlLoadIntercept(OnWebSyncFunc&& onUrlLoadInterceptImpl)
231 {
232     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
233     CHECK_NULL_VOID(webEventHub);
234     webEventHub->SetOnUrlLoadInterceptEvent(std::move(onUrlLoadInterceptImpl));
235 }
236 
SetOnFileSelectorShow(OnWebSyncFunc && onFileSelectorShowImpl)237 void WebView::SetOnFileSelectorShow(OnWebSyncFunc&& onFileSelectorShowImpl)
238 {
239     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
240     CHECK_NULL_VOID(webEventHub);
241     webEventHub->SetOnFileSelectorShowEvent(std::move(onFileSelectorShowImpl));
242 }
243 
SetOnContextMenuShow(OnWebSyncFunc && onContextMenuImpl)244 void WebView::SetOnContextMenuShow(OnWebSyncFunc&& onContextMenuImpl)
245 {
246     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
247     CHECK_NULL_VOID(webEventHub);
248     webEventHub->SetOnContextMenuShowEvent(std::move(onContextMenuImpl));
249 }
250 
SetFileAccessEnabled(bool isFileAccessEnabled)251 void WebView::SetFileAccessEnabled(bool isFileAccessEnabled)
252 {
253     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
254     CHECK_NULL_VOID(webPattern);
255     webPattern->UpdateFileAccessEnabled(isFileAccessEnabled);
256 }
257 
SetOnLineImageAccessEnabled(bool isOnLineImageAccessEnabled)258 void WebView::SetOnLineImageAccessEnabled(bool isOnLineImageAccessEnabled)
259 {
260     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
261     CHECK_NULL_VOID(webPattern);
262     webPattern->UpdateOnLineImageAccessEnabled(isOnLineImageAccessEnabled);
263 }
264 
SetDomStorageAccessEnabled(bool isDomStorageAccessEnabled)265 void WebView::SetDomStorageAccessEnabled(bool isDomStorageAccessEnabled)
266 {
267     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
268     CHECK_NULL_VOID(webPattern);
269     webPattern->UpdateDomStorageAccessEnabled(isDomStorageAccessEnabled);
270 }
271 
SetImageAccessEnabled(bool isImageAccessEnabled)272 void WebView::SetImageAccessEnabled(bool isImageAccessEnabled)
273 {
274     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
275     CHECK_NULL_VOID(webPattern);
276     webPattern->UpdateImageAccessEnabled(isImageAccessEnabled);
277 }
278 
SetMixedMode(MixedModeContent mixedContentMode)279 void WebView::SetMixedMode(MixedModeContent mixedContentMode)
280 {
281     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
282     CHECK_NULL_VOID(webPattern);
283     webPattern->UpdateMixedMode(mixedContentMode);
284 }
285 
SetZoomAccessEnabled(bool isZoomAccessEnabled)286 void WebView::SetZoomAccessEnabled(bool isZoomAccessEnabled)
287 {
288     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
289     CHECK_NULL_VOID(webPattern);
290     webPattern->UpdateZoomAccessEnabled(isZoomAccessEnabled);
291 }
292 
SetGeolocationAccessEnabled(bool isGeolocationAccessEnabled)293 void WebView::SetGeolocationAccessEnabled(bool isGeolocationAccessEnabled)
294 {
295     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
296     CHECK_NULL_VOID(webPattern);
297     webPattern->UpdateGeolocationAccessEnabled(isGeolocationAccessEnabled);
298 }
299 
SetUserAgent(const std::string & userAgent)300 void WebView::SetUserAgent(const std::string& userAgent)
301 {
302     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
303     CHECK_NULL_VOID(webPattern);
304     webPattern->UpdateUserAgent(userAgent);
305 }
306 
SetCustomScheme(const std::string & customScheme)307 void WebView::SetCustomScheme(const std::string& customScheme)
308 {
309     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
310     CHECK_NULL_VOID(webPattern);
311     webPattern->SetCustomScheme(customScheme);
312 }
313 
SetRenderExitedId(OnWebAsyncFunc && renderExitedId)314 void WebView::SetRenderExitedId(OnWebAsyncFunc&& renderExitedId)
315 {
316     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
317     CHECK_NULL_VOID(webEventHub);
318     webEventHub->SetOnRenderExitedEvent(std::move(renderExitedId));
319 }
320 
SetRefreshAccessedHistoryId(OnWebAsyncFunc && refreshAccessedHistoryId)321 void WebView::SetRefreshAccessedHistoryId(OnWebAsyncFunc&& refreshAccessedHistoryId)
322 {
323     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
324     CHECK_NULL_VOID(webEventHub);
325     webEventHub->SetOnRefreshAccessedHistoryEvent(std::move(refreshAccessedHistoryId));
326 }
327 
SetCacheMode(WebCacheMode mode)328 void WebView::SetCacheMode(WebCacheMode mode)
329 {
330     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
331     CHECK_NULL_VOID(webPattern);
332     webPattern->UpdateCacheMode(mode);
333 }
334 
SetOverviewModeAccessEnabled(bool isOverviewModeAccessEnabled)335 void WebView::SetOverviewModeAccessEnabled(bool isOverviewModeAccessEnabled)
336 {
337     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
338     CHECK_NULL_VOID(webPattern);
339     webPattern->UpdateOverviewModeAccessEnabled(isOverviewModeAccessEnabled);
340 }
341 
SetFileFromUrlAccessEnabled(bool isFileFromUrlAccessEnabled)342 void WebView::SetFileFromUrlAccessEnabled(bool isFileFromUrlAccessEnabled)
343 {
344     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
345     CHECK_NULL_VOID(webPattern);
346     webPattern->UpdateFileFromUrlAccessEnabled(isFileFromUrlAccessEnabled);
347 }
348 
SetDatabaseAccessEnabled(bool isDatabaseAccessEnabled)349 void WebView::SetDatabaseAccessEnabled(bool isDatabaseAccessEnabled)
350 {
351     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
352     CHECK_NULL_VOID(webPattern);
353     webPattern->UpdateDatabaseAccessEnabled(isDatabaseAccessEnabled);
354 }
355 
SetTextZoomRatio(int32_t textZoomRatioNum)356 void WebView::SetTextZoomRatio(int32_t textZoomRatioNum)
357 {
358     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
359     CHECK_NULL_VOID(webPattern);
360     webPattern->UpdateTextZoomRatio(textZoomRatioNum);
361 }
362 
SetWebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled)363 void WebView::SetWebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled)
364 {
365     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
366     CHECK_NULL_VOID(webPattern);
367     webPattern->UpdateWebDebuggingAccessEnabled(isWebDebuggingAccessEnabled);
368 }
369 
SetOnMouseEventCallback(std::function<void (MouseInfo & info)> && onMouseId)370 void WebView::SetOnMouseEventCallback(std::function<void(MouseInfo& info)>&& onMouseId)
371 {
372     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
373     CHECK_NULL_VOID(webEventHub);
374     webEventHub->SetOnMouseEvent(std::move(onMouseId));
375 }
376 
SetResourceLoadId(OnWebAsyncFunc && resourceLoadId)377 void WebView::SetResourceLoadId(OnWebAsyncFunc&& resourceLoadId)
378 {
379     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
380     CHECK_NULL_VOID(webEventHub);
381     webEventHub->SetOnResourceLoadEvent(std::move(resourceLoadId));
382 }
383 
SetScaleChangeId(OnWebAsyncFunc && scaleChangeId)384 void WebView::SetScaleChangeId(OnWebAsyncFunc&& scaleChangeId)
385 {
386     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
387     CHECK_NULL_VOID(webEventHub);
388     webEventHub->SetOnScaleChangeEvent(std::move(scaleChangeId));
389 }
390 
SetScrollId(OnWebAsyncFunc && scrollId)391 void WebView::SetScrollId(OnWebAsyncFunc&& scrollId)
392 {
393     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
394     CHECK_NULL_VOID(webEventHub);
395     webEventHub->SetOnScrollEvent(std::move(scrollId));
396 }
397 
SetPermissionRequestEventId(OnWebAsyncFunc && permissionRequestEventId)398 void WebView::SetPermissionRequestEventId(OnWebAsyncFunc&& permissionRequestEventId)
399 {
400     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
401     CHECK_NULL_VOID(webEventHub);
402     webEventHub->SetOnPermissionRequestEvent(std::move(permissionRequestEventId));
403 }
404 
SetBackgroundColor(int32_t backgroundColor)405 void WebView::SetBackgroundColor(int32_t backgroundColor)
406 {
407     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
408     CHECK_NULL_VOID(webPattern);
409     webPattern->UpdateBackgroundColor(backgroundColor);
410 }
411 
SetInitialScale(float scale)412 void WebView::SetInitialScale(float scale)
413 {
414     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
415     CHECK_NULL_VOID(webPattern);
416     webPattern->UpdateInitialScale(scale);
417 }
418 
SetSearchResultReceiveEventId(OnWebAsyncFunc && searchResultReceiveEventId)419 void WebView::SetSearchResultReceiveEventId(OnWebAsyncFunc&& searchResultReceiveEventId)
420 {
421     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
422     CHECK_NULL_VOID(webEventHub);
423     webEventHub->SetOnSearchResultReceiveEvent(std::move(searchResultReceiveEventId));
424 }
425 
SetPinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)426 void WebView::SetPinchSmoothModeEnabled(bool isPinchSmoothModeEnabled)
427 {
428     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
429     CHECK_NULL_VOID(webPattern);
430     webPattern->UpdatePinchSmoothModeEnabled(isPinchSmoothModeEnabled);
431 }
432 
SetWindowNewEvent(OnWebAsyncFunc && windowNewEventId)433 void WebView::SetWindowNewEvent(OnWebAsyncFunc&& windowNewEventId)
434 {
435     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
436     CHECK_NULL_VOID(webEventHub);
437     webEventHub->SetOnWindowNewEvent(std::move(windowNewEventId));
438 }
439 
SetWindowExitEventId(OnWebAsyncFunc && windowExitEventId)440 void WebView::SetWindowExitEventId(OnWebAsyncFunc&& windowExitEventId)
441 {
442     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
443     CHECK_NULL_VOID(webEventHub);
444     webEventHub->SetOnWindowExitEvent(std::move(windowExitEventId));
445 }
446 
SetMultiWindowAccessEnabled(bool isMultiWindowAccessEnabled)447 void WebView::SetMultiWindowAccessEnabled(bool isMultiWindowAccessEnabled)
448 {
449     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
450     CHECK_NULL_VOID(webPattern);
451     webPattern->UpdateMultiWindowAccessEnabled(isMultiWindowAccessEnabled);
452 }
453 
SetJsProxyCallback(JsProxyCallback && jsProxyCallback)454 void WebView::SetJsProxyCallback(JsProxyCallback&& jsProxyCallback)
455 {
456     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
457     CHECK_NULL_VOID(webPattern);
458     webPattern->SetJsProxyCallback(std::move(jsProxyCallback));
459 }
460 
SetWebCursiveFont(const std::string & cursiveFontFamily)461 void WebView::SetWebCursiveFont(const std::string& cursiveFontFamily)
462 {
463     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
464     CHECK_NULL_VOID(webPattern);
465     webPattern->UpdateWebCursiveFont(cursiveFontFamily);
466 }
467 
SetWebFantasyFont(const std::string & fantasyFontFamily)468 void WebView::SetWebFantasyFont(const std::string& fantasyFontFamily)
469 {
470     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
471     CHECK_NULL_VOID(webPattern);
472     webPattern->UpdateWebFantasyFont(fantasyFontFamily);
473 }
474 
SetWebFixedFont(const std::string & fixedFontFamily)475 void WebView::SetWebFixedFont(const std::string& fixedFontFamily)
476 {
477     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
478     CHECK_NULL_VOID(webPattern);
479     webPattern->UpdateWebFixedFont(fixedFontFamily);
480 }
481 
SetWebSansSerifFont(const std::string & sansSerifFontFamily)482 void WebView::SetWebSansSerifFont(const std::string& sansSerifFontFamily)
483 {
484     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
485     CHECK_NULL_VOID(webPattern);
486     webPattern->UpdateWebSansSerifFont(sansSerifFontFamily);
487 }
488 
SetWebSerifFont(const std::string & serifFontFamily)489 void WebView::SetWebSerifFont(const std::string& serifFontFamily)
490 {
491     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
492     CHECK_NULL_VOID(webPattern);
493     webPattern->UpdateWebSerifFont(serifFontFamily);
494 }
495 
SetWebStandardFont(const std::string & standardFontFamily)496 void WebView::SetWebStandardFont(const std::string& standardFontFamily)
497 {
498     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
499     CHECK_NULL_VOID(webPattern);
500     webPattern->UpdateWebStandardFont(standardFontFamily);
501 }
502 
SetDefaultFixedFontSize(int32_t defaultFixedFontSize)503 void WebView::SetDefaultFixedFontSize(int32_t defaultFixedFontSize)
504 {
505     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
506     CHECK_NULL_VOID(webPattern);
507     webPattern->UpdateDefaultFixedFontSize(defaultFixedFontSize);
508 }
509 
SetDefaultFontSize(int32_t defaultFontSize)510 void WebView::SetDefaultFontSize(int32_t defaultFontSize)
511 {
512     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
513     CHECK_NULL_VOID(webPattern);
514     webPattern->UpdateDefaultFontSize(defaultFontSize);
515 }
516 
SetMinFontSize(int32_t minFontSize)517 void WebView::SetMinFontSize(int32_t minFontSize)
518 {
519     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
520     CHECK_NULL_VOID(webPattern);
521     webPattern->UpdateMinFontSize(minFontSize);
522 }
523 
SetMinLogicalFontSize(int32_t minLogicalFontSize)524 void WebView::SetMinLogicalFontSize(int32_t minLogicalFontSize)
525 {
526     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
527     CHECK_NULL_VOID(webPattern);
528     webPattern->UpdateMinLogicalFontSize(minLogicalFontSize);
529 }
530 
SetBlockNetwork(bool isNetworkBlocked)531 void WebView::SetBlockNetwork(bool isNetworkBlocked)
532 {
533     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
534     CHECK_NULL_VOID(webPattern);
535     webPattern->UpdateBlockNetwork(isNetworkBlocked);
536 }
537 
SetHorizontalScrollBarAccessEnabled(bool isHorizontalScrollBarAccessEnabled)538 void WebView::SetHorizontalScrollBarAccessEnabled(bool isHorizontalScrollBarAccessEnabled)
539 {
540     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
541     CHECK_NULL_VOID(webPattern);
542     webPattern->UpdateHorizontalScrollBarAccessEnabled(isHorizontalScrollBarAccessEnabled);
543 }
544 
SetVerticalScrollBarAccessEnabled(bool isVerticalScrollBarAccessEnabled)545 void WebView::SetVerticalScrollBarAccessEnabled(bool isVerticalScrollBarAccessEnabled)
546 {
547     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
548     CHECK_NULL_VOID(webPattern);
549     webPattern->UpdateVerticalScrollBarAccessEnabled(isVerticalScrollBarAccessEnabled);
550 }
551 
SetPageVisibleId(OnWebAsyncFunc && pageVisibleId)552 void WebView::SetPageVisibleId(OnWebAsyncFunc&& pageVisibleId)
553 {
554     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
555     CHECK_NULL_VOID(webEventHub);
556     webEventHub->SetOnPageVisibleEvent(std::move(pageVisibleId));
557 }
558 
SetOnInterceptKeyEventCallback(std::function<bool (KeyEventInfo & keyEventInfo)> && onPreKeyEventId)559 void WebView::SetOnInterceptKeyEventCallback(std::function<bool(KeyEventInfo& keyEventInfo)>&& onPreKeyEventId)
560 {
561     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
562     CHECK_NULL_VOID(webEventHub);
563     webEventHub->SetOnPreKeyEvent(std::move(onPreKeyEventId));
564 }
565 
SetDataResubmittedId(OnWebAsyncFunc && dataResubmittedId)566 void WebView::SetDataResubmittedId(OnWebAsyncFunc&& dataResubmittedId)
567 {
568     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
569     CHECK_NULL_VOID(webEventHub);
570     webEventHub->SetOnDataResubmittedEvent(std::move(dataResubmittedId));
571 }
572 
SetFaviconReceivedId(OnWebAsyncFunc && faviconReceivedId)573 void WebView::SetFaviconReceivedId(OnWebAsyncFunc&& faviconReceivedId)
574 {
575     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
576     CHECK_NULL_VOID(webEventHub);
577     webEventHub->SetOnFaviconReceivedEvent(std::move(faviconReceivedId));
578 }
579 
SetTouchIconUrlId(OnWebAsyncFunc && touchIconUrlId)580 void WebView::SetTouchIconUrlId(OnWebAsyncFunc&& touchIconUrlId)
581 {
582     auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
583     CHECK_NULL_VOID(webEventHub);
584     webEventHub->SetOnTouchIconUrlEvent(std::move(touchIconUrlId));
585 }
586 
SetDarkMode(WebDarkMode mode)587 void WebView::SetDarkMode(WebDarkMode mode)
588 {
589     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
590     CHECK_NULL_VOID(webPattern);
591     webPattern->UpdateDarkMode(mode);
592 }
593 
SetForceDarkAccess(bool access)594 void WebView::SetForceDarkAccess(bool access)
595 {
596     auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
597     CHECK_NULL_VOID(webPattern);
598     webPattern->UpdateForceDarkAccess(access);
599 }
600 
NotifyPopupWindowResult(int32_t webId,bool result)601 void WebView::NotifyPopupWindowResult(int32_t webId, bool result)
602 {
603     if (webId != -1) {
604         std::weak_ptr<OHOS::NWeb::NWeb> nwebWeak = OHOS::NWeb::NWebHelper::Instance().GetNWeb(webId);
605         auto nwebSptr = nwebWeak.lock();
606         if (nwebSptr) {
607             nwebSptr->NotifyPopupWindowResult(result);
608         }
609     }
610 }
611 } // namespace OHOS::Ace::NG
612