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/devel-api/adaptor-framework/web-engine-plugin.h>
26 #include <dali-toolkit/public-api/controls/control.h>
32 namespace Internal DALI_INTERNAL
35 } // namespace DALI_INTERNAL
38 * @addtogroup dali_toolkit_controls_web_view
43 * @brief WebView is a control for displaying web content.
45 * This enables embedding web pages in the application.
47 * For working WebView, a web engine plugin for a platform should be provided.
50 class DALI_TOOLKIT_API WebView : public Control
54 * @brief A structure used to contain the cache model enumeration.
59 * @brief Enumeration for cache model options.
64 * @brief Use the smallest cache capacity.
69 * @brief Use the bigger cache capacity than DocumentBrowser.
74 * @brief Use the biggest cache capacity.
81 * @brief A structure used to contain the cookie acceptance policy enumeration.
83 struct CookieAcceptPolicy
86 * @brief Enumeration for the cookies accept policies.
91 * @brief Accepts every cookie sent from any page.
96 * @brief Rejects all the cookies.
101 * @brief Accepts only cookies set by the main document that is loaded.
108 * @brief Enumeration for the start and end property ranges for this control.
112 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
113 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000,
117 * @brief Enumeration for the instance of properties belonging to the WebView class.
124 * @brief The url to load.
125 * @details name "url", type Property::STRING.
127 URL = PROPERTY_START_INDEX,
130 * @brief The cache model.
131 * @details Name "cacheModel", type WebView::CacheModel::Type (Property::INTEGER) or Property::STRING.
132 * @note Default is WebView::CacheModel::DOCUMENT_VIEWER.
133 * @see WebView::CacheModel::Type
138 * @brief The cookie acceptance policy.
139 * @details Name "cookieAcceptPolicy", type WebView::CookieAcceptPolicy::Type (Property::INTEGER) or Property::STRING.
140 * @note Default is WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
141 * @see WebView::CookieAcceptPolicy::Type
143 COOKIE_ACCEPT_POLICY,
146 * @brief The user agent string.
147 * @details Name "userAgent", type Property::STRING.
152 * @brief Whether JavaScript is enabled.
153 * @details Name "enableJavaScript", type Property::BOOLEAN.
154 * @note Default is true.
159 * @brief Whether images can be loaded automatically.
160 * @details Name "loadImagesAutomatically", type Property::BOOLEAN.
161 * @note Default is true.
163 LOAD_IMAGES_AUTOMATICALLY,
166 * @brief The default text encoding name.
167 * @details Name "defaultTextEncodingName", type Property::STRING.
168 * @note If the value is not set, the web engine detects web page's text encoding.
170 DEFAULT_TEXT_ENCODING_NAME,
173 * @brief The default font size in pixel.
174 * @details Name "defaultFontSize", type Property::INT.
175 * @note Default is 16.
180 * @brief The current position of scroll.
181 * @details Name "scrollPosition", type Property::VECTOR2.
186 * @brief The current position of scroll.
187 * @details Name "scrollSize", type Property::VECTOR2. Read-only.
192 * @brief The current position of scroll.
193 * @details Name "contentSize", type Property::VECTOR2. Read-only.
200 * @brief Enumeration for indicating error code of page loading.
202 enum class LoadErrorCode
210 * @brief User canceled.
215 * @brief Can't show the page for this MIME type.
217 CANT_SUPPORT_MIMETYPE,
220 * @brief File IO error.
225 * @brief Cannot connect to the network.
230 * @brief Fail to look up host from the DNS.
235 * @brief Fail to SSL/TLS handshake.
237 FAILED_TLS_HANDSHAKE,
240 * @brief Received certificate is invalid.
245 * @brief Connection timeout.
250 * @brief Too many redirects.
255 * @brief Too many requests during this load.
260 * @brief Malformed URL.
265 * @brief Unsupported scheme.
270 * @brief User authentication failed on the server.
275 * @brief Web server has an internal server error.
281 * @brief WebView signal type related with page loading.
283 typedef Signal<void(WebView, const std::string&)> WebViewPageLoadSignalType;
286 * @brief WebView signal type related with page loading error.
288 typedef Signal<void(WebView, const std::string&, LoadErrorCode)> WebViewPageLoadErrorSignalType;
291 * @brief WebView signal type related with scroll edge reached.
293 typedef Signal<void(WebView, Dali::WebEnginePlugin::ScrollEdge)> WebViewScrollEdgeReachedSignalType;
297 * @brief Creates an initialized WebView.
298 * @return A handle to a newly allocated Dali WebView
300 * @note WebView will not display anything
302 static WebView New();
305 * @brief Creates an initialized WebView.
307 * @param [in] locale The locale of Web
308 * @param [in] timezoneId The timezoneId of Web
310 static WebView New(const std::string& locale, const std::string& timezoneId);
313 * @brief Creates an uninitialized WebView.
320 * This is non-virtual since derived Handel types must not contain data or virtual methods.
325 * @brief Copy constructor.
327 * @param[in] WebView WebView to copy. The copied WebView will point at the same implementation
329 WebView(const WebView& WebView);
332 * @brief Assignment operator.
334 * @param[in] WebView The WebView to assign from
335 * @return The updated WebView
337 WebView& operator=(const WebView& WebView);
340 * @brief Downcasts a handle to WebView handle.
342 * If handle points to a WebView, the downcast produces valid handle.
343 * If not, the returned handle is left uninitialized.
345 * @param[in] handle Handle to an object
346 * @return Handle to a WebView or an uninitialized handle
348 static WebView DownCast(BaseHandle handle);
351 * @brief Loads a web page based on a given URL.
353 * @param [in] url The URL of the resource to load
355 void LoadUrl(const std::string& url);
358 * @brief Loads a given string as web contents.
360 * @param [in] htmlString The string to use as the contents of the web page
362 void LoadHTMLString(const std::string& htmlString);
365 * @brief Reloads the Web.
370 * @brief Stops loading web contents on the current page.
375 * @brief Suspends the operation associated with the view.
380 * @brief Resumes the operation associated with the view object after calling Suspend().
385 * @brief Scrolls the webpage of view by deltaX and deltaY.
386 * @param[in] deltaX The delta x of scroll
387 * @param[in] deltaY The delta y of scroll
389 void ScrollBy( int deltaX, int deltaY );
392 * @brief Returns whether forward is possible.
394 * @return True if forward is possible, false otherwise
399 * @brief Goes forward in the navigation history.
404 * @brief Returns whether backward is possible.
406 * @return True if backward is possible, false otherwise
411 * @brief Goes back in the navigation history.
416 * @brief Evaluates JavaScript code represented as a string.
418 * @param[in] script The JavaScript code
419 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
421 void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
424 * @brief Evaluates JavaScript code represented as a string.
426 * @param[in] script The JavaScript code
428 void EvaluateJavaScript(const std::string& script);
431 * @brief Inject a JavaScript object with a message handler into the WebView.
433 * @note The injected object will appear in the JavaScript context to be loaded next.
439 * webview.AddJavaScriptMessageHandler( "myObject", []( const std::string& message ) {
440 * printf( "Received a message from JS: %s", message.c_str() );
443 * // Start WebView by loading URL
444 * webview.LoadUrl( url );
448 * myObject.postMessage( "Hello World!" ); // "Received a message from JS: Hello World!"
451 * @param[in] exposedObjectName The name of exposed object
452 * @param[in] handler The callback function
454 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
457 * @brief Clears the history of Web.
462 * @brief Clears the cache of Web.
467 * @brief Clears all the cookies of Web.
472 * @brief Connects to this signal to be notified when page loading is started.
474 * @return A signal object to connect with
476 WebViewPageLoadSignalType& PageLoadStartedSignal();
479 * @brief Connects to this signal to be notified when page loading is finished.
481 * @return A signal object to connect with
483 WebViewPageLoadSignalType& PageLoadFinishedSignal();
486 * @brief Connects to this signal to be notified when an error occurs in page loading.
488 * @return A signal object to connect with.
490 WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
493 * @brief Connects to this signal to be notified when scroll edge is reached.
495 * @return A signal object to connect with.
497 WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
499 public: // Not intended for application developers
502 * @brief Creates a handle using the Toolkit::Internal implementation.
504 * @param[in] implementation The WebView implementation
506 DALI_INTERNAL WebView(Internal::WebView& implementation);
509 * @brief Allows the creation of this WebView from an Internal::CustomActor pointer.
511 * @param[in] internal A pointer to the internal CustomActor
513 explicit DALI_INTERNAL WebView(Dali::Internal::CustomActor* internal);
521 } // namespace Toolkit
525 #endif // DALI_TOOLKIT_WEB_VIEW_H