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