class WebEngineHttpAuthHandler;
class WebEngineLoadError;
class WebEnginePolicyDecision;
-class WebEngineRequestInterceptor;
class WebEngineSettings;
class HoverEvent;
class WheelEvent;
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>)>;
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
*/
// 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
/**
* @brief A class WebEngineRequestInterceptor for intercepting http request.
*/
-class WebEngineRequestInterceptor
+class WebEngineRequestInterceptor : public RefObject
{
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;
* @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;
* @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
#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>
mPlugin->RegisterFormRepostDecidedCallback(callback);
}
-void WebEngine::RegisterRequestInterceptorCallback(Dali::WebEnginePlugin::WebEngineRequestInterceptorCallback callback)
-{
- mPlugin->RegisterRequestInterceptorCallback(callback);
-}
-
void WebEngine::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
{
mPlugin->RegisterConsoleMessageReceivedCallback(callback);