3cb1eb638c27fba75643de7731fd80865ecec6e0
[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) 2018 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::CanGoForward()
97    */
98   bool CanGoForward();
99
100   /**
101    * @copydoc Dali::WebEngine::GoForward()
102    */
103   void GoForward();
104
105   /**
106    * @copydoc Dali::WebEngine::CanGoBack()
107    */
108   bool CanGoBack();
109
110   /**
111    * @copydoc Dali::WebEngine::GoBack()
112    */
113   void GoBack();
114
115   /**
116    * @copydoc Dali::WebEngine::EvaluateJavaScript()
117    */
118   void EvaluateJavaScript( const std::string& script );
119
120   /**
121    * @copydoc Dali::WebEngine::AddJavaScriptInterface()
122    */
123   void AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > cb );
124
125   /**
126    * @copydoc Dali::WebEngine::RemoveJavascriptInterface()
127    */
128   void RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName );
129
130   /**
131    * @copydoc Dali::WebEngine::ClearHistory()
132    */
133   void ClearHistory();
134
135   /**
136    * @copydoc Dali::WebEngine::ClearCache()
137    */
138   void ClearCache();
139
140   /**
141    * @copydoc Dali::WebEngine::SetSize()
142    */
143   void SetSize( int width, int height );
144
145   /**
146    * @copydoc Dali::WebEngine::SendTouchEvent()
147    */
148   bool SendTouchEvent( const Dali::TouchData& touch );
149
150   /**
151    * @copydoc Dali::WebEngine::SendKeyEvent()
152    */
153   bool SendKeyEvent( const Dali::KeyEvent& event );
154
155   /**
156    * @copydoc Dali::WebEngine::PageLoadStartedSignal()
157    */
158   Dali::WebEnginePlugin::WebEngineSignalType& PageLoadStartedSignal();
159
160   /**
161    * @copydoc Dali::WebEngine::PageLoadFinishedSignal()
162    */
163   Dali::WebEnginePlugin::WebEngineSignalType& PageLoadFinishedSignal();
164
165 private:
166
167   /**
168    * @brief Constructor.
169    */
170   WebEngine();
171
172   /**
173    * @brief Destructor.
174    */
175   virtual ~WebEngine();
176
177   // Undefined copy constructor
178   WebEngine( const WebEngine& WebEngine );
179
180   // Undefined assignment operator
181   WebEngine& operator=( const WebEngine& WebEngine );
182
183   /**
184    * @brief Initializes member data.
185    *
186    * @return Whether the initialization succeed or not.
187    */
188   bool Initialize();
189
190 private:
191
192   Dali::WebEnginePlugin* mPlugin; ///< WebEngine plugin handle
193   void* mHandle; ///< Handle for the loaded library
194
195   typedef Dali::WebEnginePlugin* (*CreateWebEngineFunction)();
196   typedef void (*DestroyWebEngineFunction)( Dali::WebEnginePlugin* plugin );
197
198   CreateWebEngineFunction mCreateWebEnginePtr;
199   DestroyWebEngineFunction mDestroyWebEnginePtr;
200 };
201
202 } // namespace Adaptor
203 } // namespace Internal
204
205 inline static Internal::Adaptor::WebEngine& GetImplementation( Dali::WebEngine& webEngine )
206 {
207   DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
208
209   BaseObject& handle = webEngine.GetBaseObject();
210
211   return static_cast< Internal::Adaptor::WebEngine& >( handle );
212 }
213
214 inline static const Internal::Adaptor::WebEngine& GetImplementation( const Dali::WebEngine& webEngine )
215 {
216   DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
217
218   const BaseObject& handle = webEngine.GetBaseObject();
219
220   return static_cast< const Internal::Adaptor::WebEngine& >( handle );
221 }
222
223 } // namespace Dali;
224
225 #endif
226