5914637246dc3a498caa0ac30f9665cda6758856
[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/signals/dali-signal.h>
24 #include <functional>
25
26 namespace Dali
27 {
28 class KeyEvent;
29 class TouchEvent;
30
31 /**
32  * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
33  * A concrete implementation must be created for each platform and provided as dynamic library.
34  */
35 class WebEnginePlugin
36 {
37 public:
38   /**
39    * @brief WebEngine signal type related with page loading.
40    */
41   typedef Signal<void(const std::string&)> WebEnginePageLoadSignalType;
42
43   /**
44    * @brief WebView signal type related with page loading error.
45    */
46   typedef Signal<void(const std::string&, int)> WebEnginePageLoadErrorSignalType;
47
48   /**
49    * @brief Enumeration for cache model options.
50    */
51   enum class CacheModel
52   {
53     /**
54      * @brief Use the smallest cache capacity.
55      */
56     DOCUMENT_VIEWER,
57
58     /**
59      * @brief Use the bigger cache capacity than DocumentBrowser.
60      */
61     DOCUMENT_BROWSER,
62
63     /**
64      * @brief Use the biggest cache capacity.
65      */
66     PRIMARY_WEB_BROWSER
67   };
68
69   /**
70    * @brief Enumeration for the cookies accept policies.
71    */
72   enum class CookieAcceptPolicy
73   {
74     /**
75      * @brief Accepts every cookie sent from any page.
76      */
77     ALWAYS,
78
79     /**
80      * @brief Rejects all the cookies.
81      */
82     NEVER,
83
84     /**
85      * @brief Accepts only cookies set by the main document that is loaded.
86      */
87     NO_THIRD_PARTY
88   };
89
90   /**
91    * @brief Constructor.
92    */
93   WebEnginePlugin()
94   {
95   }
96
97   /**
98    * @brief Destructor.
99    */
100   virtual ~WebEnginePlugin()
101   {
102   }
103
104   /**
105    * @brief Creates WebEngine instance.
106    *
107    * @param [in] width The width of Web
108    * @param [in] height The height of Web
109    * @param [in] locale The locale of Web
110    * @param [in] timezoneId The timezoneID of Web
111    */
112   virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
113
114   /**
115    * @brief Destroys WebEngine instance.
116    */
117   virtual void Destroy() = 0;
118
119   /**
120    * @brief Loads a web page based on a given URL.
121    *
122    * @param [in] url The URL of the resource to load
123    */
124   virtual void LoadUrl(const std::string& url) = 0;
125
126   /**
127    * @brief Gets image to render.
128    */
129   virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
130
131   /**
132    * @brief Returns the URL of the Web.
133    *
134    * @return Url of string type
135    */
136   virtual const std::string& GetUrl() = 0;
137
138   /**
139    * @brief Loads a given string as web contents.
140    *
141    * @param [in] htmlString The string to use as the contents of the web page
142    */
143   virtual void LoadHTMLString(const std::string& htmlString) = 0;
144
145   /**
146    * @brief Reloads the Web.
147    */
148   virtual void Reload() = 0;
149
150   /**
151    * @brief Stops loading web contents on the current page.
152    */
153   virtual void StopLoading() = 0;
154
155   /**
156    * @brief Suspends the operation associated with the view.
157    */
158   virtual void Suspend() = 0;
159
160   /**
161    * @brief Resumes the operation associated with the view object after calling Suspend().
162    */
163   virtual void Resume() = 0;
164
165   /**
166    * @brief Returns whether forward is possible.
167    *
168    * @return True if forward is possible, false otherwise
169    */
170   virtual bool CanGoForward() = 0;
171
172   /**
173    * @brief Goes to forward.
174    */
175   virtual void GoForward() = 0;
176
177   /**
178    * @brief Returns whether backward is possible.
179    *
180    * @return True if backward is possible, false otherwise
181    */
182   virtual bool CanGoBack() = 0;
183
184   /**
185    * @brief Goes to back.
186    */
187   virtual void GoBack() = 0;
188
189   /**
190    * @brief Evaluates JavaScript code represented as a string.
191    *
192    * @param[in] script The JavaScript code
193    * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
194    */
195   virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
196
197   /**
198    * @brief Add a message handler into JavaScript.
199    *
200    * @param[in] exposedObjectName The name of exposed object
201    * @param[in] handler The callback function
202    */
203   virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
204
205   /**
206    * @brief Clears the history of Web.
207    */
208   virtual void ClearHistory() = 0;
209
210   /**
211    * @brief Clears the cache of Web.
212    */
213   virtual void ClearCache() = 0;
214
215   /**
216    * @brief Clears all the cookies of Web.
217    */
218   virtual void ClearCookies() = 0;
219
220   /**
221    * @brief Get cache model option. The default is DOCUMENT_VIEWER.
222    *
223    * @return The cache model option
224    */
225   virtual CacheModel GetCacheModel() const = 0;
226
227   /**
228    * @brief Set cache model option. The default is DOCUMENT_VIEWER.
229    *
230    * @param[in] cacheModel The cache model option
231    */
232   virtual void SetCacheModel(CacheModel cacheModel) = 0;
233
234   /**
235    * @brief Gets the cookie acceptance policy. The default is NO_THIRD_PARTY.
236    *
237    * @return The cookie acceptance policy
238    */
239   virtual CookieAcceptPolicy GetCookieAcceptPolicy() const = 0;
240
241   /**
242    * @brief Sets the cookie acceptance policy. The default is NO_THIRD_PARTY.
243    *
244    * @param[in] policy The cookie acceptance policy
245    */
246   virtual void SetCookieAcceptPolicy(CookieAcceptPolicy policy) = 0;
247
248   /**
249    * @brief Get user agent string.
250    *
251    * @return The string value of user agent
252    */
253   virtual const std::string& GetUserAgent() const = 0;
254
255   /**
256    * @brief Set user agent string.
257    *
258    * @param[in] userAgent The string value of user agent
259    */
260   virtual void SetUserAgent(const std::string& userAgent) = 0;
261
262   /**
263    * @brief Returns whether JavaScript can be executable. The default is true.
264    *
265    * @return true if JavaScript executing is enabled, false otherwise
266    */
267   virtual bool IsJavaScriptEnabled() const = 0;
268
269   /**
270    * @brief Enables/disables JavaScript executing. The default is enabled.
271    *
272    * @param[in] enabled True if JavaScript executing is enabled, false otherwise
273    */
274   virtual void EnableJavaScript(bool enabled) = 0;
275
276   /**
277    * @brief Returns whether images can be loaded automatically. The default is true.
278    *
279    * @return true if images are loaded automatically, false otherwise
280    */
281   virtual bool AreImagesAutomaticallyLoaded() const = 0;
282
283   /**
284    * @brief Enables/disables auto loading of images. The default is enabled.
285    *
286    * @param[in] automatic True if images are loaded automatically, false otherwise
287    */
288   virtual void LoadImagesAutomatically(bool automatic) = 0;
289
290   /**
291    * @brief Gets the default text encoding name (e.g. UTF-8).
292    *
293    * @return The default text encoding name
294    */
295   virtual const std::string& GetDefaultTextEncodingName() const = 0;
296
297   /**
298    * @brief Sets the default text encoding name (e.g. UTF-8).
299    *
300    * @param[in] defaultTextEncodingName The default text encoding name
301    */
302   virtual void SetDefaultTextEncodingName(const std::string& defaultTextEncodingName) = 0;
303
304   /**
305    * @brief Returns the default font size in pixel. The default value is 16.
306    *
307    * @return The default font size
308    */
309   virtual int GetDefaultFontSize() const = 0;
310
311   /**
312    * @brief Sets the default font size in pixel. The default value is 16.
313    *
314    * @param[in] defaultFontSize A new default font size to set
315    */
316   virtual void SetDefaultFontSize(int defaultFontSize) = 0;
317
318   /**
319    * @brief Sets size of Web Page.
320    */
321   virtual void SetSize(int width, int height) = 0;
322
323   /**
324    * @brief Sends Touch Events.
325    */
326   virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
327
328   /**
329    * @brief Sends Key Events.
330    */
331   virtual bool SendKeyEvent(const KeyEvent& event) = 0;
332
333   /**
334    * @brief Sets focus.
335    */
336   virtual void SetFocus( bool focused ) = 0;
337
338   /**
339    * @brief Connects to this signal to be notified when page loading is started.
340    *
341    * @return A signal object to connect with.
342    */
343   virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
344
345   /**
346    * @brief Connects to this signal to be notified when page loading is finished.
347    *
348    * @return A signal object to connect with.
349    */
350   virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
351
352   /**
353    * @brief Connects to this signal to be notified when an error occurs in page loading.
354    *
355    * @return A signal object to connect with.
356    */
357   virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
358 };
359
360 } // namespace Dali
361
362 #endif