Add APIs to show javascript popup in web engine.
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / web-engine-plugin.h
old mode 100755 (executable)
new mode 100644 (file)
index c3b9389..373b59d
@@ -2,7 +2,7 @@
 #define DALI_WEB_ENGINE_PLUGIN_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * 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.
 
 // EXTERNAL INCLUDES
 #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>
 
 namespace Dali
 {
 class KeyEvent;
+class PixelData;
 class TouchEvent;
+class WebEngineBackForwardList;
+class WebEngineContext;
+class WebEngineCookieManager;
+class WebEngineSettings;
 
 /**
  * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
@@ -38,12 +44,12 @@ public:
   /**
    * @brief WebEngine signal type related with page loading.
    */
-  typedef Signal<void(const std::string&)> WebEnginePageLoadSignalType;
+  using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
 
   /**
    * @brief WebView signal type related with page loading error.
    */
-  typedef Signal<void(const std::string&, int)> WebEnginePageLoadErrorSignalType;
+  using WebEnginePageLoadErrorSignalType = Signal<void(const std::string&, int)>;
 
   // forward declaration.
   enum class ScrollEdge;
@@ -51,49 +57,31 @@ public:
   /**
    * @brief WebView signal type related with scroll edge reached.
    */
-  typedef Signal< void( const ScrollEdge )> WebEngineScrollEdgeReachedSignalType;
+  using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
 
   /**
-   * @brief Enumeration for cache model options.
+   * @brief WebView signal type related with page url changed.
    */
-  enum class CacheModel
-  {
-    /**
-     * @brief Use the smallest cache capacity.
-     */
-    DOCUMENT_VIEWER,
-
-    /**
-     * @brief Use the bigger cache capacity than DocumentBrowser.
-     */
-    DOCUMENT_BROWSER,
-
-    /**
-     * @brief Use the biggest cache capacity.
-     */
-    PRIMARY_WEB_BROWSER
-  };
+  using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
 
   /**
-   * @brief Enumeration for the cookies accept policies.
+   * @brief Alert callback when JavaScript alert is called with a message.
+   *  It returns true if a pop-up is created successfully, false otherwise.
    */
-  enum class CookieAcceptPolicy
-  {
-    /**
-     * @brief Accepts every cookie sent from any page.
-     */
-    ALWAYS,
-
-    /**
-     * @brief Rejects all the cookies.
-     */
-    NEVER,
-
-    /**
-     * @brief Accepts only cookies set by the main document that is loaded.
-     */
-    NO_THIRD_PARTY
-  };
+  using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
+
+  /**
+   * @brief Confirm callback when JavaScript confirm is called with a message.
+   *  It returns true if a pop-up is created successfully, false otherwise.
+   */
+  using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
+
+  /**
+   * @brief Prompt callback when JavaScript prompt is called with a message
+   *  and an optional value that is the default value for the input field.
+   *  It returns true if a pop-up is created successfully, false otherwise.
+   */
+  using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
 
   /**
    * @brief Enumeration for the scroll edge.
@@ -127,11 +115,41 @@ public:
   virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
 
   /**
+   * @brief Creates WebEngine instance.
+   *
+   * @param [in] width The width of Web
+   * @param [in] height The height of Web
+   * @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;
+
+  /**
    * @brief Destroys WebEngine instance.
    */
   virtual void Destroy() = 0;
 
   /**
+   * @brief Get settings of WebEngine.
+   */
+  virtual WebEngineSettings& GetSettings() const = 0;
+
+  /**
+   * @brief Get context of WebEngine.
+   */
+  virtual WebEngineContext& GetContext() const = 0;
+
+  /**
+   * @brief Get cookie manager of WebEngine.
+   */
+  virtual WebEngineCookieManager& GetCookieManager() const = 0;
+
+  /**
+   * @brief Get back-forward list of WebEngine.
+   */
+  virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
+
+  /**
    * @brief Loads a web page based on a given URL.
    *
    * @param [in] url The URL of the resource to load
@@ -139,6 +157,20 @@ public:
   virtual void LoadUrl(const std::string& url) = 0;
 
   /**
+   * @brief Returns the title of the Web.
+   *
+   * @return The title of web page
+   */
+  virtual std::string GetTitle() const = 0;
+
+  /**
+   * @brief Returns the Favicon of the Web.
+   *
+   * @return Favicon of Dali::PixelData& type
+   */
+  virtual Dali::PixelData GetFavicon() const = 0;
+
+  /**
    * @brief Gets image to render.
    */
   virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
@@ -155,7 +187,7 @@ public:
    *
    * @param [in] htmlString The string to use as the contents of the web page
    */
-  virtual void LoadHTMLString(const std::string& htmlString) = 0;
+  virtual void LoadHtmlString(const std::string& htmlString) = 0;
 
   /**
    * @brief Reloads the Web.
@@ -180,27 +212,27 @@ public:
   /**
    * @brief Scrolls the webpage of view by deltaX and deltaY.
    */
-  virtual void ScrollBy( int deltaX, int deltaY ) = 0;
+  virtual void ScrollBy(int deltaX, int deltaY) = 0;
 
   /**
    * @brief Scroll to the specified position of the given view.
    */
-  virtual void SetScrollPosition( int x, int y ) = 0;
+  virtual void SetScrollPosition(int x, int y) = 0;
 
   /**
    * @brief Gets the current scroll position of the given view.
    */
-  virtual void GetScrollPosition( int& x, int& y ) const = 0;
+  virtual Dali::Vector2 GetScrollPosition() const = 0;
 
   /**
    * @brief Gets the possible scroll size of the given view.
    */
-  virtual void GetScrollSize( int& width, int& height ) const = 0;
+  virtual Dali::Vector2 GetScrollSize() const = 0;
 
   /**
    * @brief Gets the last known content's size.
    */
-  virtual void GetContentSize( int& width, int& height ) const = 0;
+  virtual Dali::Vector2 GetContentSize() const = 0;
 
   /**
    * @brief Returns whether forward is possible.
@@ -243,47 +275,50 @@ public:
   virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
 
   /**
-   * @brief Clears the history of Web.
+   * @brief Register a callback for JavaScript alert.
+   *
+   * @param[in] callback The callback function
    */
-  virtual void ClearHistory() = 0;
+  virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
 
   /**
-   * @brief Clears the cache of Web.
+   * @brief Reply for JavaScript alert.
    */
-  virtual void ClearCache() = 0;
+  virtual void JavaScriptAlertReply() = 0;
 
   /**
-   * @brief Clears all the cookies of Web.
+   * @brief Register a callback for JavaScript confirm.
+   *
+   * @param[in] callback The callback function
    */
-  virtual void ClearCookies() = 0;
+  virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
 
   /**
-   * @brief Get cache model option. The default is DOCUMENT_VIEWER.
-   *
-   * @return The cache model option
+   * @brief Reply for JavaScript confirm.
    */
-  virtual CacheModel GetCacheModel() const = 0;
+  virtual void JavaScriptConfirmReply( bool confirmed ) = 0;
 
   /**
-   * @brief Set cache model option. The default is DOCUMENT_VIEWER.
+   * @brief Register a callback for JavaScript prompt.
    *
-   * @param[in] cacheModel The cache model option
+   * @param[in] callback The callback function
    */
-  virtual void SetCacheModel(CacheModel cacheModel) = 0;
+  virtual void RegisterJavaScriptPromptCallback( JavaScriptPromptCallback callback ) = 0;
 
   /**
-   * @brief Gets the cookie acceptance policy. The default is NO_THIRD_PARTY.
-   *
-   * @return The cookie acceptance policy
+   * @brief Reply for JavaScript prompt.
    */
-  virtual CookieAcceptPolicy GetCookieAcceptPolicy() const = 0;
+  virtual void JavaScriptPromptReply( const std::string& result ) = 0;
 
   /**
-   * @brief Sets the cookie acceptance policy. The default is NO_THIRD_PARTY.
-   *
-   * @param[in] policy The cookie acceptance policy
+   * @brief Clears the history of Web.
+   */
+  virtual void ClearHistory() = 0;
+
+  /**
+   * @brief Clears all tiles resources of Web.
    */
-  virtual void SetCookieAcceptPolicy(CookieAcceptPolicy policy) = 0;
+  virtual void ClearAllTilesResources() = 0;
 
   /**
    * @brief Get user agent string.
@@ -300,87 +335,50 @@ public:
   virtual void SetUserAgent(const std::string& userAgent) = 0;
 
   /**
-   * @brief Returns whether JavaScript can be executable. The default is true.
-   *
-   * @return true if JavaScript executing is enabled, false otherwise
-   */
-  virtual bool IsJavaScriptEnabled() const = 0;
-
-  /**
-   * @brief Enables/disables JavaScript executing. The default is enabled.
-   *
-   * @param[in] enabled True if JavaScript executing is enabled, false otherwise
+   * @brief Sets size of Web Page.
    */
-  virtual void EnableJavaScript(bool enabled) = 0;
+  virtual void SetSize(int width, int height) = 0;
 
   /**
-   * @brief Returns whether images can be loaded automatically. The default is true.
-   *
-   * @return true if images are loaded automatically, false otherwise
+   * @brief Sends Touch Events.
    */
-  virtual bool AreImagesAutomaticallyLoaded() const = 0;
+  virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
 
   /**
-   * @brief Enables/disables auto loading of images. The default is enabled.
-   *
-   * @param[in] automatic True if images are loaded automatically, false otherwise
+   * @brief Sends Key Events.
    */
-  virtual void LoadImagesAutomatically(bool automatic) = 0;
+  virtual bool SendKeyEvent(const KeyEvent& event) = 0;
 
   /**
-   * @brief Gets the default text encoding name (e.g. UTF-8).
-   *
-   * @return The default text encoding name
+   * @brief Sets focus.
    */
-  virtual const std::string& GetDefaultTextEncodingName() const = 0;
+  virtual void SetFocus(bool focused) = 0;
 
   /**
-   * @brief Sets the default text encoding name (e.g. UTF-8).
-   *
-   * @param[in] defaultTextEncodingName The default text encoding name
+   * @brief Update display area.
+   * @param[in] displayArea The display area need be updated.
    */
-  virtual void SetDefaultTextEncodingName(const std::string& defaultTextEncodingName) = 0;
+  virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
 
   /**
-   * @brief Returns the default font size in pixel. The default value is 16.
-   *
-   * @return The default font size
+   * @brief Enable video hole.
+   * @param[in] enabled True if enabled, false othewise.
    */
-  virtual int GetDefaultFontSize() const = 0;
+  virtual void EnableVideoHole(bool enabled) = 0;
 
   /**
-   * @brief Sets the default font size in pixel. The default value is 16.
+   * @brief Connects to this signal to be notified when page loading is started.
    *
-   * @param[in] defaultFontSize A new default font size to set
-   */
-  virtual void SetDefaultFontSize(int defaultFontSize) = 0;
-
-  /**
-   * @brief Sets size of Web Page.
-   */
-  virtual void SetSize(int width, int height) = 0;
-
-  /**
-   * @brief Sends Touch Events.
-   */
-  virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
-
-  /**
-   * @brief Sends Key Events.
-   */
-  virtual bool SendKeyEvent(const KeyEvent& event) = 0;
-
-  /**
-   * @brief Sets focus.
+   * @return A signal object to connect with.
    */
-  virtual void SetFocus( bool focused ) = 0;
+  virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
 
   /**
-   * @brief Connects to this signal to be notified when page loading is started.
+   * @brief Connects to this signal to be notified when page loading is in progress.
    *
    * @return A signal object to connect with.
    */
-  virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
+  virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
 
   /**
    * @brief Connects to this signal to be notified when page loading is finished.
@@ -402,6 +400,14 @@ public:
    * @return A signal object to connect with.
    */
   virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
+
+  /**
+   * @brief Connects to this signal to be notified when url is changed.
+   *
+   * @return A signal object to connect with.
+   */
+  virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;
+
 };
 
 } // namespace Dali