a9a9928426bc2547581a9fa106dd18f9c633bdcb
[platform/core/uifw/dali-adaptor.git] / dali / internal / web-engine / common / web-engine-impl.h
1 #ifndef DALI_WEB_ENGINE_IMPL_H
2 #define DALI_WEB_ENGINE_IMPL_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/object/base-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/web-engine.h>
26 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace Adaptor
35 {
36
37 class WebEngine;
38
39 typedef IntrusivePtr< WebEngine > WebEnginePtr;
40
41 /**
42  * @brief WebEngine class is used for Web.
43  */
44 class WebEngine : public Dali::BaseObject
45 {
46 public:
47
48   /**
49    * @brief Creates a new WebEngine handle
50    *
51    * @return WebEngine pointer
52    */
53   static WebEnginePtr New();
54
55   /**
56    * @copydoc Dali::WebEngine::Create()
57    */
58   void Create( int width, int height, const std::string& locale, const std::string& timezoneId );
59
60   /**
61    * @copydoc Dali::WebEngine::Destroy()
62    */
63   void Destroy();
64
65   /**
66    * @copydoc Dali::WebEngine::GetNativeImageSource()
67    */
68   Dali::NativeImageInterfacePtr GetNativeImageSource();
69
70   /**
71    * @copydoc Dali::WebEngine::LoadUrl()
72    */
73   void LoadUrl( const std::string& url );
74
75   /**
76    * @copydoc Dali::WebEngine::GetUrl()
77    */
78   const std::string& GetUrl();
79
80   /**
81    * @copydoc Dali::WebEngine::LoadHTMLString()
82    */
83   void LoadHTMLString( const std::string& htmlString );
84
85   /**
86    * @copydoc Dali::WebEngine::Reload()
87    */
88   void Reload();
89
90   /**
91    * @copydoc Dali::WebEngine::StopLoading()
92    */
93   void StopLoading();
94
95   /**
96    * @copydoc Dali::WebEngine::Suspend()
97    */
98   void Suspend();
99
100   /**
101    * @copydoc Dali::WebEngine::Resume()
102    */
103   void Resume();
104
105   /**
106    * @copydoc Dali::WebEngine::CanGoForward()
107    */
108   bool CanGoForward();
109
110   /**
111    * @copydoc Dali::WebEngine::GoForward()
112    */
113   void GoForward();
114
115   /**
116    * @copydoc Dali::WebEngine::CanGoBack()
117    */
118   bool CanGoBack();
119
120   /**
121    * @copydoc Dali::WebEngine::GoBack()
122    */
123   void GoBack();
124
125   /**
126    * @copydoc Dali::WebEngine::EvaluateJavaScript()
127    */
128   void EvaluateJavaScript( const std::string& script, std::function< void(const std::string&) > resultHandler );
129
130   /**
131    * @copydoc Dali::WebEngine::AddJavaScriptMessageHandler()
132    */
133   void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void(const std::string&) > handler );
134
135   /**
136    * @copydoc Dali::WebEngine::ClearHistory()
137    */
138   void ClearHistory();
139
140   /**
141    * @copydoc Dali::WebEngine::ClearCache()
142    */
143   void ClearCache();
144
145   /**
146    * @copydoc Dali::WebEngine::ClearCookies()
147    */
148   void ClearCookies();
149
150   /**
151    * @copydoc Dali::WebEngine::GetCacheModel()
152    */
153   Dali::WebEnginePlugin::CacheModel GetCacheModel() const;
154
155   /**
156    * @copydoc Dali::WebEngine::SetCacheModel()
157    */
158   void SetCacheModel( Dali::WebEnginePlugin::CacheModel cacheModel );
159
160   /**
161    * @copydoc Dali::WebEngine::GetCookieAcceptPolicy()
162    */
163   Dali::WebEnginePlugin::CookieAcceptPolicy GetCookieAcceptPolicy() const;
164
165   /**
166    * @copydoc Dali::WebEngine::SetCookieAcceptPolicy()
167    */
168   void SetCookieAcceptPolicy( Dali::WebEnginePlugin::CookieAcceptPolicy policy );
169
170   /**
171    * @copydoc Dali::WebEngine::GetUserAgent()
172    */
173   const std::string& GetUserAgent() const;
174
175   /**
176    * @copydoc Dali::WebEngine::SetUserAgent()
177    */
178   void SetUserAgent( const std::string& userAgent );
179
180   /**
181    * @copydoc Dali::WebEngine::IsJavaScriptEnabled()
182    */
183   bool IsJavaScriptEnabled() const;
184
185   /**
186    * @copydoc Dali::WebEngine::EnableJavaScript()
187    */
188   void EnableJavaScript( bool enabled );
189
190   /**
191    * @copydoc Dali::WebEngine::AreImagesAutomaticallyLoaded()
192    */
193   bool AreImagesAutomaticallyLoaded() const;
194
195   /**
196    * @copydoc Dali::WebEngine::LoadImagesAutomatically()
197    */
198   void LoadImagesAutomatically( bool automatic );
199
200   /**
201    * @copydoc Dali::WebEngine::GetDefaultTextEncodingName()
202    */
203   const std::string& GetDefaultTextEncodingName() const;
204
205   /**
206    * @copydoc Dali::WebEngine::SetDefaultTextEncodingName()
207    */
208   void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName );
209
210   /**
211    * @copydoc Dali::WebEngine::GetDefaultFontSize()
212    */
213   int GetDefaultFontSize() const;
214
215   /**
216    * @copydoc Dali::WebEngine::SetDefaultFontSize()
217    */
218   void SetDefaultFontSize( int defaultFontSize );
219
220   /**
221    * @copydoc Dali::WebEngine::SetSize()
222    */
223   void SetSize( int width, int height );
224
225   /**
226    * @copydoc Dali::WebEngine::SendTouchEvent()
227    */
228   bool SendTouchEvent( const Dali::TouchEvent& touch );
229
230   /**
231    * @copydoc Dali::WebEngine::SendKeyEvent()
232    */
233   bool SendKeyEvent( const Dali::KeyEvent& event );
234
235   /**
236    * @copydoc Dali::WebEngine::SetFocus()
237    */
238   void SetFocus( bool focused );
239
240   /**
241    * @copydoc Dali::WebEngine::PageLoadStartedSignal()
242    */
243   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
244
245   /**
246    * @copydoc Dali::WebEngine::PageLoadFinishedSignal()
247    */
248   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
249
250   /**
251    * @copydoc Dali::WebEngine::PageLoadErrorSignal()
252    */
253   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
254
255 private:
256
257   /**
258    * @brief Constructor.
259    */
260   WebEngine();
261
262   /**
263    * @brief Destructor.
264    */
265   virtual ~WebEngine();
266
267   // Undefined copy constructor
268   WebEngine( const WebEngine& WebEngine );
269
270   // Undefined assignment operator
271   WebEngine& operator=( const WebEngine& WebEngine );
272
273   /**
274    * @brief Initializes member data.
275    *
276    * @return Whether the initialization succeed or not.
277    */
278   bool Initialize();
279
280   /**
281    * @brief Initializes library handle by loading web engine plugin.
282    *
283    * @return Whether the initialization succeed or not.
284    */
285   bool InitializePluginHandle();
286
287 private:
288
289   typedef Dali::WebEnginePlugin* (*CreateWebEngineFunction)();
290   typedef void (*DestroyWebEngineFunction)( Dali::WebEnginePlugin* plugin );
291
292   Dali::WebEnginePlugin*                                  mPlugin; ///< WebEnginePlugin instance
293   void*                                                   mHandle; ///< Handle for the loaded library
294   CreateWebEngineFunction                                 mCreateWebEnginePtr;  ///< Function to create plugin instance
295   DestroyWebEngineFunction                                mDestroyWebEnginePtr; ///< Function to destroy plugin instance
296 };
297
298 } // namespace Adaptor
299 } // namespace Internal
300
301 inline static Internal::Adaptor::WebEngine& GetImplementation( Dali::WebEngine& webEngine )
302 {
303   DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
304
305   BaseObject& handle = webEngine.GetBaseObject();
306
307   return static_cast< Internal::Adaptor::WebEngine& >( handle );
308 }
309
310 inline static const Internal::Adaptor::WebEngine& GetImplementation( const Dali::WebEngine& webEngine )
311 {
312   DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
313
314   const BaseObject& handle = webEngine.GetBaseObject();
315
316   return static_cast< const Internal::Adaptor::WebEngine& >( handle );
317 }
318
319 } // namespace Dali;
320
321 #endif
322