1 /* 2 * Copyright (c) 2021-2022 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_CONTROLLER_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WEB_CONTROLLER_H 18 19 #include "base/memory/referenced.h" 20 #include "bridge/declarative_frontend/engine/bindings.h" 21 #include "core/components/declaration/web/web_declaration.h" 22 #include "core/components/web/web_component.h" 23 #include "frameworks/bridge/declarative_frontend/jsview/js_web.h" 24 25 namespace OHOS::Ace::Framework { 26 class JSWebController : public Referenced { 27 public: 28 JSWebController(); 29 ~JSWebController() override = default; 30 31 static void JSBind(BindingTarget globalObj); 32 static void Constructor(const JSCallbackInfo& args); 33 static void Destructor(JSWebController* webController); 34 35 void Reload() const; 36 void LoadUrl(const JSCallbackInfo& args); 37 void ExecuteTypeScript(const JSCallbackInfo& args); 38 void LoadDataWithBaseUrl(const JSCallbackInfo& args); 39 void Refresh(const JSCallbackInfo& args); 40 void StopLoading(const JSCallbackInfo& args); 41 void GetHitTestResult(const JSCallbackInfo& args); 42 void GetHitTestValue(const JSCallbackInfo& args); 43 void GetCookieManager(const JSCallbackInfo& args); 44 void GetProgress(const JSCallbackInfo& args); 45 void GetPageHeight(const JSCallbackInfo& args); 46 void GetTitle(const JSCallbackInfo& args); 47 void CreateWebMessagePorts(const JSCallbackInfo& args); 48 void PostWebMessage(const JSCallbackInfo& args); 49 void GetWebId(const JSCallbackInfo& args); 50 void GetDefaultUserAgent(const JSCallbackInfo& args); 51 void AddJavascriptInterface(const JSCallbackInfo& args); 52 void RemoveJavascriptInterface(const JSCallbackInfo& args); 53 void SetJavascriptInterface(const JSCallbackInfo& args); 54 void OnInactive(const JSCallbackInfo& args); 55 void OnActive(const JSCallbackInfo& args); 56 void Zoom(const JSCallbackInfo& args); 57 void ZoomIn(const JSCallbackInfo& args); 58 void ZoomOut(const JSCallbackInfo& args); 59 void RequestFocus(const JSCallbackInfo& args); 60 void SearchAllAsync(const JSCallbackInfo& args); 61 void ClearMatches(const JSCallbackInfo& args); 62 void SearchNext(const JSCallbackInfo& args); 63 void GetUrl(const JSCallbackInfo& args); 64 65 // Backward and Forward for web page 66 void Backward(const JSCallbackInfo& args); 67 void Forward(const JSCallbackInfo& args); 68 void BackOrForward(const JSCallbackInfo& args); 69 void AccessStep(const JSCallbackInfo& args); 70 void AccessBackward(const JSCallbackInfo& args); 71 void AccessForward(const JSCallbackInfo& args); 72 void ClearHistory(const JSCallbackInfo& args); 73 void ClearSslCache(const JSCallbackInfo& args); 74 void ClearClientAuthenticationCache(const JSCallbackInfo& args); 75 GetController()76 const RefPtr<WebController>& GetController() const 77 { 78 return webController_; 79 } 80 SetController(const RefPtr<WebController> & webController)81 void SetController(const RefPtr<WebController>& webController) 82 { 83 webController_ = webController; 84 } 85 86 protected: 87 void InitJavascriptInterface(); 88 void SetJavascriptCallBackImpl(); 89 std::shared_ptr<WebJSValue> GetJavaScriptResult( 90 const std::string& objectName, 91 const std::string& objectMethod, 92 const std::vector<std::shared_ptr<WebJSValue>>& args); 93 94 private: 95 using ObjectClassMap = std::map<std::string, JSRef<JSObject>>; 96 ObjectClassMap objectorMap_; 97 int32_t instanceId_ = INSTANCE_ID_UNDEFINED; 98 std::unordered_map<std::string, std::vector<std::string>> methods_; 99 RefPtr<WebController> webController_; 100 ACE_DISALLOW_COPY_AND_MOVE(JSWebController); 101 JSRef<JSObject> jsWebCookie_; 102 bool jsWebCookieInit_ = false; 103 }; 104 } // namespace OHOS::Ace::Framework 105 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WEB_CONTROLLER_H 106