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