Implement WebView APIs
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / web-view / web-view.h
index 71d05d3..ad39718 100644 (file)
@@ -53,6 +53,60 @@ class DALI_TOOLKIT_API WebView : public Control
 public:
 
   /**
 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.
    */
   enum PropertyRange
    * @brief Enumeration for the start and end property ranges for this control.
    */
   enum PropertyRange
@@ -69,15 +123,153 @@ public:
     enum
     {
       /**
     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.
        */
        */
-      URL = PROPERTY_START_INDEX
+      DEFAULT_FONT_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
+  };
+
+  /**
+   * @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;
 
 public:
 
 
 public:
 
@@ -143,13 +335,6 @@ public:
   void LoadUrl( const std::string& url );
 
   /**
   void LoadUrl( const std::string& url );
 
   /**
-   * @brief Returns the URL of the Web.
-   *
-   * @return Url of string type
-   */
-  const std::string& GetUrl();
-
-  /**
    * @brief Loads a given string as web contents.
    *
    * @param [in] htmlString The string to use as the contents of the web page
    * @brief Loads a given string as web contents.
    *
    * @param [in] htmlString The string to use as the contents of the web page
@@ -167,6 +352,16 @@ public:
   void StopLoading();
 
   /**
   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 Returns whether forward is possible.
    *
    * @return True if forward is possible, false otherwise
    * @brief Returns whether forward is possible.
    *
    * @return True if forward is possible, false otherwise
@@ -191,28 +386,45 @@ public:
   void GoBack();
 
   /**
   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.
 
   /**
    * @brief Clears the history of Web.
@@ -225,18 +437,30 @@ public:
   void ClearCache();
 
   /**
   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
    */
    * @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
    */
 
   /**
    * @brief Connects to this signal to be notified when page loading is finished.
    *
    * @return A signal object to connect with
    */
-  WebViewSignalType& PageLoadFinishedSignal();
+  WebViewPageLoadSignalType& PageLoadFinishedSignal();
+
+  /**
+   * @brief Connects to this signal to be notified when an error occurs in page loading.
+   *
+   * @return A signal object to connect with.
+   */
+  WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
 
 public: // Not intended for application developers
 
 
 public: // Not intended for application developers