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 SetBlurOnKeyboardHideMode(BlurOnKeyboardHideMode mode) override; 88 void SetCopyOptionMode(CopyOptions mode) override; 89 void SetOverviewModeAccessEnabled(bool isOverviewModeAccessEnabled) override; 90 void SetFileFromUrlAccessEnabled(bool isFileFromUrlAccessEnabled) override; 91 void SetDatabaseAccessEnabled(bool isDatabaseAccessEnabled) override; 92 void SetTextZoomRatio(int32_t textZoomRatioNum) override; 93 void SetOnMouseEvent(std::function<void(MouseInfo& info)>&& jsCallback) override; 94 void SetResourceLoadId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 95 void SetScaleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 96 void SetScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 97 void SetPermissionRequestEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 98 void SetScreenCaptureRequestEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 99 void SetBackgroundColor(Color backgroundColor) override; 100 void InitialScale(float scale) override; 101 void SetSearchResultReceiveEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 102 void SetWebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled) override; 103 104 void SetOnDragStart( 105 std::function<NG::DragDropBaseInfo(const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams)>&& 106 onDragStart) override; 107 void SetOnDragEnter( 108 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragEnter) override; 109 void SetOnDragMove( 110 std::function<void(const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams)>&& onDragMoveId) 111 override; 112 void SetOnDragLeave( 113 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragLeave) override; 114 void SetOnDrop(std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDropId) override; 115 void AddDragFrameNodeToManager(); 116 void SetPinchSmoothModeEnabled(bool isPinchSmoothModeEnabled) override; 117 void SetWindowNewEvent(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& jsCallback) override; 118 void SetWindowExitEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 119 120 void SetMultiWindowAccessEnabled(bool isMultiWindowAccessEnable) override; 121 void SetAllowWindowOpenMethod(bool isAllowWindowOpenMethod) override; 122 void SetWebCursiveFont(const std::string& cursiveFontFamily) override; 123 void SetWebFantasyFont(const std::string& fixedFontFamily) override; 124 void SetWebFixedFont(const std::string& fixedFontFamily) override; 125 void SetWebSansSerifFont(const std::string& sansSerifFontFamily) override; 126 void SetWebSerifFont(const std::string& serifFontFamily) override; 127 void SetWebStandardFont(const std::string& standardFontFamily) override; 128 void SetDefaultFixedFontSize(int32_t defaultFixedFontSize) override; 129 void SetDefaultFontSize(int32_t defaultFontSize) override; 130 void SetDefaultTextEncodingFormat(const std::string& textEncodingFormat) override; 131 void SetMinFontSize(int32_t minFontSize) override; 132 void SetMinLogicalFontSize(int32_t minLogicalFontSize) override; 133 void SetBlockNetwork(bool isNetworkBlocked) override; 134 135 void SetPageVisibleId(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& pageVisibleId) override; 136 void SetOnInterceptKeyEventCallback(std::function<bool(KeyEventInfo& keyEventInfo)>&& keyEventInfo) override; 137 void SetDataResubmittedId( 138 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& dataResubmittedId) override; 139 void SetOnDataResubmitted( 140 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& dataResubmittedId) override; 141 void SetFaviconReceivedId( 142 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& faviconReceivedId) override; 143 void SetAudioStateChangedId( 144 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& audioStateChanged) override; 145 void SetFirstContentfulPaintId( 146 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& firstContentfulPaintId) override; 147 void SetFirstMeaningfulPaintId( 148 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& firstMeaningfulPaintId) override; 149 void SetLargestContentfulPaintId( 150 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& largestContentfulPaintId) override; 151 void SetSafeBrowsingCheckResultId( 152 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& safeBrowsingCheckResultId) override; 153 void SetNavigationEntryCommittedId( 154 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& navigationEntryCommittedId) override; 155 void SetTouchIconUrlId(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& touchIconUrlId) override; 156 157 void SetDarkMode(WebDarkMode mode) override; 158 void SetForceDarkAccess(bool access) override; 159 void SetHorizontalScrollBarAccessEnabled(bool isHorizontalScrollBarAccessEnabled) override; 160 void SetVerticalScrollBarAccessEnabled(bool isVerticalScrollBarAccessEnabled) override; 161 162 void SetOnControllerAttached(std::function<void()>&& callback) override; 163 void NotifyPopupWindowResult(int32_t webId, bool result) override; 164 void SetAudioResumeInterval(int32_t resumeInterval) override; 165 void SetAudioExclusive(bool audioExclusive) override; 166 void SetOverScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 167 void SetNativeEmbedModeEnabled(bool isEmbedModeEnabled) override; 168 void RegisterNativeEmbedRule(const std::string& tag, const std::string& type) override; 169 void SetNativeEmbedLifecycleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 170 void SetNativeEmbedVisibilityChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 171 void SetNativeEmbedGestureEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 172 void SetLayoutMode(WebLayoutMode mode) override; 173 void SetNestedScroll(const NestedScrollOptions& nestedOpt) override; 174 void SetNestedScrollExt(const NestedScrollOptionsExt& nestedOpt) override; 175 void SetMetaViewport(bool enabled) override; 176 void JavaScriptOnDocumentStart(const ScriptItems& scriptItems) override; 177 void JavaScriptOnDocumentEnd(const ScriptItems& scriptItems) override; 178 void SetDefaultFileSelectorShow(std::function<void(const std::shared_ptr<BaseEventInfo>&)>&& jsCallback) override; 179 void SetPermissionClipboard(std::function<void(const std::shared_ptr<BaseEventInfo>&)>&& jsCallback) override; 180 void SetOpenAppLinkFunction(std::function<void(const std::shared_ptr<BaseEventInfo>&)>&& jsCallback) override; 181 void SetIntelligentTrackingPreventionResultId( 182 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& 183 intelligentTrackingPreventionResultId) override; 184 void SetTextAutosizing(bool isTextAutosizing) override; 185 void SetNativeVideoPlayerConfig(bool enable, bool shouldOverlay) override; 186 void SetRenderProcessNotRespondingId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 187 void SetRenderProcessRespondingId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 188 void SetViewportFitChangedId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 189 void SetSelectionMenuOptions(const WebMenuOptionsParam& webMenuOption) override; 190 void SetAdsBlockedEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 191 void SetOnInterceptKeyboardAttach( 192 std::function<WebKeyboardOption(const BaseEventInfo* info)>&& jsCallback) override; 193 void SetUpdateInstanceIdCallback(std::function<void(int32_t)>&& callback) override; 194 void SetOverlayScrollbarEnabled(bool isEnabled) override; 195 void SetKeyboardAvoidMode(const WebKeyboardAvoidMode& mode) override; 196 void SetEditMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback, 197 const NG::OnMenuItemClickCallback&& onMenuItemClick) override; 198 void SetEnabledHapticFeedback(bool isEnabled) override; 199 }; 200 } // namespace OHOS::Ace::NG 201 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WEB_WEB_MODEL_NG_H 202