Add APIs for intercepting http request in web engine. 01/254301/3
authorhuayong.xu <huayong.xu@samsung.com>
Fri, 26 Feb 2021 03:43:46 +0000 (11:43 +0800)
committerhuayong.xu <huayong.xu@samsung.com>
Wed, 31 Mar 2021 09:42:22 +0000 (17:42 +0800)
This patch is to add APIs for intercepting http request in web
engine.

Change-Id: I87c940df20c1665f6f807dea6f5421fc609f550d

dali/devel-api/adaptor-framework/web-engine-plugin.h [changed mode: 0755->0644]
dali/devel-api/adaptor-framework/web-engine-request-interceptor.h [new file with mode: 0755]
dali/devel-api/adaptor-framework/web-engine.cpp
dali/devel-api/adaptor-framework/web-engine.h
dali/devel-api/file.list
dali/internal/web-engine/common/web-engine-impl.cpp
dali/internal/web-engine/common/web-engine-impl.h

old mode 100755 (executable)
new mode 100644 (file)
index 3432996..f71d023
@@ -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<void(bool)>;
 
   /**
+   * @brief WebView signal type related with http request interceptor.
+   */
+  using WebEngineRequestInterceptorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineRequestInterceptor>)>;
+
+  /**
    * @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 (executable)
index 0000000..dc20661
--- /dev/null
@@ -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 <string>
+
+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
index d5c7c96..65a93dc 100755 (executable)
@@ -22,6 +22,7 @@
 #include <dali/devel-api/adaptor-framework/web-engine-back-forward-list.h>
 #include <dali/devel-api/adaptor-framework/web-engine-context.h>
 #include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
+#include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
 #include <dali/devel-api/adaptor-framework/web-engine-settings.h>
 #include <dali/internal/web-engine/common/web-engine-impl.h>
 
@@ -499,4 +500,9 @@ Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& WebEngine::FrameRendere
   return GetImplementation(*this).FrameRenderedSignal();
 }
 
+Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& WebEngine::RequestInterceptorSignal()
+{
+  return GetImplementation(*this).RequestInterceptorSignal();
+}
+
 } // namespace Dali
index b4b997e..1684f02 100755 (executable)
@@ -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
index 4633ed9..0e9e569 100755 (executable)
@@ -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
index c4eab0d..a8acdb1 100755 (executable)
@@ -29,6 +29,7 @@
 #include <dali/devel-api/adaptor-framework/web-engine-back-forward-list.h>
 #include <dali/devel-api/adaptor-framework/web-engine-context.h>
 #include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
+#include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
 #include <dali/devel-api/adaptor-framework/web-engine-settings.h>
 #include <dali/internal/system/common/environment-variables.h>
 #include <dali/public-api/adaptor-framework/native-image-source.h>
@@ -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
index 88834f1..b9b37d3 100644 (file)
@@ -484,6 +484,11 @@ public:
    */
   Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal();
 
+  /**
+   * @copydoc Dali::WebEngine::RequestInterceptorSignal()
+   */
+  Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal();
+
 private:
   /**
    * @brief Constructor.