19d93f3c9cb23cfaba0c8abaf298bfeabb22c714
[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::PageLoadStartedSignal()
237    */
238   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
239
240   /**
241    * @copydoc Dali::WebEngine::PageLoadFinishedSignal()
242    */
243   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
244
245   /**
246    * @copydoc Dali::WebEngine::PageLoadErrorSignal()
247    */
248   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
249
250 private:
251
252   /**
253    * @brief Constructor.
254    */
255   WebEngine();
256
257   /**
258    * @brief Destructor.
259    */
260   virtual ~WebEngine();
261
262   // Undefined copy constructor
263   WebEngine( const WebEngine& WebEngine );
264
265   // Undefined assignment operator
266   WebEngine& operator=( const WebEngine& WebEngine );
267
268   /**
269    * @brief Initializes member data.
270    *
271    * @return Whether the initialization succeed or not.
272    */
273   bool Initialize();
274
275   /**
276    * @brief Initializes library handle by loading web engine plugin.
277    *
278    * @return Whether the initialization succeed or not.
279    */
280   bool InitializePluginHandle();
281
282 private:
283
284   typedef Dali::WebEnginePlugin* (*CreateWebEngineFunction)();
285   typedef void (*DestroyWebEngineFunction)( Dali::WebEnginePlugin* plugin );
286
287   Dali::WebEnginePlugin*                                  mPlugin; ///< WebEnginePlugin instance
288   void*                                                   mHandle; ///< Handle for the loaded library
289   CreateWebEngineFunction                                 mCreateWebEnginePtr;  ///< Function to create plugin instance
290   DestroyWebEngineFunction                                mDestroyWebEnginePtr; ///< Function to destroy plugin instance
291 };
292
293 } // namespace Adaptor
294 } // namespace Internal
295
296 inline static Internal::Adaptor::WebEngine& GetImplementation( Dali::WebEngine& webEngine )
297 {
298   DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
299
300   BaseObject& handle = webEngine.GetBaseObject();
301
302   return static_cast< Internal::Adaptor::WebEngine& >( handle );
303 }
304
305 inline static const Internal::Adaptor::WebEngine& GetImplementation( const Dali::WebEngine& webEngine )
306 {
307   DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
308
309   const BaseObject& handle = webEngine.GetBaseObject();
310
311   return static_cast< const Internal::Adaptor::WebEngine& >( handle );
312 }
313
314 } // namespace Dali;
315
316 #endif
317