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