#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
{
+class ImageView;
+class WebBackForwardList;
+class WebContext;
+class WebCookieManager;
+class WebSettings;
namespace Internal DALI_INTERNAL
{
- class WebView;
-} // namespace Internal
+class WebView;
+} // namespace DALI_INTERNAL
/**
* @addtogroup dali_toolkit_controls_web_view
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,
};
/**
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 user agent string.
+ * @details name "userAgent", type Property::STRING.
+ */
+ USER_AGENT,
+
+ /**
+ * @brief The current position of scroll.
+ * @details name "scrollPosition", type Property::VECTOR2.
+ */
+ SCROLL_POSITION,
+
+ /**
+ * @brief The current size of scroll.
+ * @details name "scrollSize", type Property::VECTOR2.
+ * @note The value is read-only.
*/
- URL = PROPERTY_START_INDEX
+ SCROLL_SIZE,
+
+ /**
+ * @brief The current size of content.
+ * @details name "contentSize", type Property::VECTOR2.
+ * @note The value is read-only.
+ */
+ CONTENT_SIZE,
+
+ /**
+ * @brief The title of web page.
+ * @details name "title", type Property::STRING.
+ * @note The value is read-only.
+ */
+ TITLE,
+
+ /**
+ * @brief Whether video hole is enabled or not.
+ * @details name "videoHoleEnabled", type Property::BOOLEAN.
+ * @note The value is read-only.
+ */
+ VIDEO_HOLE_ENABLED,
};
};
- typedef Signal< void ( WebView, const std::string& ) > WebViewSignalType;
+ /**
+ * @brief Enumeration for indicating error code of page loading.
+ */
+ enum class LoadErrorCode
+ {
+ UNKNOWN = 0, ///< Unknown.
+ CANCELED, ///< User canceled.
+ CANT_SUPPORT_MIMETYPE, ///< Can't show the page for this MIME type.
+ FAILED_FILE_IO, ///< File IO error.
+ CANT_CONNECT, ///< Cannot connect to the network.
+ CANT_LOOKUP_HOST, ///< Fail to look up host from the DNS.
+ FAILED_TLS_HANDSHAKE, ///< Fail to SSL/TLS handshake.
+ INVALID_CERTIFICATE, ///< Received certificate is invalid.
+ REQUEST_TIMEOUT, ///< Connection timeout.
+ TOO_MANY_REDIRECTS, ///< Too many redirects.
+ TOO_MANY_REQUESTS, ///< Too many requests during this load.
+ BAD_URL, ///< Malformed URL.
+ UNSUPPORTED_SCHEME, ///< Unsupported scheme.
+ AUTHENTICATION, ///< User authentication failed on the server.
+ INTERNAL_SERVER ///< Web server has an internal server error.
+ };
+
+ /**
+ * @brief WebView signal type related with page loading.
+ */
+ typedef Signal<void(WebView, const std::string&)> WebViewPageLoadSignalType;
-public:
+ /**
+ * @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
*
* @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 initialized WebView.
+ *
+ * @param [in] argc The count of arguments of Applications
+ * @param [in] argv The string array of arguments of Applications
+ */
+ static WebView New( int argc, char** argv );
/**
* @brief Creates an uninitialized WebView.
*
* @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.
* @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.
* @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.
+ * @brief Get WebSettings of WebEngine.
+ */
+ Dali::Toolkit::WebSettings* GetSettings() const;
+
+ /**
+ * @brief Get WebContext of WebEngine.
+ */
+ Dali::Toolkit::WebContext* GetContext() const;
+
+ /**
+ * @brief Get CookieManager of WebEngine.
+ */
+ Dali::Toolkit::WebCookieManager* GetCookieManager() const;
+
+ /**
+ * @brief Get WebBackForwardList of WebEngine.
+ */
+ Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
+
+ /**
+ * @brief Get Favicon of web page.
*
- * @param [in] url The URL of the resource to load
+ * @return Handle to a fav icon
*/
- void LoadUrl( const std::string& url );
+ Dali::Toolkit::ImageView& GetFavicon();
/**
- * @brief Returns the URL of the Web.
+ * @brief Loads a web page based on a given URL.
*
- * @return Url of string type
+ * @param [in] url The URL of the resource to load
*/
- 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.
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
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 all tiles resources of Web.
*/
- void ClearHistory();
+ void ClearAllTilesResources();
/**
- * @brief Clears the cache of Web.
+ * @brief Clears the history of Web.
*/
- void ClearCache();
+ void ClearHistory();
/**
* @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
-
};
/**