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 class WebBackForwardList;
34 class WebCookieManager;
37 namespace Internal DALI_INTERNAL
40 } // namespace DALI_INTERNAL
43 * @addtogroup dali_toolkit_controls_web_view
48 * @brief WebView is a control for displaying web content.
50 * This enables embedding web pages in the application.
52 * For working WebView, a web engine plugin for a platform should be provided.
55 class DALI_TOOLKIT_API WebView : public Control
60 * @brief Enumeration for the start and end property ranges for this control.
64 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
65 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000,
69 * @brief Enumeration for the instance of properties belonging to the WebView class.
76 * @brief The url to load.
77 * @details name "url", type Property::STRING.
79 URL = PROPERTY_START_INDEX,
82 * @brief The user agent string.
83 * @details Name "userAgent", type Property::STRING.
88 * @brief The current position of scroll.
89 * @details Name "scrollPosition", type Property::VECTOR2.
94 * @brief The current position of scroll.
95 * @details Name "scrollSize", type Property::VECTOR2. Read-only.
100 * @brief The current position of scroll.
101 * @details Name "contentSize", type Property::VECTOR2. Read-only.
108 * @brief Enumeration for indicating error code of page loading.
110 enum class LoadErrorCode
118 * @brief User canceled.
123 * @brief Can't show the page for this MIME type.
125 CANT_SUPPORT_MIMETYPE,
128 * @brief File IO error.
133 * @brief Cannot connect to the network.
138 * @brief Fail to look up host from the DNS.
143 * @brief Fail to SSL/TLS handshake.
145 FAILED_TLS_HANDSHAKE,
148 * @brief Received certificate is invalid.
153 * @brief Connection timeout.
158 * @brief Too many redirects.
163 * @brief Too many requests during this load.
168 * @brief Malformed URL.
173 * @brief Unsupported scheme.
178 * @brief User authentication failed on the server.
183 * @brief Web server has an internal server error.
189 * @brief WebView signal type related with page loading.
191 typedef Signal<void(WebView, const std::string&)> WebViewPageLoadSignalType;
194 * @brief WebView signal type related with page loading error.
196 typedef Signal<void(WebView, const std::string&, LoadErrorCode)> WebViewPageLoadErrorSignalType;
199 * @brief WebView signal type related with scroll edge reached.
201 typedef Signal<void(WebView, Dali::WebEnginePlugin::ScrollEdge)> WebViewScrollEdgeReachedSignalType;
205 * @brief Creates an initialized WebView.
206 * @return A handle to a newly allocated Dali WebView
208 * @note WebView will not display anything
210 static WebView New();
213 * @brief Creates an initialized WebView.
215 * @param [in] locale The locale of Web
216 * @param [in] timezoneId The timezoneId of Web
218 static WebView New(const std::string& locale, const std::string& timezoneId);
221 * @brief Creates an uninitialized WebView.
228 * This is non-virtual since derived Handel types must not contain data or virtual methods.
233 * @brief Copy constructor.
235 * @param[in] WebView WebView to copy. The copied WebView will point at the same implementation
237 WebView(const WebView& WebView);
240 * @brief Assignment operator.
242 * @param[in] WebView The WebView to assign from
243 * @return The updated WebView
245 WebView& operator=(const WebView& WebView);
248 * @brief Downcasts a handle to WebView handle.
250 * If handle points to a WebView, the downcast produces valid handle.
251 * If not, the returned handle is left uninitialized.
253 * @param[in] handle Handle to an object
254 * @return Handle to a WebView or an uninitialized handle
256 static WebView DownCast(BaseHandle handle);
259 * @brief Get WebSettings of WebEngine.
261 Dali::Toolkit::WebSettings* GetSettings() const;
264 * @brief Get WebContext of WebEngine.
266 Dali::Toolkit::WebContext* GetContext() const;
269 * @brief Get CookieManager of WebEngine.
271 Dali::Toolkit::WebCookieManager* GetCookieManager() const;
274 * @brief Get WebBackForwardList of WebEngine.
276 Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
279 * @brief Loads a web page based on a given URL.
281 * @param [in] url The URL of the resource to load
283 void LoadUrl(const std::string& url);
286 * @brief Loads a given string as web contents.
288 * @param [in] htmlString The string to use as the contents of the web page
290 void LoadHtmlString(const std::string& htmlString);
293 * @brief Reloads the Web.
298 * @brief Stops loading web contents on the current page.
303 * @brief Suspends the operation associated with the view.
308 * @brief Resumes the operation associated with the view object after calling Suspend().
313 * @brief Scrolls the webpage of view by deltaX and deltaY.
314 * @param[in] deltaX The delta x of scroll
315 * @param[in] deltaY The delta y of scroll
317 void ScrollBy( int deltaX, int deltaY );
320 * @brief Returns whether forward is possible.
322 * @return True if forward is possible, false otherwise
327 * @brief Goes forward in the navigation history.
332 * @brief Returns whether backward is possible.
334 * @return True if backward is possible, false otherwise
339 * @brief Goes back in the navigation history.
344 * @brief Evaluates JavaScript code represented as a string.
346 * @param[in] script The JavaScript code
347 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
349 void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
352 * @brief Evaluates JavaScript code represented as a string.
354 * @param[in] script The JavaScript code
356 void EvaluateJavaScript(const std::string& script);
359 * @brief Inject a JavaScript object with a message handler into the WebView.
361 * @note The injected object will appear in the JavaScript context to be loaded next.
367 * webview.AddJavaScriptMessageHandler( "myObject", []( const std::string& message ) {
368 * printf( "Received a message from JS: %s", message.c_str() );
371 * // Start WebView by loading URL
372 * webview.LoadUrl( url );
376 * myObject.postMessage( "Hello World!" ); // "Received a message from JS: Hello World!"
379 * @param[in] exposedObjectName The name of exposed object
380 * @param[in] handler The callback function
382 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
385 * @brief Clears the history of Web.
390 * @brief Connects to this signal to be notified when page loading is started.
392 * @return A signal object to connect with
394 WebViewPageLoadSignalType& PageLoadStartedSignal();
397 * @brief Connects to this signal to be notified when page loading is finished.
399 * @return A signal object to connect with
401 WebViewPageLoadSignalType& PageLoadFinishedSignal();
404 * @brief Connects to this signal to be notified when an error occurs in page loading.
406 * @return A signal object to connect with.
408 WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
411 * @brief Connects to this signal to be notified when scroll edge is reached.
413 * @return A signal object to connect with.
415 WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
417 public: // Not intended for application developers
420 * @brief Creates a handle using the Toolkit::Internal implementation.
422 * @param[in] implementation The WebView implementation
424 DALI_INTERNAL WebView(Internal::WebView& implementation);
427 * @brief Allows the creation of this WebView from an Internal::CustomActor pointer.
429 * @param[in] internal A pointer to the internal CustomActor
431 explicit DALI_INTERNAL WebView(Dali::Internal::CustomActor* internal);
439 } // namespace Toolkit
443 #endif // DALI_TOOLKIT_WEB_VIEW_H