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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WEB_WEB_MODEL_NG_H 16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WEB_WEB_MODEL_NG_H 17 18 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) 19 #include "base/web/webview/ohos_nweb/include/nweb_helper.h" 20 #endif 21 #include "core/components_ng/base/view_abstract.h" 22 #include "core/components_ng/base/view_stack_processor.h" 23 #include "core/components_ng/pattern/web/web_model.h" 24 25 namespace OHOS::Ace::NG { 26 using OnWebSyncFunc = std::function<bool(const std::shared_ptr<BaseEventInfo>& info)>; 27 using OnWebAsyncFunc = std::function<void(const std::shared_ptr<BaseEventInfo>& info)>; 28 using SetWebIdCallback = std::function<void(int32_t)>; 29 using SetHapPathCallback = std::function<void(const std::string&)>; 30 using JsProxyCallback = std::function<void()>; 31 32 class ACE_EXPORT WebModelNG : public OHOS::Ace::WebModel { 33 public: 34 void Create(const std::string& src, const RefPtr<WebController>& webController) override; 35 void Create(const std::string& src, std::function<void(int32_t)>&& setWebIdCallback, 36 std::function<void(const std::string&)>&& setHapPathCallback, int32_t parentWebId, bool popup) override; 37 void SetCustomScheme(const std::string& cmdLine) override; 38 void SetOnCommonDialog(std::function<bool(const BaseEventInfo* info)>&& jsCallback, int dialogEventType) override; 39 void SetOnConsoleLog(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 40 void SetOnPageStart(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 41 void SetOnPageFinish(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 42 void SetOnProgressChange(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 43 void SetOnTitleReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 44 void SetOnFullScreenExit(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 45 void SetOnFullScreenEnter(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 46 void SetOnGeolocationHide(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 47 void SetOnGeolocationShow(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 48 void SetOnRequestFocus(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 49 void SetOnDownloadStart(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 50 void SetOnHttpAuthRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 51 void SetOnSslErrorRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 52 void SetOnSslSelectCertRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 53 void SetMediaPlayGestureAccess(bool isNeedGestureAccess) override; 54 void SetOnKeyEvent(std::function<void(KeyEventInfo& keyEventInfo)>&& jsCallback) override; 55 void SetOnErrorReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 56 void SetOnHttpErrorReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 57 void SetOnInterceptRequest(std::function<RefPtr<WebResponse>(const BaseEventInfo* info)>&& jsCallback) override; 58 void SetOnUrlLoadIntercept(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 59 void SetOnLoadIntercept(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 60 void SetOnFileSelectorShow(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 61 void SetOnContextMenuShow(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 62 void SetOnContextMenuHide(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 63 void SetJsEnabled(bool isJsEnabled) override; 64 void SetFileAccessEnabled(bool isFileAccessEnabled) override; 65 void SetOnLineImageAccessEnabled(bool isOnLineImageAccessEnabled) override; 66 void SetDomStorageAccessEnabled(bool isDomStorageAccessEnabled) override; 67 void SetImageAccessEnabled(bool isImageAccessEnabled) override; 68 void SetMixedMode(MixedModeContent mixedMode) override; 69 void SetZoomAccessEnabled(bool isZoomAccessEnabled) override; 70 void SetGeolocationAccessEnabled(bool isGeolocationAccessEnabled) override; 71 void SetJsProxyCallback(std::function<void()>&& jsProxyCallback) override; 72 void SetUserAgent(const std::string& userAgent) override; 73 void SetRenderExitedId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 74 void SetRefreshAccessedHistoryId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 75 void SetCacheMode(WebCacheMode cacheMode) override; 76 void SetOverviewModeAccessEnabled(bool isOverviewModeAccessEnabled) override; 77 void SetFileFromUrlAccessEnabled(bool isFileFromUrlAccessEnabled) override; 78 void SetDatabaseAccessEnabled(bool isDatabaseAccessEnabled) override; 79 void SetTextZoomRatio(int32_t textZoomRatioNum) override; 80 void SetOnMouseEvent(std::function<void(MouseInfo& info)>&& jsCallback) override; 81 void SetResourceLoadId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 82 void SetScaleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 83 void SetScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 84 void SetPermissionRequestEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 85 void SetScreenCaptureRequestEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 86 void SetBackgroundColor(Color backgroundColor) override; 87 void InitialScale(float scale) override; 88 void SetSearchResultReceiveEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 89 void SetWebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled) override; 90 91 void SetOnDragStart( 92 std::function<NG::DragDropBaseInfo(const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams)>&& 93 onDragStart) override; 94 void SetOnDragEnter( 95 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragEnter) override; 96 void SetOnDragMove( 97 std::function<void(const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams)>&& onDragMoveId) 98 override; 99 void SetOnDragLeave( 100 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragLeave) override; 101 void SetOnDrop(std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDropId) override; 102 void AddDragFrameNodeToManager(); 103 void SetPinchSmoothModeEnabled(bool isPinchSmoothModeEnabled) override; 104 void SetWindowNewEvent(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& jsCallback) override; 105 void SetWindowExitEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 106 107 void SetMultiWindowAccessEnabled(bool isMultiWindowAccessEnable) override; 108 void SetAllowWindowOpenMethod(bool isAllowWindowOpenMethod) override; 109 void SetWebCursiveFont(const std::string& cursiveFontFamily) override; 110 void SetWebFantasyFont(const std::string& fixedFontFamily) override; 111 void SetWebFixedFont(const std::string& fixedFontFamily) override; 112 void SetWebSansSerifFont(const std::string& sansSerifFontFamily) override; 113 void SetWebSerifFont(const std::string& serifFontFamily) override; 114 void SetWebStandardFont(const std::string& standardFontFamily) override; 115 void SetDefaultFixedFontSize(int32_t defaultFixedFontSize) override; 116 void SetDefaultFontSize(int32_t defaultFontSize) override; 117 void SetMinFontSize(int32_t minFontSize) override; 118 void SetMinLogicalFontSize(int32_t minLogicalFontSize) override; 119 void SetBlockNetwork(bool isNetworkBlocked) override; 120 121 void SetPageVisibleId(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& pageVisibleId) override; 122 void SetOnInterceptKeyEventCallback(std::function<bool(KeyEventInfo& keyEventInfo)>&& keyEventInfo) override; 123 void SetDataResubmittedId( 124 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& dataResubmittedId) override; 125 void SetOnDataResubmitted( 126 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& dataResubmittedId) override; 127 void SetFaviconReceivedId( 128 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& faviconReceivedId) override; 129 void SetAudioStateChangedId( 130 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& audioStateChanged) override; 131 void SetFirstContentfulPaintId( 132 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& firstContentfulPaintId) override; 133 void SetTouchIconUrlId(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& touchIconUrlId) override; 134 135 void SetDarkMode(WebDarkMode mode) override; 136 void SetForceDarkAccess(bool access) override; 137 void SetHorizontalScrollBarAccessEnabled(bool isHorizontalScrollBarAccessEnabled) override; 138 void SetVerticalScrollBarAccessEnabled(bool isVerticalScrollBarAccessEnabled) override; 139 140 void SetOnControllerAttached(std::function<void()>&& callback) override; 141 void NotifyPopupWindowResult(int32_t webId, bool result) override; 142 void SetAudioResumeInterval(int32_t resumeInterval) override; 143 void SetAudioExclusive(bool audioExclusive) override; 144 void SetOverScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 145 }; 146 } // namespace OHOS::Ace::NG 147 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WEB_WEB_MODEL_NG_H