1 #ifndef DALI_TOOLKIT_WEB_VIEW_H
2 #define DALI_TOOLKIT_WEB_VIEW_H
5 * Copyright (c) 2020 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>
31 namespace Internal DALI_INTERNAL
34 } // namespace DALI_INTERNAL
37 * @addtogroup dali_toolkit_controls_web_view
42 * @brief WebView is a control for displaying web content.
44 * This enables embedding web pages in the application.
46 * For working WebView, a web engine plugin for a platform should be provided.
49 class DALI_TOOLKIT_API WebView : public Control
53 * @brief A structure used to contain the cache model enumeration.
58 * @brief Enumeration for cache model options.
63 * @brief Use the smallest cache capacity.
68 * @brief Use the bigger cache capacity than DocumentBrowser.
73 * @brief Use the biggest cache capacity.
80 * @brief A structure used to contain the cookie acceptance policy enumeration.
82 struct CookieAcceptPolicy
85 * @brief Enumeration for the cookies accept policies.
90 * @brief Accepts every cookie sent from any page.
95 * @brief Rejects all the cookies.
100 * @brief Accepts only cookies set by the main document that is loaded.
107 * @brief Enumeration for the start and end property ranges for this control.
111 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
112 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000,
116 * @brief Enumeration for the instance of properties belonging to the WebView class.
123 * @brief The url to load.
124 * @details name "url", type Property::STRING.
126 URL = PROPERTY_START_INDEX,
129 * @brief The cache model.
130 * @details Name "cacheModel", type WebView::CacheModel::Type (Property::INTEGER) or Property::STRING.
131 * @note Default is WebView::CacheModel::DOCUMENT_VIEWER.
132 * @see WebView::CacheModel::Type
137 * @brief The cookie acceptance policy.
138 * @details Name "cookieAcceptPolicy", type WebView::CookieAcceptPolicy::Type (Property::INTEGER) or Property::STRING.
139 * @note Default is WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
140 * @see WebView::CookieAcceptPolicy::Type
142 COOKIE_ACCEPT_POLICY,
145 * @brief The user agent string.
146 * @details Name "userAgent", type Property::STRING.
151 * @brief Whether JavaScript is enabled.
152 * @details Name "enableJavaScript", type Property::BOOLEAN.
153 * @note Default is true.
158 * @brief Whether images can be loaded automatically.
159 * @details Name "loadImagesAutomatically", type Property::BOOLEAN.
160 * @note Default is true.
162 LOAD_IMAGES_AUTOMATICALLY,
165 * @brief The default text encoding name.
166 * @details Name "defaultTextEncodingName", type Property::STRING.
167 * @note If the value is not set, the web engine detects web page's text encoding.
169 DEFAULT_TEXT_ENCODING_NAME,
172 * @brief The default font size in pixel.
173 * @details Name "defaultFontSize", type Property::INT.
174 * @note Default is 16.
181 * @brief Enumeration for indicating error code of page loading.
183 enum class LoadErrorCode
191 * @brief User canceled.
196 * @brief Can't show the page for this MIME type.
198 CANT_SUPPORT_MIMETYPE,
201 * @brief File IO error.
206 * @brief Cannot connect to the network.
211 * @brief Fail to look up host from the DNS.
216 * @brief Fail to SSL/TLS handshake.
218 FAILED_TLS_HANDSHAKE,
221 * @brief Received certificate is invalid.
226 * @brief Connection timeout.
231 * @brief Too many redirects.
236 * @brief Too many requests during this load.
241 * @brief Malformed URL.
246 * @brief Unsupported scheme.
251 * @brief User authentication failed on the server.
256 * @brief Web server has an internal server error.
262 * @brief WebView signal type related with page loading.
264 typedef Signal<void(WebView, const std::string&)> WebViewPageLoadSignalType;
267 * @brief WebView signal type related with page loading error.
269 typedef Signal<void(WebView, const std::string&, LoadErrorCode)> WebViewPageLoadErrorSignalType;
273 * @brief Creates an initialized WebView.
274 * @return A handle to a newly allocated Dali WebView
276 * @note WebView will not display anything
278 static WebView New();
281 * @brief Creates an initialized WebView.
283 * @param [in] locale The locale of Web
284 * @param [in] timezoneId The timezoneId of Web
286 static WebView New(const std::string& locale, const std::string& timezoneId);
289 * @brief Creates an uninitialized WebView.
296 * This is non-virtual since derived Handel types must not contain data or virtual methods.
301 * @brief Copy constructor.
303 * @param[in] WebView WebView to copy. The copied WebView will point at the same implementation
305 WebView(const WebView& WebView);
308 * @brief Assignment operator.
310 * @param[in] WebView The WebView to assign from
311 * @return The updated WebView
313 WebView& operator=(const WebView& WebView);
316 * @brief Downcasts a handle to WebView handle.
318 * If handle points to a WebView, the downcast produces valid handle.
319 * If not, the returned handle is left uninitialized.
321 * @param[in] handle Handle to an object
322 * @return Handle to a WebView or an uninitialized handle
324 static WebView DownCast(BaseHandle handle);
327 * @brief Loads a web page based on a given URL.
329 * @param [in] url The URL of the resource to load
331 void LoadUrl(const std::string& url);
334 * @brief Loads a given string as web contents.
336 * @param [in] htmlString The string to use as the contents of the web page
338 void LoadHTMLString(const std::string& htmlString);
341 * @brief Reloads the Web.
346 * @brief Stops loading web contents on the current page.
351 * @brief Suspends the operation associated with the view.
356 * @brief Resumes the operation associated with the view object after calling Suspend().
361 * @brief Returns whether forward is possible.
363 * @return True if forward is possible, false otherwise
368 * @brief Goes forward in the navigation history.
373 * @brief Returns whether backward is possible.
375 * @return True if backward is possible, false otherwise
380 * @brief Goes back in the navigation history.
385 * @brief Evaluates JavaScript code represented as a string.
387 * @param[in] script The JavaScript code
388 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
390 void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
393 * @brief Evaluates JavaScript code represented as a string.
395 * @param[in] script The JavaScript code
397 void EvaluateJavaScript(const std::string& script);
400 * @brief Inject a JavaScript object with a message handler into the WebView.
402 * @note The injected object will appear in the JavaScript context to be loaded next.
408 * webview.AddJavaScriptMessageHandler( "myObject", []( const std::string& message ) {
409 * printf( "Received a message from JS: %s", message.c_str() );
412 * // Start WebView by loading URL
413 * webview.LoadUrl( url );
417 * myObject.postMessage( "Hello World!" ); // "Received a message from JS: Hello World!"
420 * @param[in] exposedObjectName The name of exposed object
421 * @param[in] handler The callback function
423 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
426 * @brief Clears the history of Web.
431 * @brief Clears the cache of Web.
436 * @brief Clears all the cookies of Web.
441 * @brief Connects to this signal to be notified when page loading is started.
443 * @return A signal object to connect with
445 WebViewPageLoadSignalType& PageLoadStartedSignal();
448 * @brief Connects to this signal to be notified when page loading is finished.
450 * @return A signal object to connect with
452 WebViewPageLoadSignalType& PageLoadFinishedSignal();
455 * @brief Connects to this signal to be notified when an error occurs in page loading.
457 * @return A signal object to connect with.
459 WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
461 public: // Not intended for application developers
464 * @brief Creates a handle using the Toolkit::Internal implementation.
466 * @param[in] implementation The WebView implementation
468 DALI_INTERNAL WebView(Internal::WebView& implementation);
471 * @brief Allows the creation of this WebView from an Internal::CustomActor pointer.
473 * @param[in] internal A pointer to the internal CustomActor
475 explicit DALI_INTERNAL WebView(Dali::Internal::CustomActor* internal);
483 } // namespace Toolkit
487 #endif // DALI_TOOLKIT_WEB_VIEW_H