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 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 WebType type = WebType::SURFACE, bool incognitoMode = false) override; 37 void Create(const std::string& src, std::function<void(int32_t)>&& setWebIdCallback, 38 std::function<void(const std::string&)>&& setHapPathCallback, 39 int32_t parentWebId, bool popup, WebType type = WebType::SURFACE, bool incognitoMode = false) override; 40 void SetCustomScheme(const std::string& cmdLine) override; 41 void SetOnCommonDialog(std::function<bool(const BaseEventInfo* info)>&& jsCallback, int dialogEventType) override; 42 void SetOnConsoleLog(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 43 void SetOnPageStart(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 44 void SetOnPageFinish(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 45 void SetOnProgressChange(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 46 void SetOnTitleReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 47 void SetOnFullScreenExit(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 48 void SetOnFullScreenEnter(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 49 void SetOnGeolocationHide(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 50 void SetOnGeolocationShow(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 51 void SetOnRequestFocus(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 52 void SetOnDownloadStart(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 53 void SetOnHttpAuthRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 54 void SetOnSslErrorRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 55 void SetOnSslSelectCertRequest(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 56 void SetMediaPlayGestureAccess(bool isNeedGestureAccess) override; 57 void SetOnKeyEvent(std::function<void(KeyEventInfo& keyEventInfo)>&& jsCallback) override; 58 void SetOnErrorReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 59 void SetOnHttpErrorReceive(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 60 void SetOnInterceptRequest(std::function<RefPtr<WebResponse>(const BaseEventInfo* info)>&& jsCallback) override; 61 void SetOnUrlLoadIntercept(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 62 void SetOnLoadIntercept(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 63 void SetOnFileSelectorShow(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 64 void SetOnContextMenuShow(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override; 65 void SetOnContextMenuHide(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 66 void SetJsEnabled(bool isJsEnabled) override; 67 void SetFileAccessEnabled(bool isFileAccessEnabled) override; 68 void SetOnLineImageAccessEnabled(bool isOnLineImageAccessEnabled) override; 69 void SetDomStorageAccessEnabled(bool isDomStorageAccessEnabled) override; 70 void SetImageAccessEnabled(bool isImageAccessEnabled) override; 71 void SetMixedMode(MixedModeContent mixedMode) override; 72 void SetZoomAccessEnabled(bool isZoomAccessEnabled) override; 73 void SetGeolocationAccessEnabled(bool isGeolocationAccessEnabled) override; 74 void SetJsProxyCallback(std::function<void()>&& jsProxyCallback) override; 75 void SetUserAgent(const std::string& userAgent) override; 76 void SetRenderExitedId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 77 void SetRefreshAccessedHistoryId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 78 void SetCacheMode(WebCacheMode cacheMode) override; 79 void SetOverScrollMode(OverScrollMode mode) override; 80 void SetCopyOptionMode(CopyOptions mode) override; 81 void SetOverviewModeAccessEnabled(bool isOverviewModeAccessEnabled) override; 82 void SetFileFromUrlAccessEnabled(bool isFileFromUrlAccessEnabled) override; 83 void SetDatabaseAccessEnabled(bool isDatabaseAccessEnabled) override; 84 void SetTextZoomRatio(int32_t textZoomRatioNum) override; 85 void SetOnMouseEvent(std::function<void(MouseInfo& info)>&& jsCallback) override; 86 void SetResourceLoadId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 87 void SetScaleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 88 void SetScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 89 void SetPermissionRequestEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 90 void SetScreenCaptureRequestEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 91 void SetBackgroundColor(Color backgroundColor) override; 92 void InitialScale(float scale) override; 93 void SetSearchResultReceiveEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 94 void SetWebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled) override; 95 96 void SetOnDragStart( 97 std::function<NG::DragDropBaseInfo(const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams)>&& 98 onDragStart) override; 99 void SetOnDragEnter( 100 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragEnter) override; 101 void SetOnDragMove( 102 std::function<void(const RefPtr<OHOS::Ace::DragEvent>& info, const std::string& extraParams)>&& onDragMoveId) 103 override; 104 void SetOnDragLeave( 105 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragLeave) override; 106 void SetOnDrop(std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDropId) override; 107 void AddDragFrameNodeToManager(); 108 void SetPinchSmoothModeEnabled(bool isPinchSmoothModeEnabled) override; 109 void SetWindowNewEvent(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& jsCallback) override; 110 void SetWindowExitEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 111 112 void SetMultiWindowAccessEnabled(bool isMultiWindowAccessEnable) override; 113 void SetAllowWindowOpenMethod(bool isAllowWindowOpenMethod) override; 114 void SetWebCursiveFont(const std::string& cursiveFontFamily) override; 115 void SetWebFantasyFont(const std::string& fixedFontFamily) override; 116 void SetWebFixedFont(const std::string& fixedFontFamily) override; 117 void SetWebSansSerifFont(const std::string& sansSerifFontFamily) override; 118 void SetWebSerifFont(const std::string& serifFontFamily) override; 119 void SetWebStandardFont(const std::string& standardFontFamily) override; 120 void SetDefaultFixedFontSize(int32_t defaultFixedFontSize) override; 121 void SetDefaultFontSize(int32_t defaultFontSize) override; 122 void SetMinFontSize(int32_t minFontSize) override; 123 void SetMinLogicalFontSize(int32_t minLogicalFontSize) override; 124 void SetBlockNetwork(bool isNetworkBlocked) override; 125 126 void SetPageVisibleId(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& pageVisibleId) override; 127 void SetOnInterceptKeyEventCallback(std::function<bool(KeyEventInfo& keyEventInfo)>&& keyEventInfo) override; 128 void SetDataResubmittedId( 129 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& dataResubmittedId) override; 130 void SetOnDataResubmitted( 131 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& dataResubmittedId) override; 132 void SetFaviconReceivedId( 133 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& faviconReceivedId) override; 134 void SetAudioStateChangedId( 135 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& audioStateChanged) override; 136 void SetFirstContentfulPaintId( 137 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& firstContentfulPaintId) override; 138 void SetSafeBrowsingCheckResultId( 139 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& safeBrowsingCheckResultId) override; 140 void SetNavigationEntryCommittedId( 141 std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& navigationEntryCommittedId) override; 142 void SetTouchIconUrlId(std::function<void(const std::shared_ptr<BaseEventInfo>& info)>&& touchIconUrlId) override; 143 144 void SetDarkMode(WebDarkMode mode) override; 145 void SetForceDarkAccess(bool access) override; 146 void SetHorizontalScrollBarAccessEnabled(bool isHorizontalScrollBarAccessEnabled) override; 147 void SetVerticalScrollBarAccessEnabled(bool isVerticalScrollBarAccessEnabled) override; 148 149 void SetOnControllerAttached(std::function<void()>&& callback) override; 150 void NotifyPopupWindowResult(int32_t webId, bool result) override; 151 void SetAudioResumeInterval(int32_t resumeInterval) override; 152 void SetAudioExclusive(bool audioExclusive) override; 153 void SetOverScrollId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 154 void SetNativeEmbedModeEnabled(bool isEmbedModeEnabled) override; 155 void SetNativeEmbedLifecycleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 156 void SetNativeEmbedGestureEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override; 157 void SetLayoutMode(WebLayoutMode mode) override; 158 void SetNestedScroll(const NestedScrollOptions& nestedOpt) override; 159 void JavaScriptOnDocumentStart(const ScriptItems& scriptItems) override; 160 void JavaScriptOnDocumentEnd(const ScriptItems& scriptItems) override; 161 162 void SetPermissionClipboard(std::function<void(const std::shared_ptr<BaseEventInfo>&)>&& jsCallback) override; 163 }; 164 } // namespace OHOS::Ace::NG 165 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WEB_WEB_MODEL_NG_H