Updated all header files to new format
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / web-view / web-view.h
1 #ifndef DALI_TOOLKIT_WEB_VIEW_H
2 #define DALI_TOOLKIT_WEB_VIEW_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <functional>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control.h>
26 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 class ImageView;
33 class WebBackForwardList;
34 class WebContext;
35 class WebCookieManager;
36 class WebSettings;
37
38 namespace Internal DALI_INTERNAL
39 {
40 class WebView;
41 } // namespace DALI_INTERNAL
42
43 /**
44  * @addtogroup dali_toolkit_controls_web_view
45  * @{
46  */
47
48 /**
49  * @brief WebView is a control for displaying web content.
50  *
51  * This enables embedding web pages in the application.
52  *
53  * For working WebView, a web engine plugin for a platform should be provided.
54  *
55  */
56 class DALI_TOOLKIT_API WebView : public Control
57 {
58 public:
59   /**
60    * @brief Enumeration for the start and end property ranges for this control.
61    */
62   enum PropertyRange
63   {
64     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
65     PROPERTY_END_INDEX   = PROPERTY_START_INDEX + 1000,
66   };
67
68   /**
69    * @brief Enumeration for the instance of properties belonging to the WebView class.
70    */
71   struct Property
72   {
73     enum
74     {
75       /**
76        * @brief The url to load.
77        * @details name "url", type Property::STRING.
78        */
79       URL = PROPERTY_START_INDEX,
80
81       /**
82        * @brief The user agent string.
83        * @details name "userAgent", type Property::STRING.
84        */
85       USER_AGENT,
86
87       /**
88        * @brief The current position of scroll.
89        * @details name "scrollPosition", type Property::VECTOR2.
90        */
91       SCROLL_POSITION,
92
93       /**
94        * @brief The current size of scroll.
95        * @details name "scrollSize", type Property::VECTOR2.
96        * @note The value is read-only.
97        */
98       SCROLL_SIZE,
99
100       /**
101        * @brief The current size of content.
102        * @details name "contentSize", type Property::VECTOR2.
103        * @note The value is read-only.
104        */
105       CONTENT_SIZE,
106
107       /**
108        * @brief The title of web page.
109        * @details name "title", type Property::STRING.
110        * @note The value is read-only.
111        */
112       TITLE,
113
114       /**
115        * @brief Whether video hole is enabled or not.
116        * @details name "videoHoleEnabled", type Property::BOOLEAN.
117        * @note The value is read-only.
118        */
119       VIDEO_HOLE_ENABLED,
120     };
121   };
122
123   /**
124    * @brief Enumeration for indicating error code of page loading.
125    */
126   enum class LoadErrorCode
127   {
128     UNKNOWN = 0,           ///< Unknown.
129     CANCELED,              ///< User canceled.
130     CANT_SUPPORT_MIMETYPE, ///< Can't show the page for this MIME type.
131     FAILED_FILE_IO,        ///< File IO error.
132     CANT_CONNECT,          ///< Cannot connect to the network.
133     CANT_LOOKUP_HOST,      ///< Fail to look up host from the DNS.
134     FAILED_TLS_HANDSHAKE,  ///< Fail to SSL/TLS handshake.
135     INVALID_CERTIFICATE,   ///< Received certificate is invalid.
136     REQUEST_TIMEOUT,       ///< Connection timeout.
137     TOO_MANY_REDIRECTS,    ///< Too many redirects.
138     TOO_MANY_REQUESTS,     ///< Too many requests during this load.
139     BAD_URL,               ///< Malformed URL.
140     UNSUPPORTED_SCHEME,    ///< Unsupported scheme.
141     AUTHENTICATION,        ///< User authentication failed on the server.
142     INTERNAL_SERVER        ///< Web server has an internal server error.
143   };
144
145   /**
146    * @brief WebView signal type related with page loading.
147    */
148   using WebViewPageLoadSignalType = Signal<void(WebView, const std::string&)>;
149
150   /**
151    * @brief WebView signal type related with page loading error.
152    */
153   using WebViewPageLoadErrorSignalType = Signal<void(WebView, const std::string&, LoadErrorCode)>;
154
155   /**
156    * @brief WebView signal type related with scroll edge reached.
157    */
158   using WebViewScrollEdgeReachedSignalType = Signal<void(WebView, Dali::WebEnginePlugin::ScrollEdge)>;
159
160 public:
161   /**
162    * @brief Creates an initialized WebView.
163    * @return A handle to a newly allocated Dali WebView
164    *
165    * @note WebView will not display anything
166    */
167   static WebView New();
168
169   /**
170    * @brief Creates an initialized WebView.
171    *
172    * @param [in] locale The locale of Web
173    * @param [in] timezoneId The timezoneId of Web
174    */
175   static WebView New(const std::string& locale, const std::string& timezoneId);
176
177   /**
178    * @brief Creates an initialized WebView.
179    *
180    * @param [in] argc The count of arguments of Applications
181    * @param [in] argv The string array of arguments of Applications
182    */
183   static WebView New(int argc, char** argv);
184
185   /**
186    * @brief Creates an uninitialized WebView.
187    */
188   WebView();
189
190   /**
191    * @brief Destructor.
192    *
193    * This is non-virtual since derived Handel types must not contain data or virtual methods.
194    */
195   ~WebView();
196
197   /*
198    * @brief Copy constructor.
199    *
200    * @param[in] WebView WebView to copy. The copied WebView will point at the same implementation
201    */
202   WebView(const WebView& WebView);
203
204   /**
205    * @brief Assignment operator.
206    *
207    * @param[in] WebView The WebView to assign from
208    * @return The updated WebView
209    */
210   WebView& operator=(const WebView& WebView);
211
212   /**
213    * @brief Downcasts a handle to WebView handle.
214    *
215    * If handle points to a WebView, the downcast produces valid handle.
216    * If not, the returned handle is left uninitialized.
217    *
218    * @param[in] handle Handle to an object
219    * @return Handle to a WebView or an uninitialized handle
220    */
221   static WebView DownCast(BaseHandle handle);
222
223   /**
224    * @brief Get WebSettings of WebEngine.
225    */
226   Dali::Toolkit::WebSettings* GetSettings() const;
227
228   /**
229    * @brief Get WebContext of WebEngine.
230    */
231   Dali::Toolkit::WebContext* GetContext() const;
232
233   /**
234    * @brief Get CookieManager of WebEngine.
235    */
236   Dali::Toolkit::WebCookieManager* GetCookieManager() const;
237
238   /**
239    * @brief Get WebBackForwardList of WebEngine.
240    */
241   Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
242
243   /**
244    * @brief Get Favicon of web page.
245    *
246    * @return Handle to a fav icon
247    */
248   Dali::Toolkit::ImageView& GetFavicon();
249
250   /**
251    * @brief Loads a web page based on a given URL.
252    *
253    * @param [in] url The URL of the resource to load
254    */
255   void LoadUrl(const std::string& url);
256
257   /**
258    * @brief Loads a given string as web contents.
259    *
260    * @param [in] htmlString The string to use as the contents of the web page
261    */
262   void LoadHtmlString(const std::string& htmlString);
263
264   /**
265    * @brief Reloads the Web.
266    */
267   void Reload();
268
269   /**
270    * @brief Stops loading web contents on the current page.
271    */
272   void StopLoading();
273
274   /**
275    * @brief Suspends the operation associated with the view.
276    */
277   void Suspend();
278
279   /**
280    * @brief Resumes the operation associated with the view object after calling Suspend().
281    */
282   void Resume();
283
284   /**
285    * @brief Scrolls the webpage of view by deltaX and deltaY.
286    * @param[in] deltaX The delta x of scroll
287    * @param[in] deltaY The delta y of scroll
288    */
289   void ScrollBy(int deltaX, int deltaY);
290
291   /**
292    * @brief Returns whether forward is possible.
293    *
294    * @return True if forward is possible, false otherwise
295    */
296   bool CanGoForward();
297
298   /**
299    * @brief Goes forward in the navigation history.
300    */
301   void GoForward();
302
303   /**
304    * @brief Returns whether backward is possible.
305    *
306    * @return True if backward is possible, false otherwise
307    */
308   bool CanGoBack();
309
310   /**
311    * @brief Goes back in the navigation history.
312    */
313   void GoBack();
314
315   /**
316    * @brief Evaluates JavaScript code represented as a string.
317    *
318    * @param[in] script The JavaScript code
319    * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
320    */
321   void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
322
323   /**
324    * @brief Evaluates JavaScript code represented as a string.
325    *
326    * @param[in] script The JavaScript code
327    */
328   void EvaluateJavaScript(const std::string& script);
329
330   /**
331    * @brief Inject a JavaScript object with a message handler into the WebView.
332    *
333    * @note The injected object will appear in the JavaScript context to be loaded next.
334    *
335    * Example:
336    *
337    * 1. Native
338    *
339    *     webview.AddJavaScriptMessageHandler( "myObject", []( const std::string& message ) {
340    *         printf( "Received a message from JS: %s", message.c_str() );
341    *     });
342    *
343    *     // Start WebView by loading URL
344    *     webview.LoadUrl( url );
345    *
346    * 2. JavaScript
347    *
348    *     myObject.postMessage( "Hello World!" ); // "Received a message from JS: Hello World!"
349    *
350    *
351    * @param[in] exposedObjectName The name of exposed object
352    * @param[in] handler The callback function
353    */
354   void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
355
356   /**
357    * @brief Clears all tiles resources of Web.
358    */
359   void ClearAllTilesResources();
360
361   /**
362    * @brief Clears the history of Web.
363    */
364   void ClearHistory();
365
366   /**
367    * @brief Connects to this signal to be notified when page loading is started.
368    *
369    * @return A signal object to connect with
370    */
371   WebViewPageLoadSignalType& PageLoadStartedSignal();
372
373   /**
374    * @brief Connects to this signal to be notified when page loading is finished.
375    *
376    * @return A signal object to connect with
377    */
378   WebViewPageLoadSignalType& PageLoadFinishedSignal();
379
380   /**
381    * @brief Connects to this signal to be notified when an error occurs in page loading.
382    *
383    * @return A signal object to connect with.
384    */
385   WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
386
387   /**
388    * @brief Connects to this signal to be notified when scroll edge is reached.
389    *
390    * @return A signal object to connect with.
391    */
392   WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
393
394 public: // Not intended for application developers
395   /// @cond internal
396   /**
397    * @brief Creates a handle using the Toolkit::Internal implementation.
398    *
399    * @param[in] implementation The WebView implementation
400    */
401   DALI_INTERNAL WebView(Internal::WebView& implementation);
402
403   /**
404    * @brief Allows the creation of this WebView from an Internal::CustomActor pointer.
405    *
406    * @param[in] internal A pointer to the internal CustomActor
407    */
408   explicit DALI_INTERNAL WebView(Dali::Internal::CustomActor* internal);
409   /// @endcond
410 };
411
412 /**
413  * @}
414  */
415
416 } // namespace Toolkit
417
418 } // namespace Dali
419
420 #endif // DALI_TOOLKIT_WEB_VIEW_H