1 /* 2 * Copyright (c) 2021-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 16 #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WEB_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WEB_H 18 19 #include <string> 20 21 #include "bridge/declarative_frontend/jsview/js_view_common_def.h" 22 #include "core/components/web/web_component.h" 23 #include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h" 24 25 namespace OHOS::Ace::Framework { 26 using JSwebEventCallback = std::function<void()>; 27 class JSWeb : public JSContainerBase { 28 public: 29 static void JSBind(BindingTarget globalObj); 30 static void Create(const JSCallbackInfo& info); 31 static void OnAlert(const JSCallbackInfo& args); 32 static void OnBeforeUnload(const JSCallbackInfo& args); 33 static void OnConfirm(const JSCallbackInfo& args); 34 static void OnFullScreenEnter(const JSCallbackInfo& args); 35 static void OnFullScreenExit(const JSCallbackInfo& args); 36 static void OnPrompt(const JSCallbackInfo& args); 37 static void OnConsoleLog(const JSCallbackInfo& args); 38 static void OnPageStart(const JSCallbackInfo& args); 39 static void OnPageFinish(const JSCallbackInfo& args); 40 static void OnProgressChange(const JSCallbackInfo& args); 41 static void OnTitleReceive(const JSCallbackInfo& args); 42 static void OnGeolocationHide(const JSCallbackInfo& args); 43 static void OnGeolocationShow(const JSCallbackInfo& args); 44 static void OnRequestFocus(const JSCallbackInfo& args); 45 static void OnError(const JSCallbackInfo& args); 46 static void OnMessage(const JSCallbackInfo& args); 47 static void OnDownloadStart(const JSCallbackInfo& args); 48 static void OnErrorReceive(const JSCallbackInfo& args); 49 static void OnHttpErrorReceive(const JSCallbackInfo& args); 50 static void OnFileSelectorShow(const JSCallbackInfo& args); 51 static void OnInterceptRequest(const JSCallbackInfo& args); 52 static void OnUrlLoadIntercept(const JSCallbackInfo& args); 53 static void OnLoadIntercept(const JSCallbackInfo& args); 54 static void JsEnabled(bool isJsEnabled); 55 static void ContentAccessEnabled(bool isContentAccessEnabled); 56 static void FileAccessEnabled(bool isFileAccessEnabled); 57 static void OnFocus(const JSCallbackInfo& args); 58 static void OnLineImageAccessEnabled(bool isOnLineImageAccessEnabled); 59 static void DomStorageAccessEnabled(bool isDomStorageAccessEnabled); 60 static void ImageAccessEnabled(bool isImageAccessEnabled); 61 static void MixedMode(int32_t MixedModeNum); 62 static void ZoomAccessEnabled(bool isZoomAccessEnabled); 63 static void GeolocationAccessEnabled(bool isGeolocationAccessEnabled); 64 static void JavaScriptProxy(const JSCallbackInfo& args); 65 static void UserAgent(const std::string& userAgent); 66 static void OnRenderExited(const JSCallbackInfo& args); 67 static void OnRefreshAccessedHistory(const JSCallbackInfo& args); 68 static void CacheMode(int32_t cacheMode); 69 static void OverviewModeAccess(bool isOverviewModeAccessEnabled); 70 static void WebDebuggingAccess(const JSCallbackInfo& args); 71 static void WideViewModeAccess(const JSCallbackInfo& args); 72 static void FileFromUrlAccess(bool isFileFromUrlAccessEnabled); 73 static void DatabaseAccess(bool isDatabaseAccessEnabled); 74 static void TextZoomRatio(int32_t textZoomRatioNum); 75 static void WebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled); 76 static void OnMouse(const JSCallbackInfo& args); 77 static void OnResourceLoad(const JSCallbackInfo& args); 78 static void OnScaleChange(const JSCallbackInfo& args); 79 static void OnScroll(const JSCallbackInfo& args); 80 static void WebRotate(const JSCallbackInfo& args); 81 static void BackgroundColor(const JSCallbackInfo& info); 82 static void InitialScale(float scale); 83 static void Password(bool password); 84 static void TableData(bool tableData); 85 static void OnFileSelectorShowAbandoned(const JSCallbackInfo& args); 86 static void OnHttpAuthRequest(const JSCallbackInfo& args); 87 static void OnSslErrRequest(const JSCallbackInfo& args); 88 static void OnSslErrorRequest(const JSCallbackInfo& args); 89 static void OnAllSslErrorRequest(const JSCallbackInfo& args); 90 static void OnSslSelectCertRequest(const JSCallbackInfo& args); 91 static void OnPermissionRequest(const JSCallbackInfo& args); 92 static void OnScreenCaptureRequest(const JSCallbackInfo& args); 93 static void BindSelectionMenu(const JSCallbackInfo& info); 94 static void OnContextMenuHide(const JSCallbackInfo& args); 95 static void OnContextMenuShow(const JSCallbackInfo& args); 96 static void OnSearchResultReceive(const JSCallbackInfo& args); 97 static void MediaPlayGestureAccess(bool isNeedGestureAccess); 98 static void OnKeyEvent(const JSCallbackInfo& args); 99 static void JsOnDragStart(const JSCallbackInfo& info); 100 static void JsOnDragEnter(const JSCallbackInfo& info); 101 static void JsOnDragMove(const JSCallbackInfo& info); 102 static void JsOnDragLeave(const JSCallbackInfo& info); 103 static void JsOnDrop(const JSCallbackInfo& info); 104 static void PinchSmoothModeEnabled(bool isPinchSmoothModeEnabled); 105 static void OnWindowNew(const JSCallbackInfo& args); 106 static void OnWindowExit(const JSCallbackInfo& args); 107 static void MultiWindowAccessEnabled(bool isMultiWindowAccessEnable); 108 static void AllowWindowOpenMethod(bool isAllowWindowOpenMethod); 109 static void WebCursiveFont(const std::string& cursiveFontFamily); 110 static void WebFantasyFont(const std::string& fantasyFontFamily); 111 static void WebFixedFont(const std::string& fixedFontFamily); 112 static void WebSansSerifFont(const std::string& sansSerifFontFamily); 113 static void WebSerifFont(const std::string& serifFontFamily); 114 static void WebStandardFont(const std::string& standardFontFamily); 115 static void DefaultFixedFontSize(int32_t defaultFixedFontSize); 116 static void DefaultFontSize(int32_t defaultFontSize); 117 static void DefaultTextEncodingFormat(const JSCallbackInfo& args); 118 static void MinFontSize(int32_t minFontSize); 119 static void MinLogicalFontSize(int32_t minLogicalFontSize); 120 static void BlockNetwork(bool isNetworkBlocked); 121 static void OnPageVisible(const JSCallbackInfo& args); 122 static void OnInterceptKeyEvent(const JSCallbackInfo& args); 123 static void OnDataResubmitted(const JSCallbackInfo& args); 124 static void OnFaviconReceived(const JSCallbackInfo& args); 125 static void OnTouchIconUrlReceived(const JSCallbackInfo& args); 126 static void DarkMode(int32_t darkMode); 127 static void ForceDarkAccess(bool access); 128 static void HorizontalScrollBarAccess(bool isHorizontalScrollBarAccessEnabled); 129 static void VerticalScrollBarAccess(bool isVerticalScrollBarAccessEnabled); 130 static void OnAudioStateChanged(const JSCallbackInfo& args); 131 static void MediaOptions(const JSCallbackInfo& args); 132 static void OnFirstContentfulPaint(const JSCallbackInfo& args); 133 static void OnFirstMeaningfulPaint(const JSCallbackInfo& args); 134 static void OnLargestContentfulPaint(const JSCallbackInfo& args); 135 static void OnSafeBrowsingCheckResult(const JSCallbackInfo& args); 136 static void OnNavigationEntryCommitted(const JSCallbackInfo& args); 137 static void OnIntelligentTrackingPreventionResult(const JSCallbackInfo& args); 138 static void OnControllerAttached(const JSCallbackInfo& args); 139 static void OnOverScroll(const JSCallbackInfo& args); 140 static void SetLayoutMode(int32_t layoutMode); 141 static void SetNestedScroll(const JSCallbackInfo& info); 142 static void SetMetaViewport(const JSCallbackInfo& args); 143 static void OverScrollMode(int overScrollMode); 144 static void BlurOnKeyboardHideMode(int blurOnKeyboardHideMode); 145 static void EnableNativeEmbedMode(bool isEmbedModeEnabled); 146 static void RegisterNativeEmbedRule(const std::string& tag, const std::string& type); 147 static void OnNativeEmbedLifecycleChange(const JSCallbackInfo& args); 148 static void OnNativeEmbedVisibilityChange(const JSCallbackInfo& args); 149 static void OnNativeEmbedGestureEvent(const JSCallbackInfo& args); 150 static void JavaScriptOnDocumentStart(const JSCallbackInfo& args); 151 static void JavaScriptOnDocumentEnd(const JSCallbackInfo& args); 152 // Enable or disable debugging of web content 153 static bool webDebuggingAccess_; 154 static JSwebEventCallback OnControllerAttachedCallback_; 155 static void CopyOption(int32_t copyOption); 156 static void OnOverrideUrlLoading(const JSCallbackInfo& args); 157 static void TextAutosizing(const JSCallbackInfo& args); 158 static void EnableNativeVideoPlayer(const JSCallbackInfo& args); 159 static void OnRenderProcessNotResponding(const JSCallbackInfo& args); 160 static void OnRenderProcessResponding(const JSCallbackInfo& args); 161 static void OnViewportFitChanged(const JSCallbackInfo& args); 162 static void SelectionMenuOptions(const JSCallbackInfo& args); 163 static void OnAdsBlocked(const JSCallbackInfo& args); 164 static void OnInterceptKeyboardAttach(const JSCallbackInfo& args); 165 static void ForceDisplayScrollBar(const JSCallbackInfo& args); 166 static void KeyboardAvoidMode(int32_t mode); 167 static void EditMenuOptions(const JSCallbackInfo& info); 168 static void EnableHapticFeedback(const JSCallbackInfo& args); 169 170 protected: 171 static void OnCommonDialog(const JSCallbackInfo& args, int dialogEventType); 172 static void ParseRawfileWebSrc(const JSRef<JSVal>& srcValue, std::string& webSrc); 173 static void ParseJsCustomKeyboardOption(const JsiExecutionContext& context, 174 const JSRef<JSVal>& keyboardOpt, WebKeyboardOption& keyboardOption); 175 176 private: 177 static void ParseScriptItems(const JSCallbackInfo& args, ScriptItems& scriptItems); 178 static bool CheckNestedScrollMode(const int32_t& modeValue); 179 }; 180 } // namespace OHOS::Ace::Framework 181 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WEB_H 182