Support scroll in web view.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / web-view / web-view.h
old mode 100644 (file)
new mode 100755 (executable)
index 71d05d3..f447eda
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_WEB_VIEW_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
 #include <functional>
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
 #include <dali-toolkit/public-api/controls/control.h>
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Internal DALI_INTERNAL
 {
-  class WebView;
-} // namespace Internal
+class WebView;
+} // namespace DALI_INTERNAL
 
 /**
  * @addtogroup dali_toolkit_controls_web_view
@@ -51,6 +50,59 @@ namespace Internal DALI_INTERNAL
 class DALI_TOOLKIT_API WebView : public Control
 {
 public:
+  /**
+   * @brief A structure used to contain the cache model enumeration.
+   */
+  struct CacheModel
+  {
+    /**
+     * @brief Enumeration for cache model options.
+     */
+    enum Type
+    {
+      /**
+       * @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
+    };
+  };
+
+  /**
+   * @brief A structure used to contain the cookie acceptance policy enumeration.
+   */
+  struct CookieAcceptPolicy
+  {
+    /**
+     * @brief Enumeration for the cookies accept policies.
+     */
+    enum Type
+    {
+      /**
+       * @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
+    };
+  };
 
   /**
    * @brief Enumeration for the start and end property ranges for this control.
@@ -58,7 +110,7 @@ public:
   enum PropertyRange
   {
     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
-    PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000,
+    PROPERTY_END_INDEX   = PROPERTY_START_INDEX + 1000,
   };
 
   /**
@@ -69,19 +121,179 @@ public:
     enum
     {
       /**
-       * @brief name "url", type string
-       *
-       * @details Sets the url to load
+       * @brief The url to load.
+       * @details name "url", type Property::STRING.
+       */
+      URL = PROPERTY_START_INDEX,
+
+      /**
+       * @brief The cache model.
+       * @details Name "cacheModel", type WebView::CacheModel::Type (Property::INTEGER) or Property::STRING.
+       * @note Default is WebView::CacheModel::DOCUMENT_VIEWER.
+       * @see WebView::CacheModel::Type
+       */
+      CACHE_MODEL,
+
+      /**
+       * @brief The cookie acceptance policy.
+       * @details Name "cookieAcceptPolicy", type WebView::CookieAcceptPolicy::Type (Property::INTEGER) or Property::STRING.
+       * @note Default is WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
+       * @see WebView::CookieAcceptPolicy::Type
+       */
+      COOKIE_ACCEPT_POLICY,
+
+      /**
+       * @brief The user agent string.
+       * @details Name "userAgent", type Property::STRING.
+       */
+      USER_AGENT,
+
+      /**
+       * @brief Whether JavaScript is enabled.
+       * @details Name "enableJavaScript", type Property::BOOLEAN.
+       * @note Default is true.
+       */
+      ENABLE_JAVASCRIPT,
+
+      /**
+       * @brief Whether images can be loaded automatically.
+       * @details Name "loadImagesAutomatically", type Property::BOOLEAN.
+       * @note Default is true.
+       */
+      LOAD_IMAGES_AUTOMATICALLY,
+
+      /**
+       * @brief The default text encoding name.
+       * @details Name "defaultTextEncodingName", type Property::STRING.
+       * @note If the value is not set, the web engine detects web page's text encoding.
+       */
+      DEFAULT_TEXT_ENCODING_NAME,
+
+      /**
+       * @brief The default font size in pixel.
+       * @details Name "defaultFontSize", type Property::INT.
+       * @note Default is 16.
+       */
+      DEFAULT_FONT_SIZE,
+
+      /**
+       * @brief The current position of scroll.
+       * @details Name "scrollPosition", type Property::VECTOR2.
+       */
+      SCROLL_POSITION,
+
+      /**
+       * @brief The current position of scroll.
+       * @details Name "scrollSize", type Property::VECTOR2. Read-only.
        */
-      URL = PROPERTY_START_INDEX
+      SCROLL_SIZE,
+
+      /**
+       * @brief The current position of scroll.
+       * @details Name "contentSize", type Property::VECTOR2. Read-only.
+       */
+      CONTENT_SIZE,
     };
   };
 
-  typedef Signal< void ( WebView, const std::string& ) > WebViewSignalType;
+  /**
+   * @brief Enumeration for indicating error code of page loading.
+   */
+  enum class LoadErrorCode
+  {
+    /**
+     * @brief Unknown.
+     */
+    UNKNOWN = 0,
+
+    /**
+     * @brief User canceled.
+     */
+    CANCELED,
+
+    /**
+     * @brief Can't show the page for this MIME type.
+     */
+    CANT_SUPPORT_MIMETYPE,
+
+    /**
+     * @brief File IO error.
+     */
+    FAILED_FILE_IO,
+
+    /**
+     * @brief Cannot connect to the network.
+     */
+    CANT_CONNECT,
+
+    /**
+     * @brief Fail to look up host from the DNS.
+     */
+    CANT_LOOKUP_HOST,
+
+    /**
+     * @brief Fail to SSL/TLS handshake.
+     */
+    FAILED_TLS_HANDSHAKE,
+
+    /**
+     * @brief Received certificate is invalid.
+     */
+    INVALID_CERTIFICATE,
+
+    /**
+     * @brief Connection timeout.
+     */
+    REQUEST_TIMEOUT,
+
+    /**
+     * @brief Too many redirects.
+     */
+    TOO_MANY_REDIRECTS,
+
+    /**
+     * @brief Too many requests during this load.
+     */
+    TOO_MANY_REQUESTS,
+
+    /**
+     * @brief Malformed URL.
+     */
+    BAD_URL,
+
+    /**
+     * @brief Unsupported scheme.
+     */
+    UNSUPPORTED_SCHEME,
+
+    /**
+     * @brief User authentication failed on the server.
+     */
+    AUTHENTICATION,
+
+    /**
+     * @brief Web server has an internal server error.
+     */
+    INTERNAL_SERVER
+  };
 
-public:
+  /**
+   * @brief WebView signal type related with page loading.
+   */
+  typedef Signal<void(WebView, const std::string&)> WebViewPageLoadSignalType;
 
   /**
+   * @brief WebView signal type related with page loading error.
+   */
+  typedef Signal<void(WebView, const std::string&, LoadErrorCode)> WebViewPageLoadErrorSignalType;
+
+  /**
+   * @brief WebView signal type related with scroll edge reached.
+   */
+  typedef Signal<void(WebView, Dali::WebEnginePlugin::ScrollEdge)> WebViewScrollEdgeReachedSignalType;
+
+public:
+  /**
    * @brief Creates an initialized WebView.
    * @return A handle to a newly allocated Dali WebView
    *
@@ -95,7 +307,7 @@ public:
    * @param [in] locale The locale of Web
    * @param [in] timezoneId The timezoneId of Web
    */
-  static WebView New( const std::string& locale, const std::string& timezoneId );
+  static WebView New(const std::string& locale, const std::string& timezoneId);
 
   /**
    * @brief Creates an uninitialized WebView.
@@ -114,7 +326,7 @@ public:
    *
    * @param[in] WebView WebView to copy. The copied WebView will point at the same implementation
    */
-  WebView( const WebView& WebView );
+  WebView(const WebView& WebView);
 
   /**
    * @brief Assignment operator.
@@ -122,7 +334,7 @@ public:
    * @param[in] WebView The WebView to assign from
    * @return The updated WebView
    */
-  WebView& operator=( const WebView& WebView );
+  WebView& operator=(const WebView& WebView);
 
   /**
    * @brief Downcasts a handle to WebView handle.
@@ -133,28 +345,21 @@ public:
    * @param[in] handle Handle to an object
    * @return Handle to a WebView or an uninitialized handle
    */
-  static WebView DownCast( BaseHandle handle );
+  static WebView DownCast(BaseHandle handle);
 
   /**
    * @brief Loads a web page based on a given URL.
    *
    * @param [in] url The URL of the resource to load
    */
-  void LoadUrl( const std::string& url );
-
-  /**
-   * @brief Returns the URL of the Web.
-   *
-   * @return Url of string type
-   */
-  const std::string& GetUrl();
+  void LoadUrl(const std::string& url);
 
   /**
    * @brief Loads a given string as web contents.
    *
    * @param [in] htmlString The string to use as the contents of the web page
    */
-  void LoadHTMLString( const std::string& htmlString );
+  void LoadHTMLString(const std::string& htmlString);
 
   /**
    * @brief Reloads the Web.
@@ -167,6 +372,23 @@ public:
   void StopLoading();
 
   /**
+   * @brief Suspends the operation associated with the view.
+   */
+  void Suspend();
+
+  /**
+   * @brief Resumes the operation associated with the view object after calling Suspend().
+   */
+  void Resume();
+
+  /**
+   * @brief Scrolls the webpage of view by deltaX and deltaY.
+   * @param[in] deltaX The delta x of scroll
+   * @param[in] deltaY The delta y of scroll
+   */
+  void ScrollBy( int deltaX, int deltaY );
+
+  /**
    * @brief Returns whether forward is possible.
    *
    * @return True if forward is possible, false otherwise
@@ -191,28 +413,45 @@ public:
   void GoBack();
 
   /**
-    * @brief Evaluates JavaScript code represented as a string.
-    *
-    * @param[in] script The JavaScript code
-    */
-  void EvaluateJavaScript( const std::string& script );
+   * @brief Evaluates JavaScript code represented as a string.
+   *
+   * @param[in] script The JavaScript code
+   * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
+   */
+  void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
 
   /**
-    * @brief Adds a JavaScript interface.
-    *
-    * @param[in] exposedObjectName The name of exposed object
-    * @param[in] jsFunctionName The name of JavaScript function
-    * @param[in] callback The callback function
-    */
-  void AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > callback );
+   * @brief Evaluates JavaScript code represented as a string.
+   *
+   * @param[in] script The JavaScript code
+   */
+  void EvaluateJavaScript(const std::string& script);
 
   /**
-    * @brief Removes a JavaScript interface.
-    *
-    * @param[in] exposedObjectName The name of exposed object
-    * @param[in] jsFunctionName The name of JavaScript function
-    */
-  void RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName );
+   * @brief Inject a JavaScript object with a message handler into the WebView.
+   *
+   * @note The injected object will appear in the JavaScript context to be loaded next.
+   *
+   * Example:
+   *
+   * 1. Native
+   *
+   *     webview.AddJavaScriptMessageHandler( "myObject", []( const std::string& message ) {
+   *         printf( "Received a message from JS: %s", message.c_str() );
+   *     });
+   *
+   *     // Start WebView by loading URL
+   *     webview.LoadUrl( url );
+   *
+   * 2. JavaScript
+   *
+   *     myObject.postMessage( "Hello World!" ); // "Received a message from JS: Hello World!"
+   *
+   *
+   * @param[in] exposedObjectName The name of exposed object
+   * @param[in] handler The callback function
+   */
+  void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
 
   /**
    * @brief Clears the history of Web.
@@ -225,37 +464,54 @@ public:
   void ClearCache();
 
   /**
+   * @brief Clears all the cookies of Web.
+   */
+  void ClearCookies();
+
+  /**
    * @brief Connects to this signal to be notified when page loading is started.
    *
    * @return A signal object to connect with
    */
-  WebViewSignalType& PageLoadStartedSignal();
+  WebViewPageLoadSignalType& PageLoadStartedSignal();
 
   /**
    * @brief Connects to this signal to be notified when page loading is finished.
    *
    * @return A signal object to connect with
    */
-  WebViewSignalType& PageLoadFinishedSignal();
+  WebViewPageLoadSignalType& PageLoadFinishedSignal();
 
-public: // Not intended for application developers
+  /**
+   * @brief Connects to this signal to be notified when an error occurs in page loading.
+   *
+   * @return A signal object to connect with.
+   */
+  WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
 
+  /**
+   * @brief Connects to this signal to be notified when scroll edge is reached.
+   *
+   * @return A signal object to connect with.
+   */
+  WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
+
+public: // Not intended for application developers
   /// @cond internal
   /**
    * @brief Creates a handle using the Toolkit::Internal implementation.
    *
    * @param[in] implementation The WebView implementation
    */
-  DALI_INTERNAL WebView( Internal::WebView& implementation );
+  DALI_INTERNAL WebView(Internal::WebView& implementation);
 
   /**
    * @brief Allows the creation of this WebView from an Internal::CustomActor pointer.
    *
    * @param[in] internal A pointer to the internal CustomActor
    */
-  explicit DALI_INTERNAL WebView( Dali::Internal::CustomActor* internal );
+  explicit DALI_INTERNAL WebView(Dali::Internal::CustomActor* internal);
   /// @endcond
-
 };
 
 /**