Implement more request interceptor APIs. 62/263062/1
authorhuayong.xu <huayong.xu@samsung.com>
Tue, 24 Aug 2021 01:38:40 +0000 (09:38 +0800)
committerJiyun Yang <ji.yang@samsung.com>
Wed, 25 Aug 2021 08:34:22 +0000 (17:34 +0900)
Change-Id: Id2c0a9eca5043ef3c9b559aee4d1713037dd3145

dali/devel-api/adaptor-framework/web-engine-context.h
dali/devel-api/adaptor-framework/web-engine-hit-test.h
dali/devel-api/adaptor-framework/web-engine-plugin.h
dali/devel-api/adaptor-framework/web-engine-request-interceptor.h
dali/devel-api/adaptor-framework/web-engine.cpp
dali/devel-api/adaptor-framework/web-engine.h
dali/internal/web-engine/common/web-engine-impl.cpp
dali/internal/web-engine/common/web-engine-impl.h

index 4db0aba..3f9a36d 100755 (executable)
@@ -25,6 +25,7 @@
 #include <vector>
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
 #include <dali/devel-api/adaptor-framework/web-engine-security-origin.h>
 
 namespace Dali
@@ -36,6 +37,11 @@ class WebEngineContext
 {
 public:
   /**
+   * @brief WebView callback related with http request interceptor.
+   */
+  using WebEngineRequestInterceptedCallback = std::function<void(Dali::WebEngineRequestInterceptorPtr)>;
+
+  /**
    * @brief Callback for getting web database origins.
    */
   using WebEngineSecurityOriginAcquiredCallback = std::function<void(std::vector<std::unique_ptr<Dali::WebEngineSecurityOrigin>>&)>;
@@ -276,6 +282,13 @@ public:
   virtual void RegisterMimeOverriddenCallback(WebEngineMimeOverriddenCallback callback) = 0;
 
   /**
+   * @brief Callback to be called when http request need be intercepted.
+   *
+   * @param[in] callback
+   */
+  virtual void RegisterRequestInterceptedCallback(WebEngineRequestInterceptedCallback callback) = 0;
+
+  /**
    * @brief Toggle the cache to be enabled or disabled
    * Function works asynchronously.
    *
index 356fec8..62dbcfa 100755 (executable)
@@ -128,7 +128,7 @@ public:
    *
    * @return the attribute data of the hit element in the coordinates of the hit test
    */
-  virtual Dali::Property::Map& GetAttributes() const = 0;
+  virtual Dali::Property::Map GetAttributes() const = 0;
 
   /**
    * @brief Get the image file name extension of hit element of the hit test.
index 07daee3..5ac59fd 100755 (executable)
@@ -45,7 +45,6 @@ class WebEngineHitTest;
 class WebEngineHttpAuthHandler;
 class WebEngineLoadError;
 class WebEnginePolicyDecision;
-class WebEngineRequestInterceptor;
 class WebEngineSettings;
 class HoverEvent;
 class WheelEvent;
@@ -104,11 +103,6 @@ public:
   using VideoPlayingCallback = std::function<void(bool)>;
 
   /**
-   * @brief WebView callback related with http request interceptor.
-   */
-  using WebEngineRequestInterceptorCallback = std::function<void(std::unique_ptr<Dali::WebEngineRequestInterceptor>)>;
-
-  /**
    * @brief WebView callback related with console message logged.
    */
   using WebEngineConsoleMessageReceivedCallback = std::function<void(std::unique_ptr<Dali::WebEngineConsoleMessage>)>;
@@ -819,13 +813,6 @@ public:
   virtual void RegisterFormRepostDecidedCallback(WebEngineFormRepostDecidedCallback callback) = 0;
 
   /**
-   * @brief Callback to be called when http request need be intercepted.
-   *
-   * @param[in] callback
-   */
-  virtual void RegisterRequestInterceptorCallback(WebEngineRequestInterceptorCallback callback) = 0;
-
-  /**
    * @brief Callback to be called when console message will be logged.
    *
    * @param[in] callback
index dc20661..d777c63 100755 (executable)
  */
 
 // EXTERNAL INCLUDES
+#include <dali/public-api/common/intrusive-ptr.h>
+#include <dali/public-api/object/property-map.h>
+#include <dali/public-api/object/ref-object.h>
+
 #include <string>
 
 namespace Dali
@@ -26,7 +30,7 @@ namespace Dali
 /**
  * @brief A class WebEngineRequestInterceptor for intercepting http request.
  */
-class WebEngineRequestInterceptor
+class WebEngineRequestInterceptor : public RefObject
 {
 public:
   /**
@@ -42,14 +46,30 @@ public:
   /**
    * @brief Returns request url.
    *
-   * @return url on success or empty on failure
+   * @return url if succeeded or empty otherwise
    */
   virtual std::string GetUrl() const = 0;
 
   /**
+   * @brief Returns http headers.
+   *
+   * @return headers if succeeded or empty otherwise
+   */
+  virtual Dali::Property::Map GetHeaders() const = 0;
+
+  /**
+   * @brief Returns http method.
+   *
+   * @return method if succeeded or empty otherwise
+   */
+  virtual std::string GetMethod() const = 0;
+
+  /**
    * @brief Ignores request.
+   * @note After this call, any further calls result in undefined behavior.
+   *       This function can be called only INSIDE Dali::WebEngineContext::WebEngineRequestInterceptedCallback.
    *
-   * @return true on success or false on failure
+   * @return true if succeeded or false otherwise
    */
   virtual bool Ignore() = 0;
 
@@ -59,7 +79,7 @@ public:
    * @param[in] statusCode Status code of response
    * @param[in] customStatusText Status code of response
    *
-   * @return true if succeeded or false if failed
+   * @return true if succeeded or false otherwise
    */
   virtual bool SetResponseStatus(int statusCode, const std::string& customStatusText) = 0;
 
@@ -69,21 +89,58 @@ public:
    * @param[in] fieldName Key of response header
    * @param[in] fieldValue Value of response header
    *
-   * @return true if succeeded or false if failed
+   * @return true if succeeded or false otherwise
    */
   virtual bool AddResponseHeader(const std::string& fieldName, const std::string& fieldValue) = 0;
 
   /**
+   * @brief Adds HTTP headers to response.
+   *
+   * @param[in] headers Headers of response
+   *
+   * @return true if succeeded or false otherwise
+   */
+  virtual bool AddResponseHeaders(const Dali::Property::Map& headers) = 0;
+
+  /**
    * @brief Writes whole response body at once.
    *
    * @param[in] body Contents of response
-   * @param[in] length Length of Contents of response
+   * @param[in] length Length of contents of response
    *
-   * @return true if succeeded or false if failed
+   * @return true if succeeded or false otherwise
    */
   virtual bool AddResponseBody(const std::string& body, uint32_t length) = 0;
+
+  /**
+   * @brief Writes whole response at once.
+   *
+   * @param[in] headers Headers of response
+   * @param[in] body Contents of response
+   * @param[in] length Length of contents of response
+   *
+   * @return true if succeeded or false otherwise
+   */
+  virtual bool AddResponse(const std::string& headers, const std::string& body, uint32_t length) = 0;
+
+  /**
+   * @brief Writes a part of response body.
+   * @note If this function returns false, handling the request is done.
+   *       Any further calls result in undefined behavior.
+   *       User should always check return value, because response to this request might not be needed any more,
+   *       and function can return false even though user still has data to write.
+   *       This function can be called only OUTSIDE Dali::WebEngineContext::WebEngineRequestInterceptedCallback.
+   *
+   * @param[in] chunk Chunks of response
+   * @param[in] length Length of chunks of response
+   *
+   * @return true if succeeded or false otherwise
+   */
+  virtual bool WriteResponseChunk(const std::string& chunk, uint32_t length) = 0;
 };
 
+using WebEngineRequestInterceptorPtr = Dali::IntrusivePtr<WebEngineRequestInterceptor>;
+
 } // namespace Dali
 
 #endif // DALI_WEB_ENGINE_REQUEST_INTERCEPTOR_H
index 86f67f1..db92561 100755 (executable)
@@ -29,7 +29,6 @@
 #include <dali/devel-api/adaptor-framework/web-engine-http-auth-handler.h>
 #include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
 #include <dali/devel-api/adaptor-framework/web-engine-policy-decision.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>
 
@@ -517,11 +516,6 @@ void WebEngine::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngi
   GetImplementation(*this).RegisterFormRepostDecidedCallback(callback);
 }
 
-void WebEngine::RegisterRequestInterceptorCallback(Dali::WebEnginePlugin::WebEngineRequestInterceptorCallback callback)
-{
-  GetImplementation(*this).RegisterRequestInterceptorCallback(callback);
-}
-
 void WebEngine::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
 {
   GetImplementation(*this).RegisterConsoleMessageReceivedCallback(callback);
index 4ba8cbf..7bd2ea2 100755 (executable)
@@ -688,13 +688,6 @@ public:
   void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
 
   /**
-   * @brief Callback to be called when http request need be intercepted.
-   *
-   * @param[in] callback
-   */
-  void RegisterRequestInterceptorCallback(Dali::WebEnginePlugin::WebEngineRequestInterceptorCallback callback);
-
-  /**
    * @brief Callback to be called when console message will be logged.
    *
    * @param[in] callback
index f4753f0..9afe674 100755 (executable)
@@ -35,7 +35,6 @@
 #include <dali/devel-api/adaptor-framework/web-engine-http-auth-handler.h>
 #include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
 #include <dali/devel-api/adaptor-framework/web-engine-policy-decision.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>
@@ -611,11 +610,6 @@ void WebEngine::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngi
   mPlugin->RegisterFormRepostDecidedCallback(callback);
 }
 
-void WebEngine::RegisterRequestInterceptorCallback(Dali::WebEnginePlugin::WebEngineRequestInterceptorCallback callback)
-{
-  mPlugin->RegisterRequestInterceptorCallback(callback);
-}
-
 void WebEngine::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
 {
   mPlugin->RegisterConsoleMessageReceivedCallback(callback);
index c3ad4d0..73e311b 100755 (executable)
@@ -495,11 +495,6 @@ public:
   void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
 
   /**
-   * @copydoc Dali::WebEngine::RegisterRequestInterceptorCallback()
-   */
-  void RegisterRequestInterceptorCallback(Dali::WebEnginePlugin::WebEngineRequestInterceptorCallback callback);
-
-  /**
    @copydoc Dali::WebEngine::RegisterConsoleMessageReceivedCallback()
    */
   void RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback);