1 #ifndef DALI_TOOLKIT_WEB_VIEW_H
2 #define DALI_TOOLKIT_WEB_VIEW_H
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
25 #include <dali-toolkit/public-api/controls/control.h>
33 namespace Internal DALI_INTERNAL
36 } // namespace Internal
39 * @addtogroup dali_toolkit_controls_web_view
44 * @brief WebView is a control for displaying web content.
46 * This enables embedding web pages in the application.
48 * For working WebView, a web engine plugin for a platform should be provided.
51 class DALI_TOOLKIT_API WebView : public Control
56 * @brief A structure used to contain the cache model enumeration.
61 * @brief Enumeration for cache model options.
66 * @brief Use the smallest cache capacity.
71 * @brief Use the bigger cache capacity than DocumentBrowser.
76 * @brief Use the biggest cache capacity.
83 * @brief A structure used to contain the cookie acceptance policy enumeration.
85 struct CookieAcceptPolicy
88 * @brief Enumeration for the cookies accept policies.
93 * @brief Accepts every cookie sent from any page.
98 * @brief Rejects all the cookies.
103 * @brief Accepts only cookies set by the main document that is loaded.
110 * @brief Enumeration for the start and end property ranges for this control.
114 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
115 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000,
119 * @brief Enumeration for the instance of properties belonging to the WebView class.
126 * @brief The url to load.
127 * @details name "url", type Property::STRING.
129 URL = PROPERTY_START_INDEX,
132 * @brief The cache model.
133 * @details Name "cacheModel", type WebView::CacheModel::Type (Property::INTEGER) or Property::STRING.
134 * @note Default is WebView::CacheModel::DOCUMENT_VIEWER.
135 * @see WebView::CacheModel::Type
140 * @brief The cookie acceptance policy.
141 * @details Name "cookieAcceptPolicy", type WebView::CookieAcceptPolicy::Type (Property::INTEGER) or Property::STRING.
142 * @note Default is WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
143 * @see WebView::CookieAcceptPolicy::Type
145 COOKIE_ACCEPT_POLICY,
148 * @brief The user agent string.
149 * @details Name "userAgent", type Property::STRING.
154 * @brief Whether JavaScript is enabled.
155 * @details Name "enableJavaScript", type Property::BOOLEAN.
156 * @note Default is true.
161 * @brief Whether images can be loaded automatically.
162 * @details Name "loadImagesAutomatically", type Property::BOOLEAN.
163 * @note Default is true.
165 LOAD_IMAGES_AUTOMATICALLY,
168 * @brief The default text encoding name.
169 * @details Name "defaultTextEncodingName", type Property::STRING.
170 * @note If the value is not set, the web engine detects web page's text encoding.
172 DEFAULT_TEXT_ENCODING_NAME,
175 * @brief The default font size in pixel.
176 * @details Name "defaultFontSize", type Property::INT.
177 * @note Default is 16.
184 * @brief Enumeration for indicating error code of page loading.
186 enum class LoadErrorCode
194 * @brief User canceled.
199 * @brief Can't show the page for this MIME type.
201 CANT_SUPPORT_MIMETYPE,
204 * @brief File IO error.
209 * @brief Cannot connect to the network.
214 * @brief Fail to look up host from the DNS.
219 * @brief Fail to SSL/TLS handshake.
221 FAILED_TLS_HANDSHAKE,
224 * @brief Received certificate is invalid.
229 * @brief Connection timeout.
234 * @brief Too many redirects.
239 * @brief Too many requests during this load.
244 * @brief Malformed URL.
249 * @brief Unsupported scheme.
254 * @brief User authentication failed on the server.
259 * @brief Web server has an internal server error.
265 * @brief WebView signal type related with page loading.
267 typedef Signal< void ( WebView, const std::string& ) > WebViewPageLoadSignalType;
270 * @brief WebView signal type related with page loading error.
272 typedef Signal< void ( WebView, const std::string&, LoadErrorCode ) > WebViewPageLoadErrorSignalType;
277 * @brief Creates an initialized WebView.
278 * @return A handle to a newly allocated Dali WebView
280 * @note WebView will not display anything
282 static WebView New();
285 * @brief Creates an initialized WebView.
287 * @param [in] locale The locale of Web
288 * @param [in] timezoneId The timezoneId of Web
290 static WebView New( const std::string& locale, const std::string& timezoneId );
293 * @brief Creates an uninitialized WebView.
300 * This is non-virtual since derived Handel types must not contain data or virtual methods.
305 * @brief Copy constructor.
307 * @param[in] WebView WebView to copy. The copied WebView will point at the same implementation
309 WebView( const WebView& WebView );
312 * @brief Assignment operator.
314 * @param[in] WebView The WebView to assign from
315 * @return The updated WebView
317 WebView& operator=( const WebView& WebView );
320 * @brief Downcasts a handle to WebView handle.
322 * If handle points to a WebView, the downcast produces valid handle.
323 * If not, the returned handle is left uninitialized.
325 * @param[in] handle Handle to an object
326 * @return Handle to a WebView or an uninitialized handle
328 static WebView DownCast( BaseHandle handle );
331 * @brief Loads a web page based on a given URL.
333 * @param [in] url The URL of the resource to load
335 void LoadUrl( const std::string& url );
338 * @brief Loads a given string as web contents.
340 * @param [in] htmlString The string to use as the contents of the web page
342 void LoadHTMLString( const std::string& htmlString );
345 * @brief Reloads the Web.
350 * @brief Stops loading web contents on the current page.
355 * @brief Suspends the operation associated with the view.
360 * @brief Resumes the operation associated with the view object after calling Suspend().
365 * @brief Returns whether forward is possible.
367 * @return True if forward is possible, false otherwise
372 * @brief Goes forward in the navigation history.
377 * @brief Returns whether backward is possible.
379 * @return True if backward is possible, false otherwise
384 * @brief Goes back in the navigation history.
389 * @brief Evaluates JavaScript code represented as a string.
391 * @param[in] script The JavaScript code
392 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
394 void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler );
397 * @brief Evaluates JavaScript code represented as a string.
399 * @param[in] script The JavaScript code
401 void EvaluateJavaScript( const std::string& script );
404 * @brief Inject a JavaScript object with a message handler into the WebView.
406 * @note The injected object will appear in the JavaScript context to be loaded next.
412 * webview.AddJavaScriptMessageHandler( "myObject", []( const std::string& message ) {
413 * printf( "Received a message from JS: %s", message.c_str() );
416 * // Start WebView by loading URL
417 * webview.LoadUrl( url );
421 * myObject.postMessage( "Hello World!" ); // "Received a message from JS: Hello World!"
424 * @param[in] exposedObjectName The name of exposed object
425 * @param[in] handler The callback function
427 void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
430 * @brief Clears the history of Web.
435 * @brief Clears the cache of Web.
440 * @brief Clears all the cookies of Web.
445 * @brief Connects to this signal to be notified when page loading is started.
447 * @return A signal object to connect with
449 WebViewPageLoadSignalType& PageLoadStartedSignal();
452 * @brief Connects to this signal to be notified when page loading is finished.
454 * @return A signal object to connect with
456 WebViewPageLoadSignalType& PageLoadFinishedSignal();
459 * @brief Connects to this signal to be notified when an error occurs in page loading.
461 * @return A signal object to connect with.
463 WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
465 public: // Not intended for application developers
469 * @brief Creates a handle using the Toolkit::Internal implementation.
471 * @param[in] implementation The WebView implementation
473 DALI_INTERNAL WebView( Internal::WebView& implementation );
476 * @brief Allows the creation of this WebView from an Internal::CustomActor pointer.
478 * @param[in] internal A pointer to the internal CustomActor
480 explicit DALI_INTERNAL WebView( Dali::Internal::CustomActor* internal );
489 } // namespace Toolkit
493 #endif // DALI_TOOLKIT_WEB_VIEW_H