1 /* 2 * Copyright (c) 2023-2024 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 using setPermissionClipboardCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>; 32 33 class ACE_EXPORT WebModelNG : public OHOS::Ace::WebModel { 34 public: 35 void Create(const std::string& src, const RefPtr<WebController>& webController, 36 RenderMode renderMode = RenderMode::ASYNC_RENDER, bool incognitoMode = false, 37 const std::string& sharedRenderProcessToken = "") override; 38 void Create(const std::string& src, std::function<void(int32_t)>&& setWebIdCallback, 39 std::function<void(const std::string&)>&& setHapPathCallback, int32_t parentWebId, bool popup, 40 RenderMode renderMode = RenderMode::ASYNC_RENDER, bool incognitoMode = false, 41 const std::string& sharedRenderProcessToken = "") override; 42 Color GetDefaultBackgroundColor() override; 43 void SetCustomScheme(const std::string& cmdLine) override; 44 void SetOnCommonDialog(std::function<bool(const BaseEventInfo* info)>&& jsCallback, int dialogEventType) override; 45 void SetOnConsoleLog(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 46 void SetOnPageStart(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 47 void SetOnPageFinish(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 48 void SetOnProgressChange(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 49 void SetOnTitleReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 50 void SetOnFullScreenExit(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 51 void SetOnFullScreenEnter(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 52 void SetOnGeolocationHide(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 53 void SetOnGeolocationShow(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 54 void SetOnRequestFocus(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 55 void SetOnDownloadStart(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 56 void SetOnHttpAuthRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 57 void SetOnSslErrorRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 58 void SetOnAllSslErrorRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 59 void SetOnSslSelectCertRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 60 void SetMediaPlayGestureAccess(bool isNeedGestureAccess) override; 61 void SetOnKeyEvent(std::function<void(KeyEventInfo& keyEventInfo)>&& jsCallback) override; 62 void SetOnErrorReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 63 void SetOnHttpErrorReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 64 void SetOnInterceptRequest(std::function<RefPtr<WebResponse>(const BaseEventInfo* info)>&& jsCallback) override; 65 void SetOnUrlLoadIntercept(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 66 void SetOnLoadIntercept(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 67 void SetOnOverrideUrlLoading(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 68 void SetOnFileSelectorShow(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 69 void SetOnContextMenuShow(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 70 void SetOnContextMenuHide(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 71 void SetNewDragStyle(bool isNewDragStyle) override; 72 void SetPreviewSelectionMenu(const std::shared_ptr<WebPreviewSelectionMenuParam>& param) override; 73 void SetJsEnabled(bool isJsEnabled) override; 74 void SetFileAccessEnabled(bool isFileAccessEnabled) override; 75 void SetOnLineImageAccessEnabled(bool isOnLineImageAccessEnabled) override; 76 void SetDomStorageAccessEnabled(bool isDomStorageAccessEnabled) override; 77 void SetImageAccessEnabled(bool isImageAccessEnabled) override; 78 void SetMixedMode(MixedModeContent mixedMode) override; 79 void SetZoomAccessEnabled(bool isZoomAccessEnabled) override; 80 void SetGeolocationAccessEnabled(bool isGeolocationAccessEnabled) override; 81 void SetJsProxyCallback(std::function<void()>&& jsProxyCallback) override; 82 void SetUserAgent(const std::string& userAgent) override; 83 void SetRenderExitedId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 84 void SetRefreshAccessedHistoryId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 85 void SetCacheMode(WebCacheMode cacheMode) override; 86 void SetOverScrollMode(OverScrollMode mode) override; 87 void SetCopyOptionMode(CopyOptions mode) override; 88 void SetOverviewModeAccessEnabled(bool isOverviewModeAccessEnabled) override; 89 void SetFileFromUrlAccessEnabled(bool isFileFromUrlAccessEnabled) override; 90 void SetDatabaseAccessEnabled(bool isDatabaseAccessEnabled) override; 91 void SetTextZoomRatio(int32_t textZoomRatioNum) override; 92 void SetOnMouseEvent(std::function<void(MouseInfo& info)>&& jsCallback) override; 93 void SetResourceLoadId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 94 void SetScaleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 95 void SetScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 96 void SetPermissionRequestEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 97 void SetScreenCaptureRequestEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 98 void SetBackgroundColor(Color backgroundColor) override; 99 void InitialScale(float scale) override; 100 void SetSearchResultReceiveEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 101 void SetWebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled) override; 102 103 void SetOnDragStart( 104 std::function<NG::DragDropBaseInfo(const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams)>&& 105 onDragStart) override; 106 void SetOnDragEnter( 107 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragEnter) override; 108 void SetOnDragMove( 109 std::function<void(const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams)>&& onDragMoveId) 110 override; 111 void SetOnDragLeave( 112 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragLeave) override; 113 void SetOnDrop(std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDropId) override; 114 void AddDragFrameNodeToManager(); 115 void SetPinchSmoothModeEnabled(bool isPinchSmoothModeEnabled) override; 116 void SetWindowNewEvent(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& jsCallback) override; 117 void SetWindowExitEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 118 119 void SetMultiWindowAccessEnabled(bool isMultiWindowAccessEnable) override; 120 void SetAllowWindowOpenMethod(bool isAllowWindowOpenMethod) override; 121 void SetWebCursiveFont(const std::string& cursiveFontFamily) override; 122 void SetWebFantasyFont(const std::string& fixedFontFamily) override; 123 void SetWebFixedFont(const std::string& fixedFontFamily) override; 124 void SetWebSansSerifFont(const std::string& sansSerifFontFamily) override; 125 void SetWebSerifFont(const std::string& serifFontFamily) override; 126 void SetWebStandardFont(const std::string& standardFontFamily) override; 127 void SetDefaultFixedFontSize(int32_t defaultFixedFontSize) override; 128 void SetDefaultFontSize(int32_t defaultFontSize) override; 129 void SetDefaultTextEncodingFormat(const std::string& textEncodingFormat) override; 130 void SetMinFontSize(int32_t minFontSize) override; 131 void SetMinLogicalFontSize(int32_t minLogicalFontSize) override; 132 void SetBlockNetwork(bool isNetworkBlocked) override; 133 134 void SetPageVisibleId(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& pageVisibleId) override; 135 void SetOnInterceptKeyEventCallback(std::function<bool(KeyEventInfo& keyEventInfo)>&& keyEventInfo) override; 136 void SetDataResubmittedId( 137 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& dataResubmittedId) override; 138 void SetOnDataResubmitted( 139 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& dataResubmittedId) override; 140 void SetFaviconReceivedId( 141 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& faviconReceivedId) override; 142 void SetAudioStateChangedId( 143 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& audioStateChanged) override; 144 void SetFirstContentfulPaintId( 145 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& firstContentfulPaintId) override; 146 void SetFirstMeaningfulPaintId( 147 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& firstMeaningfulPaintId) override; 148 void SetLargestContentfulPaintId( 149 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& largestContentfulPaintId) override; 150 void SetSafeBrowsingCheckResultId( 151 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& safeBrowsingCheckResultId) override; 152 void SetNavigationEntryCommittedId( 153 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& navigationEntryCommittedId) override; 154 void SetTouchIconUrlId(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& touchIconUrlId) override; 155 156 void SetDarkMode(WebDarkMode mode) override; 157 void SetForceDarkAccess(bool access) override; 158 void SetHorizontalScrollBarAccessEnabled(bool isHorizontalScrollBarAccessEnabled) override; 159 void SetVerticalScrollBarAccessEnabled(bool isVerticalScrollBarAccessEnabled) override; 160 161 void SetOnControllerAttached(std::function<void()>&& callback) override; 162 void NotifyPopupWindowResult(int32_t webId, bool result) override; 163 void SetAudioResumeInterval(int32_t resumeInterval) override; 164 void SetAudioExclusive(bool audioExclusive) override; 165 void SetOverScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 166 void SetNativeEmbedModeEnabled(bool isEmbedModeEnabled) override; 167 void RegisterNativeEmbedRule(const std::string& tag, const std::string& type) override; 168 void SetNativeEmbedLifecycleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 169 void SetNativeEmbedVisibilityChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 170 void SetNativeEmbedGestureEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 171 void SetLayoutMode(WebLayoutMode mode) override; 172 void SetNestedScroll(const NestedScrollOptions& nestedOpt) override; 173 void SetMetaViewport(bool enabled) override; 174 void JavaScriptOnDocumentStart(const ScriptItems& scriptItems) override; 175 void JavaScriptOnDocumentEnd(const ScriptItems& scriptItems) override; 176 void SetDefaultFileSelectorShow(std::function<void(const std::shared_ptr<BaseEventInfo>&)>&& jsCallback) override; 177 void SetPermissionClipboard(std::function<void(const std::shared_ptr<BaseEventInfo>&)>&& jsCallback) override; 178 void SetOpenAppLinkFunction(std::function<void(const std::shared_ptr<BaseEventInfo>&)>&& jsCallback) override; 179 void SetIntelligentTrackingPreventionResultId( 180 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& 181 intelligentTrackingPreventionResultId) override; 182 void SetTextAutosizing(bool isTextAutosizing) override; 183 void SetNativeVideoPlayerConfig(bool enable, bool shouldOverlay) override; 184 void SetRenderProcessNotRespondingId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 185 void SetRenderProcessRespondingId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 186 void SetViewportFitChangedId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 187 void SetSelectionMenuOptions(const WebMenuOptionsParam& webMenuOption) override; 188 void SetAdsBlockedEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 189 void SetOnInterceptKeyboardAttach( 190 std::function<WebKeyboardOption(const BaseEventInfo* info)>&& jsCallback) override; 191 void SetUpdateInstanceIdCallback(std::function<void(int32_t)>&& callback) override; 192 void SetOverlayScrollbarEnabled(bool isEnabled) override; 193 void SetKeyboardAvoidMode(const WebKeyboardAvoidMode& mode) override; 194 void SetEditMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback, 195 const NG::OnMenuItemClickCallback&& onMenuItemClick) override; 196 void SetEnabledHapticFeedback(bool isEnabled) override; 197 }; 198 } // namespace OHOS::Ace::NG 199 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WEB_WEB_MODEL_NG_H 200