From: huayong.xu Date: Fri, 26 Feb 2021 03:43:46 +0000 (+0800) Subject: Add APIs for intercepting http request in web engine. X-Git-Tag: dali_2.0.21~13^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git;a=commitdiff_plain;h=472f322133acbf0f02f99c3fd0b6e1ace985c2c2 Add APIs for intercepting http request in web engine. This patch is to add APIs for intercepting http request in web engine. Change-Id: I87c940df20c1665f6f807dea6f5421fc609f550d --- diff --git a/dali/devel-api/adaptor-framework/web-engine-plugin.h b/dali/devel-api/adaptor-framework/web-engine-plugin.h old mode 100755 new mode 100644 index 3432996..f71d023 --- a/dali/devel-api/adaptor-framework/web-engine-plugin.h +++ b/dali/devel-api/adaptor-framework/web-engine-plugin.h @@ -35,6 +35,7 @@ class WebEngineBackForwardList; class WebEngineContext; class WebEngineCookieManager; class WebEngineFormRepostDecision; +class WebEngineRequestInterceptor; class WebEngineSettings; class HoverEvent; class WheelEvent; @@ -88,6 +89,11 @@ public: using VideoPlayingCallback = std::function; /** + * @brief WebView signal type related with http request interceptor. + */ + using WebEngineRequestInterceptorSignalType = Signal)>; + + /** * @brief Alert callback when JavaScript alert is called with a message. * It returns true if a pop-up is created successfully, false otherwise. */ @@ -524,13 +530,13 @@ public: * @brief Support mouse events or not. * @param[in] enabled True if enabled, false othewise. */ - virtual void EnableMouseEvents( bool enabled ) = 0; + virtual void EnableMouseEvents(bool enabled) = 0; /** * @brief Support key events or not. * @param[in] enabled True if enabled, false othewise. */ - virtual void EnableKeyEvents( bool enabled ) = 0; + virtual void EnableKeyEvents(bool enabled) = 0; /** * @brief Sets focus. @@ -665,13 +671,13 @@ public: * @brief Sends Hover Events. * @param[in] event The hover event would be sent. */ - virtual bool SendHoverEvent( const HoverEvent& event ) = 0; + virtual bool SendHoverEvent(const HoverEvent& event) = 0; /** * @brief Sends Wheel Events. * @param[in] event The wheel event would be sent. */ - virtual bool SendWheelEvent( const WheelEvent& event ) = 0; + virtual bool SendWheelEvent(const WheelEvent& event) = 0; /** * @brief Connects to this signal to be notified when page loading is started. @@ -728,6 +734,13 @@ public: * @return A signal object to connect with. */ virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0; + + /** + * @brief Connects to this signal to be notified when http request need be intercepted. + * + * @return A signal object to connect with. + */ + virtual WebEngineRequestInterceptorSignalType& RequestInterceptorSignal() = 0; }; // specialization has to be done in the same namespace diff --git a/dali/devel-api/adaptor-framework/web-engine-request-interceptor.h b/dali/devel-api/adaptor-framework/web-engine-request-interceptor.h new file mode 100755 index 0000000..dc20661 --- /dev/null +++ b/dali/devel-api/adaptor-framework/web-engine-request-interceptor.h @@ -0,0 +1,89 @@ +#ifndef DALI_WEB_ENGINE_REQUEST_INTERCEPTOR_H +#define DALI_WEB_ENGINE_REQUEST_INTERCEPTOR_H + +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +namespace Dali +{ +/** + * @brief A class WebEngineRequestInterceptor for intercepting http request. + */ +class WebEngineRequestInterceptor +{ +public: + /** + * @brief Constructor. + */ + WebEngineRequestInterceptor() = default; + + /** + * @brief Destructor. + */ + virtual ~WebEngineRequestInterceptor() = default; + + /** + * @brief Returns request url. + * + * @return url on success or empty on failure + */ + virtual std::string GetUrl() const = 0; + + /** + * @brief Ignores request. + * + * @return true on success or false on failure + */ + virtual bool Ignore() = 0; + + /** + * @brief Sets status code and status text of response for intercepted request. + * + * @param[in] statusCode Status code of response + * @param[in] customStatusText Status code of response + * + * @return true if succeeded or false if failed + */ + virtual bool SetResponseStatus(int statusCode, const std::string& customStatusText) = 0; + + /** + * @brief Adds HTTP header to response for intercepted request. + * + * @param[in] fieldName Key of response header + * @param[in] fieldValue Value of response header + * + * @return true if succeeded or false if failed + */ + virtual bool AddResponseHeader(const std::string& fieldName, const std::string& fieldValue) = 0; + + /** + * @brief Writes whole response body at once. + * + * @param[in] body Contents of response + * @param[in] length Length of Contents of response + * + * @return true if succeeded or false if failed + */ + virtual bool AddResponseBody(const std::string& body, uint32_t length) = 0; +}; + +} // namespace Dali + +#endif // DALI_WEB_ENGINE_REQUEST_INTERCEPTOR_H diff --git a/dali/devel-api/adaptor-framework/web-engine.cpp b/dali/devel-api/adaptor-framework/web-engine.cpp index d5c7c96..65a93dc 100755 --- a/dali/devel-api/adaptor-framework/web-engine.cpp +++ b/dali/devel-api/adaptor-framework/web-engine.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -499,4 +500,9 @@ Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& WebEngine::FrameRendere return GetImplementation(*this).FrameRenderedSignal(); } +Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& WebEngine::RequestInterceptorSignal() +{ + return GetImplementation(*this).RequestInterceptorSignal(); +} + } // namespace Dali diff --git a/dali/devel-api/adaptor-framework/web-engine.h b/dali/devel-api/adaptor-framework/web-engine.h index b4b997e..1684f02 100755 --- a/dali/devel-api/adaptor-framework/web-engine.h +++ b/dali/devel-api/adaptor-framework/web-engine.h @@ -664,6 +664,13 @@ public: */ Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal(); + /** + * @brief Connects to this signal to be notified when http request need be intercepted. + * + * @return A signal object to connect with. + */ + Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal(); + private: // Not intended for application developers /** * @brief Internal constructor diff --git a/dali/devel-api/file.list b/dali/devel-api/file.list index 4633ed9..0e9e569 100755 --- a/dali/devel-api/file.list +++ b/dali/devel-api/file.list @@ -89,6 +89,7 @@ SET( devel_api_adaptor_framework_header_files ${adaptor_devel_api_dir}/adaptor-framework/web-engine-cookie-manager.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-form-repost-decision.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-plugin.h + ${adaptor_devel_api_dir}/adaptor-framework/web-engine-request-interceptor.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-settings.h ${adaptor_devel_api_dir}/adaptor-framework/key-extension-plugin.h ${adaptor_devel_api_dir}/adaptor-framework/virtual-keyboard.h diff --git a/dali/internal/web-engine/common/web-engine-impl.cpp b/dali/internal/web-engine/common/web-engine-impl.cpp index c4eab0d..a8acdb1 100755 --- a/dali/internal/web-engine/common/web-engine-impl.cpp +++ b/dali/internal/web-engine/common/web-engine-impl.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -594,6 +595,11 @@ Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& WebEngine::FrameRendere return mPlugin->FrameRenderedSignal(); } +Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& WebEngine::RequestInterceptorSignal() +{ + return mPlugin->RequestInterceptorSignal(); +} + } // namespace Adaptor } // namespace Internal } // namespace Dali diff --git a/dali/internal/web-engine/common/web-engine-impl.h b/dali/internal/web-engine/common/web-engine-impl.h index 88834f1..b9b37d3 100644 --- a/dali/internal/web-engine/common/web-engine-impl.h +++ b/dali/internal/web-engine/common/web-engine-impl.h @@ -484,6 +484,11 @@ public: */ Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal(); + /** + * @copydoc Dali::WebEngine::RequestInterceptorSignal() + */ + Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal(); + private: /** * @brief Constructor.