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