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>
33 class WebBackForwardList;
35 class WebCookieManager;
38 namespace Internal DALI_INTERNAL
41 } // namespace DALI_INTERNAL
44 * @addtogroup dali_toolkit_controls_web_view
49 * @brief WebView is a control for displaying web content.
51 * This enables embedding web pages in the application.
53 * For working WebView, a web engine plugin for a platform should be provided.
56 class DALI_TOOLKIT_API WebView : public Control
61 * @brief Enumeration for the start and end property ranges for this control.
65 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
66 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000,
70 * @brief Enumeration for the instance of properties belonging to the WebView class.
77 * @brief The url to load.
78 * @details name "url", type Property::STRING.
80 URL = PROPERTY_START_INDEX,
83 * @brief The user agent string.
84 * @details Name "userAgent", type Property::STRING.
89 * @brief The current position of scroll.
90 * @details Name "scrollPosition", type Property::VECTOR2.
95 * @brief The current position of scroll.
96 * @details Name "scrollSize", type Property::VECTOR2. Read-only.
101 * @brief The current position of scroll.
102 * @details Name "contentSize", type Property::VECTOR2. Read-only.
107 * @brief The title of web page.
108 * @details Name "title", type Property::STRING.
109 * @note The value is read-only.
116 * @brief Enumeration for indicating error code of page loading.
118 enum class LoadErrorCode
126 * @brief User canceled.
131 * @brief Can't show the page for this MIME type.
133 CANT_SUPPORT_MIMETYPE,
136 * @brief File IO error.
141 * @brief Cannot connect to the network.
146 * @brief Fail to look up host from the DNS.
151 * @brief Fail to SSL/TLS handshake.
153 FAILED_TLS_HANDSHAKE,
156 * @brief Received certificate is invalid.
161 * @brief Connection timeout.
166 * @brief Too many redirects.
171 * @brief Too many requests during this load.
176 * @brief Malformed URL.
181 * @brief Unsupported scheme.
186 * @brief User authentication failed on the server.
191 * @brief Web server has an internal server error.
197 * @brief WebView signal type related with page loading.
199 typedef Signal<void(WebView, const std::string&)> WebViewPageLoadSignalType;
202 * @brief WebView signal type related with page loading error.
204 typedef Signal<void(WebView, const std::string&, LoadErrorCode)> WebViewPageLoadErrorSignalType;
207 * @brief WebView signal type related with scroll edge reached.
209 typedef Signal<void(WebView, Dali::WebEnginePlugin::ScrollEdge)> WebViewScrollEdgeReachedSignalType;
213 * @brief Creates an initialized WebView.
214 * @return A handle to a newly allocated Dali WebView
216 * @note WebView will not display anything
218 static WebView New();
221 * @brief Creates an initialized WebView.
223 * @param [in] locale The locale of Web
224 * @param [in] timezoneId The timezoneId of Web
226 static WebView New(const std::string& locale, const std::string& timezoneId);
229 * @brief Creates an initialized WebView.
231 * @param [in] argc The count of arguments of Applications
232 * @param [in] argv The string array of arguments of Applications
234 static WebView New( int argc, char** argv );
237 * @brief Creates an uninitialized WebView.
244 * This is non-virtual since derived Handel types must not contain data or virtual methods.
249 * @brief Copy constructor.
251 * @param[in] WebView WebView to copy. The copied WebView will point at the same implementation
253 WebView(const WebView& WebView);
256 * @brief Assignment operator.
258 * @param[in] WebView The WebView to assign from
259 * @return The updated WebView
261 WebView& operator=(const WebView& WebView);
264 * @brief Downcasts a handle to WebView handle.
266 * If handle points to a WebView, the downcast produces valid handle.
267 * If not, the returned handle is left uninitialized.
269 * @param[in] handle Handle to an object
270 * @return Handle to a WebView or an uninitialized handle
272 static WebView DownCast(BaseHandle handle);
275 * @brief Get WebSettings of WebEngine.
277 Dali::Toolkit::WebSettings* GetSettings() const;
280 * @brief Get WebContext of WebEngine.
282 Dali::Toolkit::WebContext* GetContext() const;
285 * @brief Get CookieManager of WebEngine.
287 Dali::Toolkit::WebCookieManager* GetCookieManager() const;
290 * @brief Get WebBackForwardList of WebEngine.
292 Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
295 * @brief Get Favicon of web page.
297 * @return Handle to a fav icon
299 Dali::Toolkit::ImageView& GetFavicon();
302 * @brief Loads a web page based on a given URL.
304 * @param [in] url The URL of the resource to load
306 void LoadUrl(const std::string& url);
309 * @brief Loads a given string as web contents.
311 * @param [in] htmlString The string to use as the contents of the web page
313 void LoadHtmlString(const std::string& htmlString);
316 * @brief Reloads the Web.
321 * @brief Stops loading web contents on the current page.
326 * @brief Suspends the operation associated with the view.
331 * @brief Resumes the operation associated with the view object after calling Suspend().
336 * @brief Scrolls the webpage of view by deltaX and deltaY.
337 * @param[in] deltaX The delta x of scroll
338 * @param[in] deltaY The delta y of scroll
340 void ScrollBy( int deltaX, int deltaY );
343 * @brief Returns whether forward is possible.
345 * @return True if forward is possible, false otherwise
350 * @brief Goes forward in the navigation history.
355 * @brief Returns whether backward is possible.
357 * @return True if backward is possible, false otherwise
362 * @brief Goes back in the navigation history.
367 * @brief Evaluates JavaScript code represented as a string.
369 * @param[in] script The JavaScript code
370 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
372 void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
375 * @brief Evaluates JavaScript code represented as a string.
377 * @param[in] script The JavaScript code
379 void EvaluateJavaScript(const std::string& script);
382 * @brief Inject a JavaScript object with a message handler into the WebView.
384 * @note The injected object will appear in the JavaScript context to be loaded next.
390 * webview.AddJavaScriptMessageHandler( "myObject", []( const std::string& message ) {
391 * printf( "Received a message from JS: %s", message.c_str() );
394 * // Start WebView by loading URL
395 * webview.LoadUrl( url );
399 * myObject.postMessage( "Hello World!" ); // "Received a message from JS: Hello World!"
402 * @param[in] exposedObjectName The name of exposed object
403 * @param[in] handler The callback function
405 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
408 * @brief Clears all tiles resources of Web.
410 void ClearAllTilesResources();
413 * @brief Clears the history of Web.
418 * @brief Connects to this signal to be notified when page loading is started.
420 * @return A signal object to connect with
422 WebViewPageLoadSignalType& PageLoadStartedSignal();
425 * @brief Connects to this signal to be notified when page loading is finished.
427 * @return A signal object to connect with
429 WebViewPageLoadSignalType& PageLoadFinishedSignal();
432 * @brief Connects to this signal to be notified when an error occurs in page loading.
434 * @return A signal object to connect with.
436 WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
439 * @brief Connects to this signal to be notified when scroll edge is reached.
441 * @return A signal object to connect with.
443 WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
445 public: // Not intended for application developers
448 * @brief Creates a handle using the Toolkit::Internal implementation.
450 * @param[in] implementation The WebView implementation
452 DALI_INTERNAL WebView(Internal::WebView& implementation);
455 * @brief Allows the creation of this WebView from an Internal::CustomActor pointer.
457 * @param[in] internal A pointer to the internal CustomActor
459 explicit DALI_INTERNAL WebView(Dali::Internal::CustomActor* internal);
467 } // namespace Toolkit
471 #endif // DALI_TOOLKIT_WEB_VIEW_H