Implement WebEngine::GetPlainTextAsynchronously
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / web-engine-plugin.h
index ad74323..07daee3 100755 (executable)
  */
 
 // EXTERNAL INCLUDES
+#include <functional>
+#include <memory>
+
+// INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/web-engine-hit-test.h>
 #include <dali/devel-api/common/bitwise-enum.h>
 #include <dali/public-api/images/native-image-interface.h>
 #include <dali/public-api/math/rect.h>
 #include <dali/public-api/signals/dali-signal.h>
-#include <functional>
-#include <memory>
 
 namespace Dali
 {
@@ -36,9 +39,9 @@ class WebEngineCertificate;
 class WebEngineConsoleMessage;
 class WebEngineContext;
 class WebEngineContextMenu;
-class WebEngineContextMenuItem;
 class WebEngineCookieManager;
 class WebEngineFormRepostDecision;
+class WebEngineHitTest;
 class WebEngineHttpAuthHandler;
 class WebEngineLoadError;
 class WebEnginePolicyDecision;
@@ -55,35 +58,40 @@ class WebEnginePlugin
 {
 public:
   /**
-   * @brief WebEngine signal type related with page loading.
+   * @brief WebView signal type related with frame rendered.
+   */
+  using WebEngineFrameRenderedSignalType = Signal<void(void)>;
+
+  /**
+   * @brief WebEngine callback related with page loading.
    */
-  using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
+  using WebEnginePageLoadCallback = std::function<void(const std::string&)>;
 
   /**
-   * @brief WebView signal type related with page loading error.
+   * @brief WebView callback related with page loading error.
    */
-  using WebEnginePageLoadErrorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineLoadError>)>;
+  using WebEnginePageLoadErrorCallback = std::function<void(std::unique_ptr<Dali::WebEngineLoadError>)>;
 
   // forward declaration.
   enum class ScrollEdge;
 
   /**
-   * @brief WebView signal type related with scroll edge reached.
+   * @brief WebView callback related with scroll edge reached.
    */
-  using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
+  using WebEngineScrollEdgeReachedCallback = std::function<void(const ScrollEdge)>;
 
   /**
-   * @brief WebView signal type related with page url changed.
+   * @brief WebView callback related with page url changed.
    */
-  using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
+  using WebEngineUrlChangedCallback = std::function<void(const std::string&)>;
 
   /**
-   * @brief WebView signal type related with screen captured.
+   * @brief WebView callback related with screen captured.
    */
   using ScreenshotCapturedCallback = std::function<void(Dali::PixelData)>;
 
   /**
-   * @brief WebView signal type related with geolocation permission.
+   * @brief WebView callback related with geolocation permission.
    *  Host and protocol of security origin will be provided when requesting
    *  geolocation permission.
    *  It returns true if a pop-up is created successfully, false otherwise.
@@ -91,39 +99,44 @@ public:
   using GeolocationPermissionCallback = std::function<bool(const std::string&, const std::string&)>;
 
   /**
-   * @brief WebView signal type related with video playing.
+   * @brief WebView callback related with video playing.
    */
   using VideoPlayingCallback = std::function<void(bool)>;
 
   /**
-   * @brief WebView signal type related with http request interceptor.
+   * @brief WebView callback related with http request interceptor.
    */
-  using WebEngineRequestInterceptorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineRequestInterceptor>)>;
+  using WebEngineRequestInterceptorCallback = std::function<void(std::unique_ptr<Dali::WebEngineRequestInterceptor>)>;
 
   /**
-   * @brief WebView signal type related with console message will be logged.
+   * @brief WebView callback related with console message logged.
    */
-  using WebEngineConsoleMessageSignalType = Signal<void(std::shared_ptr<Dali::WebEngineConsoleMessage>)>;
+  using WebEngineConsoleMessageReceivedCallback = std::function<void(std::unique_ptr<Dali::WebEngineConsoleMessage>)>;
 
   /**
-   * @brief WebView signal type related with certificate changed.
+   * @brief WebView callback related with certificate changed.
    */
-  using WebEngineCertificateSignalType = Signal<void(std::shared_ptr<Dali::WebEngineCertificate>)>;
+  using WebEngineCertificateCallback = std::function<void(std::unique_ptr<Dali::WebEngineCertificate>)>;
 
   /**
-   * @brief WebView signal type related with http authentication.
+   * @brief WebView callback related with http authentication.
    */
-  using WebEngineHttpAuthHandlerSignalType = Signal<void(std::shared_ptr<Dali::WebEngineHttpAuthHandler>)>;
+  using WebEngineHttpAuthHandlerCallback = std::function<void(std::unique_ptr<Dali::WebEngineHttpAuthHandler>)>;
 
   /**
-   * @brief WebView signal type related with context menu customized.
+   * @brief WebView callback related with context menu shown.
    */
-  using WebEngineContextMenuCustomizedSignalType = Signal<void(std::shared_ptr<Dali::WebEngineContextMenu>)>;
+  using WebEngineContextMenuShownCallback = std::function<void(std::unique_ptr<Dali::WebEngineContextMenu>)>;
 
   /**
-   * @brief WebView signal type related with context menu item selected.
+   * @brief WebView callback related with context menu hidden.
    */
-  using WebEngineContextMenuItemSelectedSignalType = Signal<void(std::shared_ptr<Dali::WebEngineContextMenuItem>)>;
+  using WebEngineContextMenuHiddenCallback = std::function<void(std::unique_ptr<Dali::WebEngineContextMenu>)>;
+
+  /**
+   * @brief Message result callback when JavaScript is executed with a message.
+   */
+  using JavaScriptMessageHandlerCallback = std::function<void(const std::string&)>;
 
   /**
    * @brief Alert callback when JavaScript alert is called with a message.
@@ -145,19 +158,29 @@ public:
   using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
 
   /**
-   * @brief WebView signal type related with form repost decision.
+   * @brief WebView callback related with form repost decision.
    */
-  using WebEngineFormRepostDecisionSignalType = Signal<void(std::shared_ptr<Dali::WebEngineFormRepostDecision>)>;
+  using WebEngineFormRepostDecidedCallback = std::function<void(std::unique_ptr<Dali::WebEngineFormRepostDecision>)>;
 
   /**
-   * @brief WebView signal type related with frame rendered.
+   * @brief WebView callback related with frame rendered.
    */
-  using WebEngineFrameRenderedSignalType = Signal<void(void)>;
+  using WebEngineFrameRenderedCallback = std::function<void(void)>;
+
+  /**
+   * @brief WebView callback related with response policy would be decided.
+   */
+  using WebEngineResponsePolicyDecidedCallback = std::function<void(std::unique_ptr<Dali::WebEnginePolicyDecision>)>;
+
+  /**
+   * @brief Hit test callback called after hit test is created asynchronously.
+   */
+  using WebEngineHitTestCreatedCallback = std::function<bool(std::unique_ptr<Dali::WebEngineHitTest>)>;
 
   /**
-   * @brief WebView signal type related with policy would be decided.
+   * @brief The callback to be called when the web engine received a plain text of current web page.
    */
-  using WebEnginePolicyDecisionSignalType = Signal<void(std::shared_ptr<Dali::WebEnginePolicyDecision>)>;
+  using PlainTextReceivedCallback = std::function<void(const std::string&)>;
 
   /**
    * @brief Enumeration for the scroll edge.
@@ -204,7 +227,7 @@ public:
    * @param [in] locale The locale of Web
    * @param [in] timezoneId The timezoneID of Web
    */
-  virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
+  virtual void Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneId) = 0;
 
   /**
    * @brief Create WebEngine instance.
@@ -214,7 +237,7 @@ public:
    * @param [in] argc The count of application arguments
    * @param [in] argv The string array of application arguments
    */
-  virtual void Create(int width, int height, int argc, char** argv) = 0;
+  virtual void Create(uint32_t width, uint32_t height, uint32_t argc, char** argv) = 0;
 
   /**
    * @brief Destroy WebEngine instance.
@@ -272,7 +295,7 @@ public:
    *
    * @return Url of string type
    */
-  virtual const std::string& GetUrl() = 0;
+  virtual std::string GetUrl() const = 0;
 
   /**
    * @brief Load a given string as web contents.
@@ -381,7 +404,7 @@ public:
    * @param[in] deltaX horizontal offset to scroll
    * @param[in] deltaY vertical offset to scroll
    */
-  virtual void ScrollBy(int deltaX, int deltaY) = 0;
+  virtual void ScrollBy(int32_t deltaX, int32_t deltaY) = 0;
 
   /**
    * @brief Scroll edge of view by deltaX and deltaY.
@@ -391,12 +414,12 @@ public:
    *
    * @return true if succeeded, false otherwise
    */
-  virtual bool ScrollEdgeBy(int deltaX, int deltaY) = 0;
+  virtual bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY) = 0;
 
   /**
    * @brief Scroll to the specified position of the given view.
    */
-  virtual void SetScrollPosition(int x, int y) = 0;
+  virtual void SetScrollPosition(int32_t x, int32_t y) = 0;
 
   /**
    * @brief Get the current scroll position of the given view.
@@ -443,7 +466,7 @@ public:
    * @param[in] script The JavaScript code
    * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
    */
-  virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
+  virtual void EvaluateJavaScript(const std::string& script, JavaScriptMessageHandlerCallback resultHandler) = 0;
 
   /**
    * @brief Add a message handler into JavaScript.
@@ -451,7 +474,7 @@ public:
    * @param[in] exposedObjectName The name of exposed object
    * @param[in] handler The callback function
    */
-  virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
+  virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, JavaScriptMessageHandlerCallback handler) = 0;
 
   /**
    * @brief Register a callback for JavaScript alert.
@@ -490,6 +513,29 @@ public:
   virtual void JavaScriptPromptReply(const std::string& result) = 0;
 
   /**
+   * @brief Create a new hit test.
+   *
+   * @param[in] x the horizontal position to query
+   * @param[in] y the vertical position to query
+   * @param[in] mode the mode of hit test
+   *
+   * @return a new hit test object.
+   */
+  virtual std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) = 0;
+
+  /**
+   * @brief create a hit test asynchronously.
+   *
+   * @param[in] x the horizontal position to query
+   * @param[in] y the vertical position to query
+   * @param[in] mode the mode of hit test
+   * @param[in] callback The callback function
+   *
+   * @return true if succeeded, false otherwise
+   */
+  virtual bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, WebEngineHitTestCreatedCallback callback) = 0;
+
+  /**
    * @brief Clear the history of Web.
    */
   virtual void ClearHistory() = 0;
@@ -504,7 +550,7 @@ public:
    *
    * @return The string value of user agent
    */
-  virtual const std::string& GetUserAgent() const = 0;
+  virtual std::string GetUserAgent() const = 0;
 
   /**
    * @brief Set user agent string.
@@ -516,7 +562,7 @@ public:
   /**
    * @brief Set size of Web Page.
    */
-  virtual void SetSize(int width, int height) = 0;
+  virtual void SetSize(uint32_t width, uint32_t height) = 0;
 
   /**
    * @brief Set background color of web page.
@@ -663,7 +709,7 @@ public:
    *
    * @return pixel data of screen shot
    */
-  virtual Dali::PixelData GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor) = 0;
+  virtual Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor) = 0;
 
   /**
    * @brief Request to get snapshot of the specified viewArea of page asynchronously.
@@ -674,7 +720,7 @@ public:
    *
    * @return true if requested successfully, false otherwise
    */
-  virtual bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, ScreenshotCapturedCallback callback) = 0;
+  virtual bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, ScreenshotCapturedCallback callback) = 0;
 
   /**
    * @brief Asynchronously request to check if there is a video playing in the given view.
@@ -696,7 +742,7 @@ public:
    * @brief Update display area.
    * @param[in] displayArea The display area need be updated.
    */
-  virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
+  virtual void UpdateDisplayArea(Dali::Rect<int32_t> displayArea) = 0;
 
   /**
    * @brief Enable video hole.
@@ -717,116 +763,123 @@ public:
   virtual bool SendWheelEvent(const WheelEvent& event) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when page loading is started.
+   * @brief Connect to this signal to be notified when frame is rendered.
    *
    * @return A signal object to connect with.
    */
-  virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
+  virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;
 
   /**
-   * @brief Connect to this signal to be notified when page loading is in progress.
+   * @brief Callback to be called when page loading is started.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
+  virtual void RegisterPageLoadStartedCallback(WebEnginePageLoadCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when page loading is finished.
+   * @brief Callback to be called when page loading is in progress.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
+  virtual void RegisterPageLoadInProgressCallback(WebEnginePageLoadCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when an error occurs in page loading.
+   * @brief Callback to be called when page loading is finished.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
+  virtual void RegisterPageLoadFinishedCallback(WebEnginePageLoadCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when scroll edge is reached.
+   * @brief Callback to be called when an error occurs in page loading.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
+  virtual void RegisterPageLoadErrorCallback(WebEnginePageLoadErrorCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when url is changed.
+   * @brief Callback to be called when scroll edge is reached.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;
+  virtual void RegisterScrollEdgeReachedCallback(WebEngineScrollEdgeReachedCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when form repost decision is requested.
+   * @brief Callback to be called when url is changed.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal() = 0;
+  virtual void RegisterUrlChangedCallback(WebEngineUrlChangedCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when frame is rendered.
+   * @brief Callback to be called when form repost decision is requested.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;
+  virtual void RegisterFormRepostDecidedCallback(WebEngineFormRepostDecidedCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when http request need be intercepted.
+   * @brief Callback to be called when http request need be intercepted.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEngineRequestInterceptorSignalType& RequestInterceptorSignal() = 0;
+  virtual void RegisterRequestInterceptorCallback(WebEngineRequestInterceptorCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when console message will be logged.
+   * @brief Callback to be called when console message will be logged.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEngineConsoleMessageSignalType& ConsoleMessageSignal() = 0;
+  virtual void RegisterConsoleMessageReceivedCallback(WebEngineConsoleMessageReceivedCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when new policy would be decided.
+   * @brief Callback to be called when response policy would be decided.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEnginePolicyDecisionSignalType& PolicyDecisionSignal() = 0;
+  virtual void RegisterResponsePolicyDecidedCallback(WebEngineResponsePolicyDecidedCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when certificate need be confirmed.
+   * @brief Callback to be called when certificate need be confirmed.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEngineCertificateSignalType& CertificateConfirmSignal() = 0;
+  virtual void RegisterCertificateConfirmedCallback(WebEngineCertificateCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when ssl certificate is changed.
+   * @brief Callback to be called when ssl certificate is changed.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEngineCertificateSignalType& SslCertificateChangedSignal() = 0;
+  virtual void RegisterSslCertificateChangedCallback(WebEngineCertificateCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when http authentication need be confirmed.
+   * @brief Callback to be called when http authentication need be confirmed.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEngineHttpAuthHandlerSignalType& HttpAuthHandlerSignal() = 0;
+  virtual void RegisterHttpAuthHandlerCallback(WebEngineHttpAuthHandlerCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when context menu would be customized.
+   * @brief Callback to be called when context menu would be shown.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
    */
-  virtual WebEngineContextMenuCustomizedSignalType& ContextMenuCustomizedSignal() = 0;
+  virtual void RegisterContextMenuShownCallback(WebEngineContextMenuShownCallback callback) = 0;
 
   /**
-   * @brief Connect to this signal to be notified when context menu item is selected.
+   * @brief Callback to be called when context menu would be hidden.
    *
-   * @return A signal object to connect with.
+   * @param[in] callback
+   */
+  virtual void RegisterContextMenuHiddenCallback(WebEngineContextMenuHiddenCallback callback) = 0;
+
+  /**
+   * @brief Get a plain text of current web page asynchronously.
+   *
+   * @param[in] callback The callback function called asynchronously.
    */
-  virtual WebEngineContextMenuItemSelectedSignalType& ContextMenuItemSelectedSignal() = 0;
+  virtual void GetPlainTextAsynchronously(PlainTextReceivedCallback callback) = 0;
 };
 
 // specialization has to be done in the same namespace