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