Merge "Add lock for image loading" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / web-engine-plugin.h
1 #ifndef DALI_WEB_ENGINE_PLUGIN_H
2 #define DALI_WEB_ENGINE_PLUGIN_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 <dali/public-api/images/native-image-interface.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/signals/dali-signal.h>
25 #include <functional>
26
27 namespace Dali
28 {
29 class KeyEvent;
30 class PixelData;
31 class TouchEvent;
32 class WebEngineBackForwardList;
33 class WebEngineContext;
34 class WebEngineCookieManager;
35 class WebEngineSettings;
36 class HoverEvent;
37 class WheelEvent;
38
39 /**
40  * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
41  * A concrete implementation must be created for each platform and provided as dynamic library.
42  */
43 class WebEnginePlugin
44 {
45 public:
46   /**
47    * @brief WebEngine signal type related with page loading.
48    */
49   using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
50
51   /**
52    * @brief WebView signal type related with page loading error.
53    */
54   using WebEnginePageLoadErrorSignalType = Signal<void(const std::string&, int)>;
55
56   // forward declaration.
57   enum class ScrollEdge;
58
59   /**
60    * @brief WebView signal type related with scroll edge reached.
61    */
62   using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
63
64   /**
65    * @brief WebView signal type related with page url changed.
66    */
67   using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
68
69   /**
70    * @brief Alert callback when JavaScript alert is called with a message.
71    *  It returns true if a pop-up is created successfully, false otherwise.
72    */
73   using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
74
75   /**
76    * @brief Confirm callback when JavaScript confirm is called with a message.
77    *  It returns true if a pop-up is created successfully, false otherwise.
78    */
79   using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
80
81   /**
82    * @brief Prompt callback when JavaScript prompt is called with a message
83    *  and an optional value that is the default value for the input field.
84    *  It returns true if a pop-up is created successfully, false otherwise.
85    */
86   using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
87
88   /**
89    * @brief Enumeration for the scroll edge.
90    */
91   enum class ScrollEdge
92   {
93     LEFT,   ///< Left edge reached.
94     RIGHT,  ///< Right edge reached.
95     TOP,    ///< Top edge reached.
96     BOTTOM, ///< Bottom edge reached.
97   };
98
99   /**
100    * @brief Constructor.
101    */
102   WebEnginePlugin() = default;
103
104   /**
105    * @brief Destructor.
106    */
107   virtual ~WebEnginePlugin() = default;
108
109   /**
110    * @brief Creates WebEngine instance.
111    *
112    * @param [in] width The width of Web
113    * @param [in] height The height of Web
114    * @param [in] locale The locale of Web
115    * @param [in] timezoneId The timezoneID of Web
116    */
117   virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
118
119   /**
120    * @brief Creates WebEngine instance.
121    *
122    * @param [in] width The width of Web
123    * @param [in] height The height of Web
124    * @param [in] argc The count of application arguments
125    * @param [in] argv The string array of application arguments
126    */
127   virtual void Create(int width, int height, int argc, char** argv) = 0;
128
129   /**
130    * @brief Destroys WebEngine instance.
131    */
132   virtual void Destroy() = 0;
133
134   /**
135    * @brief Get settings of WebEngine.
136    */
137   virtual WebEngineSettings& GetSettings() const = 0;
138
139   /**
140    * @brief Get context of WebEngine.
141    */
142   virtual WebEngineContext& GetContext() const = 0;
143
144   /**
145    * @brief Get cookie manager of WebEngine.
146    */
147   virtual WebEngineCookieManager& GetCookieManager() const = 0;
148
149   /**
150    * @brief Get back-forward list of WebEngine.
151    */
152   virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
153
154   /**
155    * @brief Loads a web page based on a given URL.
156    *
157    * @param [in] url The URL of the resource to load
158    */
159   virtual void LoadUrl(const std::string& url) = 0;
160
161   /**
162    * @brief Returns the title of the Web.
163    *
164    * @return The title of web page
165    */
166   virtual std::string GetTitle() const = 0;
167
168   /**
169    * @brief Returns the Favicon of the Web.
170    *
171    * @return Favicon of Dali::PixelData& type
172    */
173   virtual Dali::PixelData GetFavicon() const = 0;
174
175   /**
176    * @brief Gets image to render.
177    */
178   virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
179
180   /**
181    * @brief Returns the URL of the Web.
182    *
183    * @return Url of string type
184    */
185   virtual const std::string& GetUrl() = 0;
186
187   /**
188    * @brief Loads a given string as web contents.
189    *
190    * @param [in] htmlString The string to use as the contents of the web page
191    */
192   virtual void LoadHtmlString(const std::string& htmlString) = 0;
193
194   /**
195    * @brief Reloads the Web.
196    */
197   virtual void Reload() = 0;
198
199   /**
200    * @brief Stops loading web contents on the current page.
201    */
202   virtual void StopLoading() = 0;
203
204   /**
205    * @brief Suspends the operation associated with the view.
206    */
207   virtual void Suspend() = 0;
208
209   /**
210    * @brief Resumes the operation associated with the view object after calling Suspend().
211    */
212   virtual void Resume() = 0;
213
214   /**
215    * @brief Scrolls the webpage of view by deltaX and deltaY.
216    */
217   virtual void ScrollBy(int deltaX, int deltaY) = 0;
218
219   /**
220    * @brief Scroll to the specified position of the given view.
221    */
222   virtual void SetScrollPosition(int x, int y) = 0;
223
224   /**
225    * @brief Gets the current scroll position of the given view.
226    */
227   virtual Dali::Vector2 GetScrollPosition() const = 0;
228
229   /**
230    * @brief Gets the possible scroll size of the given view.
231    */
232   virtual Dali::Vector2 GetScrollSize() const = 0;
233
234   /**
235    * @brief Gets the last known content's size.
236    */
237   virtual Dali::Vector2 GetContentSize() const = 0;
238
239   /**
240    * @brief Returns whether forward is possible.
241    *
242    * @return True if forward is possible, false otherwise
243    */
244   virtual bool CanGoForward() = 0;
245
246   /**
247    * @brief Goes to forward.
248    */
249   virtual void GoForward() = 0;
250
251   /**
252    * @brief Returns whether backward is possible.
253    *
254    * @return True if backward is possible, false otherwise
255    */
256   virtual bool CanGoBack() = 0;
257
258   /**
259    * @brief Goes to back.
260    */
261   virtual void GoBack() = 0;
262
263   /**
264    * @brief Evaluates JavaScript code represented as a string.
265    *
266    * @param[in] script The JavaScript code
267    * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
268    */
269   virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
270
271   /**
272    * @brief Add a message handler into JavaScript.
273    *
274    * @param[in] exposedObjectName The name of exposed object
275    * @param[in] handler The callback function
276    */
277   virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
278
279   /**
280    * @brief Register a callback for JavaScript alert.
281    *
282    * @param[in] callback The callback function
283    */
284   virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
285
286   /**
287    * @brief Reply for JavaScript alert.
288    */
289   virtual void JavaScriptAlertReply() = 0;
290
291   /**
292    * @brief Register a callback for JavaScript confirm.
293    *
294    * @param[in] callback The callback function
295    */
296   virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
297
298   /**
299    * @brief Reply for JavaScript confirm.
300    */
301   virtual void JavaScriptConfirmReply( bool confirmed ) = 0;
302
303   /**
304    * @brief Register a callback for JavaScript prompt.
305    *
306    * @param[in] callback The callback function
307    */
308   virtual void RegisterJavaScriptPromptCallback( JavaScriptPromptCallback callback ) = 0;
309
310   /**
311    * @brief Reply for JavaScript prompt.
312    */
313   virtual void JavaScriptPromptReply( const std::string& result ) = 0;
314
315   /**
316    * @brief Clears the history of Web.
317    */
318   virtual void ClearHistory() = 0;
319
320   /**
321    * @brief Clears all tiles resources of Web.
322    */
323   virtual void ClearAllTilesResources() = 0;
324
325   /**
326    * @brief Get user agent string.
327    *
328    * @return The string value of user agent
329    */
330   virtual const std::string& GetUserAgent() const = 0;
331
332   /**
333    * @brief Set user agent string.
334    *
335    * @param[in] userAgent The string value of user agent
336    */
337   virtual void SetUserAgent(const std::string& userAgent) = 0;
338
339   /**
340    * @brief Sets size of Web Page.
341    */
342   virtual void SetSize(int width, int height) = 0;
343
344   /**
345    * @brief Sends Touch Events.
346    */
347   virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
348
349   /**
350    * @brief Sends Key Events.
351    */
352   virtual bool SendKeyEvent(const KeyEvent& event) = 0;
353
354   /**
355    * @brief Support mouse events or not.
356    * @param[in] enabled True if enabled, false othewise.
357    */
358   virtual void EnableMouseEvents( bool enabled ) = 0;
359
360   /**
361    * @brief Support key events or not.
362    * @param[in] enabled True if enabled, false othewise.
363    */
364   virtual void EnableKeyEvents( bool enabled ) = 0;
365
366   /**
367    * @brief Sets focus.
368    * @param[in] focused True if focus is gained, false lost.
369    */
370   virtual void SetFocus(bool focused) = 0;
371
372   /**
373    * @brief Update display area.
374    * @param[in] displayArea The display area need be updated.
375    */
376   virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
377
378   /**
379    * @brief Enable video hole.
380    * @param[in] enabled True if enabled, false othewise.
381    */
382   virtual void EnableVideoHole(bool enabled) = 0;
383
384   /**
385    * @brief Sends Hover Events.
386    * @param[in] event The hover event would be sent.
387    */
388   virtual bool SendHoverEvent( const HoverEvent& event ) = 0;
389
390   /**
391    * @brief Sends Wheel Events.
392    * @param[in] event The wheel event would be sent.
393    */
394   virtual bool SendWheelEvent( const WheelEvent& event ) = 0;
395
396   /**
397    * @brief Connects to this signal to be notified when page loading is started.
398    *
399    * @return A signal object to connect with.
400    */
401   virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
402
403   /**
404    * @brief Connects to this signal to be notified when page loading is in progress.
405    *
406    * @return A signal object to connect with.
407    */
408   virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
409
410   /**
411    * @brief Connects to this signal to be notified when page loading is finished.
412    *
413    * @return A signal object to connect with.
414    */
415   virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
416
417   /**
418    * @brief Connects to this signal to be notified when an error occurs in page loading.
419    *
420    * @return A signal object to connect with.
421    */
422   virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
423
424   /**
425    * @brief Connects to this signal to be notified when scroll edge is reached.
426    *
427    * @return A signal object to connect with.
428    */
429   virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
430
431   /**
432    * @brief Connects to this signal to be notified when url is changed.
433    *
434    * @return A signal object to connect with.
435    */
436   virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;
437
438 };
439
440 } // namespace Dali
441
442 #endif